mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-05-08 10:18:02 +02:00
Add toy font constructor and getters
New public API: cairo_toy_font_face_create() cairo_toy_font_face_get_family() cairo_toy_font_face_get_slant() cairo_toy_font_face_get_weight()
This commit is contained in:
parent
bca9a21e98
commit
7e57892983
16 changed files with 422 additions and 46 deletions
|
|
@ -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
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
||||
<!-- ##### FUNCTION cairo_status_to_string ##### -->
|
||||
<para>
|
||||
|
|
|
|||
|
|
@ -244,3 +244,41 @@ Cairo has two sets of text rendering capabilities:
|
|||
@extents:
|
||||
|
||||
|
||||
<!-- ##### FUNCTION cairo_toy_font_face_create ##### -->
|
||||
<para>
|
||||
|
||||
</para>
|
||||
|
||||
@family:
|
||||
@slant:
|
||||
@weight:
|
||||
@Returns:
|
||||
|
||||
|
||||
<!-- ##### FUNCTION cairo_toy_font_face_get_family ##### -->
|
||||
<para>
|
||||
|
||||
</para>
|
||||
|
||||
@font_face:
|
||||
@Returns:
|
||||
|
||||
|
||||
<!-- ##### FUNCTION cairo_toy_font_face_get_slant ##### -->
|
||||
<para>
|
||||
|
||||
</para>
|
||||
|
||||
@font_face:
|
||||
@Returns:
|
||||
|
||||
|
||||
<!-- ##### FUNCTION cairo_toy_font_face_get_weight ##### -->
|
||||
<para>
|
||||
|
||||
</para>
|
||||
|
||||
@font_face:
|
||||
@Returns:
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 "<unknown error status>";
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
24
src/cairo.h
24
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 *
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
1
test/.gitignore
vendored
1
test/.gitignore
vendored
|
|
@ -197,6 +197,7 @@ text-pattern
|
|||
text-rotate
|
||||
text-transform
|
||||
text-zero-len
|
||||
toy-font-face
|
||||
transforms
|
||||
translate-show-surface
|
||||
trap-clip
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
129
test/toy-font-face.c
Normal file
129
test/toy-font-face.c
Normal file
|
|
@ -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 <cworth@cworth.org>
|
||||
* Behdad Esfahbod <behdad@behdad.org>
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <cairo.h>
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if HAVE_FCFINI
|
||||
#include <fontconfig/fontconfig.h>
|
||||
#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;
|
||||
}
|
||||
BIN
test/user-font-proxy-pdf-ref.png
Normal file
BIN
test/user-font-proxy-pdf-ref.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.9 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 8.3 KiB After Width: | Height: | Size: 7.1 KiB |
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue