freetype
[Top][All Lists]
Advanced

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

Re: [ft] Right justification of text with glyphs reaching further than a


From: Peter Hunter
Subject: Re: [ft] Right justification of text with glyphs reaching further than advance
Date: Mon, 18 Feb 2013 14:17:46 +1100

Gregor Mückl wrote

>Hi!
>
>I'm having a sort of conceptual problem: text that is right-aligned by my 
>layout algorithm is overshooting the >right boundary when rendered. 
>This is bad because the last glyph in the line ends up getting visibly 
>truncated there. All glyph dimensions >used by this algorithm are provided by 
>Freetype.
>
>This problem seems to occur because of two conditions that are met:>
>
>1. using the advance of the last glyph in the line to compute the total line 
>length and therefore implicitly >the space between the second-to-last 
>character and the right edge.
>
>2. an italic font where the top parts of most glyphs reach further than the 
>advance
>
>So how would I find out the actual width of the character so that 
>right-aligning it will never lead to >truncation of the glyph?
>
>My guess is that I need some sort of bounding box, but for some reason I 
>cannot make FT_Glyph_Get_CBox return >a non-zero bounding box. Is there some 
>other way how I can obtain a control box or bounding box for a TrueType >font 
>at the current font size? Or do I need to use a different measure anyway?

The distance from the rightmost part of a character to the nominal character 
advance is called a trailing side bearing. In the case of characters from an 
italic font, this distance is often negative.
For instance capital T from italic times font might have an advance of 1139 but 
a trailing side bearing of
 -191. So the right most part of the T overhangs the advance by 191 units.
The side bearing information is available via the glyph metrics
 
        width = face->glyph->advance.x;
        leadingSideBearing   = face->glyph->metrics.horiBearingX;
        trailingSidebearing  = face->glyph->metrics.horiBearingX  + 
face->glyph->metrics.width - face->glyph->advance.x;

You may need to adjust the final character width by it's trailing side bearing 
(if negative)

Peter



reply via email to

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