diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c index 92b60c73b..092838ab4 100644 --- a/src/cairo-ft-font.c +++ b/src/cairo-ft-font.c @@ -1021,6 +1021,14 @@ _render_glyph_outline (FT_Face face, return status; } + /* + * Note: the font's coordinate system is upside down from ours, so the + * Y coordinate of the control box needs to be negated. + */ + + (*surface)->base.device_x_offset = floor ((double) cbox.xMin / 64.0); + (*surface)->base.device_y_offset = floor (-(double) cbox.yMax / 64.0); + return CAIRO_STATUS_SUCCESS; } @@ -1059,7 +1067,19 @@ _render_glyph_bitmap (FT_Face face, if (error) return CAIRO_STATUS_NO_MEMORY; - return _get_bitmap_surface (&glyphslot->bitmap, FALSE, font_options, surface); + status = _get_bitmap_surface (&glyphslot->bitmap, FALSE, font_options, surface); + if (status) + return status; + + /* + * Note: the font's coordinate system is upside down from ours, so the + * Y coordinate of the control box needs to be negated. + */ + + (*surface)->base.device_x_offset = glyphslot->bitmap_left; + (*surface)->base.device_y_offset = -glyphslot->bitmap_top; + + return status; } #if 0 diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c index cb0171ba5..a0469046d 100644 --- a/src/cairo-scaled-font.c +++ b/src/cairo-scaled-font.c @@ -858,7 +858,7 @@ _cairo_scaled_font_show_glyphs (cairo_scaled_font_t *scaled_font, * they are implemented in terms of other operators in cairo-gstate.c */ assert (op != CAIRO_OPERATOR_SOURCE && op != CAIRO_OPERATOR_CLEAR); - + if (scaled_font->status) return scaled_font->status; @@ -920,10 +920,10 @@ _cairo_scaled_font_show_glyphs (cairo_scaled_font_t *scaled_font, /* round glyph locations to the nearest pixel */ x = (int) floor (glyphs[i].x + - scaled_glyph->metrics.x_bearing + + glyph_surface->base.device_x_offset + 0.5); y = (int) floor (glyphs[i].y + - scaled_glyph->metrics.y_bearing + + glyph_surface->base.device_y_offset + 0.5); _cairo_pattern_init_for_surface (&glyph_pattern, &glyph_surface->base); diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c index a62afed84..dc7d394e1 100644 --- a/src/cairo-xlib-surface.c +++ b/src/cairo-xlib-surface.c @@ -2119,8 +2119,8 @@ _cairo_xlib_surface_add_glyph (Display *dpy, * sitting around for x and y. */ - glyph_info.x = -(int) floor(scaled_glyph->metrics.x_bearing + 0.5); - glyph_info.y = -(int) floor(scaled_glyph->metrics.y_bearing + 0.5); + glyph_info.x = -(int) glyph_surface->base.device_x_offset; + glyph_info.y = -(int) glyph_surface->base.device_y_offset; glyph_info.width = glyph_surface->width; glyph_info.height = glyph_surface->height; glyph_info.xOff = 0;