[mapserver-commits] r7846 - trunk/mapserver

svn at osgeo.org svn at osgeo.org
Thu Aug 14 00:30:10 EDT 2008


Author: sdlime
Date: 2008-08-14 00:30:09 -0400 (Thu, 14 Aug 2008)
New Revision: 7846

Modified:
   trunk/mapserver/mapdraw.c
   trunk/mapserver/maplegend.c
   trunk/mapserver/mapserver.h
Log:
Fixed msDrawLabel() to draw background effects (background and background shadow) if defined. Note the parameters for msDrawLabel() have changed. (#2705)

Modified: trunk/mapserver/mapdraw.c
===================================================================
--- trunk/mapserver/mapdraw.c	2008-08-13 13:57:24 UTC (rev 7845)
+++ trunk/mapserver/mapdraw.c	2008-08-14 04:30:09 UTC (rev 7846)
@@ -1466,8 +1466,7 @@
               for(s=0; s<layer->class[c]->numstyles; s++)
                 msDrawMarkerSymbol(&map->symbolset, image, &annopnt, (layer->class[c]->styles[s]), layer->scalefactor);
 	    }
-	    msDrawLabel(image, annopnt, shape->text, &label, &map->fontset, layer->scalefactor);
-
+	    msDrawLabel(map, image, annopnt, shape->text, &label, layer->scalefactor);
           }
 	}
       }
@@ -1503,7 +1502,7 @@
             for(s=0; s<layer->class[c]->numstyles; s++)
 	      msDrawMarkerSymbol(&map->symbolset, image, &annopnt, (layer->class[c]->styles[s]), layer->scalefactor);
 	  }
-	  msDrawLabel(image, annopnt, shape->text, &label, &map->fontset, layer->scalefactor);
+	  msDrawLabel(map, image, annopnt, shape->text, &label, layer->scalefactor);
         }
       }
       break;
@@ -1532,7 +1531,7 @@
                 for(s=0; s<layer->class[c]->numstyles; s++)
 	          msDrawMarkerSymbol(&map->symbolset, image, point, (layer->class[c]->styles[s]), layer->scalefactor);
 	      }
-	      msDrawLabel(image, *point, shape->text, &label, &map->fontset, layer->scalefactor);
+	      msDrawLabel(map, image, *point, shape->text, &label, layer->scalefactor);
 	    }
 	  }
 	}
@@ -1572,7 +1571,7 @@
 	  if(layer->labelcache) {
 	    if(msAddLabel(map, layer->index, c, shape->index, shape->tileindex, point, NULL, shape->text, -1, &label) != MS_SUCCESS) return(MS_FAILURE);
 	  } else
-	    msDrawLabel(image, *point, shape->text, &label, &map->fontset, layer->scalefactor);
+	    msDrawLabel(map, image, *point, shape->text, &label, layer->scalefactor);
 	}
       }
     }
@@ -1664,7 +1663,7 @@
 	if(layer->labelcache) {
             if(msAddLabel(map, layer->index, c, shape->index, shape->tileindex, &annopnt, NULL, shape->text, length, &label) != MS_SUCCESS) return(MS_FAILURE);
 	} else
-          msDrawLabel(image, annopnt, shape->text, &label, &map->fontset, layer->scalefactor);
+          msDrawLabel(map, image, annopnt, shape->text, &label, layer->scalefactor);
       }
     }
     }
@@ -1730,7 +1729,7 @@
 	if(layer->labelcache) {
 	  if(msAddLabel(map, layer->index, c, shape->index, shape->tileindex, &annopnt, NULL, shape->text, MS_MIN(shape->bounds.maxx-shape->bounds.minx,shape->bounds.maxy-shape->bounds.miny), &label) != MS_SUCCESS) return(MS_FAILURE);
 	} else
-	  msDrawLabel(image, annopnt, shape->text, &label, &map->fontset, layer->scalefactor);
+	  msDrawLabel(map, image, annopnt, shape->text, &label, layer->scalefactor);
       }
     }
     break;
@@ -1784,7 +1783,7 @@
           for(s=0; s<theclass->numstyles; s++)
   	    msDrawMarkerSymbol(&map->symbolset, image, point, (theclass->styles[s]), layer->scalefactor);
 	}
-	msDrawLabel(image, *point, newtext, label, &map->fontset, layer->scalefactor);
+	msDrawLabel(map, image, *point, newtext, label, layer->scalefactor);
       }
     }
     break;
@@ -1804,7 +1803,7 @@
       if(layer->labelcache) {
         if(msAddLabel(map, layer->index, classindex, -1, -1, point, NULL, newtext, -1,NULL) != MS_SUCCESS) return(MS_FAILURE);
       } else
-	msDrawLabel(image, *point, newtext, label, &map->fontset, layer->scalefactor);
+	msDrawLabel(map, image, *point, newtext, label, layer->scalefactor);
     }
     break;
   default:
@@ -1942,98 +1941,141 @@
     }
 }
 
-int msDrawLabel(imageObj *image, pointObj labelPnt, char *string, 
-                labelObj *label, fontSetObj *fontset, double scalefactor)
+/*
+** Draws a single label independently of the label cache. No collision avoidance is performed.
+*/
+int msDrawLabel(mapObj *map, imageObj *image, pointObj labelPnt, char *string, labelObj *label, double scalefactor)
 {
+  shapeObj billboard;
+  lineObj billboard_line;
+  pointObj billboard_points[5];
+
+  rectObj r;
+
+  styleObj style;
+
   if(!string)
     return(0); /* not an error, just don't want to do anything */
 
   if(strlen(string) == 0)
     return(0); /* not an error, just don't want to do anything */
 
-
-/* ======================================================================= */
-/*      TODO : This is a temporary hack to call the drawlableswf directly. */
-/*      Normally the only functions that should be wrapped here is         */
-/*      draw_text. We did this since msGetLabelSize has not yet been       */
-/*      implemented for MING FDB fonts.                                    */
-/* ======================================================================= */
-
+  /* ======================================================================= */
+  /*      TODO : This is a temporary hack to call the drawlableswf directly. */
+  /*      Normally the only functions that should be wrapped here is         */
+  /*      draw_text. We did this since msGetLabelSize has not yet been       */
+  /*      implemented for MING FDB fonts.                                    */
+  /* ======================================================================= */
 #ifdef USE_MING_FLASH
   if ( MS_RENDERER_SWF(image->format) )
-      return msDrawLabelSWF(image, labelPnt, string, label, fontset, scalefactor);
+    return msDrawLabelSWF(image, labelPnt, string, label, &(map->fontset), scalefactor);
 #endif
-  
-  
- if(label->position != MS_XY) {
+
+  /* initialize a few things for handling a background */
+  if(MS_VALID_COLOR(label->backgroundcolor)) {
+    billboard.numlines = 1;
+    billboard.line = &billboard_line;
+    billboard.line->numpoints = 5;
+    billboard.line->point = billboard_points;
+    initStyle(&style);
+  }
+
+  if(msGetLabelSize(image, string, label, &r, &(map->fontset), scalefactor, MS_FALSE) == -1) return(-1);
+
+  if(label->position != MS_XY) {
     pointObj p;
-    rectObj r;
 
-    if(msGetLabelSize(image,string, label, &r, fontset, scalefactor, MS_FALSE) == -1) return(-1);
-    p = get_metrics(&labelPnt, label->position, r, label->offsetx, label->offsety, label->angle, 0, NULL);
-    msDrawText(image, p, string, label, fontset, scalefactor); /* actually draw the label */
+    if(MS_VALID_COLOR(label->backgroundcolor)) {
+      p = get_metrics_line(&labelPnt, label->position, r, label->offsetx, label->offsety, label->angle, 1, billboard.line);
+
+      /* draw the background and background shadow (if necessary) */
+      if(MS_VALID_COLOR(label->backgroundshadowcolor)) {
+	MS_COPYCOLOR(&(style.color), &(label->backgroundshadowcolor));
+	style.offsetx = label->backgroundshadowsizex;
+	style.offsety = label->backgroundshadowsizey;
+	msDrawShadeSymbol(&(map->symbolset), image, &billboard, &style, 1);
+	style.offsetx = 0;
+	style.offsety = 0;
+      }
+      MS_COPYCOLOR(&(style.color), &(label->backgroundcolor));
+      msDrawShadeSymbol(&(map->symbolset), image, &billboard, &style, 1);
+    } else
+      p = get_metrics_line(&labelPnt, label->position, r, label->offsetx, label->offsety, label->angle, 0, NULL);
+
+    /* draw the label text */
+    msDrawText(image, p, string, label, &(map->fontset), scalefactor); /* actually draw the label */
   } else {
     labelPnt.x += label->offsetx;
     labelPnt.y += label->offsety;
-    msDrawText(image, labelPnt, string, label, fontset, scalefactor); /* actually draw the label */
+
+    if(MS_VALID_COLOR(label->backgroundcolor)) {
+      get_metrics_line(&labelPnt, label->position, r, label->offsetx, label->offsety, label->angle, 1, billboard.line);
+
+      /* draw the background and background shadow (if necessary) */
+      if(MS_VALID_COLOR(label->backgroundshadowcolor)) {
+        MS_COPYCOLOR(&(style.color), &(label->backgroundshadowcolor));
+        style.offsetx = label->backgroundshadowsizex;
+        style.offsety = label->backgroundshadowsizey;
+        msDrawShadeSymbol(&(map->symbolset), image, &billboard, &style, 1);
+        style.offsetx = 0;
+        style.offsety = 0;
+      }
+      MS_COPYCOLOR(&(style.color), &(label->backgroundcolor));
+      msDrawShadeSymbol(&(map->symbolset), image, &billboard, &style, 1);
+    }
+
+    /* draw the label text */
+    msDrawText(image, labelPnt, string, label, &(map->fontset), scalefactor); /* actually draw the label */
   }
 
   return(0);
 }
 
-
+/*
+** Render the text (no background effects) for a label.
+*/ 
 int msDrawText(imageObj *image, pointObj labelPnt, char *string, labelObj *label, fontSetObj *fontset, double scalefactor)
 {
-    int nReturnVal = -1;
+  int nReturnVal = -1;
 
-    if (image)
-    {
-        if( MS_RENDERER_GD(image->format) )
-            nReturnVal = msDrawTextGD(image->img.gd, labelPnt, string, 
-                                     label, fontset, scalefactor);
+  if (image) {
+    if( MS_RENDERER_GD(image->format) )
+      nReturnVal = msDrawTextGD(image->img.gd, labelPnt, string, label, fontset, scalefactor);
 #ifdef USE_AGG
-        else if( MS_RENDERER_AGG(image->format) )
-            nReturnVal = msDrawTextAGG(image, labelPnt, string, 
-                                     label, fontset, scalefactor);
+    else if( MS_RENDERER_AGG(image->format) )
+      nReturnVal = msDrawTextAGG(image, labelPnt, string, label, fontset, scalefactor);
 #endif
-	else if( MS_RENDERER_IMAGEMAP(image->format) )
-            nReturnVal = msDrawTextIM(image, labelPnt, string, 
-                                     label, fontset, scalefactor);
+    else if( MS_RENDERER_IMAGEMAP(image->format) )
+      nReturnVal = msDrawTextIM(image, labelPnt, string, label, fontset, scalefactor);
 #ifdef USE_MING_FLASH
-        else if( MS_RENDERER_SWF(image->format) )
-            nReturnVal = draw_textSWF(image, labelPnt, string, label, 
-                                      fontset, scalefactor); 
+    else if( MS_RENDERER_SWF(image->format) )
+      nReturnVal = draw_textSWF(image, labelPnt, string, label, fontset, scalefactor); 
 #endif
 #ifdef USE_PDF
-        else if( MS_RENDERER_PDF(image->format) )
-            nReturnVal = msDrawTextPDF(image, labelPnt, string, label, 
-                                      fontset, scalefactor); 
+    else if( MS_RENDERER_PDF(image->format) )
+      nReturnVal = msDrawTextPDF(image, labelPnt, string, label, fontset, scalefactor); 
 #endif
-        else if( MS_RENDERER_SVG(image->format) )
-            nReturnVal = msDrawTextSVG(image, labelPnt, string, label, 
-                                      fontset, scalefactor); 
-    }
+    else if( MS_RENDERER_SVG(image->format) )
+      nReturnVal = msDrawTextSVG(image, labelPnt, string, label, fontset, scalefactor); 
+  }
 
-    return nReturnVal;
+  return nReturnVal;
 }
 
 int msDrawTextLine(imageObj *image, char *string, labelObj *label, labelPathObj *labelpath, fontSetObj *fontset, double scalefactor) 
 {
-    int nReturnVal = -1;
+  int nReturnVal = -1;
 
-    if (image)
-    {
-        if( MS_RENDERER_GD(image->format) )
-            nReturnVal = msDrawTextLineGD(image->img.gd, string, 
-                    label, labelpath, fontset, scalefactor);
+  if(image) {
+    if( MS_RENDERER_GD(image->format) )
+      nReturnVal = msDrawTextLineGD(image->img.gd, string, label, labelpath, fontset, scalefactor);
 #ifdef USE_AGG
-        else if( MS_RENDERER_AGG(image->format) )
-            nReturnVal = msDrawTextLineAGG(image, string, 
-                    label, labelpath, fontset, scalefactor);
+    else if( MS_RENDERER_AGG(image->format) )
+      nReturnVal = msDrawTextLineAGG(image, string, label, labelpath, fontset, scalefactor);
 #endif
-    }
+  }
 
-    return nReturnVal;
+  return nReturnVal;
 }
 
 int msDrawLabelCache(imageObj *image, mapObj *map)
@@ -2045,9 +2087,11 @@
       int i, l, priority;
       int oldAlphaBlending=0;
       rectObj r;
+
       shapeObj billboard;
       lineObj billboard_line;
       pointObj billboard_points[5];
+
       labelCacheMemberObj *cachePtr=NULL;
       layerObj *layerPtr=NULL;
       labelObj *labelPtr=NULL;
@@ -2067,7 +2111,7 @@
         oldAlphaBlending = image->img.gd->alphaBlendingFlag;
         gdImageAlphaBlending( image->img.gd, 1);
       }
-            
+
       billboard.numlines = 1;
       billboard.line = &billboard_line;
       billboard.line->numpoints = 5;

Modified: trunk/mapserver/maplegend.c
===================================================================
--- trunk/mapserver/maplegend.c	2008-08-13 13:57:24 UTC (rev 7845)
+++ trunk/mapserver/maplegend.c	2008-08-14 04:30:09 UTC (rev 7846)
@@ -366,7 +366,7 @@
  
     /* TODO: note tbonfort: if this todo concerned treating the individual heights of the legend labels, then this is now done */
 
-    msDrawLabel(image, pnt, cur->transformedText, &(map->legend.label), &map->fontset, 1.0);
+    msDrawLabel(map, image, pnt, cur->transformedText, &(map->legend.label), 1.0);
     if(offset) {
       /* if we had multiple lines, adjust the current position so it points to the bottom of the current label */
       pnt.y += cur->height-offset;

Modified: trunk/mapserver/mapserver.h
===================================================================
--- trunk/mapserver/mapserver.h	2008-08-13 13:57:24 UTC (rev 7845)
+++ trunk/mapserver/mapserver.h	2008-08-14 04:30:09 UTC (rev 7846)
@@ -1838,7 +1838,7 @@
 MS_DLL_EXPORT void msDrawLineSymbol(symbolSetObj *symbolset, imageObj *image, shapeObj *p, styleObj *style, double scalefactor);
 MS_DLL_EXPORT void msDrawShadeSymbol(symbolSetObj *symbolset, imageObj *image, shapeObj *p, styleObj *style, double scalefactor);
 
-MS_DLL_EXPORT int msDrawLabel(imageObj *image, pointObj labelPnt, char *string, labelObj *label, fontSetObj *fontset, double scalefactor);
+MS_DLL_EXPORT int msDrawLabel(mapObj *map, imageObj *image, pointObj labelPnt, char *string, labelObj *label, double scalefactor);
 MS_DLL_EXPORT int msDrawText(imageObj *image, pointObj labelPnt, char *string, labelObj *label, fontSetObj *fontset, double scalefactor);
 MS_DLL_EXPORT int msDrawTextLine(imageObj *image, char *string, labelObj *label, labelPathObj *labelpath, fontSetObj *fontset, double scalefactor);
 MS_DLL_EXPORT int msDrawLabelCache(imageObj *image, mapObj *map);



More information about the mapserver-commits mailing list