diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2011-07-13 12:32:24 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2011-07-13 12:35:51 +0100 |
commit | 84c66589bc6f6a9f924863e578a49e4f2492ec87 (patch) | |
tree | 20bdcdc8a8461a60bbb6baf5a04c3156a99a2a2d | |
parent | 727a0092d1128f8dd6e6054efb586f26e47fa2d0 (diff) |
ft-font: If the pattern is already resolved, use it immediately
This skips an relatively expensive search for the a good match if the
pattern already contains a face or a filename.
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
-rw-r--r-- | src/cairo-ft-font.c | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c index acb71217..e6d7de35 100644 --- a/src/cairo-ft-font.c +++ b/src/cairo-ft-font.c @@ -2946,28 +2946,38 @@ _cairo_ft_resolve_pattern (FcPattern *pattern, FcDefaultSubstitute (pattern); - resolved = FcFontMatch (NULL, pattern, &result); - if (!resolved) { - /* We failed to find any font. Substitute twin so that the user can - * see something (and hopefully recognise that the font is missing) - * and not just receive a NO_MEMORY error during rendering. - */ - font_face = _cairo_font_face_twin_create_fallback (); + status = _cairo_ft_unscaled_font_create_for_pattern (pattern, &unscaled); + if (unlikely (status)) { + font_face = (cairo_font_face_t *)&_cairo_font_face_nil; goto FREE_PATTERN; } - status = _cairo_ft_unscaled_font_create_for_pattern (resolved, &unscaled); - if (unlikely (status || unscaled == NULL)) { - font_face = (cairo_font_face_t *)&_cairo_font_face_nil; - goto FREE_RESOLVED; - } + if (unscaled == NULL) { + resolved = FcFontMatch (NULL, pattern, &result); + if (!resolved) { + /* We failed to find any font. Substitute twin so that the user can + * see something (and hopefully recognise that the font is missing) + * and not just receive a NO_MEMORY error during rendering. + */ + font_face = _cairo_font_face_twin_create_fallback (); + goto FREE_PATTERN; + } + + status = _cairo_ft_unscaled_font_create_for_pattern (resolved, &unscaled); + if (unlikely (status || unscaled == NULL)) { + font_face = (cairo_font_face_t *)&_cairo_font_face_nil; + goto FREE_RESOLVED; + } + } else + resolved = pattern; _get_pattern_ft_options (resolved, &ft_options); font_face = _cairo_ft_font_face_create (unscaled, &ft_options); _cairo_unscaled_font_destroy (&unscaled->base); FREE_RESOLVED: - FcPatternDestroy (resolved); + if (resolved != pattern) + FcPatternDestroy (resolved); FREE_PATTERN: FcPatternDestroy (pattern); |