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

« back to all changes in this revision

Viewing changes to filter/pdftopdf/P2PPattern.cxx

  • Committer: Package Import Robot
  • Author(s): Till Kamppeter
  • Date: 2012-07-22 18:57:32 UTC
  • mfrom: (1.1.17)
  • Revision ID: package-import@ubuntu.com-20120722185732-26kkte5p1lth3rt5
Tags: 1.0.20-0bzr1
* 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.

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
 P2PPattern.cc
 
27
 pdftopdf pattern object
 
28
*/
 
29
#include "goo/gmem.h"
 
30
#include "Object.h"
 
31
#include "P2PObject.h"
 
32
#include "GfxState.h"
 
33
#include "Dict.h"
 
34
#include "XRef.h"
 
35
#include "P2POutputStream.h"
 
36
#include "P2PMatrix.h"
 
37
#include "P2PPattern.h"
 
38
#include "P2PError.h"
 
39
#include "P2PFont.h"
 
40
#include "P2PGfx.h"
 
41
#include "P2PDoc.h"
 
42
 
 
43
P2PPattern::P2PPattern(Object *objA, XRef *xrefA, P2PMatrix *matA)
 
44
{
 
45
  P2PObject *pobj;
 
46
 
 
47
  mat = *matA;
 
48
  if (objA->isRef()) {
 
49
    pobj = P2PObject::find(objA->getRefNum(),objA->getRefGen());
 
50
    if (pobj != 0) {
 
51
      pattern = static_cast<OrgPattern *>(pobj);
 
52
      pattern->reference();
 
53
    } else {
 
54
      pattern = new OrgPattern(objA->getRefNum(),objA->getRefGen(),xrefA);
 
55
    }
 
56
  } else if (objA->isDict()) {
 
57
    pattern = new OrgPattern(objA);
 
58
  } else {
 
59
    p2pError(-1,const_cast<char *>("Illegal Pattern object type"));
 
60
  }
 
61
}
 
62
 
 
63
P2PPattern::~P2PPattern()
 
64
{
 
65
  if (pattern != 0) {
 
66
    int c = pattern->free();
 
67
    if (c <= 0) delete pattern;
 
68
    pattern = 0;
 
69
  }
 
70
}
 
71
 
 
72
void P2PPattern::output(P2POutputStream *str, XRef *xrefA)
 
73
{
 
74
  GfxPattern *orgPattern;
 
75
 
 
76
  if (getOffset() >= 0) return; /* already output */
 
77
  if (pattern == 0 || (orgPattern = pattern->getPattern()) == 0) return;
 
78
  switch (orgPattern->getType()) {
 
79
  case 1: /* tiling pattern */
 
80
    outputTilingPattern(str,orgPattern, xrefA);
 
81
    break;
 
82
  case 2: /* shading pattern */
 
83
    outputShadingPattern(str,orgPattern,pattern->getOrgObject(),xrefA);
 
84
    break;
 
85
  default:
 
86
    p2pError(-1,const_cast<char *>("Unknown pattern type %d"),orgPattern->getType());
 
87
    break;
 
88
  }
 
89
}
 
90
 
 
91
void P2PPattern::outputTilingPattern(P2POutputStream *str,
 
92
  GfxPattern *patternA, XRef *xref)
 
93
{
 
94
  P2PFontResource fontResource;
 
95
  P2PFontResource *fr = 0;
 
96
  Dict *resDict;
 
97
  GfxTilingPattern *tilingPattern
 
98
     = static_cast<GfxTilingPattern *>(patternA);
 
99
  double *box;
 
100
  double *orgMat;
 
101
  Object lenobj;
 
102
  int start;
 
103
  int len;
 
104
 
 
105
  outputBegin(str);
 
106
 
 
107
  if (P2PDoc::options.fontEmbedding
 
108
     && (resDict = tilingPattern->getResDict()) != 0) {
 
109
    fontResource.setup(resDict,xref);
 
110
    fr = &fontResource;
 
111
  }
 
112
  /* output dict part */
 
113
  str->puts("<< /Type /Pattern /PatternType 1");
 
114
  str->printf(" /PaintType %d",tilingPattern->getPaintType());
 
115
  str->printf(" /TilingType %d",tilingPattern->getTilingType());
 
116
  box = tilingPattern->getBBox();
 
117
  str->printf(" /BBox [ %f %f %f %f ]",box[0],box[1],box[2],box[3]);
 
118
  str->printf(" /XStep %f",tilingPattern->getXStep());
 
119
  str->printf(" /YStep %f",tilingPattern->getYStep());
 
120
  str->puts(" /Resources ");
 
121
  if ((resDict = tilingPattern->getResDict()) == 0) {
 
122
    str->puts("<< /ProcSet [ /PDF ] >>");
 
123
  } else {
 
124
    if (fr != 0) {
 
125
      /* replace font resource */
 
126
      const char *p = "Font";
 
127
      P2PObject *objp = fr;
 
128
 
 
129
      P2POutput::outputDict(resDict,&p,&objp,1,str,xref);
 
130
    } else {
 
131
      P2POutput::outputDict(resDict,str,xref);
 
132
    }
 
133
  }
 
134
  orgMat = tilingPattern->getMatrix();
 
135
  P2PMatrix porgMat(orgMat[0],orgMat[1],orgMat[2],orgMat[3],
 
136
                   orgMat[4],orgMat[5]);
 
137
  porgMat.trans(&mat);
 
138
  str->puts(" /Matrix [ ");
 
139
  porgMat.output(str);
 
140
  str->puts(" ]\n");
 
141
  str->puts(" /Length ");
 
142
  P2PObj *pobj = new P2PObj();
 
143
  P2PXRef::put(pobj);
 
144
  pobj->outputRef(str);
 
145
  if (P2PDoc::options.contentsCompress && str->canDeflate()) {
 
146
    str->puts(" /Filter /FlateDecode ");
 
147
  }
 
148
  str->puts(" >>\n");
 
149
 
 
150
  /* output Contents */
 
151
  P2PGfx output(xref,str,fr,0);
 
152
  str->puts("stream\n");
 
153
  start = str->getPosition();
 
154
  if (P2PDoc::options.contentsCompress) str->startDeflate();
 
155
  output.outputContents(tilingPattern->getContentStream(),0,resDict,&porgMat);
 
156
  if (P2PDoc::options.contentsCompress) str->endDeflate();
 
157
  len = str->getPosition()-start;
 
158
  str->puts("\nendstream\n");
 
159
  /* set length object value */
 
160
  lenobj.initInt(len);
 
161
  pobj->setObj(&lenobj);
 
162
  lenobj.free();
 
163
 
 
164
  outputEnd(str);
 
165
 
 
166
  /* out length object */
 
167
  pobj->output(str,xref);
 
168
}
 
169
 
 
170
void P2PPattern::outputShadingPattern(P2POutputStream *str,
 
171
  GfxPattern *patternA, Object *objA, XRef *xref)
 
172
{
 
173
  GfxShadingPattern *shadingPattern
 
174
     = static_cast<GfxShadingPattern *>(patternA);
 
175
  double *orgMat;
 
176
  Object matObj;
 
177
  int i;
 
178
  Object m[6];
 
179
 
 
180
  outputBegin(str);
 
181
 
 
182
  orgMat = shadingPattern->getMatrix();
 
183
  P2PMatrix porgMat(orgMat[0],orgMat[1],orgMat[2],orgMat[3],
 
184
                   orgMat[4],orgMat[5]);
 
185
  porgMat.trans(&mat);
 
186
  /* make matrix object */
 
187
  matObj.initArray(xref);
 
188
  for (i = 0;i < 6;i++) {
 
189
    m[i].initReal(porgMat.mat[i]);
 
190
    matObj.arrayAdd(&(m[i]));
 
191
  }
 
192
 
 
193
  /* replace Matrix */
 
194
  const char *p = "Matrix";
 
195
  P2PObject *objp = new P2PObj(&matObj);
 
196
  P2POutput::outputDict(objA->getDict(),&p,&objp,1,str,xref);
 
197
  delete objp;
 
198
 
 
199
  outputEnd(str);
 
200
 
 
201
  matObj.free();
 
202
  for (i = 0;i < 6;i++) {
 
203
    m[i].free();
 
204
  }
 
205
}
 
206
 
 
207
P2PPattern::OrgPattern::OrgPattern(int orgNumA, int orgGenA, XRef *xref)
 
208
  : P2PObject(orgNumA, orgGenA)
 
209
{
 
210
  pattern = 0;
 
211
  refCount = 1;
 
212
  xref->fetch(orgNumA,orgGenA,&orgObj);
 
213
#ifdef OLD_CS_PARSE
 
214
  if ((pattern = GfxPattern::parse(&orgObj)) == 0) {
 
215
#else
 
216
  if ((pattern = GfxPattern::parse(&orgObj,NULL)) == 0) {
 
217
#endif
 
218
    p2pError(-1,const_cast<char *>("Bad Pattern"));
 
219
  }
 
220
}
 
221
 
 
222
P2PPattern::OrgPattern::OrgPattern(Object *objA)
 
223
{
 
224
  pattern = 0;
 
225
  refCount = 1;
 
226
  objA->copy(&orgObj);
 
227
#ifdef OLD_CS_PARSE
 
228
  if ((pattern = GfxPattern::parse(&orgObj)) == 0) {
 
229
#else
 
230
  if ((pattern = GfxPattern::parse(&orgObj,NULL)) == 0) {
 
231
#endif
 
232
    p2pError(-1,const_cast<char *>("Bad Pattern"));
 
233
  }
 
234
}
 
235
 
 
236
P2PPattern::OrgPattern::~OrgPattern()
 
237
{
 
238
  if (pattern != 0) delete pattern;
 
239
  orgObj.free();
 
240
}