css: Implement font-stretch

The font-stretch CSS property is defined in the Level 3 CSS Fonts
module, available at:

  http://dev.w3.org/csswg/css-fonts/#propdef-font-stretch

It allows defining a normal, condensed, or expanded face to the font
description. Pango already supports it, so this is literally just the
CSS parser machinery needed to bridge our CSS to the FontDescription
API.

https://bugzilla.gnome.org/show_bug.cgi?id=735593
This commit is contained in:
Emmanuele Bassi
2014-08-28 12:50:49 +01:00
parent f05e9d2612
commit 5ad60caa3c
13 changed files with 139 additions and 3 deletions

View File

@ -436,6 +436,60 @@ _gtk_css_font_weight_value_get (const GtkCssValue *value)
return value->value;
}
/* PangoStretch */
static const GtkCssValueClass GTK_CSS_VALUE_FONT_STRETCH = {
gtk_css_value_enum_free,
gtk_css_value_enum_compute,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
gtk_css_value_enum_print
};
static GtkCssValue font_stretch_values[] = {
{ &GTK_CSS_VALUE_FONT_STRETCH, 1, PANGO_STRETCH_ULTRA_CONDENSED, "ultra-condensed" },
{ &GTK_CSS_VALUE_FONT_STRETCH, 1, PANGO_STRETCH_EXTRA_CONDENSED, "extra-condensed" },
{ &GTK_CSS_VALUE_FONT_STRETCH, 1, PANGO_STRETCH_CONDENSED, "condensed" },
{ &GTK_CSS_VALUE_FONT_STRETCH, 1, PANGO_STRETCH_SEMI_CONDENSED, "semi-condensed" },
{ &GTK_CSS_VALUE_FONT_STRETCH, 1, PANGO_STRETCH_NORMAL, "normal" },
{ &GTK_CSS_VALUE_FONT_STRETCH, 1, PANGO_STRETCH_SEMI_EXPANDED, "semi-expanded" },
{ &GTK_CSS_VALUE_FONT_STRETCH, 1, PANGO_STRETCH_EXPANDED, "expanded" },
{ &GTK_CSS_VALUE_FONT_STRETCH, 1, PANGO_STRETCH_EXTRA_EXPANDED, "extra-expanded" },
{ &GTK_CSS_VALUE_FONT_STRETCH, 1, PANGO_STRETCH_ULTRA_EXPANDED, "ultra-expanded" },
};
GtkCssValue *
_gtk_css_font_stretch_value_new (PangoStretch font_stretch)
{
g_return_val_if_fail (font_stretch < G_N_ELEMENTS (font_stretch_values), NULL);
return _gtk_css_value_ref (&font_stretch_values[font_stretch]);
}
GtkCssValue *
_gtk_css_font_stretch_value_try_parse (GtkCssParser *parser)
{
guint i;
g_return_val_if_fail (parser != NULL, NULL);
for (i = 0; i < G_N_ELEMENTS (font_stretch_values); i++)
{
if (_gtk_css_parser_try (parser, font_stretch_values[i].name, TRUE))
return _gtk_css_value_ref (&font_stretch_values[i]);
}
return NULL;
}
PangoStretch
_gtk_css_font_stretch_value_get (const GtkCssValue *value)
{
g_return_val_if_fail (value->class == &GTK_CSS_VALUE_FONT_STRETCH, PANGO_STRETCH_NORMAL);
return value->value;
}
/* GtkCssArea */
static const GtkCssValueClass GTK_CSS_VALUE_AREA = {