3
Copyright (c) 2006-2007, BBR Inc. All rights reserved.
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:
13
The above copyright notice and this permission notice shall be included
14
in all copies or substantial portions of the Software.
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.
27
pdftopdf pattern object
31
#include "P2PObject.h"
35
#include "P2POutputStream.h"
36
#include "P2PMatrix.h"
37
#include "P2PPattern.h"
43
P2PPattern::P2PPattern(Object *objA, XRef *xrefA, P2PMatrix *matA)
49
pobj = P2PObject::find(objA->getRefNum(),objA->getRefGen());
51
pattern = static_cast<OrgPattern *>(pobj);
54
pattern = new OrgPattern(objA->getRefNum(),objA->getRefGen(),xrefA);
56
} else if (objA->isDict()) {
57
pattern = new OrgPattern(objA);
59
p2pError(-1,const_cast<char *>("Illegal Pattern object type"));
63
P2PPattern::~P2PPattern()
66
int c = pattern->free();
67
if (c <= 0) delete pattern;
72
void P2PPattern::output(P2POutputStream *str, XRef *xrefA)
74
GfxPattern *orgPattern;
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);
82
case 2: /* shading pattern */
83
outputShadingPattern(str,orgPattern,pattern->getOrgObject(),xrefA);
86
p2pError(-1,const_cast<char *>("Unknown pattern type %d"),orgPattern->getType());
91
void P2PPattern::outputTilingPattern(P2POutputStream *str,
92
GfxPattern *patternA, XRef *xref)
94
P2PFontResource fontResource;
95
P2PFontResource *fr = 0;
97
GfxTilingPattern *tilingPattern
98
= static_cast<GfxTilingPattern *>(patternA);
107
if (P2PDoc::options.fontEmbedding
108
&& (resDict = tilingPattern->getResDict()) != 0) {
109
fontResource.setup(resDict,xref);
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 ] >>");
125
/* replace font resource */
126
const char *p = "Font";
127
P2PObject *objp = fr;
129
P2POutput::outputDict(resDict,&p,&objp,1,str,xref);
131
P2POutput::outputDict(resDict,str,xref);
134
orgMat = tilingPattern->getMatrix();
135
P2PMatrix porgMat(orgMat[0],orgMat[1],orgMat[2],orgMat[3],
136
orgMat[4],orgMat[5]);
138
str->puts(" /Matrix [ ");
141
str->puts(" /Length ");
142
P2PObj *pobj = new P2PObj();
144
pobj->outputRef(str);
145
if (P2PDoc::options.contentsCompress && str->canDeflate()) {
146
str->puts(" /Filter /FlateDecode ");
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 */
161
pobj->setObj(&lenobj);
166
/* out length object */
167
pobj->output(str,xref);
170
void P2PPattern::outputShadingPattern(P2POutputStream *str,
171
GfxPattern *patternA, Object *objA, XRef *xref)
173
GfxShadingPattern *shadingPattern
174
= static_cast<GfxShadingPattern *>(patternA);
182
orgMat = shadingPattern->getMatrix();
183
P2PMatrix porgMat(orgMat[0],orgMat[1],orgMat[2],orgMat[3],
184
orgMat[4],orgMat[5]);
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]));
194
const char *p = "Matrix";
195
P2PObject *objp = new P2PObj(&matObj);
196
P2POutput::outputDict(objA->getDict(),&p,&objp,1,str,xref);
202
for (i = 0;i < 6;i++) {
207
P2PPattern::OrgPattern::OrgPattern(int orgNumA, int orgGenA, XRef *xref)
208
: P2PObject(orgNumA, orgGenA)
212
xref->fetch(orgNumA,orgGenA,&orgObj);
214
if ((pattern = GfxPattern::parse(&orgObj)) == 0) {
216
if ((pattern = GfxPattern::parse(&orgObj,NULL)) == 0) {
218
p2pError(-1,const_cast<char *>("Bad Pattern"));
222
P2PPattern::OrgPattern::OrgPattern(Object *objA)
228
if ((pattern = GfxPattern::parse(&orgObj)) == 0) {
230
if ((pattern = GfxPattern::parse(&orgObj,NULL)) == 0) {
232
p2pError(-1,const_cast<char *>("Bad Pattern"));
236
P2PPattern::OrgPattern::~OrgPattern()
238
if (pattern != 0) delete pattern;