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:
procedure TcaFontSelecter.InitSelectedFontProperties;
var
FontData: TFontData;
PPI: Integer;
begin
FontData := GetFontData(FLabel.Font.Handle);
PPI := Forms.Screen.PixelsPerInch;
FontData.Height := -FontData.Height; // GetFontData returns Height as a +ve value
FSelectedFont.Name := FontData.Name;
FSelectedFont.Size := -MulDiv(FontData.Height, 72, PPI) // This should give Size as a +ve value
end;
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