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

« back to all changes in this revision

Viewing changes to filter/pdftopdf/P2PDoc.cxx

  • Committer: Package Import Robot
  • Author(s): Till Kamppeter
  • Date: 2012-08-20 14:53:42 UTC
  • mfrom: (2.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20120820145342-bddzpwqv0klmt84d
Tags: 1.0.22-1
* New upstream release
   - pdftopdf filter replaced by new QPDF-based filter from Tobias
     Hoffmann's Google Summer of Code project. The former Poppler-based
     pdftopdf duplicated a lot of Poppler's code. The old filter is
     still in the package as pdftopdf.old with source code in
     filter/pdftopdf.old. It will be removed in a later release.
   - bannertopdf: Page duplication routine fixed.
   - bannertopdf: Fixed invalid output of a direct stream object.
   - Added most recent contributors to AUTHORS and COPYING files.
* debian/control: Added build dependency on libqpdf-dev.
* debian/copyright: Updated for the addition of the new pdftopdf filter.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 
3
 
Copyright (c) 2006-2007, BBR Inc.  All rights reserved.
4
 
 
5
 
Permission is hereby granted, free of charge, to any person obtaining
6
 
a copy of this software and associated documentation files (the
7
 
"Software"), to deal in the Software without restriction, including
8
 
without limitation the rights to use, copy, modify, merge, publish,
9
 
distribute, sublicense, and/or sell copies of the Software, and to
10
 
permit persons to whom the Software is furnished to do so, subject to
11
 
the following conditions:
12
 
 
13
 
The above copyright notice and this permission notice shall be included
14
 
in all copies or substantial portions of the Software.
15
 
 
16
 
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
 
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
 
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
 
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
 
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
 
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
 
 
24
 
*/
25
 
/*
26
 
 P2PDoc.cc
27
 
 pdftopdf doc
28
 
*/
29
 
 
30
 
#include <config.h>
31
 
#include "goo/gmem.h"
32
 
#include "P2PDoc.h"
33
 
#include "P2PXRef.h"
34
 
#include "XRef.h"
35
 
#include "P2PCatalog.h"
36
 
#include <time.h>
37
 
 
38
 
P2PDoc::Options P2PDoc::options;
39
 
 
40
 
/* Constructor */
41
 
P2PDoc::P2PDoc(PDFDoc *orgDocA)
42
 
{
43
 
  orgDoc = orgDocA;
44
 
  catalog = new P2PCatalog(orgDoc->getCatalog(),orgDoc->getXRef());
45
 
}
46
 
 
47
 
P2PDoc::~P2PDoc()
48
 
{
49
 
  delete catalog;
50
 
  P2PXRef::clean();
51
 
}
52
 
 
53
 
void P2PDoc::output(P2POutputStream *str, int deviceCopies, bool deviceCollate)
54
 
{
55
 
  int xrefOffset;
56
 
  int num, gen;
57
 
  time_t        curtime;
58
 
  struct tm     *curtm;
59
 
  char          curdate[255];
60
 
  char  version[10];
61
 
  XRef *xref = orgDoc->getXRef();
62
 
  Object obj;
63
 
  Dict documentInfo(xref);
64
 
 
65
 
  /* get time data */
66
 
  curtime = time(NULL);
67
 
  curtm = localtime(&curtime);
68
 
  strftime(curdate, sizeof(curdate),"D:%Y%m%d%H%M%S%z", curtm);
69
 
 
70
 
  /*
71
 
   *  fill document info 
72
 
   */
73
 
  if (options.title != 0) {
74
 
    documentInfo.add(strdup("Title"),(new Object())->initString(new GooString(options.title)));
75
 
  }
76
 
  documentInfo.add(strdup("CreationDate"),(new Object())->initString(new GooString(curdate)));
77
 
  documentInfo.add(strdup("ModDate"),(new Object())->initString(new GooString(curdate)));
78
 
  documentInfo.add(strdup("Producer"),(new Object())->initString(new GooString("pdftopdf")));
79
 
 
80
 
  /* Hack to produce "/False". Object::initBool results wrongly in "false" */
81
 
  documentInfo.add(strdup("Trapped"),(new Object())->initName("False"));
82
 
 
83
 
  obj.initDict(&documentInfo);
84
 
  P2PObj object(&obj);
85
 
  P2PXRef::put(&object);
86
 
 
87
 
 
88
 
  /* output header */
89
 
  snprintf(version,sizeof(version),"%%PDF-%d.%d\n",
90
 
     orgDoc->getPDFMajorVersion(),orgDoc->getPDFMinorVersion());
91
 
  str->puts(version);
92
 
  str->puts("%\0201\0202\0203\0204\n");
93
 
  str->puts("% This file was generated by pdftopdf\n");
94
 
 
95
 
  /*
96
 
   * output device copies commen
97
 
   * This is not standard, but like PostScript.
98
 
   */
99
 
  if (deviceCopies > 0) {
100
 
    str->printf("%%%%PDFTOPDFNumCopies : %d\n",deviceCopies);
101
 
    str->printf("%%%%PDFTOPDFCollate : %s\n",deviceCollate ? "true" : "false");
102
 
  }
103
 
 
104
 
  /* output body */
105
 
  catalog->output(str,options.copies,options.collate);
106
 
  /* output objects that are not output yet. */
107
 
  P2PXRef::flush(str,xref);
108
 
 
109
 
  /* output cross reference */
110
 
  xrefOffset = P2PXRef::output(str);
111
 
 
112
 
  /* output trailer */
113
 
  catalog->getNum(&num,&gen);
114
 
  str->puts("trailer\n");
115
 
  str->printf("<< /Size %d /Root %d %d R \n",P2PXRef::getNObjects(),
116
 
    num,gen);
117
 
 
118
 
  object.getNum(&num,&gen);
119
 
  str->printf("   /Info %d %d R\n",num,gen);
120
 
 
121
 
  str->puts(">>\n");
122
 
  str->puts("startxref\n");
123
 
  str->printf("%d\n",xrefOffset);
124
 
  str->puts("%%EOF\n");
125
 
}
126
 
 
127
 
int P2PDoc::nup(int n, PDFRectangle *box,
128
 
  unsigned int borderFlag, unsigned int layout,
129
 
  int xpos, int ypos)
130
 
{
131
 
  if (n == 1) return 0;
132
 
  switch (n) {
133
 
  case 2:
134
 
  case 4:
135
 
  case 6:
136
 
  case 8:
137
 
  case 9:
138
 
  case 16:
139
 
    break;
140
 
  default:
141
 
    return -1;
142
 
  }
143
 
  return catalog->nup(n,box,borderFlag,layout,xpos,ypos);
144
 
}
145
 
 
146
 
void P2PDoc::select()
147
 
{
148
 
  catalog->select(options.pageSet,options.pageRanges);
149
 
}
150
 
 
151
 
void P2PDoc::fit(PDFRectangle *box, double zoom)
152
 
{
153
 
  catalog->fit(box,zoom);
154
 
}
155
 
 
156
 
void P2PDoc::mirror()
157
 
{
158
 
  catalog->mirror();
159
 
}
160
 
 
161
 
void P2PDoc::rotate(int orientation)
162
 
{
163
 
  catalog->rotate(orientation);
164
 
}
165
 
 
166
 
void P2PDoc::position(PDFRectangle *box, int xpos, int ypos)
167
 
{
168
 
  catalog->position(box,xpos,ypos);
169
 
}
170
 
 
171
 
void P2PDoc::scale(double zoom)
172
 
{
173
 
  catalog->scale(zoom);
174
 
}
175
 
 
176
 
void P2PDoc::autoRotate(PDFRectangle *box)
177
 
{
178
 
  catalog->autoRotate(box);
179
 
}
180
 
 
181
 
void P2PDoc::setMediaBox(PDFRectangle *mediaBoxA)
182
 
{
183
 
  catalog->setMediaBox(mediaBoxA);
184
 
}
185
 
 
186
 
int P2PDoc::getNumberOfPages()
187
 
{
188
 
  return catalog->getNumberOfPages();
189
 
}