Skip to content

Commit cea8520

Browse files
committed
fix rendering of legendicons with 0-length name (#4782)
1 parent 8250fdf commit cea8520

File tree

2 files changed

+39
-27
lines changed

2 files changed

+39
-27
lines changed

maplegend.c

+38-26
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ int msLegendCalcSize(mapObj *map, int scale_independent, int *size_x, int *size_
491491
for(j=lp->numclasses-1; j>=0; j--) {
492492
textSymbolObj ts;
493493
text = lp->class[j]->title?lp->class[j]->title:lp->class[j]->name; /* point to the right legend text, title takes precedence */
494-
if(!text || !*text) continue; /* skip it */
494+
if(!text) continue; /* skip it */
495495

496496
/* skip the class if the classgroup is defined */
497497
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_
504504
}
505505
if(hittest && hittest->layerhits[layerindex].classhits[j].status == 0) continue;
506506

507-
initTextSymbol(&ts);
508-
msPopulateTextSymbolForLabelAndString(&ts,&map->legend.label,msStrdup(text),lp->scalefactor*resolutionfactor,resolutionfactor, 0);
509-
if(UNLIKELY(MS_FAILURE == msGetTextSymbolSize(map,&ts,&rect))) {
507+
if(*text) {
508+
initTextSymbol(&ts);
509+
msPopulateTextSymbolForLabelAndString(&ts,&map->legend.label,msStrdup(text),lp->scalefactor*resolutionfactor,resolutionfactor, 0);
510+
if(UNLIKELY(MS_FAILURE == msGetTextSymbolSize(map,&ts,&rect))) {
511+
freeTextSymbol(&ts);
512+
return MS_FAILURE;
513+
}
510514
freeTextSymbol(&ts);
511-
return MS_FAILURE;
512-
}
513-
freeTextSymbol(&ts);
514515

515-
maxwidth = MS_MAX(maxwidth, MS_NINT(rect.maxx - rect.minx));
516-
*size_y += MS_MAX(MS_NINT(rect.maxy - rect.miny), map->legend.keysizey);
516+
maxwidth = MS_MAX(maxwidth, MS_NINT(rect.maxx - rect.minx));
517+
*size_y += MS_MAX(MS_NINT(rect.maxy - rect.miny), map->legend.keysizey);
518+
} else {
519+
*size_y += map->legend.keysizey;
520+
}
517521
nLegendItems++;
518522
}
519523
}
@@ -599,7 +603,7 @@ imageObj *msDrawLegend(mapObj *map, int scale_independent, map_hittest *hittest)
599603

600604
for(j=lp->numclasses-1; j>=0; j--) {
601605
text = lp->class[j]->title?lp->class[j]->title:lp->class[j]->name; /* point to the right legend text, title takes precedence */
602-
if(!text || !*text) continue; /* skip it */
606+
if(!text) continue; /* skip it */
603607

604608
/* skip the class if the classgroup is defined */
605609
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)
616620

617621
cur = (legendlabel*) msSmallMalloc(sizeof(legendlabel));
618622
initTextSymbol(&cur->ts);
619-
msPopulateTextSymbolForLabelAndString(&cur->ts,&map->legend.label,msStrdup(text),lp->scalefactor*map->resolution/map->defresolution,map->resolution/map->defresolution, 0);
620-
if(UNLIKELY(MS_FAILURE == msComputeTextPath(map,&cur->ts))) {
621-
ret = MS_FAILURE;
622-
goto cleanup;
623-
}
624-
if(UNLIKELY(MS_FAILURE == msGetTextSymbolSize(map,&cur->ts,&rect))) {
625-
ret = MS_FAILURE;
626-
goto cleanup;
623+
if(*text) {
624+
msPopulateTextSymbolForLabelAndString(&cur->ts,&map->legend.label,msStrdup(text),lp->scalefactor*map->resolution/map->defresolution,map->resolution/map->defresolution, 0);
625+
if(UNLIKELY(MS_FAILURE == msComputeTextPath(map,&cur->ts))) {
626+
ret = MS_FAILURE;
627+
goto cleanup;
628+
}
629+
if(UNLIKELY(MS_FAILURE == msGetTextSymbolSize(map,&cur->ts,&rect))) {
630+
ret = MS_FAILURE;
631+
goto cleanup;
632+
}
633+
cur->height = MS_MAX(MS_NINT(rect.maxy - rect.miny), map->legend.keysizey);
634+
} else {
635+
cur->height = map->legend.keysizey;
627636
}
628637

629638
cur->classindex = j;
630639
cur->layerindex = i;
631640
cur->pred = head;
632-
cur->height = MS_MAX(MS_NINT(rect.maxy - rect.miny), map->legend.keysizey);
633641
head = cur;
634642
}
635643
}
@@ -668,16 +676,20 @@ imageObj *msDrawLegend(mapObj *map, int scale_independent, map_hittest *hittest)
668676
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)
669677
return NULL;
670678

671-
pnt.y += cur->height - cur->ts.textpath->bounds.bbox.maxy;
672-
673-
ret = msDrawTextSymbol(map,image,pnt,&cur->ts);
674-
if(UNLIKELY(ret == MS_FAILURE))
675-
goto cleanup;
679+
pnt.y += cur->height;
680+
681+
if(cur->ts.annotext) {
682+
pnt.y -= cur->ts.textpath->bounds.bbox.maxy;
683+
ret = msDrawTextSymbol(map,image,pnt,&cur->ts);
684+
if(UNLIKELY(ret == MS_FAILURE))
685+
goto cleanup;
686+
pnt.y += cur->ts.textpath->bounds.bbox.maxy;
687+
freeTextSymbol(&cur->ts);
688+
}
676689

677-
pnt.y += map->legend.keyspacingy + cur->ts.textpath->bounds.bbox.maxy; /* bump y for next label */
690+
pnt.y += map->legend.keyspacingy; /* bump y for next label */
678691

679692
/* clean up */
680-
freeTextSymbol(&cur->ts);
681693
head = cur;
682694
cur = cur->pred;
683695
free(head);

msautotest

Submodule msautotest updated from b029514 to a6a03ad

0 commit comments

Comments
 (0)