[cairo] Font metrics under font transformations

Bill Spitzak spitzak at d2.com
Thu Jan 13 11:35:39 PST 2005



Gustavo J. A. M. Carneiro wrote:

>   OK.  This discussion is becoming way too complicated for me to follow,
> so let me just give my opinion before a 'monster' is created.
> 
>   I think most users don't want metrics to be affected by the CTM.  And
> they don't want vectorial metrics either.  My ideal API would be one
> that returned font metrics such that one could easily draw a bounding
> box around a label without knowing or caring about any transformation
> matrices in effect at the moment.

I fully agree, and I want to try my proposal again. My proposal has 
these advantages which seem to exactly match what is being requested in 
all these messages:

   The "distance between letters" is only 1 number and not a vector.

   Everything is reported in user space.

   Vertical text is handled without any extra interface

Here is the proposal. I drew some pictures of it at

   http://mysite.verizon.net/spitzak/cairo_text.html

however it appears people were confused by my diagram. In the diagram I 
rotated the CTM as well as the font matrix so the letters remained 
upright. It may be more clear if you instead pretended the three lines 
of text were all horizontal, with the "x_advance->" labels all 
horizontal and parallel.

The proposal is this:

The glyph metrics are returned in user space. Thus the program using 
them can be completely unaware of the CTM or the font matrix. The 
returned values are:

   The "x_advance". After drawing a glyph at x,y, drawing the next glyph 
at x+x_advance, y will produce the recommended glyph spacing. THERE IS 
NO Y!!! If you rotate the font matrix the glyphs are drawn "tilted" but 
still in a horizontal line. If you want a tilted baseline you should 
rotate the CTM and leave the font matrix un-rotated. This value is the 
obvious value for non-rotated font matrix. If you rotate the font matrix 
90 degrees it should be the vertical escapement. Intermediate rotations 
produce some intermediate value.

   The "glyph extent" box. This is *FOUR* numbers describing the four 
edges of a rectangle parallel to the user's xy axis that surrounds the 
glyph (ideally the *minimum* box but this is not guaranteed).

   The "ascent" and "descent". These are two numbers and they describe 
two vertical (in user space) vectors (the x coordinate is zero). People 
assign all kinds of meaning to these, but the only real fact is that if 
you have a box that is H tall in y, then putting the origin at (h-a+d)/2 
from the bottom edge will make the font look centered. If the font 
matrix is rotated 90 degrees these probably become equal as the letters 
will be centered about the origin.

   The "line spacing". This is one number that describes a minimum 
distance in Y to space the origins apart to draw parallel rows of 
glyphs. The calling program will know whether to add or subtract this 
from Y. This value would probably be the length of the vector (0,1) 
transformed by the font matrix, though for a very narrow font and 90 
degree rotation of the matrix perhaps it becomes smaller?



More information about the cairo mailing list