diff --git a/doc/public/cairo-sections.txt b/doc/public/cairo-sections.txt index 3954c45b4..4b9cdc577 100644 --- a/doc/public/cairo-sections.txt +++ b/doc/public/cairo-sections.txt @@ -408,6 +408,10 @@ cairo_show_text_glyphs cairo_font_extents cairo_text_extents cairo_glyph_extents +cairo_toy_font_face_create +cairo_toy_font_face_get_family +cairo_toy_font_face_get_slant +cairo_toy_font_face_get_weight
diff --git a/doc/public/tmpl/cairo-status.sgml b/doc/public/tmpl/cairo-status.sgml index 37b5898c8..7d65bd543 100644 --- a/doc/public/tmpl/cairo-status.sgml +++ b/doc/public/tmpl/cairo-status.sgml @@ -68,6 +68,8 @@ code is required before or after each individual cairo function call. @CAIRO_STATUS_USER_FONT_ERROR: @CAIRO_STATUS_NEGATIVE_COUNT: @CAIRO_STATUS_INVALID_CLUSTERS: +@CAIRO_STATUS_INVALID_SLANT: +@CAIRO_STATUS_INVALID_WEIGHT: diff --git a/doc/public/tmpl/cairo-text.sgml b/doc/public/tmpl/cairo-text.sgml index 06e365ce1..3e5c6bb96 100644 --- a/doc/public/tmpl/cairo-text.sgml +++ b/doc/public/tmpl/cairo-text.sgml @@ -244,3 +244,41 @@ Cairo has two sets of text rendering capabilities: @extents: + + + + + +@family: +@slant: +@weight: +@Returns: + + + + + + + +@font_face: +@Returns: + + + + + + + +@font_face: +@Returns: + + + + + + + +@font_face: +@Returns: + + diff --git a/src/cairo-font-face.c b/src/cairo-font-face.c index 1d6739823..4f822a21c 100644 --- a/src/cairo-font-face.c +++ b/src/cairo-font-face.c @@ -41,19 +41,78 @@ #define _BSD_SOURCE /* for strdup() */ #include "cairoint.h" -/* Forward declare so we can use it as an arbitrary backend for - * _cairo_font_face_nil. - */ static const cairo_font_face_backend_t _cairo_toy_font_face_backend; /* #cairo_font_face_t */ -const cairo_font_face_t _cairo_font_face_nil = { - { 0 }, /* hash_entry */ - CAIRO_STATUS_NO_MEMORY, /* status */ +const cairo_toy_font_face_t _cairo_font_face_nil = { + { + { 0 }, /* hash_entry */ + CAIRO_STATUS_NO_MEMORY, /* status */ CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ - { 0, 0, 0, NULL }, /* user_data */ + { 0, 0, 0, NULL }, /* user_data */ &_cairo_toy_font_face_backend + }, + CAIRO_FONT_FAMILY_DEFAULT, /* family */ + TRUE, /* owns_family */ + CAIRO_FONT_SLANT_DEFAULT, /* slant */ + CAIRO_FONT_WEIGHT_DEFAULT /* weight */ +}; + +static const cairo_toy_font_face_t _cairo_font_face_null_pointer = { + { + { 0 }, /* hash_entry */ + CAIRO_STATUS_NULL_POINTER, /* status */ + CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ + { 0, 0, 0, NULL }, /* user_data */ + &_cairo_toy_font_face_backend + }, + CAIRO_FONT_FAMILY_DEFAULT, /* family */ + TRUE, /* owns_family */ + CAIRO_FONT_SLANT_DEFAULT, /* slant */ + CAIRO_FONT_WEIGHT_DEFAULT /* weight */ +}; + +static const cairo_toy_font_face_t _cairo_font_face_invalid_string = { + { + { 0 }, /* hash_entry */ + CAIRO_STATUS_INVALID_STRING, /* status */ + CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ + { 0, 0, 0, NULL }, /* user_data */ + &_cairo_toy_font_face_backend + }, + CAIRO_FONT_FAMILY_DEFAULT, /* family */ + TRUE, /* owns_family */ + CAIRO_FONT_SLANT_DEFAULT, /* slant */ + CAIRO_FONT_WEIGHT_DEFAULT /* weight */ +}; + +static const cairo_toy_font_face_t _cairo_font_face_invalid_slant = { + { + { 0 }, /* hash_entry */ + CAIRO_STATUS_INVALID_SLANT, /* status */ + CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ + { 0, 0, 0, NULL }, /* user_data */ + &_cairo_toy_font_face_backend + }, + CAIRO_FONT_FAMILY_DEFAULT, /* family */ + TRUE, /* owns_family */ + CAIRO_FONT_SLANT_DEFAULT, /* slant */ + CAIRO_FONT_WEIGHT_DEFAULT /* weight */ +}; + +static const cairo_toy_font_face_t _cairo_font_face_invalid_weight = { + { + { 0 }, /* hash_entry */ + CAIRO_STATUS_INVALID_WEIGHT, /* status */ + CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ + { 0, 0, 0, NULL }, /* user_data */ + &_cairo_toy_font_face_backend + }, + CAIRO_FONT_FAMILY_DEFAULT, /* family */ + TRUE, /* owns_family */ + CAIRO_FONT_SLANT_DEFAULT, /* slant */ + CAIRO_FONT_WEIGHT_DEFAULT /* weight */ }; cairo_status_t @@ -371,7 +430,7 @@ _cairo_toy_font_face_keys_equal (const void *key_a, } /** - * _cairo_toy_font_face_create: + * cairo_toy_font_face_create: * @family: a font family name, encoded in UTF-8 * @slant: the slant for the font * @weight: the weight for the font @@ -380,18 +439,57 @@ _cairo_toy_font_face_keys_equal (const void *key_a, * These font faces are used in implementation of the the #cairo_t "toy" * font API. * - * Return value: a newly created #cairo_font_face_t, destroy with - * cairo_font_face_destroy() + * If @family is the zero-length string "", the platform-specific default + * family is assumed. The default family then can be queried using + * cairo_toy_font_face_get_family(). + * + * The cairo_select_font_face() function uses this to create font faces. + * See that function for limitations of toy font faces. + * + * Return value: a newly created #cairo_font_face_t. Free with + * cairo_font_face_destroy() when you are done using it. + * + * Since: 1.8 **/ cairo_font_face_t * -_cairo_toy_font_face_create (const char *family, - cairo_font_slant_t slant, - cairo_font_weight_t weight) +cairo_toy_font_face_create (const char *family, + cairo_font_slant_t slant, + cairo_font_weight_t weight) { cairo_status_t status; cairo_toy_font_face_t key, *font_face; cairo_hash_table_t *hash_table; + if (family == NULL) + return (cairo_font_face_t*) &_cairo_font_face_null_pointer; + + /* Make sure we've got valid UTF-8 for the family */ + status = _cairo_utf8_to_ucs4 (family, -1, NULL, NULL); + if (status == CAIRO_STATUS_INVALID_STRING) + return (cairo_font_face_t*) &_cairo_font_face_invalid_string; + else if (status) + return (cairo_font_face_t*) &_cairo_font_face_nil; + + switch (slant) { + case CAIRO_FONT_SLANT_NORMAL: + case CAIRO_FONT_SLANT_ITALIC: + case CAIRO_FONT_SLANT_OBLIQUE: + break; + default: + return (cairo_font_face_t*) &_cairo_font_face_invalid_slant; + } + + switch (weight) { + case CAIRO_FONT_WEIGHT_NORMAL: + case CAIRO_FONT_WEIGHT_BOLD: + break; + default: + return (cairo_font_face_t*) &_cairo_font_face_invalid_weight; + } + + if (*family == '\0') + family = CAIRO_FONT_FAMILY_DEFAULT; + hash_table = _cairo_toy_font_face_hash_table_lock (); if (hash_table == NULL) goto UNWIND; @@ -444,6 +542,7 @@ _cairo_toy_font_face_create (const char *family, UNWIND: return (cairo_font_face_t*) &_cairo_font_face_nil; } +slim_hidden_def (cairo_toy_font_face_create); static void _cairo_toy_font_face_destroy (void *abstract_face) @@ -493,6 +592,77 @@ _cairo_toy_font_face_scaled_font_create (void *abstract_font_face scaled_font)); } +static cairo_bool_t +_cairo_font_face_is_toy (cairo_font_face_t *font_face) +{ + return font_face->backend == &_cairo_toy_font_face_backend; +} + +/** + * cairo_toy_font_face_get_family: + * @font_face: A toy font face + * + * Gets the familly name of a toy font. + * + * Return value: The family name. This string is owned by the font face + * and remains valid as long as the font face is alive (referenced). + * + * Since: 1.8 + **/ +const char * +cairo_toy_font_face_get_family (cairo_font_face_t *font_face) +{ + cairo_toy_font_face_t *toy_font_face = (cairo_toy_font_face_t *) font_face; + if (! _cairo_font_face_is_toy (font_face)) { + if (_cairo_font_face_set_error (font_face, CAIRO_STATUS_FONT_TYPE_MISMATCH)) + return CAIRO_FONT_FAMILY_DEFAULT; + } + assert (toy_font_face->owns_family); + return toy_font_face->family; +} + +/** + * cairo_toy_font_face_get_slant: + * @font_face: A toy font face + * + * Gets the slant a toy font. + * + * Return value: The slant value + * + * Since: 1.8 + **/ +cairo_font_slant_t +cairo_toy_font_face_get_slant (cairo_font_face_t *font_face) +{ + cairo_toy_font_face_t *toy_font_face = (cairo_toy_font_face_t *) font_face; + if (! _cairo_font_face_is_toy (font_face)) { + if (_cairo_font_face_set_error (font_face, CAIRO_STATUS_FONT_TYPE_MISMATCH)) + return CAIRO_FONT_SLANT_DEFAULT; + } + return toy_font_face->slant; +} + +/** + * cairo_toy_font_face_get_weight: + * @font_face: A toy font face + * + * Gets the weight a toy font. + * + * Return value: The weight value + * + * Since: 1.8 + **/ +cairo_font_weight_t +cairo_toy_font_face_get_weight (cairo_font_face_t *font_face) +{ + cairo_toy_font_face_t *toy_font_face = (cairo_toy_font_face_t *) font_face; + if (! _cairo_font_face_is_toy (font_face)) { + if (_cairo_font_face_set_error (font_face, CAIRO_STATUS_FONT_TYPE_MISMATCH)) + return CAIRO_FONT_WEIGHT_DEFAULT; + } + return toy_font_face->weight; +} + static const cairo_font_face_backend_t _cairo_toy_font_face_backend = { CAIRO_FONT_TYPE_TOY, _cairo_toy_font_face_destroy, diff --git a/src/cairo-gstate.c b/src/cairo-gstate.c index b9d59d3da..b23d0b69e 100644 --- a/src/cairo-gstate.c +++ b/src/cairo-gstate.c @@ -1215,7 +1215,7 @@ _cairo_gstate_select_font_face (cairo_gstate_t *gstate, cairo_font_face_t *font_face; cairo_status_t status; - font_face = _cairo_toy_font_face_create (family, slant, weight); + font_face = cairo_toy_font_face_create (family, slant, weight); if (font_face->status) return font_face->status; @@ -1389,7 +1389,7 @@ _cairo_gstate_ensure_font_face (cairo_gstate_t *gstate) return gstate->font_face->status; - font_face = _cairo_toy_font_face_create (CAIRO_FONT_FAMILY_DEFAULT, + font_face = cairo_toy_font_face_create (CAIRO_FONT_FAMILY_DEFAULT, CAIRO_FONT_SLANT_DEFAULT, CAIRO_FONT_WEIGHT_DEFAULT); if (font_face->status) diff --git a/src/cairo-misc.c b/src/cairo-misc.c index 71338bffe..3432e501f 100644 --- a/src/cairo-misc.c +++ b/src/cairo-misc.c @@ -113,6 +113,10 @@ cairo_status_to_string (cairo_status_t status) return "negative number used where it is not allowed"; case CAIRO_STATUS_INVALID_CLUSTERS: return "input clusters do not represent the accompanying text and glyph arrays"; + case CAIRO_STATUS_INVALID_SLANT: + return "invalid value for an input #cairo_font_slant_t"; + case CAIRO_STATUS_INVALID_WEIGHT: + return "input value for an input #cairo_font_weight_t"; } return ""; diff --git a/src/cairo-surface.c b/src/cairo-surface.c index ca703aa6a..3eca6fc34 100644 --- a/src/cairo-surface.c +++ b/src/cairo-surface.c @@ -2632,6 +2632,8 @@ _cairo_surface_create_in_error (cairo_status_t status) case CAIRO_STATUS_USER_FONT_ERROR: case CAIRO_STATUS_NEGATIVE_COUNT: case CAIRO_STATUS_INVALID_CLUSTERS: + case CAIRO_STATUS_INVALID_SLANT: + case CAIRO_STATUS_INVALID_WEIGHT: default: _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); return (cairo_surface_t *) &_cairo_surface_nil; diff --git a/src/cairo.c b/src/cairo.c index 46e587b1e..4151eedf1 100644 --- a/src/cairo.c +++ b/src/cairo.c @@ -2641,8 +2641,12 @@ cairo_copy_clip_rectangle_list (cairo_t *cr) * * If text is drawn without a call to cairo_select_font_face(), (nor * cairo_set_font_face() nor cairo_set_scaled_font()), the default - * family is "sans", slant is %CAIRO_FONT_SLANT_NORMAL, and weight is + * family is platform-specific, but is essentially "sans-serif". + * Default slant is %CAIRO_FONT_SLANT_NORMAL, and default weight is * %CAIRO_FONT_WEIGHT_NORMAL. + * + * This function is equivalent to a call to cairo_toy_font_face_create() + * followed by cairo_set_font_face(). **/ void cairo_select_font_face (cairo_t *cr, diff --git a/src/cairo.h b/src/cairo.h index 0829591e8..1be31ab9a 100644 --- a/src/cairo.h +++ b/src/cairo.h @@ -208,6 +208,8 @@ typedef struct _cairo_user_data_key { * @CAIRO_STATUS_USER_FONT_ERROR: error occurred in a user-font callback function (Since 1.8) * @CAIRO_STATUS_NEGATIVE_COUNT: negative number used where it is not allowed (Since 1.8) * @CAIRO_STATUS_INVALID_CLUSTERS: input clusters do not represent the accompanying text and glyph array (Since 1.8) + * @CAIRO_STATUS_INVALID_SLANT: invalid value for an input #cairo_font_slant_t (Since 1.8) + * @CAIRO_STATUS_INVALID_CLUSTERS: input value for an input #cairo_font_weight_t (Since 1.8) * * #cairo_status_t is used to indicate errors that can occur when * using Cairo. In some cases it is returned directly by functions. @@ -247,7 +249,9 @@ typedef enum _cairo_status { CAIRO_STATUS_USER_FONT_IMMUTABLE, CAIRO_STATUS_USER_FONT_ERROR, CAIRO_STATUS_NEGATIVE_COUNT, - CAIRO_STATUS_INVALID_CLUSTERS + CAIRO_STATUS_INVALID_CLUSTERS, + CAIRO_STATUS_INVALID_SLANT, + CAIRO_STATUS_INVALID_WEIGHT /* after adding a new error: update CAIRO_STATUS_LAST_STATUS in cairoint.h */ } cairo_status_t; @@ -1333,6 +1337,24 @@ cairo_public void cairo_scaled_font_get_font_options (cairo_scaled_font_t *scaled_font, cairo_font_options_t *options); + +/* Toy fonts */ + +cairo_public cairo_font_face_t * +cairo_toy_font_face_create (const char *family, + cairo_font_slant_t slant, + cairo_font_weight_t weight); + +cairo_public const char * +cairo_toy_font_face_get_family (cairo_font_face_t *font_face); + +cairo_public cairo_font_slant_t +cairo_toy_font_face_get_slant (cairo_font_face_t *font_face); + +cairo_public cairo_font_weight_t +cairo_toy_font_face_get_weight (cairo_font_face_t *font_face); + + /* User fonts */ cairo_public cairo_font_face_t * diff --git a/src/cairoint.h b/src/cairoint.h index 0f2177694..486a164db 100644 --- a/src/cairoint.h +++ b/src/cairoint.h @@ -110,7 +110,7 @@ _cairo_win32_tmpfile (void); * a bit of a pain, but it should be easy to always catch as long as * one adds a new test case to test a trigger of the new status value. */ -#define CAIRO_STATUS_LAST_STATUS CAIRO_STATUS_INVALID_CLUSTERS +#define CAIRO_STATUS_LAST_STATUS CAIRO_STATUS_INVALID_SLANT /* Size in bytes of buffer to use off the stack per functions. @@ -1304,7 +1304,7 @@ _cairo_color_equal (const cairo_color_t *color_a, /* cairo-font-face.c */ -extern const cairo_private cairo_font_face_t _cairo_font_face_nil; +extern const cairo_private cairo_toy_font_face_t _cairo_font_face_nil; cairo_private void _cairo_font_face_init (cairo_font_face_t *font_face, @@ -1314,11 +1314,6 @@ cairo_private cairo_status_t _cairo_font_face_set_error (cairo_font_face_t *font_face, cairo_status_t status); -cairo_private cairo_font_face_t * -_cairo_toy_font_face_create (const char *family, - cairo_font_slant_t slant, - cairo_font_weight_t weight); - cairo_private void _cairo_unscaled_font_init (cairo_unscaled_font_t *font, const cairo_unscaled_font_backend_t *backend); @@ -2447,6 +2442,7 @@ slim_hidden_proto (cairo_surface_set_fallback_resolution); slim_hidden_proto (cairo_surface_copy_page); slim_hidden_proto (cairo_surface_show_page); slim_hidden_proto (cairo_surface_status); +slim_hidden_proto (cairo_toy_font_face_create); slim_hidden_proto (cairo_version_string); #if CAIRO_HAS_PNG_FUNCTIONS diff --git a/test/.gitignore b/test/.gitignore index 4a72553dc..1edaff3d4 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -197,6 +197,7 @@ text-pattern text-rotate text-transform text-zero-len +toy-font-face transforms translate-show-surface trap-clip diff --git a/test/Makefile.am b/test/Makefile.am index f9ab75d44..5af7c0860 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -158,6 +158,7 @@ text-pattern$(EXEEXT) \ text-rotate$(EXEEXT) \ text-transform$(EXEEXT) \ text-zero-len$(EXEEXT) \ +toy-font-face$(EXEEXT) \ transforms$(EXEEXT) \ translate-show-surface$(EXEEXT) \ trap-clip$(EXEEXT) \ @@ -715,6 +716,7 @@ REFERENCE_IMAGES = \ user-font-pdf-ref.png \ user-font-svg-ref.png \ user-font-proxy-ref.png \ + user-font-proxy-pdf-ref.png \ user-font-proxy-ps-ref.png \ user-font-proxy-svg-ref.png \ unbounded-operator-quartz-ref.png \ @@ -764,6 +766,7 @@ png \ ps-features \ svg-clip \ svg-surface \ +toy-font-face \ user-data # A hook that summarises the failures diff --git a/test/toy-font-face.c b/test/toy-font-face.c new file mode 100644 index 000000000..262f7ce5f --- /dev/null +++ b/test/toy-font-face.c @@ -0,0 +1,129 @@ +/* + * Copyright © 2005,2008 Red Hat, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * Red Hat, Inc. not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior + * permission. Red Hat, Inc. makes no representations about the + * suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR + * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: Carl D. Worth + * Behdad Esfahbod + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include + +#if HAVE_FCFINI +#include +#endif + +int +main (void) +{ + cairo_t *cr; + cairo_surface_t *surface; + cairo_font_face_t *font_face; + + surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 0, 0); + cr = cairo_create (surface); + cairo_surface_destroy (surface); + + font_face = cairo_font_face_reference (cairo_get_font_face (cr)); + assert (cairo_font_face_get_type (font_face) == CAIRO_FONT_TYPE_TOY); + assert (cairo_toy_font_face_get_family (font_face) != NULL); + assert (cairo_toy_font_face_get_slant (font_face) == CAIRO_FONT_SLANT_NORMAL); + assert (cairo_toy_font_face_get_weight (font_face) == CAIRO_FONT_WEIGHT_NORMAL); + assert (cairo_font_face_status(font_face) == CAIRO_STATUS_SUCCESS); + cairo_font_face_destroy (font_face); + + cairo_select_font_face (cr, + "bizarre", + CAIRO_FONT_SLANT_OBLIQUE, + CAIRO_FONT_WEIGHT_BOLD); + font_face = cairo_font_face_reference (cairo_get_font_face (cr)); + assert (cairo_font_face_get_type (font_face) == CAIRO_FONT_TYPE_TOY); + assert (0 == (strcmp) (cairo_toy_font_face_get_family (font_face), "bizarre")); + assert (cairo_toy_font_face_get_slant (font_face) == CAIRO_FONT_SLANT_OBLIQUE); + assert (cairo_toy_font_face_get_weight (font_face) == CAIRO_FONT_WEIGHT_BOLD); + assert (cairo_font_face_status(font_face) == CAIRO_STATUS_SUCCESS); + cairo_font_face_destroy (font_face); + + font_face = cairo_toy_font_face_create ("bozarre", + CAIRO_FONT_SLANT_OBLIQUE, + CAIRO_FONT_WEIGHT_BOLD); + assert (cairo_font_face_get_type (font_face) == CAIRO_FONT_TYPE_TOY); + assert (0 == (strcmp) (cairo_toy_font_face_get_family (font_face), "bozarre")); + assert (cairo_toy_font_face_get_slant (font_face) == CAIRO_FONT_SLANT_OBLIQUE); + assert (cairo_toy_font_face_get_weight (font_face) == CAIRO_FONT_WEIGHT_BOLD); + assert (cairo_font_face_status(font_face) == CAIRO_STATUS_SUCCESS); + cairo_font_face_destroy (font_face); + + font_face = cairo_toy_font_face_create (NULL, + CAIRO_FONT_SLANT_OBLIQUE, + CAIRO_FONT_WEIGHT_BOLD); + assert (cairo_font_face_get_type (font_face) == CAIRO_FONT_TYPE_TOY); + assert (0 == (strcmp) (cairo_toy_font_face_get_family (font_face), "")); + assert (cairo_toy_font_face_get_slant (font_face) == CAIRO_FONT_SLANT_NORMAL); + assert (cairo_toy_font_face_get_weight (font_face) == CAIRO_FONT_WEIGHT_NORMAL); + assert (cairo_font_face_status(font_face) == CAIRO_STATUS_NULL_POINTER); + cairo_font_face_destroy (font_face); + + font_face = cairo_toy_font_face_create ("\xff", + CAIRO_FONT_SLANT_OBLIQUE, + CAIRO_FONT_WEIGHT_BOLD); + assert (cairo_font_face_get_type (font_face) == CAIRO_FONT_TYPE_TOY); + assert (0 == (strcmp) (cairo_toy_font_face_get_family (font_face), "")); + assert (cairo_toy_font_face_get_slant (font_face) == CAIRO_FONT_SLANT_NORMAL); + assert (cairo_toy_font_face_get_weight (font_face) == CAIRO_FONT_WEIGHT_NORMAL); + assert (cairo_font_face_status(font_face) == CAIRO_STATUS_INVALID_STRING); + cairo_font_face_destroy (font_face); + + font_face = cairo_toy_font_face_create ("sans", + -1, + CAIRO_FONT_WEIGHT_BOLD); + assert (cairo_font_face_get_type (font_face) == CAIRO_FONT_TYPE_TOY); + assert (0 == (strcmp) (cairo_toy_font_face_get_family (font_face), "")); + assert (cairo_toy_font_face_get_slant (font_face) == CAIRO_FONT_SLANT_NORMAL); + assert (cairo_toy_font_face_get_weight (font_face) == CAIRO_FONT_WEIGHT_NORMAL); + assert (cairo_font_face_status(font_face) == CAIRO_STATUS_INVALID_SLANT); + cairo_font_face_destroy (font_face); + + font_face = cairo_toy_font_face_create ("sans", + CAIRO_FONT_SLANT_OBLIQUE, + -1); + assert (cairo_font_face_get_type (font_face) == CAIRO_FONT_TYPE_TOY); + assert (0 == (strcmp) (cairo_toy_font_face_get_family (font_face), "")); + assert (cairo_toy_font_face_get_slant (font_face) == CAIRO_FONT_SLANT_NORMAL); + assert (cairo_toy_font_face_get_weight (font_face) == CAIRO_FONT_WEIGHT_NORMAL); + assert (cairo_font_face_status(font_face) == CAIRO_STATUS_INVALID_WEIGHT); + cairo_font_face_destroy (font_face); + + cairo_destroy (cr); + + cairo_debug_reset_static_data (); +#if HAVE_FCFINI + FcFini (); +#endif + + return 0; +} diff --git a/test/user-font-proxy-pdf-ref.png b/test/user-font-proxy-pdf-ref.png new file mode 100644 index 000000000..0eda0f420 Binary files /dev/null and b/test/user-font-proxy-pdf-ref.png differ diff --git a/test/user-font-proxy-ps-ref.png b/test/user-font-proxy-ps-ref.png index 78bee6c05..4305411b9 100644 Binary files a/test/user-font-proxy-ps-ref.png and b/test/user-font-proxy-ps-ref.png differ diff --git a/test/user-font-proxy.c b/test/user-font-proxy.c index f54139cee..c7b29abdf 100644 --- a/test/user-font-proxy.c +++ b/test/user-font-proxy.c @@ -51,42 +51,43 @@ cairo_test_t test = { draw }; -static cairo_user_data_key_t fallback_scaled_font_key; +static cairo_user_data_key_t fallback_font_face_key; static cairo_status_t test_scaled_font_init (cairo_scaled_font_t *scaled_font, cairo_font_extents_t *extents) { - cairo_t *cr; - cairo_surface_t *surface; - cairo_matrix_t ctm; + cairo_font_face_t *font_face; + cairo_matrix_t font_matrix, ctm; cairo_font_options_t *font_options; cairo_scaled_font_t *fallback_scaled_font; - /* painful way to get default font face used by toy api */ - surface = cairo_image_surface_create (CAIRO_FORMAT_A8, 0, 0); - cr = cairo_create (surface); - cairo_surface_destroy (surface); + font_face = cairo_toy_font_face_create ("", + CAIRO_FONT_SLANT_NORMAL, + CAIRO_FONT_WEIGHT_NORMAL); - cairo_set_font_size (cr, 1.); + cairo_matrix_init_identity (&font_matrix); cairo_scaled_font_get_scale_matrix (scaled_font, &ctm); - cairo_set_matrix (cr, &ctm); font_options = cairo_font_options_create (); cairo_scaled_font_get_font_options (scaled_font, font_options); - cairo_set_font_options (cr, font_options); + + fallback_scaled_font = cairo_scaled_font_create (font_face, + &font_matrix, + &ctm, + font_options); + cairo_font_options_destroy (font_options); - fallback_scaled_font = cairo_scaled_font_reference (cairo_get_scaled_font (cr)), - cairo_scaled_font_set_user_data (scaled_font, - &fallback_scaled_font_key, - fallback_scaled_font, - cairo_scaled_font_destroy); - - cairo_destroy (cr); - cairo_scaled_font_extents (fallback_scaled_font, extents); + cairo_scaled_font_destroy (fallback_scaled_font); + + cairo_scaled_font_set_user_data (scaled_font, + &fallback_font_face_key, + font_face, + cairo_font_face_destroy); + return CAIRO_STATUS_SUCCESS; } @@ -101,9 +102,9 @@ test_scaled_font_render_glyph (cairo_scaled_font_t *scaled_font, /* XXX only works for ASCII. need ucs4_to_utf8 :( */ text[0] = glyph; - cairo_set_scaled_font (cr, - cairo_scaled_font_get_user_data (scaled_font, - &fallback_scaled_font_key)); + cairo_set_font_face (cr, + cairo_scaled_font_get_user_data (scaled_font, + &fallback_font_face_key)); cairo_show_text (cr, text); cairo_text_extents (cr, text, extents);