[cairo] Showing my ignorance about text rendering again

ecir hana ecir.hana at gmail.com
Wed Feb 24 03:24:00 PST 2010

On Wed, Feb 24, 2010 at 8:02 AM, Behdad Esfahbod <behdad at behdad.org> wrote:
> On 02/23/2010 07:26 PM, Peter Clifton wrote:
>> Hi guys,
> Hi Peter,
>> I figured someone might know the answer to this - as it will take me
>> ages to figure out from the source code...
> Always happy to help.
>> When rending text with pango-cairo, where does the inter-line spacing
>> metric come from?
> From what I remember Pango simply uses ascent+descent as line height.
>> Lets say I have a 13pt sans-serif font, lets say family "Arial". My
>> estimation (from looking at the rendering), that "something" is giving
>> about 12% leading. IE.. inter-baseline spacing is 1.12 times 13 points.
>> (When converted to appropriate world coordinates).
>> Is the "height line" coming from the font metrics, freetype, ...?
>> I know the answer to this question is probably "no", but should I expect
>> text rendered in a 13pt font to measure 13 points anywhere? (I had
>> previously believed this was the nominal designed inter-baseline
>> spacing, but that only seems true for zero leading).
>> Would one normally expect the ascent + descent of a "13 pt" font to
>> measure 13 points?
> This is one of the most confusing issues with fonts.  No one really knows what
> a "13 pt" font means.  A font designer has the final say on how large the font
> will render.

A font is the file which contains the outline data or instructions to
draw an outline. A typeface is the design of actual shape of the
outlines. A glyph is the outline of one character.

If you draw a glyph, theoretically you draw it on an infinite plate.
Pure theoretically, you are not required to follow these but in
practice everyone does: the plane is actually a square, its
coordinates are not real numbers but discrete values and the count of
such values in Postscript fonts is 1000, in TrueType 2048 and in
OpenType could be 1000 or 2048.

Such square does not have a real unit (the axises are just called
"unit"), it is called "em" (because it is based on how wide "M" is -
the widest character). Also, this "em" square" is always the same size
as the font. That is, 17pt font has 17pt big em size.

It is true, that the real "point" has not definitive length and it is
also true that the length varied in time. In practice however, 1 pt =
1/72 inch. Otherwise, all book would look differently, for more, an
quote from PDF spec:

"The length of a unit along both the x and y axes is set by the
UserUnit entry (PDF 1.6) in the page dictionary (see Table 3.27). If
that entry is not present or supported, the default value of 1 ⁄ 72
inch is used. This coordinate system is called default user space."

"Note: The default for the size of the unit in default user space (1 ⁄
72 inch) is approximately the same as a point, a unit widely used in
the printing industry. It is not exactly the same, however; there is
no universal definition of a point."

As you noticed, so far we only talked about the real size of some
weird square. That is, what a designer draws into such square (and
this what you see when you print or display the typeface) has nothing
to do with its size. Then, however, it is possible to define several
"guidelines" - among others ascender, descender, line height. It is
not required ascender + descender equals to font size but it practice
most fonts adheres to this rule. Also completely different thing is
inter-line spacing (or leading, if you want). While it is possible to
define the default line spacing in font, the application is free to
change it (if the users asks for it).

So back to you question, "Would one normally expect the ascent +
descent of a "13 pt" font to measure 13 points?" Yes, but it is bit of
tautology. It says nothing about the actual appearance of the type,
nor about the line spacing.

'This is one of the most confusing issues with fonts.  No one really
knows what a "13 pt" font means.  A font designer has the final say on
how large the font will render.'

13 pt = 0.18 inch. That's the em (square) size. That doesn't mean
however, that if you print some text the distance from highest point
of a line to lowest point will be 0.18 inch. Of course, you have the
final say how large the font will render, just note that what you
scale is actually a bit larger than the glyph.

For more, look e.g. here: ("twardoch" is right. If he says something
else than I did, he's right again)

More information about the cairo mailing list