[gtk+/wip/cssvalue: 76/142] cssvalue: Add enum values for the pango enums
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/cssvalue: 76/142] cssvalue: Add enum values for the pango enums
- Date: Sat, 7 Apr 2012 19:52:45 +0000 (UTC)
commit 9ea3b2f0eeab3f612f2046d2540d7e54c8fcf06e
Author: Benjamin Otte <otte redhat com>
Date: Wed Mar 28 09:04:54 2012 +0200
cssvalue: Add enum values for the pango enums
And fix the parser to conform to the CSS spec while at it.
gtk/gtkcssenumvalue.c | 154 +++++++++++++++++++++++++++++++++++++
gtk/gtkcssenumvalueprivate.h | 12 +++
gtk/gtkcssshorthandpropertyimpl.c | 15 ++--
gtk/gtkcssstylepropertyimpl.c | 103 +++++++++++++++++--------
gtk/gtkcssvalue.c | 21 -----
gtk/gtkcssvalueprivate.h | 3 -
6 files changed, 241 insertions(+), 67 deletions(-)
---
diff --git a/gtk/gtkcssenumvalue.c b/gtk/gtkcssenumvalue.c
index 5f59cdd..7e79fc7 100644
--- a/gtk/gtkcssenumvalue.c
+++ b/gtk/gtkcssenumvalue.c
@@ -102,3 +102,157 @@ _gtk_css_border_style_value_get (const GtkCssValue *value)
return value->value;
}
+/* PangoStyle */
+
+static const GtkCssValueClass GTK_CSS_VALUE_FONT_STYLE = {
+ gtk_css_value_enum_free,
+ gtk_css_value_enum_equal,
+ gtk_css_value_enum_print
+};
+
+static GtkCssValue font_style_values[] = {
+ { >K_CSS_VALUE_FONT_STYLE, 1, PANGO_STYLE_NORMAL, "normal" },
+ { >K_CSS_VALUE_FONT_STYLE, 1, PANGO_STYLE_OBLIQUE, "oblique" },
+ { >K_CSS_VALUE_FONT_STYLE, 1, PANGO_STYLE_ITALIC, "italic" }
+};
+
+GtkCssValue *
+_gtk_css_font_style_value_new (PangoStyle font_style)
+{
+ g_return_val_if_fail (font_style < G_N_ELEMENTS (font_style_values), NULL);
+
+ return _gtk_css_value_ref (&font_style_values[font_style]);
+}
+
+GtkCssValue *
+_gtk_css_font_style_value_try_parse (GtkCssParser *parser)
+{
+ guint i;
+
+ g_return_val_if_fail (parser != NULL, NULL);
+
+ for (i = 0; i < G_N_ELEMENTS (font_style_values); i++)
+ {
+ if (_gtk_css_parser_try (parser, font_style_values[i].name, TRUE))
+ return _gtk_css_value_ref (&font_style_values[i]);
+ }
+
+ return NULL;
+}
+
+PangoStyle
+_gtk_css_font_style_value_get (const GtkCssValue *value)
+{
+ g_return_val_if_fail (value->class == >K_CSS_VALUE_FONT_STYLE, PANGO_STYLE_NORMAL);
+
+ return value->value;
+}
+
+/* PangoVariant */
+
+static const GtkCssValueClass GTK_CSS_VALUE_FONT_VARIANT = {
+ gtk_css_value_enum_free,
+ gtk_css_value_enum_equal,
+ gtk_css_value_enum_print
+};
+
+static GtkCssValue font_variant_values[] = {
+ { >K_CSS_VALUE_FONT_VARIANT, 1, PANGO_VARIANT_NORMAL, "normal" },
+ { >K_CSS_VALUE_FONT_VARIANT, 1, PANGO_VARIANT_SMALL_CAPS, "small-caps" }
+};
+
+GtkCssValue *
+_gtk_css_font_variant_value_new (PangoVariant font_variant)
+{
+ g_return_val_if_fail (font_variant < G_N_ELEMENTS (font_variant_values), NULL);
+
+ return _gtk_css_value_ref (&font_variant_values[font_variant]);
+}
+
+GtkCssValue *
+_gtk_css_font_variant_value_try_parse (GtkCssParser *parser)
+{
+ guint i;
+
+ g_return_val_if_fail (parser != NULL, NULL);
+
+ for (i = 0; i < G_N_ELEMENTS (font_variant_values); i++)
+ {
+ if (_gtk_css_parser_try (parser, font_variant_values[i].name, TRUE))
+ return _gtk_css_value_ref (&font_variant_values[i]);
+ }
+
+ return NULL;
+}
+
+PangoVariant
+_gtk_css_font_variant_value_get (const GtkCssValue *value)
+{
+ g_return_val_if_fail (value->class == >K_CSS_VALUE_FONT_VARIANT, PANGO_VARIANT_NORMAL);
+
+ return value->value;
+}
+
+/* PangoWeight */
+
+static const GtkCssValueClass GTK_CSS_VALUE_FONT_WEIGHT = {
+ gtk_css_value_enum_free,
+ gtk_css_value_enum_equal,
+ gtk_css_value_enum_print
+};
+
+static GtkCssValue font_weight_values[] = {
+ { >K_CSS_VALUE_FONT_WEIGHT, 1, PANGO_WEIGHT_THIN, "100" },
+ { >K_CSS_VALUE_FONT_WEIGHT, 1, PANGO_WEIGHT_ULTRALIGHT, "200" },
+ { >K_CSS_VALUE_FONT_WEIGHT, 1, PANGO_WEIGHT_LIGHT, "300" },
+ { >K_CSS_VALUE_FONT_WEIGHT, 1, PANGO_WEIGHT_NORMAL, "normal" },
+ { >K_CSS_VALUE_FONT_WEIGHT, 1, PANGO_WEIGHT_MEDIUM, "500" },
+ { >K_CSS_VALUE_FONT_WEIGHT, 1, PANGO_WEIGHT_SEMIBOLD, "600" },
+ { >K_CSS_VALUE_FONT_WEIGHT, 1, PANGO_WEIGHT_BOLD, "bold" },
+ { >K_CSS_VALUE_FONT_WEIGHT, 1, PANGO_WEIGHT_ULTRABOLD, "800" },
+ { >K_CSS_VALUE_FONT_WEIGHT, 1, PANGO_WEIGHT_HEAVY, "900" }
+};
+
+GtkCssValue *
+_gtk_css_font_weight_value_new (PangoWeight font_weight)
+{
+ guint i;
+
+ for (i = 0; i < G_N_ELEMENTS (font_weight_values); i++)
+ {
+ if (font_weight_values[i].value == font_weight)
+ return _gtk_css_value_ref (&font_weight_values[i]);
+ }
+
+ g_return_val_if_reached (NULL);
+}
+
+GtkCssValue *
+_gtk_css_font_weight_value_try_parse (GtkCssParser *parser)
+{
+ guint i;
+
+ g_return_val_if_fail (parser != NULL, NULL);
+
+ for (i = 0; i < G_N_ELEMENTS (font_weight_values); i++)
+ {
+ if (_gtk_css_parser_try (parser, font_weight_values[i].name, TRUE))
+ return _gtk_css_value_ref (&font_weight_values[i]);
+ }
+ /* special cases go here */
+ if (_gtk_css_parser_try (parser, "400", TRUE))
+ return _gtk_css_value_ref (&font_weight_values[3]);
+ if (_gtk_css_parser_try (parser, "700", TRUE))
+ return _gtk_css_value_ref (&font_weight_values[6]);
+
+ return NULL;
+}
+
+PangoWeight
+_gtk_css_font_weight_value_get (const GtkCssValue *value)
+{
+ g_return_val_if_fail (value->class == >K_CSS_VALUE_FONT_WEIGHT, PANGO_WEIGHT_NORMAL);
+
+ return value->value;
+}
+
diff --git a/gtk/gtkcssenumvalueprivate.h b/gtk/gtkcssenumvalueprivate.h
index 8801bf4..ec37ec7 100644
--- a/gtk/gtkcssenumvalueprivate.h
+++ b/gtk/gtkcssenumvalueprivate.h
@@ -30,6 +30,18 @@ GtkCssValue * _gtk_css_border_style_value_new (GtkBorderStyle border
GtkCssValue * _gtk_css_border_style_value_try_parse (GtkCssParser *parser);
GtkBorderStyle _gtk_css_border_style_value_get (const GtkCssValue *value);
+GtkCssValue * _gtk_css_font_style_value_new (PangoStyle style);
+GtkCssValue * _gtk_css_font_style_value_try_parse (GtkCssParser *parser);
+PangoStyle _gtk_css_font_style_value_get (const GtkCssValue *value);
+
+GtkCssValue * _gtk_css_font_variant_value_new (PangoVariant variant);
+GtkCssValue * _gtk_css_font_variant_value_try_parse (GtkCssParser *parser);
+PangoVariant _gtk_css_font_variant_value_get (const GtkCssValue *value);
+
+GtkCssValue * _gtk_css_font_weight_value_new (PangoWeight weight);
+GtkCssValue * _gtk_css_font_weight_value_try_parse (GtkCssParser *parser);
+PangoWeight _gtk_css_font_weight_value_get (const GtkCssValue *value);
+
G_END_DECLS
diff --git a/gtk/gtkcssshorthandpropertyimpl.c b/gtk/gtkcssshorthandpropertyimpl.c
index cb12522..e4d98a0 100644
--- a/gtk/gtkcssshorthandpropertyimpl.c
+++ b/gtk/gtkcssshorthandpropertyimpl.c
@@ -438,18 +438,15 @@ parse_font (GtkCssShorthandProperty *shorthand,
}
if (mask & PANGO_FONT_MASK_STYLE)
{
- values[1] = _gtk_css_value_new_from_enum (PANGO_TYPE_STYLE,
- pango_font_description_get_style (desc));
+ values[1] = _gtk_css_font_style_value_new (pango_font_description_get_style (desc));
}
if (mask & PANGO_FONT_MASK_VARIANT)
{
- values[2] = _gtk_css_value_new_from_enum (PANGO_TYPE_VARIANT,
- pango_font_description_get_style (desc));
+ values[2] = _gtk_css_font_variant_value_new (pango_font_description_get_variant (desc));
}
if (mask & PANGO_FONT_MASK_WEIGHT)
{
- values[3] = _gtk_css_value_new_from_enum (PANGO_TYPE_WEIGHT,
- pango_font_description_get_weight (desc));
+ values[3] = _gtk_css_font_weight_value_new (pango_font_description_get_weight (desc));
}
if (mask & PANGO_FONT_MASK_SIZE)
{
@@ -748,15 +745,15 @@ pack_font_description (GtkCssShorthandProperty *shorthand,
v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-style"))), query_data);
if (v)
- pango_font_description_set_style (description, _gtk_css_value_get_pango_style (v));
+ pango_font_description_set_style (description, _gtk_css_font_style_value_get (v));
v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-variant"))), query_data);
if (v)
- pango_font_description_set_variant (description, _gtk_css_value_get_pango_variant (v));
+ pango_font_description_set_variant (description, _gtk_css_font_variant_value_get (v));
v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-weight"))), query_data);
if (v)
- pango_font_description_set_weight (description, _gtk_css_value_get_pango_weight (v));
+ pango_font_description_set_weight (description, _gtk_css_font_weight_value_get (v));
g_value_init (value, PANGO_TYPE_FONT_DESCRIPTION);
g_value_take_boxed (value, description);
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index cad536e..eaa3464 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -301,15 +301,28 @@ parse_pango_style (GtkCssStyleProperty *property,
GtkCssParser *parser,
GFile *base)
{
- int value;
+ GtkCssValue *value = _gtk_css_font_style_value_try_parse (parser);
+
+ if (value == NULL)
+ _gtk_css_parser_error (parser, "unknown value for property");
- if (!_gtk_css_parser_try_enum (parser, PANGO_TYPE_STYLE, &value))
- {
- _gtk_css_parser_error (parser, "unknown value for property");
- return NULL;
- }
+ return value;
+}
- return _gtk_css_value_new_from_enum (PANGO_TYPE_STYLE, value);
+static void
+query_pango_style (GtkCssStyleProperty *property,
+ const GtkCssValue *css_value,
+ GValue *value)
+{
+ g_value_init (value, PANGO_TYPE_STYLE);
+ g_value_set_enum (value, _gtk_css_font_style_value_get (css_value));
+}
+
+static GtkCssValue *
+assign_pango_style (GtkCssStyleProperty *property,
+ const GValue *value)
+{
+ return _gtk_css_font_style_value_new (g_value_get_enum (value));
}
static GtkCssValue *
@@ -317,15 +330,28 @@ parse_pango_weight (GtkCssStyleProperty *property,
GtkCssParser *parser,
GFile *base)
{
- int value;
+ GtkCssValue *value = _gtk_css_font_weight_value_try_parse (parser);
+
+ if (value == NULL)
+ _gtk_css_parser_error (parser, "unknown value for property");
- if (!_gtk_css_parser_try_enum (parser, PANGO_TYPE_WEIGHT, &value))
- {
- _gtk_css_parser_error (parser, "unknown value for property");
- return NULL;
- }
+ return value;
+}
- return _gtk_css_value_new_from_enum (PANGO_TYPE_WEIGHT, value);
+static void
+query_pango_weight (GtkCssStyleProperty *property,
+ const GtkCssValue *css_value,
+ GValue *value)
+{
+ g_value_init (value, PANGO_TYPE_WEIGHT);
+ g_value_set_enum (value, _gtk_css_font_weight_value_get (css_value));
+}
+
+static GtkCssValue *
+assign_pango_weight (GtkCssStyleProperty *property,
+ const GValue *value)
+{
+ return _gtk_css_font_weight_value_new (g_value_get_enum (value));
}
static GtkCssValue *
@@ -333,15 +359,28 @@ parse_pango_variant (GtkCssStyleProperty *property,
GtkCssParser *parser,
GFile *base)
{
- int value;
+ GtkCssValue *value = _gtk_css_font_variant_value_try_parse (parser);
+
+ if (value == NULL)
+ _gtk_css_parser_error (parser, "unknown value for property");
- if (!_gtk_css_parser_try_enum (parser, PANGO_TYPE_VARIANT, &value))
- {
- _gtk_css_parser_error (parser, "unknown value for property");
- return NULL;
- }
+ return value;
+}
- return _gtk_css_value_new_from_enum (PANGO_TYPE_VARIANT, value);
+static void
+query_pango_variant (GtkCssStyleProperty *property,
+ const GtkCssValue *css_value,
+ GValue *value)
+{
+ g_value_init (value, PANGO_TYPE_VARIANT);
+ g_value_set_enum (value, _gtk_css_font_variant_value_get (css_value));
+}
+
+static GtkCssValue *
+assign_pango_variant (GtkCssStyleProperty *property,
+ const GValue *value)
+{
+ return _gtk_css_font_variant_value_new (g_value_get_enum (value));
}
static GtkCssValue *
@@ -1212,34 +1251,30 @@ _gtk_css_style_property_init_properties (void)
parse_pango_style,
NULL,
NULL,
- query_simple,
- assign_simple,
+ query_pango_style,
+ assign_pango_style,
NULL,
- _gtk_css_value_new_from_enum (PANGO_TYPE_STYLE,
- PANGO_STYLE_NORMAL));
+ _gtk_css_font_style_value_new (PANGO_STYLE_NORMAL));
gtk_css_style_property_register ("font-variant",
PANGO_TYPE_VARIANT,
GTK_STYLE_PROPERTY_INHERIT,
parse_pango_variant,
NULL,
NULL,
- query_simple,
- assign_simple,
+ query_pango_variant,
+ assign_pango_variant,
NULL,
- _gtk_css_value_new_from_enum (PANGO_TYPE_VARIANT,
- PANGO_VARIANT_NORMAL));
- /* xxx: need to parse this properly, ie parse the numbers */
+ _gtk_css_font_variant_value_new (PANGO_VARIANT_NORMAL));
gtk_css_style_property_register ("font-weight",
PANGO_TYPE_WEIGHT,
GTK_STYLE_PROPERTY_INHERIT,
parse_pango_weight,
NULL,
NULL,
- query_simple,
- assign_simple,
+ query_pango_weight,
+ assign_pango_weight,
NULL,
- _gtk_css_value_new_from_enum (PANGO_TYPE_WEIGHT,
- PANGO_WEIGHT_NORMAL));
+ _gtk_css_font_weight_value_new (PANGO_WEIGHT_NORMAL));
gtk_css_style_property_register ("text-shadow",
G_TYPE_NONE,
diff --git a/gtk/gtkcssvalue.c b/gtk/gtkcssvalue.c
index df883bd..9cc6de2 100644
--- a/gtk/gtkcssvalue.c
+++ b/gtk/gtkcssvalue.c
@@ -576,27 +576,6 @@ _gtk_css_value_get_border_corner_radius (const GtkCssValue *value)
return value->u.ptr;
}
-PangoStyle
-_gtk_css_value_get_pango_style (const GtkCssValue *value)
-{
- g_return_val_if_fail (_gtk_css_value_holds (value, PANGO_TYPE_STYLE), 0);
- return value->u.gint;
-}
-
-PangoVariant
-_gtk_css_value_get_pango_variant (const GtkCssValue *value)
-{
- g_return_val_if_fail (_gtk_css_value_holds (value, PANGO_TYPE_VARIANT), 0);
- return value->u.gint;
-}
-
-PangoWeight
-_gtk_css_value_get_pango_weight (const GtkCssValue *value)
-{
- g_return_val_if_fail (_gtk_css_value_holds (value, PANGO_TYPE_WEIGHT), 0);
- return value->u.gint;
-}
-
GtkGradient *
_gtk_css_value_get_gradient (const GtkCssValue *value)
{
diff --git a/gtk/gtkcssvalueprivate.h b/gtk/gtkcssvalueprivate.h
index f8699a7..22e885a 100644
--- a/gtk/gtkcssvalueprivate.h
+++ b/gtk/gtkcssvalueprivate.h
@@ -108,9 +108,6 @@ const GtkCssBackgroundSize *_gtk_css_value_get_background_size (const
const GtkCssBackgroundPosition *_gtk_css_value_get_background_position (const GtkCssValue *value);
const GtkCssBorderCornerRadius *_gtk_css_value_get_border_corner_radius (const GtkCssValue *value);
const GtkCssBorderImageRepeat *_gtk_css_value_get_border_image_repeat (const GtkCssValue *value);
-PangoStyle _gtk_css_value_get_pango_style (const GtkCssValue *value);
-PangoVariant _gtk_css_value_get_pango_variant (const GtkCssValue *value);
-PangoWeight _gtk_css_value_get_pango_weight (const GtkCssValue *value);
GtkGradient *_gtk_css_value_get_gradient (const GtkCssValue *value);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]