Understanding Windows Fonts

Before talking about font usage in DataFlex, we need to discuss how Windows fonts work. Fonts in Windows can be confusing, as it contains both pre-computer and Windows legacy behaviors.  This section provides just the information that pertains 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 points term, 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 http://msdn.microsoft.com/en-us/library/dd145037%28v=vs.85%29.aspx 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 actually 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 be different 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 take away is:

 

See Also

Understanding Fonts in DataFlex

How DataFlex Handles Fonts

How to Use Fonts in DataFlex