! Please note that this is a snapshot of our old Bugzilla server, which is read only since May 29, 2020. Please go to gitlab.xfce.org for our new server !
Improved ellipsization etc.
Status:
CLOSED: FIXED
Product:
Xfce4-clipman-plugin
Component:
General

Comments

Description Darren Salt 2006-08-06 15:40:52 CEST
Ellipsization (as it stands) is somewhat broken: it doesn't properly take into account that one character isn't necessarily one byte (or, for that matter, one glyph) or the width of each glyph.

Also, replacement of tabs, LFs and CRs need not be done: the label could be put into single-line mode (with the effect that you'll get [000A] and [000D] instead).
Comment 1 Darren Salt 2006-08-06 15:41:17 CEST
Created attachment 710 
Improve the ellipsization
Comment 2 Nick Schermer editbugs 2006-08-06 15:58:43 CEST
Although I agree with you there is one problem now, the title that is generated has the same length (thus size) as the clip, and it gets fully utf8 validated.
Both consume time and memory.

Maybe it's better to use g_strndup (txt, chars+5), so all the 'visible' characters have all their needed bytes?

If there is a decent solution for this, I'll apply the patch.

Thanks in advance,
Nick
Comment 3 Darren Salt 2006-08-06 16:23:17 CEST
chars+5 is not really any better. This really needs to be done according to the width of the rendered string. chars*6 is closer and is likely to be enough to cover use of combining marks, but is still (potentially) leaving the string short  if you have a lot of narrow glyphs.

Also, what if an option to control the position of the ellipsis is added?

Generating the title once would seem to be more appropriate, despite the memory usage. As things stand, it turns out that clipman_regenerate_titles() can be removed without side-effects.
Comment 4 Darren Salt 2006-08-06 17:14:52 CEST
MAXCHARS*8 should cover it, at least with PANGO_ELLIPSIZE_END. *6 will probably cover it too, but *8 leaves a margin for error. (There's still at least the pathological case - lots of zero-width (non-)joiners - but it's probably safe to ignore that.)

It *won't* cover it if PANGO_ELLIPSIZE_MIDDLE is used, at least not for long selections.
Comment 5 Nick Schermer editbugs 2006-08-06 22:08:20 CEST
I've committed you patch, removed the regenerate_title function and
added strndup (length*8), which could save some time/mem on huge
amounts of text.

I think an ellipses position option is a bit overkill, remember we're still
using Xfce :-).

Thanks for your time,
Nick
Comment 6 Darren Salt 2006-08-07 01:36:44 CEST
length*8 combined with the removal of regenerate_title is a bad choice. To demonstrate:

1. Set the length to 10 characters.
2. Select the whole of the initial description of this BTS entry.
3. Look at the clipman menu. Ellipsization is fine.
4. Set the length to 120 characters.
5. Look at the clipman menu. Whoops, no ellipsization.

The more non-ASCII glyphs are present, the sooner this will become obvious. From what I've seen of Chinese (simplified) text, each glyph requires three bytes (if encoded using UTF-8), so 10 characters -> 80 bytes -> 26 glyphs and one truncated character. That's important, because g_locale_to_utf8() will return NULL due to the invalid character, and there's no check for that -> segfault.
Comment 7 Darren Salt 2006-08-07 01:53:08 CEST
Created attachment 712 
Properly truncate UTF-8 strings & fix a null dereference.
Comment 8 Nick Schermer editbugs 2006-08-07 06:12:47 CEST
Committed, thanks

Bug #2128

Reported by:
Darren Salt
Reported on: 2006-08-06
Last modified on: 2012-04-09

People

Assignee:
Mike Massonnet
CC List:
0 users

Version

Version:
unspecified

Attachments

Additional information