[mapserver-commits] r7577 - trunk/mapserver
svn at osgeo.org
svn at osgeo.org
Mon May 12 12:32:28 EDT 2008
Author: tbonfort
Date: 2008-05-12 12:32:27 -0400 (Mon, 12 May 2008)
New Revision: 7577
Modified:
trunk/mapserver/HISTORY.TXT
trunk/mapserver/mapagg.cpp
trunk/mapserver/mapdraw.c
trunk/mapserver/mapgraticule.c
trunk/mapserver/mapimagemap.c
trunk/mapserver/maplabel.c
trunk/mapserver/maplegend.c
trunk/mapserver/mapscale.c
trunk/mapserver/mapserver.h
trunk/mapserver/mapsvg.c
Log:
use an agg specific label size calculation function where possible (#2357)
Modified: trunk/mapserver/HISTORY.TXT
===================================================================
--- trunk/mapserver/HISTORY.TXT 2008-05-12 15:20:41 UTC (rev 7576)
+++ trunk/mapserver/HISTORY.TXT 2008-05-12 16:32:27 UTC (rev 7577)
@@ -12,6 +12,7 @@
Current Version (5.1-dev, SVN trunk):
-------------------------------------
+- AGG: use an agg specific label size calculation function where possible (#2357)
- mapogcsld.c: fetch TextSymbolizer/Label/ogc:PropertyName correctly (#2611)
Modified: trunk/mapserver/mapagg.cpp
===================================================================
--- trunk/mapserver/mapagg.cpp 2008-05-12 15:20:41 UTC (rev 7576)
+++ trunk/mapserver/mapagg.cpp 2008-05-12 16:32:27 UTC (rev 7577)
@@ -1947,6 +1947,26 @@
}
+int msGetLabelSizeAGG(imageObj *img, char *string, labelObj *label, rectObj *rect, fontSetObj *fontset, double scalefactor, int adjustBaseline)
+{
+ AGGMapserverRenderer* ren = getAGGRenderer(img);
+ int size;
+ size = MS_NINT(label->size*scalefactor);
+ size = MS_MAX(size, label->minsize);
+ size = MS_MIN(size, label->maxsize);
+ char * font = msLookupHashTable(&(fontset->fonts), label->font);
+ if(!font) {
+ msSetError(MS_TTFERR, "Requested font (%s) not found.", "msGetLabelSizeAGG()", label->font);
+ return MS_FAILURE;
+ }
+ if(ren->getLabelSize(string, font, label->size, rect) != MS_SUCCESS)
+ return MS_FAILURE;
+ if(adjustBaseline) {
+ label->offsety += MS_NINT(((rect->miny+rect->maxy) + size) / 2);
+ label->offsetx += MS_NINT(rect->minx / 2);
+ }
+ return MS_SUCCESS;
+}
// ---------------------------------------------------------------------------
// Draw a label curved along a line
// ---------------------------------------------------------------------------
Modified: trunk/mapserver/mapdraw.c
===================================================================
--- trunk/mapserver/mapdraw.c 2008-05-12 15:20:41 UTC (rev 7576)
+++ trunk/mapserver/mapdraw.c 2008-05-12 16:32:27 UTC (rev 7577)
@@ -1955,7 +1955,7 @@
pointObj p;
rectObj r;
- if(msGetLabelSize(string, label, &r, fontset, scalefactor, MS_FALSE) == -1) return(-1);
+ 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 */
} else {
@@ -2086,7 +2086,7 @@
if(!cachePtr->text || strlen(cachePtr->text) == 0)
continue; /* not an error, just don't want to do anything */
- if(msGetLabelSize(cachePtr->text, labelPtr, &r, &(map->fontset), layerPtr->scalefactor, MS_TRUE) == -1)
+ if(msGetLabelSize(image,cachePtr->text, labelPtr, &r, &(map->fontset), layerPtr->scalefactor, MS_TRUE) == -1)
return(-1);
if(labelPtr->autominfeaturesize && ((r.maxx-r.minx) > cachePtr->featuresize))
Modified: trunk/mapserver/mapgraticule.c
===================================================================
--- trunk/mapserver/mapgraticule.c 2008-05-12 15:20:41 UTC (rev 7576)
+++ trunk/mapserver/mapgraticule.c 2008-05-12 16:32:27 UTC (rev 7577)
@@ -655,7 +655,7 @@
if( pLayer->transform )
msTransformShapeToPixel( pShape, pLayer->map->extent, pLayer->map->cellsize );
- if (msGetLabelSize( pShape->text, &pLayer->class[0]->label, &rectLabel, &pLayer->map->fontset, 1.0, MS_FALSE) != 0)
+ if (msGetLabelSizeGD( pShape->text, &pLayer->class[0]->label, &rectLabel, &pLayer->map->fontset, 1.0, MS_FALSE) != 0)
return MS_FAILURE; /* msSetError already called */
switch( ePosition )
Modified: trunk/mapserver/mapimagemap.c
===================================================================
--- trunk/mapserver/mapimagemap.c 2008-05-12 15:20:41 UTC (rev 7576)
+++ trunk/mapserver/mapimagemap.c 2008-05-12 16:32:27 UTC (rev 7577)
@@ -1850,7 +1850,7 @@
if(cachePtr->label.type == MS_TRUETYPE)
cachePtr->label.size = (int)(cachePtr->label.size*layerPtr->scalefactor);
- if(msGetLabelSize(cachePtr->text, labelPtr, &r, &(map->fontset), layerPtr->scalefactor, MS_TRUE) == -1)
+ if(msGetLabelSize(img,cachePtr->text, labelPtr, &r, &(map->fontset), layerPtr->scalefactor, MS_TRUE) == -1)
return(-1);
if(labelPtr->autominfeaturesize && ((r.maxx-r.minx) > cachePtr->featuresize))
Modified: trunk/mapserver/maplabel.c
===================================================================
--- trunk/mapserver/maplabel.c 2008-05-12 15:20:41 UTC (rev 7576)
+++ trunk/mapserver/maplabel.c 2008-05-12 16:32:27 UTC (rev 7577)
@@ -1,5 +1,5 @@
/******************************************************************************
- * $Id:$
+ * $Id$
*
* Project: MapServer
* Purpose: Labeling Implementation.
@@ -396,6 +396,17 @@
#endif
}
+
+int msGetLabelSize(imageObj *img, char *string, labelObj *label, rectObj *rect, fontSetObj *fontset, double scalefactor, int adjustBaseline)
+{
+#ifdef USE_AGG
+ if(MS_RENDERER_AGG(img->format))
+ return msGetLabelSizeAGG(img,string,label,rect,fontset,scalefactor,adjustBaseline);
+ else
+#endif
+ return msGetLabelSizeGD(string,label,rect,fontset,scalefactor,adjustBaseline);
+}
+
/*
** Note: All these routines assume a reference point at the LL corner of the text. GD's
** bitmapped fonts use UL and this is compensated for. Note the rect is relative to the
@@ -403,7 +414,7 @@
*/
/* assumes an angle of 0 regardless of what's in the label object */
-int msGetLabelSize(char *string, labelObj *label, rectObj *rect, fontSetObj *fontset, double scalefactor, int adjustBaseline)
+int msGetLabelSizeGD(char *string, labelObj *label, rectObj *rect, fontSetObj *fontset, double scalefactor, int adjustBaseline)
{
int size;
if(label->type == MS_TRUETYPE) {
@@ -802,7 +813,7 @@
label.outlinecolor = style->outlinecolor;
label.antialias = symbol->antialias;
- if(msGetLabelSize(symbol->character, &label, &label_rect, symbolset->fontset, scalefactor, MS_FALSE) == -1)
+ if(msGetLabelSizeGD(symbol->character, &label, &label_rect, symbolset->fontset, scalefactor, MS_FALSE) == -1)
return(-1);
label_width = (int) label_rect.maxx - (int) label_rect.minx;
Modified: trunk/mapserver/maplegend.c
===================================================================
--- trunk/mapserver/maplegend.c 2008-05-12 15:20:41 UTC (rev 7576)
+++ trunk/mapserver/maplegend.c 2008-05-12 16:32:27 UTC (rev 7577)
@@ -200,7 +200,7 @@
transformedText = strdup(lp->class[j]->name);
if ( transformedText == NULL
- || msGetLabelSize(transformedText, &map->legend.label,
+ || msGetLabelSizeGD(transformedText, &map->legend.label,
&rect, &(map->fontset), 1.0, MS_FALSE) != 0)
{ /* something bad happened */
if (transformedText)
@@ -309,7 +309,7 @@
cur->pred=head;
head=cur;
if(cur->transformedText==NULL||
- msGetLabelSize(cur->transformedText, &map->legend.label, &rect, &(map->fontset), 1.0, MS_FALSE) != 0)
+ msGetLabelSizeGD(cur->transformedText, &map->legend.label, &rect, &(map->fontset), 1.0, MS_FALSE) != 0)
{ /* something bad happened, free allocated mem */
while(cur) {
if(cur->transformedText!=cur->theclass->name)
Modified: trunk/mapserver/mapscale.c
===================================================================
--- trunk/mapserver/mapscale.c 2008-05-12 15:20:41 UTC (rev 7576)
+++ trunk/mapserver/mapscale.c 2008-05-12 16:32:27 UTC (rev 7577)
@@ -1,5 +1,5 @@
/******************************************************************************
- * $Id:$
+ * $Id$
*
* Project: MapServer
* Purpose: Scale object rendering.
@@ -310,7 +310,7 @@
map->scalebar.label.position = MS_CC;
p.x = ox + j*isx; /* + MS_NINT(fontPtr->w/2); */
p.y = oy + map->scalebar.height + MS_NINT(VSPACING*fontPtr->h);
- if(msGetLabelSize(label,&(map->scalebar.label), &r,
+ if(msGetLabelSizeGD(label,&(map->scalebar.label), &r,
&(map->fontset), 1, MS_FALSE) == -1) return(NULL);
p2 = get_metrics(&p, MS_CC, r, 0,0, 0, 0, NULL);
msDrawTextGD(image->img.gd, p2, label, &(map->scalebar.label), &(map->fontset), 1.0);
@@ -323,7 +323,7 @@
map->scalebar.label.position = MS_CR;
p.x = ox; /* + MS_NINT(fontPtr->w/2); */
p.y = oy + map->scalebar.height + MS_NINT(VSPACING*fontPtr->h);
- if(msGetLabelSize(label,&(map->scalebar.label), &r,
+ if(msGetLabelSizeGD(label,&(map->scalebar.label), &r,
&(map->fontset), 1, MS_FALSE) == -1) return(NULL);
p2 = get_metrics(&p, MS_CR, r, 0,0, 0, 0, NULL);
msDrawTextGD(image->img.gd, p2, label, &(map->scalebar.label), &(map->fontset), 1.0);
@@ -343,7 +343,7 @@
map->scalebar.label.position = MS_CC;
p.x = ox + j*isx; /* + MS_NINT(fontPtr->w/2); */
p.y = oy + map->scalebar.height + MS_NINT(VSPACING*fontPtr->h);
- if(msGetLabelSize(label,&(map->scalebar.label), &r,
+ if(msGetLabelSizeGD(label,&(map->scalebar.label), &r,
&(map->fontset), 1, MS_FALSE) == -1) return(NULL);
p2 = get_metrics(&p, MS_CC, r, 0,0, 0, 0, NULL);
msDrawTextGD(image->img.gd, p2, label, &(map->scalebar.label), &(map->fontset), 1.0);
@@ -359,7 +359,7 @@
map->scalebar.label.position = MS_CR;
p.x = ox; /* + MS_NINT(fontPtr->w/2); */
p.y = oy + map->scalebar.height + MS_NINT(VSPACING*fontPtr->h);
- if(msGetLabelSize(label,&(map->scalebar.label), &r,
+ if(msGetLabelSizeGD(label,&(map->scalebar.label), &r,
&(map->fontset), 1, MS_FALSE) == -1) return(NULL);
p2 = get_metrics(&p, MS_CR, r, 0,0, 0, 0, NULL);
msDrawTextGD(image->img.gd, p2, label, &(map->scalebar.label), &(map->fontset), 1.0);
Modified: trunk/mapserver/mapserver.h
===================================================================
--- trunk/mapserver/mapserver.h 2008-05-12 15:20:41 UTC (rev 7576)
+++ trunk/mapserver/mapserver.h 2008-05-12 16:32:27 UTC (rev 7577)
@@ -1680,7 +1680,9 @@
MS_DLL_EXPORT int msInitFontSet(fontSetObj *fontset);
MS_DLL_EXPORT int msFreeFontSet(fontSetObj *fontset);
MS_DLL_EXPORT char *msTransformLabelText(labelObj *label, char *text);
-MS_DLL_EXPORT int msGetLabelSize(char *string, labelObj *label, rectObj *rect, fontSetObj *fontSet, double scalefactor, int adjustBaseline);
+MS_DLL_EXPORT int msGetLabelSize(imageObj *img, char *string, labelObj *label, rectObj *rect, fontSetObj *fontSet, double scalefactor, int adjustBaseline);
+MS_DLL_EXPORT int msGetLabelSizeGD(char *string, labelObj *label, rectObj *rect, fontSetObj *fontSet, double scalefactor, int adjustBaseline);
+
MS_DLL_EXPORT int msGetLabelSizeEx(char *string, labelObj *label, rectObj *rect, fontSetObj *fontSet, double scalefactor, int adjustBaseline, double **offsets);
MS_DLL_EXPORT int msAddLabel(mapObj *map, int layerindex, int classindex, int shapeindex, int tileindex, pointObj *point, labelPathObj *labelpath, char *string, double featuresize, labelObj *label);
MS_DLL_EXPORT void msTestLabelCacheCollisions(labelCacheObj *labelcache, labelObj *labelPtr, int mapwidth, int mapheight, int buffer, labelCacheMemberObj *cachePtr, int current_priority, int current_label);
@@ -1926,6 +1928,7 @@
MS_DLL_EXPORT void msDrawLineSymbolAGG(symbolSetObj *symbolset, imageObj *image, shapeObj *p, styleObj *style, double scalefactor);
MS_DLL_EXPORT void msDrawShadeSymbolAGG(symbolSetObj *symbolset, imageObj *image,shapeObj *p, styleObj *style, double scalefactor);
+MS_DLL_EXPORT int msGetLabelSizeAGG(imageObj *img, char *string, labelObj *label, rectObj *rect, fontSetObj *fontSet, double scalefactor, int adjustBaseline);
MS_DLL_EXPORT int msDrawTextAGG(imageObj *imgage, pointObj labelPnt, char *string, labelObj *label, fontSetObj *fontset, double scalefactor);
MS_DLL_EXPORT int msDrawTextLineAGG(imageObj *image, char *string, labelObj *label, labelPathObj *labelpath, fontSetObj *fontset, double scalefactor);
Modified: trunk/mapserver/mapsvg.c
===================================================================
--- trunk/mapserver/mapsvg.c 2008-05-12 15:20:41 UTC (rev 7576)
+++ trunk/mapserver/mapsvg.c 2008-05-12 16:32:27 UTC (rev 7577)
@@ -1152,7 +1152,7 @@
if(!cachePtr->text || strlen(cachePtr->text) == 0)
continue; /* not an error, just don't want to do anything */
- if(msGetLabelSize(cachePtr->text, labelPtr, &r, &(map->fontset), layerPtr->scalefactor, MS_TRUE) == -1)
+ if(msGetLabelSizeGD(cachePtr->text, labelPtr, &r, &(map->fontset), layerPtr->scalefactor, MS_TRUE) == -1)
return(-1);
if(labelPtr->autominfeaturesize && ((r.maxx-r.minx) > cachePtr->featuresize))
More information about the mapserver-commits
mailing list