[mapserver-commits] r11793 - trunk/mapserver
svn at osgeo.org
svn at osgeo.org
Tue Jun 7 13:53:41 EDT 2011
Author: tbonfort
Date: 2011-06-07 10:53:41 -0700 (Tue, 07 Jun 2011)
New Revision: 11793
Modified:
trunk/mapserver/HISTORY.TXT
trunk/mapserver/mapagg.cpp
trunk/mapserver/maprendering.c
trunk/mapserver/mapserver.h
Log:
Add support for dashes on polygon hatches
Modified: trunk/mapserver/HISTORY.TXT
===================================================================
--- trunk/mapserver/HISTORY.TXT 2011-06-07 17:25:07 UTC (rev 11792)
+++ trunk/mapserver/HISTORY.TXT 2011-06-07 17:53:41 UTC (rev 11793)
@@ -15,6 +15,8 @@
Current Version (SVN trunk, 6.1-dev, future 6.2):
-------------------------------------------------
+- Add support for dashes on polygon hatches
+
- Union layer 3 new processing options added (#3900)
- Changed msRemoveStyle to allow removing all styles (#3895)
Modified: trunk/mapserver/mapagg.cpp
===================================================================
--- trunk/mapserver/mapagg.cpp 2011-06-07 17:25:07 UTC (rev 11792)
+++ trunk/mapserver/mapagg.cpp 2011-06-07 17:53:41 UTC (rev 11793)
@@ -919,7 +919,7 @@
return path;
}
-int agg2RenderPolygonHatched(imageObj *img, shapeObj *poly, double spacing, double width, double angle, colorObj *color) {
+int agg2RenderPolygonHatched(imageObj *img, shapeObj *poly, double spacing, double width, double *pattern, int patternlength, double angle, colorObj *color) {
msComputeBounds(poly);
@@ -940,9 +940,6 @@
//render the hatch clipped by the shape
- mapserver::conv_stroke <mapserver::path_storage > stroke(hatch);
- stroke.width(width);
- stroke.line_cap(mapserver::butt_cap);
polygon_adaptor polygons(poly);
@@ -954,7 +951,28 @@
mapserver::scanline_storage_aa8 storage2;
mapserver::scanline_p8 sl1,sl2;
ras1.filling_rule(mapserver::fill_non_zero);
- ras1.add_path(stroke);
+
+
+ if(patternlength>1) {
+ //dash the hatch and render it clipped by the shape
+ mapserver::conv_dash<mapserver::path_storage > dash(hatch);
+ mapserver::conv_stroke<mapserver::conv_dash<mapserver::path_storage> > stroke(dash);
+ for (int i=0; i<patternlength; i+=2) {
+ if (i < patternlength-1) {
+ dash.add_dash(pattern[i], pattern[i+1]);
+ }
+ }
+ stroke.width(width);
+ stroke.line_cap(mapserver::butt_cap);
+ ras1.add_path(stroke);
+ } else {
+ //render the hatch clipped by the shape
+ mapserver::conv_stroke <mapserver::path_storage > stroke(hatch);
+ stroke.width(width);
+ stroke.line_cap(mapserver::butt_cap);
+ ras1.add_path(stroke);
+ }
+
mapserver::render_scanlines(ras1, r->sl_line, storage1);
ras2.filling_rule(mapserver::fill_even_odd);
ras2.add_path(polygons);
@@ -966,14 +984,8 @@
}
-int msHatchPolygon(imageObj *img, shapeObj *poly, double spacing, double width, double angle, colorObj *color) {
- assert(MS_RENDERER_PLUGIN(img->format));
- msComputeBounds(poly);
- int pw=(int)(poly->bounds.maxx-poly->bounds.minx+width*2)+1;
- int ph=(int)(poly->bounds.maxy-poly->bounds.miny+width*2)+1;
- mapserver::path_storage lines = createHatch(pw,ph, angle, spacing);
- lines.transform(mapserver::trans_affine_translation(poly->bounds.minx-width,poly->bounds.miny-width));
- polygon_adaptor polygons(poly);
+template<class VertexSource> void renderPolygonHatches(imageObj *img,VertexSource &clipper, colorObj *color) {
+
shapeObj shape;
msInitShape(&shape);
int allocated = 20;
@@ -982,14 +994,6 @@
shape.numlines = 1;
shape.line[0].point = (pointObj*)msSmallCalloc(allocated,sizeof(pointObj));
shape.line[0].numpoints = 0;
- mapserver::conv_stroke<mapserver::path_storage> stroke(lines);
- stroke.width(width);
- stroke.line_cap(mapserver::butt_cap);
- //mapserver::conv_clipper<mapserver::path_storage,polygon_adaptor> clipper(*lines,polygons, mapserver::clipper_and);
- //mapserver::conv_clipper<polygon_adaptor,mapserver::path_storage> clipper(polygons,lines, mapserver::clipper_and);
- mapserver::conv_clipper<polygon_adaptor,mapserver::conv_stroke<mapserver::path_storage> > clipper(polygons,stroke, mapserver::clipper_and);
- clipper.rewind(0);
-
double x=0,y=0;
unsigned int cmd, prevCmd=-1;
while((cmd = clipper.vertex(&x,&y)) != mapserver::path_cmd_stop) {
@@ -1020,6 +1024,44 @@
prevCmd = cmd;
}
free(shape.line[0].point);
+}
+
+int msHatchPolygon(imageObj *img, shapeObj *poly, double spacing, double width, double *pattern, int patternlength, double angle, colorObj *color) {
+ assert(MS_RENDERER_PLUGIN(img->format));
+ msComputeBounds(poly);
+ int pw=(int)(poly->bounds.maxx-poly->bounds.minx+width*2)+1;
+ int ph=(int)(poly->bounds.maxy-poly->bounds.miny+width*2)+1;
+ mapserver::path_storage lines = createHatch(pw,ph, angle, spacing);
+ lines.transform(mapserver::trans_affine_translation(poly->bounds.minx-width,poly->bounds.miny-width));
+ polygon_adaptor polygons(poly);
+
+
+
+ if(patternlength>1) {
+ //dash the hatch and render it clipped by the shape
+ mapserver::conv_dash<mapserver::path_storage > dash(lines);
+ mapserver::conv_stroke<mapserver::conv_dash<mapserver::path_storage> > stroke(dash);
+ for (int i=0; i<patternlength; i+=2) {
+ if (i < patternlength-1) {
+ dash.add_dash(pattern[i], pattern[i+1]);
+ }
+ }
+ stroke.width(width);
+ stroke.line_cap(mapserver::butt_cap);
+ mapserver::conv_clipper<polygon_adaptor,mapserver::conv_stroke<mapserver::conv_dash<mapserver::path_storage> > > clipper(polygons,stroke, mapserver::clipper_and);
+ clipper.rewind(0);
+ renderPolygonHatches(img,clipper,color);
+ } else {
+ //render the hatch clipped by the shape
+ mapserver::conv_stroke <mapserver::path_storage > stroke(lines);
+ stroke.width(width);
+ stroke.line_cap(mapserver::butt_cap);
+ mapserver::conv_clipper<polygon_adaptor,mapserver::conv_stroke<mapserver::path_storage> > clipper(polygons,stroke, mapserver::clipper_and);
+ clipper.rewind(0);
+ renderPolygonHatches(img,clipper,color);
+ }
+
+
//assert(prevCmd == mapserver::path_cmd_line_to);
//delete lines;
return MS_SUCCESS;
Modified: trunk/mapserver/maprendering.c
===================================================================
--- trunk/mapserver/maprendering.c 2011-06-07 17:25:07 UTC (rev 11792)
+++ trunk/mapserver/maprendering.c 2011-06-07 17:53:41 UTC (rev 11793)
@@ -586,6 +586,8 @@
goto cleanup; /*finished plain polygon*/
} else if(symbol->type == MS_SYMBOL_HATCH) {
double width, spacing;
+ double pattern[MS_MAXPATTERNLENGTH];
+ int i;
if(MS_VALID_COLOR(style->backgroundcolor)) {
ret = renderer->renderPolygon(image,offsetPolygon, &style->backgroundcolor);
@@ -597,10 +599,16 @@
spacing = (style->size <= 0)?scalefactor:style->size*scalefactor;
spacing = MS_MIN(spacing, style->maxsize);
spacing = MS_MAX(spacing, style->minsize);
+
+ /* scale the pattern by the factor applied to the width */
+ for(i=0;i<style->patternlength;i++) {
+ pattern[i] = style->pattern[i]*width/style->width;
+ }
+
if(renderer->renderPolygonHatched) {
- ret = renderer->renderPolygonHatched(image,offsetPolygon,spacing,width,style->angle, &style->color);
+ ret = renderer->renderPolygonHatched(image,offsetPolygon,spacing,width,pattern,style->patternlength,style->angle, &style->color);
} else {
- ret = msHatchPolygon(image,offsetPolygon,spacing,width,style->angle, &style->color);
+ ret = msHatchPolygon(image,offsetPolygon,spacing,width,pattern,style->patternlength,style->angle, &style->color);
}
goto cleanup;
}
Modified: trunk/mapserver/mapserver.h
===================================================================
--- trunk/mapserver/mapserver.h 2011-06-07 17:25:07 UTC (rev 11792)
+++ trunk/mapserver/mapserver.h 2011-06-07 17:53:41 UTC (rev 11793)
@@ -2191,7 +2191,7 @@
/* Prototypes for functions in mapgeomutil.cpp */
/* ==================================================================== */
MS_DLL_EXPORT shapeObj *msRasterizeArc(double x0, double y0, double radius, double startAngle, double endAngle, int isSlice);
-MS_DLL_EXPORT int msHatchPolygon(imageObj *img, shapeObj *poly, double spacing, double width, double angle, colorObj *color);
+MS_DLL_EXPORT int msHatchPolygon(imageObj *img, shapeObj *poly, double spacing, double width, double *pattern, int patternlength, double angle, colorObj *color);
@@ -2655,7 +2655,7 @@
int (*renderLine)(imageObj *img, shapeObj *p, strokeStyleObj *style);
int (*renderPolygon)(imageObj *img, shapeObj *p, colorObj *color);
int (*renderPolygonTiled)(imageObj *img, shapeObj *p, imageObj *tile);
- int (*renderPolygonHatched)(imageObj *img, shapeObj *poly, double spacing, double width, double angle, colorObj *color);
+ int (*renderPolygonHatched)(imageObj *img, shapeObj *poly, double spacing, double width, double *pattern, int patternlength, double angle, colorObj *color);
int (*renderLineTiled)(imageObj *img, shapeObj *p, imageObj *tile);
int (*renderBitmapGlyphs)(imageObj *img, double x, double y,
More information about the mapserver-commits
mailing list