PetaMem has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks,
I have this HTML-table of a given size. Now I want to make sure, the text I will fill into it, will not expand it. Truncating text is ok.
However, as proportional font is used in display, I cannot simply say "truncate after n chars", because then I'd had to take n for the worst case (some MWMWMWMW string) and in that case the other extreme (some IIIIIIIII string) would get truncated too early.
So I thought of some heuristics, where every character would be given some units of width it has. The most narrow character would get 1 unit, whereas the most wide character would get some multiple of that value to approximate better than the one character = one width computation.
These values could be stored in some hash, where the char is the key, and the number of units is the value, and computation would be simply splitting the string to chars, iterating over that list and adding values. And truncating over some given threshold.
Now the questions:
Many thanks for your suggestions.
Bye
PetaMem All Perl: MT, NLP, NLU
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Text width metrics/heuristics
by Fang (Pilgrim) on Jun 09, 2005 at 08:54 UTC | |
|
Re: Text width metrics/heuristics
by muntfish (Chaplain) on Jun 09, 2005 at 08:54 UTC | |
|
Re: Text width metrics/heuristics
by ww (Archbishop) on Jun 09, 2005 at 14:49 UTC |