Here's the problem. A TFont object is saved (streamed to a file) on a 96 DPI resolution with Size
property set to 9pt. Then DPI is changed to 192 and when object is deserialized, its Size
property value becomes 5pt.
Environment: app is a VCL forms app, marked as DPI-aware ("true/PM"). Form's Scaled property does not affect the behavior as TFont object is being saved/loaded outside of form's object, using WriteComponent
/ReadRootComponent
functions.
Screenshots to illustrate the problem using test app. The app merely saves TFont to a file and Load button reads it back and shows the loaded font's size/height in a memo.
Screenshot 1: program started on 96dpi system, font is Tahoma 8pt, saved to a file and loaded. Everything's fine.
Serialized font is saved in a file:
object TTest
F.Charset = DEFAULT_CHARSET
F.Color = clWindowText
F.Height = -11
F.Name = 'Tahoma'
F.Style = []
end
Screesnhot 2: started on 192dpi system, loading the serialized font, and its size becomes 4pt.
Delphi saves the Height property, and Size is being calculated based on Height, resulting in smaller fonts...
Is there a way, instead of manually scaling the size (NewHeight = Height * SystemDPI / 96), to make Delphi preserve the "pt" font size regardless of DPI setting? I feel that I'm missing something here...