1

Having recently posetd a question about retrieving the user's font settings, like 96 or 120 dpi, several SO gurus told me to use dpiX and dpiY from any graphic object.

But does the dpi relates to the screen size (X / Y) or the font size (X only available) ?

In other words, can I be certain that dpiX = dpiY in all cases?

Otherwise, the new font would look stretched, wouldn't it?

For instance what if dpiX = 96 and dpiY = 60 ???

Didier Levy
  • 3,393
  • 9
  • 35
  • 57

1 Answers1

0

If your text is aligned with the horizontal or vertical axis, then you use the DPI for the other axis to specify the height. When the font is instantiated, it will take the other dimension into account.

For example, if you want normally oriented text, then you compute the pixel height in terms of the vertical DPI:

lf.lfHeight = -::MulDiv(point_size, ::GetSysMetrics(hdc, LOGPIXELSY), 72);

If your text is rotated 90 degrees, then you'd use LOGPIXELSX instead of LOGPIXELSY.

That being said, I've never seen a Windows display for which the DPI wasn't the same in both directions. I have seen them differ on some printers, and the drivers handle this inconsistently, which led to this unanswered question.

Community
  • 1
  • 1
Adrian McCarthy
  • 45,555
  • 16
  • 123
  • 175