From cee4622567f8eea0a2e168cbe641855cabd6e7ce Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 17 Sep 2017 21:27:59 -0400 Subject: [PATCH] css: Implement font-kerning This gets translated to the OpenType feature kern. --- gtk/gtkcssstyle.c | 7 +++++++ gtk/gtkcssstylepropertyimpl.c | 21 +++++++++++++++++++++ gtk/gtkcsstypesprivate.h | 1 + 3 files changed, 29 insertions(+) diff --git a/gtk/gtkcssstyle.c b/gtk/gtkcssstyle.c index 250371f7fe..dcce352b32 100644 --- a/gtk/gtkcssstyle.c +++ b/gtk/gtkcssstyle.c @@ -225,6 +225,7 @@ gtk_css_style_get_pango_attributes (GtkCssStyle *style) const GdkRGBA *color; const GdkRGBA *decoration_color; gint letter_spacing; + GtkCssValue *kerning; /* text-decoration */ decoration_line = _gtk_css_text_decoration_line_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_TEXT_DECORATION_LINE)); @@ -260,6 +261,12 @@ gtk_css_style_get_pango_attributes (GtkCssStyle *style) attrs = add_pango_attr (attrs, pango_attr_letter_spacing_new (letter_spacing * PANGO_SCALE)); } + kerning = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_FONT_KERNING); + if (strcmp (_gtk_css_ident_value_get (kerning), "normal") == 0) + attrs = add_pango_attr (attrs, pango_attr_font_features_new ("kern 1")); + else if (strcmp (_gtk_css_ident_value_get (kerning), "none") == 0) + attrs = add_pango_attr (attrs, pango_attr_font_features_new ("kern 0")); + return attrs; } diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c index d50b2d3129..bf98160fd1 100644 --- a/gtk/gtkcssstylepropertyimpl.c +++ b/gtk/gtkcssstylepropertyimpl.c @@ -530,6 +530,19 @@ parse_text_decoration_style (GtkCssStyleProperty *property, return value; } +static GtkCssValue * +parse_font_kerning (GtkCssStyleProperty *property, + GtkCssParser *parser) +{ + GtkCssValue *value = NULL; + + value = _gtk_css_ident_value_try (parser, "auto", "normal", "none", NULL); + if (value == NULL) + _gtk_css_parser_error (parser, "unknown value for property"); + + return value; +} + static GtkCssValue * box_shadow_value_parse (GtkCssStyleProperty *property, GtkCssParser *parser) @@ -1015,6 +1028,14 @@ _gtk_css_style_property_init_properties (void) parse_text_decoration_style, NULL, _gtk_css_text_decoration_style_value_new (GTK_CSS_TEXT_DECORATION_STYLE_SOLID)); + gtk_css_style_property_register ("font-kerning", + GTK_CSS_PROPERTY_FONT_KERNING, + G_TYPE_NONE, + 0, + GTK_CSS_AFFECTS_TEXT | GTK_CSS_AFFECTS_TEXT_ATTRS, + parse_font_kerning, + NULL, + _gtk_css_ident_value_new ("auto")); gtk_css_style_property_register ("text-shadow", GTK_CSS_PROPERTY_TEXT_SHADOW, diff --git a/gtk/gtkcsstypesprivate.h b/gtk/gtkcsstypesprivate.h index 27d9af8566..b4f79fb80c 100644 --- a/gtk/gtkcsstypesprivate.h +++ b/gtk/gtkcsstypesprivate.h @@ -163,6 +163,7 @@ enum { /*< skip >*/ GTK_CSS_PROPERTY_TEXT_DECORATION_LINE, GTK_CSS_PROPERTY_TEXT_DECORATION_COLOR, GTK_CSS_PROPERTY_TEXT_DECORATION_STYLE, + GTK_CSS_PROPERTY_FONT_KERNING, GTK_CSS_PROPERTY_TEXT_SHADOW, GTK_CSS_PROPERTY_BOX_SHADOW, GTK_CSS_PROPERTY_MARGIN_TOP,