Microsoft KB Archive/108073
PSS ID Number: 108073
Article Last Modified on 10/29/2003
The information in this article applies to:
- Microsoft Visual Basic Standard Edition for Windows 3.0
- Microsoft Visual Basic Professional Edition for Windows 3.0
This article was previously published under Q108073
When you set the FontSize property of the Printer object in Visual Basic, the font size you get may differ from the size you requested. This behavior occurs with both Postscript printer fonts and Truetype fonts.
This behavior occurs because Windows doesn't store the requested point size. Instead, Windows stores the closest character cell height that is supported on the current printer device. The character cell height is rounded to an integer number of pixels (dots). Rounding is necessary because Windows doesn't support a fractional device unit such as half a dot (pixel).
This behavior is by design.
As an example, if your printer prints at 96 dots per inch (DPI) and you request a 10 point font, Windows creates a logical printer font that is exactly 13 dots high:
13 dots = CInt( (10 points * 96 DPI) / (72 points per inch) )
The above CInt function rounds to the nearest integer. The conversion depends on the DPI resolution of your printer.
When you set the FontSize property to 10 points, the FontSize will actually be set to 9.75 points, which is the nearest point size the printer can support at 96 DPI:
9.75 points = 13 dots * (72 points per inch) / (96 DPI)
On 300 DPI printers, the minimum interval between supported font sizes is 0.24 points. You get 0.24 points per dot as a result of the following formula:
(72 points per inch) / (300 DPI)
On 600 DPI printers, such as with an HP LaserJet 4 driver, supported font sizes are at intervals of 0.12 points.
In typesetting, a point is 1/72 of an inch. The height of fonts is usually expressed in points.
Windows automatically maps the requested font or font size to the nearest one supported by the screen or printer device if that font or size does not exist on that device.
Steps to Reproduce Behavior
As an example, the Hewlett-Packard (HP) LaserJet with the HP PostScript cartridge supports point sizes down to a resolution of 0.25 point. In Visual Basic, you can set the Printer.FontSize property to a desired point size. You can set the Printer.FontName property to the PostScript font. However, the Printer.FontSize property displays font sizes at 0.24 point intervals instead of 0.25 points. You get font sizes such as 9.6, 9.84, 10.08, 10.32, 10.56, 10.8, 11.04, and so forth. Setting the font size to 11.0 points actually gives you a font with 10.8 points.
The following steps reproduce this behavior:
- In the Windows Control Panel, select a printer that uses a 300 DPI driver, such as on the HP LaserJet IIIsi. Printers with different DPI settings will return fonts in different increments.
- Start a new project in Visual Basic. Form1 is created by default.
Add the following to the Form Load event procedure:
Sub Form_Load () For j = 9 To 12 Step .25 Printer.FontSize = j 'Set printer font size in increments of .25 Debug.Print Printer.FontSize Next End Sub
- Start the program (or press F5). Choose Debug from the Window menu. Although you requested fonts in increments of 0.25 points, you instead get fonts in increments of 0.24 points: 9.36, 9.6, 9.84, 10.08, 10.32, 10.56, 10.8, 11.04, 11.28, 11.52, 12
Additional query words: 3.00 H-P laser jet HPLJ PS Apple LaserWriter
Keywords: kbcode kbprb kbprint KB108073
Technology: kbAudDeveloper kbVB300 kbVB300Search kbVBSearch kbZNotKeyword2 kbZNotKeyword6