After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 697357 - Selectable labels redraw wrong in gtjk 3.8
Selectable labels redraw wrong in gtjk 3.8
Status: RESOLVED FIXED
Product: pango
Classification: Platform
Component: cairo
1.34.x
Other Linux
: Normal normal
: ---
Assigned To: pango-maint
pango-maint
Depends on:
Blocks:
 
 
Reported: 2013-04-05 13:51 UTC by Alexander Larsson
Modified: 2013-05-31 06:25 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
example (122.35 KB, image/png)
2013-04-05 13:52 UTC, Alexander Larsson
  Details
Workaround bug in drawing multiline selection label (2.62 KB, patch)
2013-04-08 08:52 UTC, Olivier Brunel (jjacky)
none Details | Review
Example patch for pango-cairo (614 bytes, patch)
2013-04-08 10:53 UTC, Alexander Larsson
none Details | Review
pango-cairo output (13.24 KB, image/png)
2013-04-08 10:55 UTC, Alexander Larsson
  Details
cairo trace of issue (4.00 KB, text/plain)
2013-04-08 11:49 UTC, Alexander Larsson
  Details

Description Alexander Larsson 2013-04-05 13:51:56 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.
Comment 1 Alexander Larsson 2013-04-05 13:52:28 UTC
Created attachment 240745 [details]
example
Comment 2 Olivier Brunel (jjacky) 2013-04-08 08:52:50 UTC
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).
Comment 3 Alexander Larsson 2013-04-08 10:32:00 UTC
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.
Comment 4 Alexander Larsson 2013-04-08 10:53:27 UTC
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
Comment 5 Alexander Larsson 2013-04-08 10:53:58 UTC
Created attachment 240934 [details] [review]
Example patch for pango-cairo
Comment 6 Alexander Larsson 2013-04-08 10:55:50 UTC
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.
Comment 7 Alexander Larsson 2013-04-08 11:49:07 UTC
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.
Comment 8 Behdad Esfahbod 2013-04-08 21:30:50 UTC
To me sounds like a cairo issue.  Pango never sets or resets cairo clip.