summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2012-06-04 20:16:12 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2012-06-04 20:18:03 +0100
commit9fa047c0ea49d94f9f27947931fe21b70f6463d5 (patch)
tree19b96d75e9dccb16c55b34633686571969a243d5
parent0210499578898ba5bab8dbd323455c6735419a5a (diff)
composite-rectangles,scaled-font: Use accurate extents if the font is broken
If the font metrics appear broken, i.e. key values are being reported as zero, skip approximating the bbox of the glyph string. References: https://bugs.freedesktop.org/show_bug.cgi?id=50688 Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
-rw-r--r--src/cairo-composite-rectangles.c5
-rw-r--r--src/cairo-scaled-font.c11
-rw-r--r--src/cairoint.h2
3 files changed, 14 insertions, 4 deletions
diff --git a/src/cairo-composite-rectangles.c b/src/cairo-composite-rectangles.c
index c2de02a4..c358671f 100644
--- a/src/cairo-composite-rectangles.c
+++ b/src/cairo-composite-rectangles.c
@@ -413,10 +413,11 @@ _cairo_composite_rectangles_init_for_glyphs (cairo_composite_rectangles_t *exten
/* Computing the exact bbox and the overlap is expensive.
* First perform a cheap test to see if the glyphs are all clipped out.
*/
- if (extents->is_bounded & CAIRO_OPERATOR_BOUND_BY_MASK) {
+ if (extents->is_bounded & CAIRO_OPERATOR_BOUND_BY_MASK &&
_cairo_scaled_font_glyph_approximate_extents (scaled_font,
glyphs, num_glyphs,
- &extents->mask);
+ &extents->mask))
+ {
if (! _cairo_rectangle_intersect (&extents->bounded, &extents->mask))
return CAIRO_INT_STATUS_NOTHING_TO_DO;
}
diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c
index 59440b2c..7ea3a212 100644
--- a/src/cairo-scaled-font.c
+++ b/src/cairo-scaled-font.c
@@ -2252,7 +2252,7 @@ _cairo_scaled_font_glyph_device_extents (cairo_scaled_font_t *scaled_font,
return CAIRO_STATUS_SUCCESS;
}
-void
+cairo_bool_t
_cairo_scaled_font_glyph_approximate_extents (cairo_scaled_font_t *scaled_font,
const cairo_glyph_t *glyphs,
int num_glyphs,
@@ -2261,6 +2261,14 @@ _cairo_scaled_font_glyph_approximate_extents (cairo_scaled_font_t *scaled_font,
double x0, x1, y0, y1, pad;
int i;
+ /* If any of the factors are suspect (i.e. the font is broken), bail */
+ if (scaled_font->fs_extents.max_x_advance == 0 ||
+ scaled_font->fs_extents.height == 0 ||
+ scaled_font->max_scale == 0)
+ {
+ return FALSE;
+ }
+
assert (num_glyphs);
x0 = x1 = glyphs[0].x;
@@ -2285,6 +2293,7 @@ _cairo_scaled_font_glyph_approximate_extents (cairo_scaled_font_t *scaled_font,
extents->width = ceil (x1 + pad) - extents->x;
extents->y = floor (y0 - pad);
extents->height = ceil (y1 + pad) - extents->y;
+ return TRUE;
}
#if 0
diff --git a/src/cairoint.h b/src/cairoint.h
index c81d3ef7..d531caf9 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -1156,7 +1156,7 @@ _cairo_scaled_font_glyph_device_extents (cairo_scaled_font_t *scaled_font,
cairo_rectangle_int_t *extents,
cairo_bool_t *overlap);
-cairo_private void
+cairo_private cairo_bool_t
_cairo_scaled_font_glyph_approximate_extents (cairo_scaled_font_t *scaled_font,
const cairo_glyph_t *glyphs,
int num_glyphs,