[mapserver-commits] r13189 - sandbox/tb-labels

svn at osgeo.org svn at osgeo.org
Thu Mar 1 05:27:49 EST 2012


Author: tbonfort
Date: 2012-03-01 02:27:49 -0800 (Thu, 01 Mar 2012)
New Revision: 13189

Modified:
   sandbox/tb-labels/mapdraw.c
   sandbox/tb-labels/maplabel.c
   sandbox/tb-labels/maplegend.c
   sandbox/tb-labels/mapserver.h
   sandbox/tb-labels/maputil.c
Log:
move transformLabelText to msShapeGetAnnotation
avoid leak on new marker poly computation code


Modified: sandbox/tb-labels/mapdraw.c
===================================================================
--- sandbox/tb-labels/mapdraw.c	2012-03-01 09:04:34 UTC (rev 13188)
+++ sandbox/tb-labels/mapdraw.c	2012-03-01 10:27:49 UTC (rev 13189)
@@ -1597,15 +1597,6 @@
   if(msBindLayerToShape(layer, shape, querymapMode) != MS_SUCCESS)
     return MS_FAILURE; /* error message is set in msBindLayerToShape() */
   
-  /* RFC77 TODO: could this step be done in msShapeGetAnnotation()? */
-  for(i=0; i<layer->class[c]->numlabels; i++) {
-    if(layer->class[c]->labels[i]->annotext && (layer->class[c]->labels[i]->encoding || layer->class[c]->labels[i]->wrap || layer->class[c]->labels[i]->maxlength)) {
-      char *newtext = msTransformLabelText(map ,image, layer->class[c]->labels[i], layer->class[c]->labels[i]->annotext);
-      free(layer->class[c]->labels[i]->annotext);
-      layer->class[c]->labels[i]->annotext = newtext;
-    }
-  }
-
   switch(layer->type) {
   case MS_LAYER_CIRCLE:
     if(shape->numlines != 1) return(MS_SUCCESS); /* invalid shape */
@@ -2189,7 +2180,7 @@
     
     msFree(label->annotext); /* free any previously allocated annotation text */
     if(labeltext && (label->encoding || label->wrap || label->maxlength))
-      label->annotext = msTransformLabelText(map,image,label,labeltext); /* apply wrap character and encoding to the label text */
+      label->annotext = msTransformLabelText(map,label,labeltext); /* apply wrap character and encoding to the label text */
     else
       label->annotext = msStrdup(labeltext);
   }
@@ -2677,27 +2668,27 @@
          symbolObj *symbol = map->symbolset.symbol[style->symbol];
          if(msGetMarkerSize(&map->symbolset, style, &sx, &sy, layerPtr->scalefactor) != MS_SUCCESS)
             return MS_FAILURE;
-         lineObj *line = msSmallMalloc(sizeof(lineObj));
-         line->point = msSmallMalloc(5*sizeof(pointObj));
-         line->numpoints = 5;
-         line->point[0].x = sx / 2.0;
-         line->point[0].y = sy / 2.0;
-         line->point[1].x =  line->point[0].x;
-         line->point[1].y = -line->point[0].y;
-         line->point[2].x = -line->point[0].x;
-         line->point[2].y = -line->point[0].y;
-         line->point[3].x = -line->point[0].x;
-         line->point[3].y =  line->point[0].y;
-         line->point[4].x =  line->point[0].x;
-         line->point[4].y =  line->point[0].y;
+         lineObj line;
+         line.point = msSmallMalloc(5*sizeof(pointObj));
+         line.numpoints = 5;
+         line.point[0].x = sx / 2.0;
+         line.point[0].y = sy / 2.0;
+         line.point[1].x =  line.point[0].x;
+         line.point[1].y = -line.point[0].y;
+         line.point[2].x = -line.point[0].x;
+         line.point[2].y = -line.point[0].y;
+         line.point[3].x = -line.point[0].x;
+         line.point[3].y =  line.point[0].y;
+         line.point[4].x =  line.point[0].x;
+         line.point[4].y =  line.point[0].y;
          int p;
          double aox,aoy;
          if(symbol->anchorpoint_x != 0.5 || symbol->anchorpoint_y != 0.5) {
             aox = (0.5 - symbol->anchorpoint_x) * sx;
             aoy = (0.5 - symbol->anchorpoint_y) * sy;
             for(p=0;p<5;p++) {
-               line->point[p].x += aox;
-               line->point[p].y += aoy;
+               line.point[p].x += aox;
+               line.point[p].y += aoy;
             }
          }
          if(style->angle) {
@@ -2705,18 +2696,18 @@
             double sina = sin(rot);
             double cosa = cos(rot);
             for(p=0;p<5;p++) {
-               double tmpx = line->point[p].x;
-               line->point[p].x = line->point[p].x * cosa - line->point[p].y * sina;
-               line->point[p].y = tmpx * sina + line->point[p].y * cosa;
+               double tmpx = line.point[p].x;
+               line.point[p].x = line.point[p].x * cosa - line.point[p].y * sina;
+               line.point[p].y = tmpx * sina + line.point[p].y * cosa;
             }
          }
          aox = cachePtr->point.x + style->offsetx * layerPtr->scalefactor;
          aoy = cachePtr->point.y + style->offsety * layerPtr->scalefactor;
          for(p=0;p<5;p++) {
-               line->point[p].x += aox;
-               line->point[p].y += aoy;
+               line.point[p].x += aox;
+               line.point[p].y += aoy;
          }
-         msAddLineDirectly(markerPoly,line);
+         msAddLineDirectly(markerPoly,&line);
          msComputeBounds(markerPoly);
          break;
       }

Modified: sandbox/tb-labels/maplabel.c
===================================================================
--- sandbox/tb-labels/maplabel.c	2012-03-01 09:04:34 UTC (rev 13188)
+++ sandbox/tb-labels/maplabel.c	2012-03-01 10:27:49 UTC (rev 13189)
@@ -159,7 +159,7 @@
     }
 }
 
-char *msAlignText(mapObj *map, imageObj *image, labelObj *label, char *text) {
+char *msAlignText(mapObj *map, labelObj *label, char *text) {
     double spacewidth=0.0; /*size of a single space, in fractional pixels*/
     int numlines;
     char **textlines,*newtext,*newtextptr;
@@ -284,7 +284,7 @@
  * Note: it is the caller's responsibility to free the returned 
  * char array
  */
-char *msTransformLabelText(mapObj *map, imageObj* image,labelObj *label, char *text)
+char *msTransformLabelText(mapObj *map, labelObj *label, char *text)
 {
     char *newtext = text;
     if(label->encoding)
@@ -297,7 +297,7 @@
     }
 
     if(newtext && label->align!=MS_ALIGN_LEFT ) {
-        newtext = msAlignText(map, image,label, newtext);
+        newtext = msAlignText(map, label, newtext);
     }
 
     return newtext;

Modified: sandbox/tb-labels/maplegend.c
===================================================================
--- sandbox/tb-labels/maplegend.c	2012-03-01 09:04:34 UTC (rev 13188)
+++ sandbox/tb-labels/maplegend.c	2012-03-01 10:27:49 UTC (rev 13189)
@@ -411,7 +411,7 @@
         * same as the class name pointer
         */
        if(map->legend.label.encoding || map->legend.label.wrap)
-         transformedText = msTransformLabelText(map,NULL,&map->legend.label, text);
+         transformedText = msTransformLabelText(map,&map->legend.label, text);
        else
          transformedText = msStrdup(text);
 
@@ -521,7 +521,7 @@
        * same as the class name pointer
        */
       if(map->legend.label.encoding || map->legend.label.wrap)
-        cur->transformedText = msTransformLabelText(map,NULL,&map->legend.label,text);
+        cur->transformedText = msTransformLabelText(map,&map->legend.label,text);
       else
         cur->transformedText = msStrdup(text); /* so we can always do msFree() when cleaning up */
 

Modified: sandbox/tb-labels/mapserver.h
===================================================================
--- sandbox/tb-labels/mapserver.h	2012-03-01 09:04:34 UTC (rev 13188)
+++ sandbox/tb-labels/mapserver.h	2012-03-01 10:27:49 UTC (rev 13189)
@@ -2029,7 +2029,7 @@
 MS_DLL_EXPORT char *msFontsetLookupFont(fontSetObj *fontset, char *fontKey);
 MS_DLL_EXPORT int msFontsetLookupFonts(char* fontstring, int *numfonts, fontSetObj *fontset, char **lookedUpFonts);
 
-MS_DLL_EXPORT char *msTransformLabelText(mapObj *map, imageObj* image, labelObj *label, char *text);
+MS_DLL_EXPORT char *msTransformLabelText(mapObj *map, labelObj *label, char *text);
 MS_DLL_EXPORT int msGetTruetypeTextBBox(rendererVTableObj *renderer, char* fontstring, fontSetObj *fontset, double size, char *string, rectObj *rect, double **advances);
 
 MS_DLL_EXPORT int msGetLabelSize(mapObj *map, labelObj *label, char *string, double size, rectObj *rect, double **advances);

Modified: sandbox/tb-labels/maputil.c
===================================================================
--- sandbox/tb-labels/maputil.c	2012-03-01 09:04:34 UTC (rev 13188)
+++ sandbox/tb-labels/maputil.c	2012-03-01 10:27:49 UTC (rev 13189)
@@ -658,36 +658,43 @@
 
   i = shape->classindex;
   for(j=0; j<layer->class[i]->numlabels; j++) {
+     labelObj *lbl = layer->class[i]->labels[j]; /* shortcut */
 
-    layer->class[i]->labels[j]->status = MS_ON;
+    lbl->status = MS_ON;
     if(layer->map->scaledenom > 0) {
-      if((layer->class[i]->labels[j]->maxscaledenom != -1) && (layer->map->scaledenom >= layer->class[i]->labels[j]->maxscaledenom)) {
-        layer->class[i]->labels[j]->status = MS_OFF;
+      if((lbl->maxscaledenom != -1) && (layer->map->scaledenom >= lbl->maxscaledenom)) {
+        lbl->status = MS_OFF;
         continue; /* next label */
       }
-      if((layer->class[i]->labels[j]->minscaledenom != -1) && (layer->map->scaledenom < layer->class[i]->labels[j]->minscaledenom)) {
-        layer->class[i]->labels[j]->status = MS_OFF;
+      if((lbl->minscaledenom != -1) && (layer->map->scaledenom < lbl->minscaledenom)) {
+        lbl->status = MS_OFF;
         continue; /* next label */
       }
     }
-    if(msEvalExpression(layer, shape, &(layer->class[i]->labels[j]->expression), -1) != MS_TRUE) {
-      layer->class[i]->labels[j]->status = MS_OFF;
+    if(msEvalExpression(layer, shape, &(lbl->expression), -1) != MS_TRUE) {
+      lbl->status = MS_OFF;
       continue; /* next label */
     }
 
-    msFree(layer->class[i]->labels[j]->annotext);
-    layer->class[i]->labels[j]->annotext = NULL;
+    msFree(lbl->annotext);
+    lbl->annotext = NULL;
 
-    if(layer->class[i]->labels[j]->text.string) {    
-      layer->class[i]->labels[j]->annotext = evalTextExpression(&(layer->class[i]->labels[j]->text), shape);
+    if(lbl->text.string) {    
+      lbl->annotext = evalTextExpression(&(lbl->text), shape);
     } else if(layer->class[i]->text.string) {
-      layer->class[i]->labels[j]->annotext = evalTextExpression(&(layer->class[i]->text), shape);
+      lbl->annotext = evalTextExpression(&(layer->class[i]->text), shape);
     } else {
       if (shape->values && layer->labelitemindex >= 0 && shape->values[layer->labelitemindex] && strlen(shape->values[layer->labelitemindex]) )
-        layer->class[i]->labels[j]->annotext = msStrdup(shape->values[layer->labelitemindex]);
+        lbl->annotext = msStrdup(shape->values[layer->labelitemindex]);
       else if(shape->text)
-        layer->class[i]->labels[j]->annotext = msStrdup(shape->text); /* last resort but common with iniline features */
+        lbl->annotext = msStrdup(shape->text); /* last resort but common with iniline features */
     }
+
+    if(lbl->annotext && (lbl->encoding || lbl->wrap || lbl->maxlength)) {
+       char *newtext = msTransformLabelText(layer->map , lbl, lbl->annotext);
+       free(lbl->annotext);
+       lbl->annotext = newtext;
+    }
   }
 
   return MS_SUCCESS;



More information about the mapserver-commits mailing list