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

svn at osgeo.org svn at osgeo.org
Sun Jan 15 09:28:56 EST 2012


Author: sdlime
Date: 2012-01-15 06:28:56 -0800 (Sun, 15 Jan 2012)
New Revision: 12984

Modified:
   sandbox/sdlime/rfc-77/mapagg.cpp
   sandbox/sdlime/rfc-77/mapcopy.c
   sandbox/sdlime/rfc-77/mapdraw.c
   sandbox/sdlime/rfc-77/mapgraticule.c
   sandbox/sdlime/rfc-77/mapimagemap.c
   sandbox/sdlime/rfc-77/maplabel.c
   sandbox/sdlime/rfc-77/mapunion.c
Log:
Compiles, but doesn't work. All pieces in place though. Now to test/debug...

Modified: sandbox/sdlime/rfc-77/mapagg.cpp
===================================================================
--- sandbox/sdlime/rfc-77/mapagg.cpp	2012-01-14 01:13:02 UTC (rev 12983)
+++ sandbox/sdlime/rfc-77/mapagg.cpp	2012-01-15 14:28:56 UTC (rev 12984)
@@ -679,7 +679,8 @@
    pixel_format pf(b);
    AGG2Renderer *r = AGG_RENDERER(dest);
    mapserver::rect_base<int> src_rect(srcX,srcY,srcX+width,srcY+height);
-   r->m_renderer_base.blend_from(pf,&src_rect, dstX-srcX, dstY-srcY, unsigned(opacity * 255));
+   // r->m_renderer_base.blend_from(pf,&src_rect, dstX-srcX, dstY-srcY, unsigned(opacity * 255));
+   r->m_renderer_base.blend_from(pf,&src_rect, dstX, dstY, unsigned(opacity * 255));
    return MS_SUCCESS;
 }
 

Modified: sandbox/sdlime/rfc-77/mapcopy.c
===================================================================
--- sandbox/sdlime/rfc-77/mapcopy.c	2012-01-14 01:13:02 UTC (rev 12983)
+++ sandbox/sdlime/rfc-77/mapcopy.c	2012-01-15 14:28:56 UTC (rev 12984)
@@ -329,7 +329,7 @@
   /*
   ** other book keeping information (RFC 77 TODO)
   */
-  MS_COPYSTRING(dst->string, src->string);
+  MS_COPYSTRING(dst->annotext, src->annotext);
 
   return MS_SUCCESS;
 }

Modified: sandbox/sdlime/rfc-77/mapdraw.c
===================================================================
--- sandbox/sdlime/rfc-77/mapdraw.c	2012-01-14 01:13:02 UTC (rev 12983)
+++ sandbox/sdlime/rfc-77/mapdraw.c	2012-01-15 14:28:56 UTC (rev 12984)
@@ -2331,6 +2331,12 @@
             cachePtr->status = MS_TRUE;
             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));             
+
+	    if(!cachePtr->status)
+              continue;
+
+            msDrawTextLine(image, cachePtr->text, labelPtr, cachePtr->labelpath, &(map->fontset), layerPtr->scalefactor); /* Draw the curved label */
+
           } else {
             int drawLabelText=MS_TRUE; // not used yet
 
@@ -2454,29 +2460,29 @@
    
             if(!cachePtr->status)
               continue; /* next label */
-   
-            /* here's where we draw the label styles */
-            if(!cachePtr->labelpath && cachePtr->label.numstyles > 0) {
-              for(i=0; i<cachePtr->label.numstyles; i++) {
-                if(cachePtr->label.styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOINT)
-                  msDrawMarkerSymbol(&map->symbolset, image, &(cachePtr->point), cachePtr->label.styles[i], layerPtr->scalefactor);
-                else if(cachePtr->label.styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOLY) {
-                  msDrawShadeSymbol(&map->symbolset, image, &labelPoly, cachePtr->label.styles[i], layerPtr->scalefactor);
-                } else {
-                  /* TODO: need error msg about unsupported geomtransform */
-                  return MS_FAILURE;
-                }
-              }
-            }
-   
+
             if(layerPtr->type == MS_LAYER_ANNOTATION && cachePtr->numstyles > 0) { /* need to draw a marker */
               for(i=0; i<cachePtr->numstyles; i++)
                 msDrawMarkerSymbol(&map->symbolset, image, &(cachePtr->point), &(cachePtr->styles[i]), layerPtr->scalefactor);
             }
+
+            for(ll=(cachePtr->numlabels-1); ll>=0; ll--) {
+              labelPtr = &(cachePtr->labels[ll]);
+
+              /* here's where we draw the label styles */
+              if(labelPtr->numstyles > 0) {
+                for(i=0; i<labelPtr->numstyles; i++) {
+                  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);
+                  } else {
+                    /* TODO: need error msg about unsupported geomtransform */
+                    return MS_FAILURE;
+                  }
+                }
+              }
    
-            if(cachePtr->labelpath) {
-              msDrawTextLine(image, cachePtr->text, labelPtr, cachePtr->labelpath, &(map->fontset), layerPtr->scalefactor); /* Draw the curved label */
-            } else {
               msDrawText(image, p, cachePtr->text, labelPtr, &(map->fontset), layerPtr->scalefactor); /* actually draw the label */
             }
           }

Modified: sandbox/sdlime/rfc-77/mapgraticule.c
===================================================================
--- sandbox/sdlime/rfc-77/mapgraticule.c	2012-01-14 01:13:02 UTC (rev 12983)
+++ sandbox/sdlime/rfc-77/mapgraticule.c	2012-01-15 14:28:56 UTC (rev 12984)
@@ -83,7 +83,7 @@
   if( layer->numclasses == 0 )
       msDebug( "GRID layer has no classes, nothing will be rendered.\n" );
 
-  if( layer->numclasses == 0 || layer->class[0]->label.size == -1 )
+  if( layer->numclasses == 0 || layer->class[0]->numlabels > 0 )
     pInfo->blabelaxes = 0;
   else
     pInfo->blabelaxes = 1;
@@ -1083,8 +1083,11 @@
   graticuleObj *pInfo = (graticuleObj  *) pLayer->layerinfo;
   rectObj rectLabel;
   pointObj ptPoint;
-  double size = pLayer->class[0]->label.size; /* TODO TBT: adjust minsize/maxsize/resolution */
+  double size = -1;
 
+  if(pLayer->class[0]->numlabels > 0)
+    size = pLayer->class[0]->labels[0]->size; /* TODO TBT: adjust minsize/maxsize/resolution. TODO RFC 77: ok to use first label? */
+
   if( pInfo == NULL || pShape == NULL ) {
     msSetError(MS_MISCERR, "Assertion failed: Null shape or layerinfo!, ", "_AdjustLabelPosition()");
     return MS_FAILURE;
@@ -1101,11 +1104,11 @@
 #endif
 
   if(pLayer->transform) {
-     msTransformShapeToPixelRound(pShape, pLayer->map->extent, pLayer->map->cellsize);
+    msTransformShapeToPixelRound(pShape, pLayer->map->extent, pLayer->map->cellsize);
   }
 
-  if(msGetLabelSize(pLayer->map, &pLayer->class[0]->label,pShape->text, size,&rectLabel,NULL) != MS_SUCCESS)
-	  return MS_FAILURE;  /* msSetError already called */
+  if(pLayer->class[0]->numlabels > 0 && msGetLabelSize(pLayer->map, pLayer->class[0]->labels[0], pShape->text, size, &rectLabel,NULL) != MS_SUCCESS)
+    return MS_FAILURE;  /* msSetError already called */
 
   switch( ePosition ) {
   case posBottom:

Modified: sandbox/sdlime/rfc-77/mapimagemap.c
===================================================================
--- sandbox/sdlime/rfc-77/mapimagemap.c	2012-01-14 01:13:02 UTC (rev 12983)
+++ sandbox/sdlime/rfc-77/mapimagemap.c	2012-01-15 14:28:56 UTC (rev 12984)
@@ -1809,163 +1809,6 @@
 
 int msDrawLabelCacheIM(imageObj* img, mapObj *map)
 {
-  pointObj p;
-  int i, j, l, priority;
-  rectObj r;
-  
-  labelCacheMemberObj *cachePtr=NULL;
-  layerObj *layerPtr=NULL;
-  labelObj *labelPtr=NULL;
-
-  int marker_width, marker_height;
-  int marker_offset_x, marker_offset_y, label_offset_x, label_offset_y;
-  rectObj marker_rect;
-  int label_mindistance, label_buffer;
-
-  label_mindistance=-1;
-  label_buffer=0;
-
-  DEBUG_IF printf("msDrawLabelCacheIM\n<BR>");
-  for(priority=MS_MAX_LABEL_PRIORITY-1; priority>=0; priority--) {
-   labelCacheSlotObj *cacheslot;
-   cacheslot = &(map->labelcache.slots[priority]);
-
-   for(l=cacheslot->numlabels-1; l>=0; l--) {
-	double size = cachePtr->label.size*layerPtr->scalefactor;
-    cachePtr = &(cacheslot->labels[l]); /* point to right spot in the label cache */
-
-    layerPtr = (GET_LAYER(map, cachePtr->layerindex)); /* set a couple of other pointers, avoids nasty references */
-    labelPtr = &(cachePtr->label);
-
-    if(!cachePtr->text || strlen(cachePtr->text) == 0)
-      continue; /* not an error, just don't want to do anything */
-
-    if(labelPtr->type == MS_TRUETYPE) {
-    	size = MS_MAX(size, labelPtr->minsize*img->resolutionfactor);
-    	size = MS_MIN(size, labelPtr->maxsize*img->resolutionfactor);  
-    }
-
-    if(msGetLabelSize(map,labelPtr,cachePtr->text, size,&r, NULL) != MS_SUCCESS) {
-      return MS_FAILURE;
-    }
-
-    label_offset_x = labelPtr->offsetx*layerPtr->scalefactor;
-    label_offset_y = labelPtr->offsety*layerPtr->scalefactor;
-    label_buffer = MS_NINT(labelPtr->buffer*img->resolutionfactor);
-    label_mindistance = MS_NINT(labelPtr->mindistance*img->resolutionfactor);
-
-    if(labelPtr->autominfeaturesize && (cachePtr->featuresize != -1) && ((r.maxx-r.minx) > cachePtr->featuresize))
-      continue; /* label too large relative to the feature */
-
-    marker_offset_x = marker_offset_y = 0; /* assume no marker */
-    if((layerPtr->type == MS_LAYER_ANNOTATION && cachePtr->numstyles > 0) || layerPtr->type == MS_LAYER_POINT) { /* there *is* a marker       */
-
-      /* TO DO: at the moment only checks the bottom style, perhaps should check all of them */
-      if (msGetMarkerSize(&map->symbolset, &(cachePtr->styles[0]), &marker_width, &marker_height, layerPtr->scalefactor) != MS_SUCCESS)
-	return(MS_FAILURE);
-
-      marker_width = (int) (marker_width * layerPtr->scalefactor);
-      marker_height = (int) (marker_height * layerPtr->scalefactor);
-
-      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);
-      marker_rect.miny = MS_NINT(cachePtr->point.y - .5 * marker_height);
-      marker_rect.maxx = marker_rect.minx + (marker_width-1);
-      marker_rect.maxy = marker_rect.miny + (marker_height-1);
-
-      for(i=0; i<cachePtr->numstyles; i++) {
-        if(cachePtr->styles[i].size == -1)
-          cachePtr->styles[i].size = (int) msSymbolGetDefaultSize( 
-              map->symbolset.symbol[cachePtr->styles[i].symbol] );
-	cachePtr->styles[i].size = (int)
-            ( cachePtr->styles[i].size * layerPtr->scalefactor);
-      }
-    }
-
-    if(labelPtr->position == MS_AUTO) {
-
-      if(layerPtr->type == MS_LAYER_LINE) {
-	int position = MS_UC;
-
-	for(j=0; j<2; j++) { /* Two angles or two positions, depending on angle. Steep angles will use the angle approach, otherwise we'll rotate between UC and LC. */
-
-	  msFreeShape(cachePtr->poly);
-	  cachePtr->status = MS_TRUE; /* assume label *can* be drawn */
-
-	  p = get_metrics(&(cachePtr->point), position, 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 */
-
-          /* Compare against rendered labels and markers (sets cachePtr->status) */
-          msTestLabelCacheCollisions(&(map->labelcache), labelPtr, 
-                                     -1, -1, label_buffer, cachePtr, priority, l, label_mindistance, (r.maxx-r.minx));
-
-	  if(cachePtr->status) /* found a suitable place for this label */
-	    break;
-
-	} /* next angle */
-
-      } else {
-	for(j=0; j<=7; j++) { /* loop through the outer label positions */
-
-	  msFreeShape(cachePtr->poly);
-	  cachePtr->status = MS_TRUE; /* assume label *can* be drawn */
-
-	  p = get_metrics(&(cachePtr->point), j, 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 */
-
-          /* Compare against rendered labels and markers (sets cachePtr->status) */
-          msTestLabelCacheCollisions(&(map->labelcache), labelPtr, 
-                                     -1, -1, label_buffer, cachePtr, priority, l,label_mindistance, (r.maxx-r.minx));
-
-	  if(cachePtr->status) /* found a suitable place for this label */
-	    break;
-	} /* next position */
-      }
-
-      if(labelPtr->force) cachePtr->status = MS_TRUE; /* draw in spite of collisions based on last position, need a *best* position */
-
-    } else {
-
-      cachePtr->status = MS_TRUE; /* assume label *can* be drawn */
-
-      if(labelPtr->position == MS_CC) /* don't need the marker_offset */
-        p = get_metrics(&(cachePtr->point), labelPtr->position, r, label_offset_x, label_offset_y, labelPtr->angle, label_buffer, cachePtr->poly);
-      else
-        p = get_metrics(&(cachePtr->point), labelPtr->position, 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, part of overlap tests */
-
-      if(!labelPtr->force) { /* no need to check anything else */
-
-        /* Compare against rendered labels and markers (sets cachePtr->status) */
-        msTestLabelCacheCollisions(&(map->labelcache), labelPtr, 
-                                   -1, -1, label_buffer, cachePtr, priority, l,label_mindistance, (r.maxx-r.minx));
-      }
-    } /* end position if-then-else */
-
-    /* imagePolyline(img, cachePtr->poly, 1, 0, 0); */
-
-    if(!cachePtr->status)
-      continue; /* next label */
-
-/* if(layerPtr->type == MS_LAYER_ANNOTATION && cachePtr->numstyles > 0) { // need to draw a marker */
-/* for(i=0; i<cachePtr->numstyles; i++) */
-/* msDrawMarkerSymbolIM(&map->symbolset, img, &(cachePtr->point), &(cachePtr->styles[i]), layerPtr->scalefactor); */
-/* } */
-
-/* if(MS_VALID_COLOR(labelPtr->backgroundcolor)) billboardIM(img, cachePtr->poly, labelPtr); */
-    msDrawTextIM(img, p, cachePtr->text, labelPtr, &(map->fontset), layerPtr->scalefactor); /* actually draw the label, we scaled it in msAddLabel */
-
-   } /* next label in cache */
-  } /* next priority */
-
   return(MS_SUCCESS);
 }
 

Modified: sandbox/sdlime/rfc-77/maplabel.c
===================================================================
--- sandbox/sdlime/rfc-77/maplabel.c	2012-01-14 01:13:02 UTC (rev 12983)
+++ sandbox/sdlime/rfc-77/maplabel.c	2012-01-15 14:28:56 UTC (rev 12984)
@@ -452,6 +452,27 @@
   return(MS_SUCCESS);
 }
 
+/* 
+** 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); 
+}
+
 /* msTestLabelCacheCollisions()
 **
 ** Compares current label against labels already drawn and markers from cache and discards it
@@ -961,27 +982,6 @@
     return rp;
 }
 
-* 
-** 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); 
-} 
-
 /*
 ** Variation on msIntersectPolygons. Label polygons aren't like shapefile polygons. They
 ** have no holes, and often do have overlapping parts (i.e. road symbols).

Modified: sandbox/sdlime/rfc-77/mapunion.c
===================================================================
--- sandbox/sdlime/rfc-77/mapunion.c	2012-01-14 01:13:02 UTC (rev 12983)
+++ sandbox/sdlime/rfc-77/mapunion.c	2012-01-15 14:28:56 UTC (rev 12984)
@@ -543,10 +543,11 @@
                     }
                     /* set up annotation */
                     msFree(layerinfo->classText);
-                    if((srclayer->class[layerinfo->classIndex]->text.string || srclayer->labelitem) && 
-                        srclayer->class[layerinfo->classIndex]->label.size != -1)
-                        layerinfo->classText = msShapeGetAnnotation(srclayer, shape);
-                    else
+                    // TODO RFC 77: if((srclayer->class[layerinfo->classIndex]->text.string || srclayer->labelitem) && srclayer->class[layerinfo->classIndex]->label.size != -1)
+                    if(srclayer->class[layerinfo->classIndex]->numlabels > 0) {                       
+                        msShapeGetAnnotation(srclayer, shape);
+                        layerinfo->classText = msStrdup(srclayer->class[layerinfo->classIndex]->labels[0]->annotext); /* pull text from the first label only */
+                    } else
                         layerinfo->classText = NULL;
                 }
 
@@ -735,19 +736,27 @@
             c->styles[i]->numbindings = 0;
         }
 
-        if (msCopyLabel(&(c->label), &(src->label)) != MS_SUCCESS) 
+        for (i = 0; i < src->numlabels; i++) 
         {
-            msSetError(MS_MEMERR, "Failed to copy label.", "msCopyClass()");
-            return MS_FAILURE;
-        }
+	    // RFC 77 TODO: allocation need to be done, but is the right way (from mapcopy.c)?
+            if (msGrowClassLabels(c) == NULL)
+	        return MS_FAILURE;
+	    initLabel(c->labels[i]);
 
-        /* remove the bindings on the label */
-        for(j=0; j<MS_LABEL_BINDING_LENGTH; j++)
-        {
-            msFree(c->label.bindings[j].item);
-            c->label.bindings[j].item = NULL;
+            if (msCopyLabel(c->labels[i], src->labels[i]) != MS_SUCCESS) 
+            {
+                msSetError(MS_MEMERR, "Failed to copy label.", "msUnionLayerGetAutoStyle()");
+                return MS_FAILURE;
+            }
+
+            /* remove the bindings on the label */
+            for(j=0; j<MS_LABEL_BINDING_LENGTH; j++)
+            {
+                msFree(c->labels[i]->bindings[j].item);
+                c->labels[i]->bindings[j].item = NULL;
+            }
+            c->labels[i]->numbindings = 0;
         }
-        c->label.numbindings = 0;
 
         c->type = src->type;
         c->layer = layer;



More information about the mapserver-commits mailing list