No announcement yet.

Converting Font Size : lfWeight and lfHeight

  • Filter
  • Time
  • Show
Clear All
new posts

  • Converting Font Size : lfWeight and lfHeight

    Me again!, gotta love this forum, I appreciate everyones help!

    I'm wondering if lfHeight and Font Size are the same number? Or I'm wondering if FontSize is some sort've combination of Font Height and Weight, and I was always wondering, I can never seem to get my fonts to match (look-like) those of fonts generated in VB, or DELPHI, or even Notepad for that matter, mine always seem slightly different. I was also wondering if there is some default lfWidth to be used if it is indeed not related to the Font Size attribute. Anywho, a few rambling questions I'd love have answered by the guru's who post and moderate this board.



  • #2
    Matt --

    Font Size is kind of an inexact term. As far as I know there is no "official definition" and different programs use it differently. So getting results that are consistent with another program would require that you figure out what they mean by Font Size.

    Perhaps this will help. It is from the Win32.HLP file...


    Specifies the height, in logical units, of the font's character cell or character. The character height value (also known as the em height) is the character cell height value minus the internal-leading value. The font mapper interprets the value specified in lfHeight in the following manner:

    > 0 The font mapper transforms this value into device units and matches it against the cell height of the available fonts.

    0 The font mapper uses a default height value when it searches for a match.

    < 0 The font mapper transforms this value into device units and matches its absolute value against the character height of the available fonts.

    For all height comparisons, the font mapper looks for the largest font that does not exceed the requested size.

    -- Eric

    Perfect Sync Development Tools
    Perfect Sync Web Site
    Contact Us: mailto:[email protected][email protected]</A>

    [This message has been edited by Eric Pearson (edited March 10, 2001).]
    "Not my circus, not my monkeys."


    • #3

      The font height and Font size (Point size) are not the same thing.

      Here is how you calculate the Font height using a Font Point Size :

      FUNCTION FontHeight(BYVAL PointSize&) AS LONG
      hDC = GetDC(%HWND_DESKTOP)
      V&=GetDeviceCaps(hDC, %LOGPIXELSY)
      ReleaseDC %HWND_DESKTOP, hDC
      FUNCTION=-MulDiv(PointSize&, V&, 72) 
      The code above is the proper way to calculate the font height based
      on a Point size. By using GetDeviceCaps the font will be autosized
      based on the end users system wide font setting (Small Fonts/ Large Fonts).

      Microsoft recommends using the MulDiv function (API) to get the right

      Chris Boss
      Computer Workshop
      Developer of "EZGUI"