~ubuntu-branches/ubuntu/quantal/cups-filters/quantal-updates

« back to all changes in this revision

Viewing changes to pdftoopvp/pdftoopvp.cxx

  • Committer: Package Import Robot
  • Author(s): Till Kamppeter
  • Date: 2012-07-28 11:54:32 UTC
  • mfrom: (1.1.17) (22 sid)
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: package-import@ubuntu.com-20120728115432-p5fgn9hv6du22cqa
* New upstream release
   - pdftops: Added another workaround for Kyocera printers: Some
     models get very slow on images which request interpolation,
     so now we remove the image interpolation requests by additional
     PostScript code only inserted for Kyocera printers (LP: #1026974).
   - Made the Poppler-based filters pdftopdf and pdftoopvp build with
     both Poppler 0.18.x and 0.20.x (Upstream bug #1055).
   - Fixes according to Coverity scan results (Upstream bug #1054).
   - Switched build system to autotools. This especially fixes several
     build problems in Gentoo. Also build-tested with CUPS 1.6.0b1.
   - Fixes for compatibility with clang/gcc-4.7.
   - textonly: Filter did not work as a pipe with copies=1 (Upstream bug
     #1032).
   - texttopdf: Avoid trimming the results of FcFontSort(), as this may
     miss some reasonable candidates under certain circumstances. BTW,
     fix passing a non-pointer as a pointer to "result" (Closes: #670055).
   - Corrected documentation. The option for the maximum image rendering
     resolution in pdftops is "pdftops-max-image-resolution", not
     "pdftops-max-image-resolution-default".
* debian/patches/fcfontsort-no-trim.patch: Removed, fixed upstream.
* debian/rules: Updated options for ./configure and make for the new autotools
  build system.
* debian/watch: Switched to bz2 upstream packages.
* debian/rules, debian/copyright, debian/cups-filters.docs: Updated for
  renamed documentation files.
* debian/control, debian/libfontembed1.install,
  debian/libfontembed-dev.install: Added new binary packages for libfontembed.
* debian/copyright: Updated for recent file additions, and rearrangement of
  directories.
* debian/control: Added missing build dependency on libpoppler-cpp-dev.
* debian/copyright: Corrections (Closes: #682752).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//========================================================================
2
 
//
3
 
// pdftoopvp.cc
4
 
//
5
 
// Copyright 2005 AXE,Inc.
6
 
//
7
 
// 2007,2008,2009 Modified by BBR Inc.
8
 
//========================================================================
9
 
 
10
 
#include <config.h>
11
 
#include <stdio.h>
12
 
#include <stdlib.h>
13
 
#include <unistd.h>
14
 
#include <ctype.h>
15
 
#include <math.h>
16
 
#include "goo/GooString.h"
17
 
#define GSTRING_H // for old GooString.h
18
 
#include "goo/gmem.h"
19
 
#include "GlobalParams.h"
20
 
#include "Object.h"
21
 
#include "PDFDoc.h"
22
 
#include "splash/SplashBitmap.h"
23
 
#include "OPRS.h"
24
 
#include "OPVPOutputDev.h"
25
 
#include "Gfx.h"
26
 
#include <cups/cups.h>
27
 
#include <cups/ppd.h>
28
 
#include "Error.h"
29
 
#include "mcheck.h"
30
 
 
31
 
#define MMPERINCH (25.4)
32
 
 
33
 
static int resolution = 300;
34
 
static int hResolution = 0;
35
 
static int vResolution = 0;
36
 
static GBool mono = gFalse;
37
 
static GBool reverse = gFalse;
38
 
static GBool gray = gFalse;
39
 
static char enableFreeTypeStr[16] = "";
40
 
static GBool quiet = gFalse;
41
 
static char outputOrderStr[256] = "";
42
 
static GBool oldLipsDriver = gFalse;
43
 
static GBool HPDriver = gFalse;
44
 
static GBool NECDriver = gFalse;
45
 
static GBool clipPathNotSaved = gFalse;
46
 
static GBool noShearImage = gFalse;
47
 
static GBool noLineStyle = gFalse;
48
 
static GBool noImageMask = gFalse;
49
 
static GBool noClipPath = gFalse;
50
 
static GBool ignoreMiterLimit = gFalse;
51
 
static GBool noMiterLimit = gFalse;
52
 
static char printerDriver[1024] = "";
53
 
static char printerModel[1024] = "";
54
 
static char jobInfo[4096] = "";
55
 
static char docInfo[1024] = "";
56
 
static char pageInfo[1024] = "";
57
 
static GBool noBitmapChar = gFalse;
58
 
static char bitmapCharThreshold[20] = "2000";
59
 
static char maxClipPathLength[20] = "2000";
60
 
static char maxFillPathLength[20] = "4000";
61
 
static int pageWidth = -1;
62
 
static int pageHeight = -1;
63
 
 
64
 
static int outOnePage(PDFDoc *doc, OPVPOutputDev *opvpOut, int pg)
65
 
{
66
 
  char buf[1024];
67
 
  char *p;
68
 
  double pw = doc->getPageMediaWidth(pg);
69
 
  double ph = doc->getPageMediaHeight(pg);
70
 
  int paperWidth;
71
 
  int paperHeight;
72
 
 
73
 
  if (pw != pageWidth || ph != pageHeight) {
74
 
    if (pageInfo[0] != '\0') {
75
 
      snprintf(buf,sizeof(buf),"%s;MediaSize=%dx%dmm",pageInfo,
76
 
       (int)(pw*MMPERINCH/72),
77
 
       (int)(ph*MMPERINCH/72));
78
 
    } else {
79
 
      snprintf(buf,sizeof(buf),"MediaSize=%dx%dmm",
80
 
       (int)(pw*MMPERINCH/72),
81
 
       (int)(ph*MMPERINCH/72));
82
 
    }
83
 
    p = buf;
84
 
  } else {
85
 
    pw = pageWidth;
86
 
    ph = pageHeight;
87
 
    p = pageInfo;
88
 
  }
89
 
 
90
 
  paperWidth = (int)(pw*hResolution/72+0.5);
91
 
  paperHeight = (int)(ph*vResolution/72+0.5);
92
 
  if (opvpOut->OPVPStartPage(p,paperWidth,paperHeight) < 0) {
93
 
      error(-1,"Start Page failed");
94
 
      return 2;
95
 
  }
96
 
  opvpOut->setScale(1.0,1.0,0,0,0,0,paperHeight);
97
 
  doc->displayPage(opvpOut, pg, resolution, resolution,
98
 
    0, gTrue, gTrue, gFalse);
99
 
  if (opvpOut->outSlice() < 0) {
100
 
    error(-1,"OutSlice failed");
101
 
    return 2;
102
 
  }
103
 
  if (opvpOut->OPVPEndPage() < 0) {
104
 
      error(-1,"End Page failed");
105
 
      return 2;
106
 
  }
107
 
  return 0;
108
 
}
109
 
 
110
 
#define MAX_OPVP_OPTIONS 20
111
 
 
112
 
void CDECL myErrorFun(int pos, char *msg, va_list args)
113
 
{
114
 
  if (pos >= 0) {
115
 
    fprintf(stderr, "ERROR (%d): ", pos);
116
 
  } else {
117
 
    fprintf(stderr, "ERROR: ");
118
 
  }
119
 
  vfprintf(stderr, msg, args);
120
 
  fprintf(stderr, "\n");
121
 
  fflush(stderr);
122
 
}
123
 
 
124
 
static GBool getColorProfilePath(ppd_file_t *ppd, GooString *path)
125
 
{
126
 
    // get color profile path
127
 
    char *colorModel;
128
 
    char *cupsICCQualifier2;
129
 
    char *cupsICCQualifier2Choice;
130
 
    char *cupsICCQualifier3;
131
 
    char *cupsICCQualifier3Choice;
132
 
    ppd_attr_t *attr;
133
 
    ppd_choice_t *choice;
134
 
 
135
 
    if ((attr = ppdFindAttr(ppd,"ColorModel",NULL)) != NULL) {
136
 
        colorModel = attr->value;
137
 
    } else {
138
 
        colorModel = NULL;
139
 
    }
140
 
    if ((attr = ppdFindAttr(ppd,"cupsICCQualifier2",NULL)) != NULL) {
141
 
        cupsICCQualifier2 = attr->value;
142
 
    } else {
143
 
        cupsICCQualifier2 = "MediaType";
144
 
    }
145
 
    if ((choice = ppdFindMarkedChoice(ppd,cupsICCQualifier2)) != NULL) {
146
 
        cupsICCQualifier2Choice = choice->choice;
147
 
    } else {
148
 
        cupsICCQualifier2Choice = NULL;
149
 
    }
150
 
    if ((attr = ppdFindAttr(ppd,"cupsICCQualifier3",NULL)) != NULL) {
151
 
        cupsICCQualifier3 = attr->value;
152
 
    } else {
153
 
        cupsICCQualifier3 = "Resolution";
154
 
    }
155
 
    if ((choice = ppdFindMarkedChoice(ppd,cupsICCQualifier3)) != NULL) {
156
 
        cupsICCQualifier3Choice = choice->choice;
157
 
    } else {
158
 
        cupsICCQualifier3Choice = NULL;
159
 
    }
160
 
 
161
 
    for (attr = ppdFindAttr(ppd,"cupsICCProfile",NULL);attr != NULL;
162
 
       attr = ppdFindNextAttr(ppd,"cupsICCProfile",NULL)) {
163
 
        // check color model
164
 
        char buf[PPD_MAX_NAME];
165
 
        char *p, *r;
166
 
 
167
 
        strncpy(buf,attr->spec,sizeof(buf));
168
 
        if ((p = strchr(buf,'.')) != NULL) {
169
 
            *p = '\0';
170
 
        }
171
 
        if (colorModel != NULL && buf[0] != '\0'
172
 
            && strcasecmp(buf,colorModel) != 0) continue;
173
 
        if (p == NULL) {
174
 
            break;
175
 
        } else {
176
 
            p++;
177
 
            if ((r = strchr(p,'.')) != 0) {
178
 
                *r = '\0';
179
 
            }
180
 
        }
181
 
        if (cupsICCQualifier2Choice != NULL && p[0] != '\0'
182
 
            && strcasecmp(p,cupsICCQualifier2Choice) != 0) continue;
183
 
        if (r == NULL) {
184
 
            break;
185
 
        } else {
186
 
            r++;
187
 
            if ((p = strchr(r,'.')) != 0) {
188
 
                *p = '\0';
189
 
            }
190
 
        }
191
 
        if (cupsICCQualifier3Choice == NULL || r[0] == '\0'
192
 
            || strcasecmp(r,cupsICCQualifier3Choice) == 0) break;
193
 
    }
194
 
    if (attr != NULL) {
195
 
        // matched
196
 
        path->clear();
197
 
        if (attr->value[0] != '/') {
198
 
            path->append(CUPS_DATADIR);
199
 
            path->append("/profiles/");
200
 
        }
201
 
        path->append(attr->value);
202
 
        return gTrue;
203
 
    }
204
 
    return gFalse;
205
 
}
206
 
 
207
 
int main(int argc, char *argv[]) {
208
 
/* mtrace(); */
209
 
  int exitCode;
210
 
{
211
 
  PDFDoc *doc;
212
 
  SplashColor paperColor;
213
 
  OPVPOutputDev *opvpOut;
214
 
  GBool ok = gTrue;
215
 
  int pg;
216
 
  char *optionKeys[MAX_OPVP_OPTIONS];
217
 
  char *optionVals[MAX_OPVP_OPTIONS];
218
 
  int nOptions = 0;
219
 
  int numPages;
220
 
  int i;
221
 
  GooString fileName;
222
 
  GooString colorProfilePath("opvp.icc");
223
 
 
224
 
  exitCode = 99;
225
 
  setErrorFunction(::myErrorFun);
226
 
 
227
 
  // parse args
228
 
  int num_options;
229
 
  cups_option_t *options;
230
 
  const char *val;
231
 
  char *ppdFileName;
232
 
  ppd_file_t *ppd = 0;
233
 
  ppd_attr_t *attr;
234
 
  GooString jobInfoStr;
235
 
  GooString docInfoStr;
236
 
  GooString pageInfoStr;
237
 
  GBool colorProfile = gFalse;
238
 
 
239
 
 
240
 
  if (argc < 6 || argc > 7) {
241
 
    error(-1,"ERROR: %s job-id user title copies options [file]",
242
 
      argv[0]);
243
 
    return (1);
244
 
  }
245
 
 
246
 
  if ((ppdFileName = getenv("PPD")) != 0) {
247
 
    if ((ppd = ppdOpenFile(ppdFileName)) != 0) {
248
 
      /* get attributes from PPD File */
249
 
      if ((attr = ppdFindAttr(ppd,"opvpJobInfo",0)) != 0) {
250
 
        jobInfoStr.append(attr->value);
251
 
      }
252
 
      if ((attr = ppdFindAttr(ppd,"opvpDocInfo",0)) != 0) {
253
 
        docInfoStr.append(attr->value);
254
 
      }
255
 
      if ((attr = ppdFindAttr(ppd,"opvpPageInfo",0)) != 0) {
256
 
        pageInfoStr.append(attr->value);
257
 
      }
258
 
      if ((attr = ppdFindAttr(ppd,"pdftoopvpOldLipsDriver",0)) != 0) {
259
 
        if (strcasecmp(attr->value,"true") == 0) {
260
 
          oldLipsDriver = gTrue;
261
 
        } else {
262
 
          oldLipsDriver = gFalse;
263
 
        }
264
 
      }
265
 
      if ((attr = ppdFindAttr(ppd,"pdftoopvpHPDriver",0)) != 0) {
266
 
        if (strcasecmp(attr->value,"true") == 0) {
267
 
          HPDriver = gTrue;
268
 
        } else {
269
 
          HPDriver = gFalse;
270
 
        }
271
 
      }
272
 
      if ((attr = ppdFindAttr(ppd,"pdftoopvpNECDriver",0)) != 0) {
273
 
        if (strcasecmp(attr->value,"true") == 0) {
274
 
          NECDriver = gTrue;
275
 
        } else {
276
 
          NECDriver = gFalse;
277
 
        }
278
 
      }
279
 
      if ((attr = ppdFindAttr(ppd,"pdftoopvpClipPathNotSaved",0)) != 0) {
280
 
        if (strcasecmp(attr->value,"true") == 0) {
281
 
          clipPathNotSaved = gTrue;
282
 
        } else {
283
 
          clipPathNotSaved = gFalse;
284
 
        }
285
 
      }
286
 
      if ((attr = ppdFindAttr(ppd,"pdftoopvpShearImage",0)) != 0) {
287
 
        if (strcasecmp(attr->value,"true") == 0) {
288
 
          noShearImage = gFalse;
289
 
        } else {
290
 
          noShearImage = gTrue;
291
 
        }
292
 
      }
293
 
      if ((attr = ppdFindAttr(ppd,"pdftoopvpLineStyle",0)) != 0) {
294
 
        if (strcasecmp(attr->value,"true") == 0) {
295
 
          noLineStyle = gFalse;
296
 
        } else {
297
 
          noLineStyle = gTrue;
298
 
        }
299
 
      }
300
 
      if ((attr = ppdFindAttr(ppd,"pdftoopvpImageMask",0)) != 0) {
301
 
        if (strcasecmp(attr->value,"true") == 0) {
302
 
          noImageMask = gFalse;
303
 
        } else {
304
 
          noImageMask = gTrue;
305
 
        }
306
 
      }
307
 
      if ((attr = ppdFindAttr(ppd,"pdftoopvpClipPath",0)) != 0) {
308
 
        if (strcasecmp(attr->value,"true") == 0) {
309
 
          noClipPath = gFalse;
310
 
        } else {
311
 
          noClipPath = gTrue;
312
 
        }
313
 
      }
314
 
      if ((attr = ppdFindAttr(ppd,"pdftoopvpMiterLimit",0)) != 0) {
315
 
        if (strcasecmp(attr->value,"true") == 0) {
316
 
          noMiterLimit = gFalse;
317
 
        } else {
318
 
          noMiterLimit = gTrue;
319
 
        }
320
 
      }
321
 
      if ((attr = ppdFindAttr(ppd,"pdftoopvpIgnoreMiterLimit",0)) != 0) {
322
 
        if (strcasecmp(attr->value,"true") == 0) {
323
 
          ignoreMiterLimit = gTrue;
324
 
        } else {
325
 
          ignoreMiterLimit = gFalse;
326
 
        }
327
 
      }
328
 
      if ((attr = ppdFindAttr(ppd,"pdftoopvpBitmapCharThreshold",0)) != 0) {
329
 
        strncpy(bitmapCharThreshold,attr->value,
330
 
          sizeof(bitmapCharThreshold)-1);
331
 
      }
332
 
      if ((attr = ppdFindAttr(ppd,"pdftoopvpMaxClipPathLength",0)) != 0) {
333
 
        strncpy(maxClipPathLength,attr->value,
334
 
          sizeof(maxClipPathLength)-1);
335
 
      }
336
 
      if ((attr = ppdFindAttr(ppd,"pdftoopvpMaxFillPathLength",0)) != 0) {
337
 
        strncpy(maxFillPathLength,attr->value,
338
 
          sizeof(maxFillPathLength)-1);
339
 
      }
340
 
      if ((attr = ppdFindAttr(ppd,"pdftoopvpBitmapChar",0)) != 0) {
341
 
        if (strcasecmp(attr->value,"true") == 0) {
342
 
          noBitmapChar = gFalse;
343
 
        } else {
344
 
          noBitmapChar = gTrue;
345
 
        }
346
 
      }
347
 
      if ((attr = ppdFindAttr(ppd,"opvpDriver",0)) != 0) {
348
 
          strncpy(printerDriver,attr->value,sizeof(printerDriver)-1);
349
 
          printerDriver[sizeof(printerDriver)-1] = '\0';
350
 
      }
351
 
      if ((attr = ppdFindAttr(ppd,"opvpModel",0)) != 0) {
352
 
          strncpy(printerModel,attr->value,sizeof(printerModel)-1);
353
 
          printerModel[sizeof(printerModel)-1] = '\0';
354
 
      }
355
 
      ppdMarkDefaults(ppd);
356
 
    }
357
 
  }
358
 
  /* get attributes and options from command line option */
359
 
  num_options = cupsParseOptions(argv[5],0,&options);
360
 
  cupsMarkOptions(ppd,num_options,options);
361
 
 
362
 
  for (i = 0;i < num_options;i++) {
363
 
    if (strcasecmp(options[i].name,"Resolution") == 0) {
364
 
      resolution = atoi(options[i].value);
365
 
    } else if (strcasecmp(options[i].name,"pdftoopvpOldLipsDriver") == 0) {
366
 
      oldLipsDriver = gTrue;
367
 
    } else if (strcasecmp(options[i].name,"pdftoopvpHPDriver") == 0) {
368
 
      HPDriver = gTrue;
369
 
    } else if (strcasecmp(options[i].name,"pdftoopvpNECDriver") == 0) {
370
 
      NECDriver = gTrue;
371
 
    } else if (strcasecmp(options[i].name,"pdftoopvpClipPathNotSaved") == 0) {
372
 
      clipPathNotSaved = gTrue;
373
 
    } else if (strcasecmp(options[i].name,"pdftoopvpShearImage") == 0) {
374
 
      if (strcasecmp(options[i].value,"false") == 0) {
375
 
        noShearImage = gTrue;
376
 
      }
377
 
    } else if (strcasecmp(options[i].name,"pdftoopvpLineStyle") == 0) {
378
 
      if (strcasecmp(options[i].value,"false") == 0) {
379
 
        noLineStyle = gTrue;
380
 
      }
381
 
    } else if (strcasecmp(options[i].name,"pdftoopvpImageMask") == 0) {
382
 
      if (strcasecmp(options[i].value,"false") == 0) {
383
 
        noImageMask = gTrue;
384
 
      }
385
 
    } else if (strcasecmp(options[i].name,"pdftoopvpClipPath") == 0) {
386
 
      if (strcasecmp(options[i].value,"false") == 0) {
387
 
        noClipPath = gTrue;
388
 
      }
389
 
    } else if (strcasecmp(options[i].name,"pdftoopvpMiterLimit") == 0) {
390
 
      if (strcasecmp(options[i].value,"false") == 0) {
391
 
        noMiterLimit = gTrue;
392
 
      }
393
 
    } else if (strcasecmp(options[i].name,"pdftoopvpIgnoreMiterLimit") == 0) {
394
 
      if (strcasecmp(options[i].value,"true") == 0) {
395
 
        ignoreMiterLimit = gTrue;
396
 
      }
397
 
    }
398
 
     else if (strcasecmp(options[i].name,"pdftoopvpBitmapChar") == 0) {
399
 
      if (strcasecmp(options[i].value,"false") == 0) {
400
 
        noBitmapChar = gTrue;
401
 
      }
402
 
    } else if (strcasecmp(options[i].name,"pdftoopvpBitmapCharThreshold") == 0) {
403
 
      strncpy(bitmapCharThreshold,options[i].value,
404
 
        sizeof(bitmapCharThreshold)-1);
405
 
    } else if (strcasecmp(options[i].name,"pdftoopvpMaxClipPathLength") == 0) {
406
 
      strncpy(maxClipPathLength,options[i].value,
407
 
        sizeof(maxClipPathLength)-1);
408
 
    } else if (strcasecmp(options[i].name,"pdftoopvpMaxFillPathLength") == 0) {
409
 
      strncpy(maxFillPathLength,options[i].value,
410
 
        sizeof(maxFillPathLength)-1);
411
 
    } else if (strcasecmp(options[i].name,"opvpDriver") == 0) {
412
 
      strncpy(printerDriver,options[i].value,sizeof(printerDriver)-1);
413
 
      printerDriver[sizeof(printerDriver)-1] = '\0';
414
 
    } else if (strcasecmp(options[i].name,"opvpModel") == 0) {
415
 
      strncpy(printerModel,options[i].value,sizeof(printerModel)-1);
416
 
      printerModel[sizeof(printerModel)-1] = '\0';
417
 
    } else if (strcasecmp(options[i].name,"opvpJobInfo") == 0) {
418
 
      /* do nothing here */;
419
 
    } else if (strcasecmp(options[i].name,"opvpDocInfo") == 0) {
420
 
      /* do nothing here */;
421
 
    } else if (strcasecmp(options[i].name,"opvpPageInfo") == 0) {
422
 
      /* do nothing here */;
423
 
    }
424
 
  }
425
 
  if (ppd != 0) {
426
 
    int section;
427
 
    ppd_choice_t **choices;
428
 
    ppd_size_t *pagesize;
429
 
 
430
 
    if ((pagesize = ppdPageSize(ppd,0)) != 0) {
431
 
      pageWidth = (int)pagesize->width;
432
 
      pageHeight = (int)pagesize->length;
433
 
    }
434
 
    for (section = (int)PPD_ORDER_ANY;
435
 
      section <= (int)PPD_ORDER_PROLOG;section++) {
436
 
      int n;
437
 
 
438
 
      n = ppdCollect(ppd,(ppd_section_t)section,&choices);
439
 
      for (i = 0;i < n;i++) {
440
 
 
441
 
        if (strcasecmp(((ppd_option_t *)(choices[i]->option))->keyword,
442
 
           "Resolution") == 0) {
443
 
          resolution = atoi(choices[i]->choice);
444
 
        }
445
 
      }
446
 
      if (choices != 0) free(choices);
447
 
    }
448
 
 
449
 
    strncpy(jobInfo,jobInfoStr.getCString(),sizeof(jobInfo)-1);
450
 
    jobInfo[sizeof(jobInfo)-1] = '\0';
451
 
    strncpy(docInfo,docInfoStr.getCString(),sizeof(docInfo)-1);
452
 
    docInfo[sizeof(docInfo)-1] = '\0';
453
 
    strncpy(pageInfo,pageInfoStr.getCString(),sizeof(pageInfo)-1);
454
 
    pageInfo[sizeof(pageInfo)-1] = '\0';
455
 
 
456
 
    colorProfile = getColorProfilePath(ppd,&colorProfilePath);
457
 
 
458
 
    ppdClose(ppd);
459
 
  }
460
 
  if ((val = cupsGetOption("opvpJobInfo",num_options, options)) != 0) {
461
 
    /* override ppd value */
462
 
    strncpy(jobInfo,val,sizeof(jobInfo)-1);
463
 
    jobInfo[sizeof(jobInfo)-1] = '\0';
464
 
  }
465
 
  if ((val = cupsGetOption("opvpDocInfo",num_options, options)) != 0) {
466
 
    /* override ppd value */
467
 
    strncpy(docInfo,val,sizeof(docInfo)-1);
468
 
    docInfo[sizeof(docInfo)-1] = '\0';
469
 
  }
470
 
  if ((val = cupsGetOption("opvpPageInfo",num_options, options)) != 0) {
471
 
    /* override ppd value */
472
 
    strncpy(pageInfo,val,sizeof(pageInfo)-1);
473
 
    pageInfo[sizeof(pageInfo)-1] = '\0';
474
 
  }
475
 
 
476
 
  cupsFreeOptions(num_options,options);
477
 
#if 0
478
 
  /* for debug parameters */
479
 
  fprintf(stderr,"WARNING:resolution=%d\n",resolution);
480
 
  fprintf(stderr,"WARNING:sliceHeight=%d\n",sliceHeight);
481
 
  fprintf(stderr,"WARNING:oldLipsDriver=%d\n",oldLipsDriver);
482
 
  fprintf(stderr,"WARNING:HPDriver=%d\n",HPDriver);
483
 
  fprintf(stderr,"WARNING:NECDriver=%d\n",NECDriver);
484
 
  fprintf(stderr,"WARNING:clipPathNotSaved=%d\n",clipPathNotSaved);
485
 
  fprintf(stderr,"WARNING:noShearImage=%d\n",noShearImage);
486
 
  fprintf(stderr,"WARNING:noLineStyle=%d\n",noLineStyle);
487
 
  fprintf(stderr,"WARNING:noClipPath=%d\n",noClipPath);
488
 
  fprintf(stderr,"WARNING:noMiterLimit=%d\n",noMiterLimit);
489
 
  fprintf(stderr,"WARNING:printerDriver=%s\n",printerDriver);
490
 
  fprintf(stderr,"WARNING:printerModel=%s\n",printerModel);
491
 
  fprintf(stderr,"WARNING:jobInfo=%s\n",jobInfo);
492
 
  fprintf(stderr,"WARNING:docInfo=%s\n",docInfo);
493
 
  fprintf(stderr,"WARNING:pageInfo=%s\n",pageInfo);
494
 
  fprintf(stderr,"WARNING:noBitmapChar=%d\n",noBitmapChar);
495
 
  fprintf(stderr,"WARNING:bitmapCharThreshold=%s\n",bitmapCharThreshold);
496
 
  fprintf(stderr,"WARNING:maxClipPathLength=%s\n",maxClipPathLength);
497
 
  fprintf(stderr,"WARNING:maxFillPathLength=%s\n",maxFillPathLength);
498
 
exit(0);
499
 
#endif
500
 
 
501
 
  if (oldLipsDriver) {
502
 
    optionKeys[nOptions] = "OPVP_OLDLIPSDRIVER";
503
 
    optionVals[nOptions] = "1";
504
 
    nOptions++;
505
 
    clipPathNotSaved = gTrue;
506
 
    noShearImage = gTrue;
507
 
  }
508
 
  if (HPDriver) {
509
 
    noClipPath = gTrue;
510
 
    noLineStyle = gTrue;
511
 
    noShearImage = gTrue;
512
 
  }
513
 
  if (NECDriver) {
514
 
    noMiterLimit = gTrue;
515
 
    strcpy(maxClipPathLength,"6");
516
 
    noShearImage = gTrue;
517
 
  }
518
 
  if (clipPathNotSaved) {
519
 
    optionKeys[nOptions] = "OPVP_CLIPPATHNOTSAVED";
520
 
    optionVals[nOptions] = "1";
521
 
    nOptions++;
522
 
  }
523
 
  if (noShearImage) {
524
 
    optionKeys[nOptions] = "OPVP_NOSHEARIMAGE";
525
 
    optionVals[nOptions] = "1";
526
 
    nOptions++;
527
 
  }
528
 
  if (noLineStyle) {
529
 
    optionKeys[nOptions] = "OPVP_NOLINESTYLE";
530
 
    optionVals[nOptions] = "1";
531
 
    nOptions++;
532
 
  }
533
 
  if (noImageMask) {
534
 
    optionKeys[nOptions] = "OPVP_NOIMAGEMASK";
535
 
    optionVals[nOptions] = "1";
536
 
    nOptions++;
537
 
  }
538
 
  if (noClipPath) {
539
 
    optionKeys[nOptions] = "OPVP_NOCLIPPATH";
540
 
    optionVals[nOptions] = "1";
541
 
    nOptions++;
542
 
  }
543
 
  if (noMiterLimit) {
544
 
    optionKeys[nOptions] = "OPVP_NOMITERLIMIT";
545
 
    optionVals[nOptions] = "1";
546
 
    nOptions++;
547
 
  }
548
 
  if (noBitmapChar) {
549
 
    optionKeys[nOptions] = "OPVP_NOBITMAPCHAR";
550
 
    optionVals[nOptions] = "1";
551
 
    nOptions++;
552
 
  }
553
 
  if (ignoreMiterLimit) {
554
 
    optionKeys[nOptions] = "OPVP_IGNOREMITERLIMIT";
555
 
    optionVals[nOptions] = "1";
556
 
    nOptions++;
557
 
  }
558
 
  optionKeys[nOptions] = "OPVP_BITMAPCHARTHRESHOLD";
559
 
  optionVals[nOptions] = bitmapCharThreshold;
560
 
  nOptions++;
561
 
  optionKeys[nOptions] = "OPVP_MAXCLIPPATHLENGTH";
562
 
  optionVals[nOptions] = maxClipPathLength;
563
 
  nOptions++;
564
 
  optionKeys[nOptions] = "OPVP_MAXFILLPATHLENGTH";
565
 
  optionVals[nOptions] = maxFillPathLength;
566
 
  nOptions++;
567
 
  if (hResolution == 0) hResolution = resolution;
568
 
  if (hResolution == 0) hResolution = resolution;
569
 
  if (vResolution == 0) vResolution = resolution;
570
 
  if (strcasecmp(outputOrderStr,"reverse") == 0) {
571
 
    reverse = gTrue;
572
 
  }
573
 
 
574
 
  if (argc > 6) {
575
 
    fileName.append(argv[6]);
576
 
  } else {
577
 
    fileName.append("-");
578
 
  }
579
 
 
580
 
  // read config file
581
 
  globalParams = new GlobalParams();
582
 
  if (enableFreeTypeStr[0]) {
583
 
    if (!globalParams->setEnableFreeType(enableFreeTypeStr)) {
584
 
      error(-1,"Bad '-freetype' value on command line");
585
 
      ok = gFalse;
586
 
    }
587
 
  }
588
 
  globalParams->setAntialias("no");
589
 
  if (quiet) {
590
 
    globalParams->setErrQuiet(quiet);
591
 
  }
592
 
  if (!ok) {
593
 
    exitCode = 2;
594
 
    goto err0;
595
 
  }
596
 
 
597
 
  if (fileName.cmp("-") == 0) {
598
 
    /* stdin */
599
 
    char *s;
600
 
    GooString name;
601
 
    int fd;
602
 
    Object obj;
603
 
    BaseStream *str;
604
 
    FILE *fp;
605
 
    char buf[4096];
606
 
    int n;
607
 
 
608
 
    /* create a tmp file */
609
 
    if ((s = getenv("TMPDIR")) != 0) {
610
 
      name.append(s);
611
 
    } else {
612
 
      name.append("/tmp");
613
 
    }
614
 
    name.append("/XXXXXX");
615
 
    fd = mkstemp(name.getCString());
616
 
    /* remove name */
617
 
    unlink(name.getCString());
618
 
    if (fd < 0) {
619
 
      error(-1,"Can't create temporary file");
620
 
      exitCode = 2;
621
 
      goto err0;
622
 
    }
623
 
 
624
 
    /* check JCL */
625
 
    while (fgets(buf,sizeof(buf)-1,stdin) != NULL
626
 
        && strncmp(buf,"%PDF",4) != 0) {
627
 
      if (strncmp(buf,"pdftoopvp jobInfo:",18) == 0) {
628
 
        /* JCL jobInfo exists, override jobInfo */
629
 
        strncpy(jobInfo,buf+18,sizeof(jobInfo)-1);
630
 
        for (i = sizeof(jobInfo)-2;i >= 0
631
 
          && (jobInfo[i] == 0 || jobInfo[i] == '\n' || jobInfo[i] == ';')
632
 
          ;i--);
633
 
        jobInfo[i+1] = 0;
634
 
      }
635
 
    }
636
 
    if (strncmp(buf,"%PDF",4) != 0) {
637
 
      error(-1,"Can't find PDF header");
638
 
      exitCode = 2;
639
 
      goto err0;
640
 
    }
641
 
    /* copy PDF header */
642
 
    n = strlen(buf);
643
 
    if (write(fd,buf,n) != n) {
644
 
      error(-1,"Can't copy stdin to temporary file");
645
 
      close(fd);
646
 
      exitCode = 2;
647
 
      goto err0;
648
 
    }
649
 
    /* copy rest stdin to the tmp file */
650
 
    while ((n = fread(buf,1,sizeof(buf),stdin)) > 0) {
651
 
      if (write(fd,buf,n) != n) {
652
 
        error(-1,"Can't copy stdin to temporary file");
653
 
        close(fd);
654
 
        exitCode = 2;
655
 
        goto err0;
656
 
      }
657
 
    }
658
 
    if (lseek(fd,0,SEEK_SET) < 0) {
659
 
        error(-1,"Can't rewind temporary file");
660
 
        close(fd);
661
 
        exitCode = 2;
662
 
        goto err0;
663
 
    }
664
 
 
665
 
    if ((fp = fdopen(fd,"rb")) == 0) {
666
 
        error(-1,"Can't fdopen temporary file");
667
 
        close(fd);
668
 
        exitCode = 2;
669
 
        goto err0;
670
 
    }
671
 
 
672
 
    obj.initNull();
673
 
    str = new FileStream(fp,0,gFalse,0,&obj);
674
 
    doc = new PDFDoc(str);
675
 
  } else {
676
 
    /* no jcl check */
677
 
    doc = new PDFDoc(fileName.copy());
678
 
  }
679
 
  if (!doc->isOk()) {
680
 
    error(-1," Parsing PDF failed: error code %d",
681
 
      doc->getErrorCode());
682
 
    exitCode = 2;
683
 
    goto err05;
684
 
  }
685
 
 
686
 
  if (doc->isEncrypted() && !doc->okToPrint()) {
687
 
    error(-1,"Print Permission Denied");
688
 
    exitCode = 2;
689
 
    goto err05;
690
 
  }
691
 
 
692
 
  /* paperColor is white */
693
 
  paperColor[0] = 255;
694
 
  paperColor[1] = 255;
695
 
  paperColor[2] = 255;
696
 
#ifdef USE_CMS
697
 
  /* set color profile file name */
698
 
  GfxColorSpace::setDisplayProfileName(&colorProfilePath);
699
 
#endif
700
 
  opvpOut = new OPVPOutputDev();
701
 
  if (opvpOut->init(mono ? splashModeMono1 :
702
 
                                    gray ? splashModeMono8 :
703
 
                                             splashModeRGB8,
704
 
                                  colorProfile,
705
 
                                  gFalse, paperColor,
706
 
                                 printerDriver,1,printerModel,
707
 
                                 nOptions,optionKeys,optionVals) < 0) {
708
 
      error(-1,"OPVPOutputDev Initialize fail");
709
 
      exitCode = 2;
710
 
      goto err1;
711
 
  }
712
 
 
713
 
  opvpOut->startDoc(doc->getXRef());
714
 
 
715
 
#if 0
716
 
fprintf(stderr,"JobInfo=%s\n",jobInfo);
717
 
#endif
718
 
  if (opvpOut->OPVPStartJob(jobInfo) < 0) {
719
 
      error(-1,"Start job failed");
720
 
      exitCode = 2;
721
 
      goto err1;
722
 
  }
723
 
  if (opvpOut->OPVPStartDoc(docInfo) < 0) {
724
 
      error(-1,"Start Document failed");
725
 
      exitCode = 2;
726
 
      goto err2;
727
 
  }
728
 
  numPages = doc->getNumPages();
729
 
  for (pg = 1; pg <= numPages; ++pg) {
730
 
    if ((exitCode = outOnePage(doc,opvpOut,pg)) != 0) break;
731
 
  }
732
 
  if (opvpOut->OPVPEndDoc() < 0) {
733
 
      error(-1,"End Document failed");
734
 
      exitCode = 2;
735
 
  }
736
 
err2:
737
 
  if (opvpOut->OPVPEndJob() < 0) {
738
 
      error(-1,"End job failed");
739
 
      exitCode = 2;
740
 
  }
741
 
 
742
 
  // clean up
743
 
 err1:
744
 
  delete opvpOut;
745
 
 err05:
746
 
  delete doc;
747
 
 err0:
748
 
  delete globalParams;
749
 
 
750
 
  // check for memory leaks
751
 
  Object::memCheck(stderr);
752
 
  gMemReport(stderr);
753
 
 
754
 
}
755
 
/* muntrace(); */
756
 
  return exitCode;
757
 
}
758
 
 
759
 
/* for memory debug */
760
 
void *operator new(size_t size)
761
 
{
762
 
    void *p = malloc(size);
763
 
    return p;
764
 
}
765
 
 
766
 
void operator delete(void *p)
767
 
{
768
 
    free(p);
769
 
}