diff options
Diffstat (limited to 'src/cairo-ft-font.c')
-rw-r--r-- | src/cairo-ft-font.c | 87 |
1 files changed, 51 insertions, 36 deletions
diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c index cd112532..773f6ea0 100644 --- a/src/cairo-ft-font.c +++ b/src/cairo-ft-font.c @@ -182,7 +182,7 @@ _cairo_ft_unscaled_font_map_create (void) assert (cairo_ft_unscaled_font_map == NULL); font_map = malloc (sizeof (cairo_ft_unscaled_font_map_t)); - if (font_map == NULL) { + if (unlikely (font_map == NULL)) { _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); goto FAIL; } @@ -190,7 +190,7 @@ _cairo_ft_unscaled_font_map_create (void) font_map->hash_table = _cairo_hash_table_create (_cairo_ft_unscaled_font_keys_equal); - if (font_map->hash_table == NULL) + if (unlikely (font_map->hash_table == NULL)) goto FAIL; if (FT_Init_FreeType (&font_map->ft_library)) @@ -261,7 +261,7 @@ _cairo_ft_unscaled_font_map_lock (void) { _cairo_ft_unscaled_font_map_create (); - if (cairo_ft_unscaled_font_map == NULL) { + if (unlikely (cairo_ft_unscaled_font_map == NULL)) { CAIRO_MUTEX_UNLOCK (_cairo_ft_unscaled_font_map_mutex); _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); return NULL; @@ -340,8 +340,9 @@ _cairo_ft_unscaled_font_init (cairo_ft_unscaled_font_t *unscaled, unscaled->face = NULL; filename_copy = strdup (filename); - if (filename_copy == NULL) + if (unlikely (filename_copy == NULL)) return _cairo_error (CAIRO_STATUS_NO_MEMORY); + _cairo_ft_unscaled_font_init_key (unscaled, FALSE, filename_copy, id, NULL); } @@ -416,15 +417,15 @@ _cairo_ft_unscaled_font_create_internal (cairo_bool_t from_face, cairo_status_t status; font_map = _cairo_ft_unscaled_font_map_lock (); - if (font_map == NULL) + if (unlikely (font_map == NULL)) goto UNWIND; _cairo_ft_unscaled_font_init_key (&key, from_face, filename, id, font_face); /* Return existing unscaled font if it exists in the hash table. */ - if (_cairo_hash_table_lookup (font_map->hash_table, &key.base.hash_entry, - (cairo_hash_entry_t **) &unscaled)) - { + unscaled = _cairo_hash_table_lookup (font_map->hash_table, + &key.base.hash_entry); + if (unscaled != NULL) { _cairo_unscaled_font_reference (&unscaled->base); _cairo_ft_unscaled_font_map_unlock (); return unscaled; @@ -432,18 +433,18 @@ _cairo_ft_unscaled_font_create_internal (cairo_bool_t from_face, /* Otherwise create it and insert into hash table. */ unscaled = malloc (sizeof (cairo_ft_unscaled_font_t)); - if (unscaled == NULL) { + if (unlikely (unscaled == NULL)) { _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); goto UNWIND_FONT_MAP_LOCK; } status = _cairo_ft_unscaled_font_init (unscaled, from_face, filename, id, font_face); - if (status) + if (unlikely (status)) goto UNWIND_UNSCALED_MALLOC; status = _cairo_hash_table_insert (font_map->hash_table, &unscaled->base.hash_entry); - if (status) + if (unlikely (status)) goto UNWIND_UNSCALED_FONT_INIT; _cairo_ft_unscaled_font_map_unlock (); @@ -621,7 +622,7 @@ _compute_transform (cairo_ft_font_transform_t *sf, status = _cairo_matrix_compute_basis_scale_factors (scale, &x_scale, &y_scale, 1); - if (status) + if (unlikely (status)) return status; /* FreeType docs say this about x_scale and y_scale: @@ -671,7 +672,7 @@ _cairo_ft_unscaled_font_set_scale (cairo_ft_unscaled_font_t *unscaled, unscaled->current_scale = *scale; status = _compute_transform (&sf, scale); - if (status) + if (unlikely (status)) return status; unscaled->x_scale = sf.x_scale; @@ -874,7 +875,7 @@ _get_bitmap_surface (FT_Bitmap *bitmap, stride = bitmap->pitch; stride_rgba = (width_rgba * 4 + 3) & ~3; data_rgba = calloc (stride_rgba, height); - if (data_rgba == NULL) { + if (unlikely (data_rgba == NULL)) { if (own_buffer) free (bitmap->buffer); return _cairo_error (CAIRO_STATUS_NO_MEMORY); @@ -1073,7 +1074,7 @@ _render_glyph_outline (FT_Face face, bitmap.width = width * hmul; bitmap.rows = height * vmul; bitmap.buffer = calloc (stride, bitmap.rows); - if (bitmap.buffer == NULL) + if (unlikely (bitmap.buffer == NULL)) return _cairo_error (CAIRO_STATUS_NO_MEMORY); FT_Outline_Translate (outline, -cbox.xMin*hmul, -cbox.yMin*vmul); @@ -1084,7 +1085,7 @@ _render_glyph_outline (FT_Face face, } status = _get_bitmap_surface (&bitmap, TRUE, font_options, surface); - if (status) + if (unlikely (status)) return status; } @@ -1125,7 +1126,7 @@ _render_glyph_bitmap (FT_Face face, return _cairo_error (CAIRO_STATUS_NO_MEMORY); status = _get_bitmap_surface (&glyphslot->bitmap, FALSE, font_options, surface); - if (status) + if (unlikely (status)) return status; /* @@ -1212,13 +1213,13 @@ _transform_glyph_bitmap (cairo_matrix_t * shape, transformed_to_original = original_to_transformed; status = cairo_matrix_invert (&transformed_to_original); - if (status) + if (unlikely (status)) return status; /* We need to pad out the width to 32-bit intervals for cairo-xlib-surface.c */ width = (width + 3) & ~3; image = cairo_image_surface_create (CAIRO_FORMAT_A8, width, height); - if (image->status) + if (unlikely (image->status)) return image->status; /* Initialize it to empty @@ -1227,7 +1228,7 @@ _transform_glyph_bitmap (cairo_matrix_t * shape, CAIRO_COLOR_TRANSPARENT, 0, 0, width, height); - if (status) { + if (unlikely (status)) { cairo_surface_destroy (image); return status; } @@ -1245,7 +1246,7 @@ _transform_glyph_bitmap (cairo_matrix_t * shape, _cairo_pattern_fini (&pattern.base); - if (status) { + if (unlikely (status)) { cairo_surface_destroy (image); return status; } @@ -1512,7 +1513,7 @@ _cairo_ft_scaled_font_create (cairo_ft_unscaled_font_t *unscaled, return _cairo_error (CAIRO_STATUS_NO_MEMORY); scaled_font = malloc (sizeof(cairo_ft_scaled_font_t)); - if (scaled_font == NULL) { + if (unlikely (scaled_font == NULL)) { status = _cairo_error (CAIRO_STATUS_NO_MEMORY); goto FAIL; } @@ -1527,7 +1528,7 @@ _cairo_ft_scaled_font_create (cairo_ft_unscaled_font_t *unscaled, font_face, font_matrix, ctm, options, &_cairo_ft_scaled_font_backend); - if (status) { + if (unlikely (status)) { _cairo_unscaled_font_destroy (&unscaled->base); free (scaled_font); goto FAIL; @@ -1535,7 +1536,7 @@ _cairo_ft_scaled_font_create (cairo_ft_unscaled_font_t *unscaled, status = _cairo_ft_unscaled_font_set_scale (unscaled, &scaled_font->base.scale); - if (status) { + if (unlikely (status)) { _cairo_unscaled_font_destroy (&unscaled->base); free (scaled_font); goto FAIL; @@ -1626,7 +1627,7 @@ _cairo_ft_scaled_font_create_toy (cairo_toy_font_face_t *toy_face, cairo_matrix_multiply (&scale, font_matrix, ctm); status = _compute_transform (&sf, &scale); - if (status) + if (unlikely (status)) return status; pattern = FcPatternCreate (); @@ -1686,7 +1687,7 @@ _cairo_ft_scaled_font_create_toy (cairo_toy_font_face_t *toy_face, } status = _cairo_ft_font_options_substitute (font_options, pattern); - if (status) + if (unlikely (status)) goto FREE_PATTERN; FcDefaultSubstitute (pattern); @@ -1863,7 +1864,7 @@ _decompose_glyph_outline (FT_Face face, } status = _cairo_path_fixed_close_path (path); - if (status) { + if (unlikely (status)) { _cairo_path_fixed_destroy (path); return status; } @@ -1918,7 +1919,7 @@ _cairo_ft_scaled_glyph_init (void *abstract_font, status = _cairo_ft_unscaled_font_set_scale (scaled_font->unscaled, &scaled_font->base.scale); - if (status) + if (unlikely (status)) goto FAIL; /* Ignore global advance unconditionally */ @@ -2066,14 +2067,16 @@ _cairo_ft_scaled_glyph_init (void *abstract_font, } else { status = _render_glyph_bitmap (face, &scaled_font->ft_options.base, &surface); - if (status == CAIRO_STATUS_SUCCESS && unscaled->have_shape) { + if (likely (status == CAIRO_STATUS_SUCCESS) && + unscaled->have_shape) + { status = _transform_glyph_bitmap (&unscaled->current_shape, &surface); - if (status) + if (unlikely (status)) cairo_surface_destroy (&surface->base); } } - if (status) + if (unlikely (status)) goto FAIL; _cairo_scaled_glyph_set_surface (scaled_glyph, @@ -2115,7 +2118,7 @@ _cairo_ft_scaled_glyph_init (void *abstract_font, else status = CAIRO_INT_STATUS_UNSUPPORTED; - if (status) + if (unlikely (status)) goto FAIL; _cairo_scaled_glyph_set_path (scaled_glyph, @@ -2530,7 +2533,7 @@ cairo_ft_font_face_create_for_pattern (FcPattern *pattern) cairo_ft_options_t ft_options; unscaled = _cairo_ft_unscaled_font_create_for_pattern (pattern); - if (unscaled == NULL) { + if (unlikely (unscaled == NULL)) { _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); return (cairo_font_face_t *)&_cairo_font_face_nil; } @@ -2597,7 +2600,7 @@ cairo_ft_font_face_create_for_ft_face (FT_Face face, cairo_ft_options_t ft_options; unscaled = _cairo_ft_unscaled_font_create_from_face (face); - if (unscaled == NULL) { + if (unlikely (unscaled == NULL)) { _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); return (cairo_font_face_t *)&_cairo_font_face_nil; } @@ -2658,14 +2661,14 @@ cairo_ft_scaled_font_lock_face (cairo_scaled_font_t *abstract_font) return NULL; face = _cairo_ft_unscaled_font_lock_face (scaled_font->unscaled); - if (face == NULL) { + if (unlikely (face == NULL)) { status = _cairo_scaled_font_set_error (&scaled_font->base, CAIRO_STATUS_NO_MEMORY); return NULL; } status = _cairo_ft_unscaled_font_set_scale (scaled_font->unscaled, &scaled_font->base.scale); - if (status) { + if (unlikely (status)) { _cairo_ft_unscaled_font_unlock_face (scaled_font->unscaled); status = _cairo_scaled_font_set_error (&scaled_font->base, status); return NULL; @@ -2739,6 +2742,18 @@ _cairo_ft_scaled_font_is_vertical (cairo_scaled_font_t *scaled_font) return FALSE; } +unsigned int +_cairo_ft_scaled_font_get_load_flags (cairo_scaled_font_t *scaled_font) +{ + cairo_ft_scaled_font_t *ft_scaled_font; + + if (! _cairo_scaled_font_is_ft (scaled_font)) + return 0; + + ft_scaled_font = (cairo_ft_scaled_font_t *) scaled_font; + return ft_scaled_font->ft_options.load_flags; +} + void _cairo_ft_font_reset_static_data (void) { |