[pango] Factor out translation of CTFontDescriptor into seperate function



commit 76124c029f4262831f0c8eaca802b45179c407da
Author: Kristian Rietveld <kris gtk org>
Date:   Sat Mar 6 11:16:09 2010 +0100

    Factor out translation of CTFontDescriptor into seperate function

 pango/pangocoretext-fontmap.c |  113 ++++++++++++++++++++++-------------------
 1 files changed, 61 insertions(+), 52 deletions(-)
---
diff --git a/pango/pangocoretext-fontmap.c b/pango/pangocoretext-fontmap.c
index b8cf671..67a7209 100644
--- a/pango/pangocoretext-fontmap.c
+++ b/pango/pangocoretext-fontmap.c
@@ -145,6 +145,65 @@ pango_coverage_from_cf_charset (CFCharacterSetRef charset)
   return coverage;
 }
 
+static inline PangoCoreTextFace *
+pango_core_text_face_from_ct_font_descriptor (CTFontDescriptorRef desc)
+{
+  int font_traits;
+  char *buffer;
+  CFStringRef str;
+  CFNumberRef number;
+  CGFloat value;
+  CFDictionaryRef dict;
+  CFCharacterSetRef charset;
+  PangoCoreTextFace *face = g_object_new (PANGO_TYPE_CORE_TEXT_FACE,
+                                          NULL);
+
+  /* Get font name */
+  str = CTFontDescriptorCopyAttribute (desc, kCTFontNameAttribute);
+  buffer = gchar_from_cf_string (str);
+
+  /* We strdup again to save space. */
+  face->postscript_name = g_strdup (buffer);
+
+  CFRelease (str);
+  g_free (buffer);
+
+  /* Get style name */
+  str = CTFontDescriptorCopyAttribute (desc, kCTFontStyleNameAttribute);
+  buffer = gchar_from_cf_string (str);
+
+  face->style_name = g_strdup (buffer);
+
+  CFRelease (str);
+  g_free (buffer);
+
+  /* Get font traits, symbolic traits */
+  dict = CTFontDescriptorCopyAttribute (desc, kCTFontTraitsAttribute);
+  number = (CFNumberRef)CFDictionaryGetValue (dict,
+                                              kCTFontWeightTrait);
+  if (CFNumberGetValue (number, kCFNumberCGFloatType, &value))
+    /* Map value from range [-1.0, 1.0] to range [1, 14] */
+    face->weight = (value + 1.0f) * 6.5f + 1;
+  else
+    face->weight = PANGO_WEIGHT_NORMAL;
+
+  number = (CFNumberRef)CFDictionaryGetValue (dict,
+                                              kCTFontSymbolicTrait);
+  if (CFNumberGetValue (number, kCFNumberIntType, &font_traits))
+    {
+      face->traits = font_traits;
+    }
+  CFRelease (dict);
+
+  /* Get font coverage */
+  charset = CTFontDescriptorCopyAttribute (desc,
+                                           kCTFontCharacterSetAttribute);
+  face->coverage = pango_coverage_from_cf_charset (charset);
+  CFRelease (charset);
+
+  return face;
+}
+
 static void
 pango_core_text_family_list_faces (PangoFontFamily  *family,
                                    PangoFontFace  ***faces,
@@ -195,62 +254,12 @@ pango_core_text_family_list_faces (PangoFontFamily  *family,
       count = CFArrayGetCount (ctfaces);
       for (i = 0; i < count; i++)
         {
-          int font_traits;
-          char *buffer;
-          CFStringRef str;
-          CFNumberRef number;
-          CGFloat value;
-          CFDictionaryRef dict;
-          CFCharacterSetRef charset;
+          PangoCoreTextFace *face;
           CTFontDescriptorRef desc = CFArrayGetValueAtIndex (ctfaces, i);
-          PangoCoreTextFace *face = g_object_new (PANGO_TYPE_CORE_TEXT_FACE,
-                                                  NULL);
 
+          face = pango_core_text_face_from_ct_font_descriptor (desc);
           face->family = ctfamily;
 
-          /* Get font name */
-          str = CTFontDescriptorCopyAttribute (desc, kCTFontNameAttribute);
-          buffer = gchar_from_cf_string (str);
-
-          /* We strdup again to save space. */
-          face->postscript_name = g_strdup (buffer);
-
-          CFRelease (str);
-          g_free (buffer);
-
-          /* Get style name */
-          str = CTFontDescriptorCopyAttribute (desc, kCTFontStyleNameAttribute);
-          buffer = gchar_from_cf_string (str);
-
-          face->style_name = g_strdup (buffer);
-
-          CFRelease (str);
-          g_free (buffer);
-
-          /* Get font traits, symbolic traits */
-          dict = CTFontDescriptorCopyAttribute (desc, kCTFontTraitsAttribute);
-          number = (CFNumberRef)CFDictionaryGetValue (dict,
-                                                      kCTFontWeightTrait);
-          if (CFNumberGetValue (number, kCFNumberCGFloatType, &value))
-            /* Map value from range [-1.0, 1.0] to range [1, 14] */
-            face->weight = (value + 1.0f) * 6.5f + 1;
-          else
-            face->weight = PANGO_WEIGHT_NORMAL;
-
-          number = (CFNumberRef)CFDictionaryGetValue (dict,
-                                                      kCTFontSymbolicTrait);
-          if (CFNumberGetValue (number, kCFNumberIntType, &font_traits))
-            {
-              face->traits = font_traits;
-            }
-          CFRelease (dict);
-
-          /* Get font coverage */
-          charset = CTFontDescriptorCopyAttribute (desc,
-                                                   kCTFontCharacterSetAttribute);
-          face->coverage = pango_coverage_from_cf_charset (charset);
-          CFRelease (charset);
-
           faces = g_list_prepend (faces, face);
         }
 



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