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

svn at osgeo.org svn at osgeo.org
Sun Jan 15 19:04:22 EST 2012


Author: sdlime
Date: 2012-01-15 16:04:22 -0800 (Sun, 15 Jan 2012)
New Revision: 12985

Modified:
   sandbox/sdlime/rfc-77/mapdraw.c
   sandbox/sdlime/rfc-77/maplabel.c
   sandbox/sdlime/rfc-77/maplegend.c
   sandbox/sdlime/rfc-77/mapscale.c
   sandbox/sdlime/rfc-77/mapserver.h
Log:
Wrote msAddLabelGroup(). Changed msAddLabel() signature.

Modified: sandbox/sdlime/rfc-77/mapdraw.c
===================================================================
--- sandbox/sdlime/rfc-77/mapdraw.c	2012-01-15 14:28:56 UTC (rev 12984)
+++ sandbox/sdlime/rfc-77/mapdraw.c	2012-01-16 00:04:22 UTC (rev 12985)
@@ -1592,7 +1592,7 @@
 
             if(annopaths[i]) {
               if(layer->labelcache) {
-                if(msAddLabel(map, layer->index, c, annoshape, NULL, annopaths[i], label->annotext, -1, label) != MS_SUCCESS) return(MS_FAILURE);
+                if(msAddLabel(map, label, layer->index, c, annoshape, NULL, annopaths[i], -1) != MS_SUCCESS) return(MS_FAILURE);
               } else {
                 /* TODO: handle drawing curved labels outside the cache */
                 msFreeLabelPathObj(annopaths[i]);
@@ -1608,7 +1608,7 @@
             for (i=0; i<numpoints; i++) {
               label->angle = *angles[i];              
               if(layer->labelcache) {
-                if(msAddLabel(map, layer->index, c, annoshape, annopoints[i], NULL, label->annotext, *lengths[i], label) != MS_SUCCESS) return(MS_FAILURE);
+                if(msAddLabel(map, label, layer->index, c, annoshape, annopoints[i], NULL, *lengths[i]) != MS_SUCCESS) return(MS_FAILURE);
               } else {
                 msDrawLabel(map, image, *annopoints[i], label->annotext, label, layer->scalefactor);
               }
@@ -1624,7 +1624,7 @@
             if(label->anglemode != MS_NONE) label->angle = *angles[i]; /* angle derived from line overrides even the rotation value. */
               
             if(layer->labelcache) {
-              if(msAddLabel(map, layer->index, c, annoshape, annopoints[i], NULL, label->annotext, *lengths[i], label) != MS_SUCCESS) return(MS_FAILURE);
+              if(msAddLabel(map, label, layer->index, c, annoshape, annopoints[i], NULL, *lengths[i]) != MS_SUCCESS) return(MS_FAILURE);
             } else {
               if(layer->class[c]->numstyles > 0 && MS_VALID_COLOR(layer->class[c]->styles[0]->color)) {
                 for(s=0; s<layer->class[c]->numstyles; s++) {                  
@@ -1697,7 +1697,7 @@
 
         if(layer->labelcache) {
           if (bLabelNoClip == MS_TRUE) msComputeBounds(shape); /* compute the bounds, previous bounds were calculated on a non transformed shape */
-          if(msAddLabelGroup(map, layer->index, shape, &annopnt, MS_MIN(shape->bounds.maxx-shape->bounds.minx,shape->bounds.maxy-shape->bounds.miny)) != MS_SUCCESS) return (MS_FAILURE);
+          if(msAddLabelGroup(map, layer->index, c, shape, &annopnt, MS_MIN(shape->bounds.maxx-shape->bounds.minx,shape->bounds.maxy-shape->bounds.miny)) != MS_SUCCESS) return (MS_FAILURE);
         } else {
 	  if(layer->class[c]->numstyles > 0 && MS_VALID_COLOR(layer->class[c]->styles[0]->color)) {
             for(s=0; s<layer->class[c]->numstyles; s++) {
@@ -1726,7 +1726,7 @@
             msOffsetPointRelativeTo(point, layer);
 
           if(layer->labelcache) {
-            if(msAddLabelGroup(map, layer->index, shape, point, -1) != MS_SUCCESS) return (MS_FAILURE);
+            if(msAddLabelGroup(map, layer->index, c, shape, point, -1) != MS_SUCCESS) return (MS_FAILURE);
 	  } else {
             if(layer->class[c]->numstyles > 0 && MS_VALID_COLOR(layer->class[c]->styles[0]->color)) {
               for(s=0; s<layer->class[c]->numstyles; s++) {
@@ -1771,7 +1771,7 @@
         }
 
         if(layer->labelcache) {
-          if(msAddLabelGroup(map, layer->index, shape, point, -1) != MS_SUCCESS) return (MS_FAILURE);
+          if(msAddLabelGroup(map, layer->index, c, shape, point, -1) != MS_SUCCESS) return (MS_FAILURE);
 	} else {
           for(l=0; l<layer->class[c]->numlabels; l++)
             msDrawLabel(map, image, *point, layer->class[c]->labels[l]->annotext, layer->class[c]->labels[l], layer->scalefactor);
@@ -1872,7 +1872,7 @@
 
           if(annopaths[i]) {
             if(layer->labelcache) {
-              if(msAddLabel(map, layer->index, c, annoshape, NULL, annopaths[i], label->annotext, -1, label) != MS_SUCCESS) return(MS_FAILURE);
+              if(msAddLabel(map, label, layer->index, c, annoshape, NULL, annopaths[i], -1) != MS_SUCCESS) return(MS_FAILURE);
             } else {
               /* TODO: handle drawing curved labels outside the cache */
               msFreeLabelPathObj(annopaths[i]);
@@ -1886,9 +1886,9 @@
           annopoints = msPolylineLabelPointExtended(annoshape, minfeaturesize, label->repeatdistance, &angles, &lengths, &numpoints, regularLines, numRegularLines, MS_FALSE);          
           
           for (i=0; i<numpoints; i++) {
-            label->angle = *angles[i];            
+            label->angle = *angles[i];
             if(layer->labelcache) {
-              if(msAddLabel(map, layer->index, c, annoshape, annopoints[i], NULL, label->annotext, *lengths[i], label) != MS_SUCCESS) return(MS_FAILURE);
+              if(msAddLabel(map, label, layer->index, c, annoshape, annopoints[i], NULL, *lengths[i]) != MS_SUCCESS) return(MS_FAILURE);
             } else {
               msDrawLabel(map, image, *annopoints[i], label->annotext, label, layer->scalefactor);
             }
@@ -1904,7 +1904,7 @@
           if(label->anglemode != MS_NONE) label->angle = *angles[i]; /* angle derived from line overrides even the rotation value. */
           
           if(layer->labelcache) {
-            if(msAddLabel(map, layer->index, c, annoshape, annopoints[i], NULL, label->annotext, *lengths[i], label) != MS_SUCCESS) return(MS_FAILURE);
+            if(msAddLabel(map, label, layer->index, c, annoshape, annopoints[i], NULL, *lengths[i]) != MS_SUCCESS) return(MS_FAILURE);
           } else {
             msDrawLabel(map, image, *annopoints[i], label->annotext, label, layer->scalefactor);
           }
@@ -2038,7 +2038,7 @@
 
 	if(layer->labelcache) {
           if (bLabelNoClip == MS_TRUE) msComputeBounds(shape); /* compute the bounds, previous bounds were calculated on a non transformed shape */
-          if(msAddLabelGroup(map, layer->index, shape, &annopnt, MS_MIN(shape->bounds.maxx-shape->bounds.minx,shape->bounds.maxy-shape->bounds.miny)) != MS_SUCCESS) return (MS_FAILURE);
+          if(msAddLabelGroup(map, c, layer->index, shape, &annopnt, MS_MIN(shape->bounds.maxx-shape->bounds.minx,shape->bounds.maxy-shape->bounds.miny)) != MS_SUCCESS) return (MS_FAILURE);
 	} else {
           for(l=0; l<layer->class[c]->numlabels; l++)
             msDrawLabel(map, image, annopnt, layer->class[c]->labels[l]->annotext, layer->class[c]->labels[l], layer->scalefactor);
@@ -2092,7 +2092,7 @@
 
     if(labeltext) {
       if(layer->labelcache) {
-        if(msAddLabel(map, layer->index, classindex, NULL, point, NULL, label->annotext, -1, label) != MS_SUCCESS) return(MS_FAILURE);
+        if(msAddLabel(map, label, layer->index, classindex, NULL, point, NULL, -1) != MS_SUCCESS) return(MS_FAILURE);
       } else {
 	if(theclass->numstyles > 0 && MS_VALID_COLOR(theclass->styles[0]->color)) {
           for(s=0; s<theclass->numstyles; s++) {
@@ -2119,7 +2119,7 @@
     }
     if(labeltext) {
       if(layer->labelcache) {
-        if(msAddLabel(map, layer->index, classindex, NULL, point, NULL, label->annotext, -1, label) != MS_SUCCESS) return(MS_FAILURE);
+        if(msAddLabel(map, label, layer->index, classindex, NULL, point, NULL, -1) != MS_SUCCESS) return(MS_FAILURE);
       } else
 	msDrawLabel(map, image, *point, label->annotext, label, layer->scalefactor);
     }

Modified: sandbox/sdlime/rfc-77/maplabel.c
===================================================================
--- sandbox/sdlime/rfc-77/maplabel.c	2012-01-15 14:28:56 UTC (rev 12984)
+++ sandbox/sdlime/rfc-77/maplabel.c	2012-01-16 00:04:22 UTC (rev 12985)
@@ -302,12 +302,151 @@
     return newtext;
 }
 
-int msAddLabelGroup(mapObj *map, int layerindex, shapeObj *shape, pointObj *point, double featuresize) {
-  // copy msAddLabel...
-  // if the number of labels is 1 then call msAddLabel() accordingly
+int msAddLabelGroup(mapObj *map, int layerindex, int classindex, shapeObj *shape, pointObj *point, double featuresize) {
+  int i, priority;
+  labelCacheSlotObj *cacheslot;
+
+  labelCacheMemberObj *cachePtr=NULL;
+  layerObj *layerPtr=NULL;
+  classObj *classPtr=NULL;
+
+  layerPtr = (GET_LAYER(map, layerindex)); /* set up a few pointers for clarity */
+  classPtr = GET_LAYER(map, layerindex)->class[classindex];
+
+  /* if the number of labels is 1 then call msAddLabel() accordingly */
+  if(classPtr->numlabels == 1) {
+    msAddLabel(map, classPtr->labels[0], layerindex, classindex, shape, point, NULL, featuresize);
+  }
+
+  // if( label == NULL )
+  //   label = &(classPtr->label);
+
+  // RFC 77 TODO : could happen in msShapeGetAnnotation() or move to the numtext/numlabels loops below
+  // if(map->scaledenom > 0) {
+  //   if((label->maxscaledenom != -1) && (map->scaledenom >= label->maxscaledenom))
+  //     return(MS_SUCCESS);
+  //   if((label->minscaledenom != -1) && (map->scaledenom < label->minscaledenom))
+  //     return(MS_SUCCESS);
+  // }
+
+  /* Validate label priority value and get ref on label cache for it */
+  priority = classPtr->labels[0]->priority; /* take priority from the first label */
+  if (priority < 1)
+    priority = 1;
+  else if (priority > MS_MAX_LABEL_PRIORITY)
+    priority = MS_MAX_LABEL_PRIORITY;
+
+  cacheslot = &(map->labelcache.slots[priority-1]);
+
+  if(cacheslot->numlabels == cacheslot->cachesize) { /* just add it to the end */
+    cacheslot->labels = (labelCacheMemberObj *) realloc(cacheslot->labels, sizeof(labelCacheMemberObj)*(cacheslot->cachesize+MS_LABELCACHEINCREMENT));
+    MS_CHECK_ALLOC(cacheslot->labels, sizeof(labelCacheMemberObj)*(cacheslot->cachesize+MS_LABELCACHEINCREMENT), MS_FAILURE);
+    cacheslot->cachesize += MS_LABELCACHEINCREMENT;
+  }
+
+  cachePtr = &(cacheslot->labels[cacheslot->numlabels]);
+
+  cachePtr->layerindex = layerindex; /* so we can get back to this *raw* data if necessary */
+  cachePtr->classindex = classindex;
+
+  if(shape) {
+    cachePtr->tileindex = shape->tileindex;
+    cachePtr->shapeindex = shape->index;
+    cachePtr->shapetype = shape->type;
+  } else {
+    cachePtr->tileindex = cachePtr->shapeindex = -1;    
+    cachePtr->shapetype = MS_SHAPE_POINT;
+  }
+
+  /* store the label point and set the labelpath to NULL */
+  cachePtr->point = *point; /* the actual label point */
+  cachePtr->point.x = MS_NINT(cachePtr->point.x);
+  cachePtr->point.y = MS_NINT(cachePtr->point.y);
+  cachePtr->labelpath = NULL;
+
+  // cachePtr->text = msStrdup(string); /* the actual text */
+
+  /* TODO: perhaps we can get rid of this next section and just store a marker size? Why do we cache the styles for a point layer? */
+
+  /* copy the styles (only if there is an accompanying marker)
+   * We cannot simply keeep refs because the rendering code alters some members of the style objects
+   */
+  cachePtr->styles = NULL;
+  cachePtr->numstyles = 0;
+  if(layerPtr->type == MS_LAYER_ANNOTATION && classPtr->numstyles > 0) {
+    cachePtr->numstyles = classPtr->numstyles;
+    cachePtr->styles = (styleObj *) msSmallMalloc(sizeof(styleObj)*classPtr->numstyles);
+    if (classPtr->numstyles > 0) {
+      for(i=0; i<classPtr->numstyles; i++) {
+	initStyle(&(cachePtr->styles[i]));
+	msCopyStyle(&(cachePtr->styles[i]), classPtr->styles[i]);
+      }
+    }
+  }
+
+  /* 
+  ** copy the labels: 
+  **   we cannot simply keep refs because the rendering code alters some members of the style objects
+  */
+  cachePtr->numlabels = classPtr->numlabels;
+  cachePtr->labels = (labelObj *) msSmallMalloc(sizeof(labelObj)*cachePtr->numlabels);
+  for(i=0; i<cachePtr->numlabels; i++)
+    msCopyLabel(&(cachePtr->labels[i]), classPtr->labels[i]);
+
+  cachePtr->markerid = -1;
+
+  cachePtr->featuresize = featuresize;
+
+  cachePtr->poly = (shapeObj *) msSmallMalloc(sizeof(shapeObj));
+  msInitShape(cachePtr->poly);
+
+  cachePtr->status = MS_FALSE;
+
+  if(layerPtr->type == MS_LAYER_POINT) { /* cache the marker placement, it's already on the map */
+    rectObj rect;
+    int w, h;
+
+    if(cacheslot->nummarkers == cacheslot->markercachesize) { /* just add it to the end */
+      cacheslot->markers = (markerCacheMemberObj *) realloc(cacheslot->markers, sizeof(markerCacheMemberObj)*(cacheslot->cachesize+MS_LABELCACHEINCREMENT));
+      MS_CHECK_ALLOC(cacheslot->markers, sizeof(markerCacheMemberObj)*(cacheslot->cachesize+MS_LABELCACHEINCREMENT), MS_FAILURE); 
+      cacheslot->markercachesize+=MS_LABELCACHEINCREMENT;
+    }
+
+    i = cacheslot->nummarkers;
+
+    cacheslot->markers[i].poly = (shapeObj *) msSmallMalloc(sizeof(shapeObj));
+    msInitShape(cacheslot->markers[i].poly);
+
+    /* TO DO: at the moment only checks the bottom style, perhaps should check all of them */
+    /* #2347: after RFC-24 classPtr->styles could be NULL so we check it */
+    if(classPtr->styles != NULL) {
+      if(msGetMarkerSize(&map->symbolset, classPtr->styles[0], &w, &h, layerPtr->scalefactor) != MS_SUCCESS) 
+        return(MS_FAILURE);
+    } else {
+      msSetError(MS_MISCERR, "msAddLabel error: missing style definition for layer '%s'", "msAddLabel()", layerPtr->name);
+      return(MS_FAILURE);
+    }
+    rect.minx = MS_NINT(point->x - .5 * w);
+    rect.miny = MS_NINT(point->y - .5 * h);
+    rect.maxx = rect.minx + (w-1);
+    rect.maxy = rect.miny + (h-1);
+    msRectToPolygon(rect, cacheslot->markers[i].poly);    
+    cacheslot->markers[i].id = cacheslot->numlabels;
+ 
+    cachePtr->markerid = i;
+
+    cacheslot->nummarkers++;
+  }
+
+  cacheslot->numlabels++;
+
+  /* Maintain main labelCacheObj.numlabels only for backwards compatibility */
+  map->labelcache.numlabels++;
+
+  return(MS_SUCCESS);
 }
 
-int msAddLabel(mapObj *map, int layerindex, int classindex, shapeObj *shape, pointObj *point, labelPathObj *labelpath, char *string, double featuresize, labelObj *label) {
+int msAddLabel(mapObj *map, labelObj *label, int layerindex, int classindex, shapeObj *shape, pointObj *point, labelPathObj *labelpath, double featuresize) {
   int i;
   labelCacheSlotObj *cacheslot;
 
@@ -315,7 +454,8 @@
   layerObj *layerPtr=NULL;
   classObj *classPtr=NULL;
 
-  if(!string) return(MS_SUCCESS); /* not an error */ 
+  if(!label) return(MS_FAILURE); // RFC 77 TODO: set a proper message
+  if(!label->annotext) 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];
@@ -373,8 +513,6 @@
     cachePtr->point.y = MS_NINT(labelpath->path.point[i].y);
   }
 
-  cachePtr->text = msStrdup(string); /* the actual text */
-
   /* TODO: perhaps we can get rid of this next section and just store a marker size? Why do we cache the styles for a point layer? */
 
   /* copy the styles (only if there is an accompanying marker)

Modified: sandbox/sdlime/rfc-77/maplegend.c
===================================================================
--- sandbox/sdlime/rfc-77/maplegend.c	2012-01-15 14:28:56 UTC (rev 12984)
+++ sandbox/sdlime/rfc-77/maplegend.c	2012-01-16 00:04:22 UTC (rev 12985)
@@ -710,11 +710,12 @@
   GET_LAYER(map, l)->class[0]->labels[0]->force = MS_TRUE;
   GET_LAYER(map, l)->class[0]->labels[0]->size = MS_MEDIUM; /* must set a size to have a valid label definition */
   GET_LAYER(map, l)->class[0]->labels[0]->priority = MS_MAX_LABEL_PRIORITY;
+  GET_LAYER(map, l)->class[0]->labels[0]->annotext = msStrdup("");
 
   if(map->legend.postlabelcache) /* add it directly to the image */
     msDrawMarkerSymbol(&map->symbolset, img, &point, GET_LAYER(map, l)->class[0]->styles[0], 1.0);
   else
-    msAddLabel(map, l, 0, NULL, &point, NULL, "", 1.0, NULL);
+    msAddLabel(map, GET_LAYER(map, l)->class[0]->labels[0], l, 0, NULL, &point, NULL, -1);
 
   /* Mark layer as deleted so that it doesn't interfere with html legends or with saving maps */
   GET_LAYER(map, l)->status = MS_DELETE;

Modified: sandbox/sdlime/rfc-77/mapscale.c
===================================================================
--- sandbox/sdlime/rfc-77/mapscale.c	2012-01-15 14:28:56 UTC (rev 12984)
+++ sandbox/sdlime/rfc-77/mapscale.c	2012-01-16 00:04:22 UTC (rev 12985)
@@ -442,11 +442,12 @@
   GET_LAYER(map, l)->class[0]->labels[0]->force = MS_TRUE;
   GET_LAYER(map, l)->class[0]->labels[0]->size = MS_MEDIUM; /* must set a size to have a valid label definition */
   GET_LAYER(map, l)->class[0]->labels[0]->priority = MS_MAX_LABEL_PRIORITY;
+  GET_LAYER(map, l)->class[0]->labels[0]->annotext = msStrdup("");
 
   if(map->scalebar.postlabelcache) /* TODO: add it directly to the image */
     msDrawMarkerSymbol(&map->symbolset, img, &point, GET_LAYER(map, l)->class[0]->styles[0], 1.0);
   else
-    msAddLabel(map, l, 0, NULL, &point, NULL, "", 1.0, NULL);
+    msAddLabel(map, GET_LAYER(map, l)->class[0]->labels[0], l, 0, NULL, &point, NULL, -1);
 
   /* Mark layer as deleted so that it doesn't interfere with html legends or with saving maps */
   GET_LAYER(map, l)->status = MS_DELETE;

Modified: sandbox/sdlime/rfc-77/mapserver.h
===================================================================
--- sandbox/sdlime/rfc-77/mapserver.h	2012-01-15 14:28:56 UTC (rev 12984)
+++ sandbox/sdlime/rfc-77/mapserver.h	2012-01-16 00:04:22 UTC (rev 12985)
@@ -1988,9 +1988,10 @@
 MS_DLL_EXPORT int msGetTruetypeTextBBox(rendererVTableObj *renderer, char *font, double size, char *string, rectObj *rect, double **advances);
 
 MS_DLL_EXPORT int msGetLabelSize(mapObj *map, labelObj *label, char *string, double size, rectObj *rect, double **advances);
-MS_DLL_EXPORT int msAddLabel(mapObj *map, int layerindex, int classindex, shapeObj *shape, pointObj *point, labelPathObj *labelpath, char *string, double featuresize, labelObj *label);
-MS_DLL_EXPORT int msAddLabelGroup(mapObj *map, int layerindex, shapeObj *shape, pointObj *point, double featuresize);
-// MS_DLL_EXPORT int msAddLabel(mapObj *map, layerObj *layer, shapeObj *shape, double featuresize);
+
+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 void msTestLabelCacheCollisions(labelCacheObj *labelcache, labelObj *labelPtr, int mapwidth, int mapheight, int buffer, labelCacheMemberObj *cachePtr, int current_priority, int current_label, int mindistance, double label_size);
 MS_DLL_EXPORT labelCacheMemberObj *msGetLabelCacheMember(labelCacheObj *labelcache, int i);
 



More information about the mapserver-commits mailing list