GNOME Bugzilla – Bug 697357
Selectable labels redraw wrong in gtjk 3.8
Last modified: 2013-05-31 06:25:07 UTC
In the testgtk labels test if you enable selectable and select a region then the part of the labels which are on a row that is selected, but not selected, redraw wrong.
Created attachment 240745 [details] example
Created attachment 240929 [details] [review] Workaround bug in drawing multiline selection label From what I could see, what happens is that on lines with both selected & unselected text, the entire text is redrawn using the selected foreground color. It also happens with GTK2, only if the colors are the same it might get unnoticed. Here however, it's hard to miss. I don't know much about pango innerworkings, so I don't know why this is or what, but it isn't actually the entire line that's affected, boundaries are determined by attributes. E.g. make a selection and go to a line with a word or two in e.g. different color, they won't be badly drawn, until one character gets to be part of the selection. This patch is more a workaround than a fix really, but by adding an attribute over the entire selection we make sure the rendering is always as expected (nothing outside of selection gets improperly redrawn).
Looking at gtk_label_draw() in the selected case we do: clip = gdk_pango_layout_get_clip_region (priv->layout, x, y, range, 1); gdk_cairo_region (cr, clip); cairo_clip (cr); get the selected color bg and fg, then: gdk_cairo_set_source_rgba (cr, &bg_color); cairo_paint (cr); gdk_cairo_set_source_rgba (cr, &fg_color); cairo_move_to (cr, x, y); _gtk_pango_fill_layout (cr, priv->layout); The bg_color paint is correctly clipped, but for some reason its like _gtk_pango_fill_layout doesn't respect the clipping region set. Commenting out the fill call makes everything look right (except there is no text inside the selected region). I think the attribute changes causes it to separate the drawing into separate sections with different drawing attributes which means we get separate calls to gtk_fill_layout_renderer_draw_glyphs. Some are entierly outside the clip region and gets clipped on a higher level. So, this points to a problem with pango_cairo_show_glyph_string() not respecting clipping.
Yeah, this seems to be a pango cairo issue. I've got a patch that adds some clipping to the cairo version of pango-viewer, and it shows the same behaviour
Created attachment 240934 [details] [review] Example patch for pango-cairo
Created attachment 240936 [details] pango-cairo output When i patch pango with the above and run: ./pango-view --backend=cairo test-mixed.txt I get this output. See how the text renders outside the red area, which should indicate the clipping region.
Created attachment 240939 [details] cairo trace of issue I can also reproduce the bug with: ./pango-view --backend=cairo test-latin.txt -w 200 Here is a cairo-trace log from that.
To me sounds like a cairo issue. Pango never sets or resets cairo clip.
Fixed in: http://cgit.freedesktop.org/cairo/commit/?id=41bef0fc385381b8c6b9091ec7ca2abe04cfc147