Different font size Mac OS <> Windows

Found an issue in the documentation ? Please report it here !

Moderator: Documentation Editors

Lebostein
Addict
Addict
Posts: 829
Joined: Fri Jun 11, 2004 7:07 am

Different font size Mac OS <> Windows

Post 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?

Image

Image
Last edited by Lebostein on Mon Feb 24, 2014 7:53 pm, edited 1 time in total.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Different font size Mac OS <> Windows

Post by ts-soft »

PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Different font size Mac OS <> Windows

Post 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.
Lebostein
Addict
Addict
Posts: 829
Joined: Fri Jun 11, 2004 7:07 am

Re: Different font size Mac OS <> Windows

Post 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....
User avatar
glomph
User
User
Posts: 48
Joined: Tue Apr 27, 2010 1:43 am
Location: St. Elsewhere / Germany
Contact:

Re: Different font size Mac OS <> Windows

Post 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 
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Different font size Mac OS <> Windows

Post 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 :wink:
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
glomph
User
User
Posts: 48
Joined: Tue Apr 27, 2010 1:43 am
Location: St. Elsewhere / Germany
Contact:

Re: Different font size Mac OS <> Windows

Post by glomph »

:)
thanks
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Different font size Mac OS <> Windows

Post 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...
Lebostein
Addict
Addict
Posts: 829
Joined: Fri Jun 11, 2004 7:07 am

Re: Different font size Mac OS <> Windows

Post 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...
Lebostein
Addict
Addict
Posts: 829
Joined: Fri Jun 11, 2004 7:07 am

Re: Different font size Mac OS <> Windows

Post by Lebostein »

This could be the cause of the problem:
http://www.purebasic.fr/english/viewtop ... =4&t=58853
Fred
Administrator
Administrator
Posts: 18199
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Different font size Mac OS <> Windows

Post 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.
User avatar
mk-soft
Always Here
Always Here
Posts: 6242
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Different font size Mac OS <> Windows

Post 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.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
jamirokwai
Enthusiast
Enthusiast
Posts: 798
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

Re: Different font size Mac OS <> Windows

Post 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.
Regards,
JamiroKwai
Post Reply