textview: add support for underline and strikethrough colors
This commit adds the GtkTextTag:underline-rgba and :strikethrough-rgba properties and the necessary plumbing to apply these colors in GtkTextLayout. With this change, you can alter the color of underlines including those of type PANGO_UNDERLINE_ERROR. You might want to alter the underline color to differentiate between spelling and grammer mistakes. In code editors, it is convenient to differentiate between errors and warnings. Note that the GtkTextAppearance struct is public ABI and has no spare room for new fields, so we are resorting to some tricky packing to store the colors in the unused pixel field of the fg_color and bg_color structs. This packing is accomplished by the macros in gtktextattributesprivate.h. Signed-off-by: Christian Hergert <christian@hergert.me> https://bugzilla.gnome.org/show_bug.cgi?id=402168
This commit is contained in:
committed by
Matthias Clasen
parent
416c370da1
commit
28063ee2e4
@ -4793,10 +4793,38 @@ get_tag_for_attributes (PangoAttrIterator *iter)
|
||||
if (attr)
|
||||
g_object_set (tag, "underline", ((PangoAttrInt*)attr)->value, NULL);
|
||||
|
||||
attr = pango_attr_iterator_get (iter, PANGO_ATTR_UNDERLINE_COLOR);
|
||||
if (attr)
|
||||
{
|
||||
PangoColor *color;
|
||||
GdkRGBA rgba;
|
||||
|
||||
color = &((PangoAttrColor*)attr)->color;
|
||||
rgba.red = color->red / 65535.;
|
||||
rgba.green = color->green / 65535.;
|
||||
rgba.blue = color->blue / 65535.;
|
||||
rgba.alpha = 1.;
|
||||
g_object_set (tag, "underline-rgba", &rgba, NULL);
|
||||
}
|
||||
|
||||
attr = pango_attr_iterator_get (iter, PANGO_ATTR_STRIKETHROUGH);
|
||||
if (attr)
|
||||
g_object_set (tag, "strikethrough", (gboolean) (((PangoAttrInt*)attr)->value != 0), NULL);
|
||||
|
||||
attr = pango_attr_iterator_get (iter, PANGO_ATTR_STRIKETHROUGH_COLOR);
|
||||
if (attr)
|
||||
{
|
||||
PangoColor *color;
|
||||
GdkRGBA rgba;
|
||||
|
||||
color = &((PangoAttrColor*)attr)->color;
|
||||
rgba.red = color->red / 65535.;
|
||||
rgba.green = color->green / 65535.;
|
||||
rgba.blue = color->blue / 65535.;
|
||||
rgba.alpha = 1.;
|
||||
g_object_set (tag, "strikethrough-rgba", &rgba, NULL);
|
||||
}
|
||||
|
||||
attr = pango_attr_iterator_get (iter, PANGO_ATTR_RISE);
|
||||
if (attr)
|
||||
g_object_set (tag, "rise", ((PangoAttrInt*)attr)->value, NULL);
|
||||
|
||||
Reference in New Issue
Block a user