Permalink
Browse files

fix rendering of legendicons with 0-length name (#4782)

  • Loading branch information...
tbonfort committed Oct 5, 2013
1 parent 8250fdf commit cea85203de93e533e7edf301e5e3b19869bfabe5
Showing with 39 additions and 27 deletions.
  1. +38 −26 maplegend.c
  2. +1 −1 msautotest
@@ -491,7 +491,7 @@ int msLegendCalcSize(mapObj *map, int scale_independent, int *size_x, int *size_
for(j=lp->numclasses-1; j>=0; j--) {
textSymbolObj ts;
text = lp->class[j]->title?lp->class[j]->title:lp->class[j]->name; /* point to the right legend text, title takes precedence */
if(!text || !*text) continue; /* skip it */
if(!text) continue; /* skip it */
/* skip the class if the classgroup is defined */
if(lp->classgroup && (lp->class[j]->group == NULL || strcasecmp(lp->class[j]->group, lp->classgroup) != 0))
@@ -504,16 +504,20 @@ int msLegendCalcSize(mapObj *map, int scale_independent, int *size_x, int *size_
}
if(hittest && hittest->layerhits[layerindex].classhits[j].status == 0) continue;
initTextSymbol(&ts);
msPopulateTextSymbolForLabelAndString(&ts,&map->legend.label,msStrdup(text),lp->scalefactor*resolutionfactor,resolutionfactor, 0);
if(UNLIKELY(MS_FAILURE == msGetTextSymbolSize(map,&ts,&rect))) {
if(*text) {
initTextSymbol(&ts);
msPopulateTextSymbolForLabelAndString(&ts,&map->legend.label,msStrdup(text),lp->scalefactor*resolutionfactor,resolutionfactor, 0);
if(UNLIKELY(MS_FAILURE == msGetTextSymbolSize(map,&ts,&rect))) {
freeTextSymbol(&ts);
return MS_FAILURE;
}
freeTextSymbol(&ts);
return MS_FAILURE;
}
freeTextSymbol(&ts);
maxwidth = MS_MAX(maxwidth, MS_NINT(rect.maxx - rect.minx));
*size_y += MS_MAX(MS_NINT(rect.maxy - rect.miny), map->legend.keysizey);
maxwidth = MS_MAX(maxwidth, MS_NINT(rect.maxx - rect.minx));
*size_y += MS_MAX(MS_NINT(rect.maxy - rect.miny), map->legend.keysizey);
} else {
*size_y += map->legend.keysizey;
}
nLegendItems++;
}
}
@@ -599,7 +603,7 @@ imageObj *msDrawLegend(mapObj *map, int scale_independent, map_hittest *hittest)
for(j=lp->numclasses-1; j>=0; j--) {
text = lp->class[j]->title?lp->class[j]->title:lp->class[j]->name; /* point to the right legend text, title takes precedence */
if(!text || !*text) continue; /* skip it */
if(!text) continue; /* skip it */
/* skip the class if the classgroup is defined */
if(lp->classgroup && (lp->class[j]->group == NULL || strcasecmp(lp->class[j]->group, lp->classgroup) != 0))
@@ -616,20 +620,24 @@ imageObj *msDrawLegend(mapObj *map, int scale_independent, map_hittest *hittest)
cur = (legendlabel*) msSmallMalloc(sizeof(legendlabel));
initTextSymbol(&cur->ts);
msPopulateTextSymbolForLabelAndString(&cur->ts,&map->legend.label,msStrdup(text),lp->scalefactor*map->resolution/map->defresolution,map->resolution/map->defresolution, 0);
if(UNLIKELY(MS_FAILURE == msComputeTextPath(map,&cur->ts))) {
ret = MS_FAILURE;
goto cleanup;
}
if(UNLIKELY(MS_FAILURE == msGetTextSymbolSize(map,&cur->ts,&rect))) {
ret = MS_FAILURE;
goto cleanup;
if(*text) {
msPopulateTextSymbolForLabelAndString(&cur->ts,&map->legend.label,msStrdup(text),lp->scalefactor*map->resolution/map->defresolution,map->resolution/map->defresolution, 0);
if(UNLIKELY(MS_FAILURE == msComputeTextPath(map,&cur->ts))) {
ret = MS_FAILURE;
goto cleanup;
}
if(UNLIKELY(MS_FAILURE == msGetTextSymbolSize(map,&cur->ts,&rect))) {
ret = MS_FAILURE;
goto cleanup;
}
cur->height = MS_MAX(MS_NINT(rect.maxy - rect.miny), map->legend.keysizey);
} else {
cur->height = map->legend.keysizey;
}
cur->classindex = j;
cur->layerindex = i;
cur->pred = head;
cur->height = MS_MAX(MS_NINT(rect.maxy - rect.miny), map->legend.keysizey);
head = cur;
}
}
@@ -668,16 +676,20 @@ imageObj *msDrawLegend(mapObj *map, int scale_independent, map_hittest *hittest)
if(msDrawLegendIcon(map, map->layers[cur->layerindex], map->layers[cur->layerindex]->class[cur->classindex], map->legend.keysizex, map->legend.keysizey, image, HMARGIN, (int) pnt.y, scale_independent, ch) != MS_SUCCESS)
return NULL;
pnt.y += cur->height - cur->ts.textpath->bounds.bbox.maxy;
ret = msDrawTextSymbol(map,image,pnt,&cur->ts);
if(UNLIKELY(ret == MS_FAILURE))
goto cleanup;
pnt.y += cur->height;
if(cur->ts.annotext) {
pnt.y -= cur->ts.textpath->bounds.bbox.maxy;
ret = msDrawTextSymbol(map,image,pnt,&cur->ts);
if(UNLIKELY(ret == MS_FAILURE))
goto cleanup;
pnt.y += cur->ts.textpath->bounds.bbox.maxy;
freeTextSymbol(&cur->ts);
}
pnt.y += map->legend.keyspacingy + cur->ts.textpath->bounds.bbox.maxy; /* bump y for next label */
pnt.y += map->legend.keyspacingy; /* bump y for next label */
/* clean up */
freeTextSymbol(&cur->ts);
head = cur;
cur = cur->pred;
free(head);
Submodule msautotest updated from b02951 to a6a03a

0 comments on commit cea8520

Please sign in to comment.