label wrap and centering

Steve Lime Steve.Lime at DNR.STATE.MN.US
Thu Nov 29 23:15:57 EST 2007


Alignment would be a great addition. I had it working ok years ago when MapServer had
native freetype support, but pulled it when GD added it. A small price to pay. I think I'd just
go with 'ALIGN' as we might be able to reuse the keyword elsewhere, although perhaps being
explicit is better. Are you talking about AGG only or would this apply to GD as well?

On the wrapping, I wonder if this is limited to just wrapping. For example, we could define a
new parameter called MAXLENGTH and behave a couple of ways:

1) if WRAP is set to a character or string do as you propose
2) if WRAP is set to AUTO (this would be new) then we automatically add a newline every
MAXLENGTH characters. Might be able to do some funky labeling with that, for instance a
string of 123 with MAXLENGTH 1 would be rendered as:

1
2
3

just an idea, but this would allow splitting not possible with WRAP

3) if no WRAP is set and MAXLENGTH is set (default would be -1?) then we would skip
that label. The only way to do that now is using a length([item]) expression and this would be
faster.

4) if MAXLENGTH isn't set then we behave just as we do now

Steve

>>> thomas bonfort <thomas.bonfort at GMAIL.COM> 11/29/07 9:15 AM >>>
hi all.

I've opened this bug a few weeks ago
http://trac.osgeo.org/mapserver/ticket/2383 and implementing it shouldn't be
too difficult. It sure isn't a perfect solution but imho still much better
that the current way of treating the label WRAP parameter, by ensuring that
no wrapping occurs until the current line length has reached a specified
length. It would avoid breaking after short words, i.e.

"This is a long label" with wrap=' '

could be rendered by

"This is a
long label"


instead of
"This
is
a
long
label"

of course labels with very long words following short ones would be somewhat
messed up
for example "this is a verlylongwordinthelabel" would not be wrapped at all
if minwraplength was set longer than "this is a"

complementary or not to this, I've also tried out some rather naive text
centering for multiline labels, that works by padding each line with a
number of 'space' characters. As you might expect, the results are much
better with monospace fonts, but aren't /too/ horrible when using non
monospaced font AND all the lines are roughly the same length. The same
approach could also be used for aligning text to the right, although in that
case a monospace font would be mandatory.
 Doing *real* centering would be really much harder, and would have to be
done seperately for each renderer as the exact line lengths need to be
known, and the starting offsets adjusted accordingly.

each of these two additions would require an additional keyword, for example
"MINWRAPLENGTH" for the first, and maybe "TEXTALIGN" (LEFT|CENTER|RIGHT) for
the second.

thoughts / ideas / comments welcome !

cheers,
thomas



More information about the mapserver-dev mailing list