[mapserver-commits] r13237 - trunk/mapserver
svn at osgeo.org
svn at osgeo.org
Tue Mar 13 08:02:51 EDT 2012
Author: tbonfort
Date: 2012-03-13 05:02:51 -0700 (Tue, 13 Mar 2012)
New Revision: 13237
Modified:
trunk/mapserver/mapdraw.c
trunk/mapserver/maplabel.c
trunk/mapserver/mapserver.h
Log:
change msTestLabelCacheCollisions to accept a shapeObj parameter instead of using cachePtr->poly.
bail out earlier on unsupported label combinations
don't add inactive labels to the labelcache with line layers
Modified: trunk/mapserver/mapdraw.c
===================================================================
--- trunk/mapserver/mapdraw.c 2012-03-13 11:59:50 UTC (rev 13236)
+++ trunk/mapserver/mapdraw.c 2012-03-13 12:02:51 UTC (rev 13237)
@@ -1110,8 +1110,12 @@
if (classgroup)
msFree(classgroup);
- if(status != MS_DONE) {
+ if(status != MS_DONE || retcode == MS_FAILURE) {
msLayerClose(layer);
+ if(shpcache) {
+ freeFeatureList(shpcache);
+ shpcache = NULL;
+ }
return MS_FAILURE;
}
@@ -2333,7 +2337,7 @@
cachePtr->leaderbbox->maxy = cachePtr->leaderline->point[0].y;
cachePtr->leaderbbox->miny = cachePtr->point.y;
}
- cachePtr->status = msTestLabelCacheCollisions(map, cachePtr, 0,0,0);
+ cachePtr->status = msTestLabelCacheCollisions(map, cachePtr, cachePtr->poly, cachePtr->labels[0].mindistance,0,0);
if(cachePtr->status) {
int ll;
for(ll=0;ll<cachePtr->numlabels;ll++) {
@@ -2753,15 +2757,12 @@
/* compare against image bounds, rendered labels and markers (sets cachePtr->status), if FORCE=TRUE then skip it */
cachePtr->status = MS_TRUE;
assert(cachePtr->poly == NULL);
- /* use a ref to the bounds as the cache's polygon */
- cachePtr->poly = &cachePtr->labelpath->bounds;
if(!labelPtr->force)
- cachePtr->status = msTestLabelCacheCollisions(map,cachePtr,label_mindistance,priority,l);
+ cachePtr->status = msTestLabelCacheCollisions(map,cachePtr,&cachePtr->labelpath->bounds,label_mindistance,priority,l);
if(!cachePtr->status) {
- cachePtr->poly = NULL;
msFreeShape(&cachePtr->labelpath->bounds);
continue;
} else {
@@ -2783,7 +2784,6 @@
msDrawTextLine(image, labelPtr->annotext, labelPtr, cachePtr->labelpath, &(map->fontset), layerPtr->scalefactor); /* Draw the curved label */
} else { /* point-based label */
- shapeObj *tmppoly;
marker_offset_x = marker_offset_y = 0; /* assume no marker */
@@ -2796,13 +2796,9 @@
marker_offset_x = (marker_poly.bounds.maxx-marker_poly.bounds.minx)/2.0;
marker_offset_y = (marker_poly.bounds.maxy-marker_poly.bounds.miny)/2.0;
/* if this is an annotation layer, transfer the markerPoly */
- tmppoly = cachePtr->poly;
- cachePtr->poly = &marker_poly;
- if( MS_OFF == msTestLabelCacheCollisions(map, cachePtr, 0,priority, l)) {
- cachePtr->poly = tmppoly;
+ if( MS_OFF == msTestLabelCacheCollisions(map, cachePtr, &marker_poly, 0,priority, l)) {
continue; /* the marker collided, no point continuing */
}
- cachePtr->poly = tmppoly;
}
} else if (layerPtr->type == MS_LAYER_POINT && cachePtr->markerid!=-1) { /* there is a marker already in the image that we need to account for */
markerCacheMemberObj *markerPtr = &(cacheslot->markers[cachePtr->markerid]); /* point to the right spot in the marker cache*/
@@ -2847,10 +2843,7 @@
}
/* add marker to cachePtr->poly */
if(labelPtr->force != MS_TRUE) {
- tmppoly = cachePtr->poly;
- cachePtr->poly = &label_marker_poly;
- label_marker_status = msTestLabelCacheCollisions(map, cachePtr, 0,priority, l);
- cachePtr->poly = tmppoly;
+ label_marker_status = msTestLabelCacheCollisions(map, cachePtr,&label_marker_poly, 0,priority, l);
}
if(label_marker_status == MS_OFF &&
!(labelPtr->force || classPtr->leader.maxdistance))
@@ -2956,10 +2949,7 @@
}
}
- tmppoly = cachePtr->poly;
- cachePtr->poly = &metrics_poly;
- labelPtr->status = msTestLabelCacheCollisions(map, cachePtr, label_mindistance,priority, l);
- cachePtr->poly = tmppoly;
+ labelPtr->status = msTestLabelCacheCollisions(map, cachePtr,&metrics_poly, label_mindistance,priority, l);
/* found a suitable place for this label */
if(labelPtr->status == MS_TRUE || (i==(npositions-1) && labelPtr->force == MS_ON)) {
@@ -3006,13 +2996,10 @@
break; /* collision within the group */
}
}
- tmppoly = cachePtr->poly;
- cachePtr->poly = &metrics_poly;
/* TODO: in case we have leader lines and multiple labels, there's no use in testing for labelcache collisions
* once a first collision has been found. we only need to know that the label group has collided, and the
* poly of the whole label group: if(label_group) testLabelCacheCollisions */
- labelPtr->status = msTestLabelCacheCollisions(map, cachePtr, label_mindistance, priority, l);
- cachePtr->poly = tmppoly;
+ labelPtr->status = msTestLabelCacheCollisions(map, cachePtr,&metrics_poly, label_mindistance, priority, l);
}
} else {
labelPtr->status = MS_ON;
Modified: trunk/mapserver/maplabel.c
===================================================================
--- trunk/mapserver/maplabel.c 2012-03-13 11:59:50 UTC (rev 13236)
+++ trunk/mapserver/maplabel.c 2012-03-13 12:02:51 UTC (rev 13237)
@@ -330,7 +330,10 @@
}
}
- assert(layerPtr->type != MS_LAYER_ANNOTATION || numactivelabels == 1);
+ if (layerPtr->type == MS_LAYER_ANNOTATION && (cachePtr->numlabels > 1 || classPtr->leader.maxdistance)) {
+ msSetError(MS_MISCERR, "Multiple Labels and/or LEADERs are not supported with annotation layers", "msAddLabelGroup()");
+ return MS_FAILURE;
+ }
/* check that the label intersects the layer mask */
if(layerPtr->masklayer) {
@@ -354,7 +357,7 @@
return MS_SUCCESS;
}
} else {
- msSetError(MS_MISCERR, "Layer (%s) references references a mask layer, but the selected renderer does not support them", "msAddLabel()", layerPtr->name);
+ msSetError(MS_MISCERR, "Layer (%s) references references a mask layer, but the selected renderer does not support them", "msAddLabelGroup()", layerPtr->name);
return (MS_FAILURE);
}
}
@@ -486,11 +489,21 @@
classObj *classPtr=NULL;
if(!label) return(MS_FAILURE); // RFC 77 TODO: set a proper message
- if(!label->annotext) return(MS_SUCCESS); /* not an error */
+ if(!label->annotext || label->status == MS_OFF) return(MS_SUCCESS); /* not an error */
layerPtr = (GET_LAYER(map, layerindex)); /* set up a few pointers for clarity */
classPtr = GET_LAYER(map, layerindex)->class[classindex];
+ if(classPtr->leader.maxdistance) {
+ if (layerPtr->type == MS_LAYER_ANNOTATION) {
+ msSetError(MS_MISCERR, "LEADERs are not supported on annotation layers", "msAddLabel()");
+ return MS_FAILURE;
+ }
+ if(labelpath) {
+ msSetError(MS_MISCERR, "LEADERs are not supported on ANGLE FOLLOW labels", "msAddLabel()");
+ return MS_FAILURE;
+ }
+ }
/* check that the label intersects the layer mask */
if (layerPtr->masklayer) {
@@ -568,7 +581,8 @@
if ( point ) {
cachePtr->point = *point; /* the actual label point */
cachePtr->labelpath = NULL;
- } else if ( labelpath ) {
+ } else {
+ assert(labelpath);
cachePtr->labelpath = labelpath;
/* Use the middle point of the labelpath for mindistance calculations */
cachePtr->point = labelpath->path.point[labelpath->path.numpoints / 2];
@@ -692,8 +706,8 @@
int current_label, int mindistance, double label_size);
*/
-int msTestLabelCacheCollisions(mapObj *map, labelCacheMemberObj *cachePtr, int mindistance,
- int current_priority, int current_label) {
+int msTestLabelCacheCollisions(mapObj *map, labelCacheMemberObj *cachePtr, shapeObj *poly,
+ int mindistance, int current_priority, int current_label) {
labelCacheObj *labelcache = &(map->labelcache);
int i, p, ll, pp;
double label_width = 0;
@@ -703,7 +717,7 @@
* Check against image bounds first
*/
if(!cachePtr->labels[0].partials) {
- if(labelInImage(map->width, map->height, cachePtr->poly, labelcache->gutter) == MS_FALSE) {
+ if(labelInImage(map->width, map->height, poly, labelcache->gutter) == MS_FALSE) {
return MS_FALSE;
}
}
@@ -725,7 +739,7 @@
for ( ll = 0; ll < markerslot->nummarkers; ll++ ) {
if ( !(p == current_priority && current_label == markerslot->markers[ll].id ) ) { /* labels can overlap their own marker */
- if ( intersectLabelPolygons(markerslot->markers[ll].poly, cachePtr->poly ) == MS_TRUE ) {
+ if ( intersectLabelPolygons(markerslot->markers[ll].poly, poly ) == MS_TRUE ) {
return MS_FALSE;
}
}
@@ -733,7 +747,7 @@
}
if(mindistance > 0)
- label_width = cachePtr->poly->bounds.maxx - cachePtr->poly->bounds.minx;
+ label_width = poly->bounds.maxx - poly->bounds.minx;
for(p=current_priority; p<MS_MAX_LABEL_PRIORITY; p++) {
labelCacheSlotObj *cacheslot;
@@ -762,19 +776,19 @@
return MS_FALSE;
}
- if(intersectLabelPolygons(curCachePtr->poly, cachePtr->poly) == MS_TRUE) { /* polys intersect */
+ if(intersectLabelPolygons(curCachePtr->poly, poly) == MS_TRUE) { /* polys intersect */
return MS_FALSE;
}
if(curCachePtr->leaderline) {
/* our poly against rendered leader lines */
/* first do a bbox check */
- if(msRectOverlap(curCachePtr->leaderbbox, &(cachePtr->poly->bounds))) {
+ if(msRectOverlap(curCachePtr->leaderbbox, &(poly->bounds))) {
/* look for intersecting line segments */
- for(ll=0; ll<cachePtr->poly->numlines; ll++)
- for(pp=1; pp<cachePtr->poly->line[ll].numpoints; pp++)
+ for(ll=0; ll<poly->numlines; ll++)
+ for(pp=1; pp<poly->line[ll].numpoints; pp++)
if(msIntersectSegments(
- &(cachePtr->poly->line[ll].point[pp-1]),
- &(cachePtr->poly->line[ll].point[pp]),
+ &(poly->line[ll].point[pp-1]),
+ &(poly->line[ll].point[pp]),
&(curCachePtr->leaderline->point[0]),
&(curCachePtr->leaderline->point[1])) == MS_TRUE)
{
Modified: trunk/mapserver/mapserver.h
===================================================================
--- trunk/mapserver/mapserver.h 2012-03-13 11:59:50 UTC (rev 13236)
+++ trunk/mapserver/mapserver.h 2012-03-13 12:02:51 UTC (rev 13237)
@@ -2034,7 +2034,7 @@
MS_DLL_EXPORT int msAddLabel(mapObj *map, labelObj *label, int layerindex, int classindex, shapeObj *shape, pointObj *point, labelPathObj *labelpath, double featuresize);
MS_DLL_EXPORT int msAddLabelGroup(mapObj *map, int layerindex, int classindex, shapeObj *shape, pointObj *point, double featuresize);
-MS_DLL_EXPORT int msTestLabelCacheCollisions(mapObj *map, labelCacheMemberObj *cachePtr, int mindistance, int current_priority, int current_label);
+MS_DLL_EXPORT int msTestLabelCacheCollisions(mapObj *map, labelCacheMemberObj *cachePtr, shapeObj *poly, int mindistance, int current_priority, int current_label);
MS_DLL_EXPORT labelCacheMemberObj *msGetLabelCacheMember(labelCacheObj *labelcache, int i);
MS_DLL_EXPORT gdFontPtr msGetBitmapFont(int size);
More information about the mapserver-commits
mailing list