[mapserver-commits] r13004 - sandbox/sdlime/rfc-77

svn at osgeo.org svn at osgeo.org
Sat Jan 21 15:00:29 EST 2012


Author: sdlime
Date: 2012-01-21 12:00:28 -0800 (Sat, 21 Jan 2012)
New Revision: 13004

Modified:
   sandbox/sdlime/rfc-77/mapdraw.c
   sandbox/sdlime/rfc-77/mapfile.c
Log:
Added status, expression and text attributes to label objects.make

Modified: sandbox/sdlime/rfc-77/mapdraw.c
===================================================================
--- sandbox/sdlime/rfc-77/mapdraw.c	2012-01-19 16:11:01 UTC (rev 13003)
+++ sandbox/sdlime/rfc-77/mapdraw.c	2012-01-21 20:00:28 UTC (rev 13004)
@@ -2351,7 +2351,8 @@
             msDrawTextLine(image, cachePtr->text, labelPtr, cachePtr->labelpath, &(map->fontset), layerPtr->scalefactor); /* Draw the curved label */
 
           } else { /* point-based label */
-            int drawLabelText=MS_TRUE; // not used yet
+            int labelStatus; /* per label status tracking */
+            int drawLabelText=MS_TRUE; // unused
             shapeObj *poly=NULL; /* hold label polygon for one label, cachePtr->poly holds label polygon for the whole group */
 
             poly = (shapeObj *) msSmallMalloc(sizeof(shapeObj));
@@ -2373,7 +2374,7 @@
               marker_rect.maxx = marker_rect.minx + (marker_width-1);
               marker_rect.maxy = marker_rect.miny + (marker_height-1); 
               msRectToPolygon(marker_rect, cachePtr->poly);
-            } else if (layerPtr->type == MS_LAYER_POINT) { /* there is a marker already in the image */
+            } else if (layerPtr->type == MS_LAYER_POINT) { /* there is a marker already in the image that we need to account for */
               marker_rect = markerPtr->poly->bounds;
               marker_width = marker_rect.maxx - marker_rect.minx;
               marker_height = marker_rect.maxy - marker_rect.miny;
@@ -2384,14 +2385,18 @@
 
             fprintf(stderr, "      got marker size (%d,%d)\n", marker_width, marker_height);
 
-            /* all other cases *could* have multiple labels defined */
-            for(ll=(cachePtr->numlabels-1); ll>=0; ll--) {
+            /* 
+	    ** all other cases *could* have multiple labels defined 
+            */
+            cachePtr->status = MS_FALSE; /* assume this cache element *can't* be placed */
+
+            for(ll=0; ll<cachePtr->numlabels; ll++) {
               labelPtr = &(cachePtr->labels[ll]);
 
-              // start missing section...
-              if(!labelPtr->annotext || strlen(labelPtr->annotext) == 0) 
-                continue; /* skip this label (RFC 77 TODO: ok to bail here?) */
+              if(labelPtr->status != MS_ON) continue; /* skip this label */
+              if(!labelPtr->annotext || strlen(labelPtr->annotext) == 0) continue; /* skip this label (RFC 77 TODO: ok to bail here?) */
 
+              /* compute label size */
               if(labelPtr->type == MS_TRUETYPE) {
                 size = labelPtr->size * layerPtr->scalefactor;
                 size = MS_MAX(size, labelPtr->minsize*image->resolutionfactor);
@@ -2420,6 +2425,7 @@
                 }
               }
    
+              /* apply offset and buffer settings */
               label_offset_x = labelPtr->offsetx*scalefactor;
               label_offset_y = labelPtr->offsety*scalefactor;
               label_buffer = MS_NINT(labelPtr->buffer*image->resolutionfactor);
@@ -2427,14 +2433,13 @@
 
               if(labelPtr->autominfeaturesize && (cachePtr->featuresize != -1) && ((r.maxx-r.minx) > cachePtr->featuresize))
                 continue; /* label too large relative to the feature */
-              // end missing section
 
               fprintf(stderr, "      got label size\n");
 
+              /* compute settings for label-based styles */
               label_marker_offset_x = label_marker_offset_y = 0; /* assume no label marker */
               label_marker_width = label_marker_height = 0;
               if(labelPtr->numstyles > 0) { 
-
                 for(i=0; i<labelPtr->numstyles; i++) { 
                   /* TODO: at the moment only checks the bottom (first) label style, perhaps should check all of them */ 
                   if(labelPtr->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOINT) { 
@@ -2474,15 +2479,14 @@
                 }
    
                 for(i=0; i<npositions; i++) {
-                  msFreeShape(poly);
-                  cachePtr->status = MS_TRUE; /* assume label *can* be drawn */
+                  msFreeShape(poly);                  
    
                   labelPtr->annopoint = get_metrics(&(cachePtr->point), positions[i], r, (marker_offset_x + label_offset_x), (marker_offset_y + label_offset_y), labelPtr->angle, label_buffer, poly);
                   // if(label_marker_width > 0 && label_marker_height > 0)
                   //   msRectToPolygon(label_marker_rect, poly); /* save marker bounding polygon (TODO: could do conversion once) */
 
                   /* first, compare poly against cachePtr->poly (group poly) if not the first label in the group */
-                  if((ll < cachePtr->numlabels-1) && intersectLabelPolygons(poly, cachePtr->poly) == MS_TRUE) continue; /* next position */
+                  if((ll != 0) && intersectLabelPolygons(poly, cachePtr->poly) == MS_TRUE) continue; /* next position */
 
                   /* second, add poly to cachePtr->poly */
                   msCopyShape(poly, cachePtr->poly);
@@ -2497,16 +2501,14 @@
                     break; /* ...out of position loop */
                   }
                 } /* next position */
-   
-                if(labelPtr->force) {
-                  /* label polygon wasn't initialized if no non-coliding position was found */
-                  if(!cachePtr->status && drawLabelPoly) 
+
+                if(!cachePtr->status && labelPtr->force) {                 
+                  if(drawLabelPoly) 
                     get_metrics_line(&(cachePtr->point), positions[npositions-1], r, (marker_offset_x + label_offset_x), (marker_offset_y + label_offset_y), labelPtr->angle, 1, labelPoly.line);
                   cachePtr->status = MS_TRUE; /* draw in spite of collisions based on last position, need a *best* position */
                 }
-   
+
               } else { /* explicit position */
-                cachePtr->status = MS_TRUE; /* assume label *can* be drawn */
                 msFreeShape(poly);
 
                 fprintf(stderr, "    explicit position case (ll=%d)\n", ll);
@@ -2523,19 +2525,19 @@
                 //   msRectToPolygon(label_marker_rect, poly); /* save marker bounding polygon, part of overlap tests */
 
                 fprintf(stderr, "    %d, %d\n", ll, cachePtr->numlabels-1);
-                if(ll < cachePtr->numlabels-1 && !labelPtr->force && intersectLabelPolygons(poly, cachePtr->poly) == MS_TRUE) {
-                  fprintf(stderr, "    [IF]\n");
-                  cachePtr->status = MS_FALSE;
-                  break; /* out of labels loop */
+                if(labelPtr->force) {
+                  msCopyShape(poly, cachePtr->poly);
+                  cachePtr->status = MS_TRUE;
                 } else {
-                  fprintf(stderr, "    [ELSE]\n");
+                  if((ll != 0) && intersectLabelPolygons(poly, cachePtr->poly) == MS_TRUE) break; /* collision within the group, done... */
                   msCopyShape(poly, cachePtr->poly);
-
-                  if(!labelPtr->force)
-                    msTestLabelCacheCollisions(&(map->labelcache), labelPtr, image->width, image->height, (map_edge_buffer-label_buffer), cachePtr, priority, l, label_mindistance, (r.maxx-r.minx));  
+                  msTestLabelCacheCollisions(&(map->labelcache), labelPtr, image->width, image->height, (map_edge_buffer-label_buffer), cachePtr, priority, l, label_mindistance, (r.maxx-r.minx));
                 }
-              }
+              } /* end else */
 
+              if(!cachePtr->status)
+                break; /* no point looking at more labels */
+
             } /* next label in the group */
    
             if(!cachePtr->status)
@@ -2548,7 +2550,6 @@
                 msDrawMarkerSymbol(&map->symbolset, image, &(cachePtr->point), &(cachePtr->styles[i]), layerPtr->scalefactor);
             }
 
-            // for(ll=(cachePtr->numlabels-1); ll>=0; ll--) {
             for(ll=0; ll<cachePtr->numlabels; ll++) {
               labelPtr = &(cachePtr->labels[ll]);
 
@@ -2571,7 +2572,7 @@
 
             msFreeShape(poly); /* clean up label polygon */
             msFree(poly);
-          }
+          } /* end else */
 	} /* next label */
       } /* next priority */
 

Modified: sandbox/sdlime/rfc-77/mapfile.c
===================================================================
--- sandbox/sdlime/rfc-77/mapfile.c	2012-01-19 16:11:01 UTC (rev 13003)
+++ sandbox/sdlime/rfc-77/mapfile.c	2012-01-21 20:00:28 UTC (rev 13004)
@@ -1682,7 +1682,7 @@
     msFree(label->bindings[i].item);
 
   freeExpression(&(label->expression));
-  freeExpression(&(label->text));
+  freeExpression(&(label->text)); // NEXT! writeLabel()
 
   /* RFC 77 TODO: free book keeping vars */
   msFree(label->annotext);



More information about the mapserver-commits mailing list