Permalink
Browse files

Merge pull request #5691 from SunveerSingh/patch-1

No need of msWrapText according to issue #5609
  • Loading branch information...
geographika committed Nov 8, 2018
2 parents bfe4a5b + 65a479c commit c95cf16bd3cd93eccf822c4f011b34dc8703ad1d
Showing with 2 additions and 99 deletions.
  1. +2 −99 maplabel.c
View
@@ -39,105 +39,8 @@
/**
* replace wrap characters with \n , respecting maximal line length.
*
* returns a pointer to the newly allocated text. memory is controlled
* inside this function, so the caller MUST use the pointer returned by
* the function:
* text = msWrapText(label,text);
*
* TODO/FIXME: function will produce erroneous/crashing? results
* if the wrap character is encoded with multiple bytes
*
* see http://mapserver.org/development/rfc/ms-rfc-40.html
* 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 c95cf16

Please sign in to comment.