css: Implement font-variant-east-asian

This is translated to the corresponding OpenType features.
This commit is contained in:
Matthias Clasen 2017-09-18 12:42:42 -04:00
parent 8a7f2ca0be
commit b91f3ce331
3 changed files with 97 additions and 0 deletions

View File

@ -231,6 +231,7 @@ gtk_css_style_get_pango_attributes (GtkCssStyle *style)
GtkCssValue *caps;
GtkCssValue *numeric;
GtkCssValue *alternatives;
GtkCssValue *east_asian;
GString *s;
int i;
@ -379,6 +380,31 @@ gtk_css_style_get_pango_attributes (GtkCssStyle *style)
g_string_append (s, "hist 1");
}
east_asian = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_FONT_VARIANT_EAST_ASIAN);
for (i = 0; i < _gtk_css_array_value_get_n_values (east_asian); i++)
{
GtkCssValue *value = _gtk_css_array_value_get_nth (east_asian, i);
if (s->len > 0) g_string_append (s, ", ");
if (strcmp (_gtk_css_ident_value_get (value), "jis78") == 0)
g_string_append (s, "jp78 1");
if (strcmp (_gtk_css_ident_value_get (value), "jis83") == 0)
g_string_append (s, "jp83 1");
if (strcmp (_gtk_css_ident_value_get (value), "jis90") == 0)
g_string_append (s, "jp90 1");
if (strcmp (_gtk_css_ident_value_get (value), "jis04") == 0)
g_string_append (s, "jp04 1");
if (strcmp (_gtk_css_ident_value_get (value), "simplified") == 0)
g_string_append (s, "smpl 1");
if (strcmp (_gtk_css_ident_value_get (value), "traditional") == 0)
g_string_append (s, "trad 1");
if (strcmp (_gtk_css_ident_value_get (value), "full-width") == 0)
g_string_append (s, "fwid 1");
if (strcmp (_gtk_css_ident_value_get (value), "proportional-width") == 0)
g_string_append (s, "pwid 1");
if (strcmp (_gtk_css_ident_value_get (value), "ruby") == 0)
g_string_append (s, "ruby 1");
}
attrs = add_pango_attr (attrs, pango_attr_font_features_new (s->str));
g_string_free (s, TRUE);

View File

@ -749,6 +749,68 @@ parse_font_variant_alternatives (GtkCssStyleProperty *property,
return value;
}
static GtkCssValue *
parse_font_variant_east_asian (GtkCssStyleProperty *property,
GtkCssParser *parser)
{
GtkCssValue *value = NULL;
if (_gtk_css_parser_try (parser, "normal", TRUE))
value = _gtk_css_array_value_new (_gtk_css_ident_value_new ("normal"));
else
{
GtkCssValue *values[3] = { NULL, NULL, NULL };
guint n_values = 0;
guint old_n;
gboolean variant = FALSE;
gboolean width = FALSE;
gboolean ruby = FALSE;
do {
old_n = n_values;
if (!variant)
{
values[n_values] = _gtk_css_ident_value_try (parser, "jis78", "jis83", "jis90", "jis04",
"simplified", "traditional", NULL);
if (values[n_values])
{
n_values++;
variant = TRUE;
}
}
if (!width)
{
values[n_values] = _gtk_css_ident_value_try (parser, "full-width"
"proportional-width", NULL);
if (values[n_values])
{
n_values++;
width = TRUE;
}
}
if (!ruby)
{
values[n_values] = _gtk_css_ident_value_try (parser, "ruby", NULL);
if (values[n_values])
{
n_values++;
ruby = TRUE;
}
}
if (old_n == n_values)
{
_gtk_css_parser_error (parser, "Not a valid value");
return NULL;
}
} while (!value_is_done_parsing (parser));
value = _gtk_css_array_value_new_from_array (values, n_values);
}
return value;
}
static GtkCssValue *
box_shadow_value_parse (GtkCssStyleProperty *property,
GtkCssParser *parser)
@ -1282,6 +1344,14 @@ _gtk_css_style_property_init_properties (void)
parse_font_variant_alternatives,
NULL,
_gtk_css_array_value_new (_gtk_css_ident_value_new ("normal")));
gtk_css_style_property_register ("font-variant-east-asian",
GTK_CSS_PROPERTY_FONT_VARIANT_EAST_ASIAN,
G_TYPE_NONE,
0,
GTK_CSS_AFFECTS_TEXT | GTK_CSS_AFFECTS_TEXT_ATTRS,
parse_font_variant_east_asian,
NULL,
_gtk_css_array_value_new (_gtk_css_ident_value_new ("normal")));
gtk_css_style_property_register ("text-shadow",
GTK_CSS_PROPERTY_TEXT_SHADOW,
G_TYPE_NONE,

View File

@ -169,6 +169,7 @@ enum { /*< skip >*/
GTK_CSS_PROPERTY_FONT_VARIANT_CAPS,
GTK_CSS_PROPERTY_FONT_VARIANT_NUMERIC,
GTK_CSS_PROPERTY_FONT_VARIANT_ALTERNATIVES,
GTK_CSS_PROPERTY_FONT_VARIANT_EAST_ASIAN,
GTK_CSS_PROPERTY_TEXT_SHADOW,
GTK_CSS_PROPERTY_BOX_SHADOW,
GTK_CSS_PROPERTY_MARGIN_TOP,