GNOME Bugzilla – Bug 327996
Ellipsizing wrapped text
Last modified: 2018-05-22 12:14:36 UTC
Pango should have a way to ellipsize wrapped text and do that correctly. That is, to tell it to ellipsize text to two lines for example, so you get something like: +---------------------+ |This is a long text | |that is ellipsized...| +---------------------+
Thinking about it, it may be done by setting a height on the layout, like we set width...
I was initially thinking about implementing this when I was doing the current ellipsization support, but decided that it was going to make an already difficult job considerably harder. Especially if you support all the ellipsization positions. (Any position other than end is probably best done as a two-pass operation ... shape the entire layout, then go back and eliminate lines, then ellipsize the omitted text into a single line.)
Adding myself to CC to track this, Maemo platform is interested to have this feature.
Nautilus bug 84390 could really use multi-line truncation in order to address icon layout improvements. I looked process_line() in pango_layout.c at some ideas, but your basic plan as described above seems sound. Adding start and end truncation seems very manageable. I think middle truncation should actually truncate the last line in the middle. In my previous experiments, this looked pretty good and seemed to convey the maximum amount of information. Thanks!
As Gene Z. Ragan said. It would be a useful in resolving bug 84390. I've tried a solution but pango code got me completely lost. I'm adding to the CC list for future checkup.
Owen: While API users can easily determine what line exceeds a certain amount of vertical space (*), I don't see any practicable way to create a new ellipsized layout from that: While the rest of lines could be thrown away using pango_layout_line_unref (), and maybe the new text can be fetched using pango_layout_get_text () I think we have no way of telling pango to render the last line ellipsized, except by using crude hacks (replace the last few characters with "..." [what about an RTL special-case], or append garbage to the last line and use ellipsization - which would possibly break overlong previous lines). Do you remember what about a the max_height implementation is particularly challenging when doing ellipsization? The first (unneccessary in some ellipsization modes) approach would be to just create the full layout and then throw away lines [from the beginning, middle or end, depending on the mode] until the max_height is reached, and then just display "..." at a certain position instead of a few characters. (*) for instance using pango_layout_get_pixel_extents() and iterating over the pango_layout_get_line_readonly() lines until this space is reached, also considering the line spacing
Bug 147608 also offers some possible solution, I'm not sure whether this includes a height or line count limit.
Humm, seems like I opened a new bug for it. See bug 469313. Keeping this one open for now since it has useful discussion.
-- 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/36.