Date: | 2007/12/03 |
---|---|
Author: | Thomas Bonfort |
Contact: | thomas.bonfort at gmail.com |
Last Edited: | 2007/12/03 |
Status: | Implemented |
Version: | MapServer 5.4 |
Id: | $Id: ms-rfc-40.txt 8278 2008-12-23 21:34:31Z hobu $ |
MapServer 5.0 supports “hard” text wrapping, where the wrap character is unconditionally treated as a newline. This RFC proposes the addition of:
These two additions are independent from one another, i.e. can be activated together or not.
A new keyword, MAXLENGTH is added to the label object, and interacts with the label WRAP parameter as follows:
The WRAP / MAXLENGTH combinations are summarized here:
maxlen =0 | maxlen > 0 | maxlen < 0 | |
---|---|---|---|
wrap = ‘char’ | current way | conditional wrap if > maxlen | hard wrap |
no wrap | no processing | skip label if > maxlen | hard wrap |
A new keyword ALIGN is added to the label object. It supports 3 values: left, center and right, and controls how text lines should be aligned w.r.t. the label bounding box. Precise placement of text can only be done at the renderer level, by exactly defining the starting pixel of the current line. While this approach could be taken, it would considerably burden the renderer code.
I propose to use a more generic though less precise way of doing, by padding the text lines with space characters to approximate indentation. The initial implementation could only rely on the number of characters in each text line:
- loop through text lines to find the line with the most characters l_max
- pad all the other lines with (l_max - l_cur)/2 space characters
A more advanced implementation will be to use the exact line lengths as returned by the renderers with the msGetLabelSize function:
- compute the size in pixels of the ” ” string (two spaces, accounts for kerning): l_2space
- loop through text lines to longest line of length pix_l_max
- pad all the other lines with (pix_l_max - pix_l_cur)/2 * 1/(2*l_2space) space characters
‘’‘Limitations’‘’: aligning text to the right will produce ugly results using this method, unless using a monospace font.
The labelObj will have new maxlength property of type integer and align property (ms_align_*).
map.h
mapfile.c
maplabel.c
maplexer.l
maplexer.c
None.