How to determine the BaseLine of a FormattedText object?

Answered How to determine the BaseLine of a FormattedText object?

  • Friday, May 11, 2012 7:35 PM
     
     

    For the internal logics of a custom control, I would like to know how the BaseLine property of a FortmattedText object depends on the FontSize, the FontFamily.LineSpacing and the LineHeight properties. Is it possible to give a general formula for that?

    thanks,
    Rutger.


    Rutger Koperdraad.

All Replies

  • Saturday, May 12, 2012 1:02 PM
     
     

    The Baseline property is the distance from the
    top of the font characters to the baseline as a fraction of the font size. For a
    FontFamily object based on Times New Roman, for
    example, the Baseline property is approximately
    0.91. Multiply that by the font size of 144 and you get 131.

    The FontFamily class also includes a property
    named LineSpacing, which is the suggested value to use for
    spacing successive lines of text as a fraction of the font size. LineSpacing is typically greater than 1 because the
    em size of a font is the approximate distance between the tops of the ascenders
    and the bottom of the descenders. Line spacing must also account for capital
    letters than contain diacritical marks.

    Applications = Code + Markup: A Guide to the
    Microsoft® Windows® Presentation Foundation

    By Charles Petzold

    Chapter 29

    • Proposed As Answer by Xperiandri Saturday, May 12, 2012 1:04 PM
    • Unproposed As Answer by cucucucu Monday, May 21, 2012 10:23 PM
    •  
  • Monday, May 21, 2012 10:33 PM
     
     Answered

    Thanks, Xperiandri.

    Actually, I found the precise formulas after some trial and error. If the LineHeight property of the FormattedText object is not set, the BaseLine property is determined by the font size and the BaseLine property of the font family

           FormattedText.BaseLine = FontFamily.BaseLine * FontSize

    If the LineHeight property of the FormattedText is set, the formula changes to

           FormattedText.BaseLine = FontFamily.BaseLine * LineHeight / FontFamily.LineSpacing

    The first formula can be derived from the second by substituting the default line height (FontFamily.LineSpacing * FontSize).


    Rutger Koperdraad.



    • Marked As Answer by cucucucu Monday, May 21, 2012 10:33 PM
    • Edited by cucucucu Monday, May 21, 2012 10:35 PM Spelling errors
    •