[cairo-commit] cairo/src cairo-ft-font.c,1.93,1.94

Carl Worth commit at pdx.freedesktop.org
Fri Aug 5 23:41:43 PDT 2005


Committed by: cworth

Update of /cvs/cairo/cairo/src
In directory gabe:/tmp/cvs-serv13913/src

Modified Files:
	cairo-ft-font.c 
Log Message:

2005-08-05  Carl Worth  <cworth at cworth.org>

        * src/cairo-ft-font.c: (_cairo_ft_unscaled_font_init),
        (_cairo_ft_unscaled_font_create_from_face),
        (_cairo_ft_unscaled_font_create_from_filename): Unify
        initialization for _cairo_ft_unscaled_font_create_from_face and
        _cairo_ft_unscaled_font_create_from_filename through new
        _cairo_ft_unscaled_font_init.


Index: cairo-ft-font.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-ft-font.c,v
retrieving revision 1.93
retrieving revision 1.94
diff -u -d -r1.93 -r1.94
--- cairo-ft-font.c	6 Aug 2005 05:37:29 -0000	1.93
+++ cairo-ft-font.c	6 Aug 2005 06:41:41 -0000	1.94
@@ -121,26 +121,79 @@
 
 const cairo_unscaled_font_backend_t cairo_ft_unscaled_font_backend;
 
-static cairo_ft_unscaled_font_t *
-_cairo_ft_unscaled_font_create_from_face (FT_Face face)
+/**
+ * _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)
 {
-    cairo_ft_unscaled_font_t *unscaled = malloc (sizeof (cairo_ft_unscaled_font_t));
-    if (!unscaled)
-	return NULL;
-	
-    unscaled->from_face = 1;
-    unscaled->face = face;
+    char *filename_copy = NULL;
+
+    if (filename) {
+	filename_copy = strdup (filename);
+	if (filename_copy == NULL)
+	    return CAIRO_STATUS_NO_MEMORY;
+    }
+
+    unscaled->filename = filename_copy;
+    unscaled->id = id;
+
+    if (face) {
+	unscaled->from_face = 1;
+	unscaled->face = face;
+    } else {
+	unscaled->from_face = 0;
+	unscaled->face = NULL;
+    }
 
-    unscaled->filename = NULL;
-    unscaled->id = 0;
-    
     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;
 }
 
@@ -154,32 +207,19 @@
 _cairo_ft_unscaled_font_create_from_filename (const char *filename,
 					      int         id)
 {
+    cairo_status_t status;
     cairo_ft_unscaled_font_t *unscaled;
-    char *new_filename;
     
-    new_filename = strdup (filename);
-    if (!new_filename)
+    unscaled = malloc (sizeof (cairo_ft_unscaled_font_t));
+    if (unscaled == NULL)
 	return NULL;
 
-    unscaled = malloc (sizeof (cairo_ft_unscaled_font_t));
-    if (!unscaled) {
-	free (new_filename);
+    status = _cairo_ft_unscaled_font_init (unscaled, filename, id, NULL);
+    if (status) {
+	free (unscaled);
 	return NULL;
     }
-	
-    unscaled->from_face = 0;
-    unscaled->face = NULL;
-
-    unscaled->filename = new_filename;
-    unscaled->id = id;
-    
-    unscaled->have_scale = 0;
-    unscaled->lock = 0;
-    
-    unscaled->faces = NULL;
 
-    _cairo_unscaled_font_init (&unscaled->base,
-			       &cairo_ft_unscaled_font_backend);
     return unscaled;
 }
 




More information about the cairo-commit mailing list