From: Matthias Clasen Date: Fri, 27 Aug 2021 00:21:23 +0000 (-0400) Subject: textview: Apply font features from css X-Git-Tag: archive/raspbian/4.4.1+ds1-2+rpi1^2~18^2^2~124^2~15 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=6ad047ab798f7d524bd6379b15d3e9d661f8b454;p=gtk4.git textview: Apply font features from css We were forgetting to propagate these values from CSS to the default attributes. Share the code for getting these values out of a GtkCssStyle. --- diff --git a/gtk/gtkcssstyle.c b/gtk/gtkcssstyle.c index 0f890a005d..03e58ab027 100644 --- a/gtk/gtkcssstyle.c +++ b/gtk/gtkcssstyle.c @@ -428,64 +428,14 @@ append_separated (GString **s, g_string_append (*s, text); } -PangoAttrList * -gtk_css_style_get_pango_attributes (GtkCssStyle *style) +char * +gtk_css_style_compute_font_features (GtkCssStyle *style) { - PangoAttrList *attrs = NULL; - GtkTextDecorationLine decoration_line; - GtkTextDecorationStyle decoration_style; - const GdkRGBA *color; - const GdkRGBA *decoration_color; - int letter_spacing; GtkCssFontVariantLigature ligatures; GtkCssFontVariantNumeric numeric; GtkCssFontVariantEastAsian east_asian; - GString *s; char *settings; - - /* text-decoration */ - decoration_line = _gtk_css_text_decoration_line_value_get (style->font_variant->text_decoration_line); - decoration_style = _gtk_css_text_decoration_style_value_get (style->font_variant->text_decoration_style); - color = gtk_css_color_value_get_rgba (style->core->color); - decoration_color = gtk_css_color_value_get_rgba (style->font_variant->text_decoration_color - ? style->font_variant->text_decoration_color - : style->core->color); - - if (decoration_line & GTK_CSS_TEXT_DECORATION_LINE_UNDERLINE) - { - attrs = add_pango_attr (attrs, pango_attr_underline_new (get_pango_underline_from_style (decoration_style))); - if (!gdk_rgba_equal (color, decoration_color)) - attrs = add_pango_attr (attrs, pango_attr_underline_color_new (decoration_color->red * 65535. + 0.5, - decoration_color->green * 65535. + 0.5, - decoration_color->blue * 65535. + 0.5)); - } - if (decoration_line & GTK_CSS_TEXT_DECORATION_LINE_OVERLINE) - { - attrs = add_pango_attr (attrs, pango_attr_overline_new (get_pango_overline_from_style (decoration_style))); - if (!gdk_rgba_equal (color, decoration_color)) - attrs = add_pango_attr (attrs, pango_attr_overline_color_new (decoration_color->red * 65535. + 0.5, - decoration_color->green * 65535. + 0.5, - decoration_color->blue * 65535. + 0.5)); - } - if (decoration_line & GTK_CSS_TEXT_DECORATION_LINE_LINE_THROUGH) - { - attrs = add_pango_attr (attrs, pango_attr_strikethrough_new (TRUE)); - if (!gdk_rgba_equal (color, decoration_color)) - attrs = add_pango_attr (attrs, pango_attr_strikethrough_color_new (decoration_color->red * 65535. + 0.5, - decoration_color->green * 65535. + 0.5, - decoration_color->blue * 65535. + 0.5)); - } - - /* letter-spacing */ - letter_spacing = _gtk_css_number_value_get (style->font->letter_spacing, 100); - if (letter_spacing != 0) - { - attrs = add_pango_attr (attrs, pango_attr_letter_spacing_new (letter_spacing * PANGO_SCALE)); - } - - /* OpenType features */ - - s = NULL; + GString *s = NULL; switch (_gtk_css_font_kerning_value_get (style->font_variant->font_kerning)) { @@ -635,11 +585,72 @@ gtk_css_style_get_pango_attributes (GtkCssStyle *style) } if (s) + return g_string_free (s, FALSE); + else + return NULL; +} + +PangoAttrList * +gtk_css_style_get_pango_attributes (GtkCssStyle *style) +{ + PangoAttrList *attrs = NULL; + GtkTextDecorationLine decoration_line; + GtkTextDecorationStyle decoration_style; + const GdkRGBA *color; + const GdkRGBA *decoration_color; + int letter_spacing; + + /* text-decoration */ + decoration_line = _gtk_css_text_decoration_line_value_get (style->font_variant->text_decoration_line); + decoration_style = _gtk_css_text_decoration_style_value_get (style->font_variant->text_decoration_style); + color = gtk_css_color_value_get_rgba (style->core->color); + decoration_color = gtk_css_color_value_get_rgba (style->font_variant->text_decoration_color + ? style->font_variant->text_decoration_color + : style->core->color); + + if (decoration_line & GTK_CSS_TEXT_DECORATION_LINE_UNDERLINE) { - attrs = add_pango_attr (attrs, pango_attr_font_features_new (s->str)); - g_string_free (s, TRUE); + attrs = add_pango_attr (attrs, pango_attr_underline_new (get_pango_underline_from_style (decoration_style))); + if (!gdk_rgba_equal (color, decoration_color)) + attrs = add_pango_attr (attrs, pango_attr_underline_color_new (decoration_color->red * 65535. + 0.5, + decoration_color->green * 65535. + 0.5, + decoration_color->blue * 65535. + 0.5)); + } + if (decoration_line & GTK_CSS_TEXT_DECORATION_LINE_OVERLINE) + { + attrs = add_pango_attr (attrs, pango_attr_overline_new (get_pango_overline_from_style (decoration_style))); + if (!gdk_rgba_equal (color, decoration_color)) + attrs = add_pango_attr (attrs, pango_attr_overline_color_new (decoration_color->red * 65535. + 0.5, + decoration_color->green * 65535. + 0.5, + decoration_color->blue * 65535. + 0.5)); + } + if (decoration_line & GTK_CSS_TEXT_DECORATION_LINE_LINE_THROUGH) + { + attrs = add_pango_attr (attrs, pango_attr_strikethrough_new (TRUE)); + if (!gdk_rgba_equal (color, decoration_color)) + attrs = add_pango_attr (attrs, pango_attr_strikethrough_color_new (decoration_color->red * 65535. + 0.5, + decoration_color->green * 65535. + 0.5, + decoration_color->blue * 65535. + 0.5)); } + /* letter-spacing */ + letter_spacing = _gtk_css_number_value_get (style->font->letter_spacing, 100); + if (letter_spacing != 0) + { + attrs = add_pango_attr (attrs, pango_attr_letter_spacing_new (letter_spacing * PANGO_SCALE)); + } + + /* OpenType features */ + { + char *font_features = gtk_css_style_compute_font_features (style); + + if (font_features) + { + attrs = add_pango_attr (attrs, pango_attr_font_features_new (font_features)); + g_free (font_features); + } + } + return attrs; } diff --git a/gtk/gtkcssstyleprivate.h b/gtk/gtkcssstyleprivate.h index 27666e9978..2bbf72058e 100644 --- a/gtk/gtkcssstyleprivate.h +++ b/gtk/gtkcssstyleprivate.h @@ -254,17 +254,17 @@ GtkCssValue * gtk_css_style_get_value (GtkCssStyle GtkCssSection * gtk_css_style_get_section (GtkCssStyle *style, guint id) G_GNUC_PURE; gboolean gtk_css_style_is_static (GtkCssStyle *style) G_GNUC_PURE; +GtkCssStaticStyle * gtk_css_style_get_static_style (GtkCssStyle *style); char * gtk_css_style_to_string (GtkCssStyle *style); gboolean gtk_css_style_print (GtkCssStyle *style, GString *string, guint indent, gboolean skip_initial); -PangoAttrList * gtk_css_style_get_pango_attributes (GtkCssStyle *style); +char * gtk_css_style_compute_font_features (GtkCssStyle *style); +PangoAttrList * gtk_css_style_get_pango_attributes (GtkCssStyle *style); PangoFontDescription * gtk_css_style_get_pango_font (GtkCssStyle *style); -GtkCssStaticStyle * gtk_css_style_get_static_style (GtkCssStyle *style); - GtkCssValues *gtk_css_values_new (GtkCssValuesType type); GtkCssValues *gtk_css_values_ref (GtkCssValues *values); diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c index fa085d0154..e37d44c722 100644 --- a/gtk/gtktextview.c +++ b/gtk/gtktextview.c @@ -57,7 +57,6 @@ #include "gtknative.h" #include "gtkwidgetprivate.h" #include "gtkjoinedmenuprivate.h" -#include "gtkcsslineheightvalueprivate.h" #include "gtkcssenumvalueprivate.h" /** @@ -7667,7 +7666,6 @@ gtk_text_view_set_attributes_from_style (GtkTextView *text_view, const GdkRGBA black = { 0, }; const GdkRGBA *color; const GdkRGBA *decoration_color; - double height; GtkTextDecorationLine decoration_line; GtkTextDecorationStyle decoration_style; @@ -7691,6 +7689,7 @@ gtk_text_view_set_attributes_from_style (GtkTextView *text_view, values->letter_spacing = _gtk_css_number_value_get (style->font->letter_spacing, 100) * PANGO_SCALE; /* text-decoration */ + decoration_line = _gtk_css_text_decoration_line_value_get (style->font_variant->text_decoration_line); decoration_style = _gtk_css_text_decoration_style_value_get (style->font_variant->text_decoration_style); color = gtk_css_color_value_get_rgba (style->core->color); @@ -7742,6 +7741,13 @@ gtk_text_view_set_attributes_from_style (GtkTextView *text_view, gdk_rgba_free (values->appearance.strikethrough_rgba); values->appearance.strikethrough_rgba = NULL; } + + /* letter-spacing */ + values->letter_spacing = _gtk_css_number_value_get (style->font->letter_spacing, 100) * PANGO_SCALE; + + /* OpenType features */ + g_free (values->font_features); + values->font_features = gtk_css_style_compute_font_features (style); } static void