[gtk+/wip/cssvalue: 87/137] cssvalue: Do a hacky conversion of font-size to a number value



commit 0095bb3847575e23efc11b16d7756f96f5501f7e
Author: Benjamin Otte <otte redhat com>
Date:   Fri Mar 30 03:51:25 2012 +0200

    cssvalue: Do a hacky conversion of font-size to a number value
    
    Just store the value as px for now.
    
    The font-size property needs a complete makeover anyway.

 gtk/gtkcssnumbervalue.c           |    6 ++++--
 gtk/gtkcssshorthandpropertyimpl.c |    4 ++--
 gtk/gtkcssstylepropertyimpl.c     |   35 ++++++++++++++++++++++++++++++-----
 gtk/gtkcsstypes.c                 |    6 ++++--
 gtk/gtkcssvalue.c                 |   18 ------------------
 gtk/gtkcssvalueprivate.h          |    2 --
 6 files changed, 40 insertions(+), 31 deletions(-)
---
diff --git a/gtk/gtkcssnumbervalue.c b/gtk/gtkcssnumbervalue.c
index e845a68..19e4c1d 100644
--- a/gtk/gtkcssnumbervalue.c
+++ b/gtk/gtkcssnumbervalue.c
@@ -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),
diff --git a/gtk/gtkcssshorthandpropertyimpl.c b/gtk/gtkcssshorthandpropertyimpl.c
index dbdbf47..3b467f7 100644
--- a/gtk/gtkcssshorthandpropertyimpl.c
+++ b/gtk/gtkcssshorthandpropertyimpl.c
@@ -450,7 +450,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);
@@ -742,7 +742,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)
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index 3108890..21d1fe6 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -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,
@@ -609,7 +625,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 *
@@ -1182,11 +1206,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 */
diff --git a/gtk/gtkcsstypes.c b/gtk/gtkcsstypes.c
index a47f8d3..411f401 100644
--- a/gtk/gtkcsstypes.c
+++ b/gtk/gtkcsstypes.c
@@ -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:
diff --git a/gtk/gtkcssvalue.c b/gtk/gtkcssvalue.c
index 8a3febb..bddad5d 100644
--- a/gtk/gtkcssvalue.c
+++ b/gtk/gtkcssvalue.c
@@ -174,17 +174,6 @@ _gtk_css_value_new_from_enum (GType type,
 }
 
 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)
 {
   GtkCssValue *value;
@@ -468,13 +457,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)
 {
diff --git a/gtk/gtkcssvalueprivate.h b/gtk/gtkcssvalueprivate.h
index 51a0941..7d8448c 100644
--- a/gtk/gtkcssvalueprivate.h
+++ b/gtk/gtkcssvalueprivate.h
@@ -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);



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