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

svn at osgeo.org svn at osgeo.org
Wed Feb 29 12:07:23 EST 2012


Author: tbonfort
Date: 2012-02-29 09:07:23 -0800 (Wed, 29 Feb 2012)
New Revision: 13184

Modified:
   sandbox/tb-labels/mapagg.cpp
   sandbox/tb-labels/mapdraw.c
   sandbox/tb-labels/maplabel.c
Log:
avoid usage of MS_NINT, tweak baseline computation


Modified: sandbox/tb-labels/mapagg.cpp
===================================================================
--- sandbox/tb-labels/mapagg.cpp	2012-02-29 10:51:31 UTC (rev 13183)
+++ sandbox/tb-labels/mapagg.cpp	2012-02-29 17:07:23 UTC (rev 13184)
@@ -183,7 +183,8 @@
          msSetError(MS_TTFERR, "AGG error loading font (%s)", "aggLoadFont()", font);
          return MS_FAILURE;
       }
-      //cache->m_feng.hinting(true);
+      if(!cache->m_feng.hinting())
+         cache->m_feng.hinting(true);
       if(cache->m_feng.resolution() != 96)
          cache->m_feng.resolution(96);
       if(!cache->m_feng.flip_y())

Modified: sandbox/tb-labels/mapdraw.c
===================================================================
--- sandbox/tb-labels/mapdraw.c	2012-02-29 10:51:31 UTC (rev 13183)
+++ sandbox/tb-labels/mapdraw.c	2012-02-29 17:07:23 UTC (rev 13184)
@@ -1825,8 +1825,8 @@
 
 	  if(layer->transform == MS_TRUE) {
 	    if(!msPointInRect(point, &map->extent)) return(MS_SUCCESS);
-	    point->x = MS_MAP2IMAGE_X(point->x, map->extent.minx, map->cellsize);
-	    point->y = MS_MAP2IMAGE_Y(point->y, map->extent.maxy, map->cellsize);
+	    point->x = MS_MAP2IMAGE_X_IC_DBL(point->x, map->extent.minx, map->cellsize);
+	    point->y = MS_MAP2IMAGE_Y_IC_DBL(point->y, map->extent.maxy, map->cellsize);
 	  } else
             msOffsetPointRelativeTo(point, layer);
 
@@ -2652,16 +2652,14 @@
       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.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;
 }
@@ -2711,9 +2709,9 @@
                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++) {
-            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;
          }
@@ -2812,8 +2810,8 @@
             /* 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;
+               marker_offset_x = (markerPoly.bounds.maxx-markerPoly.bounds.minx)/2.0;
+               marker_offset_y = (markerPoly.bounds.maxy-markerPoly.bounds.miny)/2.0;
                /* add marker to cachePtr->poly */
                transferLabelShape(&markerPoly, &poly);
             }
@@ -2845,12 +2843,12 @@
               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;
+                    marker_offset_x = (markerPoly.bounds.maxx-markerPoly.bounds.minx)/2.0;
+                    marker_offset_y = (markerPoly.bounds.maxy-markerPoly.bounds.miny)/2.0;
                  } 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);
+                    marker_offset_x = MS_MAX(marker_offset_x,(markerPoly.bounds.maxx-markerPoly.bounds.minx)/2.0);
+                    marker_offset_y = MS_MAX(marker_offset_y,(markerPoly.bounds.maxy-markerPoly.bounds.miny)/2.0);
                  }
                  /* add marker to cachePtr->poly */
                  transferLabelShape(&markerPoly, &poly);
@@ -2878,27 +2876,24 @@
                     /* TODO: treat the case with multiple labels and/or leader lines */
                  }
 
+                 /* apply offset and buffer settings */
+                 label_offset_x = labelPtr->offsetx*scalefactor;
+                 label_offset_y = labelPtr->offsety*scalefactor;
+                 label_buffer = (labelPtr->buffer*image->resolutionfactor);
+                 label_mindistance = (labelPtr->mindistance*image->resolutionfactor);
+                 
                  /* adjust the baseline (see #1449) */
                  if(labelPtr->type == MS_TRUETYPE) {
-                    char *newline = strchr(labelPtr->annotext,'\n');
-                    if(!newline) {
-                       labelPtr->offsety += ((((r.miny + r.maxy) + size) / 2.0)/scalefactor);
-                       labelPtr->offsetx += ((r.minx / 2)/scalefactor);
+                    char *lastline = strrchr(labelPtr->annotext,'\n');
+                    if(!lastline || !*(++lastline)) {
+                       label_offset_y += ((r.miny + r.maxy) + size) / 2.0;
                     } else {
                        rectObj rect2; /* bbox of first line only */
-                       *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;
+                       msGetLabelSize(map, labelPtr, lastline, size, &rect2, NULL);
+                       label_offset_y += ((rect2.miny+rect2.maxy) + size) / 2.0;
                     }
                  }
 
-                 /* apply offset and buffer settings */
-                 label_offset_x = labelPtr->offsetx*scalefactor;
-                 label_offset_y = labelPtr->offsety*scalefactor;
-                 label_buffer = (labelPtr->buffer*image->resolutionfactor);
-                 label_mindistance = (labelPtr->mindistance*image->resolutionfactor);
                  
                  /* compute the label annopoly  if we need to render the background billboard */
                  if(labelPtr->numstyles > 0) {
@@ -2962,7 +2957,9 @@
                   /* found a suitable place for this label */
                   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);
+                    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 {
                      /* remove the poly added by get_metrics for this label position, unless this is the last tested
@@ -3063,14 +3060,14 @@
                msDrawText(image, labelPtr->annopoint, labelPtr->annotext, labelPtr, &(map->fontset), layerPtr->scalefactor); /* actually draw the label */
             }
 
-           /* 
+          /* 
             styleObj tstyle;
             static int foo =0;
             if(!foo) {
                srand(time(NULL));
                foo = 1;
                initStyle(&tstyle);
-               tstyle.width = 1;
+               tstyle.width = 0.5;
                tstyle.color.alpha = 255;
             }
             tstyle.color.red = random()%255;

Modified: sandbox/tb-labels/maplabel.c
===================================================================
--- sandbox/tb-labels/maplabel.c	2012-02-29 10:51:31 UTC (rev 13183)
+++ sandbox/tb-labels/maplabel.c	2012-02-29 17:07:23 UTC (rev 13184)
@@ -548,8 +548,8 @@
     cachePtr->labelpath = labelpath;
     /* Use the middle point of the labelpath for mindistance calculations */
     i = labelpath->path.numpoints / 2;
-    cachePtr->point.x = MS_NINT(labelpath->path.point[i].x);
-    cachePtr->point.y = MS_NINT(labelpath->path.point[i].y);
+    cachePtr->point.x = labelpath->path.point[i].x;
+    cachePtr->point.y = labelpath->path.point[i].y;
   }
 
   /* TODO: perhaps we can get rid of this next section and just store a marker size? Why do we cache the styles for a point layer? */
@@ -603,22 +603,19 @@
     /* TO DO: at the moment only checks the bottom style, perhaps should check all of them */
     /* #2347: after RFC-24 classPtr->styles could be NULL so we check it */
     if(classPtr->styles != NULL) {
-      if(msGetMarkerSize(&map->symbolset, classPtr->styles[0], &w, &h, layerPtr->scalefactor) != MS_SUCCESS) 
-        return(MS_FAILURE);
-    } else {
-      msSetError(MS_MISCERR, "msAddLabel error: missing style definition for layer '%s'", "msAddLabel()", layerPtr->name);
-      return(MS_FAILURE);
-    }
-    rect.minx = MS_NINT(point->x - .5 * w);
-    rect.miny = MS_NINT(point->y - .5 * h);
-    rect.maxx = rect.minx + (w-1);
-    rect.maxy = rect.miny + (h-1);
-    msRectToPolygon(rect, cacheslot->markers[i].poly);    
-    cacheslot->markers[i].id = cacheslot->numlabels;
- 
-    cachePtr->markerid = i;
+       if(msGetMarkerSize(&map->symbolset, classPtr->styles[0], &w, &h, layerPtr->scalefactor) != MS_SUCCESS) 
+          return(MS_FAILURE);
+       rect.minx = point->x - .5 * w;
+       rect.miny = point->y - .5 * h;
+       rect.maxx = rect.minx + (w-1);
+       rect.maxy = rect.miny + (h-1);
+       msRectToPolygon(rect, cacheslot->markers[i].poly);    
+       cacheslot->markers[i].id = cacheslot->numlabels;
 
-    cacheslot->nummarkers++;
+       cachePtr->markerid = i;
+
+       cacheslot->nummarkers++;
+    }
   }
 
   cacheslot->numlabels++;
@@ -1235,23 +1232,23 @@
 
     x2 = x1 - buffer; /* ll */
     y2 = y1 + buffer;
-    poly->point[0].x = p->x + MS_NINT(x2 * cos_a - (-y2) * sin_a);
-    poly->point[0].y = p->y - MS_NINT(x2 * sin_a + (-y2) * cos_a);
+    poly->point[0].x = p->x + (x2 * cos_a - (-y2) * sin_a);
+    poly->point[0].y = p->y - (x2 * sin_a + (-y2) * cos_a);
 
     x2 = x1 - buffer; /* ul */
     y2 = y1 - h - buffer;
-    poly->point[1].x = p->x + MS_NINT(x2 * cos_a - (-y2) * sin_a);
-    poly->point[1].y = p->y - MS_NINT(x2 * sin_a + (-y2) * cos_a);
+    poly->point[1].x = p->x + (x2 * cos_a - (-y2) * sin_a);
+    poly->point[1].y = p->y - (x2 * sin_a + (-y2) * cos_a);
 
     x2 = x1 + w + buffer; /* ur */
     y2 = y1 - h - buffer;
-    poly->point[2].x = p->x + MS_NINT(x2 * cos_a - (-y2) * sin_a);
-    poly->point[2].y = p->y - MS_NINT(x2 * sin_a + (-y2) * cos_a);
+    poly->point[2].x = p->x + (x2 * cos_a - (-y2) * sin_a);
+    poly->point[2].y = p->y - (x2 * sin_a + (-y2) * cos_a);
 
     x2 = x1 + w + buffer; /* lr */
     y2 = y1 + buffer;
-    poly->point[3].x = p->x + MS_NINT(x2 * cos_a - (-y2) * sin_a);
-    poly->point[3].y = p->y - MS_NINT(x2 * sin_a + (-y2) * cos_a);
+    poly->point[3].x = p->x + (x2 * cos_a - (-y2) * sin_a);
+    poly->point[3].y = p->y - (x2 * sin_a + (-y2) * cos_a);
 
     poly->point[4].x = poly->point[0].x;
     poly->point[4].y = poly->point[0].y;



More information about the mapserver-commits mailing list