[vtk-developers] dancing fonts

Sebastien BARRE sebastien.barre at kitware.com
Mon Jul 22 16:08:41 EDT 2002


Hi David

At 7/22/2002 10:46 AM, David Gobbi wrote:

>If the justification is handled by the FreeType libraries themselves
>then it is best to leave things as they are.  But if the justification
>is handled inside VTK, is there an easy way to fix this so that
>Centered justification doesn't cause dynamic labels to dance around?

After some thinking, I changed the code slightly to cope with this 
"feature" :) I say feature here because there was not a bug, but a 
side-effect of the extra-precision in the new code (see below).

The bounding box that is returned by FTGL+FreeType is indeed very 
"accurate", i.e. it is the bounding box that includes the very first and 
last pixels of the text to be rendered.

Here is an example for different strings, using Courier Bold (width x height):

"0": 14 x 18
"1": 13 x 18
"7": 12 x 18
"10": 32 x 18
"11": 31 x 18
"17": 30 x 18

Note that each individual glyph (i.e. a single char) has a different width.
At this point, you might have a look at some font metrics notions:
http://freetype.sourceforge.net/freetype2/docs/glyphs/Image3.png

In a fixed-width font, the glyph-width is not constant, but the "advance 
width" is. The "advance width" is the distance between the origin of a 
glyph to the origin of the next glyph.
So basically the bbox for "17" is the "advance width" from "1" to "7", 
minus the BearingX (the distance from the origin of "1" to the first pixel 
of "1"), plus the glyph width of "7".

This leads to accurate results, but does not help you of course :) Since 
the resulting bboxes are not equal for strings that have the same length, 
the resulting text is "dancing" as soon as the delta is > 1 pixels.

I think we can get rid of this extra-precision since I've the feeling this 
"dancing" effect might be disturbing.

I changed the code so that the bbox is now the sum of the "advance widths". 
This will result in a larger BBox, thus in slightly smaller fonts since VTK 
sets the font size by trying to fit the bbox inside the area defined by the 
vtkActor2D's PositionCoordinate.

What do you think ?


--
Sebastien Barre




More information about the vtk-developers mailing list