diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2011-07-24 10:03:48 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2011-07-24 11:50:48 +0100 |
commit | dc67d8e7f907062c7d0f02b57498c7503cb72f69 (patch) | |
tree | 408c6ebd84d78ce7f2be019398770d6dd19eadd9 /src/cairo-scaled-font.c | |
parent | 05bed4c574a9e6577bca93bfce837804c3dc6d19 (diff) |
composite: Perform a quick is-clipped for glyphs
Computing the exact bbox of the glyphs and whether they are overlapped
is expensive. However, we can often check whether they are visible just
by looking at the maximal extents of the fonts along with the bbox of
the positions; much cheaper.
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'src/cairo-scaled-font.c')
-rw-r--r-- | src/cairo-scaled-font.c | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c index ee79e2afc..efab44f3b 100644 --- a/src/cairo-scaled-font.c +++ b/src/cairo-scaled-font.c @@ -2193,11 +2193,14 @@ _cairo_scaled_font_glyph_approximate_extents (cairo_scaled_font_t *scaled_font, int num_glyphs, cairo_rectangle_int_t *extents) { - double x0 = HUGE_VAL, x1 = -HUGE_VAL; - double y0 = HUGE_VAL, y1 = -HUGE_VAL; + double x0, x1, y0, y1, pad; int i; - for (i = 0; i < num_glyphs; i++) { + assert (num_glyphs); + + x0 = x1 = glyphs[0].x; + y0 = y1 = glyphs[0].y; + for (i = 1; i < num_glyphs; i++) { double g; g = glyphs[i].x; @@ -2209,18 +2212,14 @@ _cairo_scaled_font_glyph_approximate_extents (cairo_scaled_font_t *scaled_font, if (g > y1) y1 = g; } - if (x0 <= x1 && y0 <= y1) { - extents->x = floor (x0 - scaled_font->extents.max_x_advance); - extents->width = ceil (x1 + scaled_font->extents.max_x_advance); - extents->width -= extents->x; + pad = MAX(scaled_font->fs_extents.max_x_advance, + scaled_font->fs_extents.height); + pad *= scaled_font->max_scale; - extents->y = floor (y0 - scaled_font->extents.ascent); - extents->height = ceil (y1 + scaled_font->extents.descent); - extents->height -= extents->y; - } else { - extents->x = extents->y = 0; - extents->width = extents->height = 0; - } + extents->x = floor (x0 - pad); + extents->width = ceil (x1 + pad) - extents->x; + extents->y = floor (y0 - pad); + extents->height = ceil (y1 + pad) - extents->y; } cairo_status_t |