PRB: Printer.FontSize Return Value Is Not Requested Value

Last reviewed: February 18, 1996
Article ID: Q108073
The information in this article applies to:
  • Standard and Professional Editions of Microsoft Visual Basic for Windows, version 3.0

SYMPTOMS

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.

CAUSE

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).

STATUS

This behavior is by design.

MORE INFORMATION

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:

  1. 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.

  2. Start a new project in Visual Basic. Form1 is created by default.

  3. 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
    
    

  4. 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 reference words: 3.00 H-P laser jet HPLJ PS Apple LaserWriter
KBCategory: kbprint kbprg kbcode kbprb
KBSubcategory: APrgPrint


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 18, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.