diff options
author | Benjamin Otte <otte@redhat.com> | 2012-03-28 09:04:54 +0200 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2012-04-17 08:59:14 +0200 |
commit | d63b11e56b0c1a9620d3a7f723baa24b02ff2867 (patch) | |
tree | b431fe9ee5cbcb8780de2c200412945e9a8025f2 /gtk/gtkcssenumvalue.c | |
parent | b65d17dda8f33ce205989695f6f8c89602ababd5 (diff) | |
download | gtk+-d63b11e56b0c1a9620d3a7f723baa24b02ff2867.tar.gz |
cssvalue: Add enum values for the pango enums
And fix the parser to conform to the CSS spec while at it.
Diffstat (limited to 'gtk/gtkcssenumvalue.c')
-rw-r--r-- | gtk/gtkcssenumvalue.c | 154 |
1 files changed, 154 insertions, 0 deletions
diff --git a/gtk/gtkcssenumvalue.c b/gtk/gtkcssenumvalue.c index 5f59cdd9b1..7e79fc7407 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; +} + |