diff options
author | Matthias Clasen <mclasen@redhat.com> | 2021-08-26 18:45:38 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2021-08-26 18:46:57 -0400 |
commit | 1c6aef18626533c3dd634a56fed7ba71be35b5be (patch) | |
tree | 62ccc6b59690757003676b644a92ef835c658482 | |
parent | 4653cbe56e970c2a5123329150e242cd89546215 (diff) | |
download | gtk+-1c6aef18626533c3dd634a56fed7ba71be35b5be.tar.gz |
textview: Apply line decoration from css
We were forgetting to propagate these values from
CSS to the default attributes.
-rw-r--r-- | gtk/gtktextview.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c index 9ab2c37a37..388a549f4e 100644 --- a/gtk/gtktextview.c +++ b/gtk/gtktextview.c @@ -58,6 +58,8 @@ #include "gtkwidgetprivate.h" #include "gtkjoinedmenuprivate.h" #include "gtkcsslineheightvalueprivate.h" +#include "gtkcssenumvalueprivate.h" + /** * GtkTextView: @@ -4991,6 +4993,7 @@ gtk_text_view_css_changed (GtkWidget *widget, if ((change == NULL || gtk_css_style_change_affects (change, GTK_CSS_AFFECTS_TEXT | + GTK_CSS_AFFECTS_TEXT_ATTRS | GTK_CSS_AFFECTS_BACKGROUND | GTK_CSS_AFFECTS_CONTENT)) && priv->layout && priv->layout->default_style) @@ -7634,6 +7637,29 @@ gtk_text_view_end_selection_drag (GtkTextView *text_view) * Layout utils */ +static PangoUnderline +get_pango_underline_from_style (GtkTextDecorationStyle style) +{ + switch (style) + { + case GTK_CSS_TEXT_DECORATION_STYLE_DOUBLE: + return PANGO_UNDERLINE_DOUBLE; + case GTK_CSS_TEXT_DECORATION_STYLE_WAVY: + return PANGO_UNDERLINE_ERROR; + case GTK_CSS_TEXT_DECORATION_STYLE_SOLID: + default: + return PANGO_UNDERLINE_SINGLE; + } + + g_return_val_if_reached (PANGO_UNDERLINE_SINGLE); +} + +static PangoOverline +get_pango_overline_from_style (GtkTextDecorationStyle style) +{ + return PANGO_OVERLINE_SINGLE; +} + static void gtk_text_view_set_attributes_from_style (GtkTextView *text_view, GtkTextAttributes *values) @@ -7641,7 +7667,10 @@ gtk_text_view_set_attributes_from_style (GtkTextView *text_view, GtkCssStyle *style; const GdkRGBA black = { 0, }; const GdkRGBA *color; + const GdkRGBA *decoration_color; double height; + GtkTextDecorationLine decoration_line; + GtkTextDecorationStyle decoration_style; if (!values->appearance.bg_rgba) values->appearance.bg_rgba = gdk_rgba_copy (&black); @@ -7673,6 +7702,58 @@ 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); + 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) + { + values->appearance.underline = get_pango_underline_from_style (decoration_style); + if (values->appearance.underline_rgba) + *values->appearance.underline_rgba = *decoration_color; + else + values->appearance.underline_rgba = gdk_rgba_copy (decoration_color); + } + else + { + values->appearance.underline = PANGO_UNDERLINE_NONE; + gdk_rgba_free (values->appearance.underline_rgba); + values->appearance.underline_rgba = NULL; + } + + if (decoration_line & GTK_CSS_TEXT_DECORATION_LINE_OVERLINE) + { + values->appearance.overline = get_pango_overline_from_style (decoration_style); + if (values->appearance.overline_rgba) + *values->appearance.overline_rgba = *decoration_color; + else + values->appearance.overline_rgba = gdk_rgba_copy (decoration_color); + } + else + { + values->appearance.overline = PANGO_OVERLINE_NONE; + gdk_rgba_free (values->appearance.overline_rgba); + values->appearance.overline_rgba = NULL; + } + + if (decoration_line & GTK_CSS_TEXT_DECORATION_LINE_LINE_THROUGH) + { + values->appearance.strikethrough = TRUE; + if (values->appearance.strikethrough_rgba) + *values->appearance.strikethrough_rgba = *decoration_color; + else + values->appearance.strikethrough_rgba = gdk_rgba_copy (decoration_color); + } + else + { + values->appearance.strikethrough = FALSE; + gdk_rgba_free (values->appearance.strikethrough_rgba); + values->appearance.strikethrough_rgba = NULL; + } } static void |