Thread: Directwrite: Font height issues

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    54

    Directwrite: Font height issues

    I'm using Directwrite to display scrollable text in a render target, and I want to calculate how many lines of text will fit per screen.

    I've been using this code to calculate the number of lines that will fit on the RT:
    Code:
    /* pTextFormat is an IDWriteTextFormat pointer, dpi_y is the desktop's vertical dpi, and GetHeight() returns the height (in pixels) of the render target. */
    
    float size = (pTextFormat->GetFontSize()/72.0f)*dpi_y; 
    return (int)(GetHeight()/size);
    The results of the above code seem to be accurate for some fonts, but not for others, resulting in the RT "clipping" the text too early. For these other fonts, using

    Code:
    float size = pTextFormat->GetFontSize(); 
    return (int)(GetHeight()/size);
    instead seems to work.

    My problem is that I don't know how to tell which font should use which method, or why one method works for one font but not another.

    Edit:
    I'm using IDWriteTextLayouts to display the text.
    Last edited by Boxknife; 04-07-2011 at 04:45 PM. Reason: clarification

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error: expected identifier or ‘(’ before ‘{’ token
    By jpcanaverde in forum C Programming
    Replies: 66
    Last Post: 06-08-2010, 12:53 PM
  2. DirectX | Drawing text
    By gavra in forum Game Programming
    Replies: 4
    Last Post: 06-08-2009, 12:23 AM
  3. problem with my font manager
    By hannibar in forum C Programming
    Replies: 1
    Last Post: 03-07-2006, 08:03 AM
  4. char copy
    By variable in forum C Programming
    Replies: 8
    Last Post: 02-06-2005, 10:18 PM
  5. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM