Skip to content

Commit

Permalink
add attribute support for ALIGN and OFFSET in LABEL
Browse files Browse the repository at this point in the history
  • Loading branch information
danduk82 committed Apr 24, 2020
1 parent a2bf075 commit 89dc335
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 54 deletions.
64 changes: 45 additions & 19 deletions mapfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ int msBuildPluginLibraryPath(char **dest, const char *lib_str, mapObj *map)
char szLibPath[MS_MAXPATHLEN] = { '\0' };
char szLibPathExt[MS_MAXPATHLEN] = { '\0' };
const char *plugin_dir = NULL;

if (map)
plugin_dir = msLookupHashTable(&(map->configoptions), "MS_PLUGIN_DIR");

Expand Down Expand Up @@ -972,7 +972,7 @@ static int loadFeature(layerObj *player, int type)
msFreeShape(shape);
msFree(shape);
if(getString(&string) == MS_FAILURE) return(MS_FAILURE);

if((shape = msShapeFromWKT(string)) == NULL)
status = MS_FAILURE;

Expand Down Expand Up @@ -1529,7 +1529,16 @@ static int loadLabel(labelObj *label)
}
break;
case(ALIGN):
if((label->align = getSymbol(3, MS_ALIGN_LEFT,MS_ALIGN_CENTER,MS_ALIGN_RIGHT)) == -1) return(-1);
if((symbol = getSymbol(4, MS_ALIGN_LEFT,MS_ALIGN_CENTER,MS_ALIGN_RIGHT,MS_BINDING)) == -1)
return(-1);
if((symbol == MS_ALIGN_LEFT)||(symbol == MS_ALIGN_CENTER)||(symbol == MS_ALIGN_RIGHT)) {
label->align = symbol;
} else {
if (label->bindings[MS_LABEL_BINDING_ALIGN].item != NULL)
msFree(label->bindings[MS_LABEL_BINDING_ALIGN].item);
label->bindings[MS_LABEL_BINDING_ALIGN].item = msStrdup(msyystring_buffer);
label->numbindings++;
}
break;
case(ANTIALIAS): /*ignore*/
msyylex();
Expand Down Expand Up @@ -1633,8 +1642,25 @@ static int loadLabel(labelObj *label)
if(getInteger(&(label->minsize)) == -1) return(-1);
break;
case(OFFSET):
if(getInteger(&(label->offsetx)) == -1) return(-1);
if(getInteger(&(label->offsety)) == -1) return(-1);
if((symbol = getSymbol(2, MS_NUMBER,MS_BINDING)) == -1) return(MS_FAILURE);
if(symbol == MS_NUMBER)
label->offsetx = (int) msyynumber;
else {
if (label->bindings[MS_LABEL_BINDING_OFFSET_X].item != NULL)
msFree(label->bindings[MS_LABEL_BINDING_OFFSET_X].item);
label->bindings[MS_LABEL_BINDING_OFFSET_X].item = msStrdup(msyystring_buffer);
label->numbindings++;
}

if((symbol = getSymbol(2, MS_NUMBER,MS_BINDING)) == -1) return(MS_FAILURE);
if(symbol == MS_NUMBER)
label->offsety = (int) msyynumber;
else {
if (label->bindings[MS_LABEL_BINDING_OFFSET_Y].item != NULL)
msFree(label->bindings[MS_LABEL_BINDING_OFFSET_Y].item);
label->bindings[MS_LABEL_BINDING_OFFSET_Y].item = msStrdup(msyystring_buffer);
label->numbindings++;
}
break;
case(OUTLINECOLOR):
if(loadColor(&(label->outlinecolor), &(label->bindings[MS_LABEL_BINDING_OUTLINECOLOR])) != MS_SUCCESS) return(-1);
Expand Down Expand Up @@ -1767,7 +1793,7 @@ int msUpdateLabelFromString(labelObj *label, char *string, int url_string)
if(!label || !string) return MS_FAILURE;

msAcquireLock( TLOCK_PARSER );

if(url_string)
msyystate = MS_TOKENIZE_URL_STRING;
else
Expand Down Expand Up @@ -1967,7 +1993,7 @@ void msFreeExpression(expressionObj *exp)

int loadExpression(expressionObj *exp)
{
/* TODO: should we fall msFreeExpression if exp->string != NULL? We do some checking to avoid a leak but is it enough... */
/* TODO: should we fall msFreeExpression if exp->string != NULL? We do some checking to avoid a leak but is it enough... */

msyystring_icase = MS_TRUE;
if((exp->type = getSymbol(6, MS_STRING,MS_EXPRESSION,MS_REGEX,MS_ISTRING,MS_IREGEX,MS_LIST)) == -1) return(-1);
Expand Down Expand Up @@ -3627,9 +3653,9 @@ int initLayer(layerObj *layer, mapObj *map)
msInitExpression(&(layer->utfdata));
layer->utfitem = NULL;
layer->utfitemindex = -1;

layer->encoding = NULL;

layer->sortBy.nProperties = 0;
layer->sortBy.properties = NULL;
layer->orig_st = NULL;
Expand Down Expand Up @@ -3700,7 +3726,7 @@ int freeLayer(layerObj *layer)
msProjectDestroyReprojector(layer->reprojectorMapToLayer);
msFreeProjection(&(layer->projection));
msFreeExpression(&layer->_geomtransform);

freeCluster(&layer->cluster);

for(i=0; i<layer->maxclasses; i++) {
Expand Down Expand Up @@ -3754,9 +3780,9 @@ int freeLayer(layerObj *layer)
if(layer->maskimage) {
msFreeImage(layer->maskimage);
}

if(layer->compositer) {
freeLayerCompositer(layer->compositer);
freeLayerCompositer(layer->compositer);
}

if (layer->grid) {
Expand All @@ -3766,7 +3792,7 @@ int freeLayer(layerObj *layer)

msFreeExpression(&(layer->utfdata));
msFree(layer->utfitem);

for(i=0;i<layer->sortBy.nProperties;i++)
msFree(layer->sortBy.properties[i].item);
msFree(layer->sortBy.properties);
Expand Down Expand Up @@ -3842,7 +3868,7 @@ int loadScaletoken(scaleTokenObj *token, layerObj *layer) {
case(EOF):
msSetError(MS_EOFERR, NULL, "loadScaletoken()");
return(MS_FAILURE);
case(END):
case(END):
stop = 1;
if(token->n_entries == 0) {
msSetError(MS_PARSEERR,"Scaletoken (line:%d) has no VALUES defined","loadScaleToken()",msyylineno);
Expand All @@ -3853,7 +3879,7 @@ int loadScaletoken(scaleTokenObj *token, layerObj *layer) {
case(MS_STRING):
/* we have a key */
token->tokens = msSmallRealloc(token->tokens,(token->n_entries+1)*sizeof(scaleTokenEntryObj));

if(1 != sscanf(msyystring_buffer,"%lf",&token->tokens[token->n_entries].minscale)) {
msSetError(MS_PARSEERR, "failed to parse SCALETOKEN VALUE (%s):(line %d), expecting \"minscale\"", "loadScaletoken()",
msyystring_buffer,msyylineno);
Expand Down Expand Up @@ -4661,7 +4687,7 @@ static void writeLayer(FILE *stream, int indent, layerObj *layer)
writeIndent(stream, indent + 1);
fprintf(stream, "GEOMTRANSFORM (%s)\n", layer->_geomtransform.string);
}

writeString(stream, indent, "HEADER", NULL, layer->header);
/* join - see below */
writeKeyword(stream, indent, "LABELCACHE", layer->labelcache, 1, MS_OFF, "OFF");
Expand Down Expand Up @@ -5014,7 +5040,7 @@ static int loadOutputFormat(mapObj *map)
}
case(NAME):
msFree( name );
if((name = getToken()) == NULL)
if((name = getToken()) == NULL)
goto load_output_error;
break;
case(MIMETYPE):
Expand Down Expand Up @@ -6157,7 +6183,7 @@ int msSaveMap(mapObj *map, char *filename)
{
FILE *stream;
char szPath[MS_MAXPATHLEN];

if(!map) {
msSetError(MS_MISCERR, "Map is undefined.", "msSaveMap()");
return(-1);
Expand Down Expand Up @@ -6843,7 +6869,7 @@ static void layerSubstituteString(layerObj *layer, const char *from, const char
if(layer->tileindex) layer->tileindex = msCaseReplaceSubstring(layer->tileindex, from, to);
if(layer->connection) layer->connection = msCaseReplaceSubstring(layer->connection, from, to);
if(layer->filter.string) layer->filter.string = msCaseReplaceSubstring(layer->filter.string, from, to);

/* The bindvalues are most useful when able to substitute values from the URL */
hashTableSubstituteString(&layer->bindvals, from, to);
hashTableSubstituteString(&layer->metadata, from, to);
Expand Down
46 changes: 23 additions & 23 deletions mapserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ extern "C" {
char *filter;
struct _CompositingFilter *next;
} CompositingFilter;

typedef struct _LayerCompositer{
CompositingOperation comp_op;
int opacity;
Expand Down Expand Up @@ -623,8 +623,8 @@ extern "C" {
/* Define supported bindings here (only covers existing bindings at first). Not accessible directly using MapScript. */
#define MS_STYLE_BINDING_LENGTH 12
enum MS_STYLE_BINDING_ENUM { MS_STYLE_BINDING_SIZE, MS_STYLE_BINDING_WIDTH, MS_STYLE_BINDING_ANGLE, MS_STYLE_BINDING_COLOR, MS_STYLE_BINDING_OUTLINECOLOR, MS_STYLE_BINDING_SYMBOL, MS_STYLE_BINDING_OUTLINEWIDTH, MS_STYLE_BINDING_OPACITY, MS_STYLE_BINDING_OFFSET_X, MS_STYLE_BINDING_OFFSET_Y, MS_STYLE_BINDING_POLAROFFSET_PIXEL, MS_STYLE_BINDING_POLAROFFSET_ANGLE };
#define MS_LABEL_BINDING_LENGTH 9
enum MS_LABEL_BINDING_ENUM { MS_LABEL_BINDING_SIZE, MS_LABEL_BINDING_ANGLE, MS_LABEL_BINDING_COLOR, MS_LABEL_BINDING_OUTLINECOLOR, MS_LABEL_BINDING_FONT, MS_LABEL_BINDING_PRIORITY, MS_LABEL_BINDING_POSITION, MS_LABEL_BINDING_SHADOWSIZEX, MS_LABEL_BINDING_SHADOWSIZEY };
#define MS_LABEL_BINDING_LENGTH 12
enum MS_LABEL_BINDING_ENUM { MS_LABEL_BINDING_SIZE, MS_LABEL_BINDING_ANGLE, MS_LABEL_BINDING_COLOR, MS_LABEL_BINDING_OUTLINECOLOR, MS_LABEL_BINDING_FONT, MS_LABEL_BINDING_PRIORITY, MS_LABEL_BINDING_POSITION, MS_LABEL_BINDING_SHADOWSIZEX, MS_LABEL_BINDING_SHADOWSIZEY, MS_LABEL_BINDING_OFFSET_X, MS_LABEL_BINDING_OFFSET_Y,MS_LABEL_BINDING_ALIGN };

/************************************************************************/
/* attributeBindingObj */
Expand Down Expand Up @@ -768,7 +768,7 @@ extern "C" {
colorObj *pixel; /* for raster layers */
shapeObj *shape; /* for vector layers */
double dblval; /* for map cellsize used by simplify */
double dblval2; /* for data cellsize */
double dblval2; /* for data cellsize */
expressionObj *expr; /* expression to be evaluated (contains tokens) */
int type; /* type of parse: boolean, string/text or shape/geometry */
parseResultObj result; /* parse result */
Expand Down Expand Up @@ -877,10 +877,10 @@ extern "C" {
long tileindex;
int clear_resultcache;

int maxfeatures; /* global maxfeatures */
int maxfeatures; /* global maxfeatures */
int startindex;
int only_cache_result_count; /* set to 1 sometimes by WFS 2.0 GetFeature request */

expressionObj filter; /* by filter */
char *filteritem;

Expand Down Expand Up @@ -1136,7 +1136,7 @@ extern "C" {

labelLeaderObj *leader;
};

#ifdef SWIG
#ifdef __cplusplus
extern "C" {
Expand All @@ -1153,7 +1153,7 @@ typedef struct labelObj labelObj;
lineObj *poly;
rectObj bbox;
} label_bounds;

typedef struct {
labelObj *label;
char *annotext;
Expand All @@ -1176,14 +1176,14 @@ typedef struct labelObj labelObj;
/* */
/* basic symbolization and classification information */
/************************************************************************/

struct classObj {
#ifndef SWIG
expressionObj expression; /* the expression to be matched */
#endif

int status;
int isfallback; // TRUE if this class should be applied if and only if
int isfallback; // TRUE if this class should be applied if and only if
// no other class is applicable (e.g. SLD <ElseFilter/>)

#ifndef SWIG
Expand Down Expand Up @@ -1574,7 +1574,7 @@ typedef struct labelObj labelObj;
double maxscale;
char *value;
} scaleTokenEntryObj;

typedef struct {
char *name;
int n_entries;
Expand Down Expand Up @@ -1659,7 +1659,7 @@ typedef struct labelObj labelObj;
scaleTokenObj *scaletokens;
int numscaletokens;
originalScaleTokenStrings *orig_st;

#endif

char *data; /* filename, can be relative or full path */
Expand Down Expand Up @@ -1785,7 +1785,7 @@ typedef struct labelObj labelObj;
#endif
char *mask;

#ifndef SWIG
#ifndef SWIG
expressionObj _geomtransform;
#endif

Expand All @@ -1799,7 +1799,7 @@ typedef struct labelObj labelObj;
#ifndef SWIG
sortByClause sortBy;
#endif

LayerCompositer *compositer;

hashTableObj connectionoptions;
Expand Down Expand Up @@ -2533,7 +2533,7 @@ void msPopulateTextSymbolForLabelAndString(textSymbolObj *ts, labelObj *l, char
MS_DLL_EXPORT int msGraticuleLayerInitializeVirtualTable(layerObj *layer);
MS_DLL_EXPORT int msRASTERLayerInitializeVirtualTable(layerObj *layer);
MS_DLL_EXPORT int msUVRASTERLayerInitializeVirtualTable(layerObj *layer);
MS_DLL_EXPORT int msContourLayerInitializeVirtualTable(layerObj *layer);
MS_DLL_EXPORT int msContourLayerInitializeVirtualTable(layerObj *layer);
MS_DLL_EXPORT int msPluginLayerInitializeVirtualTable(layerObj *layer);
MS_DLL_EXPORT int msUnionLayerInitializeVirtualTable(layerObj *layer);
MS_DLL_EXPORT void msPluginFreeVirtualTableFactory(void);
Expand All @@ -2554,7 +2554,7 @@ void msPopulateTextSymbolForLabelAndString(textSymbolObj *ts, labelObj *l, char
MS_DLL_EXPORT int msDrawQueryLayer(mapObj *map, layerObj *layer, imageObj *image);
MS_DLL_EXPORT int msDrawWMSLayer(mapObj *map, layerObj *layer, imageObj *image);
MS_DLL_EXPORT int msDrawWFSLayer(mapObj *map, layerObj *layer, imageObj *image);

#define MS_DRAWMODE_FEATURES 0x00001
#define MS_DRAW_FEATURES(mode) (MS_DRAWMODE_FEATURES&(mode))
#define MS_DRAWMODE_LABELS 0x00002
Expand Down Expand Up @@ -2700,7 +2700,7 @@ void msPopulateTextSymbolForLabelAndString(textSymbolObj *ts, labelObj *l, char
MS_DLL_EXPORT unsigned char *msSaveImageBuffer(imageObj* image, int *size_ptr, outputFormatObj *format);
MS_DLL_EXPORT shapeObj* msOffsetPolyline(shapeObj* shape, double offsetx, double offsety);
MS_DLL_EXPORT int msMapSetLayerProjections(mapObj* map);

/* Functions to chnage the drawing order of the layers. */
/* Defined in mapobject.c */
MS_DLL_EXPORT int msMoveLayerUp(mapObj *map, int nLayerIndex);
Expand Down Expand Up @@ -2946,8 +2946,8 @@ void msPopulateTextSymbolForLabelAndString(textSymbolObj *ts, labelObj *l, char
MS_DLL_EXPORT void msStyleSetGeomTransform(styleObj *s, char *transform);
MS_DLL_EXPORT char *msStyleGetGeomTransform(styleObj *style);

MS_DLL_EXPORT int msGeomTransformShape(mapObj *map, layerObj *layer, shapeObj *shape);
MS_DLL_EXPORT int msGeomTransformShape(mapObj *map, layerObj *layer, shapeObj *shape);

/* ==================================================================== */
/* end of prototypes for functions in mapgeomtransform.c */
/* ==================================================================== */
Expand All @@ -2967,7 +2967,7 @@ void msPopulateTextSymbolForLabelAndString(textSymbolObj *ts, labelObj *l, char
/* prototypes for functions in mapsmoothing.c */
/* ==================================================================== */
MS_DLL_EXPORT shapeObj* msSmoothShapeSIA(shapeObj *shape, int ss, int si, char *preprocessing);

/* ==================================================================== */
/* end of prototypes for functions in mapsmoothing.c */
/* ==================================================================== */
Expand All @@ -2982,7 +2982,7 @@ void msPopulateTextSymbolForLabelAndString(textSymbolObj *ts, labelObj *l, char
MS_DLL_EXPORT char* msV8GetFeatureStyle(mapObj *map, const char *filename,
layerObj *layer, shapeObj *shape);
MS_DLL_EXPORT shapeObj *msV8TransformShape(shapeObj *shape,
const char* filename);
const char* filename);
#endif
/* ==================================================================== */
/* end of prototypes for functions in mapv8.cpp */
Expand Down Expand Up @@ -3112,10 +3112,10 @@ void msPopulateTextSymbolForLabelAndString(textSymbolObj *ts, labelObj *l, char
int msSaveRasterBuffer(mapObj *map, rasterBufferObj *data, FILE *stream, outputFormatObj *format);
int msSaveRasterBufferToBuffer(rasterBufferObj *data, bufferObj *buffer, outputFormatObj *format);
int msLoadMSRasterBufferFromFile(char *path, rasterBufferObj *rb);

/* in mapagg.cpp */
void msApplyBlurringCompositingFilter(rasterBufferObj *rb, unsigned int radius);

int WARN_UNUSED msApplyCompositingFilter(mapObj *map, rasterBufferObj *rb, CompositingFilter *filter);

void msBufferInit(bufferObj *buffer);
Expand Down
Loading

0 comments on commit 89dc335

Please sign in to comment.