[mapserver-commits] r8650 - trunk/mapserver

svn at osgeo.org svn at osgeo.org
Fri Mar 6 18:35:45 EST 2009


Author: tbonfort
Date: 2009-03-06 18:35:45 -0500 (Fri, 06 Mar 2009)
New Revision: 8650

Modified:
   trunk/mapserver/HISTORY.TXT
   trunk/mapserver/mapagg.cpp
   trunk/mapserver/mapgd.c
   trunk/mapserver/maplegend.c
   trunk/mapserver/mapserver.h
Log:
Refactor legend icon drawing (remove renderer specific versions)
Add label styling or markers for annotation layer legend icons (#2917)


Modified: trunk/mapserver/HISTORY.TXT
===================================================================
--- trunk/mapserver/HISTORY.TXT	2009-03-06 22:35:33 UTC (rev 8649)
+++ trunk/mapserver/HISTORY.TXT	2009-03-06 23:35:45 UTC (rev 8650)
@@ -11,6 +11,8 @@
 
 Current Version (SVN trunk):
 ----------------------------
+- Refactor legend icon drawing (remove renderer specific versions)
+  Add label styling or markers for annotation layer legend icons (#2917)
 
 Version 5.4.0-beta3 (2009-3-5):
 --------------------------------

Modified: trunk/mapserver/mapagg.cpp
===================================================================
--- trunk/mapserver/mapagg.cpp	2009-03-06 22:35:33 UTC (rev 8649)
+++ trunk/mapserver/mapagg.cpp	2009-03-06 23:35:45 UTC (rev 8650)
@@ -2268,133 +2268,6 @@
     return buf;
 }
 
-int msDrawLegendIconAGG(mapObj *map, layerObj *lp, classObj *theclass, 
-        int width, int height, imageObj *image, int dstX, int dstY)
-{
-  int i, type;
-  shapeObj box, zigzag;
-  pointObj marker;
-  char szPath[MS_MAXPATHLEN];
-  AGGMapserverRenderer* ren = getAGGRenderer(image);
-  styleObj outline_style;
-  //bool clip = MS_VALID_COLOR(map->legend.outlinecolor); //TODO: enforce this
-
-  /* initialize the box used for polygons and for outlines */
-  box.line = (lineObj *)malloc(sizeof(lineObj));
-  box.numlines = 1;
-  box.line[0].point = (pointObj *)malloc(sizeof(pointObj)*5);
-  box.line[0].numpoints = 5;
-
-  box.line[0].point[0].x = dstX;
-  box.line[0].point[0].y = dstY;
-  box.line[0].point[1].x = dstX + width - 1;
-  box.line[0].point[1].y = dstY;
-  box.line[0].point[2].x = dstX + width - 1;
-  box.line[0].point[2].y = dstY + height - 1;
-  box.line[0].point[3].x = dstX;
-  box.line[0].point[3].y = dstY + height - 1;
-  box.line[0].point[4].x = box.line[0].point[0].x;
-  box.line[0].point[4].y = box.line[0].point[0].y;
-  box.line[0].numpoints = 5;
-    
-  /* if the class has a keyimage then load it, scale it and we're done */
-  if(theclass->keyimage != NULL) {
-      
-    imageObj* keyimage = msImageLoadGD(msBuildPath(szPath, map->mappath, theclass->keyimage));
-    if(!keyimage) return(MS_FAILURE);
-    agg::rendering_buffer thepixmap = gdImg2AGGRB_BGRA(keyimage->img.gd);
-    GDpixfmt img_pixf(thepixmap);
-    img_pixf.premultiply();
-    double scalefactor = (double)width / (double)keyimage->width;
-    ren->renderPixmapBGRA(img_pixf,dstX+width/2,dstY+height/2,0,scalefactor);
-    delete[](thepixmap.buf());
-    /* TO DO: we may want to handle this differently depending on the relative size of the keyimage */
-  } else {        
-    /* some polygon layers may be better drawn using zigzag if there is no fill */
-    type = lp->type;
-    if(type == MS_LAYER_POLYGON) {
-      type = MS_LAYER_LINE;
-      for(i=0; i<theclass->numstyles; i++) {
-       if(MS_VALID_COLOR(theclass->styles[i]->color)) { /* there is a fill */
-      type = MS_LAYER_POLYGON;
-      break;
-        }
-      }
-    }
-
-    /* 
-    ** now draw the appropriate color/symbol/size combination 
-    */     
-    switch(type) {
-    case MS_LAYER_ANNOTATION:
-      if (theclass->label.size != -1)
-      {
-        rectObj label_rect;
-        labelObj label = theclass->label;
-        label.angle = 0;
-        if (label.type == MS_TRUETYPE) label.size = height;
-        marker.x = dstX + MS_NINT(width / 2.0);
-        marker.y = dstY + MS_NINT(height / 2.0);
-        if(msGetLabelSize(image, (char*)"Aa", &label, &label_rect, &map->fontset, 1.0, MS_FALSE,NULL) != -1)
-        {
-          pointObj label_point = get_metrics(&marker, MS_CC, label_rect, 0, 0, label.angle, 0, NULL);
-          msDrawTextAGG(image, label_point, (char*)"Aa", &label, &map->fontset, 1.0);
-        }
-      }
-      break;
-    case MS_LAYER_POINT:
-      marker.x = dstX + MS_NINT(width / 2.0);
-      marker.y = dstY + MS_NINT(height / 2.0);
-
-      for(i=0; i<theclass->numstyles; i++)
-        msDrawMarkerSymbolAGG(&map->symbolset, image, &marker, theclass->styles[i], lp->scalefactor);          
-      break;
-    case MS_LAYER_LINE:
-      zigzag.line = (lineObj *)malloc(sizeof(lineObj));
-      zigzag.numlines = 1;
-      zigzag.line[0].point = (pointObj *)malloc(sizeof(pointObj)*4);
-      zigzag.line[0].numpoints = 4;
-
-      zigzag.line[0].point[0].x = dstX;
-      zigzag.line[0].point[0].y = dstY + height - 1;
-      zigzag.line[0].point[1].x = dstX + MS_NINT(width / 3.0) - 1; 
-      zigzag.line[0].point[1].y = dstY;
-      zigzag.line[0].point[2].x = dstX + MS_NINT(2.0 * width / 3.0) - 1; 
-      zigzag.line[0].point[2].y = dstY + height - 1; 
-      zigzag.line[0].point[3].x = dstX + width - 1; 
-      zigzag.line[0].point[3].y = dstY; 
-
-      for(i=0; i<theclass->numstyles; i++)
-        msDrawLineSymbolAGG(&map->symbolset, image, &zigzag, theclass->styles[i], lp->scalefactor); 
-
-      free(zigzag.line[0].point);
-      free(zigzag.line);    
-      break;
-    case MS_LAYER_CIRCLE:
-    case MS_LAYER_RASTER:
-    case MS_LAYER_CHART:
-    case MS_LAYER_POLYGON:
-      for(i=0; i<theclass->numstyles; i++)     
-        msDrawShadeSymbolAGG(&map->symbolset, image, &box, theclass->styles[i], lp->scalefactor);
-      break;
-    default:
-      return MS_FAILURE;
-      break;
-    } /* end symbol drawing */
-  }   
-
-  /* handle an outline if necessary */
-  if(MS_VALID_COLOR(map->legend.outlinecolor)) {
-    initStyle(&outline_style);
-    outline_style.color = map->legend.outlinecolor;
-    msDrawLineSymbolAGG(&map->symbolset, image, &box, &outline_style, 1.0);    
-  }
-
-  free(box.line[0].point);
-  free(box.line);
-  
-  return MS_SUCCESS;
-}
 /*
  ** Free gdImagePtr
  */

Modified: trunk/mapserver/mapgd.c
===================================================================
--- trunk/mapserver/mapgd.c	2009-03-06 22:35:33 UTC (rev 8649)
+++ trunk/mapserver/mapgd.c	2009-03-06 23:35:45 UTC (rev 8650)
@@ -3161,137 +3161,6 @@
   
 }
 
-int msDrawLegendIconGD(mapObj *map, layerObj *lp, classObj *class, int width, int height, gdImagePtr img, int dstX, int dstY)
-{
-  int i, type;
-  shapeObj box, zigzag;
-  pointObj marker;
-  char szPath[MS_MAXPATHLEN];
-  imageObj *image = NULL;
-  styleObj outline_style;
-
-  /* if drawing an outline (below) we need to set clipping to keep symbols withing the outline */
-  if(MS_VALID_COLOR(map->legend.outlinecolor))
-    gdImageSetClip(img, dstX, dstY, dstX + width - 1, dstY + height - 1);
-
-  /* initialize the box used for polygons and for outlines */
-  box.line = (lineObj *)malloc(sizeof(lineObj));
-  box.numlines = 1;
-  box.line[0].point = (pointObj *)malloc(sizeof(pointObj)*5);
-  box.line[0].numpoints = 5;
-
-  box.line[0].point[0].x = dstX;
-  box.line[0].point[0].y = dstY;
-  box.line[0].point[1].x = dstX + width - 1;
-  box.line[0].point[1].y = dstY;
-  box.line[0].point[2].x = dstX + width - 1;
-  box.line[0].point[2].y = dstY + height - 1;
-  box.line[0].point[3].x = dstX;
-  box.line[0].point[3].y = dstY + height - 1;
-  box.line[0].point[4].x = box.line[0].point[0].x;
-  box.line[0].point[4].y = box.line[0].point[0].y;
-  box.line[0].numpoints = 5;
-    
-  /* if the class has a keyimage then load it, scale it and we're done */
-  if(class->keyimage != NULL) {
-    image = msImageLoadGD(msBuildPath(szPath, map->mappath, class->keyimage));
-    if(!image) return(MS_FAILURE);
-
-    /* TO DO: we may want to handle this differently depending on the relative size of the keyimage */
-    gdImageCopyResampled(img, image->img.gd, dstX, dstY, 0, 0, width, height, image->img.gd->sx, image->img.gd->sy);
-  } else {        
-    /* some polygon layers may be better drawn using zigzag if there is no fill */
-    type = lp->type;
-    if(type == MS_LAYER_POLYGON) {
-      type = MS_LAYER_LINE;
-      for(i=0; i<class->numstyles; i++) {
-       if(MS_VALID_COLOR(class->styles[i]->color)) { /* there is a fill */
-      type = MS_LAYER_POLYGON;
-      break;
-        }
-      }
-    }
-
-    /* 
-    ** now draw the appropriate color/symbol/size combination 
-    */     
-
-    /* Bug 490 - switch alpha blending on for a layer that requires it */
-    if(lp->opacity == MS_GD_ALPHA)
-      gdImageAlphaBlending(img, 1);
-
-    switch(type) {
-    case MS_LAYER_ANNOTATION:
-      if (class->label.size != -1)
-      {
-        rectObj label_rect;
-        labelObj label = class->label;
-        label.angle = 0;
-        if (label.type == MS_TRUETYPE) label.size = height;
-        marker.x = dstX + MS_NINT(width / 2.0);
-        marker.y = dstY + MS_NINT(height / 2.0);
-        if(msGetLabelSize(NULL,"Aa", &label, &label_rect, &map->fontset, 1.0, MS_FALSE,NULL) != -1)
-        {
-          pointObj label_point = get_metrics(&marker, MS_CC, label_rect, 0, 0, label.angle, 0, NULL);
-          msDrawTextGD(img, label_point, "Aa", &label, &map->fontset, 1.0);
-        }
-      }
-      break;
-    case MS_LAYER_POINT:
-      marker.x = dstX + MS_NINT(width / 2.0);
-      marker.y = dstY + MS_NINT(height / 2.0);
-
-      for(i=0; i<class->numstyles; i++)
-        msDrawMarkerSymbolGD(&map->symbolset, img, &marker, class->styles[i], lp->scalefactor);          
-      break;
-    case MS_LAYER_LINE:
-      zigzag.line = (lineObj *)malloc(sizeof(lineObj));
-      zigzag.numlines = 1;
-      zigzag.line[0].point = (pointObj *)malloc(sizeof(pointObj)*4);
-      zigzag.line[0].numpoints = 4;
-
-      zigzag.line[0].point[0].x = dstX;
-      zigzag.line[0].point[0].y = dstY + height - 1;
-      zigzag.line[0].point[1].x = dstX + MS_NINT(width / 3.0) - 1;
-      zigzag.line[0].point[1].y = dstY;
-      zigzag.line[0].point[2].x = dstX + MS_NINT(2.0 * width / 3.0) - 1;
-      zigzag.line[0].point[2].y = dstY + height - 1;
-      zigzag.line[0].point[3].x = dstX + width - 1;
-      zigzag.line[0].point[3].y = dstY;
-      zigzag.line[0].numpoints = 4;
-
-      for(i=0; i<class->numstyles; i++)
-        msDrawLineSymbolGD(&map->symbolset, img, &zigzag, class->styles[i], lp->scalefactor); 
-
-      free(zigzag.line[0].point);
-      free(zigzag.line);    
-      break;
-    case MS_LAYER_CIRCLE:
-    case MS_LAYER_RASTER:
-    case MS_LAYER_CHART:
-    case MS_LAYER_POLYGON:
-      for(i=0; i<class->numstyles; i++)     
-        msDrawShadeSymbolGD(&map->symbolset, img, &box, class->styles[i], lp->scalefactor);
-      break;
-    default:
-      return MS_FAILURE;
-      break;
-    } /* end symbol drawing */
-  }   
-
-  /* handle an outline if necessary */
-  if(MS_VALID_COLOR(map->legend.outlinecolor)) {
-    initStyle(&outline_style);
-    outline_style.color = map->legend.outlinecolor;
-    msDrawLineSymbolGD(&map->symbolset, img, &box, &outline_style, 1.0);    
-    gdImageSetClip(img, 0, 0, img->sx - 1, img->sy - 1); /* undo any clipping settings */
-  }
-
-  free(box.line[0].point);
-  free(box.line);
-  
-  return MS_SUCCESS;
-}
 /*
  * copy src to dst using dst's palette
  * src must be a truecolor image

Modified: trunk/mapserver/maplegend.c
===================================================================
--- trunk/mapserver/maplegend.c	2009-03-06 22:35:33 UTC (rev 8649)
+++ trunk/mapserver/maplegend.c	2009-03-06 23:35:45 UTC (rev 8650)
@@ -40,17 +40,152 @@
  * renderer specific drawing functions shouldn't be called directly, but through
  * this function
  */
-int msDrawLegendIcon(mapObj *map, layerObj *lp, classObj *class, int width, int height, imageObj *img, int dstX, int dstY)
+int msDrawLegendIcon(mapObj *map, layerObj *lp, classObj *theclass, 
+        int width, int height, imageObj *image, int dstX, int dstY)
 {
-#ifdef USE_AGG
-  if(MS_RENDERER_AGG(map->outputformat))
-    return msDrawLegendIconAGG(map,lp,class,width,height,img,dstX,dstY);
-  else
-#endif
-    /*default is to draw with GD*/
-    return msDrawLegendIconGD(map,lp,class,width,height,img->img.gd,dstX,dstY);
+  int i, type;
+  shapeObj box, zigzag;
+  pointObj marker;
+  char szPath[MS_MAXPATHLEN];
+  styleObj outline_style;
+  
+  if(MS_RENDERER_GD(map->outputformat))
+    /* keep GD specific code here for now as it supports clipping */
+	if(MS_VALID_COLOR(map->legend.outlinecolor))
+	  gdImageSetClip(image->img.gd, dstX, dstY, dstX + width - 1, dstY + height - 1);
+  
+
+  /* initialize the box used for polygons and for outlines */
+  box.line = (lineObj *)malloc(sizeof(lineObj));
+  box.numlines = 1;
+  box.line[0].point = (pointObj *)malloc(sizeof(pointObj)*5);
+  box.line[0].numpoints = 5;
+
+  box.line[0].point[0].x = dstX;
+  box.line[0].point[0].y = dstY;
+  box.line[0].point[1].x = dstX + width - 1;
+  box.line[0].point[1].y = dstY;
+  box.line[0].point[2].x = dstX + width - 1;
+  box.line[0].point[2].y = dstY + height - 1;
+  box.line[0].point[3].x = dstX;
+  box.line[0].point[3].y = dstY + height - 1;
+  box.line[0].point[4].x = box.line[0].point[0].x;
+  box.line[0].point[4].y = box.line[0].point[0].y;
+  box.line[0].numpoints = 5;
+    
+  /* if the class has a keyimage, treat it as a point layer
+   * (the keyimage will be treated there) */
+  if(theclass->keyimage != NULL) {
+    type = MS_LAYER_POINT;
+  } else {        
+    /* some polygon layers may be better drawn using zigzag if there is no fill */
+    type = lp->type;
+    if(type == MS_LAYER_POLYGON) {
+      type = MS_LAYER_LINE;
+      for(i=0; i<theclass->numstyles; i++) {
+       if(MS_VALID_COLOR(theclass->styles[i]->color)) { /* there is a fill */
+      type = MS_LAYER_POLYGON;
+      break;
+        }
+      }
+    }
+  }
+
+  /* 
+  ** now draw the appropriate color/symbol/size combination 
+  */     
+  switch(type) {
+  case MS_LAYER_ANNOTATION:
+    marker.x = dstX + MS_NINT(width / 2.0);
+    marker.y = dstY + MS_NINT(height / 2.0);
+    if (theclass->numstyles > 0) {
+      for(i=0; i<theclass->numstyles; i++)
+        msDrawMarkerSymbol(&map->symbolset, image, &marker, theclass->styles[i], lp->scalefactor);          
+    } else if (theclass->label.size!=-1) {
+      labelObj label = theclass->label;
+      double lsize = label.size;
+      double langle = label.angle;
+      int lpos = label.position;
+      label.angle = 0;
+      label.position = MS_CC;
+      if (label.type == MS_TRUETYPE) label.size = height;
+      msDrawLabel(map, image, marker, (char*)"Az", &label,1.0);
+      label.size = lsize;
+      label.position = lpos;
+      label.angle = langle;
+    }
+    break;
+  case MS_LAYER_POINT:
+    marker.x = dstX + MS_NINT(width / 2.0);
+    marker.y = dstY + MS_NINT(height / 2.0);
+    if(theclass->keyimage != NULL) {
+      int symbolNum;
+      styleObj imgStyle;
+      symbolNum = msAddImageSymbol(&(map->symbolset), msBuildPath(szPath, map->mappath, theclass->keyimage));
+      if(symbolNum == -1) { 
+          msSetError(MS_GDERR, "Failed to open legend key image", "msCreateLegendIcon()");
+          return(MS_FAILURE);
+      }
+      initStyle(&imgStyle);
+      imgStyle.size = width;
+      imgStyle.symbol = symbolNum;
+      msDrawMarkerSymbol(&map->symbolset,image,&marker,&imgStyle,lp->scalefactor);
+      /* TO DO: we may want to handle this differently depending on the relative size of the keyimage */
+    } else {
+      for(i=0; i<theclass->numstyles; i++)
+        msDrawMarkerSymbol(&map->symbolset, image, &marker, theclass->styles[i], lp->scalefactor);
+    }
+    break;
+  case MS_LAYER_LINE:
+    zigzag.line = (lineObj *)malloc(sizeof(lineObj));
+    zigzag.numlines = 1;
+    zigzag.line[0].point = (pointObj *)malloc(sizeof(pointObj)*4);
+    zigzag.line[0].numpoints = 4;
+
+    zigzag.line[0].point[0].x = dstX;
+    zigzag.line[0].point[0].y = dstY + height - 1;
+    zigzag.line[0].point[1].x = dstX + MS_NINT(width / 3.0) - 1; 
+    zigzag.line[0].point[1].y = dstY;
+    zigzag.line[0].point[2].x = dstX + MS_NINT(2.0 * width / 3.0) - 1; 
+    zigzag.line[0].point[2].y = dstY + height - 1; 
+    zigzag.line[0].point[3].x = dstX + width - 1; 
+    zigzag.line[0].point[3].y = dstY; 
+
+    for(i=0; i<theclass->numstyles; i++)
+      msDrawLineSymbol(&map->symbolset, image, &zigzag, theclass->styles[i], lp->scalefactor); 
+
+    free(zigzag.line[0].point);
+    free(zigzag.line);    
+    break;
+  case MS_LAYER_CIRCLE:
+  case MS_LAYER_RASTER:
+  case MS_LAYER_CHART:
+  case MS_LAYER_POLYGON:
+    for(i=0; i<theclass->numstyles; i++)     
+      msDrawShadeSymbol(&map->symbolset, image, &box, theclass->styles[i], lp->scalefactor);
+    break;
+  default:
+    return MS_FAILURE;
+    break;
+  } /* end symbol drawing */
+
+  /* handle an outline if necessary */
+  if(MS_VALID_COLOR(map->legend.outlinecolor)) {
+    initStyle(&outline_style);
+    outline_style.color = map->legend.outlinecolor;
+    msDrawLineSymbol(&map->symbolset, image, &box, &outline_style, 1.0);
+    /* reset clipping rectangle */
+    if(MS_RENDERER_GD(map->outputformat))
+    	gdImageSetClip(image->img.gd, 0, 0, image->width - 1, image->height - 1);
+  }
+
+  free(box.line[0].point);
+  free(box.line);
+  
+  return MS_SUCCESS;
 }
 
+
 imageObj *msCreateLegendIcon(mapObj* map, layerObj* lp, classObj* class, int width, int height)
 {
   imageObj *image;

Modified: trunk/mapserver/mapserver.h
===================================================================
--- trunk/mapserver/mapserver.h	2009-03-06 22:35:33 UTC (rev 8649)
+++ trunk/mapserver/mapserver.h	2009-03-06 23:35:45 UTC (rev 8650)
@@ -1948,7 +1948,6 @@
 
 MS_DLL_EXPORT int msDrawTextGD(gdImagePtr img, pointObj labelPnt, char *string, labelObj *label, fontSetObj *fontset, double scalefactor);
 MS_DLL_EXPORT int msDrawTextLineGD(gdImagePtr img, char *string, labelObj *label, labelPathObj *labelpath, fontSetObj *fontset, double scalefactor);
-MS_DLL_EXPORT int msDrawLegendIconGD(mapObj *map, layerObj *lp, classObj *theclass, int width, int height, gdImagePtr img, int dstX, int dstY);
 
 MS_DLL_EXPORT void msImageCopyMerge (gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int w, int h, int pct);
 MS_DLL_EXPORT void msImageCopyMergeNoAlpha (gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int w, int h, int pct, colorObj *transparent);
@@ -1982,7 +1981,6 @@
 
 MS_DLL_EXPORT void msTransformShapeAGG(shapeObj *shape, rectObj extent, double cellsize);
 
-MS_DLL_EXPORT int msDrawLegendIconAGG(mapObj *map, layerObj *lp, classObj *theclass, int width, int height, imageObj *image, int dstX, int dstY);
 MS_DLL_EXPORT void msFreeSymbolCacheAGG(void *buffer);
 
 MS_DLL_EXPORT void msAlphaGD2AGG(imageObj *im);



More information about the mapserver-commits mailing list