Commit bf92f2f7 authored by Benjamin Otte's avatar Benjamin Otte

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.
parent ad05604b
......@@ -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),
......
......@@ -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)
......
......@@ -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 */
......
......@@ -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:
......
......@@ -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)
{
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment