From cea85203de93e533e7edf301e5e3b19869bfabe5 Mon Sep 17 00:00:00 2001 From: Thomas Bonfort Date: Sat, 5 Oct 2013 13:21:39 +0200 Subject: [PATCH] fix rendering of legendicons with 0-length name (#4782) --- maplegend.c | 64 +++++++++++++++++++++++++++++++---------------------- msautotest | 2 +- 2 files changed, 39 insertions(+), 27 deletions(-) diff --git a/maplegend.c b/maplegend.c index 171b468671..a58e260bf7 100644 --- a/maplegend.c +++ b/maplegend.c @@ -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); diff --git a/msautotest b/msautotest index b029514e95..a6a03ad6e0 160000 --- a/msautotest +++ b/msautotest @@ -1 +1 @@ -Subproject commit b029514e95119eb9aaa152cdb149c990809eec49 +Subproject commit a6a03ad6e085542782813082cc03d362f9a58a73