mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-01-09 00:40:22 +01:00
Map toy font face to implementation.
Quartz fonts and user fonts use an indirect font face when creating a scaled font for the toy font face. This means that they insert a scaled font into the font map that has a different font face to the one that is initially searched upon. The result is that when we try to create an identical scaled font, we fail to find the existing scaled font and attempt to insert a duplicate into the hash table - which triggers an assert. In order to avoid creating duplicate fonts, we add a new method to the font backends that allows cairo_scaled_font_create() to peek at the font_face that will be used to actually implement the scaled font constructor - thus we are able to use the correct font_face as part of the hash key.
This commit is contained in:
parent
5e4a1cb0b8
commit
954ebacb71
7 changed files with 128 additions and 21 deletions
|
|
@ -568,6 +568,39 @@ _cairo_toy_font_face_destroy (void *abstract_face)
|
|||
_cairo_toy_font_face_fini (font_face);
|
||||
}
|
||||
|
||||
static cairo_status_t
|
||||
_cairo_toy_font_face_scaled_font_get_implementation (void *abstract_font_face,
|
||||
cairo_font_face_t **font_face_out)
|
||||
{
|
||||
cairo_toy_font_face_t *font_face = abstract_font_face;
|
||||
cairo_status_t status;
|
||||
|
||||
if (font_face->base.status)
|
||||
return font_face->base.status;
|
||||
|
||||
if (CAIRO_SCALED_FONT_BACKEND_DEFAULT != &_cairo_user_scaled_font_backend &&
|
||||
0 != strcmp (font_face->family, CAIRO_USER_FONT_FAMILY_DEFAULT))
|
||||
{
|
||||
const cairo_scaled_font_backend_t * backend = CAIRO_SCALED_FONT_BACKEND_DEFAULT;
|
||||
|
||||
if (backend->get_implementation == NULL) {
|
||||
*font_face_out = &font_face->base;
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
status = backend->get_implementation (font_face,
|
||||
font_face_out);
|
||||
|
||||
if (status != CAIRO_INT_STATUS_UNSUPPORTED)
|
||||
return _cairo_font_face_set_error (&font_face->base, status);
|
||||
}
|
||||
|
||||
status = _cairo_user_scaled_font_backend.get_implementation (font_face,
|
||||
font_face_out);
|
||||
|
||||
return _cairo_font_face_set_error (&font_face->base, status);
|
||||
}
|
||||
|
||||
static cairo_status_t
|
||||
_cairo_toy_font_face_scaled_font_create (void *abstract_font_face,
|
||||
const cairo_matrix_t *font_matrix,
|
||||
|
|
@ -689,6 +722,7 @@ slim_hidden_def (cairo_toy_font_face_get_weight);
|
|||
static const cairo_font_face_backend_t _cairo_toy_font_face_backend = {
|
||||
CAIRO_FONT_TYPE_TOY,
|
||||
_cairo_toy_font_face_destroy,
|
||||
_cairo_toy_font_face_scaled_font_get_implementation,
|
||||
_cairo_toy_font_face_scaled_font_create
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -2211,6 +2211,7 @@ _cairo_ft_index_to_ucs4(void *abstract_font,
|
|||
|
||||
const cairo_scaled_font_backend_t _cairo_ft_scaled_font_backend = {
|
||||
CAIRO_FONT_TYPE_FT,
|
||||
NULL,
|
||||
_cairo_ft_scaled_font_create_toy,
|
||||
_cairo_ft_scaled_font_fini,
|
||||
_cairo_ft_scaled_glyph_init,
|
||||
|
|
@ -2317,6 +2318,7 @@ _cairo_ft_font_face_scaled_font_create (void *abstract_face,
|
|||
static const cairo_font_face_backend_t _cairo_ft_font_face_backend = {
|
||||
CAIRO_FONT_TYPE_FT,
|
||||
_cairo_ft_font_face_destroy,
|
||||
NULL, /* direct implementation */
|
||||
_cairo_ft_font_face_scaled_font_create
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -225,6 +225,7 @@ FINISH:
|
|||
static const cairo_font_face_backend_t _cairo_quartz_font_face_backend = {
|
||||
CAIRO_FONT_TYPE_QUARTZ,
|
||||
_cairo_quartz_font_face_destroy,
|
||||
NULL, /* direct implementation */
|
||||
_cairo_quartz_font_face_scaled_font_create
|
||||
};
|
||||
|
||||
|
|
@ -277,24 +278,27 @@ _cairo_quartz_scaled_to_face (void *abstract_font)
|
|||
}
|
||||
|
||||
static cairo_status_t
|
||||
_cairo_quartz_font_create_toy(cairo_toy_font_face_t *toy_face,
|
||||
const cairo_matrix_t *font_matrix,
|
||||
const cairo_matrix_t *ctm,
|
||||
const cairo_font_options_t *options,
|
||||
cairo_scaled_font_t **font_out)
|
||||
_cairo_quartz_font_get_implementation (cairo_toy_font_face_t *toy_face,
|
||||
cairo_scaled_font_t **font_face_out)
|
||||
{
|
||||
static cairo_user_data_key_t impl_font_face_key;
|
||||
cairo_font_face_t *face;
|
||||
cairo_status_t status;
|
||||
const char *family = toy_face->family;
|
||||
char *full_name = malloc(strlen(family) + 64); // give us a bit of room to tack on Bold, Oblique, etc.
|
||||
CFStringRef cgFontName = NULL;
|
||||
CGFontRef cgFont = NULL;
|
||||
int loop;
|
||||
|
||||
cairo_status_t status;
|
||||
cairo_font_face_t *face;
|
||||
cairo_scaled_font_t *scaled_font;
|
||||
face = cairo_font_face_get_user_data (&toy_face->base,
|
||||
&impl_font_face_key);
|
||||
if (face) {
|
||||
*font_face_out = face;
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
quartz_font_ensure_symbols();
|
||||
if (!_cairo_quartz_font_symbols_present)
|
||||
if (! _cairo_quartz_font_symbols_present)
|
||||
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
|
||||
|
||||
/* handle CSS-ish faces */
|
||||
|
|
@ -345,7 +349,7 @@ _cairo_quartz_font_create_toy(cairo_toy_font_face_t *toy_face,
|
|||
|
||||
if (!cgFont) {
|
||||
/* Give up */
|
||||
return CAIRO_STATUS_NO_MEMORY;
|
||||
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
|
||||
}
|
||||
|
||||
face = cairo_quartz_font_face_create_for_cgfont (cgFont);
|
||||
|
|
@ -354,6 +358,35 @@ _cairo_quartz_font_create_toy(cairo_toy_font_face_t *toy_face,
|
|||
if (face->status)
|
||||
return face->status;
|
||||
|
||||
status = cairo_font_face_set_user_data (&toy_face->base,
|
||||
&impl_font_face_key,
|
||||
face,
|
||||
(cairo_destroy_func_t) cairo_font_face_destroy);
|
||||
|
||||
if (status) {
|
||||
cairo_font_face_destroy (face);
|
||||
return status;
|
||||
}
|
||||
|
||||
*font_face_out = face;
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static cairo_status_t
|
||||
_cairo_quartz_font_create_toy (cairo_toy_font_face_t *toy_face,
|
||||
const cairo_matrix_t *font_matrix,
|
||||
const cairo_matrix_t *ctm,
|
||||
const cairo_font_options_t *options,
|
||||
cairo_scaled_font_t **font_out)
|
||||
{
|
||||
cairo_font_face_t *face;
|
||||
cairo_scaled_font_t *scaled_font;
|
||||
cairo_status_t status;
|
||||
|
||||
status = _cairo_quartz_font_get_implementation (toy_face, &face);
|
||||
if (status)
|
||||
return status;
|
||||
|
||||
status = _cairo_quartz_font_face_scaled_font_create (face,
|
||||
font_matrix, ctm,
|
||||
options,
|
||||
|
|
@ -363,7 +396,6 @@ _cairo_quartz_font_create_toy(cairo_toy_font_face_t *toy_face,
|
|||
return status;
|
||||
|
||||
*font_out = scaled_font;
|
||||
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
@ -743,6 +775,7 @@ _cairo_quartz_ucs4_to_index (void *abstract_font,
|
|||
|
||||
const cairo_scaled_font_backend_t _cairo_quartz_scaled_font_backend = {
|
||||
CAIRO_FONT_TYPE_QUARTZ,
|
||||
_cairo_quartz_font_get_implementation,
|
||||
_cairo_quartz_font_create_toy,
|
||||
_cairo_quartz_font_fini,
|
||||
_cairo_quartz_font_scaled_glyph_init,
|
||||
|
|
|
|||
|
|
@ -772,6 +772,7 @@ cairo_scaled_font_create (cairo_font_face_t *font_face,
|
|||
const cairo_font_options_t *options)
|
||||
{
|
||||
cairo_status_t status;
|
||||
cairo_font_face_t *impl_face;
|
||||
cairo_scaled_font_map_t *font_map;
|
||||
cairo_scaled_font_t key, *old = NULL, *scaled_font = NULL;
|
||||
|
||||
|
|
@ -785,11 +786,19 @@ cairo_scaled_font_create (cairo_font_face_t *font_face,
|
|||
/* Note that degenerate ctm or font_matrix *are* allowed.
|
||||
* We want to support a font size of 0. */
|
||||
|
||||
if (font_face->backend->get_implementation != NULL) {
|
||||
/* indirect implementation, lookup the face that is used for the key */
|
||||
status = font_face->backend->get_implementation (font_face, &impl_face);
|
||||
if (status)
|
||||
return _cairo_scaled_font_create_in_error (status);
|
||||
} else
|
||||
impl_face = font_face;
|
||||
|
||||
font_map = _cairo_scaled_font_map_lock ();
|
||||
if (font_map == NULL)
|
||||
return _cairo_scaled_font_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
|
||||
|
||||
_cairo_scaled_font_init_key (&key, font_face,
|
||||
_cairo_scaled_font_init_key (&key, impl_face,
|
||||
font_matrix, ctm, options);
|
||||
scaled_font = font_map->mru_scaled_font;
|
||||
if (scaled_font != NULL &&
|
||||
|
|
|
|||
|
|
@ -337,17 +337,14 @@ _cairo_user_font_face_scaled_font_create (void *abstract_
|
|||
cairo_scaled_font_t **scaled_font);
|
||||
|
||||
static cairo_status_t
|
||||
_cairo_user_scaled_font_create_toy (cairo_toy_font_face_t *toy_face,
|
||||
const cairo_matrix_t *font_matrix,
|
||||
const cairo_matrix_t *ctm,
|
||||
const cairo_font_options_t *font_options,
|
||||
cairo_scaled_font_t **font)
|
||||
_cairo_user_scaled_font_get_implementation (cairo_toy_font_face_t *toy_face,
|
||||
cairo_font_face_t **font_face_out)
|
||||
{
|
||||
cairo_status_t status;
|
||||
cairo_font_face_t *face;
|
||||
|
||||
static cairo_user_data_key_t twin_font_face_key;
|
||||
|
||||
cairo_font_face_t *face;
|
||||
cairo_status_t status;
|
||||
|
||||
face = cairo_font_face_get_user_data (&toy_face->base,
|
||||
&twin_font_face_key);
|
||||
if (!face) {
|
||||
|
|
@ -365,17 +362,38 @@ _cairo_user_scaled_font_create_toy (cairo_toy_font_face_t *toy_face,
|
|||
}
|
||||
}
|
||||
|
||||
*font_face_out = face;
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static cairo_status_t
|
||||
_cairo_user_scaled_font_create_toy (cairo_toy_font_face_t *toy_face,
|
||||
const cairo_matrix_t *font_matrix,
|
||||
const cairo_matrix_t *ctm,
|
||||
const cairo_font_options_t *font_options,
|
||||
cairo_scaled_font_t **font)
|
||||
{
|
||||
cairo_font_face_t *face;
|
||||
cairo_status_t status;
|
||||
|
||||
status = _cairo_user_scaled_font_get_implementation (toy_face, &face);
|
||||
if (status)
|
||||
return status;
|
||||
|
||||
status = _cairo_user_font_face_scaled_font_create (face,
|
||||
font_matrix,
|
||||
ctm,
|
||||
font_options,
|
||||
font);
|
||||
if (status)
|
||||
return status;
|
||||
|
||||
return status;
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
const cairo_scaled_font_backend_t _cairo_user_scaled_font_backend = {
|
||||
CAIRO_FONT_TYPE_USER,
|
||||
_cairo_user_scaled_font_get_implementation,
|
||||
_cairo_user_scaled_font_create_toy, /* create_toy */
|
||||
NULL, /* scaled_font_fini */
|
||||
_cairo_user_scaled_glyph_init,
|
||||
|
|
@ -501,6 +519,7 @@ _cairo_user_font_face_scaled_font_create (void *abstract_
|
|||
static const cairo_font_face_backend_t _cairo_user_font_face_backend = {
|
||||
CAIRO_FONT_TYPE_USER,
|
||||
NULL, /* destroy */
|
||||
NULL, /* direct implementation */
|
||||
_cairo_user_font_face_scaled_font_create
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1835,6 +1835,7 @@ _cairo_win32_scaled_font_init_glyph_path (cairo_win32_scaled_font_t *scaled_font
|
|||
|
||||
const cairo_scaled_font_backend_t _cairo_win32_scaled_font_backend = {
|
||||
CAIRO_FONT_TYPE_WIN32,
|
||||
NULL,
|
||||
_cairo_win32_scaled_font_create_toy,
|
||||
_cairo_win32_scaled_font_fini,
|
||||
_cairo_win32_scaled_font_glyph_init,
|
||||
|
|
@ -1904,6 +1905,7 @@ _cairo_win32_font_face_scaled_font_create (void *abstract_face,
|
|||
static const cairo_font_face_backend_t _cairo_win32_font_face_backend = {
|
||||
CAIRO_FONT_TYPE_WIN32,
|
||||
_cairo_win32_font_face_destroy,
|
||||
NULL, /* direct implementation */
|
||||
_cairo_win32_font_face_scaled_font_create
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -411,6 +411,10 @@ typedef struct _cairo_scaled_font_subset {
|
|||
struct _cairo_scaled_font_backend {
|
||||
cairo_font_type_t type;
|
||||
|
||||
cairo_warn cairo_status_t
|
||||
(*get_implementation) (cairo_toy_font_face_t *toy_face,
|
||||
cairo_font_face_t **font_face);
|
||||
|
||||
cairo_warn cairo_status_t
|
||||
(*create_toy) (cairo_toy_font_face_t *toy_face,
|
||||
const cairo_matrix_t *font_matrix,
|
||||
|
|
@ -483,6 +487,10 @@ struct _cairo_font_face_backend {
|
|||
void
|
||||
(*destroy) (void *font_face);
|
||||
|
||||
cairo_warn cairo_status_t
|
||||
(*get_implementation) (void *font_face,
|
||||
cairo_font_face_t **font_face_out);
|
||||
|
||||
cairo_warn cairo_status_t
|
||||
(*scaled_font_create) (void *font_face,
|
||||
const cairo_matrix_t *font_matrix,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue