beta-0.89.2
[luatex.git] / source / libs / poppler / poppler-src / poppler / GfxState.h
blobc20438b33ab7f8486f50fa8f58e7fc0f3787023c
1 //========================================================================
2 //
3 // GfxState.h
4 //
5 // Copyright 1996-2003 Glyph & Cog, LLC
6 //
7 //========================================================================
9 //========================================================================
11 // Modified under the Poppler project - http://poppler.freedesktop.org
13 // All changes made under the Poppler project to this file are licensed
14 // under GPL version 2 or later
16 // Copyright (C) 2005 Kristian Høgsberg <krh@redhat.com>
17 // Copyright (C) 2006, 2007 Jeff Muizelaar <jeff@infidigm.net>
18 // Copyright (C) 2006 Carlos Garcia Campos <carlosgc@gnome.org>
19 // Copyright (C) 2009 Koji Otani <sho@bbr.jp>
20 // Copyright (C) 2009-2011, 2013 Albert Astals Cid <aacid@kde.org>
21 // Copyright (C) 2010 Christian Feuersänger <cfeuersaenger@googlemail.com>
22 // Copyright (C) 2011 Andrea Canciani <ranma42@gmail.com>
23 // Copyright (C) 2011-2014 Thomas Freitag <Thomas.Freitag@alfa.de>
24 // Copyright (C) 2013 Lu Wang <coolwanglu@gmail.com>
25 // Copyright (C) 2015 Adrian Johnson <ajohnson@redneon.com>
27 // To see a description of the changes please see the Changelog file that
28 // came with your tarball or type make ChangeLog if you are building from git
30 //========================================================================
32 #ifndef GFXSTATE_H
33 #define GFXSTATE_H
35 #ifdef USE_GCC_PRAGMAS
36 #pragma interface
37 #endif
39 #include "poppler-config.h"
41 #include "goo/gtypes.h"
42 #include "Object.h"
43 #include "Function.h"
45 #include <assert.h>
46 #include <map>
48 class Array;
49 class Gfx;
50 class GfxFont;
51 class PDFRectangle;
52 class GfxShading;
53 class PopplerCache;
54 class GooList;
55 class OutputDev;
56 class GfxState;
57 class GfxResources;
59 class Matrix {
60 public:
61 double m[6];
63 void init(double xx, double yx, double xy, double yy, double x0, double y0) {
64 m[0] = xx; m[1] = yx; m[2] = xy; m[3] = yy; m[4] = x0; m[5] = y0;
66 GBool invertTo(Matrix *other) const;
67 void translate(double tx, double ty);
68 void scale(double sx, double sy);
69 void transform(double x, double y, double *tx, double *ty) const;
70 double determinant() const { return m[0] * m[3] - m[1] * m[2]; }
71 double norm() const;
74 //------------------------------------------------------------------------
75 // GfxBlendMode
76 //------------------------------------------------------------------------
78 enum GfxBlendMode {
79 gfxBlendNormal,
80 gfxBlendMultiply,
81 gfxBlendScreen,
82 gfxBlendOverlay,
83 gfxBlendDarken,
84 gfxBlendLighten,
85 gfxBlendColorDodge,
86 gfxBlendColorBurn,
87 gfxBlendHardLight,
88 gfxBlendSoftLight,
89 gfxBlendDifference,
90 gfxBlendExclusion,
91 gfxBlendHue,
92 gfxBlendSaturation,
93 gfxBlendColor,
94 gfxBlendLuminosity
97 //------------------------------------------------------------------------
98 // GfxColorComp
99 //------------------------------------------------------------------------
101 // 16.16 fixed point color component
102 typedef int GfxColorComp;
104 #define gfxColorComp1 0x10000
106 static inline GfxColorComp dblToCol(double x) {
107 return (GfxColorComp)(x * gfxColorComp1);
110 static inline double colToDbl(GfxColorComp x) {
111 return (double)x / (double)gfxColorComp1;
114 static inline Guchar dblToByte(double x) {
115 return (x * 255.0);
118 static inline double byteToDbl(Guchar x) {
119 return (double)x / (double)255.0;
122 static inline GfxColorComp byteToCol(Guchar x) {
123 // (x / 255) << 16 = (0.0000000100000001... * x) << 16
124 // = ((x << 8) + (x) + (x >> 8) + ...) << 16
125 // = (x << 8) + (x) + (x >> 7)
126 // [for rounding]
127 return (GfxColorComp)((x << 8) + x + (x >> 7));
130 static inline Guchar colToByte(GfxColorComp x) {
131 // 255 * x + 0.5 = 256 * x - x + 0x8000
132 return (Guchar)(((x << 8) - x + 0x8000) >> 16);
135 //------------------------------------------------------------------------
136 // GfxColor
137 //------------------------------------------------------------------------
139 #define gfxColorMaxComps funcMaxOutputs
141 struct GfxColor {
142 GfxColorComp c[gfxColorMaxComps];
145 //------------------------------------------------------------------------
146 // GfxGray
147 //------------------------------------------------------------------------
149 typedef GfxColorComp GfxGray;
151 //------------------------------------------------------------------------
152 // GfxRGB
153 //------------------------------------------------------------------------
155 struct GfxRGB {
156 GfxColorComp r, g, b;
159 //------------------------------------------------------------------------
160 // GfxCMYK
161 //------------------------------------------------------------------------
163 struct GfxCMYK {
164 GfxColorComp c, m, y, k;
167 //------------------------------------------------------------------------
168 // GfxColorSpace
169 //------------------------------------------------------------------------
171 // NB: The nGfxColorSpaceModes constant and the gfxColorSpaceModeNames
172 // array defined in GfxState.cc must match this enum.
173 enum GfxColorSpaceMode {
174 csDeviceGray,
175 csCalGray,
176 csDeviceRGB,
177 csCalRGB,
178 csDeviceCMYK,
179 csLab,
180 csICCBased,
181 csIndexed,
182 csSeparation,
183 csDeviceN,
184 csPattern
187 // wrapper of cmsHTRANSFORM to copy
188 class GfxColorTransform {
189 public:
190 void doTransform(void *in, void *out, unsigned int size);
191 // transformA should be a cmsHTRANSFORM
192 GfxColorTransform(void *transformA, int cmsIntent, unsigned int inputPixelType, unsigned int transformPixelType);
193 ~GfxColorTransform();
194 int getIntent() { return cmsIntent; }
195 int getInputPixelType() { return inputPixelType; }
196 int getTransformPixelType() { return transformPixelType; }
197 void ref();
198 unsigned int unref();
199 private:
200 GfxColorTransform() {}
201 void *transform;
202 unsigned int refCount;
203 int cmsIntent;
204 unsigned int inputPixelType;
205 unsigned int transformPixelType;
208 class GfxColorSpace {
209 public:
211 GfxColorSpace();
212 virtual ~GfxColorSpace();
213 virtual GfxColorSpace *copy() = 0;
214 virtual GfxColorSpaceMode getMode() = 0;
216 // Construct a color space. Returns NULL if unsuccessful.
217 static GfxColorSpace *parse(GfxResources *res, Object *csObj, OutputDev *out, GfxState *state, int recursion = 0);
219 // Convert to gray, RGB, or CMYK.
220 virtual void getGray(GfxColor *color, GfxGray *gray) = 0;
221 virtual void getRGB(GfxColor *color, GfxRGB *rgb) = 0;
222 virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk) = 0;
223 virtual void getDeviceN(GfxColor *color, GfxColor *deviceN) = 0;
224 virtual void getGrayLine(Guchar * /*in*/, Guchar * /*out*/, int /*length*/) { error(errInternal, -1, "GfxColorSpace::getGrayLine this should not happen"); }
225 virtual void getRGBLine(Guchar * /*in*/, unsigned int * /*out*/, int /*length*/) { error(errInternal, -1, "GfxColorSpace::getRGBLine (first variant) this should not happen"); }
226 virtual void getRGBLine(Guchar * /*in*/, Guchar * /*out*/, int /*length*/) { error(errInternal, -1, "GfxColorSpace::getRGBLine (second variant) this should not happen"); }
227 virtual void getRGBXLine(Guchar * /*in*/, Guchar * /*out*/, int /*length*/) { error(errInternal, -1, "GfxColorSpace::getRGBXLine this should not happen"); }
228 virtual void getCMYKLine(Guchar * /*in*/, Guchar * /*out*/, int /*length*/) { error(errInternal, -1, "GfxColorSpace::getCMYKLine this should not happen"); }
229 virtual void getDeviceNLine(Guchar * /*in*/, Guchar * /*out*/, int /*length*/) { error(errInternal, -1, "GfxColorSpace::getDeviceNLine this should not happen"); }
231 // create mapping for spot colorants
232 virtual void createMapping(GooList *separationList, int maxSepComps);
234 // Does this ColorSpace support getRGBLine?
235 virtual GBool useGetRGBLine() { return gFalse; }
236 // Does this ColorSpace support getGrayLine?
237 virtual GBool useGetGrayLine() { return gFalse; }
238 // Does this ColorSpace support getCMYKLine?
239 virtual GBool useGetCMYKLine() { return gFalse; }
240 // Does this ColorSpace support getDeviceNLine?
241 virtual GBool useGetDeviceNLine() { return gFalse; }
243 // Return the number of color components.
244 virtual int getNComps() = 0;
246 // Get this color space's default color.
247 virtual void getDefaultColor(GfxColor *color) = 0;
249 // Return the default ranges for each component, assuming an image
250 // with a max pixel value of <maxImgPixel>.
251 virtual void getDefaultRanges(double *decodeLow, double *decodeRange,
252 int maxImgPixel);
254 // Returns true if painting operations in this color space never
255 // mark the page (e.g., the "None" colorant).
256 virtual GBool isNonMarking() { return gFalse; }
258 // Return the color space's overprint mask.
259 Guint getOverprintMask() { return overprintMask; }
261 // Return the number of color space modes
262 static int getNumColorSpaceModes();
264 // Return the name of the <idx>th color space mode.
265 static const char *getColorSpaceModeName(int idx);
267 #ifdef USE_CMS
268 static int setupColorProfiles();
269 // displayProfileA should be a cmsHPROFILE
270 static void setDisplayProfile(void *displayProfileA);
271 static void setDisplayProfileName(GooString *name);
272 // result will be a cmsHPROFILE
273 static void *getRGBProfile();
274 // result will be a cmsHPROFILE
275 static void *getDisplayProfile();
276 #endif
277 protected:
279 Guint overprintMask;
280 int *mapping;
283 //------------------------------------------------------------------------
284 // GfxDeviceGrayColorSpace
285 //------------------------------------------------------------------------
287 class GfxDeviceGrayColorSpace: public GfxColorSpace {
288 public:
290 GfxDeviceGrayColorSpace();
291 virtual ~GfxDeviceGrayColorSpace();
292 virtual GfxColorSpace *copy();
293 virtual GfxColorSpaceMode getMode() { return csDeviceGray; }
295 virtual void getGray(GfxColor *color, GfxGray *gray);
296 virtual void getRGB(GfxColor *color, GfxRGB *rgb);
297 virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
298 virtual void getDeviceN(GfxColor *color, GfxColor *deviceN);
299 virtual void getGrayLine(Guchar *in, Guchar *out, int length);
300 virtual void getRGBLine(Guchar *in, unsigned int *out, int length);
301 virtual void getRGBLine(Guchar *in, Guchar *out, int length);
302 virtual void getRGBXLine(Guchar *in, Guchar *out, int length);
303 virtual void getCMYKLine(Guchar *in, Guchar *out, int length);
304 virtual void getDeviceNLine(Guchar *in, Guchar *out, int length);
306 virtual GBool useGetRGBLine() { return gTrue; }
307 virtual GBool useGetGrayLine() { return gTrue; }
308 virtual GBool useGetCMYKLine() { return gTrue; }
309 virtual GBool useGetDeviceNLine() { return gTrue; }
311 virtual int getNComps() { return 1; }
312 virtual void getDefaultColor(GfxColor *color);
314 private:
317 //------------------------------------------------------------------------
318 // GfxCalGrayColorSpace
319 //------------------------------------------------------------------------
321 class GfxCalGrayColorSpace: public GfxColorSpace {
322 public:
324 GfxCalGrayColorSpace();
325 virtual ~GfxCalGrayColorSpace();
326 virtual GfxColorSpace *copy();
327 virtual GfxColorSpaceMode getMode() { return csCalGray; }
329 // Construct a CalGray color space. Returns NULL if unsuccessful.
330 static GfxColorSpace *parse(Array *arr, GfxState *state);
332 virtual void getGray(GfxColor *color, GfxGray *gray);
333 virtual void getRGB(GfxColor *color, GfxRGB *rgb);
334 virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
335 virtual void getDeviceN(GfxColor *color, GfxColor *deviceN);
337 virtual int getNComps() { return 1; }
338 virtual void getDefaultColor(GfxColor *color);
340 // CalGray-specific access.
341 double getWhiteX() { return whiteX; }
342 double getWhiteY() { return whiteY; }
343 double getWhiteZ() { return whiteZ; }
344 double getBlackX() { return blackX; }
345 double getBlackY() { return blackY; }
346 double getBlackZ() { return blackZ; }
347 double getGamma() { return gamma; }
349 private:
351 double whiteX, whiteY, whiteZ; // white point
352 double blackX, blackY, blackZ; // black point
353 double gamma; // gamma value
354 double kr, kg, kb; // gamut mapping mulitpliers
355 void getXYZ(GfxColor *color, double *pX, double *pY, double *pZ);
356 #ifdef USE_CMS
357 GfxColorTransform *transform;
358 #endif
361 //------------------------------------------------------------------------
362 // GfxDeviceRGBColorSpace
363 //------------------------------------------------------------------------
365 class GfxDeviceRGBColorSpace: public GfxColorSpace {
366 public:
368 GfxDeviceRGBColorSpace();
369 virtual ~GfxDeviceRGBColorSpace();
370 virtual GfxColorSpace *copy();
371 virtual GfxColorSpaceMode getMode() { return csDeviceRGB; }
373 virtual void getGray(GfxColor *color, GfxGray *gray);
374 virtual void getRGB(GfxColor *color, GfxRGB *rgb);
375 virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
376 virtual void getDeviceN(GfxColor *color, GfxColor *deviceN);
377 virtual void getGrayLine(Guchar *in, Guchar *out, int length);
378 virtual void getRGBLine(Guchar *in, unsigned int *out, int length);
379 virtual void getRGBLine(Guchar *in, Guchar *out, int length);
380 virtual void getRGBXLine(Guchar *in, Guchar *out, int length);
381 virtual void getCMYKLine(Guchar *in, Guchar *out, int length);
382 virtual void getDeviceNLine(Guchar *in, Guchar *out, int length);
384 virtual GBool useGetRGBLine() { return gTrue; }
385 virtual GBool useGetGrayLine() { return gTrue; }
386 virtual GBool useGetCMYKLine() { return gTrue; }
387 virtual GBool useGetDeviceNLine() { return gTrue; }
389 virtual int getNComps() { return 3; }
390 virtual void getDefaultColor(GfxColor *color);
392 private:
395 //------------------------------------------------------------------------
396 // GfxCalRGBColorSpace
397 //------------------------------------------------------------------------
399 class GfxCalRGBColorSpace: public GfxColorSpace {
400 public:
402 GfxCalRGBColorSpace();
403 virtual ~GfxCalRGBColorSpace();
404 virtual GfxColorSpace *copy();
405 virtual GfxColorSpaceMode getMode() { return csCalRGB; }
407 // Construct a CalRGB color space. Returns NULL if unsuccessful.
408 static GfxColorSpace *parse(Array *arr, GfxState *state);
410 virtual void getGray(GfxColor *color, GfxGray *gray);
411 virtual void getRGB(GfxColor *color, GfxRGB *rgb);
412 virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
413 virtual void getDeviceN(GfxColor *color, GfxColor *deviceN);
415 virtual int getNComps() { return 3; }
416 virtual void getDefaultColor(GfxColor *color);
418 // CalRGB-specific access.
419 double getWhiteX() { return whiteX; }
420 double getWhiteY() { return whiteY; }
421 double getWhiteZ() { return whiteZ; }
422 double getBlackX() { return blackX; }
423 double getBlackY() { return blackY; }
424 double getBlackZ() { return blackZ; }
425 double getGammaR() { return gammaR; }
426 double getGammaG() { return gammaG; }
427 double getGammaB() { return gammaB; }
428 double *getMatrix() { return mat; }
430 private:
432 double whiteX, whiteY, whiteZ; // white point
433 double blackX, blackY, blackZ; // black point
434 double gammaR, gammaG, gammaB; // gamma values
435 double mat[9]; // ABC -> XYZ transform matrix
436 double kr, kg, kb; // gamut mapping mulitpliers
437 void getXYZ(GfxColor *color, double *pX, double *pY, double *pZ);
438 #ifdef USE_CMS
439 GfxColorTransform *transform;
440 #endif
443 //------------------------------------------------------------------------
444 // GfxDeviceCMYKColorSpace
445 //------------------------------------------------------------------------
447 class GfxDeviceCMYKColorSpace: public GfxColorSpace {
448 public:
450 GfxDeviceCMYKColorSpace();
451 virtual ~GfxDeviceCMYKColorSpace();
452 virtual GfxColorSpace *copy();
453 virtual GfxColorSpaceMode getMode() { return csDeviceCMYK; }
455 virtual void getGray(GfxColor *color, GfxGray *gray);
456 virtual void getRGB(GfxColor *color, GfxRGB *rgb);
457 virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
458 virtual void getDeviceN(GfxColor *color, GfxColor *deviceN);
459 virtual void getRGBLine(Guchar *in, unsigned int *out, int length);
460 virtual void getRGBLine(Guchar *, Guchar *out, int length);
461 virtual void getRGBXLine(Guchar *in, Guchar *out, int length);
462 virtual void getCMYKLine(Guchar *in, Guchar *out, int length);
463 virtual void getDeviceNLine(Guchar *in, Guchar *out, int length);
464 virtual GBool useGetRGBLine() { return gTrue; }
465 virtual GBool useGetCMYKLine() { return gTrue; }
466 virtual GBool useGetDeviceNLine() { return gTrue; }
468 virtual int getNComps() { return 4; }
469 virtual void getDefaultColor(GfxColor *color);
471 private:
474 //------------------------------------------------------------------------
475 // GfxLabColorSpace
476 //------------------------------------------------------------------------
478 class GfxLabColorSpace: public GfxColorSpace {
479 public:
481 GfxLabColorSpace();
482 virtual ~GfxLabColorSpace();
483 virtual GfxColorSpace *copy();
484 virtual GfxColorSpaceMode getMode() { return csLab; }
486 // Construct a Lab color space. Returns NULL if unsuccessful.
487 static GfxColorSpace *parse(Array *arr, GfxState *state);
489 virtual void getGray(GfxColor *color, GfxGray *gray);
490 virtual void getRGB(GfxColor *color, GfxRGB *rgb);
491 virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
492 virtual void getDeviceN(GfxColor *color, GfxColor *deviceN);
494 virtual int getNComps() { return 3; }
495 virtual void getDefaultColor(GfxColor *color);
497 virtual void getDefaultRanges(double *decodeLow, double *decodeRange,
498 int maxImgPixel);
500 // Lab-specific access.
501 double getWhiteX() { return whiteX; }
502 double getWhiteY() { return whiteY; }
503 double getWhiteZ() { return whiteZ; }
504 double getBlackX() { return blackX; }
505 double getBlackY() { return blackY; }
506 double getBlackZ() { return blackZ; }
507 double getAMin() { return aMin; }
508 double getAMax() { return aMax; }
509 double getBMin() { return bMin; }
510 double getBMax() { return bMax; }
512 private:
514 double whiteX, whiteY, whiteZ; // white point
515 double blackX, blackY, blackZ; // black point
516 double aMin, aMax, bMin, bMax; // range for the a and b components
517 double kr, kg, kb; // gamut mapping mulitpliers
518 void getXYZ(GfxColor *color, double *pX, double *pY, double *pZ);
519 #ifdef USE_CMS
520 GfxColorTransform *transform;
521 #endif
524 //------------------------------------------------------------------------
525 // GfxICCBasedColorSpace
526 //------------------------------------------------------------------------
528 class GfxICCBasedColorSpace: public GfxColorSpace {
529 public:
531 GfxICCBasedColorSpace(int nCompsA, GfxColorSpace *altA,
532 Ref *iccProfileStreamA);
533 virtual ~GfxICCBasedColorSpace();
534 virtual GfxColorSpace *copy();
535 virtual GfxColorSpaceMode getMode() { return csICCBased; }
537 // Construct an ICCBased color space. Returns NULL if unsuccessful.
538 static GfxColorSpace *parse(Array *arr, OutputDev *out, GfxState *state, int recursion);
540 virtual void getGray(GfxColor *color, GfxGray *gray);
541 virtual void getRGB(GfxColor *color, GfxRGB *rgb);
542 virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
543 virtual void getDeviceN(GfxColor *color, GfxColor *deviceN);
544 virtual void getRGBLine(Guchar *in, unsigned int *out, int length);
545 virtual void getRGBLine(Guchar *in, Guchar *out, int length);
546 virtual void getRGBXLine(Guchar *in, Guchar *out, int length);
547 virtual void getCMYKLine(Guchar *in, Guchar *out, int length);
548 virtual void getDeviceNLine(Guchar *in, Guchar *out, int length);
550 virtual GBool useGetRGBLine();
551 virtual GBool useGetCMYKLine();
552 virtual GBool useGetDeviceNLine();
554 virtual int getNComps() { return nComps; }
555 virtual void getDefaultColor(GfxColor *color);
557 virtual void getDefaultRanges(double *decodeLow, double *decodeRange,
558 int maxImgPixel);
560 // ICCBased-specific access.
561 GfxColorSpace *getAlt() { return alt; }
563 private:
565 int nComps; // number of color components (1, 3, or 4)
566 GfxColorSpace *alt; // alternate color space
567 double rangeMin[4]; // min values for each component
568 double rangeMax[4]; // max values for each component
569 Ref iccProfileStream; // the ICC profile
570 #ifdef USE_CMS
571 int getIntent() { return (transform != NULL) ? transform->getIntent() : 0; }
572 GfxColorTransform *transform;
573 GfxColorTransform *lineTransform; // color transform for line
574 std::map<unsigned int, unsigned int> cmsCache;
575 #endif
577 //------------------------------------------------------------------------
578 // GfxIndexedColorSpace
579 //------------------------------------------------------------------------
581 class GfxIndexedColorSpace: public GfxColorSpace {
582 public:
584 GfxIndexedColorSpace(GfxColorSpace *baseA, int indexHighA);
585 virtual ~GfxIndexedColorSpace();
586 virtual GfxColorSpace *copy();
587 virtual GfxColorSpaceMode getMode() { return csIndexed; }
589 // Construct an Indexed color space. Returns NULL if unsuccessful.
590 static GfxColorSpace *parse(GfxResources *res, Array *arr, OutputDev *out, GfxState *state, int recursion);
592 virtual void getGray(GfxColor *color, GfxGray *gray);
593 virtual void getRGB(GfxColor *color, GfxRGB *rgb);
594 virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
595 virtual void getDeviceN(GfxColor *color, GfxColor *deviceN);
596 virtual void getRGBLine(Guchar *in, unsigned int *out, int length);
597 virtual void getRGBLine(Guchar *in, Guchar *out, int length);
598 virtual void getRGBXLine(Guchar *in, Guchar *out, int length);
599 virtual void getCMYKLine(Guchar *in, Guchar *out, int length);
600 virtual void getDeviceNLine(Guchar *in, Guchar *out, int length);
602 virtual GBool useGetRGBLine() { return gTrue; }
603 virtual GBool useGetCMYKLine() { return gTrue; }
604 virtual GBool useGetDeviceNLine() { return gTrue; }
606 virtual int getNComps() { return 1; }
607 virtual void getDefaultColor(GfxColor *color);
609 virtual void getDefaultRanges(double *decodeLow, double *decodeRange,
610 int maxImgPixel);
612 // Indexed-specific access.
613 GfxColorSpace *getBase() { return base; }
614 int getIndexHigh() { return indexHigh; }
615 Guchar *getLookup() { return lookup; }
616 GfxColor *mapColorToBase(GfxColor *color, GfxColor *baseColor);
617 Guint getOverprintMask() { return base->getOverprintMask(); }
618 virtual void createMapping(GooList *separationList, int maxSepComps)
619 { base->createMapping(separationList, maxSepComps); }
622 private:
624 GfxColorSpace *base; // base color space
625 int indexHigh; // max pixel value
626 Guchar *lookup; // lookup table
629 //------------------------------------------------------------------------
630 // GfxSeparationColorSpace
631 //------------------------------------------------------------------------
633 class GfxSeparationColorSpace: public GfxColorSpace {
634 public:
636 GfxSeparationColorSpace(GooString *nameA, GfxColorSpace *altA,
637 Function *funcA);
638 virtual ~GfxSeparationColorSpace();
639 virtual GfxColorSpace *copy();
640 virtual GfxColorSpaceMode getMode() { return csSeparation; }
642 // Construct a Separation color space. Returns NULL if unsuccessful.
643 static GfxColorSpace *parse(GfxResources *res, Array *arr, OutputDev *out, GfxState *state, int recursion);
645 virtual void getGray(GfxColor *color, GfxGray *gray);
646 virtual void getRGB(GfxColor *color, GfxRGB *rgb);
647 virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
648 virtual void getDeviceN(GfxColor *color, GfxColor *deviceN);
650 virtual void createMapping(GooList *separationList, int maxSepComps);
652 virtual int getNComps() { return 1; }
653 virtual void getDefaultColor(GfxColor *color);
655 virtual GBool isNonMarking() { return nonMarking; }
657 // Separation-specific access.
658 GooString *getName() { return name; }
659 GfxColorSpace *getAlt() { return alt; }
660 Function *getFunc() { return func; }
662 private:
664 GfxSeparationColorSpace(GooString *nameA, GfxColorSpace *altA,
665 Function *funcA, GBool nonMarkingA,
666 Guint overprintMaskA, int *mappingA);
668 GooString *name; // colorant name
669 GfxColorSpace *alt; // alternate color space
670 Function *func; // tint transform (into alternate color space)
671 GBool nonMarking;
674 //------------------------------------------------------------------------
675 // GfxDeviceNColorSpace
676 //------------------------------------------------------------------------
678 class GfxDeviceNColorSpace: public GfxColorSpace {
679 public:
681 GfxDeviceNColorSpace(int nCompsA, GooString **namesA,
682 GfxColorSpace *alt, Function *func, GooList *sepsCS);
683 virtual ~GfxDeviceNColorSpace();
684 virtual GfxColorSpace *copy();
685 virtual GfxColorSpaceMode getMode() { return csDeviceN; }
687 // Construct a DeviceN color space. Returns NULL if unsuccessful.
688 static GfxColorSpace *parse(GfxResources *res, Array *arr, OutputDev *out, GfxState *state, int recursion);
690 virtual void getGray(GfxColor *color, GfxGray *gray);
691 virtual void getRGB(GfxColor *color, GfxRGB *rgb);
692 virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
693 virtual void getDeviceN(GfxColor *color, GfxColor *deviceN);
695 virtual void createMapping(GooList *separationList, int maxSepComps);
697 virtual int getNComps() { return nComps; }
698 virtual void getDefaultColor(GfxColor *color);
700 virtual GBool isNonMarking() { return nonMarking; }
702 // DeviceN-specific access.
703 GooString *getColorantName(int i) { return names[i]; }
704 GfxColorSpace *getAlt() { return alt; }
705 Function *getTintTransformFunc() { return func; }
707 private:
709 GfxDeviceNColorSpace(int nCompsA, GooString **namesA,
710 GfxColorSpace *alt, Function *func, GooList *sepsCSA,
711 int *mappingA, GBool nonMarkingA, Guint overprintMaskA);
713 int nComps; // number of components
714 GooString // colorant names
715 *names[gfxColorMaxComps];
716 GfxColorSpace *alt; // alternate color space
717 Function *func; // tint transform (into alternate color space)
718 GBool nonMarking;
719 GooList *sepsCS; // list of separation cs for spot colorants;
722 //------------------------------------------------------------------------
723 // GfxPatternColorSpace
724 //------------------------------------------------------------------------
726 class GfxPatternColorSpace: public GfxColorSpace {
727 public:
729 GfxPatternColorSpace(GfxColorSpace *underA);
730 virtual ~GfxPatternColorSpace();
731 virtual GfxColorSpace *copy();
732 virtual GfxColorSpaceMode getMode() { return csPattern; }
734 // Construct a Pattern color space. Returns NULL if unsuccessful.
735 static GfxColorSpace *parse(GfxResources *res, Array *arr, OutputDev *out, GfxState *state, int recursion);
737 virtual void getGray(GfxColor *color, GfxGray *gray);
738 virtual void getRGB(GfxColor *color, GfxRGB *rgb);
739 virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
740 virtual void getDeviceN(GfxColor *color, GfxColor *deviceN);
742 virtual int getNComps() { return 0; }
743 virtual void getDefaultColor(GfxColor *color);
745 // Pattern-specific access.
746 GfxColorSpace *getUnder() { return under; }
748 private:
750 GfxColorSpace *under; // underlying color space (for uncolored
751 // patterns)
754 //------------------------------------------------------------------------
755 // GfxPattern
756 //------------------------------------------------------------------------
758 class GfxPattern {
759 public:
761 GfxPattern(int typeA);
762 virtual ~GfxPattern();
764 static GfxPattern *parse(GfxResources *res, Object *obj, OutputDev *out, GfxState *state);
766 virtual GfxPattern *copy() = 0;
768 int getType() { return type; }
770 private:
772 int type;
775 //------------------------------------------------------------------------
776 // GfxTilingPattern
777 //------------------------------------------------------------------------
779 class GfxTilingPattern: public GfxPattern {
780 public:
782 static GfxTilingPattern *parse(Object *patObj);
783 virtual ~GfxTilingPattern();
785 virtual GfxPattern *copy();
787 int getPaintType() { return paintType; }
788 int getTilingType() { return tilingType; }
789 double *getBBox() { return bbox; }
790 double getXStep() { return xStep; }
791 double getYStep() { return yStep; }
792 Dict *getResDict()
793 { return resDict.isDict() ? resDict.getDict() : (Dict *)NULL; }
794 double *getMatrix() { return matrix; }
795 Object *getContentStream() { return &contentStream; }
797 private:
799 GfxTilingPattern(int paintTypeA, int tilingTypeA,
800 double *bboxA, double xStepA, double yStepA,
801 Object *resDictA, double *matrixA,
802 Object *contentStreamA);
804 int paintType;
805 int tilingType;
806 double bbox[4];
807 double xStep, yStep;
808 Object resDict;
809 double matrix[6];
810 Object contentStream;
813 //------------------------------------------------------------------------
814 // GfxShadingPattern
815 //------------------------------------------------------------------------
817 class GfxShadingPattern: public GfxPattern {
818 public:
820 static GfxShadingPattern *parse(GfxResources *res, Object *patObj, OutputDev *out, GfxState *state);
821 virtual ~GfxShadingPattern();
823 virtual GfxPattern *copy();
825 GfxShading *getShading() { return shading; }
826 double *getMatrix() { return matrix; }
828 private:
830 GfxShadingPattern(GfxShading *shadingA, double *matrixA);
832 GfxShading *shading;
833 double matrix[6];
836 //------------------------------------------------------------------------
837 // GfxShading
838 //------------------------------------------------------------------------
840 class GfxShading {
841 public:
843 GfxShading(int typeA);
844 GfxShading(GfxShading *shading);
845 virtual ~GfxShading();
847 static GfxShading *parse(GfxResources *res, Object *obj, OutputDev *out, GfxState *state);
849 virtual GfxShading *copy() = 0;
851 int getType() { return type; }
852 GfxColorSpace *getColorSpace() { return colorSpace; }
853 GfxColor *getBackground() { return &background; }
854 GBool getHasBackground() { return hasBackground; }
855 void getBBox(double *xMinA, double *yMinA, double *xMaxA, double *yMaxA)
856 { *xMinA = xMin; *yMinA = yMin; *xMaxA = xMax; *yMaxA = yMax; }
857 GBool getHasBBox() { return hasBBox; }
859 protected:
861 GBool init(GfxResources *res, Dict *dict, OutputDev *out, GfxState *state);
863 int type;
864 GfxColorSpace *colorSpace;
865 GfxColor background;
866 GBool hasBackground;
867 double xMin, yMin, xMax, yMax;
868 GBool hasBBox;
871 //------------------------------------------------------------------------
872 // GfxUnivariateShading
873 //------------------------------------------------------------------------
875 class GfxUnivariateShading: public GfxShading {
876 public:
878 GfxUnivariateShading(int typeA,
879 double t0A, double t1A,
880 Function **funcsA, int nFuncsA,
881 GBool extend0A, GBool extend1A);
882 GfxUnivariateShading(GfxUnivariateShading *shading);
883 virtual ~GfxUnivariateShading();
885 double getDomain0() { return t0; }
886 double getDomain1() { return t1; }
887 GBool getExtend0() { return extend0; }
888 GBool getExtend1() { return extend1; }
889 int getNFuncs() { return nFuncs; }
890 Function *getFunc(int i) { return funcs[i]; }
891 void getColor(double t, GfxColor *color);
893 void setupCache(const Matrix *ctm,
894 double xMin, double yMin,
895 double xMax, double yMax);
897 virtual void getParameterRange(double *lower, double *upper,
898 double xMin, double yMin,
899 double xMax, double yMax) = 0;
901 virtual double getDistance(double tMin, double tMax) = 0;
903 private:
905 double t0, t1;
906 Function *funcs[gfxColorMaxComps];
907 int nFuncs;
908 GBool extend0, extend1;
910 int cacheSize, lastMatch;
911 double *cacheBounds;
912 double *cacheCoeff;
913 double *cacheValues;
916 //------------------------------------------------------------------------
917 // GfxFunctionShading
918 //------------------------------------------------------------------------
920 class GfxFunctionShading: public GfxShading {
921 public:
923 GfxFunctionShading(double x0A, double y0A,
924 double x1A, double y1A,
925 double *matrixA,
926 Function **funcsA, int nFuncsA);
927 GfxFunctionShading(GfxFunctionShading *shading);
928 virtual ~GfxFunctionShading();
930 static GfxFunctionShading *parse(GfxResources *res, Dict *dict, OutputDev *out, GfxState *state);
932 virtual GfxShading *copy();
934 void getDomain(double *x0A, double *y0A, double *x1A, double *y1A)
935 { *x0A = x0; *y0A = y0; *x1A = x1; *y1A = y1; }
936 double *getMatrix() { return matrix; }
937 int getNFuncs() { return nFuncs; }
938 Function *getFunc(int i) { return funcs[i]; }
939 void getColor(double x, double y, GfxColor *color);
941 private:
943 double x0, y0, x1, y1;
944 double matrix[6];
945 Function *funcs[gfxColorMaxComps];
946 int nFuncs;
949 //------------------------------------------------------------------------
950 // GfxAxialShading
951 //------------------------------------------------------------------------
953 class GfxAxialShading: public GfxUnivariateShading {
954 public:
956 GfxAxialShading(double x0A, double y0A,
957 double x1A, double y1A,
958 double t0A, double t1A,
959 Function **funcsA, int nFuncsA,
960 GBool extend0A, GBool extend1A);
961 GfxAxialShading(GfxAxialShading *shading);
962 virtual ~GfxAxialShading();
964 static GfxAxialShading *parse(GfxResources *res, Dict *dict, OutputDev *out, GfxState *state);
966 virtual GfxShading *copy();
968 void getCoords(double *x0A, double *y0A, double *x1A, double *y1A)
969 { *x0A = x0; *y0A = y0; *x1A = x1; *y1A = y1; }
971 virtual void getParameterRange(double *lower, double *upper,
972 double xMin, double yMin,
973 double xMax, double yMax);
975 virtual double getDistance(double tMin, double tMax);
977 private:
979 double x0, y0, x1, y1;
982 //------------------------------------------------------------------------
983 // GfxRadialShading
984 //------------------------------------------------------------------------
986 class GfxRadialShading: public GfxUnivariateShading {
987 public:
989 GfxRadialShading(double x0A, double y0A, double r0A,
990 double x1A, double y1A, double r1A,
991 double t0A, double t1A,
992 Function **funcsA, int nFuncsA,
993 GBool extend0A, GBool extend1A);
994 GfxRadialShading(GfxRadialShading *shading);
995 virtual ~GfxRadialShading();
997 static GfxRadialShading *parse(GfxResources *res, Dict *dict, OutputDev *out, GfxState *state);
999 virtual GfxShading *copy();
1001 void getCoords(double *x0A, double *y0A, double *r0A,
1002 double *x1A, double *y1A, double *r1A)
1003 { *x0A = x0; *y0A = y0; *r0A = r0; *x1A = x1; *y1A = y1; *r1A = r1; }
1005 virtual void getParameterRange(double *lower, double *upper,
1006 double xMin, double yMin,
1007 double xMax, double yMax);
1009 virtual double getDistance(double tMin, double tMax);
1011 private:
1013 double x0, y0, r0, x1, y1, r1;
1016 //------------------------------------------------------------------------
1017 // GfxGouraudTriangleShading
1018 //------------------------------------------------------------------------
1020 struct GfxGouraudVertex {
1021 double x, y;
1022 GfxColor color;
1025 class GfxGouraudTriangleShading: public GfxShading {
1026 public:
1028 GfxGouraudTriangleShading(int typeA,
1029 GfxGouraudVertex *verticesA, int nVerticesA,
1030 int (*trianglesA)[3], int nTrianglesA,
1031 Function **funcsA, int nFuncsA);
1032 GfxGouraudTriangleShading(GfxGouraudTriangleShading *shading);
1033 virtual ~GfxGouraudTriangleShading();
1035 static GfxGouraudTriangleShading *parse(GfxResources *res, int typeA, Dict *dict, Stream *str, OutputDev *out, GfxState *state);
1037 virtual GfxShading *copy();
1039 int getNTriangles() { return nTriangles; }
1041 bool isParameterized() const { return nFuncs > 0; }
1044 * @precondition isParameterized() == true
1046 double getParameterDomainMin() const { assert(isParameterized()); return funcs[0]->getDomainMin(0); }
1049 * @precondition isParameterized() == true
1051 double getParameterDomainMax() const { assert(isParameterized()); return funcs[0]->getDomainMax(0); }
1054 * @precondition isParameterized() == false
1056 void getTriangle(int i, double *x0, double *y0, GfxColor *color0,
1057 double *x1, double *y1, GfxColor *color1,
1058 double *x2, double *y2, GfxColor *color2);
1061 * Variant for functions.
1063 * @precondition isParameterized() == true
1065 void getTriangle(int i, double *x0, double *y0, double *color0,
1066 double *x1, double *y1, double *color1,
1067 double *x2, double *y2, double *color2);
1069 void getParameterizedColor(double t, GfxColor *color);
1071 private:
1073 GfxGouraudVertex *vertices;
1074 int nVertices;
1075 int (*triangles)[3];
1076 int nTriangles;
1077 Function *funcs[gfxColorMaxComps];
1078 int nFuncs;
1081 //------------------------------------------------------------------------
1082 // GfxPatchMeshShading
1083 //------------------------------------------------------------------------
1086 * A tensor product cubic bezier patch consisting of 4x4 points and 4 color
1087 * values.
1089 * See the Shading Type 7 specifications. Note that Shading Type 6 is also
1090 * represented using GfxPatch.
1092 struct GfxPatch {
1094 * Represents a single color value for the patch.
1096 struct ColorValue {
1098 * For parameterized patches, only element 0 is valid; it contains
1099 * the single parameter.
1101 * For non-parameterized patches, c contains all color components
1102 * as decoded from the input stream. In this case, you will need to
1103 * use dblToCol() before assigning them to GfxColor.
1105 double c[gfxColorMaxComps];
1108 double x[4][4];
1109 double y[4][4];
1110 ColorValue color[2][2];
1113 class GfxPatchMeshShading: public GfxShading {
1114 public:
1116 GfxPatchMeshShading(int typeA, GfxPatch *patchesA, int nPatchesA,
1117 Function **funcsA, int nFuncsA);
1118 GfxPatchMeshShading(GfxPatchMeshShading *shading);
1119 virtual ~GfxPatchMeshShading();
1121 static GfxPatchMeshShading *parse(GfxResources *res, int typeA, Dict *dict, Stream *str, OutputDev *out, GfxState *state);
1123 virtual GfxShading *copy();
1125 int getNPatches() { return nPatches; }
1126 GfxPatch *getPatch(int i) { return &patches[i]; }
1128 bool isParameterized() const { return nFuncs > 0; }
1131 * @precondition isParameterized() == true
1133 double getParameterDomainMin() const { assert(isParameterized()); return funcs[0]->getDomainMin(0); }
1136 * @precondition isParameterized() == true
1138 double getParameterDomainMax() const { assert(isParameterized()); return funcs[0]->getDomainMax(0); }
1140 void getParameterizedColor(double t, GfxColor *color);
1142 private:
1144 GfxPatch *patches;
1145 int nPatches;
1146 Function *funcs[gfxColorMaxComps];
1147 int nFuncs;
1150 //------------------------------------------------------------------------
1151 // GfxImageColorMap
1152 //------------------------------------------------------------------------
1154 class GfxImageColorMap {
1155 public:
1157 // Constructor.
1158 GfxImageColorMap(int bitsA, Object *decode, GfxColorSpace *colorSpaceA);
1160 // Destructor.
1161 ~GfxImageColorMap();
1163 // Return a copy of this color map.
1164 GfxImageColorMap *copy() { return new GfxImageColorMap(this); }
1166 // Is color map valid?
1167 GBool isOk() { return ok; }
1169 // Get the color space.
1170 GfxColorSpace *getColorSpace() { return colorSpace; }
1172 // Get stream decoding info.
1173 int getNumPixelComps() { return nComps; }
1174 int getBits() { return bits; }
1176 // Get decode table.
1177 double getDecodeLow(int i) { return decodeLow[i]; }
1178 double getDecodeHigh(int i) { return decodeLow[i] + decodeRange[i]; }
1180 bool useRGBLine() { return (colorSpace2 && colorSpace2->useGetRGBLine ()) || (!colorSpace2 && colorSpace->useGetRGBLine ()); }
1181 bool useCMYKLine() { return (colorSpace2 && colorSpace2->useGetCMYKLine ()) || (!colorSpace2 && colorSpace->useGetCMYKLine ()); }
1182 bool useDeviceNLine() { return (colorSpace2 && colorSpace2->useGetDeviceNLine ()) || (!colorSpace2 && colorSpace->useGetDeviceNLine ()); }
1184 // Convert an image pixel to a color.
1185 void getGray(Guchar *x, GfxGray *gray);
1186 void getRGB(Guchar *x, GfxRGB *rgb);
1187 void getRGBLine(Guchar *in, unsigned int *out, int length);
1188 void getRGBLine(Guchar *in, Guchar *out, int length);
1189 void getRGBXLine(Guchar *in, Guchar *out, int length);
1190 void getGrayLine(Guchar *in, Guchar *out, int length);
1191 void getCMYKLine(Guchar *in, Guchar *out, int length);
1192 void getDeviceNLine(Guchar *in, Guchar *out, int length);
1193 void getCMYK(Guchar *x, GfxCMYK *cmyk);
1194 void getDeviceN(Guchar *x, GfxColor *deviceN);
1195 void getColor(Guchar *x, GfxColor *color);
1197 private:
1199 GfxImageColorMap(GfxImageColorMap *colorMap);
1201 GfxColorSpace *colorSpace; // the image color space
1202 int bits; // bits per component
1203 int nComps; // number of components in a pixel
1204 GfxColorSpace *colorSpace2; // secondary color space
1205 int nComps2; // number of components in colorSpace2
1206 GfxColorComp * // lookup table
1207 lookup[gfxColorMaxComps];
1208 GfxColorComp * // optimized case lookup table
1209 lookup2[gfxColorMaxComps];
1210 Guchar *byte_lookup;
1211 double // minimum values for each component
1212 decodeLow[gfxColorMaxComps];
1213 double // max - min value for each component
1214 decodeRange[gfxColorMaxComps];
1215 GBool ok;
1218 //------------------------------------------------------------------------
1219 // GfxSubpath and GfxPath
1220 //------------------------------------------------------------------------
1222 class GfxSubpath {
1223 public:
1225 // Constructor.
1226 GfxSubpath(double x1, double y1);
1228 // Destructor.
1229 ~GfxSubpath();
1231 // Copy.
1232 GfxSubpath *copy() { return new GfxSubpath(this); }
1234 // Get points.
1235 int getNumPoints() { return n; }
1236 double getX(int i) { return x[i]; }
1237 double getY(int i) { return y[i]; }
1238 GBool getCurve(int i) { return curve[i]; }
1240 void setX(int i, double a) { x[i] = a; }
1241 void setY(int i, double a) { y[i] = a; }
1243 // Get last point.
1244 double getLastX() { return x[n-1]; }
1245 double getLastY() { return y[n-1]; }
1247 // Add a line segment.
1248 void lineTo(double x1, double y1);
1250 // Add a Bezier curve.
1251 void curveTo(double x1, double y1, double x2, double y2,
1252 double x3, double y3);
1254 // Close the subpath.
1255 void close();
1256 GBool isClosed() { return closed; }
1258 // Add (<dx>, <dy>) to each point in the subpath.
1259 void offset(double dx, double dy);
1261 private:
1263 double *x, *y; // points
1264 GBool *curve; // curve[i] => point i is a control point
1265 // for a Bezier curve
1266 int n; // number of points
1267 int size; // size of x/y arrays
1268 GBool closed; // set if path is closed
1270 GfxSubpath(GfxSubpath *subpath);
1273 class GfxPath {
1274 public:
1276 // Constructor.
1277 GfxPath();
1279 // Destructor.
1280 ~GfxPath();
1282 // Copy.
1283 GfxPath *copy()
1284 { return new GfxPath(justMoved, firstX, firstY, subpaths, n, size); }
1286 // Is there a current point?
1287 GBool isCurPt() { return n > 0 || justMoved; }
1289 // Is the path non-empty, i.e., is there at least one segment?
1290 GBool isPath() { return n > 0; }
1292 // Get subpaths.
1293 int getNumSubpaths() { return n; }
1294 GfxSubpath *getSubpath(int i) { return subpaths[i]; }
1296 // Get last point on last subpath.
1297 double getLastX() { return subpaths[n-1]->getLastX(); }
1298 double getLastY() { return subpaths[n-1]->getLastY(); }
1300 // Move the current point.
1301 void moveTo(double x, double y);
1303 // Add a segment to the last subpath.
1304 void lineTo(double x, double y);
1306 // Add a Bezier curve to the last subpath
1307 void curveTo(double x1, double y1, double x2, double y2,
1308 double x3, double y3);
1310 // Close the last subpath.
1311 void close();
1313 // Append <path> to <this>.
1314 void append(GfxPath *path);
1316 // Add (<dx>, <dy>) to each point in the path.
1317 void offset(double dx, double dy);
1319 private:
1321 GBool justMoved; // set if a new subpath was just started
1322 double firstX, firstY; // first point in new subpath
1323 GfxSubpath **subpaths; // subpaths
1324 int n; // number of subpaths
1325 int size; // size of subpaths array
1327 GfxPath(GBool justMoved1, double firstX1, double firstY1,
1328 GfxSubpath **subpaths1, int n1, int size1);
1331 //------------------------------------------------------------------------
1332 // GfxState
1333 //------------------------------------------------------------------------
1335 class GfxState {
1336 public:
1338 * When GfxState::getReusablePath() is invoked, the currently active
1339 * path is taken per reference and its coordinates can be re-edited.
1341 * A ReusablePathIterator is intented to reduce overhead when the same
1342 * path type is used a lot of times, only with different coordinates. It
1343 * allows just to update the coordinates (occuring in the same order as
1344 * in the original path).
1346 class ReusablePathIterator {
1347 public:
1349 * Creates the ReusablePathIterator. This should only be done from
1350 * GfxState::getReusablePath().
1352 * @param path the path as it is used so far. Changing this path,
1353 * deleting it or starting a new path from scratch will most likely
1354 * invalidate the iterator (and may cause serious problems). Make
1355 * sure the path's memory structure is not changed during the
1356 * lifetime of the ReusablePathIterator.
1358 ReusablePathIterator( GfxPath* path );
1361 * Returns true if and only if the current iterator position is
1362 * beyond the last valid point.
1364 * A call to setCoord() will be undefined.
1366 bool isEnd() const;
1369 * Advances the iterator.
1371 void next();
1374 * Updates the coordinates associated to the current iterator
1375 * position.
1377 void setCoord( double x, double y );
1380 * Resets the iterator.
1382 void reset();
1383 private:
1384 GfxPath *path;
1385 int subPathOff;
1387 int coordOff;
1388 int numCoords;
1390 GfxSubpath *curSubPath;
1393 // Construct a default GfxState, for a device with resolution <hDPI>
1394 // x <vDPI>, page box <pageBox>, page rotation <rotateA>, and
1395 // coordinate system specified by <upsideDown>.
1396 GfxState(double hDPIA, double vDPIA, PDFRectangle *pageBox,
1397 int rotateA, GBool upsideDown);
1399 // Destructor.
1400 ~GfxState();
1402 // Copy.
1403 GfxState *copy(GBool copyPath = gFalse)
1404 { return new GfxState(this, copyPath); }
1406 // Accessors.
1407 double getHDPI() { return hDPI; }
1408 double getVDPI() { return vDPI; }
1409 double *getCTM() { return ctm; }
1410 void getCTM(Matrix *m) { memcpy (m->m, ctm, sizeof m->m); }
1411 double getX1() { return px1; }
1412 double getY1() { return py1; }
1413 double getX2() { return px2; }
1414 double getY2() { return py2; }
1415 double getPageWidth() { return pageWidth; }
1416 double getPageHeight() { return pageHeight; }
1417 int getRotate() { return rotate; }
1418 GfxColor *getFillColor() { return &fillColor; }
1419 GfxColor *getStrokeColor() { return &strokeColor; }
1420 void getFillGray(GfxGray *gray)
1421 { fillColorSpace->getGray(&fillColor, gray); }
1422 void getStrokeGray(GfxGray *gray)
1423 { strokeColorSpace->getGray(&strokeColor, gray); }
1424 void getFillRGB(GfxRGB *rgb)
1425 { fillColorSpace->getRGB(&fillColor, rgb); }
1426 void getStrokeRGB(GfxRGB *rgb)
1427 { strokeColorSpace->getRGB(&strokeColor, rgb); }
1428 void getFillCMYK(GfxCMYK *cmyk)
1429 { fillColorSpace->getCMYK(&fillColor, cmyk); }
1430 void getFillDeviceN(GfxColor *deviceN)
1431 { fillColorSpace->getDeviceN(&fillColor, deviceN); }
1432 void getStrokeCMYK(GfxCMYK *cmyk)
1433 { strokeColorSpace->getCMYK(&strokeColor, cmyk); }
1434 void getStrokeDeviceN(GfxColor *deviceN)
1435 { strokeColorSpace->getDeviceN(&strokeColor, deviceN); }
1436 GfxColorSpace *getFillColorSpace() { return fillColorSpace; }
1437 GfxColorSpace *getStrokeColorSpace() { return strokeColorSpace; }
1438 GfxPattern *getFillPattern() { return fillPattern; }
1439 GfxPattern *getStrokePattern() { return strokePattern; }
1440 GfxBlendMode getBlendMode() { return blendMode; }
1441 double getFillOpacity() { return fillOpacity; }
1442 double getStrokeOpacity() { return strokeOpacity; }
1443 GBool getFillOverprint() { return fillOverprint; }
1444 GBool getStrokeOverprint() { return strokeOverprint; }
1445 int getOverprintMode() { return overprintMode; }
1446 Function **getTransfer() { return transfer; }
1447 double getLineWidth() { return lineWidth; }
1448 void getLineDash(double **dash, int *length, double *start)
1449 { *dash = lineDash; *length = lineDashLength; *start = lineDashStart; }
1450 int getFlatness() { return flatness; }
1451 int getLineJoin() { return lineJoin; }
1452 int getLineCap() { return lineCap; }
1453 double getMiterLimit() { return miterLimit; }
1454 GBool getStrokeAdjust() { return strokeAdjust; }
1455 GBool getAlphaIsShape() { return alphaIsShape; }
1456 GBool getTextKnockout() { return textKnockout; }
1457 GfxFont *getFont() { return font; }
1458 double getFontSize() { return fontSize; }
1459 double *getTextMat() { return textMat; }
1460 double getCharSpace() { return charSpace; }
1461 double getWordSpace() { return wordSpace; }
1462 double getHorizScaling() { return horizScaling; }
1463 double getLeading() { return leading; }
1464 double getRise() { return rise; }
1465 int getRender() { return render; }
1466 char *getRenderingIntent() { return renderingIntent; }
1467 GfxPath *getPath() { return path; }
1468 void setPath(GfxPath *pathA);
1469 double getCurX() { return curX; }
1470 double getCurY() { return curY; }
1471 void getClipBBox(double *xMin, double *yMin, double *xMax, double *yMax)
1472 { *xMin = clipXMin; *yMin = clipYMin; *xMax = clipXMax; *yMax = clipYMax; }
1473 void getUserClipBBox(double *xMin, double *yMin, double *xMax, double *yMax);
1474 double getLineX() { return lineX; }
1475 double getLineY() { return lineY; }
1477 // Is there a current point/path?
1478 GBool isCurPt() { return path->isCurPt(); }
1479 GBool isPath() { return path->isPath(); }
1481 // Transforms.
1482 void transform(double x1, double y1, double *x2, double *y2)
1483 { *x2 = ctm[0] * x1 + ctm[2] * y1 + ctm[4];
1484 *y2 = ctm[1] * x1 + ctm[3] * y1 + ctm[5]; }
1485 void transformDelta(double x1, double y1, double *x2, double *y2)
1486 { *x2 = ctm[0] * x1 + ctm[2] * y1;
1487 *y2 = ctm[1] * x1 + ctm[3] * y1; }
1488 void textTransform(double x1, double y1, double *x2, double *y2)
1489 { *x2 = textMat[0] * x1 + textMat[2] * y1 + textMat[4];
1490 *y2 = textMat[1] * x1 + textMat[3] * y1 + textMat[5]; }
1491 void textTransformDelta(double x1, double y1, double *x2, double *y2)
1492 { *x2 = textMat[0] * x1 + textMat[2] * y1;
1493 *y2 = textMat[1] * x1 + textMat[3] * y1; }
1494 double transformWidth(double w);
1495 double getTransformedLineWidth()
1496 { return transformWidth(lineWidth); }
1497 double getTransformedFontSize();
1498 void getFontTransMat(double *m11, double *m12, double *m21, double *m22);
1500 // Change state parameters.
1501 void setCTM(double a, double b, double c,
1502 double d, double e, double f);
1503 void concatCTM(double a, double b, double c,
1504 double d, double e, double f);
1505 void shiftCTMAndClip(double tx, double ty);
1506 void setFillColorSpace(GfxColorSpace *colorSpace);
1507 void setStrokeColorSpace(GfxColorSpace *colorSpace);
1508 void setFillColor(GfxColor *color) { fillColor = *color; }
1509 void setStrokeColor(GfxColor *color) { strokeColor = *color; }
1510 void setFillPattern(GfxPattern *pattern);
1511 void setStrokePattern(GfxPattern *pattern);
1512 void setBlendMode(GfxBlendMode mode) { blendMode = mode; }
1513 void setFillOpacity(double opac) { fillOpacity = opac; }
1514 void setStrokeOpacity(double opac) { strokeOpacity = opac; }
1515 void setFillOverprint(GBool op) { fillOverprint = op; }
1516 void setStrokeOverprint(GBool op) { strokeOverprint = op; }
1517 void setOverprintMode(int op) { overprintMode = op; }
1518 void setTransfer(Function **funcs);
1519 void setLineWidth(double width) { lineWidth = width; }
1520 void setLineDash(double *dash, int length, double start);
1521 void setFlatness(int flatness1) { flatness = flatness1; }
1522 void setLineJoin(int lineJoin1) { lineJoin = lineJoin1; }
1523 void setLineCap(int lineCap1) { lineCap = lineCap1; }
1524 void setMiterLimit(double limit) { miterLimit = limit; }
1525 void setStrokeAdjust(GBool sa) { strokeAdjust = sa; }
1526 void setAlphaIsShape(GBool ais) { alphaIsShape = ais; }
1527 void setTextKnockout(GBool tk) { textKnockout = tk; }
1528 void setFont(GfxFont *fontA, double fontSizeA);
1529 void setTextMat(double a, double b, double c,
1530 double d, double e, double f)
1531 { textMat[0] = a; textMat[1] = b; textMat[2] = c;
1532 textMat[3] = d; textMat[4] = e; textMat[5] = f; }
1533 void setCharSpace(double space)
1534 { charSpace = space; }
1535 void setWordSpace(double space)
1536 { wordSpace = space; }
1537 void setHorizScaling(double scale)
1538 { horizScaling = 0.01 * scale; }
1539 void setLeading(double leadingA)
1540 { leading = leadingA; }
1541 void setRise(double riseA)
1542 { rise = riseA; }
1543 void setRender(int renderA)
1544 { render = renderA; }
1545 void setRenderingIntent(const char *intent)
1546 { strncpy(renderingIntent, intent, 31); }
1548 #ifdef USE_CMS
1549 void setDisplayProfile(void *localDisplayProfileA);
1550 void *getDisplayProfile() { return localDisplayProfile; }
1551 GfxColorTransform *getXYZ2DisplayTransform();
1552 #endif
1554 // Add to path.
1555 void moveTo(double x, double y)
1556 { path->moveTo(curX = x, curY = y); }
1557 void lineTo(double x, double y)
1558 { path->lineTo(curX = x, curY = y); }
1559 void curveTo(double x1, double y1, double x2, double y2,
1560 double x3, double y3)
1561 { path->curveTo(x1, y1, x2, y2, curX = x3, curY = y3); }
1562 void closePath()
1563 { path->close(); curX = path->getLastX(); curY = path->getLastY(); }
1564 void clearPath();
1566 // Update clip region.
1567 void clip();
1568 void clipToStrokePath();
1569 void clipToRect(double xMin, double yMin, double xMax, double yMax);
1571 // Text position.
1572 void textSetPos(double tx, double ty) { lineX = tx; lineY = ty; }
1573 void textMoveTo(double tx, double ty)
1574 { lineX = tx; lineY = ty; textTransform(tx, ty, &curX, &curY); }
1575 void textShift(double tx, double ty);
1576 void shift(double dx, double dy);
1578 // Push/pop GfxState on/off stack.
1579 GfxState *save();
1580 GfxState *restore();
1581 GBool hasSaves() { return saved != NULL; }
1582 GBool isParentState(GfxState *state) { return saved == state || (saved && saved->isParentState(state)); }
1584 // Misc
1585 GBool parseBlendMode(Object *obj, GfxBlendMode *mode);
1587 ReusablePathIterator *getReusablePath() { return new ReusablePathIterator(path); }
1588 private:
1590 double hDPI, vDPI; // resolution
1591 double ctm[6]; // coord transform matrix
1592 double px1, py1, px2, py2; // page corners (user coords)
1593 double pageWidth, pageHeight; // page size (pixels)
1594 int rotate; // page rotation angle
1596 GfxColorSpace *fillColorSpace; // fill color space
1597 GfxColorSpace *strokeColorSpace; // stroke color space
1598 GfxColor fillColor; // fill color
1599 GfxColor strokeColor; // stroke color
1600 GfxPattern *fillPattern; // fill pattern
1601 GfxPattern *strokePattern; // stroke pattern
1602 GfxBlendMode blendMode; // transparency blend mode
1603 double fillOpacity; // fill opacity
1604 double strokeOpacity; // stroke opacity
1605 GBool fillOverprint; // fill overprint
1606 GBool strokeOverprint; // stroke overprint
1607 int overprintMode; // overprint mode
1608 Function *transfer[4]; // transfer function (entries may be: all
1609 // NULL = identity; last three NULL =
1610 // single function; all four non-NULL =
1611 // R,G,B,gray functions)
1613 double lineWidth; // line width
1614 double *lineDash; // line dash
1615 int lineDashLength;
1616 double lineDashStart;
1617 int flatness; // curve flatness
1618 int lineJoin; // line join style
1619 int lineCap; // line cap style
1620 double miterLimit; // line miter limit
1621 GBool strokeAdjust; // stroke adjustment
1622 GBool alphaIsShape; // alpha is shape
1623 GBool textKnockout; // text knockout
1625 GfxFont *font; // font
1626 double fontSize; // font size
1627 double textMat[6]; // text matrix
1628 double charSpace; // character spacing
1629 double wordSpace; // word spacing
1630 double horizScaling; // horizontal scaling
1631 double leading; // text leading
1632 double rise; // text rise
1633 int render; // text rendering mode
1635 GfxPath *path; // array of path elements
1636 double curX, curY; // current point (user coords)
1637 double lineX, lineY; // start of current text line (text coords)
1639 double clipXMin, clipYMin, // bounding box for clip region
1640 clipXMax, clipYMax;
1641 char renderingIntent[32];
1643 GfxState *saved; // next GfxState on stack
1645 GfxState(GfxState *state, GBool copyPath);
1647 #ifdef USE_CMS
1648 void *localDisplayProfile;
1649 int displayProfileRef;
1650 GfxColorTransform *XYZ2DisplayTransformRelCol;
1651 GfxColorTransform *XYZ2DisplayTransformAbsCol;
1652 GfxColorTransform *XYZ2DisplayTransformSat;
1653 GfxColorTransform *XYZ2DisplayTransformPerc;
1654 #endif
1657 #endif