[mapserver-commits] r9243 - sandbox/svgsymbols/mapserver

svn at osgeo.org svn at osgeo.org
Fri Aug 7 04:38:00 EDT 2009


Author: kiranvarma
Date: 2009-08-07 04:37:58 -0400 (Fri, 07 Aug 2009)
New Revision: 9243

Modified:
   sandbox/svgsymbols/mapserver/mapgd.c
Log:
* added skeletons for SVG functions


Modified: sandbox/svgsymbols/mapserver/mapgd.c
===================================================================
--- sandbox/svgsymbols/mapserver/mapgd.c	2009-08-06 22:20:42 UTC (rev 9242)
+++ sandbox/svgsymbols/mapserver/mapgd.c	2009-08-07 08:37:58 UTC (rev 9243)
@@ -540,6 +540,12 @@
   return brush;
 }
 
+static gdImagePtr createBrushFromSVG(gdImagePtr img, int width, int height, styleObj *style, int *fgcolor, int *bgcolor)
+{
+    gdImagePtr brush;
+    return brush;
+}
+
 static gdImagePtr createBrush(gdImagePtr img, int width, int height, styleObj *style, int *fgcolor, int *bgcolor)
 {
   gdImagePtr brush;
@@ -1277,6 +1283,32 @@
     gdImageSetBrush(img, brush);
     fc = 1; bc = 0;
     break;
+  case(MS_SYMBOL_SVG):
+    if(bc == -1) bc = gdTransparent;
+
+    d = size/symbol->sizey;
+    x = MS_NINT(symbol->sizex*d);    
+    y = MS_NINT(symbol->sizey*d);
+
+    if((x < 2) && (y < 2)) break;
+
+    /* create the brush image */
+    if((brush = searchImageCache(symbolset->imagecache, style, (int)size)) == NULL) {
+      brush = createBrushFromSVG(img, x, y, style, &brush_fc, &brush_bc);  /* not in cache, create */
+
+      /* draw in the brush image  */
+      for(i=0;i < symbol->numpoints;i++) {
+	points[i].x = MS_NINT(d*symbol->points[i].x);
+	points[i].y = MS_NINT(d*symbol->points[i].y);
+      }
+      gdImageFilledPolygon(brush, points, symbol->numpoints, brush_fc);
+
+      symbolset->imagecache = addImageCache(symbolset->imagecache, &symbolset->imagecachesize, style, (int) size, brush);
+    }
+
+    gdImageSetBrush(img, brush);
+    fc = 1; bc = 0;
+    break;
   }  
 
   if(symbol->patternlength > 0) {
@@ -1522,6 +1554,65 @@
     gdImageSetTile(img, tile);
 
     break;
+  case(MS_SYMBOL_SVG):
+    d = size/symbol->sizey; /* compute the scaling factor (d) on the unrotated symbol */
+
+    if (angle != 0.0 && angle != 360.0) {
+      bRotated = MS_TRUE;
+      symbol = msRotateSymbol(symbol, style->angle);
+    }
+
+    x = MS_NINT(symbol->sizex*d)+1;    
+    y = MS_NINT(symbol->sizey*d)+1;
+
+    if((x <= 1) && (y <= 1)) { /* No sense using a tile, just fill solid       */
+      gdImageFilledEllipse(img, (int)p->x, (int)p->y, (int)(2*r), (int)(2*r), fc);
+      if(oc>-1) gdImageArc(img, (int)p->x, (int)p->y, (int)(2*r), (int)(2*r), 0, 360, oc);
+      return;
+    }
+
+    tile = createBrushFromSVG(img, x, y, style, &tile_fc, &tile_bc); /* create tile image */
+
+    /* draw in the tile image */
+    if(symbol->filled) {
+
+      for(i=0;i < symbol->numpoints;i++) {
+	sPoints[i].x = MS_NINT(d*symbol->points[i].x);
+	sPoints[i].y = MS_NINT(d*symbol->points[i].y);
+      }
+      gdImageFilledPolygon(tile, sPoints, symbol->numpoints, tile_fc);      
+
+    } else  { /* shade is a vector drawing */
+      
+      oldpnt.x = MS_NINT(d*symbol->points[0].x); /* convert first point in shade smbol */
+      oldpnt.y = MS_NINT(d*symbol->points[0].y);
+
+      gdImageSetThickness(tile, width);
+
+      /* step through the shade symbol */
+      for(i=1;i < symbol->numpoints;i++) {
+	if((symbol->points[i].x < 0) && (symbol->points[i].y < 0)) {
+	  oldpnt.x = MS_NINT(d*symbol->points[i].x);
+	  oldpnt.y = MS_NINT(d*symbol->points[i].y);
+	} else {
+	  if((symbol->points[i-1].x < 0) && (symbol->points[i-1].y < 0)) { /* Last point was PENUP, now a new beginning */
+	    oldpnt.x = MS_NINT(d*symbol->points[i].x);
+	    oldpnt.y = MS_NINT(d*symbol->points[i].y);
+	  } else {
+	    newpnt.x = MS_NINT(d*symbol->points[i].x);
+	    newpnt.y = MS_NINT(d*symbol->points[i].y);
+	    gdImageLine(tile, oldpnt.x, oldpnt.y, newpnt.x, newpnt.y, tile_fc);
+	    oldpnt = newpnt;
+	  }
+	}
+      } /* end for loop */
+
+      gdImageSetThickness(tile, 1);
+    }
+
+    gdImageSetTile(img, tile);
+
+    break;
   default:
     break;
   }
@@ -1776,6 +1867,79 @@
     }
 
     break;
+  case(MS_SYMBOL_SVG):
+
+    d = size/symbol->sizey; /* compute the scaling factor (d) on the unrotated symbol */
+
+    if (angle != 0.0 && angle != 360.0) {      
+      bRotated = MS_TRUE;
+      symbol = msRotateSymbol(symbol, style->angle);
+    }
+
+    /* We avoid MS_NINT in this context because the potentially variable
+       handling of 0.5 rounding is often a problem for symbols which are
+       often an odd size (ie. 7pixels) and so if "p" is integral the 
+       value is always on a 0.5 boundary - bug 1716 */
+    offset_x = MS_NINT_GENERIC(p->x - d*.5*symbol->sizex + ox);
+    offset_y = MS_NINT_GENERIC(p->y - d*.5*symbol->sizey + oy);
+    
+    if(symbol->filled) { /* if filled */
+      
+      k = 0; /* point counter */
+      for(j=0;j < symbol->numpoints;j++) {
+        if((symbol->points[j].x == -99) && (symbol->points[j].x == -99)) { /* new polygon (PENUP) */
+	  if(k>2) {
+            if(fc >= 0)
+	      gdImageFilledPolygon(img, mPoints, k, fc);
+	    if(oc >= 0)
+	      gdImagePolygon(img, mPoints, k, oc);
+          }
+          k = 0; /* reset point counter */
+        } else {
+  	  mPoints[k].x = MS_NINT(d*symbol->points[j].x + offset_x);
+	  mPoints[k].y = MS_NINT(d*symbol->points[j].y + offset_y); 
+          k++;
+        }
+      }
+
+      if(fc >= 0)
+	gdImageFilledPolygon(img, mPoints, k, fc);
+      if(oc >= 0)
+	gdImagePolygon(img, mPoints, k, oc);
+      
+    } else  { /* NOT filled */     
+
+      if(fc < 0) fc = oc; /* try the outline color (reference maps sometimes do this when combining a box and a custom vector marker */
+      if(fc < 0) return;
+      
+      oldpnt.x = MS_NINT(d*symbol->points[0].x + offset_x); /* convert first point in marker */
+      oldpnt.y = MS_NINT(d*symbol->points[0].y + offset_y);
+
+      gdImageSetThickness(img, width);
+      
+      for(j=1;j < symbol->numpoints;j++) { /* step through the marker */
+	if((symbol->points[j].x != -99) || (symbol->points[j].x != -99)) {
+	  if((symbol->points[j-1].x == -99) && (symbol->points[j-1].y == -99)) { /* Last point was PENUP, now a new beginning */
+	    oldpnt.x = MS_NINT(d*symbol->points[j].x + offset_x);
+	    oldpnt.y = MS_NINT(d*symbol->points[j].y + offset_y);
+	  } else {
+	    newpnt.x = MS_NINT(d*symbol->points[j].x + offset_x);
+	    newpnt.y = MS_NINT(d*symbol->points[j].y + offset_y);
+	    gdImageLine(img, oldpnt.x, oldpnt.y, newpnt.x, newpnt.y, fc);
+	    oldpnt = newpnt;
+	  }
+	}
+      } /* end for loop */   
+
+      gdImageSetThickness(img, 1); /* restore thinkness */
+    } /* end if-then-else */
+
+    if(bRotated) {
+      msFreeSymbol(symbol); /* clean up */
+      msFree(symbol);
+    }
+
+    break;
   default:
     break;
   } /* end switch statement */
@@ -2006,6 +2170,68 @@
     gdImageSetBrush(img, brush);
     fc = 1; bc = 0;
     break;
+  case(MS_SYMBOL_SVG):
+    if(bc == -1) bc = gdTransparent;
+    
+    d = (size)/symbol->sizey; /* compute the scaling factor (d) on the unrotated symbol */
+
+    if(angle != 0.0 && angle != 360.0) {
+      /* rotate the symbol creating a new symbol object */
+      oldsymbol = symbol;
+      symbol = msRotateSymbol(symbol, angle);
+    }
+
+    x = MS_NINT(symbol->sizex*d)+1;
+    y = MS_NINT(symbol->sizey*d)+1;
+    if (x < (symbol->sizex*d)) x += 1;
+    if (y < (symbol->sizey*d)) y += 1;
+
+    if((x < 2) && (y < 2)) break;
+
+    /* create the brush image */
+    if((brush = searchImageCache(symbolset->imagecache, style, (int)size)) == NULL) { 
+      brush = createBrushFromSVG(img, x, y, style, &brush_fc, &brush_bc); /* not in cache, create it */
+
+      if (symbol->filled) {
+	k = 0; /* point counter */
+	for(i=0;i < symbol->numpoints;i++) {
+	  if((symbol->points[i].x == -99) && (symbol->points[i].x == -99)) { /* new polygon (PENUP) */
+	    if(k>2) gdImageFilledPolygon(brush, points, k, brush_fc);
+	    k = 0; /* reset point counter */
+	  } else {
+	    points[k].x = MS_NINT(d*symbol->points[i].x);
+	    points[k].y = MS_NINT(d*symbol->points[i].y);
+	    k++;
+	  }
+	}
+	if(k>2) gdImageFilledPolygon(brush, points, k, brush_fc);
+      } else {
+	oldpnt.x = MS_NINT(symbol->points[0].x*d); /* convert first point in symbol */
+	oldpnt.y = MS_NINT(symbol->points[0].y*d);
+	
+	/* draw in the brush image */
+	for (i=1;i < symbol->numpoints;i++) {
+	  if((symbol->points[i].x != -99.) || (symbol->points[i].y != -99.)) {
+	    if ((symbol->points[i-1].x == -99.) && (symbol->points[i-1].y == -99.)) {
+	      /* Last point was PENUP, now a new beginning */
+	      oldpnt.x = MS_NINT(symbol->points[i].x*d);
+	      oldpnt.y = MS_NINT(symbol->points[i].y*d);
+	    } else {
+	      newpnt.x = MS_NINT(symbol->points[i].x*d);
+	      newpnt.y = MS_NINT(symbol->points[i].y*d);
+	      gdImageLine(brush, oldpnt.x, oldpnt.y, newpnt.x, newpnt.y, brush_fc);
+	      oldpnt = newpnt;
+	    }
+	  }
+	}
+      }
+
+      symbolset->imagecache = addImageCache(symbolset->imagecache, &symbolset->imagecachesize, style, (int)size, brush);
+    }
+
+    gdImageSetBrush(img, brush);
+    fc = 1; bc = 0;
+    break;
   } /* symbol type end-switch */
 
   if(symbol->patternlength > 0) {
@@ -2370,6 +2596,99 @@
     }
 
     break;
+  case(MS_SYMBOL_SVG):
+    d = size/symbol->sizey; /* compute the scaling factor (d) on the unrotated symbol */
+
+    if (angle != 0.0 && angle != 360.0) {
+      bRotated = MS_TRUE;
+      symbol = msRotateSymbol(symbol, style->angle);
+    }
+
+    x = MS_NINT(symbol->sizex*d)+1;    
+    y = MS_NINT(symbol->sizey*d)+1;
+
+    if((x <= 1) && (y <= 1)) { /* No sense using a tile, just fill solid */
+      if(style->antialias==MS_TRUE) {      
+        imageFilledPolygon(img, p, fc, ox, oy); /* fill is NOT anti-aliased, the outline IS */
+        if(oc>-1)
+          gdImageSetAntiAliased(img, oc);
+        else
+	  gdImageSetAntiAliased(img, fc);
+        imagePolyline(img, p, gdAntiAliased, ox, oy);
+      } else {
+        imageFilledPolygon(img, p, fc, ox, oy);
+        if(oc>-1) imagePolyline(img, p, oc, ox, oy);
+      }      
+      return;
+    }
+
+    if (angle != 0.0 && angle != 360.0) {
+      bRotated = MS_TRUE;
+      symbol = msRotateSymbol(symbol, style->angle);
+    }
+
+    /* create tile image */
+    tile = createBrushFromSVG(img, x, y, style, &tile_fc, &tile_bc);
+   
+    /* draw in the tile image     */
+    if(symbol->filled) {
+
+      k = 0; /* point counter */
+      for(i=0;i < symbol->numpoints;i++) {
+        if((symbol->points[i].x == -99 ) && (symbol->points[i].x == -99)) { /* new polygon (PENUP) */
+          if(k>2) gdImageFilledPolygon(tile, sPoints, k, tile_fc);      
+          k = 0; /* reset point counter */
+        } else {
+  	  sPoints[k].x = MS_NINT(d*symbol->points[i].x);
+	  sPoints[k].y = MS_NINT(d*symbol->points[i].y);
+          k++;
+        }
+      }
+      if(k>2) gdImageFilledPolygon(tile, sPoints, k, tile_fc);      
+
+    } else  { /* shade is a vector drawing */
+      
+      oldpnt.x = MS_NINT(d*symbol->points[0].x); /* convert first point in shade smbol */
+      oldpnt.y = MS_NINT(d*symbol->points[0].y);
+
+      gdImageSetThickness(tile, width);
+
+      /* step through the shade sy */
+      for(i=1;i < symbol->numpoints;i++) {
+	if((symbol->points[i].x != -99) || (symbol->points[i].y != -99)) {
+	  if((symbol->points[i-1].x == -99) && (symbol->points[i-1].y == -99)) { /* Last point was PENUP, now a new beginning */
+	    oldpnt.x = MS_NINT(d*symbol->points[i].x);
+	    oldpnt.y = MS_NINT(d*symbol->points[i].y);
+	  } else {
+	    newpnt.x = MS_NINT(d*symbol->points[i].x);
+	    newpnt.y = MS_NINT(d*symbol->points[i].y);
+	    gdImageLine(tile, oldpnt.x, oldpnt.y, newpnt.x, newpnt.y, tile_fc);
+	    oldpnt = newpnt;
+	  }
+	}
+      } /* end for loop */
+
+      gdImageSetThickness(tile, 1);
+    }
+
+    /* Fill the polygon in the main image */
+    gdImageSetTile(img, tile);
+    imageFilledPolygon(img, p, gdTiled, ox, oy);
+
+    if(style->antialias==MS_TRUE && oc>-1) { 
+      gdImageSetAntiAliased(img, oc);     
+      imagePolyline(img, p, gdAntiAliased, ox, oy);
+    } else
+      if(oc>-1) imagePolyline(img, p, oc, ox, oy);
+
+    gdImageDestroy(tile);
+
+    if(bRotated) { /* free the rotated symbol */
+      msFreeSymbol(symbol);
+      msFree(symbol);
+    }
+
+    break;
   default:
     break;
   }



More information about the mapserver-commits mailing list