Commit ad05604b authored by Benjamin Otte's avatar Benjamin Otte

cssvalue: Convert 'font-family'

It's now a CssArrayValue filled with CssStringValue
parent 7c75611b
...@@ -24,10 +24,12 @@ ...@@ -24,10 +24,12 @@
#include <cairo-gobject.h> #include <cairo-gobject.h>
#include <math.h> #include <math.h>
#include "gtkcssarrayvalueprivate.h"
#include "gtkcssenumvalueprivate.h" #include "gtkcssenumvalueprivate.h"
#include "gtkcssimageprivate.h" #include "gtkcssimageprivate.h"
#include "gtkcssimagevalueprivate.h" #include "gtkcssimagevalueprivate.h"
#include "gtkcssnumbervalueprivate.h" #include "gtkcssnumbervalueprivate.h"
#include "gtkcssstringvalueprivate.h"
#include "gtkcssstylefuncsprivate.h" #include "gtkcssstylefuncsprivate.h"
#include "gtkcsstypesprivate.h" #include "gtkcsstypesprivate.h"
#include "gtkcssvalueprivate.h" #include "gtkcssvalueprivate.h"
...@@ -432,10 +434,8 @@ parse_font (GtkCssShorthandProperty *shorthand, ...@@ -432,10 +434,8 @@ parse_font (GtkCssShorthandProperty *shorthand,
if (mask & PANGO_FONT_MASK_FAMILY) if (mask & PANGO_FONT_MASK_FAMILY)
{ {
char **strv = g_new0 (char *, 2); GtkCssValue *value = _gtk_css_string_value_new (pango_font_description_get_family (desc));
values[0] = _gtk_css_array_value_new (&value, 1);
strv[0] = g_strdup (pango_font_description_get_family (desc));
values[0] = _gtk_css_value_new_take_strv (strv);
} }
if (mask & PANGO_FONT_MASK_STYLE) if (mask & PANGO_FONT_MASK_STYLE)
{ {
...@@ -737,10 +737,8 @@ pack_font_description (GtkCssShorthandProperty *shorthand, ...@@ -737,10 +737,8 @@ pack_font_description (GtkCssShorthandProperty *shorthand,
v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-family"))), query_data); v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-family"))), query_data);
if (v) if (v)
{ {
const char **families = _gtk_css_value_get_strv (v);
/* xxx: Can we set all the families here somehow? */ /* xxx: Can we set all the families here somehow? */
if (families) pango_font_description_set_family (description, _gtk_css_string_value_get (_gtk_css_array_value_get_nth (v, 0)));
pango_font_description_set_family (description, families[0]);
} }
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);
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
/* the actual parsers we have */ /* the actual parsers we have */
#include "gtkanimationdescription.h" #include "gtkanimationdescription.h"
#include "gtkbindings.h" #include "gtkbindings.h"
#include "gtkcssarrayvalueprivate.h"
#include "gtkcssimagegradientprivate.h" #include "gtkcssimagegradientprivate.h"
#include "gtkcssimageprivate.h" #include "gtkcssimageprivate.h"
#include "gtkcssimagevalueprivate.h" #include "gtkcssimagevalueprivate.h"
...@@ -47,6 +48,7 @@ ...@@ -47,6 +48,7 @@
#include "gtkcssnumbervalueprivate.h" #include "gtkcssnumbervalueprivate.h"
#include "gtkcssrgbavalueprivate.h" #include "gtkcssrgbavalueprivate.h"
#include "gtkcssshadowvalueprivate.h" #include "gtkcssshadowvalueprivate.h"
#include "gtkcssstringvalueprivate.h"
#include "gtksymboliccolorprivate.h" #include "gtksymboliccolorprivate.h"
#include "gtkthemingengine.h" #include "gtkthemingengine.h"
#include "gtktypebuiltins.h" #include "gtktypebuiltins.h"
...@@ -93,45 +95,6 @@ gtk_css_style_property_register (const char * name, ...@@ -93,45 +95,6 @@ gtk_css_style_property_register (const char * name,
_gtk_css_value_unref (initial_value); _gtk_css_value_unref (initial_value);
} }
/*** HELPERS ***/
static void
string_append_string (GString *str,
const char *string)
{
gsize len;
g_string_append_c (str, '"');
do {
len = strcspn (string, "\"\n\r\f");
g_string_append (str, string);
string += len;
switch (*string)
{
case '\0':
break;
case '\n':
g_string_append (str, "\\A ");
break;
case '\r':
g_string_append (str, "\\D ");
break;
case '\f':
g_string_append (str, "\\C ");
break;
case '\"':
g_string_append (str, "\\\"");
break;
default:
g_assert_not_reached ();
break;
}
} while (*string);
g_string_append_c (str, '"');
}
/*** IMPLEMENTATIONS ***/ /*** IMPLEMENTATIONS ***/
static void static void
...@@ -234,6 +197,7 @@ font_family_parse (GtkCssStyleProperty *property, ...@@ -234,6 +197,7 @@ font_family_parse (GtkCssStyleProperty *property,
GFile *base) GFile *base)
{ {
GPtrArray *names; GPtrArray *names;
GtkCssValue *result;
char *name; char *name;
/* We don't special case generic families. Pango should do /* We don't special case generic families. Pango should do
...@@ -265,35 +229,54 @@ font_family_parse (GtkCssStyleProperty *property, ...@@ -265,35 +229,54 @@ font_family_parse (GtkCssStyleProperty *property,
} }
} }
g_ptr_array_add (names, name); g_ptr_array_add (names, _gtk_css_string_value_new_take (name));
} while (_gtk_css_parser_try (parser, ",", TRUE)); } while (_gtk_css_parser_try (parser, ",", TRUE));
/* NULL-terminate array */ result = _gtk_css_array_value_new ((GtkCssValue **) names->pdata, names->len);
g_ptr_array_add (names, NULL); g_ptr_array_free (names, TRUE);
return _gtk_css_value_new_take_strv ((char **) g_ptr_array_free (names, FALSE)); return result;
} }
static void static void
font_family_value_print (GtkCssStyleProperty *property, font_family_query (GtkCssStyleProperty *property,
const GtkCssValue *value, const GtkCssValue *css_value,
GString *string) GValue *value)
{ {
const char **names = _gtk_css_value_get_strv (value); GPtrArray *array;
guint i;
array = g_ptr_array_new ();
if (names == NULL || *names == NULL) for (i = 0; i < _gtk_css_array_value_get_n_values (css_value); i++)
{ {
g_string_append (string, "none"); g_ptr_array_add (array, g_strdup (_gtk_css_string_value_get (_gtk_css_array_value_get_nth (css_value, i))));
return;
} }
string_append_string (string, *names); /* NULL-terminate */
names++; g_ptr_array_add (array, NULL);
while (*names)
g_value_init (value, G_TYPE_STRV);
g_value_set_boxed (value, g_ptr_array_free (array, FALSE));
}
static GtkCssValue *
font_family_assign (GtkCssStyleProperty *property,
const GValue *value)
{
const char **names = g_value_get_boxed (value);
GtkCssValue *result;
GPtrArray *array;
array = g_ptr_array_new ();
for (names = g_value_get_boxed (value); *names; names++)
{ {
g_string_append (string, ", "); g_ptr_array_add (array, _gtk_css_string_value_new (*names));
string_append_string (string, *names);
names++;
} }
result = _gtk_css_array_value_new ((GtkCssValue **) array->pdata, array->len);
g_ptr_array_free (array, TRUE);
return result;
} }
static GtkCssValue * static GtkCssValue *
...@@ -1182,7 +1165,7 @@ gtk_symbolic_color_new_rgba (double red, ...@@ -1182,7 +1165,7 @@ gtk_symbolic_color_new_rgba (double red,
void void
_gtk_css_style_property_init_properties (void) _gtk_css_style_property_init_properties (void)
{ {
char *default_font_family[] = { "Sans", NULL }; GtkCssValue *value;
GtkCssBackgroundSize default_background_size = { GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX), GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX), FALSE, FALSE }; GtkCssBackgroundSize default_background_size = { GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX), GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX), FALSE, FALSE };
GtkCssBackgroundPosition default_background_position = { GTK_CSS_NUMBER_INIT (0, GTK_CSS_PERCENT), GTK_CSS_NUMBER_INIT (0, GTK_CSS_PERCENT)}; GtkCssBackgroundPosition default_background_position = { GTK_CSS_NUMBER_INIT (0, GTK_CSS_PERCENT), GTK_CSS_NUMBER_INIT (0, GTK_CSS_PERCENT)};
GtkCssBorderCornerRadius no_corner_radius = { GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX), GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX) }; GtkCssBorderCornerRadius no_corner_radius = { GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX), GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX) };
...@@ -1229,16 +1212,17 @@ _gtk_css_style_property_init_properties (void) ...@@ -1229,16 +1212,17 @@ _gtk_css_style_property_init_properties (void)
_gtk_css_value_new_take_symbolic_color ( _gtk_css_value_new_take_symbolic_color (
gtk_symbolic_color_new_rgba (0, 0, 0, 0))); gtk_symbolic_color_new_rgba (0, 0, 0, 0)));
value = _gtk_css_string_value_new ("Sans");
gtk_css_style_property_register ("font-family", gtk_css_style_property_register ("font-family",
G_TYPE_STRV, G_TYPE_STRV,
GTK_STYLE_PROPERTY_INHERIT, GTK_STYLE_PROPERTY_INHERIT,
font_family_parse, font_family_parse,
font_family_value_print,
NULL, NULL,
query_simple,
assign_simple,
NULL, NULL,
_gtk_css_value_new_take_strv (g_strdupv (default_font_family))); font_family_query,
font_family_assign,
NULL,
_gtk_css_array_value_new (&value, 1));
gtk_css_style_property_register ("font-style", gtk_css_style_property_register ("font-style",
PANGO_TYPE_STYLE, PANGO_TYPE_STYLE,
GTK_STYLE_PROPERTY_INHERIT, GTK_STYLE_PROPERTY_INHERIT,
......
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