Baseline Shifts in Cell When Character Italicized

Last reviewed: January 5, 1995
Article ID: Q72460
The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) for Windows versions 3.0 and 3.1

NOTE: With TrueType fonts in Windows 3.1, this process described below is not necessary. An application should do a version check to determine if it is running under version 3.0 and perform this process only if the application is indeed running under Windows 3.0 or if the application is using non TrueType fonts in Windows 3.1.

SUMMARY

When a font is italicized under Windows version 3.0, the dimensions of the character cells change because the descender of the character may require more space at the left edge of the character cell.

Because the character cell is larger, the relative position of the baseline of the character within the cell changes. The baseline itself is not affected, but when a character is drawn italic and nonitalic with the TextOut() function at the same x coordinate, the baseline of the italic font is shifted a few pixels to the right.

To account for this shift, calculate the slope of the font -- ascent divided by overhang -- after italicization. Using this slope, the number of pixels by which the character cell was expanded left is equal to descent divided by slope, or (descent times overhang) divided by ascent. This value can be subtracted from the x coordinate in the TextOut() call to align the baselines.

MORE INFORMATION

Consider the character "f". In a normal character cell, it would appear as:

          ^ ........
          | ........
          | ...xx...
          | ..x..x..
    Ascent| ..x.....
          | ..xx....
          | ..x.....
          | ..x.....
          | ..x.....
          v .xxx....<-baseline
   Descent^ ........
          v ........

When italicized, the descent is shifted to the left and the ascent is shifted to the right, along a line of constant slope equal to the ascent divided by the overhang:

          ^ ............
          | ............
          | .......xx...
          | ......x..x..
    Ascent| .....x......
          | .....xx.....
          | ....x.......
          | ....x.......
          | ...x........
          v ..xxx.......<-baseline
   Descent^ ............
          v ............
                     <->
                      Overhang

Because the descent of the character is shifted left according to the slope of the line, this particular character cell has been expanded one pixel left, which has the effect of shifting the baseline in the character cell one pixel right.

Since the overhang represents the amount the ascent of the character is shifted right in the cell, the corresponding shift of the descent can be calculated and can be called the "underhang":

                descent * overhang
   underhang = --------------------
                      ascent

When calling the TextOut() function, use the normal x-coordinate where the text should be drawn, but subtract the underhang. This places the baseline of the character exactly where it would be if the character were not italic.


Additional reference words: 3.00 3.10
KBCategory: kbprg
KBSubcategory: GdiFnt


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: January 5, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.