Skip to content
Permalink
Browse files

Fix handling of empty labels when not using labelcache (#5142)

  • Loading branch information
tbonfort committed Feb 24, 2016
1 parent 9523495 commit 6102a7a1511f610c96047020693ed8de9f18734c
Showing with 41 additions and 28 deletions.
  1. +41 −28 mapdraw.c
@@ -2093,16 +2093,19 @@ int msDrawLabel(mapObj *map, imageObj *image, pointObj labelPnt, char *string, l
textSymbolObj ts;
int needLabelPoly=MS_TRUE;
int needLabelPoint=MS_TRUE;
int haveLabelText=MS_TRUE;


if(!string || !*string) {
return MS_SUCCESS;
}
initTextSymbol(&ts);
msPopulateTextSymbolForLabelAndString(&ts, label, string, scalefactor, image->resolutionfactor, 0);
if(UNLIKELY(MS_FAILURE == msComputeTextPath(map,&ts))) {
freeTextSymbol(&ts);
return MS_FAILURE;

if(!string || !*string)
haveLabelText = MS_FALSE;

if(haveLabelText) {
initTextSymbol(&ts);
msPopulateTextSymbolForLabelAndString(&ts, label, string, scalefactor, image->resolutionfactor, 0);
if(UNLIKELY(MS_FAILURE == msComputeTextPath(map,&ts))) {
freeTextSymbol(&ts);
return MS_FAILURE;
}
}

labelPoly.line = &labelPolyLine; /* setup the label polygon structure */
@@ -2118,12 +2121,14 @@ int msDrawLabel(mapObj *map, imageObj *image, pointObj labelPnt, char *string, l
int i;

for(i=0; i<label->numstyles; i++) {
if(label->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOINT) {
if(label->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOINT
|| label->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_NONE) {
if(UNLIKELY(MS_FAILURE == msDrawMarkerSymbol(map, image, &labelPnt, label->styles[i], scalefactor))) {
freeTextSymbol(&ts);
if(haveLabelText)
freeTextSymbol(&ts);
return MS_FAILURE;
}
} else if(label->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOLY) {
} else if(haveLabelText && label->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOLY) {
if(needLabelPoly) {
p = get_metrics(&labelPnt, label->position, ts.textpath, label->offsetx * ts.scalefactor,
label->offsety * ts.scalefactor, ts.rotation, 1, &lbounds);
@@ -2147,20 +2152,23 @@ int msDrawLabel(mapObj *map, imageObj *image, pointObj labelPnt, char *string, l
}
} else {
msSetError(MS_MISCERR,"Unknown label geomtransform %s", "msDrawLabel()",label->styles[i]->_geomtransform.string);
freeTextSymbol(&ts);
if(haveLabelText)
freeTextSymbol(&ts);
return MS_FAILURE;
}
}
}

if(needLabelPoint)
p = get_metrics(&labelPnt, label->position, ts.textpath, label->offsetx * ts.scalefactor,
label->offsety * ts.scalefactor, ts.rotation, 0, &lbounds);
if(haveLabelText) {
if(needLabelPoint)
p = get_metrics(&labelPnt, label->position, ts.textpath, label->offsetx * ts.scalefactor,
label->offsety * ts.scalefactor, ts.rotation, 0, &lbounds);

/* draw the label text */
if(UNLIKELY(MS_FAILURE == msDrawTextSymbol(map,image,p,&ts))) {
freeTextSymbol(&ts);
return MS_FAILURE;
/* draw the label text */
if(UNLIKELY(MS_FAILURE == msDrawTextSymbol(map,image,p,&ts))) {
freeTextSymbol(&ts);
return MS_FAILURE;
}
}
} else {
labelPnt.x += label->offsetx * ts.scalefactor;
@@ -2170,12 +2178,13 @@ int msDrawLabel(mapObj *map, imageObj *image, pointObj labelPnt, char *string, l
int i;

for(i=0; i<label->numstyles; i++) {
if(label->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOINT) {
if(label->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOINT ||
label->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_NONE) {
if(UNLIKELY(MS_FAILURE == msDrawMarkerSymbol(map, image, &labelPnt, label->styles[i], scalefactor))) {
freeTextSymbol(&ts);
return MS_FAILURE;
}
} else if(label->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOLY) {
} else if(haveLabelText && label->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOLY) {
if(needLabelPoly) {
get_metrics(&labelPnt, label->position, ts.textpath, label->offsetx * ts.scalefactor,
label->offsety * ts.scalefactor, ts.rotation, 1, &lbounds);
@@ -2198,19 +2207,23 @@ int msDrawLabel(mapObj *map, imageObj *image, pointObj labelPnt, char *string, l
}
} else {
msSetError(MS_MISCERR,"Unknown label geomtransform %s", "msDrawLabel()",label->styles[i]->_geomtransform.string);
freeTextSymbol(&ts);
if(haveLabelText)
freeTextSymbol(&ts);
return MS_FAILURE;
}
}
}

/* draw the label text */
if(UNLIKELY(MS_FAILURE == msDrawTextSymbol(map,image,labelPnt,&ts))) {
freeTextSymbol(&ts);
return MS_FAILURE;
if(haveLabelText) {
/* draw the label text */
if(UNLIKELY(MS_FAILURE == msDrawTextSymbol(map,image,labelPnt,&ts))) {
freeTextSymbol(&ts);
return MS_FAILURE;
}
}
}
freeTextSymbol(&ts);
if(haveLabelText)
freeTextSymbol(&ts);

return MS_SUCCESS;
}

0 comments on commit 6102a7a

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