[user-font] Normalize the space we compute extents in

This way we wouldn't suffer from the limited precision of cairo_fixed_t.
Bug reported by Peter Clifton on mailing list.
This commit is contained in:
Behdad Esfahbod 2008-05-10 14:58:11 +02:00
parent f1a0e9df0e
commit 569cc30411

View file

@ -113,23 +113,45 @@ _cairo_user_scaled_glyph_init (void *abstract_font,
if (extents.width == 0.) {
/* Compute extents.x/y/width/height from meta_surface, in font space */
cairo_matrix_t matrix;
double fixed_scale, x_scale, y_scale;
cairo_box_t bbox;
double x1, y1, x2, y2;
cairo_surface_t *null_surface = _cairo_null_surface_create (cairo_surface_get_content (meta_surface));
cairo_surface_t *analysis_surface = _cairo_analysis_surface_create (null_surface, -1, -1);
cairo_surface_destroy (null_surface);
_cairo_analysis_surface_set_ctm (analysis_surface, &scaled_font->base.scale_inverse);
/* compute a normalized version of font scale matrix to compute
* extents in. This is to minimize error caused by the cairo_fixed_t
* representation. */
matrix = scaled_font->base.scale_inverse;
status = _cairo_matrix_compute_scale_factors (&matrix, &x_scale, &y_scale, /* XXX */ 1);
if (status)
return status;
/* since glyphs are pretty much 1.0x1.0, we can reduce error by
* scaling to a larger square. say, 1024.x1024. */
fixed_scale = 1024.;
x_scale /= fixed_scale;
y_scale /= fixed_scale;
if (x_scale == 0) x_scale = 1. / fixed_scale;
if (y_scale == 0) y_scale = 1. / fixed_scale;
cairo_matrix_scale (&matrix, 1. / x_scale, 1. / y_scale);
_cairo_analysis_surface_set_ctm (analysis_surface, &matrix);
status = _cairo_meta_surface_replay (meta_surface, analysis_surface);
_cairo_analysis_surface_get_bounding_box (analysis_surface, &bbox);
cairo_surface_destroy (analysis_surface);
_cairo_box_to_doubles (&bbox, &x1, &y1, &x2, &y2);
extents.x_bearing = x1;
extents.y_bearing = y1;
extents.width = x2 - x1;
extents.height = y2 - y1;
extents.x_bearing = x1 * x_scale;
extents.y_bearing = y1 * y_scale;
extents.width = (x2 - x1) * x_scale;
extents.height = (y2 - y1) * y_scale;
}
_cairo_scaled_glyph_set_metrics (scaled_glyph,