How do you detect "Large Fonts"?

Raymond Chen

Raymond

When people ask, “How do I detect Large Fonts”, they aren’t
really asking how to detect Large Fonts specifically.
Rather, Large Fonts is just the most common manifestation
of “unusual DPI”.

Windows uses a nominal DPI of 96 pixels per inch.
In other words, if Windows wants to draw a line that is one inch
long, it draws 96 pixels. Of course, the physical length of this
line depends on your screen resolution and the size of your monitor.
The value of 96 is merely nominal.

You can change this DPI setting from the Display control panel,
either by choosing Large Fonts, or by choosing a custom font size.
Standard size is 96DPI. Large is 120DPI. Custom is, well, custom.

DPI higher than 96 will become more and more prevalent as LCD technology
improves.

Programs can query the DPI setting by asking GetDeviceCaps for
the LOGPIXELSX of the screen DC.

int GetScreenDPI()
{
  HDC hdcScreen = GetDC(NULL);
  int iDPI = -1; // assume failure
  if (hdcScreen) {
    iDPI = GetDeviceCaps(hdcScreen, LOGPIXELSX);
    ReleaseDC(NULL, hdcScreen);
  }
  return iDPI;
}

The code above assumes that pixels are square, which is true
of most modern devices. (You can choose an odd screen resolution
and get non-square pixels, but most people avoid such resolutions.)
Back in the old days, there were
many devices with non-square pixels.
For example, the EGA video adapter had pixels which were 1.33 times
as tall as they were wide.

For nonsquare-pixel devices, the values of the LOGPIXELSX and
LOGPIXELSY metrics will be different. On an EGA, if the value
of the LOGPIXELSX metric were 96, then the LOGPIXELSY metric
would be 72, since there are only 72 vertical pixels per inch.
Similarly, the ASPECTX, ASPECTY and ASPECTXY values for
nonsquare-pixel devices will be somewhat interesting as well,
as this diagram demonstrates:

36
27
45

if (document.namespaces) {
document.namespaces.add(‘v’, ‘urn:schemas-microsoft-com:vml’, “#default#VML”);
for (var i = 0; i < vmlContent.length; i++) vmlContent[i].style.display = "block";
if (vmlContent.style) vmlContent.style.display = "block";
for (var i = 0; i < svgContent.length; i++) svgContent[i].style.display = "none";
if (svgContent.style) svgContent.style.display = "none";
}

36
27
45

The ASPECTX is 27 and the ASPECTY is 36, representing the 4:3 ratio
of vertical to horizontal, and the ASPECTXY is 45, representing the
hypotenuse.

Raymond Chen
Raymond Chen

Follow Raymond   

0 comments

Comments are closed.