GNOME Bugzilla – Bug 81906
Would be useful to have PANGO_WRAP_WORD_OR_CHAR
Last modified: 2004-12-22 21:47:04 UTC
Right now PangoLayout has this behavior with PANGO_WRAP_WORD: |This sentence| |may not fit | |and words are| |wrapped | |properly, but| |long words | |like | |supercalifragilistic |will look | |ugly. | <--- width ---> And this behavior with PANGO_WRAP_CHAR: |This sentence| |may not fit a| |nd words are | |wrapped prope| |rly, but long| |words like su| |percalifragil| |istic will lo| |ok ugly. | It would be useful to have a mix of the two that wraps at word boundaries unless there is a super-long word, where it would split it in half: |This sentence| |may not fit | |and words are| |wrapped | |properly, but| |long words | |like supercal| |ifragilistic | |will look | |ugly. |
We came across this while fixing a bug for gnome-icon-list
Or maybe even (with a bunch of "Underful hbox" warnings spewed to stderr :- ) |This sentence| |may not fit| |and words are| |wrapped pro-| |perly, but| |long words| |like superca-| |lifragilistic| |will look| |ugly. | Of course, TeX's paragraph builder is not the easiest thing to duplicate...
*** Bug 70477 has been marked as a duplicate of this bug. ***
*** Bug 91784 has been marked as a duplicate of this bug. ***
Created attachment 11336 [details] [review] Patch to implement PANGO_WRAP_WORD_CHAR in PangoLayout.
Created attachment 11337 [details] [review] Better patch
Please change failed_first_wrap to "always_wrap_char" - can_break_at() shouldn't care about the algorithms in the calling routine. the comment: * If @no_break_at_start is TRUE, then BREAK_NONE_FIT will never * be returned, a run will be added even if inserting the minimum amount * will cause the line to overflow. This is used when we've discovered * we can't break the line at all and have to backtrack and try again * allowing overflow. needs some fixing (before your changes) - since we don't backtrack in this case any more (if we ever did). I think @no_break_at_start problem should be renamed to @force_fit, since, if I'm not mistaken, you actually should be returning NONE_FIT for WORD_CHARS when nothing fits when @no_break_is_start is TRUE. This is to handle the case where the first character of the new item causes overflow. (I think to clarify this, it might be best to add another result type EMPTY_FIT to distinguish NOTHING_FIT but it was an OK end of the line)
Also, could you reverse first_try and call it retrying_with_char_breaks?
Created attachment 11359 [details] [review] New version
The new patch fixes all your comments, and removes the break_at_start variable in process_line.
Created attachment 11363 [details] [review] Updated patch.
This new patch fixes can_break_in to look at offset 0 too. It also handles the 2-pixel wide layout case by not breaking on char 0 if there are no previous runs.
As I mentioned yesterday on IRC, the sequence: if (width <= state->remaining_width && !no_break_at_end) { state->remaining_width -= width; insert_run (line, state, layout->text, item, TRUE); return BREAK_ALL_FIT; } also needs adjustment for the num_chars == 1 && !line->runs case or a single character item at the start of the line will cause infinite looping for the 2-pixel case. b
Created attachment 11406 [details] [review] Updated patch
New patch. This adds what you wanted and fixes a longstanding bug if the first item ALL_FITS, but is wider than the remaining width.
Created attachment 11407 [details] [review] sigh, new version with fixed long-standing bug (i hope)
2002-10-04 Alexander Larsson <alexl@redhat.com> * pango/pango-layout.[ch]: * docs/tmpl/layout.sgml: Add, implement and document PANGO_WRAP_WORD_CHAR