[cairo] A (LONG) Pango/Cairo Question
Owen Taylor
otaylor at redhat.com
Wed Aug 27 10:30:00 PDT 2008
Just two quick comments:
- Just because you want to expose a bottom-left-origin to your users,
doesn't mean that you have to work that way internally. If you try
to use a bottom-left-origin with cairo and (especially) Pango you
are fighting the system and are constantly going to be flipping
back and forth. I'd suggest just converting the coordinates that the
user passes in, work internally in top-left coordinates, and then
(if you want to use your GL transform unmodified), convert back
right before drawing.
Similarly, there's no reason to render glyphs "upside down" onto your
cache texture ... just let cairo do it's normal thing, then do the
flip when drawing. (I think it's pretty common in GL to have textures
in top-to-bottom order ... other than BMP, most image formats work
that way, after all.)
>
> pango_font_get_glyph_extents(font, glyph, &ink_rect, 0);
> pango_extents_to_pixels(&ink_rect, 0);
> cairo_set_scaled_font(cr, pango_cairo_font_get_scaled_font(...))
> // cairo_set_font_matrix(...)
> cairo_glyph.x = -ink_rect.x;
> cairo_glyph.y = -ink_rect.y;
> cairo_glyph.index = glyph;
>
> In the above code, I'm somewhat unclear as to why I set the
> cairo_glyph{x, y} values with the negative versions of the ones from the
> ink_rect object queried using the Pango API; I got this part directly
> from the Clutter project. This, then, leads me to my last question,
> which is what are these values and how should I use them?
The negatives there don't have anything to do about Y axis direction,
rather they compensate for the difference between the origin of Pango's
coordinate system for a glyph (left edge of the baseline) and the origin
of the surface we are drawing the glyph onto.
Imagine the box is the ink rect of an italic f
+--------+
| XXX|
| X |
| XXXXX |
| X |
| * X |
| X |
|XX |
+--------+
The (*) marks the origin of Pango's coordinate system ... the left edge
of the baseline. Y axis increases downwards. The ink rect, then has
coordidates something like
x=-2, y=-10, width=9, height=15
Now, we want to draw this character into it's own surface. THe surface
should have a width/height matching the ink rect 9x15. Where does the
origin go in the coordinate system of the surface? at -x, -y ...
that is, at (2,10).
- Owen
More information about the cairo
mailing list