[Cairo] Re: [xsvg] cairo_text_extents ?

Carl Worth cworth at east.isi.edu
Wed Dec 17 19:34:38 PST 2003


On Dec 16, Bill Spitzak wrote:
 > Lovely diagram trying to show what I am thinking of for rotated text is now 
 > available here:
 > 
 > http://www.cinenet.net/~spitzak/cairo_text.html

Thanks Bill,

This does make it much easier to understand what you have been
describing. From looking at your diagram it appears that what you want
is for the font matrix to be applied to the shapes of the glyphs, but
that this matrix should *not* be applied to the advance vectors used
for the relative positioning of glyphs when calling cairo_show_text.

It occurred to me that I didn't know for sure how cairo used the CTM
and font matrix when dealing with relative placement within
cairo_show_text. So, I wrote a little program to find out. It's in CVS
at cairo-demo/png/text-rotate.c. The resulting image can be seen at:

http://cairographics.org/~cworth/download/text-rotate.png

This image shows three different means of producing rotated text. In
all three examples, the CTM is rotated to position the text. In the
second example, an inverse rotation is applied to the font matrix
before drawing the text, and in the third example, an inverse rotation
is applied to the CTM before drawing the text.

As can be seen in the image, the second and third examples produce
identical results (horizontal text). If I'm understanding the proposal
correctly, you would like to see a figure like the one you give above
for the second case, (rotated CTM and inverse rotated font matrix).

The only way I can see to get that result is if the font matrix and
CTM are applied to transform the glyphs, but the font matrix is
ignored and only the CTM is applied when computing the inter-glyph
advance vectors.

After getting the cairo result, I was curious to see if the
implementation matches PostScript behavior. So I wrote a similar
program available from:

http://cairographics.org/~cworth/download/text-rotate.ps

Aside from the fact that the default orientation of the Y-axis is
opposite that of the Y-axis in cairo, this figure shows the same
general behavior as the text-rotate program using cairo.

After thinking about this, it seems to me that it would be confusing
to ignore the font matrix when positioning glyphs within cairo_show_text
even though the font matrix is used to transform the glyphs. I would
also feel quite shaky about deviating from PostScript, (especially in
the area of text behavior where I have a healthy distrust of my own
judgment).

However, it should not be too hard to use cairo to produce a figure
exactly like the one you give above. It's just that cairo_show_text
won't do it for you. You'll have to examine the extents information
and position the text manually using cairo_show_glyphs. This should
fit in fine with the Pango plan that Owen presented earlier. As he
said, vertical text support doesn't really belong in the toy API
(cairo_show_text).

And do notice that I've been focusing on glyph positioning here. The
proposal has related implications on extents, but I'm even less
certain about how extents should be handled, (especially considering
that the current implementation in cairo seems to have bugs in the
area of text extents when faced with a non-identity font matrix).

As always, feedback is quite welcome.

-Carl





More information about the cairo mailing list