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 332604 - GtkLabel cannot have an alignment and be ellipsized in 2.8.12
GtkLabel cannot have an alignment and be ellipsized in 2.8.12
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: Other
2.8.x
Other All
: Normal normal
: ---
Assigned To: Behdad Esfahbod
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2006-02-26 09:55 UTC by Joe Wreschnig
Modified: 2011-02-04 16:10 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
a demo of an ellipsized and 1.0,0.5-aligned label (305 bytes, text/plain)
2006-02-26 09:56 UTC, Joe Wreschnig
  Details
Resetting layout with makes it "work" again. (615 bytes, text/plain)
2006-05-12 21:59 UTC, Joe Wreschnig
  Details
another testcase (750 bytes, text/plain)
2006-05-27 11:25 UTC, Tommi Komulainen
  Details
more elaborate testcase (1.94 KB, text/plain)
2006-05-27 13:17 UTC, Tommi Komulainen
  Details
Fix alignment and padding problem (1.55 KB, patch)
2006-08-19 23:12 UTC, Jan Arne Petersen
none Details | Review
additional RTL-text support (2.31 KB, patch)
2006-08-20 10:22 UTC, Jan Arne Petersen
none Details | Review
alternative patch (2.12 KB, patch)
2006-08-20 22:03 UTC, Jan Arne Petersen
none Details | Review
label test source (9.57 KB, text/x-csrc)
2006-08-27 19:50 UTC, Jan Arne Petersen
  Details
my patch (1.35 KB, patch)
2007-01-04 05:14 UTC, Behdad Esfahbod
none Details | Review

Description Joe Wreschnig 2006-02-26 09:55:08 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:
Comment 1 Joe Wreschnig 2006-02-26 09:56:03 UTC
Created attachment 60144 [details]
a demo of an ellipsized and 1.0,0.5-aligned label
Comment 2 Joe Wreschnig 2006-05-12 21:13:53 UTC
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.
Comment 3 Behdad Esfahbod 2006-05-12 21:28:27 UTC
pango_layout_get_width returns -1 if no width is set, or -1 is set.  -1 means no width limit.
Comment 4 Joe Wreschnig 2006-05-12 21:59:42 UTC
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).
Comment 5 Tommi Komulainen 2006-05-27 11:25:33 UTC
Created attachment 66330 [details]
another testcase

Here's another testcase I wrote. And indeed, it also works as expected with 2.8.11
Comment 6 Tommi Komulainen 2006-05-27 13:17:03 UTC
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.)
Comment 7 Kristian Rietveld 2006-05-30 16:15:11 UTC
Reopening 322042, since that fix is clearly not right.
Comment 8 Jan Arne Petersen 2006-08-19 23:12:17 UTC
Created attachment 71221 [details] [review]
Fix alignment and padding problem
Comment 9 Jan Arne Petersen 2006-08-20 10:22:14 UTC
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.
Comment 10 Jan Arne Petersen 2006-08-20 22:03:11 UTC
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.
Comment 11 Matthias Clasen 2006-08-26 04:18:26 UTC
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
Comment 12 Jan Arne Petersen 2006-08-27 19:50:32 UTC
Created attachment 71718 [details]
label test source

A test file with some test cases for the alignment and padding problem.
Comment 13 Matthias Clasen 2006-12-30 07:03:04 UTC
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 ?
Comment 14 Behdad Esfahbod 2006-12-30 17:01:00 UTC
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.
Comment 15 Behdad Esfahbod 2007-01-04 05:14:21 UTC
Created attachment 79355 [details] [review]
my patch

proposed patch, based on patch in 71266.
Comment 16 Matthias Clasen 2007-01-04 06:00:49 UTC
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().