GNOME Bugzilla – Bug 452361
set_width() and set_ellipsize() misbehaving with very large lines
Last modified: 2018-05-22 12:29:57 UTC
Please describe the problem: I display a large amount of text in a restricted space, so I use set_width() and set_ellipsize() to let pango cut the text. It works fine, except when the line is very large, then the text escapes its boundaries. Steps to reproduce: Here is a minimal testcase in pygtk: import gtk import pango from random import random import cairo #SIZE = 1000 # Good SIZE = 15000 # Bad class Widget(gtk.DrawingArea): def __init__(self): gtk.DrawingArea.__init__(self) self.connect('expose-event', type(self).expose_event) self.modify_font(pango.FontDescription('Monospace 24')) def expose_event(self, event): context = self.window.cairo_create() text = '<' + str(random()) * SIZE + '>' pl = self.create_pango_layout(text) pl.set_width(int(self.allocation.width * pango.SCALE)) pl.set_ellipsize(pango.ELLIPSIZE_MIDDLE) context.set_source_rgb(random(), random(), random()) context.show_layout(pl) return False win = gtk.Window() box = gtk.HBox() for i in xrange(4): box.add(Widget()) win.add(box) win.show_all() gtk.main() Actual results: With, the SIZE set to 1000, it works fine. Resizing the window show the ellipsize effect. With SIZE set to 15000, the display is garbled. By the way, in both cases, the speed is quite slow. It is expected, because of the size of the buffer, but I wouldn't mind if it was faster ;-) Expected results: With SIZE set to 15000, the display should be similar to the one with SIZE set to 1000. Does this happen every time? Yes. Other information:
Created attachment 90902 [details] Screenshot with SIZE = 1000 => OK
Created attachment 90903 [details] Screenshot with SIZE = 20000 => BAD Actually, with SIZE = 20000 instead of 15000, not only the text is not between '<' and '>' it superposes with garbage.
Thanks, I can reproduce it here. Will look into it.
Created attachment 100776 [details] [review] working patch Worked on this a bit last night. Patch doesn't fix it yet, it's obviously just the start...
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/pango/issues/81.