Skip to content

Commit

Permalink
Fix handling of empty labels when not using labelcache (#5142)
Browse files Browse the repository at this point in the history
  • Loading branch information
tbonfort committed Feb 24, 2016
1 parent 9523495 commit 6102a7a
Showing 1 changed file with 41 additions and 28 deletions.
69 changes: 41 additions & 28 deletions mapdraw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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;
}
Expand Down

0 comments on commit 6102a7a

Please sign in to comment.