summaryrefslogtreecommitdiff
path: root/src/cairo-user-font.c
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@behdad.org>2008-09-25 04:27:11 -0400
committerBehdad Esfahbod <behdad@behdad.org>2008-09-25 19:25:11 -0400
commitd5a998387bcee6569d33375d592190f480f12712 (patch)
tree39bc97984de1e8448bb08a971739858429ad07dc /src/cairo-user-font.c
parentdd7e2461ce748403e121a5de5e4e4c8890e39236 (diff)
Add an internal font face
The font data and rendering is adapted from Keith Packard's Twin window system. The hinting stuff is not ported yet, but hey, it renders! The implementation uses user fonts, and the user font backend is modified to use this font face (which we call "twin" font face internally) when a toy font is needed. The font face layer is then modified to use this font if: - The toy font face "cairo" is asked for, or - No native font backend is available, or - The preferred native font backend fails to return a font with STATUS_UNSUPPORTED. No font backend does this right now but the idea is to change FreeType to return it if no fonts found on the system. We also allow building with no font backends now! The new doc/tutorial/src/twin.c file tests the twin face at various sizes.
Diffstat (limited to 'src/cairo-user-font.c')
-rw-r--r--src/cairo-user-font.c53
1 files changed, 48 insertions, 5 deletions
diff --git a/src/cairo-user-font.c b/src/cairo-user-font.c
index 0f46c58e..40b2a2fa 100644
--- a/src/cairo-user-font.c
+++ b/src/cairo-user-font.c
@@ -96,8 +96,6 @@ _cairo_user_scaled_font_create_meta_context (cairo_user_scaled_font_t *scaled_fo
return cr;
}
-static const cairo_scaled_font_backend_t cairo_user_scaled_font_backend;
-
static cairo_int_status_t
_cairo_user_scaled_glyph_init (void *abstract_font,
cairo_scaled_glyph_t *scaled_glyph,
@@ -321,9 +319,54 @@ _cairo_user_text_to_glyphs (void *abstract_font,
return status;
}
-static const cairo_scaled_font_backend_t cairo_user_scaled_font_backend = {
+static cairo_status_t
+_cairo_user_font_face_scaled_font_create (void *abstract_face,
+ const cairo_matrix_t *font_matrix,
+ const cairo_matrix_t *ctm,
+ const cairo_font_options_t *options,
+ 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_status_t status;
+ cairo_font_face_t *face;
+
+ static cairo_user_data_key_t twin_font_face_key;
+
+ face = cairo_font_face_get_user_data (&toy_face->base,
+ &twin_font_face_key);
+ if (!face) {
+ face = _cairo_font_face_twin_create (cairo_toy_font_face_get_slant (&toy_face->base),
+ cairo_toy_font_face_get_weight (&toy_face->base));
+
+ status = cairo_font_face_set_user_data (&toy_face->base,
+ &twin_font_face_key,
+ face,
+ (cairo_destroy_func_t) cairo_font_face_destroy);
+
+ if (status) {
+ cairo_font_face_destroy (face);
+ return status;
+ }
+ }
+
+ status = _cairo_user_font_face_scaled_font_create (face,
+ font_matrix,
+ ctm,
+ font_options,
+ font);
+
+ return status;
+}
+
+const cairo_scaled_font_backend_t _cairo_user_scaled_font_backend = {
CAIRO_FONT_TYPE_USER,
- NULL, /* create_toy */
+ _cairo_user_scaled_font_create_toy, /* create_toy */
NULL, /* scaled_font_fini */
_cairo_user_scaled_glyph_init,
_cairo_user_text_to_glyphs,
@@ -356,7 +399,7 @@ _cairo_user_font_face_scaled_font_create (void *abstract_
status = _cairo_scaled_font_init (&user_scaled_font->base,
&font_face->base,
font_matrix, ctm, options,
- &cairo_user_scaled_font_backend);
+ &_cairo_user_scaled_font_backend);
if (status) {
free (user_scaled_font);