Skip to content
Permalink
Browse files

No need of msWrapText according to issue #5609

After going through the code and following the issue #5609 I found that the function msWrapText is not used anywhere, so please let me know if it is correct!
  • Loading branch information...
SunveerSingh committed Oct 29, 2018
1 parent 2b9d022 commit 9c5cf7eb7baedb57673bdb2b6cf31f6adfaa9608
Showing with 1 addition and 84 deletions.
  1. +1 −84 maplabel.c
@@ -54,90 +54,7 @@
* for a summary of how wrap/maxlength interact on the result
* of the text transformation
*/
char *msWrapText(char *text, char wrap, int maxlength)
{
if(!text) /*not an error if no text*/
return text;
if(maxlength == 0) {
if(wrap!='\0') {
/* if maxlength = 0 *and* a wrap character was specified,
* replace all wrap characters by \n
* this is the traditional meaning of the wrap character
*/
msReplaceChar(text, wrap, '\n');
}
/* if neither maxlength, nor wrap were specified,
* don't transform this text */
return text;
} else if(maxlength>0) {
if(wrap!='\0') {
/* split input text at the wrap character, only if
* the current line length is over maxlength */

/* TODO: check if the wrap character is a valid byte
* inside a multibyte utf8 glyph. if so, the msCountChars
* will return an erroneous value */
int numwrapchars = msCountChars(text,wrap);

if(numwrapchars > 0) {
int num_cur_glyph_on_line = 0; /*count for the number of glyphs
on the current line*/
char *textptr = text;
char glyph[11]; /*storage for unicode fetching function*/
int glyphlen = 0; /*size of current glyph in bytes*/
while((glyphlen = msGetNextGlyph((const char**)&textptr,glyph))>0) {
num_cur_glyph_on_line++;
if(*glyph == wrap && num_cur_glyph_on_line>=(maxlength)) {
/*FIXME (if wrap becomes something other than char):*/
*(textptr-1)='\n'; /*replace wrap char with a \n*/
num_cur_glyph_on_line=0; /*reset count*/
}
}
return text;
} else {
/*there are no characters available for wrapping*/
return text;
}
} else {
/* if no wrap character was specified, but a maxlength was,
* don't draw this label if it is longer than the specified maxlength*/
if(msGetNumGlyphs(text)>maxlength) {
free(text);
return NULL;
} else {
return text;
}
}
} else {
/* negative maxlength: we split lines unconditionally, i.e. without
loooking for a wrap character*/
int numglyphs,numlines;
maxlength = -maxlength; /* use a positive value*/
numglyphs = msGetNumGlyphs(text);
numlines = (numglyphs-1) / maxlength + 1; /*count total number of lines needed
after splitting*/
if(numlines>1) {
char *newtext = msSmallMalloc(strlen(text)+numlines+1);
char *newtextptr = newtext;
char *textptr = text;
int glyphlen = 0, num_cur_glyph = 0;
while((glyphlen = msGetNextGlyph((const char**)&textptr,newtextptr))>0) {
num_cur_glyph++;
newtextptr += glyphlen;
if(num_cur_glyph%maxlength == 0 && num_cur_glyph != numglyphs) {
/*we're at a split location, insert a newline*/
*newtextptr = '\n';
newtextptr++;
}
}
free(text);
return newtext;
} else {
/*no splitting needed, return the original*/
return text;
}
}
}


void initTextPath(textPathObj *ts) {
memset(ts,0,sizeof(*ts));

0 comments on commit 9c5cf7e

Please sign in to comment.
You can’t perform that action at this time.