Recent

Author Topic: Confusion over font size and DPI on Apple Mac  (Read 1872 times)

carl_caulkett

  • Sr. Member
  • ****
  • Posts: 306
Confusion over font size and DPI on Apple Mac
« on: July 10, 2017, 02:35:25 pm »
Hello, I'm currently writing a font selector control, and for the purposes of setting a default size value, I am using the following code:

Code: Pascal  [Select][+][-]
  1. procedure TcaFontSelecter.InitSelectedFontProperties;
  2. var
  3.   FontData: TFontData;
  4.   PPI: Integer;
  5. begin
  6.   FontData := GetFontData(FLabel.Font.Handle);
  7.   PPI := Forms.Screen.PixelsPerInch;
  8.   FontData.Height := -FontData.Height;  // GetFontData returns Height as a +ve value
  9.   FSelectedFont.Name := FontData.Name;
  10.   FSelectedFont.Size := -MulDiv(FontData.Height, 72, PPI) // This should give Size as a +ve value
  11. end;
  12.  

The weird thing is that FLabel, the source of the GetFontData call, is made visible in this component, and visually, at least, appears to have the same size font as a standard TLabel, dropped straight on the form. I would expect, therefore, for the Height as returned by GetFontData to be -13 (as noted, GetFontData is returning a +ve value), and the resultant value of FSelectedFont.Size to be 10.

For some reason, which I suspect is to do with of DPI related factors, the Height as returned by GetFontData is actually 16, giving a FSelectedFont.Size to be 12. I'm sure I read somewhere recently, that recent changes to Lazarus on the Apple Mac, mean that adjustments have to be made in order for font sizes to work properly but I didn't make a note of it.

Can anyone shed some light on this question?

Thanks,
Carl
 

« Last Edit: July 10, 2017, 02:53:32 pm by carl_caulkett »
"It builds... ship it!"

Mac Mini M1
macOS 13.6 Ventura
Lazarus 2.2.6 (release version)
FPC 3.2.2 (release version)

 

TinyPortal © 2005-2018