Skip to content

Commit 84e0ce8

Browse files
geographikarouault
authored andcommitted
Add a new 'padding' template format option (#5890)
1 parent 7506203 commit 84e0ce8

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

maptemplate.c

+15-1
Original file line numberDiff line numberDiff line change
@@ -1209,6 +1209,7 @@ static int processItemTag(layerObj *layer, char **line, shapeObj *shape)
12091209
const char *name=NULL, *pattern=NULL;
12101210
const char *format=NULL, *nullFormat=NULL;
12111211
int precision;
1212+
int padding;
12121213
int uc, lc, commify;
12131214
int escape;
12141215

@@ -1224,7 +1225,8 @@ static int processItemTag(layerObj *layer, char **line, shapeObj *shape)
12241225
while (tagStart) {
12251226
format = "$value"; /* initialize the tag arguments */
12261227
nullFormat = "";
1227-
precision=-1;
1228+
precision = -1;
1229+
padding = -1;
12281230
name = pattern = NULL;
12291231
uc = lc = commify = MS_FALSE;
12301232
escape=ESCAPE_HTML;
@@ -1241,6 +1243,9 @@ static int processItemTag(layerObj *layer, char **line, shapeObj *shape)
12411243
argValue = msLookupHashTable(tagArgs, "precision");
12421244
if(argValue) precision = atoi(argValue);
12431245

1246+
argValue = msLookupHashTable(tagArgs, "padding");
1247+
if (argValue) padding = atoi(argValue);
1248+
12441249
argValue = msLookupHashTable(tagArgs, "format");
12451250
if(argValue) format = argValue;
12461251

@@ -1310,6 +1315,15 @@ static int processItemTag(layerObj *layer, char **line, shapeObj *shape)
13101315
tagValue = msReplaceSubstring(tagValue, "$value", itemValue);
13111316
msFree(itemValue);
13121317

1318+
if (padding > 0 && padding < 1000) {
1319+
int paddedSize = strlen(tagValue) + padding + 1;
1320+
char *paddedValue = NULL;
1321+
paddedValue = (char *) msSmallMalloc(paddedSize);
1322+
snprintf(paddedValue, paddedSize, "%-*s", padding, tagValue);
1323+
msFree(tagValue);
1324+
tagValue = paddedValue;
1325+
}
1326+
13131327
if(!tagValue) {
13141328
msSetError(MS_WEBERR, "Error applying item format.", "processItemTag()");
13151329
return(MS_FAILURE); /* todo leaking... */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ST. LOUIS :stlo
2+

msautotest/query/query.map

+10
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
# Test 12: simple mode=indexquery, one layer, index query
4040
# RUN_PARMS: query_test012.txt [MAPSERV] QUERY_STRING='map=[MAPFILE]&mode=indexquery&mapext=420000+5120000+582000+5200000&qlayer=bdry_counpy2&shapeindex=5' > [RESULT_DEMIME]
4141
#
42+
# Test 13: simple mode=indexquery, one layer, index query, with formatting
43+
# RUN_PARMS: query_test013.txt [MAPSERV] QUERY_STRING='map=[MAPFILE]&mode=indexquery&mapext=420000+5120000+582000+5200000&qlayer=bdry_counpy2&shapeindex=5&qformat=formattmpl' > [RESULT_DEMIME]
44+
#
4245

4346
MAP
4447
NAME 'query'
@@ -56,6 +59,13 @@ MAP
5659
FORMATOPTION "FILE=template/query.tmpl"
5760
END
5861

62+
OUTPUTFORMAT
63+
NAME 'formattmpl'
64+
DRIVER 'TEMPLATE'
65+
MIMETYPE 'text/html'
66+
FORMATOPTION "FILE=template/query_formatted.tmpl"
67+
END
68+
5969
LAYER
6070
NAME 'bdry_counpy2'
6171
VALIDATION
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<!-- MapServer Template -->
2+
[resultset layer="bdry_counpy2"][feature][item name="cty_name" padding="20" uc="true"]:[item name="cty_abbr" lc="true" padding="10"][/feature][/resultset]
3+

0 commit comments

Comments
 (0)