[mapserver-commits] r8793 - sandbox/graphics

svn at osgeo.org svn at osgeo.org
Sat Mar 14 04:55:20 EDT 2009


Author: tbonfort
Date: 2009-03-14 04:55:20 -0400 (Sat, 14 Mar 2009)
New Revision: 8793

Modified:
   sandbox/graphics/mapdraw.c
Log:
more formatting fixups :(


Modified: sandbox/graphics/mapdraw.c
===================================================================
--- sandbox/graphics/mapdraw.c	2009-03-14 08:47:01 UTC (rev 8792)
+++ sandbox/graphics/mapdraw.c	2009-03-14 08:55:20 UTC (rev 8793)
@@ -931,7 +931,8 @@
     }
   
     cache = MS_FALSE;
-    if(layer->type == MS_LAYER_LINE && (layer->class[shape.classindex]->numstyles > 1||layer->class[shape.classindex]->styles[0]->outlinewidth>0))
+    if(layer->type == MS_LAYER_LINE && (layer->class[shape.classindex]->numstyles > 1 || 
+        (layer->class[shape.classindex]->numstyles == 1 && layer->class[shape.classindex]->styles[0]->outlinewidth>0)))
       cache = MS_TRUE; /* only line layers with multiple styles need be cached (I don't think POLYLINE layers need caching - SDL) */
          
     /* With 'STYLEITEM AUTO', we will have the datasource fill the class' */
@@ -949,35 +950,51 @@
     if(annotate && (layer->class[shape.classindex]->text.string || layer->labelitem) && layer->class[shape.classindex]->label.size != -1)
       shape.text = msShapeGetAnnotation(layer, &shape);
 
-    if(cache) {
+    if (cache) {
         int i;
-        for(i=0;i<layer->class[shape.classindex]->numstyles;i++) {
-            if(layer->class[shape.classindex]->styles[i]->outlinewidth>0) {
-                colorObj tmp;
-                styleObj *styleTmp = layer->class[shape.classindex]->styles[i];
-                //msDebug("layer width before:%f\n",styleTmp->width);
-                styleTmp->width+=styleTmp->outlinewidth/layer->scalefactor*2;
-                //msDebug("layer width after:%f\n",styleTmp->width);
-                styleTmp->minwidth+=styleTmp->outlinewidth*2;
-                styleTmp->maxwidth+=styleTmp->outlinewidth*2;
-                tmp = styleTmp->color;
-                styleTmp->color=styleTmp->outlinecolor;
-                styleTmp->outlinecolor=tmp;
-                //layer->class[shape.classindex]->styles[i]->width+=layer->class[shape.classindex]->styles[i]->outlinewidth;
+        for (i = 0; i < layer->class[shape.classindex]->numstyles; i++) {
+            styleObj *pStyle = layer->class[shape.classindex]->styles[i];
+            colorObj tmp;
+            if (pStyle->outlinewidth > 0) {
+                /* 
+                 * RFC 49 implementation
+                 * if an outlinewidth is used:
+                 *  - augment the style's width to account for the outline width
+                 *  - swap the style color and outlinecolor
+                 *  - draw the shape (the outline) in the first pass of the
+                 *    caching mechanism
+                 */
+                
+                /* adapt width (must take scalefactor into account) */
+                pStyle->width += (pStyle->outlinewidth / layer->scalefactor) * 2;
+                pStyle->minwidth += pStyle->outlinewidth * 2;
+                pStyle->maxwidth += pStyle->outlinewidth * 2;
+                
+                /*swap color and outlinecolor*/
+                tmp = pStyle->color;
+                pStyle->color = pStyle->outlinecolor;
+                pStyle->outlinecolor = tmp;
             }
-        }
-        status = msDrawShape(map, layer, &shape, image, 0,MS_TRUE); /* draw only the first style */
-        for(i=0;i<layer->class[shape.classindex]->numstyles;i++) {
-            if(layer->class[shape.classindex]->styles[i]->outlinewidth>0) {
-                colorObj tmp;
-                styleObj *styleTmp = layer->class[shape.classindex]->styles[i];
-                styleTmp->width-=styleTmp->outlinewidth/layer->scalefactor*2;
-                styleTmp->minwidth-=styleTmp->outlinewidth*2;
-                styleTmp->maxwidth-=styleTmp->outlinewidth*2;
-                tmp = styleTmp->color;
-                styleTmp->color=styleTmp->outlinecolor;
-                styleTmp->outlinecolor=tmp;
+            if (i == 0 || pStyle->outlinewidth > 0) {
+                status = msDrawShape(map, layer, &shape, image, i, MS_TRUE); /* draw a single style */
             }
+            if (pStyle->outlinewidth > 0) {
+                /*
+                 * RFC 49 implementation: switch back the styleobj to its
+                 * original state, so the line fill will be drawn in the
+                 * second pass of the caching mechanism
+                 */
+                
+                /* reset widths to original state */
+                pStyle->width -= (pStyle->outlinewidth / layer->scalefactor) * 2;
+                pStyle->minwidth -= pStyle->outlinewidth * 2;
+                pStyle->maxwidth -= pStyle->outlinewidth * 2;
+                
+                /*reswap colors to original state*/
+                tmp = pStyle->color;
+                pStyle->color = pStyle->outlinecolor;
+                pStyle->outlinecolor = tmp;
+            }
         }
     }
 
@@ -1018,19 +1035,19 @@
     for(s=0; s<maxnumstyles; s++) {
       for(current=shpcache; current; current=current->next) {
         if(layer->class[current->shape.classindex]->numstyles > s) {
-          styleObj *curStyle = layer->class[current->shape.classindex]->styles[s];
-          if(curStyle->_geomtransform!=MS_GEOMTRANSFORM_NONE)
+          styleObj *pStyle = layer->class[current->shape.classindex]->styles[s];
+          if(pStyle->_geomtransform!=MS_GEOMTRANSFORM_NONE)
         	continue; /*skip this as it has already been rendered*/
           if(map->scaledenom > 0) {
-            if((curStyle->maxscaledenom != -1) && (map->scaledenom >= curStyle->maxscaledenom))
+            if((pStyle->maxscaledenom != -1) && (map->scaledenom >= pStyle->maxscaledenom))
               continue;
-            if((curStyle->minscaledenom != -1) && (map->scaledenom < curStyle->minscaledenom))
+            if((pStyle->minscaledenom != -1) && (map->scaledenom < pStyle->minscaledenom))
               continue;
           }
-          if(s==0 && curStyle->outlinewidth>0 && MS_VALID_COLOR(curStyle->color)) {
-            msDrawLineSymbol(&map->symbolset, image, &current->shape, curStyle, layer->scalefactor);  
+          if(s==0 && pStyle->outlinewidth>0 && MS_VALID_COLOR(pStyle->color)) {
+            msDrawLineSymbol(&map->symbolset, image, &current->shape, pStyle, layer->scalefactor);  
           } else if(s>0)
-            msDrawLineSymbol(&map->symbolset, image, &current->shape, curStyle, layer->scalefactor);
+            msDrawLineSymbol(&map->symbolset, image, &current->shape, pStyle, layer->scalefactor);
         }
       }
     }
@@ -1113,6 +1130,10 @@
 
     for(i=0; i<layer->numclasses; i++) {
       if(layer->type == MS_LAYER_POLYGON) { /* alter BOTTOM style since that's almost always the fill */
+	if (layer->class[i]->styles == NULL) {
+           msSetError(MS_MISCERR, "Don't know how to draw class %s of layer %s without a style definition.", "msDrawQueryLayer()", layer->class[i]->name, layer->name);
+           return(MS_FAILURE);
+	}
         if(MS_VALID_COLOR(layer->class[i]->styles[0]->color)) {
           colorbuffer[i] = layer->class[i]->styles[0]->color; /* save the color from the BOTTOM style */
           layer->class[i]->styles[0]->color = map->querymap.color;
@@ -1441,7 +1462,6 @@
   if(shape->text && (layer->class[c]->label.encoding || layer->class[c]->label.wrap
           ||layer->class[c]->label.maxlength)) {
       char *newtext=msTransformLabelText(map,image,&(layer->class[c]->label),shape->text);
-      //if(!newtext) return MS_FAILURE;
       free(shape->text);
       shape->text = newtext;
   }



More information about the mapserver-commits mailing list