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

svn at osgeo.org svn at osgeo.org
Tue Feb 28 10:39:33 EST 2012


Author: tbonfort
Date: 2012-02-28 07:39:33 -0800 (Tue, 28 Feb 2012)
New Revision: 13178

Modified:
   sandbox/tb-labels/mapdraw.c
   sandbox/tb-labels/mapprimitive.c
   sandbox/tb-labels/maprendering.c
   sandbox/tb-labels/mapserver.h
   sandbox/tb-labels/mapstring.c
Log:
woot! refactor labelcache rendering


Modified: sandbox/tb-labels/mapdraw.c
===================================================================
--- sandbox/tb-labels/mapdraw.c	2012-02-28 08:29:37 UTC (rev 13177)
+++ sandbox/tb-labels/mapdraw.c	2012-02-28 15:39:33 UTC (rev 13178)
@@ -2398,7 +2398,6 @@
    labelCacheSlotObj *cacheslot;
    labelCacheMemberObj *cachePtr;
    cacheslot = &(labelcache->slots[priority]);
-   char *value;
    for(l=cacheslot->numlabels-1; l>=0; l--) {
       cachePtr = &(cacheslot->labels[l]); /* point to right spot in the label cache */
       if(cachePtr->status == MS_FALSE && !cachePtr->labelpath) {
@@ -2414,6 +2413,8 @@
                continue;
             }
 
+            /* TODO: check the cachePtr->point doesn't intersect a rendered label before event trying to offset ?*/
+
             /* TODO: if the entry has a single label and it has position != CC, 
              * recompute the cachePtr->poly and labelPtr->annopoint using POSITION CC */
             shapeObj origPoly;
@@ -2597,20 +2598,6 @@
    return retval;
 }
 
-/*
-** Computes a marker rect relative to a point for a class and (potentially) multiple styles.
-*/
-static void getMarkerRect(classObj *class, pointObj *point, rectObj *rect) {
-  int i;
-}
-
-/*
-** Computes the offset for a label position so there is no conflict with the underlying marker.
-*/
-static void getLabelMarkerOffet(rectObj *r, int position, double *offset_x, double *offset_y) {
-
-} 
-
 /* add "to"'s geometry to "from", without unnecessary allocations.
  * the ownership of "from"'s geometry is transfered to "to"
  */
@@ -2619,10 +2606,10 @@
 
   if(!from || !to) return;
 
-  if(to->numlines <= 0) copybounds=1;
   if( to->numlines <= 0 ) {
-      to->line = (lineObj *) msSmallMalloc(from->numlines * sizeof(lineObj));
-      to->numlines = 0;
+     copybounds=1;
+     to->line = (lineObj *) msSmallMalloc(from->numlines * sizeof(lineObj));
+     to->numlines = 0;
   }
   else {
       to->line = (lineObj *) msSmallRealloc(to->line, (to->numlines+from->numlines)*sizeof(lineObj));
@@ -2645,8 +2632,97 @@
      to->bounds.maxx = MS_MAX(to->bounds.maxx,from->bounds.maxx);
      to->bounds.maxy = MS_MAX(to->bounds.maxy,from->bounds.maxy);
   }
+  msFree(from->line);
+  from->line = NULL;
+  from->numlines = 0;
+  from->bounds.minx=from->bounds.miny=from->bounds.maxx=from->bounds.maxy=-1;
 }
 
+
+int computeOldStyleMarkerPoly(mapObj *map, imageObj *image, labelCacheMemberObj *cachePtr, 
+      labelCacheSlotObj *cacheslot, shapeObj *markerPoly) {
+   layerObj *layerPtr = (GET_LAYER(map, cachePtr->layerindex));
+   if(layerPtr->type == MS_LAYER_ANNOTATION && cachePtr->numstyles > 0) {
+      /* TODO: at the moment only checks the bottom (first) marker style since it *should* be the
+         largest, perhaps we should check all of them and build a composite size */
+      double marker_width,marker_height;
+      rectObj marker_rect;
+      if(msGetMarkerSize(&map->symbolset, &(cachePtr->styles[0]), &marker_width, &marker_height, layerPtr->scalefactor) != MS_SUCCESS)
+         return MS_FAILURE;
+
+      marker_rect.minx = (cachePtr->point.x - .5 * marker_width);
+      marker_rect.miny = (cachePtr->point.y - .5 * marker_height);
+      marker_rect.maxx = marker_rect.minx + (marker_width-1);
+      marker_rect.maxy = marker_rect.miny + (marker_height-1); 
+      msRectToPolygon(marker_rect, markerPoly);
+      msComputeBounds(markerPoly);
+   } else if (layerPtr->type == MS_LAYER_POINT && cachePtr->markerid!=-1) { /* there is a marker already in the image that we need to account for */
+      markerCacheMemberObj *markerPtr = &(cacheslot->markers[cachePtr->markerid]); /* point to the right sport in the marker cache (if available) */
+      msRectToPolygon(markerPtr->poly->bounds, markerPoly);
+      msComputeBounds(markerPoly);
+   }
+   return MS_SUCCESS;
+}
+
+int computeLabelMarkerPoly(mapObj *map, imageObj *img, labelCacheMemberObj *cachePtr,
+      labelObj *label, shapeObj *markerPoly) {
+   int i;
+   layerObj *layerPtr = (GET_LAYER(map, cachePtr->layerindex));
+   for (i=0; i<label->numstyles; i++) {
+      styleObj *style = label->styles[i];
+      if(style->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOINT &&
+            style->symbol < map->symbolset.numsymbols && style->symbol > 0) {
+         double sx,sy;
+         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;
+         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;
+            }
+         }
+         if(style->angle) {
+            double rot = -style->angle * MS_DEG_TO_RAD;
+            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;
+            }
+         }
+         for(p=0;p<5;p++) {
+            aox = cachePtr->point.x + style->offsetx * layerPtr->scalefactor;
+            aoy = cachePtr->point.y + style->offsety * layerPtr->scalefactor;
+               line->point[p].x += aox;
+               line->point[p].y += aoy;
+         }
+         msAddLineDirectly(markerPoly,line);
+         msComputeBounds(markerPoly);
+         break;
+      }
+   }
+   return MS_SUCCESS;
+}
+
 int msDrawLabelCache(imageObj *image, mapObj *map)
 {
   int nReturnVal = MS_SUCCESS;
@@ -2658,24 +2734,21 @@
 
       shapeObj poly; /* hold label polygon for one label, cachePtr->poly holds label polygon for the whole group */
       msInitShape(&poly);
-      markerCacheMemberObj *markerPtr=NULL; /* for santity */
       labelCacheMemberObj *cachePtr=NULL;
       layerObj *layerPtr=NULL;
       classObj *classPtr=NULL;
       labelObj *labelPtr=NULL;
+      
+      /* holds the contour of the label styles that correspond to markers */
+      shapeObj markerPoly;
+      msInitShape(&markerPoly);
 
-      double marker_width, marker_height; /* marker is defined in POINT or ANNOTATION layer class styles */
       double marker_offset_x, marker_offset_y;
-      rectObj marker_rect = {0,0,0,0};
  
       int label_offset_x, label_offset_y;
  
-      double label_marker_width, label_marker_height; /* label_marker is defined in label styles */
-      double label_marker_offset_x, label_marker_offset_y;
-      rectObj label_marker_rect = {0,0,0,0};
 
-      int label_mindistance=-1,
-      label_buffer=0, map_edge_buffer=0;
+      int label_mindistance=-1, label_buffer=0;
 
       const char *value;
 
@@ -2696,8 +2769,6 @@
           double scalefactor,size;
           cachePtr = &(cacheslot->labels[l]); /* point to right spot in the label cache */
 
-          markerPtr = NULL;
-          if(cachePtr->markerid != -1) markerPtr = &(cacheslot->markers[cachePtr->markerid]); /* point to the right sport in the marker cache (if available) */
           layerPtr = (GET_LAYER(map, cachePtr->layerindex)); /* set a couple of other pointers, avoids nasty references */
           classPtr = (GET_CLASS(map, cachePtr->layerindex, cachePtr->classindex));
 
@@ -2733,41 +2804,28 @@
 
           } else { /* point-based label */
             shapeObj *tmppoly;
-
+            
             marker_offset_x = marker_offset_y = 0; /* assume no marker */
-            marker_width = marker_height = 0;
-            if(layerPtr->type == MS_LAYER_ANNOTATION && cachePtr->numstyles > 0) {
-              /* TODO: at the moment only checks the bottom (first) marker style since it *should* be the
-                 largest, perhaps we should check all of them and build a composite size */
-              if(msGetMarkerSize(&map->symbolset, &(cachePtr->styles[0]), &marker_width, &marker_height, layerPtr->scalefactor) != MS_SUCCESS)
-                return MS_FAILURE;
-
-              marker_offset_x = (marker_width/2.0);
-              marker_offset_y = (marker_height/2.0);
-   
-              marker_rect.minx = (cachePtr->point.x - .5 * marker_width);
-              marker_rect.miny = (cachePtr->point.y - .5 * marker_height);
-              marker_rect.maxx = marker_rect.minx + (marker_width-1);
-              marker_rect.maxy = marker_rect.miny + (marker_height-1); 
-              msRectToPolygon(marker_rect, cachePtr->poly);
-            } else if (layerPtr->type == MS_LAYER_POINT && markerPtr) { /* there is a marker already in the image that we need to account for */
-              marker_rect = markerPtr->poly->bounds;
-              marker_width = marker_rect.maxx - marker_rect.minx;
-              marker_height = marker_rect.maxy - marker_rect.miny;
-              marker_offset_x = (marker_width/2.0);
-              marker_offset_y = (marker_height/2.0);
-              msRectToPolygon(marker_rect, cachePtr->poly);
+            
+            /* compute label bbox of a marker used in an annotation layer or a point layer with markerPtr */
+            computeOldStyleMarkerPoly(map,image,cachePtr,cacheslot,&markerPoly);
+            if(markerPoly.numlines) {
+               marker_offset_x = (markerPoly.bounds.maxx-markerPoly.bounds.minx)/2;
+               marker_offset_y = (markerPoly.bounds.maxy-markerPoly.bounds.miny)/2;
+               /* add marker to cachePtr->poly */
+               transferLabelShape(&markerPoly, &poly);
             }
 
             /* 
-	    ** all other cases *could* have multiple labels defined 
+            ** all other cases *could* have multiple labels defined 
             */
             cachePtr->status = MS_OFF; /* assume this cache element *can't* be placed */
             for(ll=0; ll<cachePtr->numlabels; ll++) { /* RFC 77 TODO: Still may want to step through backwards... */
               msFreeShape(&poly);
               labelPtr = &(cachePtr->labels[ll]);
               labelPtr->status = MS_OFF;
-
+              
+              /* first check if there's anything to do with this label */
               if(!labelPtr->annotext) {
                  int s;
                  for(s=0;s<labelPtr->numstyles;s++) {
@@ -2781,6 +2839,22 @@
                  }
               }
 
+              /* compute the poly of the label styles */
+              computeLabelMarkerPoly(map,image,cachePtr,labelPtr,&markerPoly);
+              if(markerPoly.numlines) {
+                 if(cachePtr->numlabels > 1) {
+                    marker_offset_x = (markerPoly.bounds.maxx-markerPoly.bounds.minx)/2;
+                    marker_offset_y = (markerPoly.bounds.maxy-markerPoly.bounds.miny)/2;
+                 } else {
+                    /* we might be using an old style behavior with a markerPtr */
+                    marker_offset_x = MS_MAX(marker_offset_x,(markerPoly.bounds.maxx-markerPoly.bounds.minx)/2);
+                    marker_offset_y = MS_MAX(marker_offset_y,(markerPoly.bounds.maxy-markerPoly.bounds.miny)/2);
+                 }
+                 /* add marker to cachePtr->poly */
+                 transferLabelShape(&markerPoly, &poly);
+              }
+
+
               if(labelPtr->annotext) {
                  /* compute label size */
                  if(labelPtr->type == MS_TRUETYPE) {
@@ -2794,20 +2868,27 @@
                  }
                  if(msGetLabelSize(map, labelPtr, labelPtr->annotext, size, &r, NULL) != MS_SUCCESS)
                     return MS_FAILURE;
+                 
+                 if(labelPtr->autominfeaturesize && (cachePtr->featuresize != -1) && ((r.maxx-r.minx) > cachePtr->featuresize)) {
+                    /* label too large relative to the feature */
+                    /* this label cannot be rendered, go on to next cachePtr */
+                    break;
+                    /* TODO: treat the case with multiple labels and/or leader lines */
+                 }
 
                  /* adjust the baseline (see #1449) */
                  if(labelPtr->type == MS_TRUETYPE) {
-                    int nNewlines = msCountChars(labelPtr->annotext,'\n');
-                    if(!nNewlines) {
+                    char *newline = strchr(labelPtr->annotext,'\n');
+                    if(!newline) {
                        labelPtr->offsety += ((((r.miny + r.maxy) + size) / 2.0)/scalefactor);
                        labelPtr->offsetx += ((r.minx / 2)/scalefactor);
                     } else {
                        rectObj rect2; /* bbox of first line only */
-                       char *firstLine = msGetFirstLine(labelPtr->annotext);
-                       msGetLabelSize(map, labelPtr, firstLine, size, &rect2, NULL);
+                       *newline = '\0';
+                       msGetLabelSize(map, labelPtr, labelPtr->annotext, size, &rect2, NULL);
+                       *newline = '\n';
                        labelPtr->offsety += ((((rect2.miny+rect2.maxy) + size) / 2))/scalefactor;
                        labelPtr->offsetx += ((rect2.minx / 2))/scalefactor;
-                       free(firstLine);
                     }
                  }
 
@@ -2816,50 +2897,24 @@
                  label_offset_y = labelPtr->offsety*scalefactor;
                  label_buffer = (labelPtr->buffer*image->resolutionfactor);
                  label_mindistance = (labelPtr->mindistance*image->resolutionfactor);
-
-                 if(labelPtr->autominfeaturesize && (cachePtr->featuresize != -1) && ((r.maxx-r.minx) > cachePtr->featuresize))
-                    continue; /* label too large relative to the feature */
+                 
+                 /* compute the label annopoly  if we need to render the background billboard */
+                 if(labelPtr->numstyles > 0) {
+                    for(i=0; i<labelPtr->numstyles; i++) { 
+                       if(labelPtr->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOLY) {
+                          /* initialize the annotation polygon */
+                          labelPtr->annopoly = (shapeObj *) msSmallMalloc(sizeof(shapeObj));
+                          msInitShape(labelPtr->annopoly);
+                          labelPtr->annopoly->line = (lineObj *) malloc(sizeof(lineObj));
+                          labelPtr->annopoly->numlines = 1;
+                          labelPtr->annopoly->line->point =  (pointObj *) malloc(5*sizeof(pointObj));
+                          labelPtr->annopoly->line->numpoints = 5;
+                          break;
+                       }
+                    }
+                 }
               }
 
-              /* compute settings for label-based styles */
-              label_marker_offset_x = label_marker_offset_y = 0; /* assume no label marker */
-              label_marker_width = label_marker_height = 0;
-              double t_marker_offset_x =0;
-              double t_marker_offset_y = 0;
-              if(labelPtr->numstyles > 0) {
-                for(i=0; i<labelPtr->numstyles; i++) { 
-                  /* TODO: at the moment only checks the bottom (first) label style, perhaps should check all of them */ 
-                  if(labelPtr->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOINT) { 
-                    if(msGetMarkerSize(&map->symbolset, labelPtr->styles[i], &label_marker_width, &label_marker_height, layerPtr->scalefactor) != MS_SUCCESS) 
-                      return MS_FAILURE;
-                    t_marker_offset_x = labelPtr->styles[i]->offsetx;
-                    t_marker_offset_y = labelPtr->styles[i]->offsety;
-                    break; 
-                  }
-                }
-                
-                for(i=0; i<labelPtr->numstyles; i++) { 
-                  if(labelPtr->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOLY) {
-                    /* initialize the annotation polygon */
-                    labelPtr->annopoly = (shapeObj *) msSmallMalloc(sizeof(shapeObj));
-                    msInitShape(labelPtr->annopoly);
-                    labelPtr->annopoly->line = (lineObj *) malloc(sizeof(lineObj));
-                    labelPtr->annopoly->numlines = 1;
-                    labelPtr->annopoly->line->point =  (pointObj *) malloc(5*sizeof(pointObj));
-                    labelPtr->annopoly->line->numpoints = 5;
-                    break;
-                  }
-                }
-
-                label_marker_offset_x = (label_marker_width/2.0); 
-                label_marker_offset_y = (label_marker_height/2.0); 
- 
-                label_marker_rect.minx = (cachePtr->point.x - label_marker_offset_x + t_marker_offset_x ) - labelPtr->buffer; 
-                label_marker_rect.miny = (cachePtr->point.y - label_marker_offset_y + t_marker_offset_y ) - labelPtr->buffer; 
-                label_marker_rect.maxx = (cachePtr->point.x + label_marker_offset_x + t_marker_offset_x ) + labelPtr->buffer; // marker_rect.minx + (marker_width-1) + labelPtr->buffer; 
-                label_marker_rect.maxy = (cachePtr->point.y + label_marker_offset_y + t_marker_offset_y ) + labelPtr->buffer; // marker_rect.miny + (marker_height-1) + labelPtr->buffer; 
-              }
-              
               if(labelPtr->annotext && labelPtr->position == MS_AUTO) {
                 int positions[MS_POSITIONS_LENGTH], npositions=0;
    
@@ -2878,12 +2933,11 @@
                   npositions = 8;
                 }
    
-                if(label_marker_width > 0 && label_marker_height > 0)
-                  msRectToPolygon(label_marker_rect, &poly); /* save marker bounding polygon */
-
                 for(i=0; i<npositions; i++) {
                   // RFC 77 TODO: take label_marker_offset_x/y into account
-                  labelPtr->annopoint = get_metrics(&(cachePtr->point), positions[i], r, (MS_MAX(label_marker_offset_x, marker_offset_x) + label_offset_x), (MS_MAX(label_marker_offset_y, marker_offset_y) + label_offset_y), labelPtr->angle, label_buffer, &poly);
+                  labelPtr->annopoint = get_metrics(&(cachePtr->point), positions[i], r,
+                        marker_offset_x + label_offset_x, marker_offset_y + label_offset_y,
+                        labelPtr->angle, label_buffer, &poly);
 
                   if(labelPtr->force == MS_OFF) {
                      /* check for collisions inside the label group */
@@ -2904,39 +2958,35 @@
                   cachePtr->poly = tmppoly;
 
                   /* found a suitable place for this label */
-                  if(labelPtr->status) {
+                  if(labelPtr->status || (i==(npositions-1) && labelPtr->force == MS_TRUE)) {
+                    labelPtr->status = MS_TRUE; /* set to true in case we are forcing it */
                     if(labelPtr->annopoly) get_metrics_line(&(cachePtr->point), positions[i], r, (marker_offset_x + label_offset_x), (marker_offset_y + label_offset_y), labelPtr->angle, 1, labelPtr->annopoly->line);
                     break; /* ...out of position loop */
                   } else {
-                    /* reset some things */
-                    /* TB->SDL: this block seemed wrong, shouldn't the marker be deleted only once *all* auto positions have been tested? */
-
-                    /* there was a collision with a previous label, remove current label bbox before trying another position */
+                     /* remove the poly added by get_metrics for this label position, unless this is the last tested
+                      * position and we have label->force, as in that case it will be kept regardlesss of collisions */
                     msShapeDeleteLine(&poly, poly.numlines-1);
                     msComputeBounds(&poly);
                   }
                 } /* next position */
-
-                if(!labelPtr->status && labelPtr->force == MS_TRUE) {                 
-                  if(labelPtr->annopoly) get_metrics_line(&(cachePtr->point), positions[npositions-1], r, (MS_MAX(label_marker_offset_x, marker_offset_x) + label_offset_x), (MS_MAX(label_marker_offset_y, marker_offset_y) + label_offset_y), labelPtr->angle, 1, labelPtr->annopoly->line);
-                  labelPtr->status = MS_TRUE; /* draw in spite of collisions based on last position, need a *best* position */
-                }
-
               } else { /* explicit position */
 
                 if(labelPtr->annotext) {
                    if(labelPtr->position == MS_CC) { /* don't need the marker_offset */
-                      labelPtr->annopoint = get_metrics(&(cachePtr->point), labelPtr->position, r, label_offset_x, label_offset_y, labelPtr->angle, label_buffer, &poly);
-                      if(labelPtr->annopoly) get_metrics_line(&(cachePtr->point), labelPtr->position, r, label_offset_x, label_offset_y, labelPtr->angle, 1, labelPtr->annopoly->line);
+                      labelPtr->annopoint = get_metrics(&(cachePtr->point), labelPtr->position, r,
+                            label_offset_x, label_offset_y, labelPtr->angle, label_buffer, &poly);
+                      if(labelPtr->annopoly) get_metrics_line(&(cachePtr->point), labelPtr->position, r,
+                            label_offset_x, label_offset_y, labelPtr->angle, 1, labelPtr->annopoly->line);
                    } else {
-                      labelPtr->annopoint = get_metrics(&(cachePtr->point), labelPtr->position, r, (MS_MAX(label_marker_offset_x, marker_offset_x) + label_offset_x), (MS_MAX(label_marker_offset_y, marker_offset_y) + label_offset_y), labelPtr->angle, label_buffer, &poly);
-                      if(labelPtr->annopoly) get_metrics_line(&(cachePtr->point), labelPtr->position, r, (MS_MAX(label_marker_offset_x, marker_offset_x) + label_offset_x), (MS_MAX(label_marker_offset_y, marker_offset_y) + label_offset_y), labelPtr->angle, 1, labelPtr->annopoly->line);
+                      labelPtr->annopoint = get_metrics(&(cachePtr->point), labelPtr->position, r,
+                            marker_offset_x + label_offset_x, marker_offset_y + label_offset_y,
+                            labelPtr->angle, label_buffer, &poly);
+                      if(labelPtr->annopoly) get_metrics_line(&(cachePtr->point), labelPtr->position, r,
+                            marker_offset_x + label_offset_x, marker_offset_y + label_offset_y,
+                            labelPtr->angle, 1, labelPtr->annopoly->line);
                    }
                 }
 
-                if(label_marker_width > 0 && label_marker_height > 0)
-                  msRectToPolygon(label_marker_rect, &poly); /* save marker bounding polygon, part of overlap tests */
-
                 if(labelPtr->force == MS_TRUE) {
                   transferLabelShape(&poly, cachePtr->poly);
                   labelPtr->status = MS_TRUE;

Modified: sandbox/tb-labels/mapprimitive.c
===================================================================
--- sandbox/tb-labels/mapprimitive.c	2012-02-28 08:29:37 UTC (rev 13177)
+++ sandbox/tb-labels/mapprimitive.c	2012-02-28 15:39:33 UTC (rev 13178)
@@ -115,27 +115,19 @@
 }
 
 int msCopyShape(shapeObj *from, shapeObj *to) {
-  int i,copybounds=0;
+  int i;
 
   if(!from || !to) return(-1);
 
-  if(to->numlines <= 0) copybounds=1;
   for(i=0; i<from->numlines; i++)
     msAddLine(to, &(from->line[i])); /* copy each line */
 
   to->type = from->type;
 
-  if(copybounds) {
-     to->bounds.minx = from->bounds.minx;
-     to->bounds.miny = from->bounds.miny;
-     to->bounds.maxx = from->bounds.maxx;
-     to->bounds.maxy = from->bounds.maxy;
-  } else {
-     to->bounds.minx = MS_MIN(to->bounds.minx,from->bounds.minx);
-     to->bounds.miny = MS_MIN(to->bounds.miny,from->bounds.miny);
-     to->bounds.maxx = MS_MAX(to->bounds.maxx,from->bounds.maxx);
-     to->bounds.maxy = MS_MAX(to->bounds.maxy,from->bounds.maxy);
-  }
+  to->bounds.minx = from->bounds.minx;
+  to->bounds.miny = from->bounds.miny;
+  to->bounds.maxx = from->bounds.maxx;
+  to->bounds.maxy = from->bounds.maxy;
 
   if(from->text) to->text = msStrdup(from->text);
 

Modified: sandbox/tb-labels/maprendering.c
===================================================================
--- sandbox/tb-labels/maprendering.c	2012-02-28 08:29:37 UTC (rev 13177)
+++ sandbox/tb-labels/maprendering.c	2012-02-28 15:39:33 UTC (rev 13178)
@@ -862,19 +862,19 @@
          	return; // size too small
           */
 
-	 p_x = p->x;
-	 p_y = p->y;
+         p_x = p->x;
+         p_y = p->y;
 
-	 if (style->polaroffsetpixel != 0 ||
-	     style->polaroffsetangle != 0) 
-	 {
-	   double angle = style->polaroffsetangle * MS_DEG_TO_RAD;
-	   p_x +=  (style->polaroffsetpixel * cos(-angle)) * scalefactor; 
-	   p_y +=  (style->polaroffsetpixel * sin(-angle)) * scalefactor;
-	 }
+         if (style->polaroffsetpixel != 0 ||
+               style->polaroffsetangle != 0) 
+         {
+            double angle = style->polaroffsetangle * MS_DEG_TO_RAD;
+            p_x +=  (style->polaroffsetpixel * cos(-angle)) * scalefactor; 
+            p_y +=  (style->polaroffsetpixel * sin(-angle)) * scalefactor;
+         }
 
-	 p_x +=  style->offsetx * scalefactor;
-	 p_y +=  style->offsety * scalefactor;
+         p_x +=  style->offsetx * scalefactor;
+         p_y +=  style->offsety * scalefactor;
 
          if(symbol->anchorpoint_x != 0.5 || symbol->anchorpoint_y != 0.5) {
             double sx,sy;
@@ -883,11 +883,10 @@
             ox = (0.5 - symbol->anchorpoint_x) * sx;
             oy = (0.5 - symbol->anchorpoint_y) * sy;
             if(s.rotation != 0) {
-	       double sina, cosa;
+               double sina, cosa;
                double rox,roy;
-	       /* sincos(-s.rotation,&sina,&cosa); */
-	       sina = sin(-s.rotation);
-	       cosa = cos(-s.rotation);
+               sina = sin(-s.rotation);
+               cosa = cos(-s.rotation);
                rox = ox * cosa - oy * sina;
                roy = ox * sina + oy * cosa;
                p_x += rox;

Modified: sandbox/tb-labels/mapserver.h
===================================================================
--- sandbox/tb-labels/mapserver.h	2012-02-28 08:29:37 UTC (rev 13177)
+++ sandbox/tb-labels/mapserver.h	2012-02-28 15:39:33 UTC (rev 13178)
@@ -1954,7 +1954,6 @@
 MS_DLL_EXPORT int msGetUnicodeEntity(const char *inptr, int *unicode);
 MS_DLL_EXPORT int msStringIsInteger(const char *string);
 MS_DLL_EXPORT int msUTF8ToUniChar(const char *str, int *chPtr); /* maptclutf.c */
-MS_DLL_EXPORT char* msGetFirstLine(char* text);
 MS_DLL_EXPORT char* msStringEscape( const char * pszString );
 MS_DLL_EXPORT int msStringInArray( const char * pszString, char **array, int numelements);
 

Modified: sandbox/tb-labels/mapstring.c
===================================================================
--- sandbox/tb-labels/mapstring.c	2012-02-28 08:29:37 UTC (rev 13177)
+++ sandbox/tb-labels/mapstring.c	2012-02-28 15:39:33 UTC (rev 13178)
@@ -2070,45 +2070,6 @@
   return MS_SUCCESS;
 }
 
-/**
- * msGetFirstLine()
- *
- * returns the first line of a given string.
- * called by getLabelSize functions for calculating 
- * the baseline offsets of labels
- *
- * this function was implemented to avoid using the 
- * msSplitString function and its multiple mallocs, as
- * only one malloc is used here.
- *
- * this function can be called if the input isn't a
- * multiline string, but this wastes a malloc
- */
-char* msGetFirstLine(char* text) {
-    int firstLineLength=0; /*number of bytes up to first \n character */
-    int glyphLength;
-    char glyph[11];
-    const char *textptr=text;
-    char *firstLine,*firstLineCur;
-    /*loop through glyphs in text*/
-    while((glyphLength=msGetNextGlyph(&textptr,glyph))) {
-        if(glyphLength==1 && *glyph=='\n') { /*we've hit the first \n char*/
-            firstLineCur = firstLine = msSmallMalloc(firstLineLength+1);
-            
-            /*copy the first line into the return array*/
-            while(firstLineLength--) {
-                *firstLineCur++ = *text++;
-            }
-            *firstLineCur='\0';
-            return firstLine;
-        }
-        /*increment byte count if we haven't hit a \n yet*/
-        firstLineLength+=glyphLength;
-    }
-    /*no newline found in text*/
-    return msStrdup(text);
-}
-
 /************************************************************************/
 /*                             msStrdup()                               */
 /************************************************************************/



More information about the mapserver-commits mailing list