Page 1 of 1
Different font size Mac OS <> Windows
Posted: Mon Feb 24, 2014 7:21 pm
by Lebostein
check this code:
Code: Select all
LoadFont(0, "Arial", 48, #PB_Font_HighQuality)
LoadFont(1, "Comic Sans MS", 32, #PB_Font_HighQuality)
CreateImage(0, 500, 200, 24, $FFFFFF)
StartDrawing(ImageOutput(0))
DrawingMode(#PB_2DDrawing_Transparent)
DrawingFont(FontID(0))
DrawText(0, 0, "Arial 48 Mac!", $FF0000)
DrawingFont(FontID(1))
DrawText(0, 80, "Comic Sans MS 32 Mac!", $0000FF)
StopDrawing()
UsePNGImageEncoder()
SaveImage(0, "test_font_mac.png", #PB_ImagePlugin_PNG)
Why is the font size of 48 pt different?

Re: Different font size Mac OS <> Windows
Posted: Mon Feb 24, 2014 7:28 pm
by ts-soft
Re: Different font size Mac OS <> Windows
Posted: Mon Feb 24, 2014 7:53 pm
by Danilo
Code: Select all
LoadFont(0, "Arial", 48, #PB_Font_HighQuality)
CreateImage(0, 400, 100, 24, $FFFFFF)
StartDrawing(ImageOutput(0))
DrawingFont(FontID(0))
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(0, 0, "Arial 48!", $FF0000)
Debug TextHeight("X")
StopDrawing()
ShowLibraryViewer("Image",0)
CallDebugger
;UsePNGImageEncoder()
;SaveImage(0, "test_mac.png", #PB_ImagePlugin_PNG)
It outputs the TextHeight()
- Windows: 72 pixels
- Mac OS X: 54 pixels
Same display and resolution on Windows and Mac OS X: 2560x1440 @ 27",
so displays have same DPI.
Re: Different font size Mac OS <> Windows
Posted: Mon Feb 24, 2014 7:55 pm
by Lebostein
Yes! This is exactly my question! There is no length scale in this system... pt is a length unit! In PureBasic I see no connection to the pixel size.
Input: pt respectively mm (length)
Output: pixel
How I can find out the conversion factor (between length == inch and pixel == dots) of my system? The screen resolution (dots per "paper size") is the same on Windows and Mac....
Re: Different font size Mac OS <> Windows
Posted: Mon Feb 24, 2014 10:39 pm
by glomph
This works good enough for me:
Code: Select all
EnableExplicit
Global fontgrund
Global y
Global event
Procedure fntsetzen()
Protected fo$,dpi.f,font_with.f
; stopdrawing
dpi =1.70;
CompilerIf #PB_Compiler_OS =#PB_OS_Windows
dpi =GetDeviceCaps_(GetDC_(GetDesktopWindow_()), 88)
dpi =120 / dpi
CompilerEndIf
CompilerIf #PB_Compiler_OS =#PB_OS_MacOS
fo$ ="Arial"
CompilerElse
fo$ ="Arial"
CompilerEndIf
font_with=40.01
LoadFont(0, fo$, IntQ(font_with*dpi)) ; number To play With
; do startdrawing on again
EndProcedure
If OpenWindow(0, 100, 200, 300, 200, "Drawtext")
If CreateImage(0, 300, 200)
fntsetzen()
If StartDrawing(ImageOutput(0))
Box(0,0,300,200,$FFFFFF)
DrawingFont(FontID(fontgrund))
FrontColor($000000)
For y=10 To 190 Step 10
Line(0,y,300,1,#Gray)
Next
DrawingMode(#PB_2DDrawing_Default)
BackColor($FFFFFF)
DrawText(10,50,"Test")
StopDrawing()
EndIf
EndIf
ImageGadget(0, 0, 0, 0, 0, ImageID(0))
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow ;window + drawing handling from pb example
EndIf
Re: Different font size Mac OS <> Windows
Posted: Mon Feb 24, 2014 10:46 pm
by ts-soft
Danilo wrote:Same display and resolution on Windows and Mac OS X: 2560x1440 @ 27",
so displays have same DPI.
Have the same PPI, not DPI

Re: Different font size Mac OS <> Windows
Posted: Mon Feb 24, 2014 10:58 pm
by glomph
thanks
Re: Different font size Mac OS <> Windows
Posted: Tue Feb 25, 2014 8:29 am
by Danilo
Actually this gives good results (Mac OS X and Windows only - may be completely different on Linux):
Code: Select all
Procedure.d ScreenPoint2PixelsY(points.d)
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
Protected hDC = GetDC_( GetDesktopWindow_() )
Protected dpiY = GetDeviceCaps_(hDC, #LOGPIXELSY)
ReleaseDC_(GetDesktopWindow_(), hDC)
ProcedureReturn (72.0 / dpiY) * points
CompilerElse
ProcedureReturn points
CompilerEndIf
EndProcedure
LoadFont(0, "Arial", ScreenPoint2PixelsY(48), #PB_Font_HighQuality)
CreateImage(0, 400, 100, 24, $FFFFFF)
StartDrawing(ImageOutput(0))
DrawingFont(FontID(0))
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(0, 0, "Arial 48!", $FF0000)
Debug TextHeight("X")
StopDrawing()
ShowLibraryViewer("Image",0)
CallDebugger
;UsePNGImageEncoder()
;SaveImage(0, "test_mac.png", #PB_ImagePlugin_PNG)
Output for size 48:
- Windows: 55
- Mac: 54
Output for size 148:
- Windows: 165
- Mac: 166
On Windows the font size seems to be in Windows "Points" (device independent).
On Mac OS X the font size seems to be in plain Pixels.
@ts-soft:
On a screen a 'Dot' means a pixel, so it is the same. My screen can display 96 pixels per inch (PPI), and
my printer can display 1200 dots per inch (DPI). It is the same thing, how many real "points" is a device
able to display. Display is 96 DPI/PPI, Printer is 1200 DPI/PPI.
PureBasic's LoadFont() size is indeed very much different on different platforms, and that's not good.
In my opinion it would be better if LoadFont() would always take accurate pixels high, and functions like
GetDPIX() and GetDPIY() would be provided. In this case we would just know the DPI for screens, sprites,
printers, etc...
Re: Different font size Mac OS <> Windows
Posted: Fri Feb 28, 2014 10:46 am
by Lebostein
Danilo wrote:In my opinion it would be better if LoadFont() would always take accurate pixels high, and functions like
GetDPIX() and GetDPIY() would be provided. In this case we would just know the DPI for screens, sprites,
printers, etc...
That is my opinion too. The whole 2DDrawing library is based on pixels. It would be great to load fonts in pixel heights.
One problem could be the gadgets and the used fonts. To use fonts in gadgets, an pixel independent height should be used....
Perhaps it would be useful to have both options...
Re: Different font size Mac OS <> Windows
Posted: Tue Mar 25, 2014 2:47 pm
by Lebostein
Re: Different font size Mac OS <> Windows
Posted: Thu Feb 22, 2024 1:49 pm
by Fred
I tried to apply different fixes (scales the font automatically when doing StartDrawing(), adjust the size of the font when loading the font) but none of them a really good. When scaling automatically, it's wierd than the font is rendered bigger in an image than the one used in a different component (for example Scintilla). If the font is scaled automatically at LoadFont() it's the same issue as you don't have the same font than the one you choosed in FontRequester() for example. So I guess we will just document than font size is system dependant and needs manual adjustment to have the size size accross OS/Subsytems.
Re: Different font size Mac OS <> Windows
Posted: Thu Feb 22, 2024 9:13 pm
by mk-soft
It has always been the case that the fonts are handled differently by the system depending on the OS.
Sometimes I also suspect that the font files with the same name are different for each OS.
The note in the documentation is completely ok with me.
Re: Different font size Mac OS <> Windows
Posted: Fri Feb 23, 2024 9:53 am
by jamirokwai
Don't want to add more fuzz here, but did you try to use a custom TTF with RegisterFontFile() and check the sizes? The base fonts like Arial, Helvetica, Times, etc. may not be the same files, but different implementations as well on Linux, MacOS, Windows.
I don't code on windows anymore and do not have Linux ready, so I can't try it myself. But it would be interesting to see and know.