freetype
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Ascender and VisualAscender and Centering Text Vertically


From: David Turner
Subject: Re: Ascender and VisualAscender and Centering Text Vertically
Date: Wed, 11 Oct 2000 17:34:06 +0200

Hi Matthew,

> 
> I'm working on an application that uses FreeType.  One component of this
> application has to draw buttons for a user interface.  The component is
> passed a string of text, a font name and a point size.
> 
> The problem I'm running into is that it has to display the text centered
> in the button, and I can't find a good generic way of doing it.
> 
> If I place the text baseline at:
> 
>    ButtonHeight/2  -  face->height/2
> 
> The text doesn't appear properly because face->height really doesn't
> have any direct relationship to the *visual* height of the character,
> which is what I need to center on.
> 
> I tried this:
> 
>    ButtonHeight/2  -  face->ascender/2
> 
> Hoping to center the ascender in the button (which is really what I
> want; that looks correct).
> 
> Unfortunately, the visual ascender of the font seems to be usually
> something shorter than face->ascender.  What I really need to determine
> (I think) is the distance from the baseline to the top of a typical
> capital letter.
> 

you're looking for something that is normally known as the "X" height.
Try loading an "X" and an "O" and see which one has the highest
control box (normally the "O" should be slightly higher, and lower,
than the "X").

> The TrueType format seems to define this as VisualAscender, but I can't
> see how to access this through the FreeType 2.0 API, and even if I could
> access it, it appears to be TrueType specific, and I need something that
> will work for all font formats that FreeType supports.
> 

The TrueType format doesn't define a "VisualAscender". All it has is:

 - "usWinAscent" and "usWinDescent" in the OS/2 table. However, many
   fonts have this field set to 0, and this doesn't correspond to a
   typical capital letter, but to the Windows "ANSI" charset.. :-(

 - the "ascender" and "descender" fields of the "head" table.
   However, these are globals, not for capitals..

 - there is also the "sTypoAscender" and "sTypoDescender" in the
   OS/2 table, but these are not reliable too and are global..

Type 1 doesn't have any field, though I've encountered a few fonts with
a "/Ascender" and "/Descender" embedded in them..

the problem is that existing font formats do not define clearly
a "typical capital" height in their global tables. You'll need to
either:

  - compute a value from a few glyphs
  - compute the exact control box of the text and use it to position your
    string within your button..

> Is this information even available in all formats?
> 
> If not, can the information be retrieved using the autohinter?  If I
> understand correctly, the autohinter has to scan the font and gather
> metrics like this anyway in order to calculate blue zones for
> autohinting.  Is this information available via the public API or can it
> be made available?
> 
the auto-hinter does automatically compute this information, though it is
not available for now. In all cases, I suggest you to not depend on it,
just in case you're using the TrueType interpreter or a native Type 1 hinter


cheers,

- David



reply via email to

[Prev in Thread] Current Thread [Next in Thread]