Pango API extension: pango_font_matches_description



Hi,

I'm working on a glyph cache that works with Pango and I got it 
working with the current Pango API using pango_font_describe()
and pango_font_description_equal(). Since I have to call these 
functions for each glyph I lookup in my cache, the fact that 
these calls create a new PangoFontDescription by copying it from
the internal structs introduces a significant performance problem. 

As a solution I propose the addition of a new method in the 
PangoFont class: pango_font_matches_description() which is passed
a PangoFont and a PangoFontDescription and does the comparison 
in place.

Below is a patch that I would like to see included. Owen, if you 
like this, please give me a "Go" for committing this to CVS.


Salut, Sven

Index: pango/pango-font.h
===================================================================
RCS file: /cvs/gnome/pango/pango/pango-font.h,v
retrieving revision 1.19
diff -u -r1.19 pango-font.h
--- pango/pango-font.h	2001/02/28 21:15:15	1.19
+++ pango/pango-font.h	2001/03/12 12:49:48
@@ -100,7 +100,8 @@
 void                  pango_font_description_free        (PangoFontDescription        *desc);
 void                  pango_font_descriptions_free       (PangoFontDescription       **descs,
 							  int                          n_descs);
-
+gboolean              pango_font_matches_description     (const PangoFont             *font,
+                                                          const PangoFontDescription  *desc);
 PangoFontDescription *pango_font_description_from_string (const char                  *str);
 char *                pango_font_description_to_string   (const PangoFontDescription  *desc);
 char *                pango_font_description_to_filename (const PangoFontDescription  *desc);
@@ -128,8 +129,10 @@
   GObjectClass parent_class;
   
   PangoFontDescription *(*describe)           (PangoFont      *font);
+  gboolean              (*matches_description)(PangoFont                  *font,
+                                               const PangoFontDescription *desc);
   PangoCoverage *       (*get_coverage)       (PangoFont      *font,
-					      const char      *lang);
+					       const char      *lang);
   PangoEngineShape *    (*find_shaper)        (PangoFont      *font,
 					       const char     *lang,
 					       guint32         ch);
Index: pango/pangoft2.c
===================================================================
RCS file: /cvs/gnome/pango/pango/pangoft2.c,v
retrieving revision 1.16
diff -u -r1.16 pangoft2.c
--- pango/pangoft2.c	2001/03/12 00:42:41	1.16
+++ pango/pangoft2.c	2001/03/12 12:49:48
@@ -65,6 +65,8 @@
 static void pango_ft2_font_finalize   (GObject         *object);
 
 static PangoFontDescription *pango_ft2_font_describe          (PangoFont            *font);
+static gboolean            pango_ft2_font_matches_description (PangoFont                  *font,
+                                                               const PangoFontDescription *desc);
 
 static PangoCoverage *       pango_ft2_font_get_coverage      (PangoFont            *font,
 							       const char           *lang);
@@ -227,6 +229,7 @@
   object_class->shutdown = pango_ft2_font_shutdown;
   
   font_class->describe = pango_ft2_font_describe;
+  font_class->matches_description = pango_ft2_font_matches_description;
   font_class->get_coverage = pango_ft2_font_get_coverage;
   font_class->find_shaper = pango_ft2_font_find_shaper;
   font_class->get_glyph_extents = pango_ft2_font_get_glyph_extents;
@@ -869,6 +872,24 @@
   desc->size = ft2font->size;
 
   return desc;
+}
+
+static gboolean
+pango_ft2_font_matches_description (PangoFont                  *font,
+                                    const PangoFontDescription *desc)
+{
+  PangoFT2Font         *ft2font;
+  PangoFontDescription *target;
+
+  ft2font = PANGO_FT2_FONT (font);
+  target  = &ft2font->entry->description;
+
+  return (desc->style == target->style &&
+	  desc->variant == target->variant &&
+	  desc->weight == target->weight &&
+	  desc->stretch == target->stretch &&
+	  desc->size == ft2font->size &&
+	  !g_strcasecmp (desc->family_name, target->family_name));
 }
 
 PangoMap *
Index: pango/pangox.c
===================================================================
RCS file: /cvs/gnome/pango/pango/pangox.c,v
retrieving revision 1.54
diff -u -r1.54 pangox.c
--- pango/pangox.c	2001/03/08 01:49:48	1.54
+++ pango/pangox.c	2001/03/12 12:49:48
@@ -155,6 +155,8 @@
 static void pango_x_font_finalize   (GObject         *object);
 
 static PangoFontDescription *pango_x_font_describe          (PangoFont        *font);
+static gboolean  pango_x_font_matches_description (PangoFont                  *font,
+                                                   const PangoFontDescription *desc);
 static PangoCoverage *       pango_x_font_get_coverage      (PangoFont        *font,
 							     const char       *lang);
 static PangoEngineShape *    pango_x_font_find_shaper       (PangoFont        *font,
@@ -354,6 +356,7 @@
   object_class->shutdown = pango_x_font_shutdown;
   
   font_class->describe = pango_x_font_describe;
+  font_class->matches_description = pango_x_font_matches_description;
   font_class->get_coverage = pango_x_font_get_coverage;
   font_class->find_shaper = pango_x_font_find_shaper;
   font_class->get_glyph_extents = pango_x_font_get_glyph_extents;
@@ -1154,6 +1157,14 @@
 {
   /* FIXME: implement */
   return NULL;
+}
+
+static gboolean
+pango_x_font_matches_description (PangoFont                  *font,
+                                  const PangoFontDescription *desc)
+{
+  /* FIXME: implement */
+  return FALSE;
 }
 
 PangoMap *



 




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]