GNOME Bugzilla – Bug 332604
GtkLabel cannot have an alignment and be ellipsized in 2.8.12
Last modified: 2011-02-04 16:10:53 UTC
Please describe the problem: In GTK 2.8.12 if I make a label able to be ellipsized, and give it an alignment, the alignment is not respected. This worked in earlier versions. Steps to reproduce: 1. Run the code I'm going to attach with GTK 2.8.12 (and PyGTK). 2. If you want to see it work, run it again with 2.8.10 or 2.8.11. Actual results: The label is not right-aligned when using 2.8.12 and it can be ellipsized. Expected results: The behavior should be the same; specifically the label should be right-aligned in both cases. Does this happen every time? Yes. Other information:
Created attachment 60144 [details] a demo of an ellipsized and 1.0,0.5-aligned label
This seems to have been caused by the change from revision 1.181.2.3 of gtklabel.c:2181. When I revert this change, it works again. According to GDB, pango_layout_get_width is returning something not equal to -1; pango_layout_get_width isn't documented to return -1 ever, so I'm not sure when this should happen.
pango_layout_get_width returns -1 if no width is set, or -1 is set. -1 means no width limit.
Created attachment 65354 [details] Resetting layout with makes it "work" again. Okay. This extended example shows the problem in more detail: The layout's width is (properly) -1 until it's ellipsized; then it goes to 1024, which is incorrect. After manually calling PangoLayout.set_width it aligns properly again, until the widget is redrawn (e.g. try resizing the window).
Created attachment 66330 [details] another testcase Here's another testcase I wrote. And indeed, it also works as expected with 2.8.11
Created attachment 66332 [details] more elaborate testcase Extra test string stolen from bug 322042 which triggered the previous bugfix. To me it seems something is confusing alignment with justification. According to API docs the set_justify() calls should make no difference, but apparently it makes the labels align correctly. (The first label between the separators doesn't have explicit justification set, the second has justification that matches the alignment.)
Reopening 322042, since that fix is clearly not right.
Created attachment 71221 [details] [review] Fix alignment and padding problem
Created attachment 71239 [details] [review] additional RTL-text support This patch aligns the logical rect of the layout (and not the layout itself) inside the label according to the alignment and padding properties.
Created attachment 71266 [details] [review] alternative patch Sets the layout-width for ellipsized labels in the size_allocate function according to the required size (calculated line by line). This allows alignment for mixed LTR and RTL labels.
I think what we need here is a testcase showing a bunch of labels with various alignment/justification/ellipsation combinations, similar to what testcellrenderertext.c does for cell renderers
Created attachment 71718 [details] label test source A test file with some test cases for the alignment and padding problem.
The last patch appears to give the right behaviour, from playing around with it: - xalign works again for labels with ellipsization turned on - justify only affects the relative positioning of lines in multiline labels, not the positioning of the label inside a container Behdad, does it make sense to you ?
Doesn't need to walk the lines. pango_layout_get_extents() does that. I'll cook a patch as soon as I setup an svn checkout.
Created attachment 79355 [details] [review] my patch proposed patch, based on patch in 71266.
2007-01-03 Matthias Clasen <mclasen@redhat.com> Fix #332604, reported by Joe Wreschnig, patch by Jan Arne Petersen and Behdad Esfahbod. * gtk/gtklabel.c (gtk_label_size_allocate): Only set the width of the layout when necessary. (get_layout_location): Use pango_layout_get_pixel_extents() instead of pango_layout_get_width().