summaryrefslogtreecommitdiff
path: root/src/cairo-ft-font.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cairo-ft-font.c')
-rw-r--r--src/cairo-ft-font.c111
1 files changed, 44 insertions, 67 deletions
diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c
index 753810a8..7768a77c 100644
--- a/src/cairo-ft-font.c
+++ b/src/cairo-ft-font.c
@@ -177,7 +177,7 @@ _cairo_ft_unscaled_font_map_create (void)
font_map = malloc (sizeof (cairo_ft_unscaled_font_map_t));
if (font_map == NULL) {
- _cairo_error (CAIRO_STATUS_NO_MEMORY);
+ _cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
goto FAIL;
}
@@ -257,7 +257,7 @@ _cairo_ft_unscaled_font_map_lock (void)
if (cairo_ft_unscaled_font_map == NULL) {
CAIRO_MUTEX_UNLOCK (_cairo_ft_unscaled_font_map_mutex);
- _cairo_error (CAIRO_STATUS_NO_MEMORY);
+ _cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
return NULL;
}
}
@@ -330,10 +330,8 @@ _cairo_ft_unscaled_font_init (cairo_ft_unscaled_font_t *unscaled,
unscaled->face = NULL;
filename_copy = strdup (filename);
- if (filename_copy == NULL) {
- _cairo_error (CAIRO_STATUS_NO_MEMORY);
- return CAIRO_STATUS_NO_MEMORY;
- }
+ if (filename_copy == NULL)
+ return _cairo_error (CAIRO_STATUS_NO_MEMORY);
_cairo_ft_unscaled_font_init_key (unscaled, filename_copy, id);
}
@@ -426,7 +424,7 @@ _cairo_ft_unscaled_font_create_for_pattern (FcPattern *pattern)
/* Otherwise create it and insert into hash table. */
unscaled = malloc (sizeof (cairo_ft_unscaled_font_t));
if (unscaled == NULL) {
- _cairo_error (CAIRO_STATUS_NO_MEMORY);
+ _cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
goto UNWIND_FONT_MAP_LOCK;
}
@@ -461,7 +459,7 @@ _cairo_ft_unscaled_font_create_from_face (FT_Face face)
unscaled = malloc (sizeof (cairo_ft_unscaled_font_t));
if (unscaled == NULL) {
- _cairo_error (CAIRO_STATUS_NO_MEMORY);
+ _cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
return NULL;
}
@@ -560,7 +558,7 @@ _cairo_ft_unscaled_font_lock_face (cairo_ft_unscaled_font_t *unscaled)
{
unscaled->lock_count--;
CAIRO_MUTEX_UNLOCK (unscaled->mutex);
- _cairo_error (CAIRO_STATUS_NO_MEMORY);
+ _cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
return NULL;
}
@@ -666,10 +664,8 @@ _cairo_ft_unscaled_font_set_scale (cairo_ft_unscaled_font_t *unscaled,
sf.x_scale * 64.0,
sf.y_scale * 64.0,
0, 0);
- if (error) {
- _cairo_error (CAIRO_STATUS_NO_MEMORY);
- return CAIRO_STATUS_NO_MEMORY;
- }
+ if (error)
+ return _cairo_error (CAIRO_STATUS_NO_MEMORY);
} else {
double min_distance = DBL_MAX;
int i;
@@ -698,10 +694,8 @@ _cairo_ft_unscaled_font_set_scale (cairo_ft_unscaled_font_t *unscaled,
error = FT_Set_Pixel_Sizes (unscaled->face,
unscaled->face->available_sizes[best_i].width,
unscaled->face->available_sizes[best_i].height);
- if (error) {
- _cairo_error (CAIRO_STATUS_NO_MEMORY);
- return CAIRO_STATUS_NO_MEMORY;
- }
+ if (error)
+ return _cairo_error (CAIRO_STATUS_NO_MEMORY);
}
return CAIRO_STATUS_SUCCESS;
@@ -755,10 +749,8 @@ _get_bitmap_surface (FT_Bitmap *bitmap,
assert (stride == bitmap->pitch);
} else {
data = _cairo_malloc_ab (height, stride);
- if (!data) {
- _cairo_error (CAIRO_STATUS_NO_MEMORY);
- return CAIRO_STATUS_NO_MEMORY;
- }
+ if (!data)
+ return _cairo_error (CAIRO_STATUS_NO_MEMORY);
if (stride == bitmap->pitch) {
memcpy (data, bitmap->buffer, stride * height);
@@ -805,10 +797,9 @@ _get_bitmap_surface (FT_Bitmap *bitmap,
data = bitmap->buffer;
} else {
data = _cairo_malloc_ab (height, stride);
- if (!data) {
- _cairo_error (CAIRO_STATUS_NO_MEMORY);
- return CAIRO_STATUS_NO_MEMORY;
- }
+ if (!data)
+ return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+
memcpy (data, bitmap->buffer, stride * height);
}
format = CAIRO_FORMAT_A8;
@@ -850,8 +841,7 @@ _get_bitmap_surface (FT_Bitmap *bitmap,
if (data_rgba == NULL) {
if (own_buffer)
free (bitmap->buffer);
- _cairo_error (CAIRO_STATUS_NO_MEMORY);
- return CAIRO_STATUS_NO_MEMORY;
+ return _cairo_error (CAIRO_STATUS_NO_MEMORY);
}
os = 1;
@@ -919,8 +909,7 @@ _get_bitmap_surface (FT_Bitmap *bitmap,
default:
if (own_buffer)
free (bitmap->buffer);
- _cairo_error (CAIRO_STATUS_NO_MEMORY);
- return CAIRO_STATUS_NO_MEMORY;
+ return _cairo_error (CAIRO_STATUS_NO_MEMORY);
}
*surface = (cairo_image_surface_t *)
@@ -929,7 +918,7 @@ _get_bitmap_surface (FT_Bitmap *bitmap,
width, height, stride);
if ((*surface)->base.status) {
free (data);
- return CAIRO_STATUS_NO_MEMORY;
+ return _cairo_error (CAIRO_STATUS_NO_MEMORY);
}
if (subpixel)
@@ -1002,7 +991,7 @@ _render_glyph_outline (FT_Face face,
(*surface) = (cairo_image_surface_t *)
cairo_image_surface_create_for_data (NULL, format, 0, 0, 0);
if ((*surface)->base.status)
- return CAIRO_STATUS_NO_MEMORY;
+ return (*surface)->base.status;
} else {
matrix.xx = matrix.yy = 0x10000L;
@@ -1049,16 +1038,14 @@ _render_glyph_outline (FT_Face face,
bitmap.rows = height * vmul;
bitmap.buffer = calloc (stride, bitmap.rows);
if (bitmap.buffer == NULL) {
- _cairo_error (CAIRO_STATUS_NO_MEMORY);
- return CAIRO_STATUS_NO_MEMORY;
+ return _cairo_error (CAIRO_STATUS_NO_MEMORY);
}
FT_Outline_Translate (outline, -cbox.xMin*hmul, -cbox.yMin*vmul);
if (FT_Outline_Get_Bitmap (glyphslot->library, outline, &bitmap) != 0) {
free (bitmap.buffer);
- _cairo_error (CAIRO_STATUS_NO_MEMORY);
- return CAIRO_STATUS_NO_MEMORY;
+ return _cairo_error (CAIRO_STATUS_NO_MEMORY);
}
status = _get_bitmap_surface (&bitmap, TRUE, font_options, surface);
@@ -1099,10 +1086,8 @@ _render_glyph_bitmap (FT_Face face,
error = FT_Render_Glyph (glyphslot, FT_RENDER_MODE_NORMAL);
/* XXX ignoring all other errors for now. They are not fatal, typically
* just a glyph-not-found. */
- if (error == FT_Err_Out_Of_Memory) {
- _cairo_error (CAIRO_STATUS_NO_MEMORY);
- return CAIRO_STATUS_NO_MEMORY;
- }
+ if (error == FT_Err_Out_Of_Memory)
+ return _cairo_error (CAIRO_STATUS_NO_MEMORY);
status = _get_bitmap_surface (&glyphslot->bitmap, FALSE, font_options, surface);
if (status)
@@ -1199,7 +1184,7 @@ _transform_glyph_bitmap (cairo_matrix_t * shape,
width = (width + 3) & ~3;
image = cairo_image_surface_create (CAIRO_FORMAT_A8, width, height);
if (image->status)
- return CAIRO_STATUS_NO_MEMORY;
+ return image->status;
/* Initialize it to empty
*/
@@ -1486,7 +1471,7 @@ _cairo_ft_scaled_font_create (cairo_ft_unscaled_font_t *unscaled,
scaled_font = malloc (sizeof(cairo_ft_scaled_font_t));
if (scaled_font == NULL) {
_cairo_ft_unscaled_font_unlock_face (unscaled);
- _cairo_error (CAIRO_STATUS_NO_MEMORY);
+ _cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
return NULL;
}
@@ -1596,10 +1581,8 @@ _cairo_ft_scaled_font_create_toy (cairo_toy_font_face_t *toy_face,
unsigned char *family = (unsigned char*) toy_face->family;
pattern = FcPatternCreate ();
- if (!pattern) {
- _cairo_error (CAIRO_STATUS_NO_MEMORY);
- return CAIRO_STATUS_NO_MEMORY;
- }
+ if (!pattern)
+ return _cairo_error (CAIRO_STATUS_NO_MEMORY);
switch (toy_face->weight)
{
@@ -1668,10 +1651,8 @@ _cairo_ft_scaled_font_create_toy (cairo_toy_font_face_t *toy_face,
if (new_font) {
*font = new_font;
return CAIRO_STATUS_SUCCESS;
- } else {
- _cairo_error (CAIRO_STATUS_NO_MEMORY);
- return CAIRO_STATUS_NO_MEMORY;
- }
+ } else
+ return _cairo_error (CAIRO_STATUS_NO_MEMORY);
}
static void
@@ -1804,7 +1785,7 @@ _decompose_glyph_outline (FT_Face face,
path = _cairo_path_fixed_create ();
if (!path)
- return CAIRO_STATUS_NO_MEMORY;
+ return _cairo_error (CAIRO_STATUS_NO_MEMORY);
glyph = face->glyph;
@@ -1812,8 +1793,7 @@ _decompose_glyph_outline (FT_Face face,
FT_Outline_Transform (&glyph->outline, &invert_y);
if (FT_Outline_Decompose (&glyph->outline, &outline_funcs, path)) {
_cairo_path_fixed_destroy (path);
- _cairo_error (CAIRO_STATUS_NO_MEMORY);
- return CAIRO_STATUS_NO_MEMORY;
+ return _cairo_error (CAIRO_STATUS_NO_MEMORY);
}
status = _cairo_path_fixed_close_path (path);
@@ -1868,7 +1848,7 @@ _cairo_ft_scaled_glyph_init (void *abstract_font,
face = _cairo_ft_unscaled_font_lock_face (unscaled);
if (!face)
- return CAIRO_STATUS_NO_MEMORY;
+ return _cairo_error (CAIRO_STATUS_NO_MEMORY);
status = _cairo_ft_unscaled_font_set_scale (scaled_font->unscaled,
&scaled_font->base.scale);
@@ -1897,7 +1877,7 @@ _cairo_ft_scaled_glyph_init (void *abstract_font,
/* XXX ignoring all other errors for now. They are not fatal, typically
* just a glyph-not-found. */
if (error == FT_Err_Out_Of_Memory) {
- status = CAIRO_STATUS_NO_MEMORY;
+ status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
goto FAIL;
}
@@ -2036,7 +2016,7 @@ _cairo_ft_scaled_glyph_init (void *abstract_font,
}
if (info & CAIRO_SCALED_GLYPH_INFO_PATH) {
- cairo_path_fixed_t *path;
+ cairo_path_fixed_t *path = NULL; /* hide compiler warning */
/*
* A kludge -- the above code will trash the outline,
@@ -2049,9 +2029,8 @@ _cairo_ft_scaled_glyph_init (void *abstract_font,
/* XXX ignoring all other errors for now. They are not fatal, typically
* just a glyph-not-found. */
if (error == FT_Err_Out_Of_Memory) {
- _cairo_ft_unscaled_font_unlock_face (unscaled);
- _cairo_error (CAIRO_STATUS_NO_MEMORY);
- return CAIRO_STATUS_NO_MEMORY;
+ status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
+ goto FAIL;
}
#if HAVE_FT_GLYPHSLOT_EMBOLDEN
/*
@@ -2118,7 +2097,7 @@ _cairo_ft_load_truetype_table (void *abstract_font,
#if HAVE_FT_LOAD_SFNT_TABLE
face = _cairo_ft_unscaled_font_lock_face (unscaled);
if (!face)
- return CAIRO_STATUS_NO_MEMORY;
+ return _cairo_error (CAIRO_STATUS_NO_MEMORY);
if (FT_IS_SFNT (face) &&
FT_Load_Sfnt_Table (face, tag, offset, buffer, length) == 0)
@@ -2260,12 +2239,10 @@ _cairo_ft_font_face_scaled_font_create (void *abstract_face,
&font_face->base,
font_matrix, ctm,
options, ft_options);
- if (*scaled_font) {
+ if (*scaled_font)
return CAIRO_STATUS_SUCCESS;
- } else {
- _cairo_error (CAIRO_STATUS_NO_MEMORY);
- return CAIRO_STATUS_NO_MEMORY;
- }
+ else
+ return _cairo_error (CAIRO_STATUS_NO_MEMORY);
}
static const cairo_font_face_backend_t _cairo_ft_font_face_backend = {
@@ -2301,7 +2278,7 @@ _cairo_ft_font_face_create (cairo_ft_unscaled_font_t *unscaled,
/* No match found, create a new one */
font_face = malloc (sizeof (cairo_ft_font_face_t));
if (!font_face) {
- _cairo_error (CAIRO_STATUS_NO_MEMORY);
+ _cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
return NULL;
}
@@ -2451,7 +2428,7 @@ cairo_ft_font_face_create_for_pattern (FcPattern *pattern)
unscaled = _cairo_ft_unscaled_font_create_for_pattern (pattern);
if (unscaled == NULL) {
- _cairo_error (CAIRO_STATUS_NO_MEMORY);
+ _cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
return (cairo_font_face_t *)&_cairo_font_face_nil;
}
@@ -2501,7 +2478,7 @@ cairo_ft_font_face_create_for_ft_face (FT_Face face,
unscaled = _cairo_ft_unscaled_font_create_from_face (face);
if (unscaled == NULL) {
- _cairo_error (CAIRO_STATUS_NO_MEMORY);
+ _cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
return (cairo_font_face_t *)&_cairo_font_face_nil;
}