[mapserver-commits] r9826 - trunk/mapserver
svn at osgeo.org
svn at osgeo.org
Sat Feb 20 17:32:34 EST 2010
Author: sdlime
Date: 2010-02-20 17:32:33 -0500 (Sat, 20 Feb 2010)
New Revision: 9826
Modified:
trunk/mapserver/mapfile.c
trunk/mapserver/maplegend.c
trunk/mapserver/mapogcsld.c
trunk/mapserver/mapscale.c
trunk/mapserver/mapserver.h
Log:
Added basic structure changes and initialization/free code to support styles in labelObj.
Modified: trunk/mapserver/mapfile.c
===================================================================
--- trunk/mapserver/mapfile.c 2010-02-20 21:17:21 UTC (rev 9825)
+++ trunk/mapserver/mapfile.c 2010-02-20 22:32:33 UTC (rev 9826)
@@ -1343,6 +1343,12 @@
label->force = MS_FALSE;
label->priority = MS_DEFAULT_LABEL_PRIORITY;
+ /* Set maxstyles = 0, styles[] will be allocated as needed on first call
+ * to msGrowLabelStyles()
+ */
+ label->numstyles = label->maxstyles = 0;
+ label->styles = NULL;
+
label->numbindings = 0;
for(i=0; i<MS_LABEL_BINDING_LENGTH; i++) {
label->bindings[i].item = NULL;
@@ -1359,6 +1365,15 @@
msFree(label->font);
msFree(label->encoding);
+ for(i=0;i<label->numstyles;i++) { /* each style */
+ if(label->styles[i]!=NULL) {
+ if(freeStyle(label->styles[i]) == MS_SUCCESS) {
+ msFree(label->styles[i]);
+ }
+ }
+ }
+ msFree(label->styles);
+
for(i=0; i<MS_LABEL_BINDING_LENGTH; i++)
msFree(label->bindings[i].item);
}
@@ -2312,9 +2327,7 @@
/* Set maxstyles = 0, styles[] will be allocated as needed on first call
* to msGrowClassStyles()
*/
- class->numstyles = 0;
- class->maxstyles = 0;
-
+ class->numstyles = class->maxstyles = 0;
class->styles = NULL;
class->keyimage = NULL;
@@ -2403,18 +2416,54 @@
return class->styles[class->numstyles];
}
+/* exactly the same as for a classObj */
+styleObj *msGrowLabelStyles( labelObj *label )
+{
+ /* Do we need to increase the size of styles[] by MS_STYLE_ALLOCSIZE?
+ */
+ if (label->numstyles == label->maxstyles) {
+ styleObj **newStylePtr;
+ int i, newsize;
-/* msMaybeAllocateStyle()
+ newsize = label->maxstyles + MS_STYLE_ALLOCSIZE;
+
+ /* Alloc/realloc styles */
+ newStylePtr = (styleObj**)realloc(label->styles,
+ newsize*sizeof(styleObj*));
+ if (newStylePtr == NULL) {
+ msSetError(MS_MEMERR, "Failed to allocate memory for styles array.", "msGrowLabelStyles()");
+ return NULL;
+ }
+
+ label->styles = newStylePtr;
+ label->maxstyles = newsize;
+ for(i=label->numstyles; i<label->maxstyles; i++) {
+ label->styles[i] = NULL;
+ }
+ }
+
+ if (label->styles[label->numstyles]==NULL) {
+ label->styles[label->numstyles]=(styleObj*)calloc(1,sizeof(styleObj));
+ if (label->styles[label->numstyles]==NULL) {
+ msSetError(MS_MEMERR, "Failed to allocate memory for a styleObj", "msGrowLabelStyles()");
+ return NULL;
+ }
+ }
+
+ return label->styles[label->numstyles];
+}
+
+/* msMaybeAllocateClassStyle()
**
** Ensure that requested style index exists and has been initialized.
**
** Returns MS_SUCCESS/MS_FAILURE.
*/
-int msMaybeAllocateStyle(classObj* c, int idx) {
+int msMaybeAllocateClassStyle(classObj* c, int idx) {
if (c==NULL) return MS_FAILURE;
if ( idx < 0 ) {
- msSetError(MS_MISCERR, "Invalid style index: %d", "msMaybeAllocateStyle()", idx);
+ msSetError(MS_MISCERR, "Invalid style index: %d", "msMaybeAllocateClassStyle()", idx);
return MS_FAILURE;
}
@@ -2427,7 +2476,7 @@
if ( initStyle(c->styles[c->numstyles]) == MS_FAILURE ) {
msSetError(MS_MISCERR, "Failed to init new styleObj",
- "msMaybeAllocateStyle()");
+ "msMaybeAllocateClassStyle()");
return(MS_FAILURE);
}
c->numstyles++;
@@ -2591,40 +2640,40 @@
** for backwards compatability, these are shortcuts for style 0
*/
case(BACKGROUNDCOLOR):
- if (msMaybeAllocateStyle(class, 0)) return MS_FAILURE;
+ if (msMaybeAllocateClassStyle(class, 0)) return MS_FAILURE;
if(loadColor(&(class->styles[0]->backgroundcolor), NULL) != MS_SUCCESS) return(-1);
break;
case(COLOR):
- if (msMaybeAllocateStyle(class, 0)) return MS_FAILURE;
+ if (msMaybeAllocateClassStyle(class, 0)) return MS_FAILURE;
if(loadColor(&(class->styles[0]->color), NULL) != MS_SUCCESS) return(-1);
class->numstyles = 1; /* must *always* set a color or outlinecolor */
break;
#if ALPHACOLOR_ENABLED
case(ALPHACOLOR):
- if (msMaybeAllocateStyle(class, 0)) return MS_FAILURE;
+ if (msMaybeAllocateClassStyle(class, 0)) return MS_FAILURE;
if(loadColorWithAlpha(&(class->styles[0]->color)) != MS_SUCCESS) return(-1);
class->numstyles = 1; /* must *always* set a color, symbol or outlinecolor */
break;
#endif
case(MAXSIZE):
- if (msMaybeAllocateStyle(class, 0)) return MS_FAILURE;
+ if (msMaybeAllocateClassStyle(class, 0)) return MS_FAILURE;
if(getDouble(&(class->styles[0]->maxsize)) == -1) return(-1);
break;
case(MINSIZE):
- if (msMaybeAllocateStyle(class, 0)) return MS_FAILURE;
+ if (msMaybeAllocateClassStyle(class, 0)) return MS_FAILURE;
if(getDouble(&(class->styles[0]->minsize)) == -1) return(-1);
break;
case(OUTLINECOLOR):
- if (msMaybeAllocateStyle(class, 0)) return MS_FAILURE;
+ if (msMaybeAllocateClassStyle(class, 0)) return MS_FAILURE;
if(loadColor(&(class->styles[0]->outlinecolor), NULL) != MS_SUCCESS) return(-1);
class->numstyles = 1; /* must *always* set a color, symbol or outlinecolor */
break;
case(SIZE):
- if (msMaybeAllocateStyle(class, 0)) return MS_FAILURE;
+ if (msMaybeAllocateClassStyle(class, 0)) return MS_FAILURE;
if(getDouble(&(class->styles[0]->size)) == -1) return(-1);
break;
case(SYMBOL):
- if (msMaybeAllocateStyle(class, 0)) return MS_FAILURE;
+ if (msMaybeAllocateClassStyle(class, 0)) return MS_FAILURE;
if((state = getSymbol(2, MS_NUMBER,MS_STRING)) == -1) return(-1);
if(state == MS_NUMBER)
class->styles[0]->symbol = (int) msyynumber;
@@ -2641,33 +2690,33 @@
** for backwards compatability, these are shortcuts for style 1
*/
case(OVERLAYBACKGROUNDCOLOR):
- if (msMaybeAllocateStyle(class, 1)) return MS_FAILURE;
+ if (msMaybeAllocateClassStyle(class, 1)) return MS_FAILURE;
if(loadColor(&(class->styles[1]->backgroundcolor), NULL) != MS_SUCCESS) return(-1);
break;
case(OVERLAYCOLOR):
- if (msMaybeAllocateStyle(class, 1)) return MS_FAILURE;
+ if (msMaybeAllocateClassStyle(class, 1)) return MS_FAILURE;
if(loadColor(&(class->styles[1]->color), NULL) != MS_SUCCESS) return(-1);
class->numstyles = 2; /* must *always* set a color, symbol or outlinecolor */
break;
case(OVERLAYMAXSIZE):
- if (msMaybeAllocateStyle(class, 1)) return MS_FAILURE;
+ if (msMaybeAllocateClassStyle(class, 1)) return MS_FAILURE;
if(getDouble(&(class->styles[1]->maxsize)) == -1) return(-1);
break;
case(OVERLAYMINSIZE):
- if (msMaybeAllocateStyle(class, 1)) return MS_FAILURE;
+ if (msMaybeAllocateClassStyle(class, 1)) return MS_FAILURE;
if(getDouble(&(class->styles[1]->minsize)) == -1) return(-1);
break;
case(OVERLAYOUTLINECOLOR):
- if (msMaybeAllocateStyle(class, 1)) return MS_FAILURE;
+ if (msMaybeAllocateClassStyle(class, 1)) return MS_FAILURE;
if(loadColor(&(class->styles[1]->outlinecolor), NULL) != MS_SUCCESS) return(-1);
class->numstyles = 2; /* must *always* set a color, symbol or outlinecolor */
break;
case(OVERLAYSIZE):
- if (msMaybeAllocateStyle(class, 1)) return MS_FAILURE;
+ if (msMaybeAllocateClassStyle(class, 1)) return MS_FAILURE;
if(getDouble(&(class->styles[1]->size)) == -1) return(-1);
break;
case(OVERLAYSYMBOL):
- if (msMaybeAllocateStyle(class, 1)) return MS_FAILURE;
+ if (msMaybeAllocateClassStyle(class, 1)) return MS_FAILURE;
if((state = getSymbol(2, MS_NUMBER,MS_STRING)) == -1) return(-1);
if(state == MS_NUMBER)
class->styles[1]->symbol = (int) msyynumber;
Modified: trunk/mapserver/maplegend.c
===================================================================
--- trunk/mapserver/maplegend.c 2010-02-20 21:17:21 UTC (rev 9825)
+++ trunk/mapserver/maplegend.c 2010-02-20 22:32:33 UTC (rev 9826)
@@ -635,7 +635,7 @@
GET_LAYER(map, l)->status = MS_ON;
- if(msMaybeAllocateStyle(GET_LAYER(map, l)->class[0], 0)==MS_FAILURE) return MS_FAILURE;
+ if(msMaybeAllocateClassStyle(GET_LAYER(map, l)->class[0], 0)==MS_FAILURE) return MS_FAILURE;
GET_LAYER(map, l)->class[0]->styles[0]->symbol = s;
GET_LAYER(map, l)->class[0]->styles[0]->color.pen = -1;
GET_LAYER(map, l)->class[0]->label.force = MS_TRUE;
Modified: trunk/mapserver/mapogcsld.c
===================================================================
--- trunk/mapserver/mapogcsld.c 2010-02-20 21:17:21 UTC (rev 9825)
+++ trunk/mapserver/mapogcsld.c 2010-02-20 22:32:33 UTC (rev 9826)
@@ -1127,7 +1127,7 @@
nClassId = psLayer->numclasses-1;
iStyle = psLayer->class[nClassId]->numstyles;
- msMaybeAllocateStyle(psLayer->class[nClassId], iStyle);
+ msMaybeAllocateClassStyle(psLayer->class[nClassId], iStyle);
msSLDParseStroke(psStroke, psLayer->class[nClassId]->styles[iStyle],
psLayer->map, 0);
@@ -1407,7 +1407,7 @@
nClassId = psLayer->numclasses-1;
iStyle = psLayer->class[nClassId]->numstyles;
- msMaybeAllocateStyle(psLayer->class[nClassId], iStyle);
+ msMaybeAllocateClassStyle(psLayer->class[nClassId], iStyle);
msSLDParsePolygonFill(psFill, psLayer->class[nClassId]->styles[iStyle],
psLayer->map);
@@ -1431,7 +1431,7 @@
{
nClassId =psLayer->numclasses-1;
iStyle = psLayer->class[nClassId]->numstyles;
- msMaybeAllocateStyle(psLayer->class[nClassId], iStyle);
+ msMaybeAllocateClassStyle(psLayer->class[nClassId], iStyle);
}
else
{
@@ -1447,7 +1447,7 @@
nClassId = psLayer->numclasses-1;
iStyle = psLayer->class[nClassId]->numstyles;
- msMaybeAllocateStyle(psLayer->class[nClassId], iStyle);
+ msMaybeAllocateClassStyle(psLayer->class[nClassId], iStyle);
}
msSLDParseStroke(psStroke, psLayer->class[nClassId]->styles[iStyle],
@@ -2268,7 +2268,7 @@
nClassId = psLayer->numclasses-1;
iStyle = psLayer->class[nClassId]->numstyles;
- msMaybeAllocateStyle(psLayer->class[nClassId], iStyle);
+ msMaybeAllocateClassStyle(psLayer->class[nClassId], iStyle);
msSLDParseGraphicFillOrStroke(psRoot, NULL,
@@ -2495,7 +2495,7 @@
initClass(psLayer->class[psLayer->numclasses]);
nClassId = psLayer->numclasses;
psLayer->numclasses++;
- msMaybeAllocateStyle(psLayer->class[nClassId], 0);
+ msMaybeAllocateClassStyle(psLayer->class[nClassId], 0);
nStyleId = 0;
}
else
@@ -2718,7 +2718,7 @@
else
psLayer->class[nClassId]->name = strdup(pszPreviousQuality);
- msMaybeAllocateStyle(psLayer->class[nClassId], 0);
+ msMaybeAllocateClassStyle(psLayer->class[nClassId], 0);
psLayer->class[nClassId]->styles[0]->color.red =
sColor.red;
@@ -2779,7 +2779,7 @@
initClass(psLayer->class[psLayer->numclasses]);
psLayer->numclasses++;
nClassId = psLayer->numclasses-1;
- msMaybeAllocateStyle(psLayer->class[nClassId], 0);
+ msMaybeAllocateClassStyle(psLayer->class[nClassId], 0);
if (pszLabel)
psLayer->class[nClassId]->name = strdup(pszLabel);
else
@@ -2890,7 +2890,7 @@
initClass(psLayer->class[psLayer->numclasses]);
psLayer->numclasses++;
nClassId = psLayer->numclasses-1;
- msMaybeAllocateStyle(psLayer->class[nClassId], 0);
+ msMaybeAllocateClassStyle(psLayer->class[nClassId], 0);
psLayer->class[nClassId]->numstyles = 1;
psLayer->class[nClassId]->styles[0]->color.red =
sColor.red;
Modified: trunk/mapserver/mapscale.c
===================================================================
--- trunk/mapserver/mapscale.c 2010-02-20 21:17:21 UTC (rev 9825)
+++ trunk/mapserver/mapscale.c 2010-02-20 22:32:33 UTC (rev 9826)
@@ -472,7 +472,7 @@
GET_LAYER(map, l)->status = MS_ON;
/* TODO: Change this when we get rid of MS_MAXSTYLES */
- if (msMaybeAllocateStyle(GET_LAYER(map, l)->class[0], 0)==MS_FAILURE) return MS_FAILURE;
+ if (msMaybeAllocateClassStyle(GET_LAYER(map, l)->class[0], 0)==MS_FAILURE) return MS_FAILURE;
GET_LAYER(map, l)->class[0]->styles[0]->symbol = s;
GET_LAYER(map, l)->class[0]->styles[0]->color.pen = -1;
GET_LAYER(map, l)->class[0]->label.force = MS_TRUE;
Modified: trunk/mapserver/mapserver.h
===================================================================
--- trunk/mapserver/mapserver.h 2010-02-20 21:17:21 UTC (rev 9825)
+++ trunk/mapserver/mapserver.h 2010-02-20 22:32:33 UTC (rev 9826)
@@ -651,72 +651,7 @@
} attributeBindingObj;
#endif
-
/************************************************************************/
-/* labelObj */
-/* */
-/* parameters needed to annotate a layer, legend or scalebar */
-/************************************************************************/
-
-typedef struct {
- char *font;
- enum MS_FONT_TYPE type;
-
- colorObj color;
- colorObj outlinecolor;
- int outlinewidth;
-
- colorObj shadowcolor;
- int shadowsizex, shadowsizey;
-
- colorObj backgroundcolor;
- colorObj backgroundshadowcolor;
- int backgroundshadowsizex, backgroundshadowsizey;
-
- double size;
- double minsize, maxsize;
-
- int position;
- int offsetx, offsety;
-
- double angle;
- int autoangle; /* true or false */
- int autofollow; /* true or false, bug #1620 implementation */
-
- int buffer; /* space to reserve around a label */
-
- int antialias;
- int align;
-
- char wrap;
- int maxlength;
- int minlength;
- double space_size_10; /*cached size of a single space character -
- used for label text alignment of rfc40 */
-
- int minfeaturesize; /* minimum feature size (in pixels) to label */
- int autominfeaturesize; /* true or false */
-
- double minscaledenom,maxscaledenom;
-
- int mindistance;
- int repeatdistance;
- int partials; /* can labels run of an image */
-
- int force; /* labels *must* be drawn */
-
- char *encoding;
-
- int priority; /* Priority level 1 to MS_MAX_LABEL_PRIORITY, default=1 */
-
-#ifndef SWIG
- attributeBindingObj bindings[MS_LABEL_BINDING_LENGTH];
- int numbindings;
-#endif
-
-} labelObj;
-
-/************************************************************************/
/* webObj */
/* */
/* holds parameters for a mapserver/mapscript interface */
@@ -834,6 +769,76 @@
} styleObj;
/************************************************************************/
+/* labelObj */
+/* */
+/* parameters needed to annotate a layer, legend or scalebar */
+/************************************************************************/
+
+typedef struct {
+ char *font;
+ enum MS_FONT_TYPE type;
+
+ colorObj color;
+ colorObj outlinecolor;
+ int outlinewidth;
+
+ colorObj shadowcolor;
+ int shadowsizex, shadowsizey;
+
+ colorObj backgroundcolor;
+ colorObj backgroundshadowcolor;
+ int backgroundshadowsizex, backgroundshadowsizey;
+
+ double size;
+ double minsize, maxsize;
+
+ int position;
+ int offsetx, offsety;
+
+ double angle;
+ int autoangle; /* true or false */
+ int autofollow; /* true or false, bug #1620 implementation */
+
+ int buffer; /* space to reserve around a label */
+
+ int antialias;
+ int align;
+
+ char wrap;
+ int maxlength;
+ int minlength;
+ double space_size_10; /*cached size of a single space character -
+ used for label text alignment of rfc40 */
+
+ int minfeaturesize; /* minimum feature size (in pixels) to label */
+ int autominfeaturesize; /* true or false */
+
+ double minscaledenom, maxscaledenom;
+
+ int mindistance;
+ int repeatdistance;
+ int partials; /* can labels run of an image */
+
+ int force; /* labels *must* be drawn */
+
+ char *encoding;
+
+ int priority; /* Priority level 1 to MS_MAX_LABEL_PRIORITY, default=1 */
+
+#ifndef SWIG
+ styleObj **styles;
+ int maxstyles;
+#endif
+ int numstyles;
+
+#ifndef SWIG
+ attributeBindingObj bindings[MS_LABEL_BINDING_LENGTH];
+ int numbindings;
+#endif
+
+} labelObj;
+
+/************************************************************************/
/* classObj */
/* */
/* basic symbolization and classification information */
@@ -850,7 +855,6 @@
styleObj **styles;
int maxstyles;
#endif
-
int numstyles;
#ifdef SWIG
@@ -1598,7 +1602,8 @@
MS_DLL_EXPORT int initClass(classObj *_class);
MS_DLL_EXPORT int freeClass( classObj * );
MS_DLL_EXPORT styleObj *msGrowClassStyles( classObj *_class );
-MS_DLL_EXPORT int msMaybeAllocateStyle(classObj* c, int idx);
+MS_DLL_EXPORT styleObj *msGrowLabelStyles( labelObj *label );
+MS_DLL_EXPORT int msMaybeAllocateClassStyle(classObj* c, int idx);
MS_DLL_EXPORT void initLabel(labelObj *label);
MS_DLL_EXPORT void resetClassStyle(classObj *_class);
MS_DLL_EXPORT int initStyle(styleObj *style);
More information about the mapserver-commits
mailing list