[PATCH] [ft-font] Distinguish fatal backend errors whilst constructing scaled fonts.
Chris Wilson
chris at chris-wilson.co.uk
Mon Jan 26 13:36:27 PST 2009
We now have the ability to distinguish an error case where the backend is
left in an inconsistent state from a transitory error. For the former we
need to report the error condition via the return value, which will be
propagated to the font-face. For the latter we just construct an in-error
scaled font nil-object which is passed back to the user.
---
src/cairo-ft-font.c | 28 +++++++++++++++++-----------
1 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c
index 39cf164..70bc6cf 100644
--- a/src/cairo-ft-font.c
+++ b/src/cairo-ft-font.c
@@ -1523,7 +1523,7 @@ _cairo_ft_scaled_font_create (cairo_ft_unscaled_font_t *unscaled,
cairo_status_t status;
face = _cairo_ft_unscaled_font_lock_face (unscaled);
- if (!face)
+ if (unlikely (face == NULL)) /* backend error */
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
scaled_font = malloc (sizeof(cairo_ft_scaled_font_t));
@@ -1542,18 +1542,17 @@ _cairo_ft_scaled_font_create (cairo_ft_unscaled_font_t *unscaled,
font_face,
font_matrix, ctm, options,
&_cairo_ft_scaled_font_backend);
- if (unlikely (status)) {
- _cairo_unscaled_font_destroy (&unscaled->base);
- free (scaled_font);
- goto FAIL;
- }
+ if (unlikely (status))
+ goto CLEANUP_SCALED_FONT;
status = _cairo_ft_unscaled_font_set_scale (unscaled,
&scaled_font->base.scale);
if (unlikely (status)) {
+ /* This can only fail if we encounter an error with the underlying
+ * font, so propagate the error back to the font-face. */
_cairo_unscaled_font_destroy (&unscaled->base);
free (scaled_font);
- goto FAIL;
+ return status;
}
@@ -1607,13 +1606,20 @@ _cairo_ft_scaled_font_create (cairo_ft_unscaled_font_t *unscaled,
}
status = _cairo_scaled_font_set_metrics (&scaled_font->base, &fs_metrics);
+ if (unlikely (status))
+ goto CLEANUP_SCALED_FONT;
- *font_out = &scaled_font->base;
-
- FAIL:
_cairo_ft_unscaled_font_unlock_face (unscaled);
- return status;
+ *font_out = &scaled_font->base;
+ return CAIRO_STATUS_SUCCESS;
+
+ CLEANUP_SCALED_FONT:
+ _cairo_unscaled_font_destroy (&unscaled->base);
+ free (scaled_font);
+ FAIL:
+ *font_out = _cairo_scaled_font_create_in_error (status);
+ return CAIRO_STATUS_SUCCESS; /* non-backend error */
}
cairo_bool_t
--
1.6.0.4
--=-eOh/xoSIvGBTom+9YKG9--
More information about the cairo
mailing list