mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-02-16 09:40:33 +01:00
[test/user-font[-proxy]] Check for error from set_user_data().
Check in case we fail to attach our user_data.
This commit is contained in:
parent
1983929900
commit
683de2fea2
2 changed files with 55 additions and 32 deletions
|
|
@ -115,33 +115,37 @@ test_scaled_font_text_to_glyphs (cairo_scaled_font_t *scaled_font,
|
|||
clusters, num_clusters, cluster_flags);
|
||||
}
|
||||
|
||||
static cairo_font_face_t *user_font_face = NULL;
|
||||
|
||||
static cairo_font_face_t *
|
||||
get_user_font_face (void)
|
||||
static cairo_status_t
|
||||
_user_font_face_create (cairo_font_face_t **out)
|
||||
{
|
||||
if (!user_font_face) {
|
||||
cairo_font_face_t *fallback_font_face;
|
||||
cairo_font_face_t *user_font_face;
|
||||
cairo_font_face_t *fallback_font_face;
|
||||
cairo_status_t status;
|
||||
|
||||
user_font_face = cairo_user_font_face_create ();
|
||||
cairo_user_font_face_set_init_func (user_font_face, test_scaled_font_init);
|
||||
cairo_user_font_face_set_render_glyph_func (user_font_face, test_scaled_font_render_glyph);
|
||||
cairo_user_font_face_set_text_to_glyphs_func (user_font_face, test_scaled_font_text_to_glyphs);
|
||||
user_font_face = cairo_user_font_face_create ();
|
||||
cairo_user_font_face_set_init_func (user_font_face, test_scaled_font_init);
|
||||
cairo_user_font_face_set_render_glyph_func (user_font_face, test_scaled_font_render_glyph);
|
||||
cairo_user_font_face_set_text_to_glyphs_func (user_font_face, test_scaled_font_text_to_glyphs);
|
||||
|
||||
/* This also happens to be default font face on cairo_t, so does
|
||||
* not make much sense here. For demonstration only.
|
||||
*/
|
||||
fallback_font_face = cairo_toy_font_face_create ("",
|
||||
CAIRO_FONT_SLANT_NORMAL,
|
||||
CAIRO_FONT_WEIGHT_NORMAL);
|
||||
/* This also happens to be default font face on cairo_t, so does
|
||||
* not make much sense here. For demonstration only.
|
||||
*/
|
||||
fallback_font_face = cairo_toy_font_face_create ("",
|
||||
CAIRO_FONT_SLANT_NORMAL,
|
||||
CAIRO_FONT_WEIGHT_NORMAL);
|
||||
|
||||
cairo_font_face_set_user_data (user_font_face,
|
||||
&fallback_font_key,
|
||||
fallback_font_face,
|
||||
(cairo_destroy_func_t) cairo_font_face_destroy);
|
||||
status = cairo_font_face_set_user_data (user_font_face,
|
||||
&fallback_font_key,
|
||||
fallback_font_face,
|
||||
(cairo_destroy_func_t) cairo_font_face_destroy);
|
||||
if (status) {
|
||||
cairo_font_face_destroy (fallback_font_face);
|
||||
cairo_font_face_destroy (user_font_face);
|
||||
return status;
|
||||
}
|
||||
|
||||
return user_font_face;
|
||||
*out = user_font_face;
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static cairo_test_status_t
|
||||
|
|
@ -150,6 +154,8 @@ draw (cairo_t *cr, int width, int height)
|
|||
const char text[] = TEXT;
|
||||
cairo_font_extents_t font_extents;
|
||||
cairo_text_extents_t extents;
|
||||
cairo_font_face_t *font_face;
|
||||
cairo_status_t status;
|
||||
|
||||
cairo_set_source_rgb (cr, 1, 1, 1);
|
||||
cairo_paint (cr);
|
||||
|
|
@ -159,7 +165,15 @@ draw (cairo_t *cr, int width, int height)
|
|||
cairo_rotate (cr, .6);
|
||||
#endif
|
||||
|
||||
cairo_set_font_face (cr, get_user_font_face ());
|
||||
status = _user_font_face_create (&font_face);
|
||||
if (status) {
|
||||
return cairo_test_status_from_status (cairo_test_get_context (cr),
|
||||
status);
|
||||
}
|
||||
|
||||
cairo_set_font_face (cr, font_face);
|
||||
cairo_font_face_destroy (font_face);
|
||||
|
||||
cairo_set_font_size (cr, TEXT_SIZE);
|
||||
|
||||
cairo_font_extents (cr, &font_extents);
|
||||
|
|
@ -200,11 +214,6 @@ draw (cairo_t *cr, int width, int height)
|
|||
cairo_text_path (cr, text);
|
||||
cairo_fill (cr);
|
||||
|
||||
if (user_font_face) {
|
||||
cairo_font_face_destroy (user_font_face);
|
||||
user_font_face = NULL;
|
||||
}
|
||||
|
||||
return CAIRO_TEST_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -145,8 +145,8 @@ test_scaled_font_render_glyph (cairo_scaled_font_t *scaled_font,
|
|||
return CAIRO_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static cairo_font_face_t *
|
||||
_user_font_face_create (void)
|
||||
static cairo_status_t
|
||||
_user_font_face_create (cairo_font_face_t **out)
|
||||
{
|
||||
/* Simple glyph definition: 1 - 15 means lineto (or moveto for first
|
||||
* point) for one of the points on this grid:
|
||||
|
|
@ -181,15 +181,23 @@ _user_font_face_create (void)
|
|||
};
|
||||
|
||||
cairo_font_face_t *user_font_face;
|
||||
cairo_status_t status;
|
||||
|
||||
user_font_face = cairo_user_font_face_create ();
|
||||
cairo_user_font_face_set_init_func (user_font_face, test_scaled_font_init);
|
||||
cairo_user_font_face_set_render_glyph_func (user_font_face, test_scaled_font_render_glyph);
|
||||
cairo_user_font_face_set_unicode_to_glyph_func (user_font_face, test_scaled_font_unicode_to_glyph);
|
||||
|
||||
cairo_font_face_set_user_data (user_font_face, &test_font_face_glyphs_key, (void*) glyphs, NULL);
|
||||
status = cairo_font_face_set_user_data (user_font_face,
|
||||
&test_font_face_glyphs_key,
|
||||
(void*) glyphs, NULL);
|
||||
if (status) {
|
||||
cairo_font_face_destroy (user_font_face);
|
||||
return status;
|
||||
}
|
||||
|
||||
return user_font_face;
|
||||
*out = user_font_face;
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static cairo_test_status_t
|
||||
|
|
@ -199,6 +207,7 @@ draw (cairo_t *cr, int width, int height)
|
|||
const char text[] = TEXT;
|
||||
cairo_font_extents_t font_extents;
|
||||
cairo_text_extents_t extents;
|
||||
cairo_status_t status;
|
||||
|
||||
cairo_set_source_rgb (cr, 1, 1, 1);
|
||||
cairo_paint (cr);
|
||||
|
|
@ -208,7 +217,12 @@ draw (cairo_t *cr, int width, int height)
|
|||
cairo_rotate (cr, .6);
|
||||
#endif
|
||||
|
||||
font_face = _user_font_face_create ();
|
||||
status = _user_font_face_create (&font_face);
|
||||
if (status) {
|
||||
return cairo_test_status_from_status (cairo_test_get_context (cr),
|
||||
status);
|
||||
}
|
||||
|
||||
cairo_set_font_face (cr, font_face);
|
||||
cairo_font_face_destroy (font_face);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue