Skip to content

Commit

Permalink
Merge branch 'b4782-legend-notext'
Browse files Browse the repository at this point in the history
  • Loading branch information
tbonfort committed Oct 5, 2013
2 parents b52908c + cea8520 commit fff503b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 27 deletions.
64 changes: 38 additions & 26 deletions maplegend.c
Expand Up @@ -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))
Expand All @@ -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++;
}
}
Expand Down Expand Up @@ -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))
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion msautotest
Submodule msautotest updated from b02951 to a6a03a

0 comments on commit fff503b

Please sign in to comment.