Use font matrix offset to reposition glyph origin instead of adjusting advance

As the font matrix includes translation, which is otherwise unused for glyph
transformation, the interpretation of translation is fairly arbitrary. For
1.2.0, we choose to have this translation affect the glyph advance with the
thought that it could be used to do letter spacing/kerning. That is fairly
useless in practice, and a far more useful interpretation is to relocate
the origin of each glyph.

This patch uses the translation in the font matrix as an offset for the
glyph origin in user space. It turns out glyph extents were already correctly
shifted.

The end result with this patch is to have cairo match the 1.0 behaviour for
font matrix translations, but now we know why :-)

Explanation above courtesy of Keith Packard.
This commit is contained in:
Behdad Esfahbod 2006-07-14 21:42:41 -04:00
parent 47d3c5a2c6
commit 84840e6bba
2 changed files with 10 additions and 8 deletions

View file

@ -1152,9 +1152,9 @@ _cairo_scaled_glyph_set_metrics (cairo_scaled_glyph_t *scaled_glyph,
scaled_glyph->metrics.x_advance = fs_metrics->x_advance;
scaled_glyph->metrics.y_advance = fs_metrics->y_advance;
cairo_matrix_transform_point (&scaled_font->font_matrix,
&scaled_glyph->metrics.x_advance,
&scaled_glyph->metrics.y_advance);
cairo_matrix_transform_distance (&scaled_font->font_matrix,
&scaled_glyph->metrics.x_advance,
&scaled_glyph->metrics.y_advance);
scaled_glyph->bbox.p1.x = _cairo_fixed_from_double (min_device_x);
scaled_glyph->bbox.p1.y = _cairo_fixed_from_double (min_device_y);

View file

@ -1705,6 +1705,7 @@ _cairo_surface_show_glyphs (cairo_surface_t *surface,
cairo_glyph_t *dev_glyphs = (cairo_glyph_t*) glyphs;
cairo_scaled_font_t *dev_scaled_font = scaled_font;
cairo_pattern_union_t dev_source;
cairo_matrix_t font_matrix;
assert (! surface->is_snapshot);
@ -1718,7 +1719,9 @@ _cairo_surface_show_glyphs (cairo_surface_t *surface,
surface,
&dev_source.base);
if (_cairo_surface_has_device_transform (surface))
cairo_scaled_font_get_font_matrix (scaled_font, &font_matrix);
if (_cairo_surface_has_device_transform (surface) || font_matrix.x0 != 0.0 || font_matrix.y0 != 0.0)
{
int i;
@ -1728,8 +1731,8 @@ _cairo_surface_show_glyphs (cairo_surface_t *surface,
for (i = 0; i < num_glyphs; i++) {
dev_glyphs[i].index = glyphs[i].index;
dev_glyphs[i].x = glyphs[i].x;
dev_glyphs[i].y = glyphs[i].y;
dev_glyphs[i].x = glyphs[i].x + font_matrix.x0;
dev_glyphs[i].y = glyphs[i].y + font_matrix.y0;
cairo_matrix_transform_point (&surface->device_transform,
&dev_glyphs[i].x,
&dev_glyphs[i].y);
@ -1737,11 +1740,10 @@ _cairo_surface_show_glyphs (cairo_surface_t *surface,
if (! _cairo_matrix_is_integer_translation (&surface->device_transform, NULL, NULL)) {
cairo_font_options_t *font_options;
cairo_matrix_t font_matrix, dev_ctm;
cairo_matrix_t dev_ctm;
font_options = cairo_font_options_create ();
cairo_scaled_font_get_font_matrix (scaled_font, &font_matrix);
cairo_scaled_font_get_ctm (scaled_font, &dev_ctm);
cairo_matrix_multiply (&dev_ctm, &dev_ctm, &surface->device_transform);
cairo_scaled_font_get_font_options (scaled_font, font_options);