GNOME Bugzilla – Bug 402168
Add underline-color and strikethrough-color to GtkTextTag properties
Last modified: 2015-03-24 13:30:05 UTC
GtkTextTag have underline and strikethrough gobject properties but there is not a easy way to select a color to display these items. By default they use the foreground color, but sometimes you want to use a different color (use different colors to underline different errors on a source file for example). GtkTextView have "underline-error-color" style property that deals with the underline-color problem. But this is a style property, so I have to deal with rc files or GtkRCStyle and so on. An direct gobject property would be very nice. And this deals only with PANGO_UNDERLINE_ERROR. Pango supports this using pango_renderer_set_color and the appropriate PangoRenderPart.
Created attachment 81524 [details] [review] Add underline-color and strikethrough-color to GtkTextTag Add underline-color and strikethrough-color to GtkTextTag. There is a couple of issues with these patch. Well, it works (in a limited case). I can set underline-color and strikethrough-color and see the corresponding feature in bright colors, but: - (Probably) these patch breaks ABI - I can't figure from GtkTextAppearance which property user setted on the tag, so I can't fallback to reasonable default (like foreground color to strikethrough and normal underlines, red or underline-error-color style property to PANGO_UNDERLINE_ERROR. It's a working in progress... just a start... I know that a (much) better patch will be needed to CLOSE this issue.
Yes, we can't grow the public structs like this. If you want to do something like this, you will probably have to add a different GtkTextAppearanceExt struct and duplicate the machinery used to transport properties from tags down to the renderer for this new struct. Doable, just a fair amount of work.
I was looking how properties goes from tags to renderer (gtklayout.c, gtkdisplay.c, gtktexttag.c, gtktextview.c) . Everything seems really doable but I can't figure out where to put these new GtkTextAppearanceExt struct. These struct need a way to be connected with GtkTextTag. Maybe add GtkTextAppearanceExt as private data of GtkTextAppearance? (don't look a *good thing* but could works). Once I figure out how exactly todo this I will try a new patch... I will learn a little bit of GTK+ text rendering internals doing this. :)
Yes, GtkTextTag is a GObject, so I would use private data.
I actually looked into doing this a while ago while fixing bug 740954, but I ran into some issues and eventually gave up on it.
Created attachment 296428 [details] [review] add support for setting pango underline color This does not address the strikethrough, but it does add "underline-rgba" without modifying public headers. It does so by stealing a few bytes from padding around GdkColor (sizeof(GdkColor) == 12, but only 10 bytes are used). I've used a couple of macros to make accessing these bits non-ugly. We could go the route of the extended structure, but i need this today in Builder and this sort of gets me there.
I have to say, I think this is too ugly and fragile. At the very least, it would need some unit test or static assertion to ensure that the abi is unaffected.
I changed my mind, and added strikethrough color to this as well.
This API addition was added to the stable branch after the 3.16.0 release. Was that intentional?
I hoped nobody would notice