"Fossies" - the Fresh Open Source Software Archive 
Member "xpdf-4.04/xpdf/PreScanOutputDev.cc" (18 Apr 2022, 8588 Bytes) of package /linux/misc/xpdf-4.04.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "PreScanOutputDev.cc" see the
Fossies "Dox" file reference documentation and the latest
Fossies "Diffs" side-by-side code changes report:
4.03_vs_4.04.
1 //========================================================================
2 //
3 // PreScanOutputDev.cc
4 //
5 // Copyright 2005 Glyph & Cog, LLC
6 //
7 //========================================================================
8
9 #include <aconf.h>
10
11 #ifdef USE_GCC_PRAGMAS
12 #pragma implementation
13 #endif
14
15 #include <math.h>
16 #include "gmempp.h"
17 #include "GlobalParams.h"
18 #include "Page.h"
19 #include "Gfx.h"
20 #include "GfxFont.h"
21 #include "Link.h"
22 #include "PreScanOutputDev.h"
23
24 //------------------------------------------------------------------------
25 // PreScanOutputDev
26 //------------------------------------------------------------------------
27
28 PreScanOutputDev::PreScanOutputDev() {
29 clearStats();
30 }
31
32 PreScanOutputDev::~PreScanOutputDev() {
33 }
34
35 void PreScanOutputDev::startPage(int pageNum, GfxState *state) {
36 }
37
38 void PreScanOutputDev::endPage() {
39 }
40
41 void PreScanOutputDev::stroke(GfxState *state) {
42 double *dash;
43 int dashLen;
44 double dashStart;
45
46 check(state, state->getStrokeColorSpace(), state->getStrokeColor(),
47 state->getStrokeOpacity(), state->getBlendMode());
48 state->getLineDash(&dash, &dashLen, &dashStart);
49 if (dashLen != 0) {
50 gdi = gFalse;
51 }
52 }
53
54 void PreScanOutputDev::fill(GfxState *state) {
55 check(state, state->getFillColorSpace(), state->getFillColor(),
56 state->getFillOpacity(), state->getBlendMode());
57 }
58
59 void PreScanOutputDev::eoFill(GfxState *state) {
60 check(state, state->getFillColorSpace(), state->getFillColor(),
61 state->getFillOpacity(), state->getBlendMode());
62 }
63
64 void PreScanOutputDev::tilingPatternFill(GfxState *state, Gfx *gfx,
65 Object *strRef,
66 int paintType, int tilingType,
67 Dict *resDict,
68 double *mat, double *bbox,
69 int x0, int y0, int x1, int y1,
70 double xStep, double yStep) {
71 if (paintType == 1) {
72 gfx->drawForm(strRef, resDict, mat, bbox);
73 } else {
74 check(state, state->getFillColorSpace(), state->getFillColor(),
75 state->getFillOpacity(), state->getBlendMode());
76 }
77 }
78
79 GBool PreScanOutputDev::shadedFill(GfxState *state, GfxShading *shading) {
80 if (shading->getColorSpace()->getMode() != csDeviceGray &&
81 shading->getColorSpace()->getMode() != csCalGray) {
82 gray = gFalse;
83 }
84 mono = gFalse;
85 if (state->getFillOpacity() != 1 ||
86 state->getBlendMode() != gfxBlendNormal) {
87 transparency = gTrue;
88 }
89 return gTrue;
90 }
91
92 void PreScanOutputDev::clip(GfxState *state) {
93 //~ check for a rectangle "near" the edge of the page;
94 //~ else set gdi to false
95 }
96
97 void PreScanOutputDev::eoClip(GfxState *state) {
98 //~ see clip()
99 }
100
101 void PreScanOutputDev::beginStringOp(GfxState *state) {
102 int render;
103 GfxFont *font;
104 double m11, m12, m21, m22;
105 GBool simpleTTF;
106
107 render = state->getRender();
108 if (!(render & 1)) {
109 check(state, state->getFillColorSpace(), state->getFillColor(),
110 state->getFillOpacity(), state->getBlendMode());
111 }
112 if ((render & 3) == 1 || (render & 3) == 2) {
113 check(state, state->getStrokeColorSpace(), state->getStrokeColor(),
114 state->getStrokeOpacity(), state->getBlendMode());
115 }
116
117 font = state->getFont();
118 state->getFontTransMat(&m11, &m12, &m21, &m22);
119 //~ this should check for external fonts that are non-TrueType
120 simpleTTF = fabs(m11 + m22) < 0.01 &&
121 m11 > 0 &&
122 fabs(m12) < 0.01 &&
123 fabs(m21) < 0.01 &&
124 fabs(state->getHorizScaling() - 1) < 0.001 &&
125 (font->getType() == fontTrueType ||
126 font->getType() == fontTrueTypeOT);
127 if (simpleTTF) {
128 //~ need to create a FoFiTrueType object, and check for a Unicode cmap
129 }
130 if (state->getRender() != 0 || !simpleTTF) {
131 gdi = gFalse;
132 }
133 }
134
135 void PreScanOutputDev::endStringOp(GfxState *state) {
136 }
137
138 GBool PreScanOutputDev::beginType3Char(GfxState *state, double x, double y,
139 double dx, double dy,
140 CharCode code, Unicode *u, int uLen) {
141 // return false so all Type 3 chars get rendered (no caching)
142 return gFalse;
143 }
144
145 void PreScanOutputDev::endType3Char(GfxState *state) {
146 }
147
148 void PreScanOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
149 int width, int height, GBool invert,
150 GBool inlineImg, GBool interpolate) {
151 check(state, state->getFillColorSpace(), state->getFillColor(),
152 state->getFillOpacity(), state->getBlendMode());
153 if (state->getFillColorSpace()->getMode() == csPattern) {
154 patternImgMask = gTrue;
155 }
156 gdi = gFalse;
157
158 if (inlineImg) {
159 str->reset();
160 str->discardChars(height * ((width + 7) / 8));
161 str->close();
162 }
163 }
164
165 void PreScanOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
166 int width, int height,
167 GfxImageColorMap *colorMap,
168 int *maskColors, GBool inlineImg,
169 GBool interpolate) {
170 GfxColorSpace *colorSpace;
171
172 colorSpace = colorMap->getColorSpace();
173 if (colorSpace->getMode() == csIndexed) {
174 colorSpace = ((GfxIndexedColorSpace *)colorSpace)->getBase();
175 }
176 if (colorSpace->getMode() == csDeviceGray ||
177 colorSpace->getMode() == csCalGray) {
178 if (colorMap->getBits() > 1) {
179 mono = gFalse;
180 }
181 } else {
182 gray = gFalse;
183 mono = gFalse;
184 }
185 if (state->getFillOpacity() != 1 ||
186 state->getBlendMode() != gfxBlendNormal) {
187 transparency = gTrue;
188 }
189 gdi = gFalse;
190
191 if (inlineImg) {
192 str->reset();
193 str->discardChars(height * ((width * colorMap->getNumPixelComps() *
194 colorMap->getBits() + 7) / 8));
195 str->close();
196 }
197 }
198
199 void PreScanOutputDev::drawMaskedImage(GfxState *state, Object *ref,
200 Stream *str,
201 int width, int height,
202 GfxImageColorMap *colorMap,
203 Object *maskRef, Stream *maskStr,
204 int maskWidth, int maskHeight,
205 GBool maskInvert, GBool interpolate) {
206 GfxColorSpace *colorSpace;
207
208 colorSpace = colorMap->getColorSpace();
209 if (colorSpace->getMode() == csIndexed) {
210 colorSpace = ((GfxIndexedColorSpace *)colorSpace)->getBase();
211 }
212 if (colorSpace->getMode() == csDeviceGray ||
213 colorSpace->getMode() == csCalGray) {
214 if (colorMap->getBits() > 1) {
215 mono = gFalse;
216 }
217 } else {
218 gray = gFalse;
219 mono = gFalse;
220 }
221 if (state->getFillOpacity() != 1 ||
222 state->getBlendMode() != gfxBlendNormal) {
223 transparency = gTrue;
224 }
225 gdi = gFalse;
226 }
227
228 void PreScanOutputDev::drawSoftMaskedImage(GfxState *state, Object *ref,
229 Stream *str,
230 int width, int height,
231 GfxImageColorMap *colorMap,
232 Object *maskRef, Stream *maskStr,
233 int maskWidth, int maskHeight,
234 GfxImageColorMap *maskColorMap,
235 double *matte, GBool interpolate) {
236 GfxColorSpace *colorSpace;
237
238 colorSpace = colorMap->getColorSpace();
239 if (colorSpace->getMode() == csIndexed) {
240 colorSpace = ((GfxIndexedColorSpace *)colorSpace)->getBase();
241 }
242 if (colorSpace->getMode() != csDeviceGray &&
243 colorSpace->getMode() != csCalGray) {
244 gray = gFalse;
245 }
246 mono = gFalse;
247 transparency = gTrue;
248 gdi = gFalse;
249 }
250
251 GBool PreScanOutputDev::beginTransparencyGroup(
252 GfxState *state, double *bbox,
253 GfxColorSpace *blendingColorSpace,
254 GBool isolated, GBool knockout,
255 GBool forSoftMask) {
256 transparency = gTrue;
257 gdi = gFalse;
258 return gTrue;
259 }
260
261 void PreScanOutputDev::check(GfxState *state,
262 GfxColorSpace *colorSpace, GfxColor *color,
263 double opacity, GfxBlendMode blendMode) {
264 GfxGray gr;
265 GfxCMYK cmyk;
266 GfxRGB rgb;
267
268 if (colorSpace->getMode() == csPattern) {
269 mono = gFalse;
270 gray = gFalse;
271 gdi = gFalse;
272 } else if (colorSpace->getMode() == csDeviceGray ||
273 colorSpace->getMode() == csCalGray) {
274 colorSpace->getGray(color, &gr, state->getRenderingIntent());
275 if (!(gr == 0 || gr == gfxColorComp1)) {
276 mono = gFalse;
277 }
278 } else if (colorSpace->getMode() == csDeviceCMYK) {
279 colorSpace->getCMYK(color, &cmyk, state->getRenderingIntent());
280 if (cmyk.c != 0 || cmyk.m != 0 || cmyk.y != 0) {
281 mono = gFalse;
282 gray = gFalse;
283 } else if (!(cmyk.k == 0 || cmyk.k == gfxColorComp1)) {
284 mono = gFalse;
285 }
286 } else {
287 colorSpace->getRGB(color, &rgb, state->getRenderingIntent());
288 if (rgb.r != rgb.g || rgb.g != rgb.b || rgb.b != rgb.r) {
289 mono = gFalse;
290 gray = gFalse;
291 } else if (!((rgb.r == 0 && rgb.g == 0 && rgb.b == 0) ||
292 (rgb.r == gfxColorComp1 &&
293 rgb.g == gfxColorComp1 &&
294 rgb.b == gfxColorComp1))) {
295 mono = gFalse;
296 }
297 }
298 if (opacity != 1 || blendMode != gfxBlendNormal) {
299 transparency = gTrue;
300 }
301 }
302
303 void PreScanOutputDev::clearStats() {
304 mono = gTrue;
305 gray = gTrue;
306 transparency = gFalse;
307 patternImgMask = gFalse;
308 gdi = gTrue;
309 }