[Cairo] Re: [xsvg] cairo_text_extents ?

Carl Worth cworth at east.isi.edu
Tue Dec 16 07:49:55 PST 2003


On Nov 26, John Ellson wrote:
 > It is true that the left_side_bearing, right_side_bearing, ascent,
 > and descent describe a bounding box.  However the terms are
 > clearly with reference to the origin of the (first) character.
 > x,y,width,height kind of looses that for me.

I find that argument somewhat compelling. I would like the names to
indicate the fact that the metrics are with reference to the origin of
the first character. So, I'm leaning toward x_bearing,y_bearing rather
than the x,y that I proposed before.

In fact, I'm leaning far enough that I just committed the following:

	typedef struct {
	    double x_bearing;
	    double y_bearing;
	    double width;
	    double height;
	    double x_advance;
	    double y_advance;
	} cairo_text_extents_t;

There was some discussion about defining the box as two points rather
than point+width/height, but I found that to be rather awkward with
interfaces such as cairo_rectangle, (see how the code in
cairo-demo/png/text.c was simplified with the change).

The interface above has the advantage of matching the freetype
interface quite closely, (other than slightly different naming
conventions such as x_bearing rather than BearingX).

One significant difference is that freetype actually provides only a
single advance value. Freetype does have separate horiAdvance and
vertAdvance values, but also separate horiBearingX and horiBearingY
values.

We already have a plan for teaching cairo how to know whether it
should get the horizontal or vertical set of metrics from
freetype. So, it's conceivable that we could provide a single advance
value rather than x_advance and y_advance, (at least as far as
freetype is concerned).

Would that actually be useful? Would it limit things somewhere?

I haven't written much text manipulation code, but the little bit of
code I have written in libsvg-cairo actually suggests to me that
having separate x_advance/y_advance values actually makes things
easier, (even if at most one of the values will be non-zero). It seems
to allow me to write code that can correctly align text without having
to check whether the font is vertical or horizontal.

-Carl





More information about the cairo mailing list