[gtk+/wip/css: 80/125] shorthand: Do font parsing the new way



commit bdeaa75f4c9a8418077080b7233727e15e26abd0
Author: Benjamin Otte <otte redhat com>
Date:   Mon Jan 2 09:19:27 2012 +0100

    shorthand: Do font parsing the new way

 gtk/gtkcssshorthandpropertyimpl.c |   57 ++++++++++++++++++++++++++++++++++++-
 1 files changed, 56 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtkcssshorthandpropertyimpl.c b/gtk/gtkcssshorthandpropertyimpl.c
index e89633d..94b2532 100644
--- a/gtk/gtkcssshorthandpropertyimpl.c
+++ b/gtk/gtkcssshorthandpropertyimpl.c
@@ -210,6 +210,61 @@ parse_border_image (GtkCssShorthandProperty *shorthand,
   return TRUE;
 }
 
+static gboolean
+parse_font (GtkCssShorthandProperty *shorthand,
+            GValue                  *values,
+            GtkCssParser            *parser,
+            GFile                   *base)
+{
+  PangoFontDescription *desc;
+  guint mask;
+  char *str;
+
+  str = _gtk_css_parser_read_value (parser);
+  if (str == NULL)
+    return FALSE;
+
+  desc = pango_font_description_from_string (str);
+  g_free (str);
+
+  mask = pango_font_description_get_set_fields (desc);
+
+  if (mask & PANGO_FONT_MASK_FAMILY)
+    {
+      GPtrArray *strv = g_ptr_array_new ();
+
+      g_ptr_array_add (strv, g_strdup (pango_font_description_get_family (desc)));
+      g_ptr_array_add (strv, NULL);
+      g_value_init (&values[0], G_TYPE_STRV);
+      g_value_take_boxed (&values[0], g_ptr_array_free (strv, FALSE));
+    }
+  if (mask & PANGO_FONT_MASK_STYLE)
+    {
+      g_value_init (&values[1], PANGO_TYPE_STYLE);
+      g_value_set_enum (&values[1], pango_font_description_get_style (desc));
+    }
+  if (mask & PANGO_FONT_MASK_VARIANT)
+    {
+      g_value_init (&values[2], PANGO_TYPE_VARIANT);
+      g_value_set_enum (&values[2], pango_font_description_get_variant (desc));
+    }
+  if (mask & PANGO_FONT_MASK_WEIGHT)
+    {
+      g_value_init (&values[3], PANGO_TYPE_WEIGHT);
+      g_value_set_enum (&values[3], pango_font_description_get_weight (desc));
+    }
+  if (mask & PANGO_FONT_MASK_SIZE)
+    {
+      g_value_init (&values[4], G_TYPE_DOUBLE);
+      g_value_set_double (&values[4],
+                          (double) pango_font_description_get_size (desc) / PANGO_SCALE);
+    }
+
+  pango_font_description_free (desc);
+
+  return TRUE;
+}
+
 /*** PACKING ***/
 
 static GParameter *
@@ -591,7 +646,7 @@ _gtk_css_shorthand_property_init_properties (void)
   _gtk_css_shorthand_property_register   ("font",
                                           PANGO_TYPE_FONT_DESCRIPTION,
                                           font_subproperties,
-                                          NULL,
+                                          parse_font,
                                           unpack_font_description,
                                           pack_font_description,
                                           NULL);



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