label wrap and centering

Stephen Woodbridge woodbri at SWOODBRIDGE.COM
Fri Nov 30 00:06:11 EST 2007


Steve, Thomas,

I really like this idea.

Steve are you say the if MAXLENGTH is set AND WRAP is set, then we would 
fill lines up to MAXLENGTH and then look back for a WRAP char is we need to.

MAXLENGTH 4
WRAP ' '
TEXT "a b cdefg aa bb"

would wrap as:

a b
cdefg
aa
bb

I think you have to keep long words together even if the are greater the 
MAXLENGTH. Or we could set MAXLENGTH -4 to imply hard wrapping which 
would split words like:

a b
cdef
g aa
bb

We could also add a HYTHEN true|false to get something like:

a b
cde-
fg
aa
bb

Some more food for thought.

I also think that it would be good to add ALIGN support for this. It 
might make sense to require each renderer to support a function that 
passes a string and whatever info is needed, and returns the rendered 
string length or an approximation of it. This way it could be added to 
vtable and alignment calculation could be done outside the renderer.

-Steve W

Steve Lime wrote:
> 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