Permalink
Browse files

Fix label wrap (#5612) and wrap at ZERO WIDTH SPACE (#5613)

  • Loading branch information...
olt committed Jul 31, 2018
1 parent a53a72d commit 0ebd2b60453fa78068e1a8b2aedfb99a5b1b8918
Showing with 111 additions and 20 deletions.
  1. +102 −0 msautotest/renderers/labels-wrap.map
  2. +9 −20 textlayout.c
@@ -0,0 +1,102 @@
# RUN_PARMS: labels-wrap.png [SHP2IMG] -m [MAPFILE] -i png -o [RESULT]
map
imagetype png
size 200 450
extent 0 -450 200 0
debug 0
config "MS_ERRORFILE" "stderr"
fontset "data/fonts.lst"
layer
type line
status default
name "lines"
class
style
color 230 230 230
width 1
end
label
type truetype
angle follow
font "dejavu"
size 8
color 0 0 0
wrap "-"
maxlength 8
end
end
feature
points
50 -50 150 -50
end
text "W: WrapDash-With-Dash" # should wrap, dashes should not be removed
end
feature
points
50 -100 150 -100
end
text "NW: WrapDash With Space" # should not wrap
end
end
layer
type line
status default
name "lines"
class
style
color 230 230 230
width 1
end
label
type truetype
angle follow
font "dejavu"
size 8
color 0 0 0
maxlength 8
wrap " "
end
end
feature
points
50 -200 150 -200
end
text "W: WrapSpace With Space" # should wrap
end
feature
points
50 -250 150 -250
end
text "NW: WrapSpace-With-Dash" # should wrap, no dash removed
end
feature
points
50 -300 150 -300
end
text "W: WrapSpace​With​OnlyZeroSP" # should wrap, no space between words
end
feature
points
50 -350 150 -350
end
text "W: WrapSpace ​With ​ZeroSP ​and ​Space" # should wrap
end
feature
points
50 -400 150 -400
end
text "W: WrapSpace-​With-​Dash-​and-​ZeroSP" # should wrap, no dash removed
end
end
end
@@ -521,7 +521,6 @@ int msLayoutTextSymbol(mapObj *map, textSymbolObj *ts, textPathObj *tgret) {
}
}
if(ts->label->wrap || ts->label->maxlength > 0) {
if(ts->label->wrap && ts->label->maxlength == 0) {
for(i=0;i<num_glyphs;i++) {
@@ -531,27 +530,17 @@ int msLayoutTextSymbol(mapObj *map, textSymbolObj *ts, textPathObj *tgret) {
}
} else {
assert(ts->label->maxlength > 0);
if(ts->label->wrap != ' '){
for(i=0;i<num_glyphs;i++) {
/* replace all occurences of the wrap character with a space */
if(glyphs.unicodes[i]== ts->label->wrap)
glyphs.unicodes[i]= ' ';
}
}
if(num_glyphs > ts->label->maxlength) {
int num_cur_glyph_on_line = 0; /*count for the number of glyphs on the current line*/
for(i=0; i<num_glyphs; i++) {
if(glyphs.unicodes[i]== ' ')
break;
}
if(i != num_glyphs) { /* we have at least one space on which we can break */
int num_cur_glyph_on_line = 0; /*count for the number of glyphs on the current line*/
for(i=0; i<num_glyphs; i++) {
if(glyphs.unicodes[i]== ' ' && num_cur_glyph_on_line >= ts->label->maxlength) {
glyphs.unicodes[i]= '\n';
num_cur_glyph_on_line = 0;
} else {
num_cur_glyph_on_line++;
}
/* wrap at wrap character or at ZERO WIDTH SPACE (unicode 0x200b), if
* current line is too long */
if((glyphs.unicodes[i] == ts->label->wrap || glyphs.unicodes[i] == 0x200b)
&& num_cur_glyph_on_line >= ts->label->maxlength) {
glyphs.unicodes[i]= '\n';
num_cur_glyph_on_line = 0;
} else {
num_cur_glyph_on_line++;
}
}
}

0 comments on commit 0ebd2b6

Please sign in to comment.