Get RGBA from ColorRequester?

Everything else that doesn't fall into one of the other PB categories.
User avatar
bbanelli
Enthusiast
Enthusiast
Posts: 543
Joined: Tue May 28, 2013 10:51 pm
Location: Europe
Contact:

Get RGBA from ColorRequester?

Post by bbanelli »

Greetings to all,

in order to use VectorFont drawing, 32 bit color is required. However, ColorRequester() only returns 24 bit color. What is the procedure to add transparency to that value?

TIA!

Bruno
"If you lie to the compiler, it will get its revenge."
Henry Spencer
https://www.pci-z.com/
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: Get RGBA from ColorRequester?

Post by Keya »

Code: Select all

color24.l = RGB($11,$22,$33)        ;11 22 33 00  \ 
color32.l = RGBA($11,$22,$33,$FF)   ;11 22 33 FF  / ShowMemory(@colorn,4)
therefore:

Code: Select all

color32 = color24 | $FF000000       ;FF=opaque - 0=transparent
:)
User avatar
bbanelli
Enthusiast
Enthusiast
Posts: 543
Joined: Tue May 28, 2013 10:51 pm
Location: Europe
Contact:

Re: Get RGBA from ColorRequester?

Post by bbanelli »

Keya wrote:

Code: Select all

color24.l = RGB($11,$22,$33)        ;11 22 33 00  \ 
color32.l = RGBA($11,$22,$33,$FF)   ;11 22 33 FF  / ShowMemory(@colorn,4)
therefore:

Code: Select all

color32 = color24 | $FF000000       ;FF=opaque - 0=transparent
:)
Thx for the tip, Keya, seems to be working great! :)

BTW, why can't I load this particular font to Vector library? http://www.fontfabric.com/code-free-font-3/ Same thing is for Trajan Pro, Charlemagne Std and many other Windows fonts... Fonts get loaded properly but simply won't be printed at all.
"If you lie to the compiler, it will get its revenge."
Henry Spencer
https://www.pci-z.com/
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Get RGBA from ColorRequester?

Post by wilbert »

bbanelli wrote:BTW, why can't I load this particular font to Vector library?
It think that the Vector library maybe currently only supports ttf fonts and not otf fonts.
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
bbanelli
Enthusiast
Enthusiast
Posts: 543
Joined: Tue May 28, 2013 10:51 pm
Location: Europe
Contact:

Re: Get RGBA from ColorRequester?

Post by bbanelli »

wilbert wrote:
bbanelli wrote:BTW, why can't I load this particular font to Vector library?
It think that the Vector library maybe currently only supports ttf fonts and not otf fonts.
Perhaps. But that doesn't seem to be the case for mistral Regular, Lucida and some other OpenType work well.

Then I thought that maybe the fonts without "Designed for" (language) types cannot be displays. Isn't the case - no pattern there. Font embeddability makes no difference as well - some editable fonts won't display as well.

Can someone confirm that only TTF are supported? Though that would be really really bad... :( I appreciate any assistance of whatsoever!

With my best,

Bruno

Edit: after converting font to TTF with online converter, it seems to be working properly. Maybe this should be documented?
"If you lie to the compiler, it will get its revenge."
Henry Spencer
https://www.pci-z.com/
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Get RGBA from ColorRequester?

Post by srod »

Yes I agree this needs clearing up. Exactly what type of fonts can we use with the vector lib? I tried the OT font as well and can confirm your results.

Best ask Fred / Freak for clarification I reckon.
I may look like a mule, but I'm not a complete ass.
User avatar
bbanelli
Enthusiast
Enthusiast
Posts: 543
Joined: Tue May 28, 2013 10:51 pm
Location: Europe
Contact:

Re: Get RGBA from ColorRequester?

Post by bbanelli »

I have also noticed there is huge difference between drawing quality of VectorText and VectorParagraph functions. You can see examples here. Is this only me or it is a bug of a sort? Sam font, same settings, only difference is that left picture uses DrawVectorText() and right picture uses DrawVectorParagraph(). This seems to happen only on Windows, Linux version looks fine...

Code: Select all

Enumeration
  #ImageID
EndEnumeration

UsePNGImageDecoder()
UsePNGImageEncoder()
CreateImage(#ImageID, 640, 640)
If FontRequester("",0,0)
  LoadFont(100,SelectedFontName(),SelectedFontSize(),SelectedFontStyle())
Else
  End
EndIf
If StartVectorDrawing(ImageVectorOutput((#ImageID)))
  VectorFont(FontID(100), SelectedFontSize())
  VectorSourceColor(RGBA(255,255,255,255))
  MovePathCursor(0, 0)
  Text$ = "ABCDEFGH" + #CRLF$ + "IJKLMNOP" + #CRLF$ +  "RSTUVZ" + #CRLF$ + "čćžšđČĆŽĐ"
        DrawVectorText(Text$)
;   DrawVectorParagraph(Text$, 640, 640, #PB_VectorParagraph_Left)
  StopVectorDrawing()
  SaveImage(#ImageID, "preview.png", #PB_ImagePlugin_PNG, #PB_Ignore, 32)
EndIf
Edit: I've also discovered that CODE font (from the link I've posted above) works without a problem on Linux.

So, it it safe to conclude that VectorParagraph and inability to properly load some fonts should be reported as Windows vector library bugs?
"If you lie to the compiler, it will get its revenge."
Henry Spencer
https://www.pci-z.com/
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Get RGBA from ColorRequester?

Post by srod »

I can't see much difference with your images... but I can when I run your program. DrawVectorParagraph() seems sharper.
I may look like a mule, but I'm not a complete ass.
User avatar
bbanelli
Enthusiast
Enthusiast
Posts: 543
Joined: Tue May 28, 2013 10:51 pm
Location: Europe
Contact:

Re: Get RGBA from ColorRequester?

Post by bbanelli »

srod wrote:I can't see much difference with your images... but I can when I run your program. DrawVectorParagraph() seems sharper.
Zoom in and check the curves. It's like those with DrawVectorParagraph() are not anti-aliased or something...
"If you lie to the compiler, it will get its revenge."
Henry Spencer
https://www.pci-z.com/
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Get RGBA from ColorRequester?

Post by srod »

Got it yes.

I seem to recall similar issues with alpha blended text with the 2d drawing lib and am not sure that was ever fixed? Might be wrong though.
I may look like a mule, but I'm not a complete ass.
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: Get RGBA from ColorRequester?

Post by Keya »

DrawVectorParagraph() vs DrawVectorText(), Arial Bold 16 @ Win32, zoomed in. Interesting differences! They both beat DrawText() though :D
Image
User avatar
heartbone
Addict
Addict
Posts: 1058
Joined: Fri Apr 12, 2013 1:55 pm
Location: just outside of Ferguson

Re: Get RGBA from ColorRequester?

Post by heartbone »

Keya wrote:DrawVectorParagraph() vs DrawVectorText(), Arial Bold 16 @ Win32, zoomed in. Interesting differences! They both beat DrawText() though :D
Image
The text on the left looks suspiciously like Microsoft® ClearType technology.
It might prove interesting to check for the differences in Linux, or turn off the functionality in Windows®.
Keep it BASIC.
User avatar
DoubleDutch
Addict
Addict
Posts: 3219
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Re: Get RGBA from ColorRequester?

Post by DoubleDutch »

Yes, the colour being added looks like it is cleartype. Doesn't look good if printed as it adds colour to the edges of fonts.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
Michael Vogel
Addict
Addict
Posts: 2680
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Get RGBA from ColorRequester?

Post by Michael Vogel »

Okay, drifting a little bit away from the topic - but I wouldn't say, windows is the (only) reason for the color effects above, Purebasic changed it's behaviour to draw text somewhen (I believe it was between version 4.31 and 4.61 or so). Before that, I did never see such issues.

Code: Select all

OpenWindow(0,0,0,480,200,"")
CreateImage(0,480,200,32)
LoadFont(0,"Arial",-60)
StartDrawing(ImageOutput(0))
Box(0,0,240,200,#White)
Title.s="Test Hanburg"
DrawingMode(#PB_2DDrawing_AlphaBlend);  : (
;DrawingMode(#PB_2DDrawing_Default);    : )
DrawingFont(FontID(0))
DrawText(20,10,Title,$ff000000,$ffffffff)
DrawText(20,100,Title,$ffffffff,$ff000000)
StopDrawing()
ImageGadget(0,0,0,0,0,ImageID(0))
HideWindow(0,0)

Repeat
	Event=WaitWindowEvent()
	If Event=#WM_LBUTTONDOWN
		SendMessage_(WindowID(0),#WM_NCLBUTTONDOWN,#HTCAPTION,0)
	EndIf
Until Event=#PB_Event_CloseWindow Or  Event=#WM_CHAR
User avatar
heartbone
Addict
Addict
Posts: 1058
Joined: Fri Apr 12, 2013 1:55 pm
Location: just outside of Ferguson

Re: Get RGBA from ColorRequester?

Post by heartbone »

Michael Vogel wrote:Okay, drifting a little bit away from the topic - but I wouldn't say, windows is the (only) reason for the color effects above, Purebasic changed it's behaviour to draw text somewhen (I believe it was between version 4.31 and 4.61 or so). Before that, I did never see such issues.
Good demo. What's up with the -60 point size?

Those color artifacts that you see are 100% the result of Microsoft® ClearType technology.
It's supposed to work best with a white background, but your demo indicates otherwise for larger sized fonts.
Turn off ClearType, and the produced bitmaps are all grayscale.
I'm quite sure that when I reboot to Linux and run your code, the produced bitmaps will be grayscale.

It looks as if the application can have control over the font rendering, whether ClearType is used or not.

"There are many examples where applications decide one way or another to use rendering other than the system default—just as applications that choose to use different fonts, colors, sizes, or other text attributes. The most typical example is in applications that wish to have reproducible layout and flow of documents. By being specific about which way to render text, the applications can be certain of how text will flow across different PCs. Another common example, as mentioned above, is Print Preview where the ability to properly render representations of higher resolution output, particularly for small text sizes, is much improved. We recognize that for some it is counter-intuitive that an aspect viewed as a “display” property is something that applications can choose to “over-ride”. We’ve designed rendering so that the default case is to respect the setting, but applications, including Windows itself, might have elements that require explicit rendering techniques.

Although each application can make the choice on a per-font basis of which rendering to use, the majority of applications choose the default rendering. Therefore, making the decision to change the default for Windows Vista was not taken lightly. The trends in the hardware displays were strongly showing a rapid movement from CRTs to LCD-based displays as we have shown in earlier blog posts based on the Windows XP and Windows Vista real-world telemetry. Even though there were still CRTs in use, feedback from Windows XP customers was positive on the quality of ClearType rendering on CRTs. After we made the choice, the feedback on the decision to enable ClearType as the default for Windows Vista was overwhelmingly positive."


A flag into LoadFont()? DrawText()?
Keep it BASIC.
Post Reply