Announcement

Collapse
No announcement yet.

Converting Font Size : lfWeight and lfHeight

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Chris Boss
    replied
    Matt;

    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 :

    Code:
    FUNCTION FontHeight(BYVAL PointSize&) AS LONG
    hDC = GetDC(%HWND_DESKTOP)
    V&=GetDeviceCaps(hDC, %LOGPIXELSY)
    ReleaseDC %HWND_DESKTOP, hDC
    FUNCTION=-MulDiv(PointSize&, V&, 72) 
    END FUNCTION
    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
    size.




    ------------------

    Leave a comment:


  • Eric Pearson
    replied
    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...

    lfHeight

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

    Leave a comment:


  • Matt Grace
    Guest started a topic Converting Font Size : lfWeight and lfHeight

    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.

    Thanks!

    ------------------
Working...
X