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

svn at osgeo.org svn at osgeo.org
Sun Jan 22 23:43:40 EST 2012


Author: sdlime
Date: 2012-01-22 20:43:40 -0800 (Sun, 22 Jan 2012)
New Revision: 13009

Modified:
   sandbox/sdlime/rfc-77/mapdraw.c
   sandbox/sdlime/rfc-77/mapfile.c
Log:
Got MS_GEOMTRANSFORM_LABELPOLY support in place...

Modified: sandbox/sdlime/rfc-77/mapdraw.c
===================================================================
--- sandbox/sdlime/rfc-77/mapdraw.c	2012-01-22 04:11:56 UTC (rev 13008)
+++ sandbox/sdlime/rfc-77/mapdraw.c	2012-01-23 04:43:40 UTC (rev 13009)
@@ -2148,8 +2148,6 @@
   if(!string) return MS_SUCCESS; /* not an error, just don't need to do anything more */
   if(strlen(string) == 0) return MS_SUCCESS; /* not an error, just don't need to do anything more */
 
-  
-
   if(label->type == MS_TRUETYPE) {
     size = label->size * scalefactor;
     size = MS_MAX(size, label->minsize*image->resolutionfactor);
@@ -2243,11 +2241,6 @@
       int i, l, ll, priority;
       rectObj r;
 
-      shapeObj labelPoly; /* label polygon (bounding box, possibly rotated) */
-      lineObj labelPolyLine;
-      pointObj labelPolyPoints[5];
-      int drawLabelPoly=MS_FALSE;
-
       markerCacheMemberObj *markerPtr=NULL; /* for santity */
       labelCacheMemberObj *cachePtr=NULL;      
       layerObj *layerPtr=NULL;
@@ -2270,11 +2263,6 @@
 
       fprintf(stderr, "in msDrawLabelCache()...\n");
 
-      labelPoly.line = &labelPolyLine; /* setup the label polygon structure */
-      labelPoly.numlines = 1;
-      labelPoly.line->point = labelPolyPoints;
-      labelPoly.line->numpoints = 5;
-
       /* Look for labelcache_map_edge_buffer map metadata
        * If set then the value defines a buffer (in pixels) along the edge of the
        * map image where labels can't fall
@@ -2437,14 +2425,27 @@
               /* 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) { 
+              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) { 
                     if(msGetMarkerSize(&map->symbolset, labelPtr->styles[i], &label_marker_width, &label_marker_height, layerPtr->scalefactor) != MS_SUCCESS) 
                       return MS_FAILURE;
-                     break; 
-                  } 
+                    break; 
+                  }
+		}
+                
+                for(i=0; i<labelPtr->numstyles; i++) { 
+                  if(labelPtr->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOLY) {
+                    /* initialize the annotation polygon */
+                    labelPtr->annopoly = (shapeObj *) msSmallMalloc(sizeof(shapeObj));
+                    msInitShape(labelPtr->annopoly);
+                    labelPtr->annopoly->line = (lineObj *) malloc(sizeof(lineObj));
+                    labelPtr->annopoly->numlines = 1;
+                    labelPtr->annopoly->line->point =  (pointObj *) malloc(5*sizeof(pointObj));
+                    labelPtr->annopoly->line->numpoints = 5;
+                    break;
+		  }
                 }
 
                 label_marker_offset_x = MS_NINT(label_marker_width/2.0); 
@@ -2481,7 +2482,7 @@
                 if(label_marker_width > 0 && label_marker_height > 0)
                   msRectToPolygon(label_marker_rect, poly); /* save marker bounding polygon */
 
-                for(i=0; i<npositions; i++) { 
+                for(i=0; i<npositions; i++) {
   		  fprintf(stderr, "%d ", i);
                   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);
 
@@ -2497,8 +2498,7 @@
 
                   /* found a suitable place for this label */
                   if(cachePtr->status) {
-                    if(drawLabelPoly)
-                      get_metrics_line(&(cachePtr->point), positions[i], r, (marker_offset_x + label_offset_x), (marker_offset_y + label_offset_y), labelPtr->angle, 1, labelPoly.line);
+                    if(labelPtr->annopoly) get_metrics_line(&(cachePtr->point), positions[i], r, (marker_offset_x + label_offset_x), (marker_offset_y + label_offset_y), labelPtr->angle, 1, labelPtr->annopoly->line);
                     break; /* ...out of position loop */
                   } else { 
                     /* reset some things */ 
@@ -2513,8 +2513,7 @@
                 fprintf(stderr, "end (%d)\n", cachePtr->status);
 
                 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);
+                  if(labelPtr->annopoly) get_metrics_line(&(cachePtr->point), positions[npositions-1], r, (marker_offset_x + label_offset_x), (marker_offset_y + label_offset_y), labelPtr->angle, 1, labelPtr->annopoly->line);
                   cachePtr->status = MS_TRUE; /* draw in spite of collisions based on last position, need a *best* position */
                 }
 
@@ -2525,14 +2524,14 @@
 
                 if(labelPtr->position == MS_CC) { /* don't need the marker_offset */
                   labelPtr->annopoint = get_metrics(&(cachePtr->point), labelPtr->position, r, label_offset_x, label_offset_y, labelPtr->angle, label_buffer, poly);
-                  if(drawLabelPoly) get_metrics_line(&(cachePtr->point), labelPtr->position, r, label_offset_x, label_offset_y, labelPtr->angle, 1, labelPoly.line);
+                  if(labelPtr->annopoly) get_metrics_line(&(cachePtr->point), labelPtr->position, r, label_offset_x, label_offset_y, labelPtr->angle, 1, labelPtr->annopoly->line);
                 } else {
                   labelPtr->annopoint = get_metrics(&(cachePtr->point), labelPtr->position, r, (marker_offset_x + label_offset_x), (marker_offset_y + label_offset_y), labelPtr->angle, label_buffer, poly);
-                  if(drawLabelPoly) get_metrics_line(&(cachePtr->point), labelPtr->position, r, (marker_offset_x + label_offset_x), (marker_offset_y + label_offset_y), labelPtr->angle, 1, labelPoly.line);
+                  if(labelPtr->annopoly) get_metrics_line(&(cachePtr->point), labelPtr->position, r, (marker_offset_x + label_offset_x), (marker_offset_y + label_offset_y), labelPtr->angle, 1, labelPtr->annopoly->line);
                 }
 
-                // if(label_marker_width > 0 && label_marker_height > 0)
-                //   msRectToPolygon(label_marker_rect, poly); /* save marker bounding polygon, part of overlap tests */
+                if(label_marker_width > 0 && label_marker_height > 0)
+                  msRectToPolygon(label_marker_rect, poly); /* save marker bounding polygon, part of overlap tests */
 
                 fprintf(stderr, "    before: %d, %d, %d\n", ll, cachePtr->numlabels-1, cachePtr->status);
                 if(labelPtr->force == MS_TRUE) {
@@ -2572,7 +2571,7 @@
                   if(labelPtr->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOINT)
                     msDrawMarkerSymbol(&map->symbolset, image, &(cachePtr->point), labelPtr->styles[i], layerPtr->scalefactor);
                   else if(labelPtr->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOLY) {
-                    msDrawShadeSymbol(&map->symbolset, image, &labelPoly, labelPtr->styles[i], layerPtr->scalefactor);
+                    msDrawShadeSymbol(&map->symbolset, image, labelPtr->annopoly, labelPtr->styles[i], layerPtr->scalefactor);
                   } else {
                     /* TODO: need error msg about unsupported geomtransform */
                     return MS_FAILURE;

Modified: sandbox/sdlime/rfc-77/mapfile.c
===================================================================
--- sandbox/sdlime/rfc-77/mapfile.c	2012-01-22 04:11:56 UTC (rev 13008)
+++ sandbox/sdlime/rfc-77/mapfile.c	2012-01-23 04:43:40 UTC (rev 13009)
@@ -1687,6 +1687,10 @@
 
   /* RFC 77 TODO: free book keeping vars */
   msFree(label->annotext);
+  if(label->annopoly) {
+    msFreeShape(label->annopoly);
+    msFree(label->annopoly);
+  }
 
   return MS_SUCCESS;
 }



More information about the mapserver-commits mailing list