w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

pdftocairo.cc
Go to the documentation of this file.
1 //========================================================================
2 //
3 // pdftocairo.cc
4 //
5 // Copyright 2003 Glyph & Cog, LLC
6 //
7 //========================================================================
8 
9 //========================================================================
10 //
11 // Modified under the Poppler project - http://poppler.freedesktop.org
12 //
13 // All changes made under the Poppler project to this file are licensed
14 // under GPL version 2 or later
15 //
16 // Copyright (C) 2007 Ilmari Heikkinen <ilmari.heikkinen@gmail.com>
17 // Copyright (C) 2008 Richard Airlie <richard.airlie@maglabs.net>
18 // Copyright (C) 2009 Michael K. Johnson <a1237@danlj.org>
19 // Copyright (C) 2009 Shen Liang <shenzhuxi@gmail.com>
20 // Copyright (C) 2009 Stefan Thomas <thomas@eload24.com>
21 // Copyright (C) 2009, 2010, 2017-2020 Albert Astals Cid <aacid@kde.org>
22 // Copyright (C) 2010, 2011-2017 Adrian Johnson <ajohnson@redneon.com>
23 // Copyright (C) 2010, 2014 Hib Eris <hib@hiberis.nl>
24 // Copyright (C) 2010 Jonathan Liu <net147@gmail.com>
25 // Copyright (C) 2010 William Bader <williambader@hotmail.com>
26 // Copyright (C) 2011 Thomas Freitag <Thomas.Freitag@alfa.de>
27 // Copyright (C) 2011, 2015 Carlos Garcia Campos <carlosgc@gnome.org>
28 // Copyright (C) 2012 Koji Otani <sho@bbr.jp>
29 // Copyright (C) 2013 Lu Wang <coolwanglu@gmail.com>
30 // Copyright (C) 2013, 2017 Suzuki Toshiya <mpsuzuki@hiroshima-u.ac.jp>
31 // Copyright (C) 2014 Rodrigo Rivas Costa <rodrigorivascosta@gmail.com>
32 // Copyright (C) 2016 Jason Crain <jason@aquaticape.us>
33 // Copyright (C) 2018 Martin Packman <gzlist@googlemail.com>
34 // Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de>
35 // Copyright (C) 2019, 2020 Oliver Sander <oliver.sander@tu-dresden.de>
36 // Copyright (C) 2019 Kris Jurka <jurka@ejurka.com>
37 // Copyright (C) 2020, 2021 Oliver Sander <oliver.sander@tu-dresden.de>
38 // Copyright (C) 2020 Philipp Knechtges <philipp-dev@knechtges.com>
39 // Copyright (C) 2020 Salvo Miosi <salvo.ilmiosi@gmail.com>
40 //
41 // To see a description of the changes please see the Changelog file that
42 // came with your tarball or type make ChangeLog if you are building from git
43 //
44 //========================================================================
45 #ifdef _MSC_VER
46 #define strcasecmp stricmp
47 #endif
48 
49 #include "config.h"
50 #include <poppler-config.h>
51 #include <cstdint>
52 #include <cstdio>
53 #include <cmath>
54 #include <cstring>
55 #include <fcntl.h>
56 #ifdef _WIN32
57 #include <io.h>
58 #endif
59 #include "parseargs.h"
60 #include "goo/gmem.h"
61 #include "goo/GooString.h"
62 #include "goo/ImgWriter.h"
63 #include "goo/JpegWriter.h"
64 #include "goo/PNGWriter.h"
65 #include "goo/TiffWriter.h"
66 #include "GlobalParams.h"
67 #include "Object.h"
68 #include "PDFDoc.h"
69 #include "PDFDocFactory.h"
70 #include "CairoOutputDev.h"
71 #include "Win32Console.h"
72 #include "numberofcharacters.h"
73 #ifdef USE_CMS
74 # include <lcms2.h>
75 #endif
76 #include <cairo.h>
77 #ifdef CAIRO_HAS_PS_SURFACE
78 # include <cairo-ps.h>
79 #endif
80 #ifdef CAIRO_HAS_PDF_SURFACE
81 # include <cairo-pdf.h>
82 #endif
83 #ifdef CAIRO_HAS_SVG_SURFACE
84 # include <cairo-svg.h>
85 #endif
86 
87 #include "pdftocairo-win32.h"
88 
89 static bool png = false;
90 static bool jpeg = false;
91 static bool ps = false;
92 static bool eps = false;
93 static bool pdf = false;
94 static bool printToWin32 = false;
95 static bool printdlg = false;
96 static bool svg = false;
97 static bool tiff = false;
98 
99 static int firstPage = 1;
100 static int lastPage = 0;
101 static bool printOnlyOdd = false;
102 static bool printOnlyEven = false;
103 static bool singleFile = false;
104 static double resolution = 0.0;
105 static double x_resolution = 150.0;
106 static double y_resolution = 150.0;
107 static int scaleTo = 0;
108 static int x_scaleTo = 0;
109 static int y_scaleTo = 0;
110 static int crop_x = 0;
111 static int crop_y = 0;
112 static int crop_w = 0;
113 static int crop_h = 0;
114 static int sz = 0;
115 static bool useCropBox = false;
116 static bool mono = false;
117 static bool gray = false;
118 static bool transp = false;
120 static GooString icc;
121 
122 static bool level2 = false;
123 static bool level3 = false;
124 static bool origPageSizes = false;
125 static char paperSize[15] = "";
126 static int paperWidth = -1;
127 static int paperHeight = -1;
128 static bool noCrop = false;
129 static bool expand = false;
130 static bool noShrink = false;
131 static bool noCenter = false;
132 static bool duplex = false;
133 static char tiffCompressionStr[16] = "";
134 
135 static char ownerPassword[33] = "";
136 static char userPassword[33] = "";
137 static bool quiet = false;
138 static bool printVersion = false;
139 static bool printHelp = false;
140 
142 static int jpegQuality = -1;
143 static bool jpegProgressive = false;
144 static bool jpegOptimize = false;
145 
148 #ifdef CAIRO_HAS_WIN32_SURFACE
149 static bool setupdlg = false;
150 #endif
151 
152 static const ArgDesc argDesc[] = {
153 #ifdef ENABLE_LIBPNG
154  { "-png", argFlag, &png, 0, "generate a PNG file" },
155 #endif
156 #ifdef ENABLE_LIBJPEG
157  { "-jpeg", argFlag, &jpeg, 0, "generate a JPEG file" },
158  { "-jpegopt", argGooString, &jpegOpt, 0, "jpeg options, with format <opt1>=<val1>[,<optN>=<valN>]*" },
159 #endif
160 #ifdef ENABLE_LIBTIFF
161  { "-tiff", argFlag, &tiff, 0, "generate a TIFF file" },
162  { "-tiffcompression", argString, tiffCompressionStr, sizeof(tiffCompressionStr), "set TIFF compression: none, packbits, jpeg, lzw, deflate" },
163 #endif
164 #ifdef CAIRO_HAS_PS_SURFACE
165  { "-ps", argFlag, &ps, 0, "generate PostScript file" },
166  { "-eps", argFlag, &eps, 0, "generate Encapsulated PostScript (EPS)" },
167 #endif
168 #ifdef CAIRO_HAS_PDF_SURFACE
169  { "-pdf", argFlag, &pdf, 0, "generate a PDF file" },
170 #endif
171 #ifdef CAIRO_HAS_SVG_SURFACE
172  { "-svg", argFlag, &svg, 0, "generate a Scalable Vector Graphics (SVG) file" },
173 #endif
174 #ifdef CAIRO_HAS_WIN32_SURFACE
175  { "-print", argFlag, &printToWin32, 0, "print to a Windows printer" },
176  { "-printdlg", argFlag, &printdlg, 0, "show Windows print dialog and print" },
177  { "-printer", argGooString, &printer, 0, "printer name or use default if this option is not specified" },
178  { "-printopt", argGooString, &printOpt, 0, "printer options, with format <opt1>=<val1>[,<optN>=<valN>]*" },
179  { "-setupdlg", argFlag, &setupdlg, 0, "show printer setup dialog before printing" },
180 #endif
181 
182  { "-f", argInt, &firstPage, 0, "first page to print" },
183  { "-l", argInt, &lastPage, 0, "last page to print" },
184  { "-o", argFlag, &printOnlyOdd, 0, "print only odd pages" },
185  { "-e", argFlag, &printOnlyEven, 0, "print only even pages" },
186  { "-singlefile", argFlag, &singleFile, 0, "write only the first page and do not add digits" },
187 
188  { "-r", argFP, &resolution, 0, "resolution, in PPI (default is 150)" },
189  { "-rx", argFP, &x_resolution, 0, "X resolution, in PPI (default is 150)" },
190  { "-ry", argFP, &y_resolution, 0, "Y resolution, in PPI (default is 150)" },
191  { "-scale-to", argInt, &scaleTo, 0, "scales each page to fit within scale-to*scale-to pixel box" },
192  { "-scale-to-x", argInt, &x_scaleTo, 0, "scales each page horizontally to fit in scale-to-x pixels" },
193  { "-scale-to-y", argInt, &y_scaleTo, 0, "scales each page vertically to fit in scale-to-y pixels" },
194 
195  { "-x", argInt, &crop_x, 0, "x-coordinate of the crop area top left corner" },
196  { "-y", argInt, &crop_y, 0, "y-coordinate of the crop area top left corner" },
197  { "-W", argInt, &crop_w, 0, "width of crop area in pixels (default is 0)" },
198  { "-H", argInt, &crop_h, 0, "height of crop area in pixels (default is 0)" },
199  { "-sz", argInt, &sz, 0, "size of crop square in pixels (sets W and H)" },
200  { "-cropbox", argFlag, &useCropBox, 0, "use the crop box rather than media box" },
201 
202  { "-mono", argFlag, &mono, 0, "generate a monochrome image file (PNG, JPEG)" },
203  { "-gray", argFlag, &gray, 0, "generate a grayscale image file (PNG, JPEG)" },
204  { "-transp", argFlag, &transp, 0, "use a transparent background instead of white (PNG)" },
205  { "-antialias", argGooString, &antialias, 0, "set cairo antialias option" },
206 #ifdef USE_CMS
207  { "-icc", argGooString, &icc, 0, "ICC color profile to use" },
208 #endif
209 
210  { "-level2", argFlag, &level2, 0, "generate Level 2 PostScript (PS, EPS)" },
211  { "-level3", argFlag, &level3, 0, "generate Level 3 PostScript (PS, EPS)" },
212  { "-origpagesizes", argFlag, &origPageSizes, 0, "conserve original page sizes (PS, PDF, SVG)" },
213  { "-paper", argString, paperSize, sizeof(paperSize), "paper size (letter, legal, A4, A3, match)" },
214  { "-paperw", argInt, &paperWidth, 0, "paper width, in points" },
215  { "-paperh", argInt, &paperHeight, 0, "paper height, in points" },
216  { "-nocrop", argFlag, &noCrop, 0, "don't crop pages to CropBox" },
217  { "-expand", argFlag, &expand, 0, "expand pages smaller than the paper size" },
218  { "-noshrink", argFlag, &noShrink, 0, "don't shrink pages larger than the paper size" },
219  { "-nocenter", argFlag, &noCenter, 0, "don't center pages smaller than the paper size" },
220  { "-duplex", argFlag, &duplex, 0, "enable duplex printing" },
221 
222  { "-opw", argString, ownerPassword, sizeof(ownerPassword), "owner password (for encrypted files)" },
223  { "-upw", argString, userPassword, sizeof(userPassword), "user password (for encrypted files)" },
224 
225  { "-q", argFlag, &quiet, 0, "don't print any messages or errors" },
226  { "-v", argFlag, &printVersion, 0, "print copyright and version info" },
227  { "-h", argFlag, &printHelp, 0, "print usage information" },
228  { "-help", argFlag, &printHelp, 0, "print usage information" },
229  { "--help", argFlag, &printHelp, 0, "print usage information" },
230  { "-?", argFlag, &printHelp, 0, "print usage information" },
231  {}
232 };
233 
235 static bool printing;
237 static bool usePDFPageSize;
239 
240 #ifdef USE_CMS
241 static unsigned char *icc_data;
242 static int icc_data_size;
244 #endif
245 
247 {
248  const char *name;
250 };
251 
253  { "default", CAIRO_ANTIALIAS_DEFAULT }, { "none", CAIRO_ANTIALIAS_NONE }, { "gray", CAIRO_ANTIALIAS_GRAY }, { "subpixel", CAIRO_ANTIALIAS_SUBPIXEL },
254  { "fast", CAIRO_ANTIALIAS_FAST }, { "good", CAIRO_ANTIALIAS_GOOD }, { "best", CAIRO_ANTIALIAS_BEST }, { nullptr, CAIRO_ANTIALIAS_DEFAULT },
255 };
256 
257 static bool parseAntialiasOption()
258 {
260  while (option->name) {
261  if (antialias.cmp(option->name) == 0) {
263  return true;
264  }
265  option++;
266  }
267 
268  fprintf(stderr, "Error: Invalid antialias option \"%s\"\n", antialias.c_str());
269  fprintf(stderr, "Valid options are:\n");
271  while (option->name) {
272  fprintf(stderr, " %s\n", option->name);
273  option++;
274  }
275  return false;
276 }
277 
278 static bool parseJpegOptions()
279 {
280  // jpegOpt format is: <opt1>=<val1>,<opt2>=<val2>,...
281  const char *nextOpt = jpegOpt.c_str();
282  while (nextOpt && *nextOpt) {
283  const char *comma = strchr(nextOpt, ',');
284  GooString opt;
285  if (comma) {
286  opt.Set(nextOpt, comma - nextOpt);
287  nextOpt = comma + 1;
288  } else {
289  opt.Set(nextOpt);
290  nextOpt = nullptr;
291  }
292  // here opt is "<optN>=<valN> "
293  const char *equal = strchr(opt.c_str(), '=');
294  if (!equal) {
295  fprintf(stderr, "Unknown jpeg option \"%s\"\n", opt.c_str());
296  return false;
297  }
298  int iequal = equal - opt.c_str();
299  GooString value(&opt, iequal + 1, opt.getLength() - iequal - 1);
300  opt.del(iequal, opt.getLength() - iequal);
301  // here opt is "<optN>" and value is "<valN>"
302 
303  if (opt.cmp("quality") == 0) {
304  if (!isInt(value.c_str())) {
305  fprintf(stderr, "Invalid jpeg quality\n");
306  return false;
307  }
308  jpegQuality = atoi(value.c_str());
309  if (jpegQuality < 0 || jpegQuality > 100) {
310  fprintf(stderr, "jpeg quality must be between 0 and 100\n");
311  return false;
312  }
313  } else if (opt.cmp("progressive") == 0) {
314  jpegProgressive = false;
315  if (value.cmp("y") == 0) {
316  jpegProgressive = true;
317  } else if (value.cmp("n") != 0) {
318  fprintf(stderr, "jpeg progressive option must be \"y\" or \"n\"\n");
319  return false;
320  }
321  } else if (opt.cmp("optimize") == 0 || opt.cmp("optimise") == 0) {
322  jpegOptimize = false;
323  if (value.cmp("y") == 0) {
324  jpegOptimize = true;
325  } else if (value.cmp("n") != 0) {
326  fprintf(stderr, "jpeg optimize option must be \"y\" or \"n\"\n");
327  return false;
328  }
329  } else {
330  fprintf(stderr, "Unknown jpeg option \"%s\"\n", opt.c_str());
331  return false;
332  }
333  }
334  return true;
335 }
336 
338 {
339  ImgWriter *writer = nullptr;
340  FILE *file;
341  int height, width, stride;
342  unsigned char *data;
343 
344  if (png) {
345 #ifdef ENABLE_LIBPNG
346  if (transp)
348  else if (gray)
350  else if (mono)
352  else
354 
355 # ifdef USE_CMS
356  if (icc_data) {
357  cmsUInt8Number profileID[17];
358  profileID[16] = '\0';
359 
360  cmsGetHeaderProfileID(profile.get(), profileID);
361  static_cast<PNGWriter *>(writer)->setICCProfile(reinterpret_cast<char *>(profileID), icc_data, icc_data_size);
362  } else {
363  static_cast<PNGWriter *>(writer)->setSRGBProfile();
364  }
365 # endif
366 #endif
367 
368  } else if (jpeg) {
369 #ifdef ENABLE_LIBJPEG
370  if (gray)
371  writer = new JpegWriter(JpegWriter::GRAY);
372  else
373  writer = new JpegWriter(JpegWriter::RGB);
374 
375  static_cast<JpegWriter *>(writer)->setOptimize(jpegOptimize);
376  static_cast<JpegWriter *>(writer)->setProgressive(jpegProgressive);
377  if (jpegQuality >= 0)
378  static_cast<JpegWriter *>(writer)->setQuality(jpegQuality);
379 #endif
380  } else if (tiff) {
381 #ifdef ENABLE_LIBTIFF
382  if (transp)
383  writer = new TiffWriter(TiffWriter::RGBA_PREMULTIPLIED);
384  else if (gray)
385  writer = new TiffWriter(TiffWriter::GRAY);
386  else if (mono)
387  writer = new TiffWriter(TiffWriter::MONOCHROME);
388  else
389  writer = new TiffWriter(TiffWriter::RGB);
390  static_cast<TiffWriter *>(writer)->setCompressionString(tiffCompressionStr);
391 #endif
392  }
393  if (!writer)
394  return;
395 
396  if (filename->cmp("fd://0") == 0) {
397 #ifdef _WIN32
399 #endif
400  file = stdout;
401  } else
402  file = fopen(filename->c_str(), "wb");
403 
404  if (!file) {
405  fprintf(stderr, "Error opening output file %s\n", filename->c_str());
406  exit(2);
407  }
408 
414 
415  if (!writer->init(file, width, height, x_resolution, y_resolution)) {
416  fprintf(stderr, "Error writing %s\n", filename->c_str());
417  exit(2);
418  }
419  unsigned char *row = (unsigned char *)gmallocn(width, 4);
420 
421  for (int y = 0; y < height; y++) {
422  uint32_t *pixel = reinterpret_cast<uint32_t *>((data + y * stride));
423  unsigned char *rowp = row;
424  int bit = 7;
425  for (int x = 0; x < width; x++, pixel++) {
426  if (transp) {
427  if (tiff) {
428  // RGBA premultipled format
429  *rowp++ = (*pixel & 0xff0000) >> 16;
430  *rowp++ = (*pixel & 0x00ff00) >> 8;
431  *rowp++ = (*pixel & 0x0000ff) >> 0;
432  *rowp++ = (*pixel & 0xff000000) >> 24;
433  } else {
434  // unpremultiply into RGBA format
435  uint8_t a;
436  a = (*pixel & 0xff000000) >> 24;
437  if (a == 0) {
438  *rowp++ = 0;
439  *rowp++ = 0;
440  *rowp++ = 0;
441  } else {
442  *rowp++ = (((*pixel & 0xff0000) >> 16) * 255 + a / 2) / a;
443  *rowp++ = (((*pixel & 0x00ff00) >> 8) * 255 + a / 2) / a;
444  *rowp++ = (((*pixel & 0x0000ff) >> 0) * 255 + a / 2) / a;
445  }
446  *rowp++ = a;
447  }
448  } else if (gray || mono) {
449  // convert to gray
450  // The PDF Reference specifies the DeviceRGB to DeviceGray conversion as
451  // gray = 0.3*red + 0.59*green + 0.11*blue
452  const int r = (*pixel & 0x00ff0000) >> 16;
453  const int g = (*pixel & 0x0000ff00) >> 8;
454  const int b = (*pixel & 0x000000ff) >> 0;
455  // an arbitrary integer approximation of .3*r + .59*g + .11*b
456  const int grayValue = (r * 19661 + g * 38666 + b * 7209 + 32829) >> 16;
457  if (mono) {
458  if (bit == 7)
459  *rowp = 0;
460  if (grayValue > 127)
461  *rowp |= (1 << bit);
462  bit--;
463  if (bit < 0) {
464  bit = 7;
465  rowp++;
466  }
467  } else {
468  *rowp++ = grayValue;
469  }
470  } else {
471  // copy into RGB format
472  *rowp++ = (*pixel & 0x00ff0000) >> 16;
473  *rowp++ = (*pixel & 0x0000ff00) >> 8;
474  *rowp++ = (*pixel & 0x000000ff) >> 0;
475  }
476  }
477  writer->writeRow(&row);
478  }
479  gfree(row);
480  writer->close();
481  delete writer;
482  if (file == stdout)
483  fflush(file);
484  else
485  fclose(file);
486 }
487 
488 static void getCropSize(double page_w, double page_h, double *width, double *height)
489 {
490  int w = crop_w;
491  int h = crop_h;
492 
493  if (w == 0)
494  w = (int)ceil(page_w);
495 
496  if (h == 0)
497  h = (int)ceil(page_h);
498 
499  *width = (crop_x + w > page_w ? (int)ceil(page_w - crop_x) : w);
500  *height = (crop_y + h > page_h ? (int)ceil(page_h - crop_y) : h);
501 }
502 
503 static void getOutputSize(double page_w, double page_h, double *width, double *height)
504 {
505 
506  if (printing) {
507  if (usePDFPageSize) {
508  *width = page_w;
509  *height = page_h;
510  } else {
511  if (page_w > page_h) {
512  *width = paperHeight;
513  *height = paperWidth;
514  } else {
515  *width = paperWidth;
516  *height = paperHeight;
517  }
518  }
519  } else {
520  getCropSize(page_w * (x_resolution / 72.0), page_h * (y_resolution / 72.0), width, height);
521  }
522 }
523 
524 static void getFitToPageTransform(double page_w, double page_h, double paper_w, double paper_h, cairo_matrix_t *m)
525 {
526  double x_scale, y_scale, scale;
527 
528  x_scale = paper_w / page_w;
529  y_scale = paper_h / page_h;
530  if (x_scale < y_scale)
531  scale = x_scale;
532  else
533  scale = y_scale;
534 
535  if (scale > 1.0 && !expand)
536  scale = 1.0;
537  if (scale < 1.0 && noShrink)
538  scale = 1.0;
539 
541  if (!noCenter) {
542  // centre page
543  cairo_matrix_translate(m, (paper_w - page_w * scale) / 2, (paper_h - page_h * scale) / 2);
544  } else if (!svg) {
545  // move to PostScript origin
546  cairo_matrix_translate(m, 0, (paper_h - page_h * scale));
547  }
549 }
550 
551 static cairo_status_t writeStream(void *closure, const unsigned char *data, unsigned int length)
552 {
553  FILE *file = (FILE *)closure;
554 
555  if (fwrite(data, length, 1, file) == 1)
556  return CAIRO_STATUS_SUCCESS;
557  else
559 }
560 
561 static void beginDocument(GooString *inputFileName, GooString *outputFileName, double w, double h)
562 {
563  if (printing) {
564  if (printToWin32) {
565  output_file = nullptr;
566  } else {
567  if (outputFileName->cmp("fd://0") == 0)
569  else {
570  output_file = fopen(outputFileName->c_str(), "wb");
571  if (!output_file) {
572  fprintf(stderr, "Error opening output file %s\n", outputFileName->c_str());
573  exit(2);
574  }
575  }
576  }
577 
578  if (ps || eps) {
579 #ifdef CAIRO_HAS_PS_SURFACE
581  if (level2)
583  if (eps)
585  if (duplex) {
586  cairo_ps_surface_dsc_comment(surface, "%%Requirements: duplex");
588  cairo_ps_surface_dsc_comment(surface, "%%IncludeFeature: *Duplex DuplexNoTumble");
589  }
591 #endif
592  } else if (pdf) {
593 #ifdef CAIRO_HAS_PDF_SURFACE
595 #endif
596  } else if (svg) {
597 #ifdef CAIRO_HAS_SVG_SURFACE
600 #endif
601  }
602 #ifdef CAIRO_HAS_WIN32_SURFACE
603  if (printToWin32)
604  surface = win32BeginDocument(inputFileName, outputFileName);
605 #endif
606  }
607 }
608 
609 static void beginPage(double *w, double *h)
610 {
611  if (printing) {
612  if (ps || eps) {
613 #ifdef CAIRO_HAS_PS_SURFACE
614  if (*w > *h) {
615  cairo_ps_surface_dsc_comment(surface, "%%PageOrientation: Landscape");
617  } else {
618  cairo_ps_surface_dsc_comment(surface, "%%PageOrientation: Portrait");
620  }
621 #endif
622  }
623 
624 #ifdef CAIRO_HAS_PDF_SURFACE
625  if (pdf)
627 #endif
628 
629 #ifdef CAIRO_HAS_WIN32_SURFACE
630  if (printToWin32) {
631  bool changePageSize = true;
632  if (setupdlg && !origPageSizes)
633  changePageSize = false;
634  win32BeginPage(w, h, changePageSize, noShrink); // w,h will be changed to actual size used
635  }
636 #endif
637 
639 
640  } else {
642  }
643 }
644 
645 static void renderPage(PDFDoc *doc, CairoOutputDev *cairoOut, int pg, double page_w, double page_h, double output_w, double output_h)
646 {
647  cairo_t *cr;
650 
652 
653  cairoOut->setCairo(cr);
654  cairoOut->setPrinting(printing);
655  cairoOut->setAntialias(antialiasEnum);
656 
657  cairo_save(cr);
658  if (ps && output_w > output_h) {
659  // rotate 90 deg for landscape
660  cairo_translate(cr, 0, output_w);
661  cairo_matrix_init(&m, 0, -1, 1, 0, 0, 0);
662  cairo_transform(cr, &m);
663  }
665  if (printing) {
666  double cropped_w, cropped_h;
667  getCropSize(page_w, page_h, &cropped_w, &cropped_h);
668  getFitToPageTransform(cropped_w, cropped_h, output_w, output_h, &m);
669  cairo_transform(cr, &m);
670  cairo_rectangle(cr, crop_x, crop_y, cropped_w, cropped_h);
671  cairo_clip(cr);
672  } else {
673  cairo_scale(cr, x_resolution / 72.0, y_resolution / 72.0);
674  }
675  doc->displayPageSlice(cairoOut, pg, 72.0, 72.0, 0, /* rotate */
676  !useCropBox, /* useMediaBox */
677  false, /* Crop */
678  printing, -1, -1, -1, -1);
679  cairo_restore(cr);
680  cairoOut->setCairo(nullptr);
681 
682  // Blend onto white page
683  if (!printing && !transp) {
684  cairo_save(cr);
686  cairo_set_source_rgb(cr, 1, 1, 1);
687  cairo_paint(cr);
688  cairo_restore(cr);
689  }
690 
692  if (status)
693  fprintf(stderr, "cairo error: %s\n", cairo_status_to_string(status));
694  cairo_destroy(cr);
695 }
696 
697 static void endPage(GooString *imageFileName)
698 {
700 
701  if (printing) {
703 
704 #ifdef CAIRO_HAS_WIN32_SURFACE
705  if (printToWin32)
706  win32EndPage(imageFileName);
707 #endif
708 
709  } else {
710  writePageImage(imageFileName);
713  if (status)
714  fprintf(stderr, "cairo error: %s\n", cairo_status_to_string(status));
716  }
717 }
718 
719 static void endDocument()
720 {
722 
723  if (printing) {
726  if (status)
727  fprintf(stderr, "cairo error: %s\n", cairo_status_to_string(status));
729 #ifdef CAIRO_HAS_WIN32_SURFACE
730  if (printToWin32)
732 #endif
733  if (output_file)
735  }
736 }
737 
738 static bool setPSPaperSize(char *size, int &psPaperWidth, int &psPaperHeight)
739 {
740  if (!strcmp(size, "match")) {
741  psPaperWidth = psPaperHeight = -1;
742  } else if (!strcmp(size, "letter")) {
743  psPaperWidth = 612;
744  psPaperHeight = 792;
745  } else if (!strcmp(size, "legal")) {
746  psPaperWidth = 612;
747  psPaperHeight = 1008;
748  } else if (!strcmp(size, "A4")) {
749  psPaperWidth = 595;
750  psPaperHeight = 842;
751  } else if (!strcmp(size, "A3")) {
752  psPaperWidth = 842;
753  psPaperHeight = 1190;
754  } else {
755  return false;
756  }
757  return true;
758 }
759 
761 {
762  char buf[10];
763  GooString *imageName = new GooString(outputFileName);
764  if (!singleFile) {
765  snprintf(buf, sizeof(buf), "-%0*d", numDigits, page);
766  imageName->append(buf);
767  }
768  if (outputFileName->cmp("fd://0") != 0) {
769  if (png)
770  imageName->append(".png");
771  else if (jpeg)
772  imageName->append(".jpg");
773  else if (tiff)
774  imageName->append(".tif");
775  }
776 
777  return imageName;
778 }
779 
780 // If (printing || singleFile) the output file name includes the
781 // extension. Otherwise it is the file name base.
783 {
784  GooString *name;
785 
786  if (outputName) {
787  if (outputName->cmp("-") == 0) {
788  if (printToWin32 || (!printing && !singleFile)) {
789  fprintf(stderr, "Error: stdout may only be used with the ps, eps, pdf, svg output options or if -singlefile is used.\n");
790  exit(99);
791  }
792  return new GooString("fd://0");
793  }
794  return new GooString(outputName);
795  }
796 
797  if (printToWin32)
798  return nullptr; // No output file means print to printer
799 
800  if (fileName->cmp("fd://0") == 0) {
801  fprintf(stderr, "Error: an output filename or '-' must be supplied when the PDF file is stdin.\n");
802  exit(99);
803  }
804 
805  // be careful not to overwrite the input file when the output format is PDF
806  if (pdf && fileName->cmpN("http://", 7) != 0 && fileName->cmpN("https://", 8) != 0) {
807  fprintf(stderr, "Error: an output filename or '-' must be supplied when the output format is PDF and input PDF file is a local file.\n");
808  exit(99);
809  }
810 
811  // strip everything up to last '/'
812  const char *s = fileName->c_str();
813  const char *p = strrchr(s, '/');
814  if (p) {
815  p++;
816  if (*p == 0) {
817  fprintf(stderr, "Error: invalid output filename.\n");
818  exit(99);
819  }
820  name = new GooString(p);
821  } else {
822  name = new GooString(s);
823  }
824 
825  // remove .pdf extension
826  p = strrchr(name->c_str(), '.');
827  if (p && strcasecmp(p, ".pdf") == 0) {
828  GooString *name2 = new GooString(name->c_str(), name->getLength() - 4);
829  delete name;
830  name = name2;
831  }
832 
833  // append new extension
834  if (ps)
835  name->append(".ps");
836  else if (eps)
837  name->append(".eps");
838  else if (pdf)
839  name->append(".pdf");
840  else if (svg)
841  name->append(".svg");
842 
843  return name;
844 }
845 
846 static void checkInvalidPrintOption(bool option, const char *option_name)
847 {
848  if (option) {
849  fprintf(stderr, "Error: %s may only be used with the -png, -jpeg, or -tiff output options.\n", option_name);
850  exit(99);
851  }
852 }
853 
854 static void checkInvalidImageOption(bool option, const char *option_name)
855 {
856  if (option) {
857  fprintf(stderr, "Error: %s may only be used with the -ps, -eps, -pdf, or -svg output options.\n", option_name);
858  exit(99);
859  }
860 }
861 
862 #if defined(_WIN32)
863 extern "C" {
864 void
865 kpse_set_program_name (char *argv0, char *progname);
866 }
867 #endif /* _WIN32 */
868 
869 int main(int argc, char *argv[])
870 {
871  GooString *fileName = nullptr;
872  GooString *outputName = nullptr;
873  GooString *outputFileName = nullptr;
874  GooString *imageFileName = nullptr;
875  GooString *ownerPW, *userPW;
876  CairoOutputDev *cairoOut;
877  int pg, pg_num_len;
878  double pg_w, pg_h, tmp, output_w, output_h;
879  int num_outputs;
880 
881 #if defined(_WIN32)
882  kpse_set_program_name (argv[0], NULL);
883 #endif /* _WIN32 */
884  // parse args
885  Win32Console win32Console(&argc, &argv);
886  if (!parseArgs(argDesc, &argc, argv)) {
887  printUsage("pdftocairo", nullptr, argDesc);
888  exit(99);
889  }
890 
891  if (resolution != 0.0 && (x_resolution == 150.0 || y_resolution == 150.0)) {
894  }
895  if (argc < 2 || argc > 3 || printVersion || printHelp) {
896  fprintf(stderr, "pdftocairo version %s\n", PACKAGE_VERSION);
897  fprintf(stderr, "%s\n", popplerCopyright);
898  fprintf(stderr, "%s\n", xpdfCopyright);
899  if (!printVersion) {
900  printUsage("pdftocairo", "<PDF-file> [<output-file>]", argDesc);
901  }
902  if (printVersion || printHelp)
903  exit(0);
904  else
905  exit(99);
906  }
907 
908  num_outputs = (png ? 1 : 0) + (jpeg ? 1 : 0) + (tiff ? 1 : 0) + (ps ? 1 : 0) + (eps ? 1 : 0) + (pdf ? 1 : 0) + (printToWin32 ? 1 : 0) + (printdlg ? 1 : 0) + (svg ? 1 : 0);
909  if (num_outputs == 0) {
910  fprintf(stderr, "Error: one of the output format options (-png, -jpeg, -ps, -eps, -pdf, -print, -printdlg, -svg) must be used.\n");
911  exit(99);
912  }
913  if (num_outputs > 1) {
914  fprintf(stderr, "Error: use only one of the output format options (-png, -jpeg, -ps, -eps, -pdf, -printdlg, -print, -svg).\n");
915  exit(99);
916  }
917  if (png || jpeg || tiff)
918  printing = false;
919  else
920  printing = true;
921 
922  if (printing) {
923  checkInvalidPrintOption(mono, "-mono");
924  checkInvalidPrintOption(gray, "-gray");
925  checkInvalidPrintOption(transp, "-transp");
926  checkInvalidPrintOption(icc.c_str()[0], "-icc");
927  checkInvalidPrintOption(singleFile, "-singlefile");
928  checkInvalidPrintOption(useCropBox, "-cropbox");
929  checkInvalidPrintOption(scaleTo != 0, "-scale-to");
930  checkInvalidPrintOption(x_scaleTo != 0, "-scale-to-x");
931  checkInvalidPrintOption(y_scaleTo != 0, "-scale-to-y");
932  } else {
933  checkInvalidImageOption(level2, "-level2");
934  checkInvalidImageOption(level3, "-level3");
935  checkInvalidImageOption(origPageSizes, "-origpagesizes");
936  checkInvalidImageOption(paperSize[0], "-paper");
937  checkInvalidImageOption(paperWidth > 0, "-paperw");
938  checkInvalidImageOption(paperHeight > 0, "-paperh");
939  checkInvalidImageOption(noCrop, "-nocrop");
940  checkInvalidImageOption(expand, "-expand");
941  checkInvalidImageOption(noShrink, "-noshrink");
942  checkInvalidImageOption(noCenter, "-nocenter");
943  checkInvalidImageOption(duplex, "-duplex");
944  }
945 
946  if (printing)
947  useCropBox = !noCrop;
948 
949  if (icc.c_str()[0] && !png) {
950  fprintf(stderr, "Error: -icc may only be used with png output.\n");
951  exit(99);
952  }
953 
954  if (antialias.getLength() > 0) {
955  if (!parseAntialiasOption())
956  exit(99);
957  }
958 
959  if (transp && !(png || tiff)) {
960  fprintf(stderr, "Error: -transp may only be used with png or tiff output.\n");
961  exit(99);
962  }
963 
964  if (mono && gray) {
965  fprintf(stderr, "Error: -mono and -gray may not be used together.\n");
966  exit(99);
967  }
968 
969  if (mono && !(png || tiff)) {
970  fprintf(stderr, "Error: -mono may only be used with png or tiff output.\n");
971  exit(99);
972  }
973 
974  if (jpegOpt.getLength() > 0) {
975  if (!jpeg) {
976  fprintf(stderr, "Error: -jpegopt may only be used with jpeg output.\n");
977  exit(99);
978  }
979  if (!parseJpegOptions())
980  exit(99);
981  }
982 
983  if (strlen(tiffCompressionStr) > 0 && !tiff) {
984  fprintf(stderr, "Error: -tiffcompression may only be used with tiff output.\n");
985  exit(99);
986  }
987 
988  if (level2 && level3) {
989  fprintf(stderr, "Error: use only one of the 'level' options.\n");
990  exit(99);
991  }
992  if (!level2 && !level3)
993  level3 = true;
994 
995  if (eps && (origPageSizes || paperSize[0] || paperWidth > 0 || paperHeight > 0)) {
996  fprintf(stderr, "Error: page size options may not be used with eps output.\n");
997  exit(99);
998  }
999 
1000  if ((paperWidth > 0 && paperHeight <= 0) || (paperWidth <= 0 && paperHeight > 0)) {
1001  fprintf(stderr, "Error: both -paperw and -paperh must be specified.\n");
1002  exit(99);
1003  }
1004 
1005  if (paperSize[0]) {
1006  if (origPageSizes) {
1007  fprintf(stderr, "Error: -origpagesizes and -paper may not be used together.\n");
1008  exit(99);
1009  }
1011  fprintf(stderr, "Invalid paper size\n");
1012  exit(99);
1013  }
1014  }
1015  if (origPageSizes || paperWidth < 0 || paperHeight < 0)
1016  usePDFPageSize = true;
1017  else
1018  usePDFPageSize = false;
1019 
1020  if (printdlg)
1021  printToWin32 = true;
1022 
1023  globalParams = std::make_unique<GlobalParams>();
1024  if (quiet) {
1026  }
1027 
1028  // open PDF file
1029  if (ownerPassword[0]) {
1030  ownerPW = new GooString(ownerPassword);
1031  } else {
1032  ownerPW = nullptr;
1033  }
1034  if (userPassword[0]) {
1035  userPW = new GooString(userPassword);
1036  } else {
1037  userPW = nullptr;
1038  }
1039 
1040  fileName = new GooString(argv[1]);
1041  if (fileName->cmp("-") == 0) {
1042  delete fileName;
1043  fileName = new GooString("fd://0");
1044  }
1045  if (argc == 3)
1046  outputName = new GooString(argv[2]);
1047  else
1048  outputName = nullptr;
1049 
1050  outputFileName = getOutputFileName(fileName, outputName);
1051 
1052 #ifdef USE_CMS
1053  icc_data = nullptr;
1054  if (icc.c_str()[0]) {
1055  FILE *file = fopen(icc.c_str(), "rb");
1056  if (!file) {
1057  fprintf(stderr, "Error: unable to open icc profile %s\n", icc.c_str());
1058  exit(4);
1059  }
1060  fseek(file, 0, SEEK_END);
1062  fseek(file, 0, SEEK_SET);
1063  icc_data = (unsigned char *)gmalloc(icc_data_size);
1064  if (fread(icc_data, icc_data_size, 1, file) != 1) {
1065  fprintf(stderr, "Error: unable to read icc profile %s\n", icc.c_str());
1066  exit(4);
1067  }
1068  fclose(file);
1070  if (!profile) {
1071  fprintf(stderr, "Error: lcms error opening profile\n");
1072  exit(4);
1073  }
1074  } else {
1076  }
1077 #endif
1078 
1079  std::unique_ptr<PDFDoc> doc = PDFDocFactory().createPDFDoc(*fileName, ownerPW, userPW);
1080  if (!doc->isOk()) {
1081  fprintf(stderr, "Error opening PDF file.\n");
1082  exit(1);
1083  }
1084 
1085 #ifdef ENFORCE_PERMISSIONS
1086  // check for print permission
1087  if (printing && !doc->okToPrint()) {
1088  fprintf(stderr, "Printing this document is not allowed.\n");
1089  exit(3);
1090  }
1091 #endif
1092 
1093  // get page range
1094  if (firstPage < 1)
1095  firstPage = 1;
1096  if (singleFile && lastPage < 1)
1097  lastPage = firstPage;
1098  if (lastPage < 1 || lastPage > doc->getNumPages())
1099  lastPage = doc->getNumPages();
1100 
1101  if (lastPage < firstPage) {
1102  fprintf(stderr, "Wrong page range given: the first page (%d) can not be after the last page (%d).\n", firstPage, lastPage);
1103  exit(99);
1104  }
1105  if (eps && firstPage != lastPage) {
1106  fprintf(stderr, "EPS files can only contain one page.\n");
1107  exit(99);
1108  }
1109 
1110  // If our page range selection and document size indicate we're only
1111  // outputting a single page, ensure that even/odd page selection doesn't
1112  // filter out that single page.
1113  if (firstPage == lastPage && ((printOnlyEven && firstPage % 2 == 1) || (printOnlyOdd && firstPage % 2 == 0))) {
1114  fprintf(stderr, "Invalid even/odd page selection, no pages match criteria.\n");
1115  exit(99);
1116  }
1117 
1118  if (singleFile && firstPage < lastPage) {
1119  if (!quiet) {
1120  fprintf(stderr, "Warning: Single file will write only the first of the %d pages.\n", lastPage + 1 - firstPage);
1121  }
1122  lastPage = firstPage;
1123  }
1124 
1125 #ifdef CAIRO_HAS_WIN32_SURFACE
1126  if (printdlg) {
1127  bool allPages = false;
1128  if (firstPage == 1 && lastPage == doc->getNumPages())
1129  allPages = true;
1131  if (allPages) {
1132  firstPage = 1;
1133  lastPage = doc->getNumPages();
1134  }
1135  } else if (printToWin32) {
1137  }
1138 #endif
1139 
1140  cairoOut = new CairoOutputDev();
1141 #ifdef USE_CMS
1142  cairoOut->setDisplayProfile(profile);
1143 #endif
1144  cairoOut->startDoc(doc.get());
1145  if (sz != 0)
1146  crop_w = crop_h = sz;
1147  pg_num_len = numberOfCharacters(doc->getNumPages());
1148  for (pg = firstPage; pg <= lastPage; ++pg) {
1149  if (printOnlyEven && pg % 2 == 1)
1150  continue;
1151  if (printOnlyOdd && pg % 2 == 0)
1152  continue;
1153  if (useCropBox) {
1154  pg_w = doc->getPageCropWidth(pg);
1155  pg_h = doc->getPageCropHeight(pg);
1156  } else {
1157  pg_w = doc->getPageMediaWidth(pg);
1158  pg_h = doc->getPageMediaHeight(pg);
1159  }
1160 
1161  if (printing && pg == firstPage) {
1162  if (paperWidth < 0 || paperHeight < 0) {
1163  paperWidth = (int)ceil(pg_w);
1164  paperHeight = (int)ceil(pg_h);
1165  }
1166  }
1167 
1168  if ((doc->getPageRotate(pg) == 90) || (doc->getPageRotate(pg) == 270)) {
1169  tmp = pg_w;
1170  pg_w = pg_h;
1171  pg_h = tmp;
1172  }
1173  if (scaleTo != 0) {
1174  resolution = (72.0 * scaleTo) / (pg_w > pg_h ? pg_w : pg_h);
1176  } else {
1177  if (x_scaleTo > 0) {
1178  x_resolution = (72.0 * x_scaleTo) / pg_w;
1179  if (y_scaleTo == -1)
1181  }
1182  if (y_scaleTo > 0) {
1183  y_resolution = (72.0 * y_scaleTo) / pg_h;
1184  if (x_scaleTo == -1)
1186  }
1187  }
1188  if (imageFileName) {
1189  delete imageFileName;
1190  imageFileName = nullptr;
1191  }
1192  if (!printing)
1193  imageFileName = getImageFileName(outputFileName, pg_num_len, pg);
1194  getOutputSize(pg_w, pg_h, &output_w, &output_h);
1195 
1196  if (pg == firstPage)
1197  beginDocument(fileName, outputFileName, output_w, output_h);
1198  beginPage(&output_w, &output_h);
1199  renderPage(doc.get(), cairoOut, pg, pg_w, pg_h, output_w, output_h);
1200  endPage(imageFileName);
1201  }
1202  endDocument();
1203 
1204  // clean up
1205  delete cairoOut;
1206  if (fileName)
1207  delete fileName;
1208  if (outputName)
1209  delete outputName;
1210  if (outputFileName)
1211  delete outputFileName;
1212  if (imageFileName)
1213  delete imageFileName;
1214  if (ownerPW)
1215  delete ownerPW;
1216  if (userPW)
1217  delete userPW;
1218 
1219 #ifdef USE_CMS
1220  if (icc_data)
1221  gfree(icc_data);
1222 #endif
1223 
1224  return 0;
1225 }
#define width(a)
Definition: aptex-macros.h:198
#define name
#define height(a)
Definition: aptex-macros.h:200
int cairo_image_surface_get_height(cairo_surface_t *surface)
int cairo_image_surface_get_stride(cairo_surface_t *surface)
unsigned char * cairo_image_surface_get_data(cairo_surface_t *surface)
cairo_surface_t * cairo_image_surface_create(cairo_format_t format, int width, int height)
int cairo_image_surface_get_width(cairo_surface_t *surface)
void cairo_matrix_init(cairo_matrix_t *matrix, double xx, double yx, double xy, double yy, double x0, double y0)
Definition: cairo-matrix.c:111
void cairo_matrix_init_identity(cairo_matrix_t *matrix)
Definition: cairo-matrix.c:81
void cairo_matrix_translate(cairo_matrix_t *matrix, double tx, double ty)
Definition: cairo-matrix.c:197
void cairo_matrix_scale(cairo_matrix_t *matrix, double sx, double sy)
Definition: cairo-matrix.c:242
const char * cairo_status_to_string(cairo_status_t status)
Definition: cairo-misc.c:87
cairo_surface_t * cairo_pdf_surface_create_for_stream(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points)
void cairo_pdf_surface_set_size(cairo_surface_t *surface, double width_in_points, double height_in_points)
void cairo_ps_surface_dsc_begin_setup(cairo_surface_t *surface)
void cairo_ps_surface_restrict_to_level(cairo_surface_t *surface, cairo_ps_level_t level)
void cairo_ps_surface_dsc_begin_page_setup(cairo_surface_t *surface)
cairo_surface_t * cairo_ps_surface_create_for_stream(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points)
void cairo_ps_surface_set_size(cairo_surface_t *surface, double width_in_points, double height_in_points)
void cairo_ps_surface_set_eps(cairo_surface_t *surface, cairo_bool_t eps)
void cairo_ps_surface_dsc_comment(cairo_surface_t *surface, char *comment)
@ CAIRO_PS_LEVEL_2
Definition: cairo-ps.h:62
void cairo_surface_destroy(cairo_surface_t *surface)
void cairo_surface_set_fallback_resolution(cairo_surface_t *surface, double x_pixels_per_inch, double y_pixels_per_inch)
void cairo_surface_finish(cairo_surface_t *surface)
cairo_status_t cairo_surface_status(cairo_surface_t *surface)
void cairo_surface_flush(cairo_surface_t *surface)
void cairo_surface_show_page(cairo_surface_t *surface)
void cairo_svg_surface_restrict_to_version(cairo_surface_t *abstract_surface, cairo_svg_version_t version)
cairo_surface_t * cairo_svg_surface_create_for_stream(cairo_write_func_t write_func, void *closure, double width, double height)
@ CAIRO_SVG_VERSION_1_2
Definition: cairo-svg.h:53
void cairo_rectangle(cairo_t *cr, double x, double y, double width, double height)
Definition: cairo.c:2078
void cairo_translate(cairo_t *cr, double tx, double ty)
Definition: cairo.c:1409
void cairo_scale(cairo_t *cr, double sx, double sy)
Definition: cairo.c:1436
cairo_status_t cairo_status(cairo_t *cr)
Definition: cairo.c:4338
void cairo_transform(cairo_t *cr, const cairo_matrix_t *matrix)
Definition: cairo.c:1488
cairo_t * cairo_create(cairo_surface_t *target)
Definition: cairo.c:446
void cairo_save(cairo_t *cr)
Definition: cairo.c:624
void cairo_set_source_rgb(cairo_t *cr, double red, double green, double blue)
Definition: cairo.c:893
void cairo_restore(cairo_t *cr)
Definition: cairo.c:648
void cairo_paint(cairo_t *cr)
Definition: cairo.c:2213
void cairo_set_operator(cairo_t *cr, cairo_operator_t op)
Definition: cairo.c:832
void cairo_destroy(cairo_t *cr)
Definition: cairo.c:519
void cairo_clip(cairo_t *cr)
Definition: cairo.c:2706
enum _cairo_antialias cairo_antialias_t
@ CAIRO_STATUS_SUCCESS
Definition: cairo.h:315
@ CAIRO_STATUS_WRITE_ERROR
Definition: cairo.h:327
@ CAIRO_ANTIALIAS_SUBPIXEL
Definition: cairo.h:715
@ CAIRO_ANTIALIAS_DEFAULT
Definition: cairo.h:710
@ CAIRO_ANTIALIAS_BEST
Definition: cairo.h:720
@ CAIRO_ANTIALIAS_GOOD
Definition: cairo.h:719
@ CAIRO_ANTIALIAS_FAST
Definition: cairo.h:718
@ CAIRO_ANTIALIAS_NONE
Definition: cairo.h:713
@ CAIRO_ANTIALIAS_GRAY
Definition: cairo.h:714
@ CAIRO_OPERATOR_DEST_OVER
Definition: cairo.h:623
enum _cairo_status cairo_status_t
@ CAIRO_FORMAT_ARGB32
Definition: cairo.h:418
static struct brw_reg stride(struct brw_reg reg, uint32_t vstride, uint32_t width, uint32_t hstride)
void setPrinting(bool printingA)
void startDoc(PDFDoc *docA, CairoFontEngine *fontEngine=nullptr)
void setCairo(cairo_t *cr)
void setAntialias(cairo_antialias_t antialias)
void setErrQuiet(GBool errQuietA)
GooString * del(int i, int n=1)
Definition: GooString.h:214
GooString * Set(const GooString *newStr)
Definition: GooString.h:83
int cmp(const GooString *str) const
Definition: GooString.h:224
int getLength() const
Definition: GooString.h:142
GooString * append(char c)
Definition: GooString.h:161
void setDisplayProfile(const GfxLCMSProfilePtr &profile)
Definition: OutputDev.h:349
std::unique_ptr< PDFDoc > createPDFDoc(const GooString &uri, GooString *ownerPassword=nullptr, GooString *userPassword=nullptr, void *guiDataA=nullptr)
Definition: PDFDoc.h:38
void displayPageSlice(OutputDev *out, int page, double hDPI, double vDPI, int rotate, GBool useMediaBox, GBool crop, GBool printing, int sliceX, int sliceY, int sliceW, int sliceH, GBool(*abortCheckCbk)(void *data)=NULL, void *abortCheckCbkData=NULL)
Definition: PDFDoc.cc:471
int getNumPages()
Definition: PDFDoc.h:93
double getPageCropWidth(int page)
Definition: PDFDoc.h:85
double getPageCropHeight(int page)
Definition: PDFDoc.h:87
double getPageMediaHeight(int page)
Definition: PDFDoc.h:83
int getPageRotate(int page)
Definition: PDFDoc.h:89
double getPageMediaWidth(int page)
Definition: PDFDoc.h:81
GBool okToPrint(GBool ignoreOwnerPW=0)
Definition: PDFDoc.h:156
GBool isOk()
Definition: PDFDoc.h:60
@ MONOCHROME
Definition: PNGWriter.h:41
void cmsGetHeaderProfileID(cmsHPROFILE hProfile, cmsUInt8Number *ProfileID)
Definition: cmsio0.c:922
cmsHPROFILE cmsOpenProfileFromMem(const void *MemPtr, cmsUInt32Number dwSize)
Definition: cmsio0.c:1167
cmsHPROFILE cmsCreate_sRGBProfile(void)
Definition: cmsvirt.c:670
#define b
Definition: jpegint.h:372
#define strrchr
Definition: detex.c:67
#define gfree(p)
Definition: dt2dv.c:326
int w
Definition: dviconv.c:26
int h
Definition: dviconv.c:9
#define fopen
Definition: xxstdio.h:21
#define fread
Definition: xxstdio.h:25
#define fflush
Definition: xxstdio.h:24
#define fseek
Definition: xxstdio.h:30
#define ftell
Definition: xxstdio.h:31
@ GRAY
Definition: dvi2xx.c:3536
int strcmp()
Definition: coll.cpp:143
struct rect data
Definition: dvipdfm.c:64
#define s
Definition: afcover.h:80
#define comma
Definition: globals.h:57
void * gmalloc(int size)
Definition: gmem.cc:139
void * gmallocn(int nObjs, int objSize)
Definition: gmem.cc:204
__gmp_expr< mpf_t, __gmp_unary_expr< __gmp_expr< mpf_t, U >, __gmp_ceil_function > > ceil(const __gmp_expr< mpf_t, U > &expr)
Definition: gmpxx.h:3340
#define a(n)
Definition: gpos-common.c:148
#define strchr
Definition: gsftopk.c:59
double y_scale
Definition: hbf2gf.c:275
static const char * progname
Definition: cjpeg.c:136
#define SEEK_SET
Definition: jmemansi.c:26
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p
Definition: afcover.h:72
#define SEEK_END
Definition: ftzconf.h:251
void exit()
kerning y
Definition: ttdriver.c:212
#define PACKAGE_VERSION
Definition: config.h:105
unsigned int uint32_t
Definition: stdint.h:80
unsigned char uint8_t
Definition: stdint.h:78
static const char argv0[]
Definition: webpng.c:25
@ argFlag
Definition: parseargs.h:22
@ argInt
Definition: parseargs.h:24
@ argString
Definition: parseargs.h:28
@ argFP
Definition: parseargs.h:26
GlobalParams * globalParams
#define xpdfCopyright
Definition: config.h:31
static PDFDoc * doc
Definition: pdffonts.cc:89
int atoi(const char *)
#define O_BINARY
Definition: config.h:393
#define buf
#define strcasecmp
Definition: c-auto.h:150
#define fclose
Definition: debug.h:100
#define fileno
Definition: win32lib.h:72
#define fprintf
Definition: mendex.h:64
char * closure
Definition: font.h:85
#define length(c)
Definition: ctangleboot.c:65
Code related to b fwrite(a, sizeof(char), b, stdout) @d C_printf(c
int setmode()
#define snprintf
Definition: snprintf.c:41
unsigned char cmsUInt8Number
Definition: lcms2.h:90
#define RGB
Definition: mitsu.h:92
float x
Definition: cordic.py:15
Definition: pdf.py:1
static int numberOfCharacters(unsigned int n)
union value value
Definition: obx.h:44
char outputFileName[256]
Definition: param.c:262
GBool parseArgs(ArgDesc *args, int *argc, char *argv[])
Definition: parseargs.c:19
GBool isInt(char *s)
Definition: parseargs.c:155
unsigned char bit
Definition: pbm.h:9
char * filename[256]
Definition: pbmtopk.c:46
void win32BeginPage(double *w, double *h, bool changePageSize, bool useFullPage)
void win32EndDocument()
void win32SetupPrinter(GooString *printer, GooString *printOpt, bool duplex, bool setupdlg)
cairo_surface_t * win32BeginDocument(GooString *inputFileName, GooString *outputFileName)
void win32EndPage(GooString *imageFileName)
void win32ShowPrintDialog(bool *expand, bool *noShrink, bool *noCenter, bool *usePDFPageSize, bool *allPages, int *firstPage, int *lastPage, int maxPages)
static void getOutputSize(double page_w, double page_h, double *width, double *height)
Definition: pdftocairo.cc:503
static char paperSize[15]
Definition: pdftocairo.cc:125
static bool parseJpegOptions()
Definition: pdftocairo.cc:278
static bool origPageSizes
Definition: pdftocairo.cc:124
static void checkInvalidPrintOption(bool option, const char *option_name)
Definition: pdftocairo.cc:846
static double resolution
Definition: pdftocairo.cc:104
int main(int argc, char *argv[])
Definition: pdftocairo.cc:869
static bool expand
Definition: pdftocairo.cc:129
static int sz
Definition: pdftocairo.cc:114
static bool printdlg
Definition: pdftocairo.cc:95
static bool ps
Definition: pdftocairo.cc:91
static bool singleFile
Definition: pdftocairo.cc:103
static GooString * getImageFileName(GooString *outputFileName, int numDigits, int page)
Definition: pdftocairo.cc:760
static bool duplex
Definition: pdftocairo.cc:132
static void renderPage(PDFDoc *doc, CairoOutputDev *cairoOut, int pg, double page_w, double page_h, double output_w, double output_h)
Definition: pdftocairo.cc:645
static bool pdf
Definition: pdftocairo.cc:93
static FILE * output_file
Definition: pdftocairo.cc:236
static bool jpeg
Definition: pdftocairo.cc:90
static char tiffCompressionStr[16]
Definition: pdftocairo.cc:133
static void checkInvalidImageOption(bool option, const char *option_name)
Definition: pdftocairo.cc:854
static GooString jpegOpt
Definition: pdftocairo.cc:141
static bool printOnlyOdd
Definition: pdftocairo.cc:101
static bool printing
Definition: pdftocairo.cc:235
static int paperHeight
Definition: pdftocairo.cc:127
static int paperWidth
Definition: pdftocairo.cc:126
static void writePageImage(GooString *filename)
Definition: pdftocairo.cc:337
static void getFitToPageTransform(double page_w, double page_h, double paper_w, double paper_h, cairo_matrix_t *m)
Definition: pdftocairo.cc:524
static unsigned char * icc_data
Definition: pdftocairo.cc:241
static cairo_status_t writeStream(void *closure, const unsigned char *data, unsigned int length)
Definition: pdftocairo.cc:551
static bool transp
Definition: pdftocairo.cc:118
static int crop_x
Definition: pdftocairo.cc:110
static bool mono
Definition: pdftocairo.cc:116
static int jpegQuality
Definition: pdftocairo.cc:142
static bool tiff
Definition: pdftocairo.cc:97
static bool usePDFPageSize
Definition: pdftocairo.cc:237
static GfxLCMSProfilePtr profile
Definition: pdftocairo.cc:243
static bool level3
Definition: pdftocairo.cc:123
static int icc_data_size
Definition: pdftocairo.cc:242
static bool printVersion
Definition: pdftocairo.cc:138
static const ArgDesc argDesc[]
Definition: pdftocairo.cc:152
static void getCropSize(double page_w, double page_h, double *width, double *height)
Definition: pdftocairo.cc:488
static GooString * getOutputFileName(GooString *fileName, GooString *outputName)
Definition: pdftocairo.cc:782
static int lastPage
Definition: pdftocairo.cc:100
static bool svg
Definition: pdftocairo.cc:96
static bool level2
Definition: pdftocairo.cc:122
static cairo_surface_t * surface
Definition: pdftocairo.cc:234
static bool png
Definition: pdftocairo.cc:89
static void endDocument()
Definition: pdftocairo.cc:719
static GooString printOpt
Definition: pdftocairo.cc:147
static double x_resolution
Definition: pdftocairo.cc:105
static bool noShrink
Definition: pdftocairo.cc:130
static bool noCenter
Definition: pdftocairo.cc:131
static cairo_antialias_t antialiasEnum
Definition: pdftocairo.cc:238
static bool parseAntialiasOption()
Definition: pdftocairo.cc:257
static bool jpegOptimize
Definition: pdftocairo.cc:144
static GooString icc
Definition: pdftocairo.cc:120
static bool useCropBox
Definition: pdftocairo.cc:115
static double y_resolution
Definition: pdftocairo.cc:106
static int crop_y
Definition: pdftocairo.cc:111
static bool printToWin32
Definition: pdftocairo.cc:94
static void endPage(GooString *imageFileName)
Definition: pdftocairo.cc:697
static bool printHelp
Definition: pdftocairo.cc:139
static bool jpegProgressive
Definition: pdftocairo.cc:143
static const AntialiasOption antialiasOptions[]
Definition: pdftocairo.cc:252
static int x_scaleTo
Definition: pdftocairo.cc:108
static bool setPSPaperSize(char *size, int &psPaperWidth, int &psPaperHeight)
Definition: pdftocairo.cc:738
static int crop_h
Definition: pdftocairo.cc:113
static int y_scaleTo
Definition: pdftocairo.cc:109
static char ownerPassword[33]
Definition: pdftocairo.cc:135
static GooString antialias
Definition: pdftocairo.cc:119
static bool eps
Definition: pdftocairo.cc:92
static int firstPage
Definition: pdftocairo.cc:99
static bool printOnlyEven
Definition: pdftocairo.cc:102
static GooString printer
Definition: pdftocairo.cc:146
static int crop_w
Definition: pdftocairo.cc:112
static bool quiet
Definition: pdftocairo.cc:137
static char userPassword[33]
Definition: pdftocairo.cc:136
static bool setupdlg
Definition: pdftocairo.cc:149
static int scaleTo
Definition: pdftocairo.cc:107
static void beginPage(double *w, double *h)
Definition: pdftocairo.cc:609
static bool gray
Definition: pdftocairo.cc:117
static void beginDocument(GooString *inputFileName, GooString *outputFileName, double w, double h)
Definition: pdftocairo.cc:561
static bool noCrop
Definition: pdftocairo.cc:128
unsigned int gray
Definition: pgm.h:10
double scale
Definition: pnmhistmap.c:38
void printUsage()
#define popplerCopyright
static int size
Definition: ppmlabel.c:24
int g
Definition: ppmqvga.c:68
int r
Definition: ppmqvga.c:68
int equal(char *s, char *t)
static int row
Definition: ps2pk.c:587
#define status
GfxLCMSProfilePtr make_GfxLCMSProfilePtr(void *profile)
Definition: GfxState.cc:176
std::shared_ptr< void > GfxLCMSProfilePtr
Definition: GfxState.h:216
@ argGooString
Definition: parseargs.h:44
static int writer(lua_State *L, const void *b, size_t size, void *B)
Definition: lstrlib.c:182
const char * name
Definition: pdftocairo.cc:248
cairo_antialias_t value
Definition: pdftocairo.cc:249
Definition: filedef.h:30
Definition: jpeg.h:35
Definition: getopt.h:95
int value
Definition: gsftopk.c:425
char * name
Definition: getopt.h:99
Definition: mendex.h:14
Definition: ppm.h:33
Definition: tiffiop.h:70
#define FILE
Definition: t1stdio.h:34
*job_name strlen((char *) job_name) - 4)
char * file
Definition: t4ht.c:931
m
Definition: tex4ht.c:3990
return() int(((double) *(font_tbl[cur_fnt].wtbl+(int)(*(font_tbl[cur_fnt].char_wi+(int)(ch - font_tbl[cur_fnt].char_f)% 256)))/(double)(1L<< 20)) *(double) font_tbl[cur_fnt].scale)
const char * fileName
Definition: ugrep.cpp:52
Definition: obx.h:51
char cr[]
Definition: vlna.c:107
#define argv
Definition: xmain.c:270
#define argc
Definition: xmain.c:269