]> Pileus Git - ~andy/gtk/commitdiff
cssvalue: Do a hacky conversion of font-size to a number value
authorBenjamin Otte <otte@redhat.com>
Fri, 30 Mar 2012 01:51:25 +0000 (03:51 +0200)
committerBenjamin Otte <otte@redhat.com>
Tue, 17 Apr 2012 06:59:15 +0000 (08:59 +0200)
Just store the value as px for now.

The font-size property needs a complete makeover anyway.

gtk/gtkcssnumbervalue.c
gtk/gtkcssshorthandpropertyimpl.c
gtk/gtkcssstylepropertyimpl.c
gtk/gtkcsstypes.c
gtk/gtkcssvalue.c
gtk/gtkcssvalueprivate.h

index e845a686c662c355dd08bfd6aab6a30767880406..19e4c1d198bc5019ae396dafc13f1063c0c4a960 100644 (file)
@@ -173,12 +173,14 @@ _gtk_css_number_value_compute (GtkCssValue     *number,
                                         GTK_CSS_PX);
       break;
     case GTK_CSS_EM:
-      return _gtk_css_number_value_new (number->value * _gtk_css_value_get_double (_gtk_style_context_peek_property (context, "font-size")),
+      return _gtk_css_number_value_new (number->value *
+                                        _gtk_css_number_value_get (_gtk_style_context_peek_property (context, "font-size"), 100),
                                         GTK_CSS_PX);
       break;
     case GTK_CSS_EX:
       /* for now we pretend ex is half of em */
-      return _gtk_css_number_value_new (number->value * 0.5 * _gtk_css_value_get_double (_gtk_style_context_peek_property (context, "font-size")),
+      return _gtk_css_number_value_new (number->value * 0.5 * 
+                                        _gtk_css_number_value_get (_gtk_style_context_peek_property (context, "font-size"), 100),
                                         GTK_CSS_PX);
     case GTK_CSS_RAD:
       return _gtk_css_number_value_new (number->value * 360.0 / (2 * G_PI),
index 05b8fba23d4f750423f64a5c986e22d93f7ca6bf..7bba8786c71aad2a9e8554ce65fa63ce0eb0b4c9 100644 (file)
@@ -451,7 +451,7 @@ parse_font (GtkCssShorthandProperty  *shorthand,
     }
   if (mask & PANGO_FONT_MASK_SIZE)
     {
-      values[4] = _gtk_css_value_new_from_double ((double) pango_font_description_get_size (desc) / PANGO_SCALE);
+      values[4] = _gtk_css_number_value_new ((double) pango_font_description_get_size (desc) / PANGO_SCALE, GTK_CSS_PX);
     }
 
   pango_font_description_free (desc);
@@ -743,7 +743,7 @@ pack_font_description (GtkCssShorthandProperty *shorthand,
 
   v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-size"))), query_data);
   if (v)
-    pango_font_description_set_size (description, round (_gtk_css_value_get_double (v) * PANGO_SCALE));
+    pango_font_description_set_size (description, round (_gtk_css_number_value_get (v, 100) * PANGO_SCALE));
 
   v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-style"))), query_data);
   if (v)
index 5f3cc455fa1547d16baa1f42befc379846e4b9fd..64356825f05dd0d021f59f449cffef30e3bdcfd8 100644 (file)
@@ -128,6 +128,22 @@ assign_length_from_int (GtkCssStyleProperty *property,
   return _gtk_css_number_value_new (g_value_get_int (value), GTK_CSS_PX);
 }
 
+static void
+query_length_as_double (GtkCssStyleProperty *property,
+                        const GtkCssValue   *css_value,
+                        GValue              *value)
+{
+  g_value_init (value, G_TYPE_DOUBLE);
+  g_value_set_double (value, _gtk_css_number_value_get (css_value, 100));
+}
+
+static GtkCssValue *
+assign_length_from_double (GtkCssStyleProperty *property,
+                           const GValue        *value)
+{
+  return _gtk_css_number_value_new (g_value_get_double (value), GTK_CSS_PX);
+}
+
 static GtkCssValue *
 color_parse (GtkCssStyleProperty *property,
              GtkCssParser        *parser,
@@ -619,7 +635,15 @@ font_size_parse (GtkCssStyleProperty *property,
       return NULL;
     }
 
-  return _gtk_css_value_new_from_double (d);
+  return _gtk_css_number_value_new (d, GTK_CSS_PX);
+}
+
+static GtkCssValue *
+font_size_compute (GtkCssStyleProperty *property,
+                   GtkStyleContext     *context,
+                   GtkCssValue         *specified)
+{
+  return _gtk_css_number_value_compute (specified, context);
 }
 
 static GtkCssValue *
@@ -1192,11 +1216,12 @@ _gtk_css_style_property_init_properties (void)
                                           GTK_STYLE_PROPERTY_INHERIT,
                                           font_size_parse,
                                           NULL,
+                                          font_size_compute,
+                                          query_length_as_double,
+                                          assign_length_from_double,
                                           NULL,
-                                          query_simple,
-                                          assign_simple,
-                                          NULL,
-                                          _gtk_css_value_new_from_double (10.0));
+                                          /* XXX: This should be 'normal' */
+                                          _gtk_css_number_value_new (10.0, GTK_CSS_PX));
 
   /* properties that aren't referenced when computing values
    * start here */
index a47f8d3edd54abf2841b086371757eeda5367a07..411f401693d34190626f53379121854c2efb6075 100644 (file)
@@ -18,6 +18,8 @@
 #include "config.h"
 
 #include "gtkcsstypesprivate.h"
+
+#include "gtkcssnumbervalueprivate.h"
 #include "gtkstylecontextprivate.h"
 
 #define DEFINE_BOXED_TYPE_WITH_COPY_FUNC(TypeName, type_name) \
@@ -156,12 +158,12 @@ _gtk_css_number_compute (GtkCssNumber       *dest,
       dest->unit = GTK_CSS_PX;
       break;
     case GTK_CSS_EM:
-      dest->value = src->value * _gtk_css_value_get_double (_gtk_style_context_peek_property (context, "font-size"));
+      dest->value = src->value * _gtk_css_number_value_get (_gtk_style_context_peek_property (context, "font-size"), 100);
       dest->unit = GTK_CSS_PX;
       break;
     case GTK_CSS_EX:
       /* for now we pretend ex is half of em */
-      dest->value = src->value * _gtk_css_value_get_double (_gtk_style_context_peek_property (context, "font-size"));
+      dest->value = src->value * _gtk_css_number_value_get (_gtk_style_context_peek_property (context, "font-size"), 100);
       dest->unit = GTK_CSS_PX;
       break;
     case GTK_CSS_RAD:
index fa80c5287d5f51203dbe407e46d2884cee3be65e..7dd1d7b292e4063de21ee016cc115c867db3eead 100644 (file)
@@ -202,17 +202,6 @@ _gtk_css_value_new_from_enum (GType type,
   return value;
 }
 
-GtkCssValue *
-_gtk_css_value_new_from_double (double d)
-{
-  GtkCssValue *value;
-
-  value = gtk_css_value_new (G_TYPE_DOUBLE);
-  value->u.dbl = d;
-
-  return value;
-}
-
 GtkCssValue *
 _gtk_css_value_new_take_strv (char **strv)
 {
@@ -497,13 +486,6 @@ _gtk_css_value_get_enum (const GtkCssValue *value)
   return value->u.gint;
 }
 
-double
-_gtk_css_value_get_double (const GtkCssValue *value)
-{
-  g_return_val_if_fail (_gtk_css_value_holds (value, G_TYPE_DOUBLE), 0);
-  return value->u.dbl;
-}
-
 gpointer
 _gtk_css_value_dup_object (const GtkCssValue *value)
 {
index 51a094144d7fce60af558711f8814ddd8d682773..7d8448c677f68dbb03f4ab5897399d06b1c277fa 100644 (file)
@@ -75,7 +75,6 @@ GtkCssValue *_gtk_css_value_new_from_gvalue           (const GValue
 GtkCssValue *_gtk_css_value_new_from_int              (gint                        val);
 GtkCssValue *_gtk_css_value_new_from_enum             (GType                       type,
                                                        gint                        val);
-GtkCssValue *_gtk_css_value_new_from_double           (double                      d);
 GtkCssValue *_gtk_css_value_new_take_strv             (char                      **strv);
 GtkCssValue *_gtk_css_value_new_from_boxed            (GType                       type,
                                                        gpointer                    boxed);
@@ -93,7 +92,6 @@ void         _gtk_css_value_init_gvalue               (const GtkCssValue
 
 int                             _gtk_css_value_get_int                    (const GtkCssValue *value);
 int                             _gtk_css_value_get_enum                   (const GtkCssValue *value);
-double                          _gtk_css_value_get_double                 (const GtkCssValue *value);
 gpointer                        _gtk_css_value_dup_object                 (const GtkCssValue *value);
 gpointer                        _gtk_css_value_get_object                 (const GtkCssValue *value);
 gpointer                        _gtk_css_value_get_boxed                  (const GtkCssValue *value);