~ubuntu-branches/ubuntu/saucy/mapserver/saucy-security

« back to all changes in this revision

Viewing changes to shp2pdf.c

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine
  • Date: 2011-12-23 14:02:06 UTC
  • mfrom: (26.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20111223140206-n3h9t2hsa8hyslmu
Tags: 6.0.1-2
Added missed stuff for libmapscript-perl.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/******************************************************************************
2
 
 * $Id: shp2pdf.c 8489 2009-02-03 20:35:24Z tomkralidis $
3
 
 *
4
 
 * Project:  MapServer
5
 
 * Purpose:  Commandline shape to pdf converter.
6
 
 * Author:   Steve Lime and the MapServer team.
7
 
 *
8
 
 ******************************************************************************
9
 
 * Copyright (c) 1996-2005 Regents of the University of Minnesota.
10
 
 *
11
 
 * Permission is hereby granted, free of charge, to any person obtaining a
12
 
 * copy of this software and associated documentation files (the "Software"),
13
 
 * to deal in the Software without restriction, including without limitation
14
 
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15
 
 * and/or sell copies of the Software, and to permit persons to whom the
16
 
 * Software is furnished to do so, subject to the following conditions:
17
 
 *
18
 
 * The above copyright notice and this permission notice shall be included in 
19
 
 * all copies of this Software or works derived from this Software.
20
 
 *
21
 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22
 
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
 
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24
 
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
 
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26
 
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27
 
 * DEALINGS IN THE SOFTWARE.
28
 
 ****************************************************************************/
29
 
 
30
 
#include "mapserver.h"
31
 
 
32
 
MS_CVSID("$Id: shp2pdf.c 8489 2009-02-03 20:35:24Z tomkralidis $")
33
 
 
34
 
#ifdef USE_PDF
35
 
#include <pdflib.h>
36
 
 
37
 
PDF *
38
 
initializePDF(char *filename)
39
 
{
40
 
  PDF *pdf = PDF_new();
41
 
  PDF_open_file(pdf, filename);
42
 
  PDF_set_info(pdf, "Creator", "Mapserver");
43
 
  PDF_set_info(pdf, "Author", "Mapserver");
44
 
  PDF_set_info(pdf, "Title", "Mapserver PDF Map");
45
 
  return pdf;
46
 
}
47
 
 
48
 
void
49
 
releasePDF(PDF *pdf){
50
 
 
51
 
  PDF_end_page(pdf);
52
 
  PDF_close(pdf);
53
 
  PDF_delete(pdf);
54
 
}
55
 
#endif
56
 
 
57
 
 
58
 
int main(int argc, char *argv[])
59
 
{
60
 
#ifndef USE_PDF
61
 
  fprintf(stdout, "%s\n", msGetVersion());
62
 
  fprintf(stdout, "Compiled without PDF support.");
63
 
  exit(0);
64
 
#else
65
 
  int i,j,k;
66
 
 
67
 
  imageObj *image;
68
 
  
69
 
  mapObj *map=NULL;
70
 
  outputFormatObj *format=NULL;
71
 
  /* gdImagePtr       img=NULL; */
72
 
 
73
 
  char **layers=NULL;
74
 
  int num_layers=0;
75
 
 
76
 
  int layer_found=0;
77
 
  char *invalid_layer=NULL;
78
 
 
79
 
  char *outfile=NULL; /* no -o sends image to STDOUT */
80
 
 
81
 
  /* A4 Portrait */
82
 
  int PagePixelWidth = 595;
83
 
  int PagePixelHeight = 842;
84
 
  int PagePixelMargin = 50;
85
 
 
86
 
  if(argc > 1 && strcmp(argv[1], "-v") == 0) {
87
 
    printf("%s\n", msGetVersion());
88
 
    exit(0);
89
 
  }
90
 
 
91
 
  /* ---- check the number of arguments, return syntax if not correct ---- */
92
 
  if( argc < 3 ) {
93
 
    fprintf(stdout, "\nPurpose: convert a mapfile to a PDF document\n\n");
94
 
    fprintf(stdout,"Syntax: shp2pdf -m mapfile -o pdf [-e minx miny maxx maxy] [-l \"layer1 [layers2...]\"] [-t] [-d layername datavalue]\n" );
95
 
    fprintf(stdout,"  -m mapfile: Map file to operate on - required\n" );
96
 
    fprintf(stdout,"  -o pdf: output filename (stdout if not provided)\n");
97
 
    fprintf(stdout,"  -e minx miny maxx maxy: extents to render\n");
98
 
    fprintf(stdout,"  -l layers: layers to enable - make sure they are quoted and space seperated if more than one listed\n" );
99
 
    fprintf(stdout,"  -t : turn on transparency\n");
100
 
    fprintf(stdout,"  -d layername datavalue: change DATA value for a layer\n" );
101
 
    exit(0);
102
 
  }
103
 
 
104
 
  for(i=1;i<argc;i++) { /* Step though the user arguments, 1st to find map file */
105
 
 
106
 
    if(strncmp(argv[i],"-m",2) == 0) {
107
 
      map = msLoadMap(argv[i+1], NULL);
108
 
      if(!map) {
109
 
    msWriteError(stderr);
110
 
    exit(0);
111
 
      }
112
 
    }
113
 
  }
114
 
 
115
 
  if(!map) {
116
 
    fprintf(stderr, "Mapfile (-m) option not specified.\n");
117
 
    exit(0);
118
 
  }
119
 
 
120
 
  for(i=1;i<argc;i++) { /* Step though the user arguments */
121
 
 
122
 
    if(strncmp(argv[i],"-m",2) == 0) { /* skip it */
123
 
      i+=1;
124
 
    }
125
 
 
126
 
    if(strncmp(argv[i],"-o",2) == 0) {
127
 
      outfile = strdup(argv[i+1]);
128
 
      i+=1;
129
 
    }
130
 
 
131
 
    if(strncmp(argv[i],"-d",2) == 0) { /* swap layer data */
132
 
      for(j=0; j<map->numlayers; j++) {
133
 
     if(strcmp(GET_LAYER(map, j)->name, argv[i+1]) == 0) {
134
 
       free(GET_LAYER(map, j)->data);
135
 
       GET_LAYER(map, j)->data = strdup(argv[i+2]);
136
 
       break;
137
 
     }
138
 
      }
139
 
      i+=2;
140
 
    }
141
 
 
142
 
    /*if(strncmp(argv[i], "-t", 2) == 0)  transparency
143
 
      map->transparent = MS_ON;*/
144
 
 
145
 
    if(strncmp(argv[i],"-e",2) == 0) { /* change extent */
146
 
      map->extent.minx = atof(argv[i+1]);
147
 
      map->extent.miny = atof(argv[i+2]);
148
 
      map->extent.maxx = atof(argv[i+3]);
149
 
      map->extent.maxy = atof(argv[i+4]);
150
 
      i+=4;
151
 
    }
152
 
    format = msCreateDefaultOutputFormat(map, "pdf");
153
 
    map->outputformat = format;
154
 
 
155
 
    if(strncmp(argv[i],"-l",2) == 0) { /* load layer list */
156
 
      layers = msStringSplit(argv[i+1], ' ', &(num_layers));
157
 
 
158
 
      for(j=0; j<num_layers; j++) { /* loop over -l */
159
 
        layer_found=0;
160
 
        for(k=0; k<map->numlayers; k++) {
161
 
          if(GET_LAYER(map, k)->name && strcmp(GET_LAYER(map, k)->name, layers[j]) == 0) {
162
 
            layer_found=1;
163
 
            break;
164
 
          }
165
 
          else {
166
 
            invalid_layer = strdup(layers[j]);
167
 
          }
168
 
        }
169
 
        if (layer_found==0) {
170
 
          fprintf(stderr, "Layer (-l) %s not found\n", invalid_layer);
171
 
          msCleanup();
172
 
          exit(0);
173
 
        }
174
 
      }
175
 
 
176
 
      for(j=0; j<map->numlayers; j++) {
177
 
        if(GET_LAYER(map, j)->status == MS_DEFAULT)
178
 
          continue;
179
 
        else {
180
 
          GET_LAYER(map, j)->status = MS_OFF;
181
 
          for(k=0; k<num_layers; k++) {
182
 
            if(strcmp(GET_LAYER(map, j)->name, layers[k]) == 0) {
183
 
              GET_LAYER(map, j)->status = MS_ON;
184
 
              break;
185
 
            }
186
 
          }
187
 
        }
188
 
      }
189
 
      msFreeCharArray(layers, num_layers);
190
 
 
191
 
      i+=1;
192
 
     }
193
 
  }
194
 
 
195
 
  /*gdImageDestroy(img);*/
196
 
  map->height = PagePixelHeight-(2*PagePixelMargin);
197
 
  map->width = PagePixelWidth-(2*PagePixelMargin);
198
 
  image = msDrawMap(map, MS_FALSE);
199
 
  msSaveImage(map, image, outfile);
200
 
    
201
 
  msFreeMap(map);
202
 
  free(outfile);
203
 
#endif
204
 
  return(0);
205
 
} /* ---- END Main Routine ---- */