Problems Measuring Font Height

From: Jonathan Wood (jwood_at_softcircuits.com)
Date: 12/03/04

  • Next message: Relvinian: "Re: BUG in CreateCompatibleBitmap with VC++.NET/2003"
    Date: Fri, 3 Dec 2004 13:31:22 -0700
    
    

    I am trying to figure out how high a particular font will paint.

    Here's my situation: I have an owner-drawn window and want to write some
    text in it. I measure the font like this:

    font.CreateFontIndirect(&pApp->m_lfFont);
    pOldFont = dc.SelectObject(&font);
    dc.GetTextMetrics(&tm);
    dc.SelectObject(pOldFont);
    m_dm.CharSize.cx = tm.tmAveCharWidth;
    m_dm.CharSize.cy = (tm.tmHeight + tm.tmExternalLeading);

    I then paint each row using ::ExtTextOut. After painting a row, I add
    m_dm.CharSize.cy to my X coordinate and paint the next line.

    This has worked flawlessly for many years. However, I've primarily been
    using Courier and Courier New fonts and have recently found some problems
    with some other fonts such as OCRB and others.

    The problem is that I paint the text with OPAQUE background mode (I do not
    first clear the background because that causes too much flicker) but, with
    some fonts, when I then paint the next line, there is a space between the
    lines that never gets painted. Apparently, my cy measurement above is not
    accurate for all fonts and I'm moving too far down for the next line.

    Does anyone know how to determine the height a particular font will paint,
    regardless of the font?

    Thanks for any tips.

    -- 
    Jonathan Wood
    SoftCircuits
    http://www.softcircuits.com
    Available for consulting: http://www.softcircuits.com/jwood/resume.htm
    

  • Next message: Relvinian: "Re: BUG in CreateCompatibleBitmap with VC++.NET/2003"

    Relevant Pages

    • Re: Does anyone know how to blur a font to make it barely legible?
      ... If you aren't using a font that looks blurred, ... paste multiple copies into Paint and slightly offset each ... >> Jay Freedman ... >> newsgroup so all may benefit. ...
      (microsoft.public.word.docmanagement)
    • Re: Fonts, Part 2
      ... Create your page or portion of the page with the font you want. ... Then open Paint, click Edit, select Paste and an image of the page will appear ... When you have the area you want in the Cut box, click Edit and select Cut. ...
      (microsoft.public.frontpage.client)
    • Re: Make font size to fit screen
      ... I don't think you want to compute the font size in the paint() call. ... compute all of the metrics needed for painting, ... Why recompute the metrics on every repaint? ...
      (comp.lang.java.gui)
    • Font changed in Windows Programs
      ... I am running XP Home SP2 and have noted that in WordPad and Paint the font ...
      (microsoft.public.windowsxp.general)
    • Font changed in Windows Programs
      ... I am running XP Home SP2 and have noted that in WordPad and Paint the font ...
      (microsoft.public.windowsxp.customize)