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

svn at osgeo.org svn at osgeo.org
Fri Jan 13 20:13:02 EST 2012


Author: sdlime
Date: 2012-01-13 17:13:02 -0800 (Fri, 13 Jan 2012)
New Revision: 12983

Modified:
   sandbox/sdlime/rfc-77/mapdraw.c
   sandbox/sdlime/rfc-77/maplabel.c
   sandbox/sdlime/rfc-77/mapserver.h
Log:
Integrated in changes associated with ticket #4133. These will end up in trunk.

Modified: sandbox/sdlime/rfc-77/mapdraw.c
===================================================================
--- sandbox/sdlime/rfc-77/mapdraw.c	2012-01-13 17:23:18 UTC (rev 12982)
+++ sandbox/sdlime/rfc-77/mapdraw.c	2012-01-14 01:13:02 UTC (rev 12983)
@@ -2271,7 +2271,7 @@
        * map image where labels can't fall
        */
       if((value = msLookupHashTable(&(map->web.metadata), "labelcache_map_edge_buffer")) != NULL) {
-        map_edge_buffer = atoi(value);
+        map_edge_buffer = MS_ABS(atoi(value));
         if(map->debug) msDebug("msDrawLabelCache(): labelcache_map_edge_buffer = %d\n", map_edge_buffer);
       }
 
@@ -2330,66 +2330,16 @@
             /* compare against image bounds, rendered labels and markers (sets cachePtr->status), if FORCE=TRUE then skip it */
             cachePtr->status = MS_TRUE;
             if(!labelPtr->force)
-              msTestLabelCacheCollisions(&(map->labelcache), labelPtr, image->width, image->height, label_buffer + map_edge_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));             
           } else {
-            int drawLabelText;
+            int drawLabelText=MS_TRUE; // not used yet
 
             /* all other cases *could* have multiple labels defined */
             for(ll=(cachePtr->numlabels-1); ll>=0; ll--) {
               labelPtr = &(cachePtr->labels[ll]);
-         
-              drawLabelText = MS_FALSE;
-              if(labelPtr->annotext && strlen(labelPtr->annotext) > 0) {
-                drawLabelText = MS_TRUE;
 
-                if(labelPtr->type == MS_TRUETYPE) {
-                  size = labelPtr->size * layerPtr->scalefactor;
-                  size = MS_MAX(size, labelPtr->minsize*image->resolutionfactor);
-                  size = MS_MIN(size, labelPtr->maxsize*image->resolutionfactor);
-                  scalefactor = size / labelPtr->size;
-                } else {
-                  size = labelPtr->size;
-                  scalefactor = 1;
-                }
-                if(msGetLabelSize(map, labelPtr, cachePtr->text, size, &r, NULL) != MS_SUCCESS)
-                  return MS_FAILURE;
-
-                /* adjust the baseline (see #1449) */
-                if(labelPtr->type == MS_TRUETYPE) {
-                  int nNewlines = msCountChars(cachePtr->text,'\n');
-                  if(!nNewlines) {
-                    labelPtr->offsety += MS_NINT((((r.miny + r.maxy) + size) / 2.0)/scalefactor);
-                    labelPtr->offsetx += MS_NINT((r.minx / 2)/scalefactor);
-                  } else {
-                    rectObj rect2; /* bbox of first line only */
-                    char *firstLine = msGetFirstLine(cachePtr->text);
-                    msGetLabelSize(map, labelPtr, firstLine, size, &rect2, NULL);
-                    labelPtr->offsety += (MS_NINT(((rect2.miny+rect2.maxy) + size) / 2))/scalefactor;
-                    labelPtr->offsetx += (MS_NINT(rect2.minx / 2))/scalefactor;
-                    free(firstLine);
-                  }
-                }
-   
-                drawLabelPoly = MS_FALSE;
-                for(i=0; i<labelPtr->numstyles; i++) {
-                  if(labelPtr->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOLY) {
-                    drawLabelPoly = MS_TRUE;
-                    break;
-                  }
-                }
-
-                label_offset_x = labelPtr->offsetx*scalefactor;
-                label_offset_y = labelPtr->offsety*scalefactor;
-                label_buffer = MS_NINT(labelPtr->buffer*image->resolutionfactor);
-                label_mindistance = MS_NINT(labelPtr->mindistance*image->resolutionfactor);
-             
-                /* if cachePtr->featuresize is set to -1, this check has been done in msPolylineLabelPath() */
-                if(labelPtr->autominfeaturesize && (cachePtr->featuresize != -1) && ((r.maxx-r.minx) > cachePtr->featuresize))
-                  continue; /* label too large relative to the feature */
-	      }
-   
-              /*** TODO: SEE branch-6-0 FOR CHANGES DEALING WITH LABEL STYLES ***/
               marker_offset_x = marker_offset_y = 0; /* assume no marker */
+              marker_width = marker_height = 0; 
               if(layerPtr->type == MS_LAYER_ANNOTATION && cachePtr->numstyles > 0) {
    
                 /* TODO: at the moment only checks the bottom (first) marker style since it *should* be the
@@ -2412,6 +2362,32 @@
                 marker_offset_y = MS_NINT(marker_height/2.0);
               }
 
+              if(labelPtr->numstyles > 0) { 
+                int temp_marker_width, temp_marker_height; 
+
+                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], &temp_marker_width, &temp_marker_height, layerPtr->scalefactor) != MS_SUCCESS) 
+                      return MS_FAILURE;
+                     break; 
+                  } 
+                }
+
+                if(temp_marker_width > marker_width || temp_marker_height > marker_height) { 
+                  marker_width = temp_marker_width; 
+                  marker_height = temp_marker_height; 
+
+                  marker_offset_x = MS_NINT(marker_width/2.0); 
+                  marker_offset_y = MS_NINT(marker_height/2.0); 
+ 
+                  marker_rect.minx = MS_NINT(cachePtr->point.x - .5 * marker_width) - labelPtr->buffer; 
+                  marker_rect.miny = MS_NINT(cachePtr->point.y - .5 * marker_height) - labelPtr->buffer; 
+                  marker_rect.maxx = MS_NINT(cachePtr->point.x + .5 * marker_width) + labelPtr->buffer; // marker_rect.minx + (marker_width-1) + labelPtr->buffer; 
+                  marker_rect.maxy = MS_NINT(cachePtr->point.y + .5 * marker_height) + labelPtr->buffer; // marker_rect.miny + (marker_height-1) + labelPtr->buffer; 
+                } 
+              } 
+
               if(drawLabelText && labelPtr->position == MS_AUTO) {
                 int positions[MS_POSITIONS_LENGTH], npositions=0;
    
@@ -2435,11 +2411,11 @@
                   cachePtr->status = MS_TRUE; /* assume label *can* be drawn */
    
                   p = get_metrics(&(cachePtr->point), positions[i], r, (marker_offset_x + label_offset_x), (marker_offset_y + label_offset_y), labelPtr->angle, label_buffer, cachePtr->poly);
-                  if(layerPtr->type == MS_LAYER_ANNOTATION && cachePtr->numstyles > 0)
-                    msRectToPolygon(marker_rect, cachePtr->poly); /* save marker bounding polygon */
-   
+                  if(marker_width > 0 && marker_height > 0)
+                    msRectToPolygon(marker_rect, cachePtr->poly); /* save marker bounding polygon (TODO: could do this once!) */
+
                   /* Compare against image bounds, rendered labels and markers (sets cachePtr->status) */
-                  msTestLabelCacheCollisions(&(map->labelcache), labelPtr, image->width, image->height, label_buffer + map_edge_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));
 
                   /* found a suitable place for this label */
                   if(cachePtr->status) {
@@ -2467,12 +2443,12 @@
                   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(layerPtr->type == MS_LAYER_ANNOTATION && cachePtr->numstyles > 0)
-                  msRectToPolygon(marker_rect, cachePtr->poly); /* save marker bounding polygon, part of overlap tests (TODO: might need to do something similar with label styles?) */
+                if(marker_width > 0 && marker_height > 0)
+                  msRectToPolygon(marker_rect, cachePtr->poly); /* save marker bounding polygon, part of overlap tests */
 
                 /* Compare against image bounds, rendered labels and markers (sets cachePtr->status), if FORCE=TRUE then skip the test */
                 if(!labelPtr->force)
-                  msTestLabelCacheCollisions(&(map->labelcache), labelPtr, image->width, image->height, label_buffer + map_edge_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));  
               }
             }
    

Modified: sandbox/sdlime/rfc-77/maplabel.c
===================================================================
--- sandbox/sdlime/rfc-77/maplabel.c	2012-01-13 17:23:18 UTC (rev 12982)
+++ sandbox/sdlime/rfc-77/maplabel.c	2012-01-14 01:13:02 UTC (rev 12983)
@@ -961,25 +961,26 @@
     return rp;
 }
 
-/*
-** is a label completely in the image (excluding label buffer)
-*/
-/* static int labelInImage(int width, int height, shapeObj *lpoly, int buffer) */
-int labelInImage(int width, int height, shapeObj *lpoly, int buffer)
-{
-  int i,j;
-
-  for(i=0; i<lpoly->numlines; i++) {
-    for(j=1; j<lpoly->line[i].numpoints; j++) {
-      if(lpoly->line[i].point[j].x < -buffer) return(MS_FALSE);
-      if(lpoly->line[i].point[j].x >= width+buffer) return(MS_FALSE);
-      if(lpoly->line[i].point[j].y < -buffer) return(MS_FALSE);
-      if(lpoly->line[i].point[j].y >= height+buffer) return(MS_FALSE);
+* 
+** Is a label completely in the image, reserving a gutter (in pixels) inside  
+** image for no labels (effectively making image larger. The gutter can be  
+** negative in cases where a label has a buffer around it. 
+*/ 
+static int labelInImage(int width, int height, shapeObj *lpoly, int gutter) 
+{ 
+  int i,j; 
+	 
+  for(i=0; i<lpoly->numlines; i++) { 
+    for(j=1; j<lpoly->line[i].numpoints; j++) { 
+      if(lpoly->line[i].point[j].x < gutter) return(MS_FALSE); 
+      if(lpoly->line[i].point[j].x >= width-gutter) return(MS_FALSE); 
+      if(lpoly->line[i].point[j].y < gutter) return(MS_FALSE); 
+      if(lpoly->line[i].point[j].y >= height-gutter) return(MS_FALSE); 
     }
   }
 
-  return(MS_TRUE);
-}
+  return(MS_TRUE); 
+} 
 
 /*
 ** Variation on msIntersectPolygons. Label polygons aren't like shapefile polygons. They

Modified: sandbox/sdlime/rfc-77/mapserver.h
===================================================================
--- sandbox/sdlime/rfc-77/mapserver.h	2012-01-13 17:23:18 UTC (rev 12982)
+++ sandbox/sdlime/rfc-77/mapserver.h	2012-01-14 01:13:02 UTC (rev 12983)
@@ -1738,7 +1738,6 @@
 MS_DLL_EXPORT int getClassIndex(layerObj *layer, char *str);
 
 /* For maplabel */
-int labelInImage(int width, int height, shapeObj *lpoly, int buffer);
 int intersectLabelPolygons(shapeObj *p1, shapeObj *p2);
 pointObj get_metrics_line(pointObj *p, int position, rectObj rect, int ox, int oy, double angle, int buffer, lineObj *poly);
 pointObj get_metrics(pointObj *p, int position, rectObj rect, int ox, int oy, double angle, int buffer, shapeObj *poly);



More information about the mapserver-commits mailing list