/src/xpdf-4.05/xpdf/GfxState.h
Line | Count | Source (jump to first uncovered line) |
1 | | //======================================================================== |
2 | | // |
3 | | // GfxState.h |
4 | | // |
5 | | // Copyright 1996-2016 Glyph & Cog, LLC |
6 | | // |
7 | | //======================================================================== |
8 | | |
9 | | #ifndef GFXSTATE_H |
10 | | #define GFXSTATE_H |
11 | | |
12 | | #include <aconf.h> |
13 | | |
14 | | #include "gtypes.h" |
15 | | #include "Object.h" |
16 | | #include "Function.h" |
17 | | |
18 | | class Array; |
19 | | class GfxFont; |
20 | | class PDFRectangle; |
21 | | class GfxDeviceNColorSpace; |
22 | | class GfxSeparationColorSpace; |
23 | | class GfxShading; |
24 | | class GfxState; |
25 | | |
26 | | //------------------------------------------------------------------------ |
27 | | // GfxBlendMode |
28 | | //------------------------------------------------------------------------ |
29 | | |
30 | | enum GfxBlendMode { |
31 | | gfxBlendNormal, |
32 | | gfxBlendMultiply, |
33 | | gfxBlendScreen, |
34 | | gfxBlendOverlay, |
35 | | gfxBlendDarken, |
36 | | gfxBlendLighten, |
37 | | gfxBlendColorDodge, |
38 | | gfxBlendColorBurn, |
39 | | gfxBlendHardLight, |
40 | | gfxBlendSoftLight, |
41 | | gfxBlendDifference, |
42 | | gfxBlendExclusion, |
43 | | gfxBlendHue, |
44 | | gfxBlendSaturation, |
45 | | gfxBlendColor, |
46 | | gfxBlendLuminosity |
47 | | }; |
48 | | |
49 | | //------------------------------------------------------------------------ |
50 | | // GfxRenderingIntent |
51 | | //------------------------------------------------------------------------ |
52 | | |
53 | | enum GfxRenderingIntent { |
54 | | gfxRenderingIntentAbsoluteColorimetric, |
55 | | gfxRenderingIntentRelativeColorimetric, |
56 | | gfxRenderingIntentSaturation, |
57 | | gfxRenderingIntentPerceptual |
58 | | }; |
59 | | |
60 | | #define gfxNumRenderingIntents 4 |
61 | | |
62 | | //------------------------------------------------------------------------ |
63 | | // GfxColorComp |
64 | | //------------------------------------------------------------------------ |
65 | | |
66 | | // 16.16 fixed point color component |
67 | | typedef int GfxColorComp; |
68 | | |
69 | 0 | #define gfxColorComp1 0x10000 |
70 | | |
71 | 0 | static inline GfxColorComp dblToCol(double x) { |
72 | 0 | return (GfxColorComp)(x * gfxColorComp1); |
73 | 0 | } Unexecuted instantiation: fuzz_pdfload.cc:dblToCol(double) Unexecuted instantiation: Page.cc:dblToCol(double) Unexecuted instantiation: Stream.cc:dblToCol(double) Unexecuted instantiation: AcroForm.cc:dblToCol(double) Unexecuted instantiation: Annot.cc:dblToCol(double) Unexecuted instantiation: Gfx.cc:dblToCol(double) Unexecuted instantiation: GfxState.cc:dblToCol(double) Unexecuted instantiation: SplashOutputDev.cc:dblToCol(double) Unexecuted instantiation: OutputDev.cc:dblToCol(double) Unexecuted instantiation: ShadingImage.cc:dblToCol(double) Unexecuted instantiation: fuzz_JBIG2.cc:dblToCol(double) |
74 | | |
75 | 0 | static inline double colToDbl(GfxColorComp x) { |
76 | 0 | return (double)x / (double)gfxColorComp1; |
77 | 0 | } Unexecuted instantiation: fuzz_pdfload.cc:colToDbl(int) Unexecuted instantiation: Page.cc:colToDbl(int) Unexecuted instantiation: Stream.cc:colToDbl(int) Unexecuted instantiation: AcroForm.cc:colToDbl(int) Unexecuted instantiation: Annot.cc:colToDbl(int) Unexecuted instantiation: Gfx.cc:colToDbl(int) Unexecuted instantiation: GfxState.cc:colToDbl(int) Unexecuted instantiation: SplashOutputDev.cc:colToDbl(int) Unexecuted instantiation: OutputDev.cc:colToDbl(int) Unexecuted instantiation: ShadingImage.cc:colToDbl(int) Unexecuted instantiation: fuzz_JBIG2.cc:colToDbl(int) |
78 | | |
79 | 0 | static inline GfxColorComp byteToCol(Guchar x) { |
80 | | // (x / 255) << 16 = (0.0000000100000001... * x) << 16 |
81 | | // = ((x << 8) + (x) + (x >> 8) + ...) |
82 | | // = (x << 8) + (x) + (x >> 7) |
83 | | // [for rounding] |
84 | 0 | return (GfxColorComp)((x << 8) + x + (x >> 7)); |
85 | 0 | } Unexecuted instantiation: fuzz_pdfload.cc:byteToCol(unsigned char) Unexecuted instantiation: Page.cc:byteToCol(unsigned char) Unexecuted instantiation: Stream.cc:byteToCol(unsigned char) Unexecuted instantiation: AcroForm.cc:byteToCol(unsigned char) Unexecuted instantiation: Annot.cc:byteToCol(unsigned char) Unexecuted instantiation: Gfx.cc:byteToCol(unsigned char) Unexecuted instantiation: GfxState.cc:byteToCol(unsigned char) Unexecuted instantiation: SplashOutputDev.cc:byteToCol(unsigned char) Unexecuted instantiation: OutputDev.cc:byteToCol(unsigned char) Unexecuted instantiation: ShadingImage.cc:byteToCol(unsigned char) Unexecuted instantiation: fuzz_JBIG2.cc:byteToCol(unsigned char) |
86 | | |
87 | 0 | static inline GfxColorComp wordToCol(Gushort x) { |
88 | 0 | // (x / 65535) << 16 = (0.0000000000000001... * x) << 16 |
89 | 0 | // = x + (x >> 15) |
90 | 0 | // [for rounding] |
91 | 0 | return (GfxColorComp)(x + (x >> 15)); |
92 | 0 | } Unexecuted instantiation: fuzz_pdfload.cc:wordToCol(unsigned short) Unexecuted instantiation: Page.cc:wordToCol(unsigned short) Unexecuted instantiation: Stream.cc:wordToCol(unsigned short) Unexecuted instantiation: AcroForm.cc:wordToCol(unsigned short) Unexecuted instantiation: Annot.cc:wordToCol(unsigned short) Unexecuted instantiation: Gfx.cc:wordToCol(unsigned short) Unexecuted instantiation: GfxState.cc:wordToCol(unsigned short) Unexecuted instantiation: SplashOutputDev.cc:wordToCol(unsigned short) Unexecuted instantiation: OutputDev.cc:wordToCol(unsigned short) Unexecuted instantiation: ShadingImage.cc:wordToCol(unsigned short) Unexecuted instantiation: fuzz_JBIG2.cc:wordToCol(unsigned short) |
93 | | |
94 | 0 | static inline Guchar colToByte(GfxColorComp x) { |
95 | | // 255 * x + 0.5 = 256 * x - x + 0.5 |
96 | | // = [256 * (x << 16) - (x << 16) + (1 << 15)] >> 16 |
97 | 0 | return (Guchar)(((x << 8) - x + 0x8000) >> 16); |
98 | 0 | } Unexecuted instantiation: fuzz_pdfload.cc:colToByte(int) Unexecuted instantiation: Page.cc:colToByte(int) Unexecuted instantiation: Stream.cc:colToByte(int) Unexecuted instantiation: AcroForm.cc:colToByte(int) Unexecuted instantiation: Annot.cc:colToByte(int) Unexecuted instantiation: Gfx.cc:colToByte(int) Unexecuted instantiation: GfxState.cc:colToByte(int) Unexecuted instantiation: SplashOutputDev.cc:colToByte(int) Unexecuted instantiation: OutputDev.cc:colToByte(int) Unexecuted instantiation: ShadingImage.cc:colToByte(int) Unexecuted instantiation: fuzz_JBIG2.cc:colToByte(int) |
99 | | |
100 | 0 | static inline Gushort colToWord(GfxColorComp x) { |
101 | 0 | // 65535 * x + 0.5 = 65536 * x - x + 0.5 |
102 | 0 | // = [65536 * (x << 16) - (x << 16) + (1 << 15)] >> 16 |
103 | 0 | return (Gushort)(((x << 16) - x + 0x8000) >> 16); |
104 | 0 | } Unexecuted instantiation: fuzz_pdfload.cc:colToWord(int) Unexecuted instantiation: Page.cc:colToWord(int) Unexecuted instantiation: Stream.cc:colToWord(int) Unexecuted instantiation: AcroForm.cc:colToWord(int) Unexecuted instantiation: Annot.cc:colToWord(int) Unexecuted instantiation: Gfx.cc:colToWord(int) Unexecuted instantiation: GfxState.cc:colToWord(int) Unexecuted instantiation: SplashOutputDev.cc:colToWord(int) Unexecuted instantiation: OutputDev.cc:colToWord(int) Unexecuted instantiation: ShadingImage.cc:colToWord(int) Unexecuted instantiation: fuzz_JBIG2.cc:colToWord(int) |
105 | | |
106 | | //------------------------------------------------------------------------ |
107 | | // GfxColor |
108 | | //------------------------------------------------------------------------ |
109 | | |
110 | 8.08k | #define gfxColorMaxComps funcMaxOutputs |
111 | | |
112 | | struct GfxColor { |
113 | | GfxColorComp c[gfxColorMaxComps]; |
114 | | }; |
115 | | |
116 | | //------------------------------------------------------------------------ |
117 | | // GfxGray |
118 | | //------------------------------------------------------------------------ |
119 | | |
120 | | typedef GfxColorComp GfxGray; |
121 | | |
122 | | //------------------------------------------------------------------------ |
123 | | // GfxRGB |
124 | | //------------------------------------------------------------------------ |
125 | | |
126 | | struct GfxRGB { |
127 | | GfxColorComp r, g, b; |
128 | | }; |
129 | | |
130 | | //------------------------------------------------------------------------ |
131 | | // GfxCMYK |
132 | | //------------------------------------------------------------------------ |
133 | | |
134 | | struct GfxCMYK { |
135 | | GfxColorComp c, m, y, k; |
136 | | }; |
137 | | |
138 | | |
139 | | |
140 | | |
141 | | |
142 | | //------------------------------------------------------------------------ |
143 | | // GfxColorSpace |
144 | | //------------------------------------------------------------------------ |
145 | | |
146 | | // NB: The nGfxColorSpaceModes constant and the gfxColorSpaceModeNames |
147 | | // array defined in GfxState.cc must match this enum. |
148 | | enum GfxColorSpaceMode { |
149 | | csDeviceGray, |
150 | | csCalGray, |
151 | | csDeviceRGB, |
152 | | csCalRGB, |
153 | | csDeviceCMYK, |
154 | | csLab, |
155 | | csICCBased, |
156 | | csIndexed, |
157 | | csSeparation, |
158 | | csDeviceN, |
159 | | csPattern |
160 | | }; |
161 | | |
162 | | class GfxColorSpace { |
163 | | public: |
164 | | |
165 | | GfxColorSpace(); |
166 | | virtual ~GfxColorSpace(); |
167 | | virtual GfxColorSpace *copy() = 0; |
168 | | virtual GfxColorSpaceMode getMode() = 0; |
169 | | |
170 | | // Construct a color space. Returns NULL if unsuccessful. |
171 | | static GfxColorSpace *parse(Object *csObj, |
172 | | int recursion = 0); |
173 | | |
174 | | // Construct a simple color space. The <mode> argument can be |
175 | | // csDeviceGray, csDeviceRGB, or csDeviceCMYK. |
176 | | static GfxColorSpace *create(GfxColorSpaceMode mode); |
177 | | |
178 | | |
179 | | // Convert to gray, RGB, or CMYK. |
180 | | virtual void getGray(GfxColor *color, GfxGray *gray, |
181 | | GfxRenderingIntent ri) = 0; |
182 | | virtual void getRGB(GfxColor *color, GfxRGB *rgb, |
183 | | GfxRenderingIntent ri) = 0; |
184 | | virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk, |
185 | | GfxRenderingIntent ri) = 0; |
186 | | |
187 | | // Return the number of color components. |
188 | | virtual int getNComps() = 0; |
189 | | |
190 | | // Get this color space's default color. |
191 | | virtual void getDefaultColor(GfxColor *color) = 0; |
192 | | |
193 | | // Return the default ranges for each component, assuming an image |
194 | | // with a max pixel value of <maxImgPixel>. |
195 | | virtual void getDefaultRanges(double *decodeLow, double *decodeRange, |
196 | | int maxImgPixel); |
197 | | |
198 | | // Returns true if painting operations in this color space never |
199 | | // mark the page (e.g., the "None" colorant). |
200 | 0 | virtual GBool isNonMarking() { return gFalse; } |
201 | | |
202 | | |
203 | | // Return the color space's overprint mask. |
204 | 0 | Guint getOverprintMask() { return overprintMask; } |
205 | | |
206 | | // Return true if this color space object is the result of |
207 | | // substituting a DefaultGray/RGB/CMYK color space for |
208 | | // DeviceGray/RGB/CMYK. |
209 | 0 | GBool isDefaultColorSpace() { return defaultColorSpace; } |
210 | | |
211 | | // Return the number of color space modes |
212 | | static int getNumColorSpaceModes(); |
213 | | |
214 | | // Return the name of the <idx>th color space mode. |
215 | | static const char *getColorSpaceModeName(int idx); |
216 | | |
217 | | protected: |
218 | | |
219 | | Guint overprintMask; |
220 | | GBool defaultColorSpace; |
221 | | }; |
222 | | |
223 | | //------------------------------------------------------------------------ |
224 | | // GfxDeviceGrayColorSpace |
225 | | //------------------------------------------------------------------------ |
226 | | |
227 | | class GfxDeviceGrayColorSpace: public GfxColorSpace { |
228 | | public: |
229 | | |
230 | | GfxDeviceGrayColorSpace(); |
231 | | virtual ~GfxDeviceGrayColorSpace(); |
232 | | virtual GfxColorSpace *copy(); |
233 | 0 | virtual GfxColorSpaceMode getMode() { return csDeviceGray; } |
234 | | |
235 | | virtual void getGray(GfxColor *color, GfxGray *gray, GfxRenderingIntent ri); |
236 | | virtual void getRGB(GfxColor *color, GfxRGB *rgb, GfxRenderingIntent ri); |
237 | | virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk, GfxRenderingIntent ri); |
238 | | |
239 | 0 | virtual int getNComps() { return 1; } |
240 | | virtual void getDefaultColor(GfxColor *color); |
241 | | |
242 | | private: |
243 | | }; |
244 | | |
245 | | //------------------------------------------------------------------------ |
246 | | // GfxCalGrayColorSpace |
247 | | //------------------------------------------------------------------------ |
248 | | |
249 | | class GfxCalGrayColorSpace: public GfxColorSpace { |
250 | | public: |
251 | | |
252 | | GfxCalGrayColorSpace(); |
253 | | virtual ~GfxCalGrayColorSpace(); |
254 | | virtual GfxColorSpace *copy(); |
255 | 0 | virtual GfxColorSpaceMode getMode() { return csCalGray; } |
256 | | |
257 | | // Construct a CalGray color space. Returns NULL if unsuccessful. |
258 | | static GfxColorSpace *parse(Array *arr, int recursion); |
259 | | |
260 | | virtual void getGray(GfxColor *color, GfxGray *gray, GfxRenderingIntent ri); |
261 | | virtual void getRGB(GfxColor *color, GfxRGB *rgb, GfxRenderingIntent ri); |
262 | | virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk, GfxRenderingIntent ri); |
263 | | |
264 | 0 | virtual int getNComps() { return 1; } |
265 | | virtual void getDefaultColor(GfxColor *color); |
266 | | |
267 | | // CalGray-specific access. |
268 | 0 | double getWhiteX() { return whiteX; } |
269 | 0 | double getWhiteY() { return whiteY; } |
270 | 0 | double getWhiteZ() { return whiteZ; } |
271 | 0 | double getBlackX() { return blackX; } |
272 | 0 | double getBlackY() { return blackY; } |
273 | 0 | double getBlackZ() { return blackZ; } |
274 | 0 | double getGamma() { return gamma; } |
275 | | |
276 | | private: |
277 | | |
278 | | double whiteX, whiteY, whiteZ; // white point |
279 | | double blackX, blackY, blackZ; // black point |
280 | | double gamma; // gamma value |
281 | | }; |
282 | | |
283 | | //------------------------------------------------------------------------ |
284 | | // GfxDeviceRGBColorSpace |
285 | | //------------------------------------------------------------------------ |
286 | | |
287 | | class GfxDeviceRGBColorSpace: public GfxColorSpace { |
288 | | public: |
289 | | |
290 | | GfxDeviceRGBColorSpace(); |
291 | | virtual ~GfxDeviceRGBColorSpace(); |
292 | | virtual GfxColorSpace *copy(); |
293 | 0 | virtual GfxColorSpaceMode getMode() { return csDeviceRGB; } |
294 | | |
295 | | virtual void getGray(GfxColor *color, GfxGray *gray, GfxRenderingIntent ri); |
296 | | virtual void getRGB(GfxColor *color, GfxRGB *rgb, GfxRenderingIntent ri); |
297 | | virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk, GfxRenderingIntent ri); |
298 | | |
299 | 0 | virtual int getNComps() { return 3; } |
300 | | virtual void getDefaultColor(GfxColor *color); |
301 | | |
302 | | private: |
303 | | }; |
304 | | |
305 | | //------------------------------------------------------------------------ |
306 | | // GfxCalRGBColorSpace |
307 | | //------------------------------------------------------------------------ |
308 | | |
309 | | class GfxCalRGBColorSpace: public GfxColorSpace { |
310 | | public: |
311 | | |
312 | | GfxCalRGBColorSpace(); |
313 | | virtual ~GfxCalRGBColorSpace(); |
314 | | virtual GfxColorSpace *copy(); |
315 | 0 | virtual GfxColorSpaceMode getMode() { return csCalRGB; } |
316 | | |
317 | | // Construct a CalRGB color space. Returns NULL if unsuccessful. |
318 | | static GfxColorSpace *parse(Array *arr, int recursion); |
319 | | |
320 | | virtual void getGray(GfxColor *color, GfxGray *gray, GfxRenderingIntent ri); |
321 | | virtual void getRGB(GfxColor *color, GfxRGB *rgb, GfxRenderingIntent ri); |
322 | | virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk, GfxRenderingIntent ri); |
323 | | |
324 | 0 | virtual int getNComps() { return 3; } |
325 | | virtual void getDefaultColor(GfxColor *color); |
326 | | |
327 | | // CalRGB-specific access. |
328 | 0 | double getWhiteX() { return whiteX; } |
329 | 0 | double getWhiteY() { return whiteY; } |
330 | 0 | double getWhiteZ() { return whiteZ; } |
331 | 0 | double getBlackX() { return blackX; } |
332 | 0 | double getBlackY() { return blackY; } |
333 | 0 | double getBlackZ() { return blackZ; } |
334 | 0 | double getGammaR() { return gammaR; } |
335 | 0 | double getGammaG() { return gammaG; } |
336 | 0 | double getGammaB() { return gammaB; } |
337 | 0 | double *getMatrix() { return mat; } |
338 | | |
339 | | private: |
340 | | |
341 | | double whiteX, whiteY, whiteZ; // white point |
342 | | double blackX, blackY, blackZ; // black point |
343 | | double gammaR, gammaG, gammaB; // gamma values |
344 | | double mat[9]; // ABC -> XYZ transform matrix |
345 | | }; |
346 | | |
347 | | //------------------------------------------------------------------------ |
348 | | // GfxDeviceCMYKColorSpace |
349 | | //------------------------------------------------------------------------ |
350 | | |
351 | | class GfxDeviceCMYKColorSpace: public GfxColorSpace { |
352 | | public: |
353 | | |
354 | | GfxDeviceCMYKColorSpace(); |
355 | | virtual ~GfxDeviceCMYKColorSpace(); |
356 | | virtual GfxColorSpace *copy(); |
357 | 0 | virtual GfxColorSpaceMode getMode() { return csDeviceCMYK; } |
358 | | |
359 | | virtual void getGray(GfxColor *color, GfxGray *gray, GfxRenderingIntent ri); |
360 | | virtual void getRGB(GfxColor *color, GfxRGB *rgb, GfxRenderingIntent ri); |
361 | | virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk, GfxRenderingIntent ri); |
362 | | |
363 | 0 | virtual int getNComps() { return 4; } |
364 | | virtual void getDefaultColor(GfxColor *color); |
365 | | |
366 | | |
367 | | private: |
368 | | }; |
369 | | |
370 | | //------------------------------------------------------------------------ |
371 | | // GfxLabColorSpace |
372 | | //------------------------------------------------------------------------ |
373 | | |
374 | | class GfxLabColorSpace: public GfxColorSpace { |
375 | | public: |
376 | | |
377 | | GfxLabColorSpace(); |
378 | | virtual ~GfxLabColorSpace(); |
379 | | virtual GfxColorSpace *copy(); |
380 | 0 | virtual GfxColorSpaceMode getMode() { return csLab; } |
381 | | |
382 | | // Construct a Lab color space. Returns NULL if unsuccessful. |
383 | | static GfxColorSpace *parse(Array *arr, int recursion); |
384 | | |
385 | | virtual void getGray(GfxColor *color, GfxGray *gray, GfxRenderingIntent ri); |
386 | | virtual void getRGB(GfxColor *color, GfxRGB *rgb, GfxRenderingIntent ri); |
387 | | virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk, GfxRenderingIntent ri); |
388 | | |
389 | 0 | virtual int getNComps() { return 3; } |
390 | | virtual void getDefaultColor(GfxColor *color); |
391 | | |
392 | | virtual void getDefaultRanges(double *decodeLow, double *decodeRange, |
393 | | int maxImgPixel); |
394 | | |
395 | | // Lab-specific access. |
396 | 0 | double getWhiteX() { return whiteX; } |
397 | 0 | double getWhiteY() { return whiteY; } |
398 | 0 | double getWhiteZ() { return whiteZ; } |
399 | 0 | double getBlackX() { return blackX; } |
400 | 0 | double getBlackY() { return blackY; } |
401 | 0 | double getBlackZ() { return blackZ; } |
402 | 0 | double getAMin() { return aMin; } |
403 | 0 | double getAMax() { return aMax; } |
404 | 0 | double getBMin() { return bMin; } |
405 | 0 | double getBMax() { return bMax; } |
406 | | |
407 | | private: |
408 | | |
409 | | double whiteX, whiteY, whiteZ; // white point |
410 | | double blackX, blackY, blackZ; // black point |
411 | | double aMin, aMax, bMin, bMax; // range for the a and b components |
412 | | double kr, kg, kb; // gamut mapping mulitpliers |
413 | | }; |
414 | | |
415 | | //------------------------------------------------------------------------ |
416 | | // GfxICCBasedColorSpace |
417 | | //------------------------------------------------------------------------ |
418 | | |
419 | | class GfxICCBasedColorSpace: public GfxColorSpace { |
420 | | public: |
421 | | |
422 | | GfxICCBasedColorSpace(int nCompsA, GfxColorSpace *altA, |
423 | | Ref *iccProfileStreamA); |
424 | | virtual ~GfxICCBasedColorSpace(); |
425 | | virtual GfxColorSpace *copy(); |
426 | 0 | virtual GfxColorSpaceMode getMode() { return csICCBased; } |
427 | | |
428 | | // Construct an ICCBased color space. Returns NULL if unsuccessful. |
429 | | static GfxColorSpace *parse(Array *arr, |
430 | | int recursion); |
431 | | |
432 | | virtual void getGray(GfxColor *color, GfxGray *gray, GfxRenderingIntent ri); |
433 | | virtual void getRGB(GfxColor *color, GfxRGB *rgb, GfxRenderingIntent ri); |
434 | | virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk, GfxRenderingIntent ri); |
435 | | |
436 | 0 | virtual int getNComps() { return nComps; } |
437 | | virtual void getDefaultColor(GfxColor *color); |
438 | | |
439 | | virtual void getDefaultRanges(double *decodeLow, double *decodeRange, |
440 | | int maxImgPixel); |
441 | | |
442 | | |
443 | | // ICCBased-specific access. |
444 | 0 | GfxColorSpace *getAlt() { return alt; } |
445 | 0 | Ref getICCProfileStreamRef() { return iccProfileStream; } |
446 | | |
447 | | private: |
448 | | |
449 | | int nComps; // number of color components (1, 3, or 4) |
450 | | GfxColorSpace *alt; // alternate color space |
451 | | double rangeMin[4]; // min values for each component |
452 | | double rangeMax[4]; // max values for each component |
453 | | Ref iccProfileStream; // the ICC profile |
454 | | }; |
455 | | |
456 | | //------------------------------------------------------------------------ |
457 | | // GfxIndexedColorSpace |
458 | | //------------------------------------------------------------------------ |
459 | | |
460 | | class GfxIndexedColorSpace: public GfxColorSpace { |
461 | | public: |
462 | | |
463 | | GfxIndexedColorSpace(GfxColorSpace *baseA, int indexHighA); |
464 | | virtual ~GfxIndexedColorSpace(); |
465 | | virtual GfxColorSpace *copy(); |
466 | 0 | virtual GfxColorSpaceMode getMode() { return csIndexed; } |
467 | | |
468 | | // Construct an Indexed color space. Returns NULL if unsuccessful. |
469 | | static GfxColorSpace *parse(Array *arr, |
470 | | int recursion); |
471 | | |
472 | | virtual void getGray(GfxColor *color, GfxGray *gray, GfxRenderingIntent ri); |
473 | | virtual void getRGB(GfxColor *color, GfxRGB *rgb, GfxRenderingIntent ri); |
474 | | virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk, GfxRenderingIntent ri); |
475 | | |
476 | 0 | virtual int getNComps() { return 1; } |
477 | | virtual void getDefaultColor(GfxColor *color); |
478 | | |
479 | | virtual void getDefaultRanges(double *decodeLow, double *decodeRange, |
480 | | int maxImgPixel); |
481 | | |
482 | | // Indexed-specific access. |
483 | 0 | GfxColorSpace *getBase() { return base; } |
484 | 0 | int getIndexHigh() { return indexHigh; } |
485 | 0 | Guchar *getLookup() { return lookup; } |
486 | | GfxColor *mapColorToBase(GfxColor *color, GfxColor *baseColor); |
487 | | |
488 | | private: |
489 | | |
490 | | GfxColorSpace *base; // base color space |
491 | | int indexHigh; // max pixel value |
492 | | Guchar *lookup; // lookup table |
493 | | }; |
494 | | |
495 | | //------------------------------------------------------------------------ |
496 | | // GfxSeparationColorSpace |
497 | | //------------------------------------------------------------------------ |
498 | | |
499 | | class GfxSeparationColorSpace: public GfxColorSpace { |
500 | | public: |
501 | | |
502 | | GfxSeparationColorSpace(GString *nameA, GfxColorSpace *altA, |
503 | | Function *funcA); |
504 | | virtual ~GfxSeparationColorSpace(); |
505 | | virtual GfxColorSpace *copy(); |
506 | 0 | virtual GfxColorSpaceMode getMode() { return csSeparation; } |
507 | | |
508 | | // Construct a Separation color space. Returns NULL if unsuccessful. |
509 | | static GfxColorSpace *parse(Array *arr, |
510 | | int recursion); |
511 | | |
512 | | virtual void getGray(GfxColor *color, GfxGray *gray, GfxRenderingIntent ri); |
513 | | virtual void getRGB(GfxColor *color, GfxRGB *rgb, GfxRenderingIntent ri); |
514 | | virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk, GfxRenderingIntent ri); |
515 | | |
516 | 0 | virtual int getNComps() { return 1; } |
517 | | virtual void getDefaultColor(GfxColor *color); |
518 | | |
519 | 0 | virtual GBool isNonMarking() { return nonMarking; } |
520 | | |
521 | | // Separation-specific access. |
522 | 0 | GString *getName() { return name; } |
523 | 0 | GfxColorSpace *getAlt() { return alt; } |
524 | 0 | Function *getFunc() { return func; } |
525 | | |
526 | | private: |
527 | | |
528 | | GfxSeparationColorSpace(GString *nameA, GfxColorSpace *altA, |
529 | | Function *funcA, GBool nonMarkingA, |
530 | | Guint overprintMaskA); |
531 | | |
532 | | GString *name; // colorant name |
533 | | GfxColorSpace *alt; // alternate color space |
534 | | Function *func; // tint transform (into alternate color space) |
535 | | GBool nonMarking; |
536 | | }; |
537 | | |
538 | | //------------------------------------------------------------------------ |
539 | | // GfxDeviceNColorSpace |
540 | | //------------------------------------------------------------------------ |
541 | | |
542 | | class GfxDeviceNColorSpace: public GfxColorSpace { |
543 | | public: |
544 | | |
545 | | GfxDeviceNColorSpace(int nCompsA, GString **namesA, |
546 | | GfxColorSpace *alt, Function *func, |
547 | | Object *attrsA); |
548 | | virtual ~GfxDeviceNColorSpace(); |
549 | | virtual GfxColorSpace *copy(); |
550 | 0 | virtual GfxColorSpaceMode getMode() { return csDeviceN; } |
551 | | |
552 | | // Construct a DeviceN color space. Returns NULL if unsuccessful. |
553 | | static GfxColorSpace *parse(Array *arr, |
554 | | int recursion); |
555 | | |
556 | | virtual void getGray(GfxColor *color, GfxGray *gray, GfxRenderingIntent ri); |
557 | | virtual void getRGB(GfxColor *color, GfxRGB *rgb, GfxRenderingIntent ri); |
558 | | virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk, GfxRenderingIntent ri); |
559 | | |
560 | 0 | virtual int getNComps() { return nComps; } |
561 | | virtual void getDefaultColor(GfxColor *color); |
562 | | |
563 | 0 | virtual GBool isNonMarking() { return nonMarking; } |
564 | | |
565 | | // DeviceN-specific access. |
566 | 0 | GString *getColorantName(int i) { return names[i]; } |
567 | 0 | GfxColorSpace *getAlt() { return alt; } |
568 | 0 | Function *getTintTransformFunc() { return func; } |
569 | 0 | Object *getAttrs() { return &attrs; } |
570 | | |
571 | | private: |
572 | | |
573 | | GfxDeviceNColorSpace(int nCompsA, GString **namesA, |
574 | | GfxColorSpace *alt, Function *func, |
575 | | Object *attrsA, |
576 | | GBool nonMarkingA, Guint overprintMaskA); |
577 | | |
578 | | int nComps; // number of components |
579 | | GString // colorant names |
580 | | *names[gfxColorMaxComps]; |
581 | | GfxColorSpace *alt; // alternate color space |
582 | | Function *func; // tint transform (into alternate color space) |
583 | | Object attrs; |
584 | | GBool nonMarking; |
585 | | }; |
586 | | |
587 | | //------------------------------------------------------------------------ |
588 | | // GfxPatternColorSpace |
589 | | //------------------------------------------------------------------------ |
590 | | |
591 | | class GfxPatternColorSpace: public GfxColorSpace { |
592 | | public: |
593 | | |
594 | | GfxPatternColorSpace(GfxColorSpace *underA); |
595 | | virtual ~GfxPatternColorSpace(); |
596 | | virtual GfxColorSpace *copy(); |
597 | 0 | virtual GfxColorSpaceMode getMode() { return csPattern; } |
598 | | |
599 | | // Construct a Pattern color space. Returns NULL if unsuccessful. |
600 | | static GfxColorSpace *parse(Array *arr, |
601 | | int recursion); |
602 | | |
603 | | virtual void getGray(GfxColor *color, GfxGray *gray, GfxRenderingIntent ri); |
604 | | virtual void getRGB(GfxColor *color, GfxRGB *rgb, GfxRenderingIntent ri); |
605 | | virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk, GfxRenderingIntent ri); |
606 | | |
607 | 0 | virtual int getNComps() { return 0; } |
608 | | virtual void getDefaultColor(GfxColor *color); |
609 | | |
610 | | // Pattern-specific access. |
611 | 0 | GfxColorSpace *getUnder() { return under; } |
612 | | |
613 | | private: |
614 | | |
615 | | GfxColorSpace *under; // underlying color space (for uncolored |
616 | | // patterns) |
617 | | }; |
618 | | |
619 | | //------------------------------------------------------------------------ |
620 | | // GfxPattern |
621 | | //------------------------------------------------------------------------ |
622 | | |
623 | | class GfxPattern { |
624 | | public: |
625 | | |
626 | | GfxPattern(int typeA); |
627 | | virtual ~GfxPattern(); |
628 | | |
629 | | static GfxPattern *parse(Object *objRef, Object *obj |
630 | | ); |
631 | | |
632 | | virtual GfxPattern *copy() = 0; |
633 | | |
634 | 0 | int getType() { return type; } |
635 | | |
636 | | private: |
637 | | |
638 | | int type; |
639 | | }; |
640 | | |
641 | | //------------------------------------------------------------------------ |
642 | | // GfxTilingPattern |
643 | | //------------------------------------------------------------------------ |
644 | | |
645 | | class GfxTilingPattern: public GfxPattern { |
646 | | public: |
647 | | |
648 | | static GfxTilingPattern *parse(Object *patObjRef, Object *patObj); |
649 | | virtual ~GfxTilingPattern(); |
650 | | |
651 | | virtual GfxPattern *copy(); |
652 | | |
653 | 0 | int getPaintType() { return paintType; } |
654 | 0 | int getTilingType() { return tilingType; } |
655 | 0 | double *getBBox() { return bbox; } |
656 | 0 | double getXStep() { return xStep; } |
657 | 0 | double getYStep() { return yStep; } |
658 | | Dict *getResDict() |
659 | 0 | { return resDict.isDict() ? resDict.getDict() : (Dict *)NULL; } |
660 | 0 | double *getMatrix() { return matrix; } |
661 | 0 | Object *getContentStreamRef() { return &contentStreamRef; } |
662 | | GBool usesBlendMode(XRef *xref); |
663 | | |
664 | | private: |
665 | | |
666 | | GfxTilingPattern(int paintTypeA, int tilingTypeA, |
667 | | double *bboxA, double xStepA, double yStepA, |
668 | | Object *resDictA, double *matrixA, |
669 | | Object *contentStreamA); |
670 | | GBool scanResourcesForBlendMode(Object *resDict2, |
671 | | char *scannedObjs, XRef *xref); |
672 | | GBool scanExtGStateForBlendMode(Object *gsObj, |
673 | | char *scannedObjs, XRef *xref); |
674 | | GBool scanSoftMaskForBlendMode(Object *softMaskObj, |
675 | | char *scannedObjs, XRef *xref); |
676 | | GBool scanPatternForBlendMode(Object *patternObj, |
677 | | char *scannedObjs, XRef *xref); |
678 | | GBool scanXObjectForBlendMode(Object *xObj, |
679 | | char *scannedObjs, XRef *xref); |
680 | | |
681 | | int paintType; |
682 | | int tilingType; |
683 | | double bbox[4]; |
684 | | double xStep, yStep; |
685 | | Object resDict; |
686 | | double matrix[6]; |
687 | | Object contentStreamRef; |
688 | | }; |
689 | | |
690 | | //------------------------------------------------------------------------ |
691 | | // GfxShadingPattern |
692 | | //------------------------------------------------------------------------ |
693 | | |
694 | | class GfxShadingPattern: public GfxPattern { |
695 | | public: |
696 | | |
697 | | static GfxShadingPattern *parse(Object *patObj |
698 | | ); |
699 | | virtual ~GfxShadingPattern(); |
700 | | |
701 | | virtual GfxPattern *copy(); |
702 | | |
703 | 0 | GfxShading *getShading() { return shading; } |
704 | 0 | double *getMatrix() { return matrix; } |
705 | | |
706 | | private: |
707 | | |
708 | | GfxShadingPattern(GfxShading *shadingA, double *matrixA); |
709 | | |
710 | | GfxShading *shading; |
711 | | double matrix[6]; |
712 | | }; |
713 | | |
714 | | //------------------------------------------------------------------------ |
715 | | // GfxShading |
716 | | //------------------------------------------------------------------------ |
717 | | |
718 | | class GfxShading { |
719 | | public: |
720 | | |
721 | | GfxShading(int typeA); |
722 | | GfxShading(GfxShading *shading); |
723 | | virtual ~GfxShading(); |
724 | | |
725 | | static GfxShading *parse(Object *obj |
726 | | ); |
727 | | |
728 | | virtual GfxShading *copy() = 0; |
729 | | |
730 | 0 | int getType() { return type; } |
731 | 0 | GfxColorSpace *getColorSpace() { return colorSpace; } |
732 | 0 | GfxColor *getBackground() { return &background; } |
733 | 0 | GBool getHasBackground() { return hasBackground; } |
734 | | void getBBox(double *xMinA, double *yMinA, double *xMaxA, double *yMaxA) |
735 | 0 | { *xMinA = xMin; *yMinA = yMin; *xMaxA = xMax; *yMaxA = yMax; } |
736 | 0 | GBool getHasBBox() { return hasBBox; } |
737 | | |
738 | | protected: |
739 | | |
740 | | GBool init(Dict *dict |
741 | | ); |
742 | | |
743 | | int type; |
744 | | GfxColorSpace *colorSpace; |
745 | | GfxColor background; |
746 | | GBool hasBackground; |
747 | | double xMin, yMin, xMax, yMax; |
748 | | GBool hasBBox; |
749 | | }; |
750 | | |
751 | | //------------------------------------------------------------------------ |
752 | | // GfxFunctionShading |
753 | | //------------------------------------------------------------------------ |
754 | | |
755 | | class GfxFunctionShading: public GfxShading { |
756 | | public: |
757 | | |
758 | | GfxFunctionShading(double x0A, double y0A, |
759 | | double x1A, double y1A, |
760 | | double *matrixA, |
761 | | Function **funcsA, int nFuncsA); |
762 | | GfxFunctionShading(GfxFunctionShading *shading); |
763 | | virtual ~GfxFunctionShading(); |
764 | | |
765 | | static GfxFunctionShading *parse(Dict *dict |
766 | | ); |
767 | | |
768 | | virtual GfxShading *copy(); |
769 | | |
770 | | void getDomain(double *x0A, double *y0A, double *x1A, double *y1A) |
771 | 0 | { *x0A = x0; *y0A = y0; *x1A = x1; *y1A = y1; } |
772 | 0 | double *getMatrix() { return matrix; } |
773 | 0 | int getNFuncs() { return nFuncs; } |
774 | 0 | Function *getFunc(int i) { return funcs[i]; } |
775 | | void getColor(double x, double y, GfxColor *color); |
776 | | |
777 | | private: |
778 | | |
779 | | double x0, y0, x1, y1; |
780 | | double matrix[6]; |
781 | | Function *funcs[gfxColorMaxComps]; |
782 | | int nFuncs; |
783 | | }; |
784 | | |
785 | | //------------------------------------------------------------------------ |
786 | | // GfxAxialShading |
787 | | //------------------------------------------------------------------------ |
788 | | |
789 | | class GfxAxialShading: public GfxShading { |
790 | | public: |
791 | | |
792 | | GfxAxialShading(double x0A, double y0A, |
793 | | double x1A, double y1A, |
794 | | double t0A, double t1A, |
795 | | Function **funcsA, int nFuncsA, |
796 | | GBool extend0A, GBool extend1A); |
797 | | GfxAxialShading(GfxAxialShading *shading); |
798 | | virtual ~GfxAxialShading(); |
799 | | |
800 | | static GfxAxialShading *parse(Dict *dict |
801 | | ); |
802 | | |
803 | | virtual GfxShading *copy(); |
804 | | |
805 | | void getCoords(double *x0A, double *y0A, double *x1A, double *y1A) |
806 | 0 | { *x0A = x0; *y0A = y0; *x1A = x1; *y1A = y1; } |
807 | 0 | double getDomain0() { return t0; } |
808 | 0 | double getDomain1() { return t1; } |
809 | 0 | GBool getExtend0() { return extend0; } |
810 | 0 | GBool getExtend1() { return extend1; } |
811 | 0 | int getNFuncs() { return nFuncs; } |
812 | 0 | Function *getFunc(int i) { return funcs[i]; } |
813 | | void getColor(double t, GfxColor *color); |
814 | | |
815 | | private: |
816 | | |
817 | | double x0, y0, x1, y1; |
818 | | double t0, t1; |
819 | | Function *funcs[gfxColorMaxComps]; |
820 | | int nFuncs; |
821 | | GBool extend0, extend1; |
822 | | }; |
823 | | |
824 | | //------------------------------------------------------------------------ |
825 | | // GfxRadialShading |
826 | | //------------------------------------------------------------------------ |
827 | | |
828 | | class GfxRadialShading: public GfxShading { |
829 | | public: |
830 | | |
831 | | GfxRadialShading(double x0A, double y0A, double r0A, |
832 | | double x1A, double y1A, double r1A, |
833 | | double t0A, double t1A, |
834 | | Function **funcsA, int nFuncsA, |
835 | | GBool extend0A, GBool extend1A); |
836 | | GfxRadialShading(GfxRadialShading *shading); |
837 | | virtual ~GfxRadialShading(); |
838 | | |
839 | | static GfxRadialShading *parse(Dict *dict |
840 | | ); |
841 | | |
842 | | virtual GfxShading *copy(); |
843 | | |
844 | | void getCoords(double *x0A, double *y0A, double *r0A, |
845 | | double *x1A, double *y1A, double *r1A) |
846 | 0 | { *x0A = x0; *y0A = y0; *r0A = r0; *x1A = x1; *y1A = y1; *r1A = r1; } |
847 | 0 | double getDomain0() { return t0; } |
848 | 0 | double getDomain1() { return t1; } |
849 | 0 | GBool getExtend0() { return extend0; } |
850 | 0 | GBool getExtend1() { return extend1; } |
851 | 0 | int getNFuncs() { return nFuncs; } |
852 | 0 | Function *getFunc(int i) { return funcs[i]; } |
853 | | void getColor(double t, GfxColor *color); |
854 | | |
855 | | private: |
856 | | |
857 | | double x0, y0, r0, x1, y1, r1; |
858 | | double t0, t1; |
859 | | Function *funcs[gfxColorMaxComps]; |
860 | | int nFuncs; |
861 | | GBool extend0, extend1; |
862 | | }; |
863 | | |
864 | | //------------------------------------------------------------------------ |
865 | | // GfxGouraudTriangleShading |
866 | | //------------------------------------------------------------------------ |
867 | | |
868 | | struct GfxGouraudVertex { |
869 | | double x, y; |
870 | | double color[gfxColorMaxComps]; |
871 | | }; |
872 | | |
873 | | class GfxGouraudTriangleShading: public GfxShading { |
874 | | public: |
875 | | |
876 | | GfxGouraudTriangleShading(int typeA, |
877 | | GfxGouraudVertex *verticesA, int nVerticesA, |
878 | | int (*trianglesA)[3], int nTrianglesA, |
879 | | int nCompsA, Function **funcsA, int nFuncsA); |
880 | | GfxGouraudTriangleShading(GfxGouraudTriangleShading *shading); |
881 | | virtual ~GfxGouraudTriangleShading(); |
882 | | |
883 | | static GfxGouraudTriangleShading *parse(int typeA, Dict *dict, Stream *str |
884 | | ); |
885 | | |
886 | | virtual GfxShading *copy(); |
887 | | |
888 | 0 | int getNComps() { return nComps; } |
889 | 0 | int getNTriangles() { return nTriangles; } |
890 | | void getTriangle(int i, double *x0, double *y0, double *color0, |
891 | | double *x1, double *y1, double *color1, |
892 | | double *x2, double *y2, double *color2); |
893 | | void getBBox(double *xMinA, double *yMinA, double *xMaxA, double *yMaxA); |
894 | | void getColor(double *in, GfxColor *out); |
895 | | |
896 | | private: |
897 | | |
898 | | GfxGouraudVertex *vertices; |
899 | | int nVertices; |
900 | | int (*triangles)[3]; |
901 | | int nTriangles; |
902 | | Function *funcs[gfxColorMaxComps]; |
903 | | int nComps; // number of color components (1 if nFuncs > 0) |
904 | | int nFuncs; |
905 | | }; |
906 | | |
907 | | //------------------------------------------------------------------------ |
908 | | // GfxPatchMeshShading |
909 | | //------------------------------------------------------------------------ |
910 | | |
911 | | struct GfxPatch { |
912 | | double x[4][4]; |
913 | | double y[4][4]; |
914 | | double color[2][2][gfxColorMaxComps]; |
915 | | }; |
916 | | |
917 | | class GfxPatchMeshShading: public GfxShading { |
918 | | public: |
919 | | |
920 | | GfxPatchMeshShading(int typeA, GfxPatch *patchesA, int nPatchesA, |
921 | | int nCompsA, Function **funcsA, int nFuncsA); |
922 | | GfxPatchMeshShading(GfxPatchMeshShading *shading); |
923 | | virtual ~GfxPatchMeshShading(); |
924 | | |
925 | | static GfxPatchMeshShading *parse(int typeA, Dict *dict, Stream *str |
926 | | ); |
927 | | |
928 | | virtual GfxShading *copy(); |
929 | | |
930 | 0 | int getNComps() { return nComps; } |
931 | 0 | int getNPatches() { return nPatches; } |
932 | 0 | GfxPatch *getPatch(int i) { return &patches[i]; } |
933 | | void getBBox(double *xMinA, double *yMinA, double *xMaxA, double *yMaxA); |
934 | | void getColor(double *in, GfxColor *out); |
935 | | |
936 | | private: |
937 | | |
938 | | GfxPatch *patches; |
939 | | int nPatches; |
940 | | Function *funcs[gfxColorMaxComps]; |
941 | | int nComps; // number of color components (1 if nFuncs > 0) |
942 | | int nFuncs; |
943 | | }; |
944 | | |
945 | | //------------------------------------------------------------------------ |
946 | | // GfxImageColorMap |
947 | | //------------------------------------------------------------------------ |
948 | | |
949 | | class GfxImageColorMap { |
950 | | public: |
951 | | |
952 | | // Constructor. |
953 | | GfxImageColorMap(int bitsA, Object *decode, GfxColorSpace *colorSpaceA, |
954 | | int maxAllowedBits = 8); |
955 | | |
956 | | // Destructor. |
957 | | ~GfxImageColorMap(); |
958 | | |
959 | | // Return a copy of this color map. |
960 | 0 | GfxImageColorMap *copy() { return new GfxImageColorMap(this); } |
961 | | |
962 | | // Is color map valid? |
963 | 0 | GBool isOk() { return ok; } |
964 | | |
965 | | // Get the color space. |
966 | 0 | GfxColorSpace *getColorSpace() { return colorSpace; } |
967 | | |
968 | | // Get stream decoding info. |
969 | 0 | int getNumPixelComps() { return nComps; } |
970 | 0 | int getBits() { return bits; } |
971 | | |
972 | | // Get decode table. |
973 | 0 | double getDecodeLow(int i) { return decodeLow[i]; } |
974 | 0 | double getDecodeHigh(int i) { return decodeLow[i] + decodeRange[i]; } |
975 | | |
976 | | // Convert an image pixel to a color. |
977 | | void getGray(Guchar *x, GfxGray *gray, GfxRenderingIntent ri); |
978 | | void getRGB(Guchar *x, GfxRGB *rgb, GfxRenderingIntent ri); |
979 | | void getCMYK(Guchar *x, GfxCMYK *cmyk, GfxRenderingIntent ri); |
980 | | void getColor(Guchar *x, GfxColor *color); |
981 | | |
982 | | // Convert a line of <n> pixels to 8-bit colors. |
983 | | void getGrayByteLine(Guchar *in, Guchar *out, int n, GfxRenderingIntent ri); |
984 | | void getRGBByteLine(Guchar *in, Guchar *out, int n, GfxRenderingIntent ri); |
985 | | void getCMYKByteLine(Guchar *in, Guchar *out, int n, GfxRenderingIntent ri); |
986 | | |
987 | | private: |
988 | | |
989 | | GfxImageColorMap(GfxImageColorMap *colorMap); |
990 | | |
991 | | GfxColorSpace *colorSpace; // the image color space |
992 | | int bits; // bits per component |
993 | | int nComps; // number of components in a pixel |
994 | | GfxColorSpace *colorSpace2; // secondary color space |
995 | | int nComps2; // number of components in colorSpace2 |
996 | | GfxColorComp * // lookup table |
997 | | lookup[gfxColorMaxComps]; |
998 | | GfxColorComp * // optimized case lookup table |
999 | | lookup2[gfxColorMaxComps]; |
1000 | | double // minimum values for each component |
1001 | | decodeLow[gfxColorMaxComps]; |
1002 | | double // max - min value for each component |
1003 | | decodeRange[gfxColorMaxComps]; |
1004 | | GBool ok; |
1005 | | }; |
1006 | | |
1007 | | //------------------------------------------------------------------------ |
1008 | | // GfxSubpath and GfxPath |
1009 | | //------------------------------------------------------------------------ |
1010 | | |
1011 | | class GfxSubpath { |
1012 | | public: |
1013 | | |
1014 | | // Constructor. |
1015 | | GfxSubpath(double x1, double y1); |
1016 | | |
1017 | | // Destructor. |
1018 | | ~GfxSubpath(); |
1019 | | |
1020 | | // Copy. |
1021 | 0 | GfxSubpath *copy() { return new GfxSubpath(this); } |
1022 | | |
1023 | | // Get points. |
1024 | 0 | int getNumPoints() { return n; } |
1025 | 0 | double getX(int i) { return x[i]; } |
1026 | 0 | double getY(int i) { return y[i]; } |
1027 | 0 | GBool getCurve(int i) { return curve[i]; } |
1028 | | |
1029 | | // Get last point. |
1030 | 0 | double getLastX() { return x[n-1]; } |
1031 | 0 | double getLastY() { return y[n-1]; } |
1032 | | |
1033 | | // Add a line segment. |
1034 | | void lineTo(double x1, double y1); |
1035 | | |
1036 | | // Add a Bezier curve. |
1037 | | void curveTo(double x1, double y1, double x2, double y2, |
1038 | | double x3, double y3); |
1039 | | |
1040 | | // Close the subpath. |
1041 | | void close(); |
1042 | 0 | GBool isClosed() { return closed; } |
1043 | | |
1044 | | // Add (<dx>, <dy>) to each point in the subpath. |
1045 | | void offset(double dx, double dy); |
1046 | | |
1047 | | private: |
1048 | | |
1049 | | double *x, *y; // points |
1050 | | GBool *curve; // curve[i] => point i is a control point |
1051 | | // for a Bezier curve |
1052 | | int n; // number of points |
1053 | | int size; // size of x/y arrays |
1054 | | GBool closed; // set if path is closed |
1055 | | |
1056 | | GfxSubpath(GfxSubpath *subpath); |
1057 | | }; |
1058 | | |
1059 | | class GfxPath { |
1060 | | public: |
1061 | | |
1062 | | // Constructor. |
1063 | | GfxPath(); |
1064 | | |
1065 | | // Destructor. |
1066 | | ~GfxPath(); |
1067 | | |
1068 | | // Copy. |
1069 | | GfxPath *copy() |
1070 | 0 | { return new GfxPath(justMoved, firstX, firstY, subpaths, n, size); } |
1071 | | |
1072 | | // Is there a current point? |
1073 | 0 | GBool isCurPt() { return n > 0 || justMoved; } |
1074 | | |
1075 | | // Is the path non-empty, i.e., is there at least one segment? |
1076 | 0 | GBool isPath() { return n > 0; } |
1077 | | |
1078 | | // Get subpaths. |
1079 | 0 | int getNumSubpaths() { return n; } |
1080 | 0 | GfxSubpath *getSubpath(int i) { return subpaths[i]; } |
1081 | | |
1082 | | // Get last point on last subpath. |
1083 | 0 | double getLastX() { return subpaths[n-1]->getLastX(); } |
1084 | 0 | double getLastY() { return subpaths[n-1]->getLastY(); } |
1085 | | |
1086 | | // Get the current point |
1087 | | double getCurX(); |
1088 | | double getCurY(); |
1089 | | |
1090 | | // Move the current point. |
1091 | | void moveTo(double x, double y); |
1092 | | |
1093 | | // Add a segment to the last subpath. |
1094 | | void lineTo(double x, double y); |
1095 | | |
1096 | | // Add a Bezier curve to the last subpath |
1097 | | void curveTo(double x1, double y1, double x2, double y2, |
1098 | | double x3, double y3); |
1099 | | |
1100 | | // Close the last subpath. |
1101 | | void close(); |
1102 | | |
1103 | | // Append <path> to <this>. |
1104 | | void append(GfxPath *path); |
1105 | | |
1106 | | // Add (<dx>, <dy>) to each point in the path. |
1107 | | void offset(double dx, double dy); |
1108 | | |
1109 | | private: |
1110 | | |
1111 | | GBool justMoved; // set if a new subpath was just started |
1112 | | double firstX, firstY; // first point in new subpath |
1113 | | GfxSubpath **subpaths; // subpaths |
1114 | | int n; // number of subpaths |
1115 | | int size; // size of subpaths array |
1116 | | |
1117 | | GfxPath(GBool justMoved1, double firstX1, double firstY1, |
1118 | | GfxSubpath **subpaths1, int n1, int size1); |
1119 | | }; |
1120 | | |
1121 | | //------------------------------------------------------------------------ |
1122 | | // GfxState |
1123 | | //------------------------------------------------------------------------ |
1124 | | |
1125 | | class GfxState { |
1126 | | public: |
1127 | | |
1128 | | // Construct a default GfxState, for a device with resolution <hDPI> |
1129 | | // x <vDPI>, page box <pageBox>, page rotation <rotateA>, and |
1130 | | // coordinate system specified by <upsideDown>. |
1131 | | GfxState(double hDPIA, double vDPIA, PDFRectangle *pageBox, |
1132 | | int rotateA, GBool upsideDown |
1133 | | ); |
1134 | | |
1135 | | // Destructor. |
1136 | | ~GfxState(); |
1137 | | |
1138 | | // Copy. |
1139 | | GfxState *copy(GBool copyPath = gFalse) |
1140 | 0 | { return new GfxState(this, copyPath); } |
1141 | | |
1142 | | // Accessors. |
1143 | 0 | double getHDPI() { return hDPI; } |
1144 | 0 | double getVDPI() { return vDPI; } |
1145 | 0 | double *getCTM() { return ctm; } |
1146 | 0 | double getX1() { return px1; } |
1147 | 0 | double getY1() { return py1; } |
1148 | 0 | double getX2() { return px2; } |
1149 | 0 | double getY2() { return py2; } |
1150 | 0 | double getPageWidth() { return pageWidth; } |
1151 | 0 | double getPageHeight() { return pageHeight; } |
1152 | 0 | int getRotate() { return rotate; } |
1153 | 0 | GfxColor *getFillColor() { return &fillColor; } |
1154 | 0 | GfxColor *getStrokeColor() { return &strokeColor; } |
1155 | | void getFillGray(GfxGray *gray) |
1156 | 0 | { fillColorSpace->getGray(&fillColor, gray, renderingIntent); } |
1157 | | void getStrokeGray(GfxGray *gray) |
1158 | 0 | { strokeColorSpace->getGray(&strokeColor, gray, renderingIntent); } |
1159 | | void getFillRGB(GfxRGB *rgb) |
1160 | 0 | { fillColorSpace->getRGB(&fillColor, rgb, renderingIntent); } |
1161 | | void getStrokeRGB(GfxRGB *rgb) |
1162 | 0 | { strokeColorSpace->getRGB(&strokeColor, rgb, renderingIntent); } |
1163 | | void getFillCMYK(GfxCMYK *cmyk) |
1164 | 0 | { fillColorSpace->getCMYK(&fillColor, cmyk, renderingIntent); } |
1165 | | void getStrokeCMYK(GfxCMYK *cmyk) |
1166 | 0 | { strokeColorSpace->getCMYK(&strokeColor, cmyk, renderingIntent); } |
1167 | 0 | GfxColorSpace *getFillColorSpace() { return fillColorSpace; } |
1168 | 0 | GfxColorSpace *getStrokeColorSpace() { return strokeColorSpace; } |
1169 | 0 | GfxPattern *getFillPattern() { return fillPattern; } |
1170 | 0 | GfxPattern *getStrokePattern() { return strokePattern; } |
1171 | 0 | GfxBlendMode getBlendMode() { return blendMode; } |
1172 | 0 | double getFillOpacity() { return fillOpacity; } |
1173 | 0 | double getStrokeOpacity() { return strokeOpacity; } |
1174 | 0 | GBool getFillOverprint() { return fillOverprint; } |
1175 | 0 | GBool getStrokeOverprint() { return strokeOverprint; } |
1176 | 0 | int getOverprintMode() { return overprintMode; } |
1177 | 0 | GfxRenderingIntent getRenderingIntent() { return renderingIntent; } |
1178 | 0 | Function **getTransfer() { return transfer; } |
1179 | 0 | double getLineWidth() { return lineWidth; } |
1180 | | void getLineDash(double **dash, int *length, double *start) |
1181 | 0 | { *dash = lineDash; *length = lineDashLength; *start = lineDashStart; } |
1182 | 0 | double getFlatness() { return flatness; } |
1183 | 0 | int getLineJoin() { return lineJoin; } |
1184 | 0 | int getLineCap() { return lineCap; } |
1185 | 0 | double getMiterLimit() { return miterLimit; } |
1186 | 0 | GBool getStrokeAdjust() { return strokeAdjust; } |
1187 | 0 | GfxFont *getFont() { return font; } |
1188 | 0 | double getFontSize() { return fontSize; } |
1189 | 0 | double *getTextMat() { return textMat; } |
1190 | 0 | double getCharSpace() { return charSpace; } |
1191 | 0 | double getWordSpace() { return wordSpace; } |
1192 | 0 | double getHorizScaling() { return horizScaling; } |
1193 | 0 | double getLeading() { return leading; } |
1194 | 0 | double getRise() { return rise; } |
1195 | 0 | int getRender() { return render; } |
1196 | 0 | GfxPath *getPath() { return path; } |
1197 | | void setPath(GfxPath *pathA); |
1198 | 0 | double getCurX() { return curX; } |
1199 | 0 | double getCurY() { return curY; } |
1200 | | void getClipBBox(double *xMin, double *yMin, double *xMax, double *yMax) |
1201 | 0 | { *xMin = clipXMin; *yMin = clipYMin; *xMax = clipXMax; *yMax = clipYMax; } |
1202 | | void getUserClipBBox(double *xMin, double *yMin, double *xMax, double *yMax); |
1203 | 0 | double getLineX() { return lineX; } |
1204 | 0 | double getLineY() { return lineY; } |
1205 | 0 | GBool getIgnoreColorOps() { return ignoreColorOps; } |
1206 | | |
1207 | | // Is there a current point/path? |
1208 | 0 | GBool isCurPt() { return path->isCurPt(); } |
1209 | 0 | GBool isPath() { return path->isPath(); } |
1210 | | |
1211 | | // Transforms. |
1212 | | void transform(double x1, double y1, double *x2, double *y2) |
1213 | 0 | { *x2 = ctm[0] * x1 + ctm[2] * y1 + ctm[4]; |
1214 | 0 | *y2 = ctm[1] * x1 + ctm[3] * y1 + ctm[5]; } |
1215 | | void transformDelta(double x1, double y1, double *x2, double *y2) |
1216 | 0 | { *x2 = ctm[0] * x1 + ctm[2] * y1; |
1217 | 0 | *y2 = ctm[1] * x1 + ctm[3] * y1; } |
1218 | | void textTransform(double x1, double y1, double *x2, double *y2) |
1219 | 0 | { *x2 = textMat[0] * x1 + textMat[2] * y1 + textMat[4]; |
1220 | 0 | *y2 = textMat[1] * x1 + textMat[3] * y1 + textMat[5]; } |
1221 | | void textTransformDelta(double x1, double y1, double *x2, double *y2) |
1222 | 0 | { *x2 = textMat[0] * x1 + textMat[2] * y1; |
1223 | 0 | *y2 = textMat[1] * x1 + textMat[3] * y1; } |
1224 | | double transformWidth(double w); |
1225 | | double getTransformedLineWidth() |
1226 | 0 | { return transformWidth(lineWidth); } |
1227 | | double getTransformedFontSize(); |
1228 | | void getFontTransMat(double *m11, double *m12, double *m21, double *m22); |
1229 | | |
1230 | | // Change state parameters. |
1231 | | void setCTM(double a, double b, double c, |
1232 | | double d, double e, double f); |
1233 | | void concatCTM(double a, double b, double c, |
1234 | | double d, double e, double f); |
1235 | | void shiftCTM(double tx, double ty); |
1236 | | void setFillColorSpace(GfxColorSpace *colorSpace); |
1237 | | void setStrokeColorSpace(GfxColorSpace *colorSpace); |
1238 | 0 | void setFillColor(GfxColor *color) { fillColor = *color; } |
1239 | 0 | void setStrokeColor(GfxColor *color) { strokeColor = *color; } |
1240 | | void setFillPattern(GfxPattern *pattern); |
1241 | | void setStrokePattern(GfxPattern *pattern); |
1242 | 0 | void setBlendMode(GfxBlendMode mode) { blendMode = mode; } |
1243 | 0 | void setFillOpacity(double opac) { fillOpacity = opac; } |
1244 | 0 | void setStrokeOpacity(double opac) { strokeOpacity = opac; } |
1245 | 0 | void setFillOverprint(GBool op) { fillOverprint = op; } |
1246 | 0 | void setStrokeOverprint(GBool op) { strokeOverprint = op; } |
1247 | 0 | void setOverprintMode(int opm) { overprintMode = opm; } |
1248 | 0 | void setRenderingIntent(GfxRenderingIntent ri) { renderingIntent = ri; } |
1249 | | void setTransfer(Function **funcs); |
1250 | 0 | void setLineWidth(double width) { lineWidth = width; } |
1251 | | void setLineDash(double *dash, int length, double start); |
1252 | 0 | void setFlatness(double flatness1) { flatness = flatness1; } |
1253 | 0 | void setLineJoin(int lineJoin1) { lineJoin = lineJoin1; } |
1254 | 0 | void setLineCap(int lineCap1) { lineCap = lineCap1; } |
1255 | 0 | void setMiterLimit(double limit) { miterLimit = limit; } |
1256 | 0 | void setStrokeAdjust(GBool sa) { strokeAdjust = sa; } |
1257 | | void setFont(GfxFont *fontA, double fontSizeA) |
1258 | 0 | { font = fontA; fontSize = fontSizeA; } |
1259 | | void setTextMat(double a, double b, double c, |
1260 | | double d, double e, double f) |
1261 | 0 | { textMat[0] = a; textMat[1] = b; textMat[2] = c; |
1262 | 0 | textMat[3] = d; textMat[4] = e; textMat[5] = f; } |
1263 | | void setCharSpace(double space) |
1264 | 0 | { charSpace = space; } |
1265 | | void setWordSpace(double space) |
1266 | 0 | { wordSpace = space; } |
1267 | | void setHorizScaling(double scale) |
1268 | 0 | { horizScaling = 0.01 * scale; } |
1269 | | void setLeading(double leadingA) |
1270 | 0 | { leading = leadingA; } |
1271 | | void setRise(double riseA) |
1272 | 0 | { rise = riseA; } |
1273 | | void setRender(int renderA) |
1274 | 0 | { render = renderA; } |
1275 | | |
1276 | | // Add to path. |
1277 | | void moveTo(double x, double y) |
1278 | 0 | { path->moveTo(curX = x, curY = y); } |
1279 | | void lineTo(double x, double y) |
1280 | 0 | { path->lineTo(curX = x, curY = y); } |
1281 | | void curveTo(double x1, double y1, double x2, double y2, |
1282 | | double x3, double y3) |
1283 | 0 | { path->curveTo(x1, y1, x2, y2, curX = x3, curY = y3); } |
1284 | | void closePath() |
1285 | 0 | { path->close(); curX = path->getLastX(); curY = path->getLastY(); } |
1286 | | void clearPath(); |
1287 | | |
1288 | | // Update clip region. |
1289 | | void clip(); |
1290 | | void clipToStrokePath(); |
1291 | | void clipToRect(double xMin, double yMin, double xMax, double yMax); |
1292 | | void resetDevClipRect(double xMin, double yMin, double xMax, double yMax) |
1293 | 0 | { clipXMin = xMin; clipYMin = yMin; clipXMax = xMax; clipYMax = yMax; } |
1294 | | |
1295 | | // Text position. |
1296 | 0 | void textSetPos(double tx, double ty) { lineX = tx; lineY = ty; } |
1297 | | void textMoveTo(double tx, double ty) |
1298 | 0 | { lineX = tx; lineY = ty; textTransform(tx, ty, &curX, &curY); } |
1299 | | void textShift(double tx, double ty); |
1300 | | void shift(double dx, double dy); |
1301 | | |
1302 | | // Ignore color operators (in cached/uncolored Type 3 chars, and |
1303 | | // uncolored tiling patterns). Cached Type 3 char status. |
1304 | 0 | void setIgnoreColorOps(GBool ignore) { ignoreColorOps = ignore; } |
1305 | | |
1306 | | // Push/pop GfxState on/off stack. |
1307 | | GfxState *save(); |
1308 | | GfxState *restore(); |
1309 | 0 | GBool hasSaves() { return saved != NULL; } |
1310 | | |
1311 | | // Misc |
1312 | | GBool parseBlendMode(Object *obj, GfxBlendMode *mode); |
1313 | | |
1314 | | private: |
1315 | | |
1316 | | double hDPI, vDPI; // resolution |
1317 | | double ctm[6]; // coord transform matrix |
1318 | | double px1, py1, px2, py2; // page corners (user coords) |
1319 | | double pageWidth, pageHeight; // page size (pixels) |
1320 | | int rotate; // page rotation angle |
1321 | | |
1322 | | GfxColorSpace *fillColorSpace; // fill color space |
1323 | | GfxColorSpace *strokeColorSpace; // stroke color space |
1324 | | GfxColor fillColor; // fill color |
1325 | | GfxColor strokeColor; // stroke color |
1326 | | GfxPattern *fillPattern; // fill pattern |
1327 | | GfxPattern *strokePattern; // stroke pattern |
1328 | | GfxBlendMode blendMode; // transparency blend mode |
1329 | | double fillOpacity; // fill opacity |
1330 | | double strokeOpacity; // stroke opacity |
1331 | | GBool fillOverprint; // fill overprint |
1332 | | GBool strokeOverprint; // stroke overprint |
1333 | | int overprintMode; // overprint mode ("OPM") |
1334 | | GfxRenderingIntent renderingIntent; // rendering intent |
1335 | | Function *transfer[4]; // transfer function (entries may be: all |
1336 | | // NULL = identity; last three NULL = |
1337 | | // single function; all four non-NULL = |
1338 | | // R,G,B,gray functions) |
1339 | | |
1340 | | double lineWidth; // line width |
1341 | | double *lineDash; // line dash |
1342 | | int lineDashLength; |
1343 | | double lineDashStart; |
1344 | | double flatness; // curve flatness |
1345 | | int lineJoin; // line join style |
1346 | | int lineCap; // line cap style |
1347 | | double miterLimit; // line miter limit |
1348 | | GBool strokeAdjust; // stroke adjustment |
1349 | | |
1350 | | GfxFont *font; // font |
1351 | | double fontSize; // font size |
1352 | | double textMat[6]; // text matrix |
1353 | | double charSpace; // character spacing |
1354 | | double wordSpace; // word spacing |
1355 | | double horizScaling; // horizontal scaling |
1356 | | double leading; // text leading |
1357 | | double rise; // text rise |
1358 | | int render; // text rendering mode |
1359 | | |
1360 | | GfxPath *path; // array of path elements |
1361 | | double curX, curY; // current point (user coords) |
1362 | | double lineX, lineY; // start of current text line (text coords) |
1363 | | |
1364 | | double clipXMin, clipYMin, // bounding box for clip region |
1365 | | clipXMax, clipYMax; |
1366 | | |
1367 | | GBool ignoreColorOps; // ignore color ops (in cached/uncolored |
1368 | | // Type 3 chars, and uncolored tiling |
1369 | | // patterns) |
1370 | | |
1371 | | GfxState *saved; // next GfxState on stack |
1372 | | |
1373 | | GfxState(GfxState *state, GBool copyPath); |
1374 | | }; |
1375 | | |
1376 | | #endif |