From 198c1439ab21b1b19310335d93242709d1398ff3 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 11 Dec 2006 03:16:50 -0500 Subject: [PATCH] Cache rounded glyph advance values This is done in cairo_scaled_glyph_t->x/y_advance. The value is mostly useful for raster backends, for example to set as default advance of a glyph, and later on optimize glyph positionings that use the default advance. --- src/cairo-scaled-font.c | 10 ++++++++++ src/cairoint.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c index b800cf920..316c603bf 100755 --- a/src/cairo-scaled-font.c +++ b/src/cairo-scaled-font.c @@ -1211,6 +1211,7 @@ _cairo_scaled_glyph_set_metrics (cairo_scaled_glyph_t *scaled_glyph, double hm, wm; double min_user_x = 0.0, max_user_x = 0.0, min_user_y = 0.0, max_user_y = 0.0; double min_device_x = 0.0, max_device_x = 0.0, min_device_y = 0.0, max_device_y = 0.0; + double device_x_advance, device_y_advance; for (hm = 0.0; hm <= 1.0; hm += 1.0) for (wm = 0.0; wm <= 1.0; wm += 1.0) { @@ -1259,10 +1260,19 @@ _cairo_scaled_glyph_set_metrics (cairo_scaled_glyph_t *scaled_glyph, &scaled_glyph->metrics.x_advance, &scaled_glyph->metrics.y_advance); + device_x_advance = fs_metrics->x_advance; + device_y_advance = fs_metrics->y_advance; + cairo_matrix_transform_distance (&scaled_font->scale, + &device_x_advance, + &device_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); scaled_glyph->bbox.p2.x = _cairo_fixed_from_double (max_device_x); scaled_glyph->bbox.p2.y = _cairo_fixed_from_double (max_device_y); + + scaled_glyph->x_advance = _cairo_lround (device_x_advance); + scaled_glyph->y_advance = _cairo_lround (device_y_advance); } void diff --git a/src/cairoint.h b/src/cairoint.h index c89437209..f855a4132 100755 --- a/src/cairoint.h +++ b/src/cairoint.h @@ -511,6 +511,8 @@ typedef struct _cairo_scaled_glyph { cairo_scaled_font_t *scaled_font; /* font the glyph lives in */ cairo_text_extents_t metrics; /* user-space metrics */ cairo_box_t bbox; /* device-space bounds */ + int16_t x_advance; /* device-space rounded X advance */ + int16_t y_advance; /* device-space rounded Y advance */ cairo_image_surface_t *surface; /* device-space image */ cairo_path_fixed_t *path; /* device-space outline */ void *surface_private; /* for the surface backend */