Skip to content

Understanding Windows Fonts

Before discussing font usage in DataFlex, we need to understand how Windows fonts work. Fonts in Windows can be confusing, as they encompass both pre-computer and Windows legacy behaviors. This section provides information pertinent to DataFlex usage.

Fonts are defined by setting a typeface, a font size, and other attributes such as weight, italics, and underline. While most of these attributes require no explanation, the size attribute does.

Points and LogicalFonts

A typical measurement for font size is points. Point height determines the height of a font in points. Points are an old pre-computer typesetting term, where a point is 1/72 of an inch. Although computers adopted the term points, it now represents a logical inch where the actual size of an inch changes based on your display and zoom factors. What is important to understand is that a point is a common and consistent measurement that can be used on any display at any DPI (Dots Per Inch) level. In other words, the point measurement scales.

You generally do not set the font point width. When you set the height of a font, you want Windows to set the appropriate width for you.

Internally, Windows does not use points to store font size information. It uses a different measurement called a LogicalFont, as defined in a LOGFONT struct (See LOGFONT Documentation for more about this). The relationship between point height and LogicalFont height is:

LogicalFontHeight = -PointSize * LogicalPixelsPerInch / 72

Or, in Windows-speak:

lfHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72)

LogicalPixelsPerInch is determined by your display and your DPI setting. Typical values are 96 (normal), 120 (medium), and 144 (larger). As you can see from the formula, the LogicalFont height is dependent on your computer display. Therefore, you would not want to directly set font sizes in LogicalFont units. Instead, you want to use Point units and allow your software to apply this conversion to LogicalFonts.

Just to be complete, it should be noted that Windows allows you to store two different kinds of LogicalFont values, which are distinguished by being positive or negative. Each defines height a little differently (cell vs. character). There is probably some interesting history here, but it is generally recommended that you use the negative value.

Finally, note that LogicalFont height is the font height you are requesting. The actual font height may differ based on the ability of that font to display at the requested height. When the LogicalFont is converted to a PhysicalFont, it will set the height as close as it can to the requested height. Not all fonts are created equal. Some fonts, like Windows Vista’s and 7’s Segoe UI, handle just about any font height very well. Other older fonts, like MS Sans Serif, are less flexible.

Much of this is provided as background information. The takeaways are:

  • You want to use font point height because it is scalable.
  • Point height is converted to a LogicalFont height, which is mysterious, internal, and of little concern to you.
  • You only need to set the height, allowing Windows to provide the proper width.

See Also