[cairo-commit] cairo/src cairo-ft-font.c,1.98,1.99
Carl Worth
commit at pdx.freedesktop.org
Sat Aug 13 02:02:41 PDT 2005
Committed by: cworth
Update of /cvs/cairo/cairo/src
In directory gabe:/tmp/cvs-serv7485/src
Modified Files:
cairo-ft-font.c
Log Message:
2005-08-13 Carl Worth <cworth at cworth.org>
* src/cairo-ft-font.c: (_cairo_ft_unscaled_font_map_create),
(_cairo_ft_unscaled_font_init_key), (_cairo_ft_unscaled_font_init),
(_cairo_unscaled_font_is_ft), (_cairo_ft_unscaled_font_fini),
(_cairo_ft_unscaled_font_keys_equal),
(_cairo_ft_unscaled_font_create_from_face),
(_cairo_ft_unscaled_font_destroy): Shuffle functions around to put
them in a sane order within the file. There should be no
functional change here.
Index: cairo-ft-font.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-ft-font.c,v
retrieving revision 1.98
retrieving revision 1.99
diff -u -d -r1.98 -r1.99
--- cairo-ft-font.c 11 Aug 2005 21:49:07 -0000 1.98
+++ cairo-ft-font.c 13 Aug 2005 09:02:39 -0000 1.99
@@ -117,11 +117,6 @@
void *key_b);
static void
-_cairo_ft_unscaled_font_init_key (cairo_ft_unscaled_font_t *key,
- char *filename,
- int id);
-
-static void
_cairo_ft_unscaled_font_fini (cairo_ft_unscaled_font_t *unscaled);
struct _cairo_ft_font_face {
@@ -131,96 +126,8 @@
cairo_ft_font_face_t *next;
};
-static cairo_font_face_t *
-_cairo_ft_font_face_create (cairo_ft_unscaled_font_t *unscaled,
- int load_flags);
-
-static void
-_cairo_ft_font_face_destroy (void *abstract_face);
-
const cairo_unscaled_font_backend_t cairo_ft_unscaled_font_backend;
-/**
- * _cairo_ft_unscaled_font_init:
- *
- * Initialize a cairo_ft_unscaled_font_t.
- *
- * There are two basic flavors of cairo_ft_unscaled_font_t, one
- * created from an FT_Face and the other created from a filename/id
- * pair. These two flavors are identified as from_face and !from_face.
- *
- * To initialize a from_face font, pass filename==NULL, id=0 and the
- * desired face.
- *
- * To initialize a !from_face font, pass the filename/id as desired
- * and face==NULL.
- *
- * Note that the code handles these two flavors in very distinct
- * ways. For example there is a hash_table mapping
- * filename/id->cairo_unscaled_font_t in the !from_face case, but no
- * parallel in the from_face case, (where the calling code would have
- * to do its own mapping to ensure similar sharing).
- **/
-static cairo_status_t
-_cairo_ft_unscaled_font_init (cairo_ft_unscaled_font_t *unscaled,
- const char *filename,
- int id,
- FT_Face face)
-{
- char *filename_copy = NULL;
-
- if (filename) {
- filename_copy = strdup (filename);
- if (filename_copy == NULL)
- return CAIRO_STATUS_NO_MEMORY;
- }
-
- _cairo_ft_unscaled_font_init_key (unscaled, filename_copy, id);
-
- if (face) {
- unscaled->from_face = 1;
- unscaled->face = face;
- } else {
- unscaled->from_face = 0;
- unscaled->face = NULL;
- }
-
- unscaled->have_scale = 0;
- unscaled->lock = 0;
-
- unscaled->faces = NULL;
-
- _cairo_unscaled_font_init (&unscaled->base,
- &cairo_ft_unscaled_font_backend);
-
- return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_ft_unscaled_font_t *
-_cairo_ft_unscaled_font_create_from_face (FT_Face face)
-{
- cairo_status_t status;
- cairo_ft_unscaled_font_t *unscaled;
-
- unscaled = malloc (sizeof (cairo_ft_unscaled_font_t));
- if (unscaled == NULL)
- return NULL;
-
- status = _cairo_ft_unscaled_font_init (unscaled, NULL, 0, face);
- if (status) {
- free (unscaled);
- return NULL;
- }
-
- return unscaled;
-}
-
-cairo_bool_t
-_cairo_unscaled_font_is_ft (cairo_unscaled_font_t *unscaled_font)
-{
- return unscaled_font->backend == &cairo_ft_unscaled_font_backend;
-}
-
/*
* We maintain a hash table to map file/id => cairo_ft_unscaled_font_t.
* The hash table itself isn't limited in size. However, we limit the
@@ -230,57 +137,52 @@
* there are any).
*/
-static void
-_cairo_ft_unscaled_font_init_key (cairo_ft_unscaled_font_t *key,
- char *filename,
- int id)
-{
- unsigned long hash;
+typedef struct _cairo_ft_unscaled_font_map {
+ cairo_hash_table_t *hash_table;
+ FT_Library ft_library;
+ int num_open_faces;
+} cairo_ft_unscaled_font_map_t;
- key->filename = filename;
- key->id = id;
+static cairo_ft_unscaled_font_map_t *cairo_ft_unscaled_font_map = NULL;
- /* 1607 is just an arbitrary prime. */
- hash = _cairo_hash_string (filename);
- hash += ((unsigned long) id) * 1607;
-
- key->base.hash_entry.hash = hash;
-}
+CAIRO_MUTEX_DECLARE(cairo_ft_unscaled_font_map_mutex);
-static int
-_cairo_ft_unscaled_font_keys_equal (void *key_a,
- void *key_b)
+static void
+_cairo_ft_unscaled_font_map_create (void)
{
- cairo_ft_unscaled_font_t *unscaled_a = key_a;
- cairo_ft_unscaled_font_t *unscaled_b = key_b;
+ cairo_ft_unscaled_font_map_t *font_map;
- return (strcmp (unscaled_a->filename, unscaled_b->filename) == 0 &&
- unscaled_a->id == unscaled_b->id);
-}
+ /* This function is only intended to be called from
+ * _cairo_ft_unscaled_font_map_lock. So we'll crash if we can
+ * detect some other call path. */
+ assert (cairo_ft_unscaled_font_map == NULL);
-static void
-_cairo_ft_unscaled_font_fini (cairo_ft_unscaled_font_t *unscaled)
-{
- if (unscaled->filename) {
- free (unscaled->filename);
- unscaled->filename = NULL;
- }
+ font_map = malloc (sizeof (cairo_ft_unscaled_font_map_t));
+ if (font_map == NULL)
+ goto FAIL;
- if (unscaled->face) {
- FT_Done_Face (unscaled->face);
- unscaled->face = NULL;
- }
-}
+ font_map->hash_table =
+ _cairo_hash_table_create (_cairo_ft_unscaled_font_keys_equal);
-typedef struct _cairo_ft_unscaled_font_map {
- cairo_hash_table_t *hash_table;
- FT_Library ft_library;
- int num_open_faces;
-} cairo_ft_unscaled_font_map_t;
+ if (font_map->hash_table == NULL)
+ goto FAIL;
-static cairo_ft_unscaled_font_map_t *cairo_ft_unscaled_font_map = NULL;
+ if (FT_Init_FreeType (&font_map->ft_library))
+ goto FAIL;
-CAIRO_MUTEX_DECLARE(cairo_ft_unscaled_font_map_mutex);
+ font_map->num_open_faces = 0;
+
+ cairo_ft_unscaled_font_map = font_map;
+ return;
+
+FAIL:
+ if (font_map) {
+ if (font_map->hash_table)
+ _cairo_hash_table_destroy (font_map->hash_table);
+ free (font_map);
+ }
+ cairo_ft_unscaled_font_map = NULL;
+}
static void
_cairo_ft_unscaled_font_map_destroy (void)
@@ -320,9 +222,6 @@
CAIRO_MUTEX_UNLOCK (cairo_ft_unscaled_font_map_mutex);
}
-static void
-_cairo_ft_unscaled_font_map_create (void);
-
static cairo_ft_unscaled_font_map_t *
_cairo_ft_unscaled_font_map_lock (void)
{
@@ -348,40 +247,107 @@
}
static void
-_cairo_ft_unscaled_font_map_create (void)
+_cairo_ft_unscaled_font_init_key (cairo_ft_unscaled_font_t *key,
+ char *filename,
+ int id)
{
- cairo_ft_unscaled_font_map_t *font_map;
+ unsigned long hash;
- /* This function is only intended to be called from
- * _cairo_ft_unscaled_font_map_lock. So we'll crash if we can
- * detect some other call path. */
- assert (cairo_ft_unscaled_font_map == NULL);
+ key->filename = filename;
+ key->id = id;
- font_map = malloc (sizeof (cairo_ft_unscaled_font_map_t));
- if (font_map == NULL)
- goto FAIL;
+ /* 1607 is just an arbitrary prime. */
+ hash = _cairo_hash_string (filename);
+ hash += ((unsigned long) id) * 1607;
+
+ key->base.hash_entry.hash = hash;
+}
- font_map->hash_table =
- _cairo_hash_table_create (_cairo_ft_unscaled_font_keys_equal);
+/**
+ * _cairo_ft_unscaled_font_init:
+ *
+ * Initialize a cairo_ft_unscaled_font_t.
+ *
+ * There are two basic flavors of cairo_ft_unscaled_font_t, one
+ * created from an FT_Face and the other created from a filename/id
+ * pair. These two flavors are identified as from_face and !from_face.
+ *
+ * To initialize a from_face font, pass filename==NULL, id=0 and the
+ * desired face.
+ *
+ * To initialize a !from_face font, pass the filename/id as desired
+ * and face==NULL.
+ *
+ * Note that the code handles these two flavors in very distinct
+ * ways. For example there is a hash_table mapping
+ * filename/id->cairo_unscaled_font_t in the !from_face case, but no
+ * parallel in the from_face case, (where the calling code would have
+ * to do its own mapping to ensure similar sharing).
+ **/
+static cairo_status_t
+_cairo_ft_unscaled_font_init (cairo_ft_unscaled_font_t *unscaled,
+ const char *filename,
+ int id,
+ FT_Face face)
+{
+ char *filename_copy = NULL;
- if (font_map->hash_table == NULL)
- goto FAIL;
+ if (filename) {
+ filename_copy = strdup (filename);
+ if (filename_copy == NULL)
+ return CAIRO_STATUS_NO_MEMORY;
+ }
- if (FT_Init_FreeType (&font_map->ft_library))
- goto FAIL;
+ _cairo_ft_unscaled_font_init_key (unscaled, filename_copy, id);
- font_map->num_open_faces = 0;
+ if (face) {
+ unscaled->from_face = 1;
+ unscaled->face = face;
+ } else {
+ unscaled->from_face = 0;
+ unscaled->face = NULL;
+ }
- cairo_ft_unscaled_font_map = font_map;
- return;
+ unscaled->have_scale = 0;
+ unscaled->lock = 0;
+
+ unscaled->faces = NULL;
-FAIL:
- if (font_map) {
- if (font_map->hash_table)
- _cairo_hash_table_destroy (font_map->hash_table);
- free (font_map);
+ _cairo_unscaled_font_init (&unscaled->base,
+ &cairo_ft_unscaled_font_backend);
+
+ return CAIRO_STATUS_SUCCESS;
+}
+
+cairo_bool_t
+_cairo_unscaled_font_is_ft (cairo_unscaled_font_t *unscaled_font)
+{
+ return unscaled_font->backend == &cairo_ft_unscaled_font_backend;
+}
+
+static void
+_cairo_ft_unscaled_font_fini (cairo_ft_unscaled_font_t *unscaled)
+{
+ if (unscaled->filename) {
+ free (unscaled->filename);
+ unscaled->filename = NULL;
}
- cairo_ft_unscaled_font_map = NULL;
+
+ if (unscaled->face) {
+ FT_Done_Face (unscaled->face);
+ unscaled->face = NULL;
+ }
+}
+
+static int
+_cairo_ft_unscaled_font_keys_equal (void *key_a,
+ void *key_b)
+{
+ cairo_ft_unscaled_font_t *unscaled_a = key_a;
+ cairo_ft_unscaled_font_t *unscaled_b = key_b;
+
+ return (strcmp (unscaled_a->filename, unscaled_b->filename) == 0 &&
+ unscaled_a->id == unscaled_b->id);
}
/* Finds or creates a cairo_ft_unscaled_font for the filename/id from
@@ -447,6 +413,55 @@
return NULL;
}
+static cairo_ft_unscaled_font_t *
+_cairo_ft_unscaled_font_create_from_face (FT_Face face)
+{
+ cairo_status_t status;
+ cairo_ft_unscaled_font_t *unscaled;
+
+ unscaled = malloc (sizeof (cairo_ft_unscaled_font_t));
+ if (unscaled == NULL)
+ return NULL;
+
+ status = _cairo_ft_unscaled_font_init (unscaled, NULL, 0, face);
+ if (status) {
+ free (unscaled);
+ return NULL;
+ }
+
+ return unscaled;
+}
+
+static void
+_cairo_ft_unscaled_font_destroy (void *abstract_font)
+{
+ cairo_ft_unscaled_font_t *unscaled = abstract_font;
+
+ if (unscaled == NULL)
+ return;
+
+ if (unscaled->from_face) {
+ /* See comments in _ft_font_face_destroy about the "zombie" state
+ * for a _ft_font_face.
+ */
+ if (unscaled->faces && !unscaled->faces->unscaled)
+ cairo_font_face_destroy (&unscaled->faces->base);
+ } else {
+ cairo_ft_unscaled_font_map_t *font_map;
+
+ font_map = _cairo_ft_unscaled_font_map_lock ();
+ /* All created objects must have been mapped in the font map. */
+ assert (font_map != NULL);
+
+ _cairo_hash_table_remove (font_map->hash_table,
+ &unscaled->base.hash_entry);
+
+ _cairo_ft_unscaled_font_map_unlock ();
+
+ _cairo_ft_unscaled_font_fini (unscaled);
+ }
+}
+
static cairo_bool_t
_has_unlocked_face (void *entry)
{
@@ -636,36 +651,6 @@
assert (error == 0);
}
-static void
-_cairo_ft_unscaled_font_destroy (void *abstract_font)
-{
- cairo_ft_unscaled_font_t *unscaled = abstract_font;
-
- if (unscaled == NULL)
- return;
-
- if (unscaled->from_face) {
- /* See comments in _ft_font_face_destroy about the "zombie" state
- * for a _ft_font_face.
- */
- if (unscaled->faces && !unscaled->faces->unscaled)
- cairo_font_face_destroy (&unscaled->faces->base);
- } else {
- cairo_ft_unscaled_font_map_t *font_map;
-
- font_map = _cairo_ft_unscaled_font_map_lock ();
- /* All created objects must have been mapped in the font map. */
- assert (font_map != NULL);
-
- _cairo_hash_table_remove (font_map->hash_table,
- &unscaled->base.hash_entry);
-
- _cairo_ft_unscaled_font_map_unlock ();
-
- _cairo_ft_unscaled_font_fini (unscaled);
- }
-}
-
/* Empirically-derived subpixel filtering values thanks to Keith
* Packard and libXft. */
static const int filters[3][3] = {
More information about the cairo-commit
mailing list