GNOME Bugzilla – Bug 355789
Pango misaligns word-wrapped text due to trailing whitespace
Last modified: 2007-05-02 06:48:34 UTC
Please describe the problem: I wrote a test program that goes through each combination of logical/ink, line/cluster/run/char, and left/center/right alignment. When pango splits a line due to word-wrapping, it leaves the whitespace on the preceding line, which is then included as part of that line when it attempts to center-align or right-align the text. The result is that the text is not visually aligned. It is visually correct when left-align is used, but I believe the extents are wrong there too. Although the text is wrong on all modes of my test program, the following modes show it clearly via the extent boxes: 1: left line logical. 3: left cluster logical. Partially obscured by bug #355782 5: left run logical. 6: left run ink. These extra runs may actually have some uses, so long as they didn't interfere with alignment. 9: center line logical. 11: center cluster logical. Partially obscured by bug #355782 13: center run logical. 14: center run ink. Again, the extra runs may have uses. 17: right line logical. 19: right cluster logical. 21: right run logical. 22: right run ink. The extra runs here are are drawn over the red boundary box. I will attach the test program (which uses pygtk). Note that it demonstrates two other bugs (mixaligned extents, char crashes). I will file reports for them separately. Steps to reproduce: Actual results: Expected results: Does this happen every time? Other information:
Created attachment 72702 [details] Test program
Forgot to mention, when you run the test program, hit space to see the next combination.
bug 355782 has some discussion about this.
For center-aligned text, trailing empty glyphs should be ignored in alignment calculations, but be there otherwise (cursor movement etc). For right-aligned text, we should break line /before/ space characters. IOW, move the spaces to the beginning of the next line. This needs help from break.c, and the diverging from the Unicode line-breaking algorithm, and is harder to implement correctly. Or maybe we should not change break.c and fix-up in PangoLayout? The alignment is a property of PangoLayout afterall.
Consider the text "Lorem ipsum. Dolor sit amet." Right-aligned to 15 columns, with whitespace removed 123456789012345 Lorem ipsum. Dolor sit amet. whitespace not removed, intermediate state 123456789012345 Lorem ipsum. Dolor sit amet. # Too wide! Whitespace not removed, what actually happens 123456789012345 Lorem ipsum. Dolor sit amet. # Ugly, visually would have fit Openoffice (correctly IMO) choses the first option. Whitespace is irrelevent to fitting text on a line unless it immediately follows a linefeed. There is a further problem how how extensively the whitespace is hidden. In Openoffice, you can hit right-arrow to go through it one space at a time, but your cursor won't move, and "View/Nonprinting Characters" option won't show it. I think it would be better if they retained full width, and were all shown when the suitable option is enabled, but were positioned past the right or left margins. I don't know if this will break existing software though.
*** Bug 434212 has been marked as a duplicate of this bug. ***
Created attachment 87357 [details] [review] [pango-view] Add option for testing text alignment Alignment renamed to align.
Committed --align after some tweaks. 2007-04-28 Mathias Hasselmann <mathias.hasselmann@gmx.de> * pango-view/viewer-render.c (make_layout), (parse_alignment), (parse_options): Add option for testing text alignment.
I've been thinking about this and I think the right thing to do is to make one whitespace char before a non-mandatory line-break zero-width. Still trying to figure out the least-changes approach to implementing that.
Ok, didn't go that bad, though the approach is a bit hacky, and it implements the third option of comment #5, not first. That is, the final whitespace is not ignored when breaking lines. So, eg if "test test" fits the line but not "test test ", it will break the line in between and removes the whitespace only after breaking. Not very good, but much easier to implement. 2007-05-02 Behdad Esfahbod <behdad@gnome.org> Bug 355789 – Pango misaligns word-wrapped text due to trailing whitespace * pango/pango-layout.c (zero_line_final_space), (pango_layout_line_postprocess): Make logical-final whitespace on wrapped lines zero-width.
Can close now :).