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.
This commit is contained in:
Benjamin Otte 2012-03-30 03:51:25 +02:00
parent ad05604b3e
commit bf92f2f7ac
6 changed files with 40 additions and 31 deletions

View File

@ -173,12 +173,14 @@ _gtk_css_number_value_compute (GtkCssValue *number,
GTK_CSS_PX); GTK_CSS_PX);
break; break;
case GTK_CSS_EM: 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); GTK_CSS_PX);
break; break;
case GTK_CSS_EX: case GTK_CSS_EX:
/* for now we pretend ex is half of em */ /* 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); GTK_CSS_PX);
case GTK_CSS_RAD: case GTK_CSS_RAD:
return _gtk_css_number_value_new (number->value * 360.0 / (2 * G_PI), return _gtk_css_number_value_new (number->value * 360.0 / (2 * G_PI),

View File

@ -451,7 +451,7 @@ parse_font (GtkCssShorthandProperty *shorthand,
} }
if (mask & PANGO_FONT_MASK_SIZE) 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); 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); v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-size"))), query_data);
if (v) 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); v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-style"))), query_data);
if (v) if (v)

View 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); 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 * static GtkCssValue *
color_parse (GtkCssStyleProperty *property, color_parse (GtkCssStyleProperty *property,
GtkCssParser *parser, GtkCssParser *parser,
@ -619,7 +635,15 @@ font_size_parse (GtkCssStyleProperty *property,
return NULL; 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 * static GtkCssValue *
@ -1192,11 +1216,12 @@ _gtk_css_style_property_init_properties (void)
GTK_STYLE_PROPERTY_INHERIT, GTK_STYLE_PROPERTY_INHERIT,
font_size_parse, font_size_parse,
NULL, NULL,
font_size_compute,
query_length_as_double,
assign_length_from_double,
NULL, NULL,
query_simple, /* XXX: This should be 'normal' */
assign_simple, _gtk_css_number_value_new (10.0, GTK_CSS_PX));
NULL,
_gtk_css_value_new_from_double (10.0));
/* properties that aren't referenced when computing values /* properties that aren't referenced when computing values
* start here */ * start here */

View File

@ -18,6 +18,8 @@
#include "config.h" #include "config.h"
#include "gtkcsstypesprivate.h" #include "gtkcsstypesprivate.h"
#include "gtkcssnumbervalueprivate.h"
#include "gtkstylecontextprivate.h" #include "gtkstylecontextprivate.h"
#define DEFINE_BOXED_TYPE_WITH_COPY_FUNC(TypeName, type_name) \ #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; dest->unit = GTK_CSS_PX;
break; break;
case GTK_CSS_EM: 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; dest->unit = GTK_CSS_PX;
break; break;
case GTK_CSS_EX: case GTK_CSS_EX:
/* for now we pretend ex is half of em */ /* 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; dest->unit = GTK_CSS_PX;
break; break;
case GTK_CSS_RAD: case GTK_CSS_RAD:

View File

@ -202,17 +202,6 @@ _gtk_css_value_new_from_enum (GType type,
return value; 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 * GtkCssValue *
_gtk_css_value_new_take_strv (char **strv) _gtk_css_value_new_take_strv (char **strv)
{ {
@ -497,13 +486,6 @@ _gtk_css_value_get_enum (const GtkCssValue *value)
return value->u.gint; 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 gpointer
_gtk_css_value_dup_object (const GtkCssValue *value) _gtk_css_value_dup_object (const GtkCssValue *value)
{ {

View 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_int (gint val);
GtkCssValue *_gtk_css_value_new_from_enum (GType type, GtkCssValue *_gtk_css_value_new_from_enum (GType type,
gint val); 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_take_strv (char **strv);
GtkCssValue *_gtk_css_value_new_from_boxed (GType type, GtkCssValue *_gtk_css_value_new_from_boxed (GType type,
gpointer boxed); 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_int (const GtkCssValue *value);
int _gtk_css_value_get_enum (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_dup_object (const GtkCssValue *value);
gpointer _gtk_css_value_get_object (const GtkCssValue *value); gpointer _gtk_css_value_get_object (const GtkCssValue *value);
gpointer _gtk_css_value_get_boxed (const GtkCssValue *value); gpointer _gtk_css_value_get_boxed (const GtkCssValue *value);