a patch for ttc fonts with bad index
[luatex.git] / source / libs / poppler / poppler-0.36.0 / poppler / GfxState.h
blobf018e93dd341ba79d5794414f7c3b6597d7b4a7f
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>
26 // To see a description of the changes please see the Changelog file that
27 // came with your tarball or type make ChangeLog if you are building from git
29 //========================================================================
31 #ifndef GFXSTATE_H
32 #define GFXSTATE_H
34 #ifdef USE_GCC_PRAGMAS
35 #pragma interface
36 #endif
38 #include "poppler-config.h"
40 #include "goo/gtypes.h"
41 #include "Object.h"
42 #include "Function.h"
44 #include <assert.h>
45 #include <map>
47 class Array;
48 class Gfx;
49 class GfxFont;
50 class PDFRectangle;
51 class GfxShading;
52 class PopplerCache;
53 class GooList;
54 class OutputDev;
55 class GfxState;
56 class GfxResources;
58 class Matrix {
59 public:
60 double m[6];
62 GBool invertTo(Matrix *other) const;
63 void transform(double x, double y, double *tx, double *ty) const;
64 double determinant() const { return m[0] * m[3] - m[1] * m[2]; }
65 double norm() const;
68 //------------------------------------------------------------------------
69 // GfxBlendMode
70 //------------------------------------------------------------------------
72 enum GfxBlendMode {
73 gfxBlendNormal,
74 gfxBlendMultiply,
75 gfxBlendScreen,
76 gfxBlendOverlay,
77 gfxBlendDarken,
78 gfxBlendLighten,
79 gfxBlendColorDodge,
80 gfxBlendColorBurn,
81 gfxBlendHardLight,
82 gfxBlendSoftLight,
83 gfxBlendDifference,
84 gfxBlendExclusion,
85 gfxBlendHue,
86 gfxBlendSaturation,
87 gfxBlendColor,
88 gfxBlendLuminosity
91 //------------------------------------------------------------------------
92 // GfxColorComp
93 //------------------------------------------------------------------------
95 // 16.16 fixed point color component
96 typedef int GfxColorComp;
98 #define gfxColorComp1 0x10000
100 static inline GfxColorComp dblToCol(double x) {
101 return (GfxColorComp)(x * gfxColorComp1);
104 static inline double colToDbl(GfxColorComp x) {
105 return (double)x / (double)gfxColorComp1;
108 static inline Guchar dblToByte(double x) {
109 return (x * 255.0);
112 static inline double byteToDbl(Guchar x) {
113 return (double)x / (double)255.0;
116 static inline GfxColorComp byteToCol(Guchar x) {
117 // (x / 255) << 16 = (0.0000000100000001... * x) << 16
118 // = ((x << 8) + (x) + (x >> 8) + ...) << 16
119 // = (x << 8) + (x) + (x >> 7)
120 // [for rounding]
121 return (GfxColorComp)((x << 8) + x + (x >> 7));
124 static inline Guchar colToByte(GfxColorComp x) {
125 // 255 * x + 0.5 = 256 * x - x + 0x8000
126 return (Guchar)(((x << 8) - x + 0x8000) >> 16);
129 //------------------------------------------------------------------------
130 // GfxColor
131 //------------------------------------------------------------------------
133 #define gfxColorMaxComps funcMaxOutputs
135 struct GfxColor {
136 GfxColorComp c[gfxColorMaxComps];
139 //------------------------------------------------------------------------
140 // GfxGray
141 //------------------------------------------------------------------------
143 typedef GfxColorComp GfxGray;
145 //------------------------------------------------------------------------
146 // GfxRGB
147 //------------------------------------------------------------------------
149 struct GfxRGB {
150 GfxColorComp r, g, b;
153 //------------------------------------------------------------------------
154 // GfxCMYK
155 //------------------------------------------------------------------------
157 struct GfxCMYK {
158 GfxColorComp c, m, y, k;
161 //------------------------------------------------------------------------
162 // GfxColorSpace
163 //------------------------------------------------------------------------
165 // NB: The nGfxColorSpaceModes constant and the gfxColorSpaceModeNames
166 // array defined in GfxState.cc must match this enum.
167 enum GfxColorSpaceMode {
168 csDeviceGray,
169 csCalGray,
170 csDeviceRGB,
171 csCalRGB,
172 csDeviceCMYK,
173 csLab,
174 csICCBased,
175 csIndexed,
176 csSeparation,
177 csDeviceN,
178 csPattern
181 // wrapper of cmsHTRANSFORM to copy
182 class GfxColorTransform {
183 public:
184 void doTransform(void *in, void *out, unsigned int size);
185 // transformA should be a cmsHTRANSFORM
186 GfxColorTransform(void *transformA, int cmsIntent, unsigned int inputPixelType, unsigned int transformPixelType);
187 ~GfxColorTransform();
188 int getIntent() { return cmsIntent; }
189 int getInputPixelType() { return inputPixelType; }
190 int getTransformPixelType() { return transformPixelType; }
191 void ref();
192 unsigned int unref();
193 private:
194 GfxColorTransform() {}
195 void *transform;
196 unsigned int refCount;
197 int cmsIntent;
198 unsigned int inputPixelType;
199 unsigned int transformPixelType;
202 class GfxColorSpace {
203 public:
205 GfxColorSpace();
206 virtual ~GfxColorSpace();
207 virtual GfxColorSpace *copy() = 0;
208 virtual GfxColorSpaceMode getMode() = 0;
210 // Construct a color space. Returns NULL if unsuccessful.
211 static GfxColorSpace *parse(GfxResources *res, Object *csObj, OutputDev *out, GfxState *state, int recursion = 0);
213 // Convert to gray, RGB, or CMYK.
214 virtual void getGray(GfxColor *color, GfxGray *gray) = 0;
215 virtual void getRGB(GfxColor *color, GfxRGB *rgb) = 0;
216 virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk) = 0;
217 virtual void getDeviceN(GfxColor *color, GfxColor *deviceN) = 0;
218 virtual void getGrayLine(Guchar * /*in*/, Guchar * /*out*/, int /*length*/) { error(errInternal, -1, "GfxColorSpace::getGrayLine this should not happen"); }
219 virtual void getRGBLine(Guchar * /*in*/, unsigned int * /*out*/, int /*length*/) { error(errInternal, -1, "GfxColorSpace::getRGBLine (first variant) this should not happen"); }
220 virtual void getRGBLine(Guchar * /*in*/, Guchar * /*out*/, int /*length*/) { error(errInternal, -1, "GfxColorSpace::getRGBLine (second variant) this should not happen"); }
221 virtual void getRGBXLine(Guchar * /*in*/, Guchar * /*out*/, int /*length*/) { error(errInternal, -1, "GfxColorSpace::getRGBXLine this should not happen"); }
222 virtual void getCMYKLine(Guchar * /*in*/, Guchar * /*out*/, int /*length*/) { error(errInternal, -1, "GfxColorSpace::getCMYKLine this should not happen"); }
223 virtual void getDeviceNLine(Guchar * /*in*/, Guchar * /*out*/, int /*length*/) { error(errInternal, -1, "GfxColorSpace::getDeviceNLine this should not happen"); }
225 // create mapping for spot colorants
226 virtual void createMapping(GooList *separationList, int maxSepComps);
228 // Does this ColorSpace support getRGBLine?
229 virtual GBool useGetRGBLine() { return gFalse; }
230 // Does this ColorSpace support getGrayLine?
231 virtual GBool useGetGrayLine() { return gFalse; }
232 // Does this ColorSpace support getCMYKLine?
233 virtual GBool useGetCMYKLine() { return gFalse; }
234 // Does this ColorSpace support getDeviceNLine?
235 virtual GBool useGetDeviceNLine() { return gFalse; }
237 // Return the number of color components.
238 virtual int getNComps() = 0;
240 // Get this color space's default color.
241 virtual void getDefaultColor(GfxColor *color) = 0;
243 // Return the default ranges for each component, assuming an image
244 // with a max pixel value of <maxImgPixel>.
245 virtual void getDefaultRanges(double *decodeLow, double *decodeRange,
246 int maxImgPixel);
248 // Returns true if painting operations in this color space never
249 // mark the page (e.g., the "None" colorant).
250 virtual GBool isNonMarking() { return gFalse; }
252 // Return the color space's overprint mask.
253 Guint getOverprintMask() { return overprintMask; }
255 // Return the number of color space modes
256 static int getNumColorSpaceModes();
258 // Return the name of the <idx>th color space mode.
259 static const char *getColorSpaceModeName(int idx);
261 #ifdef USE_CMS
262 static int setupColorProfiles();
263 // displayProfileA should be a cmsHPROFILE
264 static void setDisplayProfile(void *displayProfileA);
265 static void setDisplayProfileName(GooString *name);
266 // result will be a cmsHPROFILE
267 static void *getRGBProfile();
268 // result will be a cmsHPROFILE
269 static void *getDisplayProfile();
270 #endif
271 protected:
273 Guint overprintMask;
274 int *mapping;
277 //------------------------------------------------------------------------
278 // GfxDeviceGrayColorSpace
279 //------------------------------------------------------------------------
281 class GfxDeviceGrayColorSpace: public GfxColorSpace {
282 public:
284 GfxDeviceGrayColorSpace();
285 virtual ~GfxDeviceGrayColorSpace();
286 virtual GfxColorSpace *copy();
287 virtual GfxColorSpaceMode getMode() { return csDeviceGray; }
289 virtual void getGray(GfxColor *color, GfxGray *gray);
290 virtual void getRGB(GfxColor *color, GfxRGB *rgb);
291 virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
292 virtual void getDeviceN(GfxColor *color, GfxColor *deviceN);
293 virtual void getGrayLine(Guchar *in, Guchar *out, int length);
294 virtual void getRGBLine(Guchar *in, unsigned int *out, int length);
295 virtual void getRGBLine(Guchar *in, Guchar *out, int length);
296 virtual void getRGBXLine(Guchar *in, Guchar *out, int length);
297 virtual void getCMYKLine(Guchar *in, Guchar *out, int length);
298 virtual void getDeviceNLine(Guchar *in, Guchar *out, int length);
300 virtual GBool useGetRGBLine() { return gTrue; }
301 virtual GBool useGetGrayLine() { return gTrue; }
302 virtual GBool useGetCMYKLine() { return gTrue; }
303 virtual GBool useGetDeviceNLine() { return gTrue; }
305 virtual int getNComps() { return 1; }
306 virtual void getDefaultColor(GfxColor *color);
308 private:
311 //------------------------------------------------------------------------
312 // GfxCalGrayColorSpace
313 //------------------------------------------------------------------------
315 class GfxCalGrayColorSpace: public GfxColorSpace {
316 public:
318 GfxCalGrayColorSpace();
319 virtual ~GfxCalGrayColorSpace();
320 virtual GfxColorSpace *copy();
321 virtual GfxColorSpaceMode getMode() { return csCalGray; }
323 // Construct a CalGray color space. Returns NULL if unsuccessful.
324 static GfxColorSpace *parse(Array *arr, GfxState *state);
326 virtual void getGray(GfxColor *color, GfxGray *gray);
327 virtual void getRGB(GfxColor *color, GfxRGB *rgb);
328 virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
329 virtual void getDeviceN(GfxColor *color, GfxColor *deviceN);
331 virtual int getNComps() { return 1; }
332 virtual void getDefaultColor(GfxColor *color);
334 // CalGray-specific access.
335 double getWhiteX() { return whiteX; }
336 double getWhiteY() { return whiteY; }
337 double getWhiteZ() { return whiteZ; }
338 double getBlackX() { return blackX; }
339 double getBlackY() { return blackY; }
340 double getBlackZ() { return blackZ; }
341 double getGamma() { return gamma; }
343 private:
345 double whiteX, whiteY, whiteZ; // white point
346 double blackX, blackY, blackZ; // black point
347 double gamma; // gamma value
348 double kr, kg, kb; // gamut mapping mulitpliers
349 void getXYZ(GfxColor *color, double *pX, double *pY, double *pZ);
350 #ifdef USE_CMS
351 GfxColorTransform *transform;
352 #endif
355 //------------------------------------------------------------------------
356 // GfxDeviceRGBColorSpace
357 //------------------------------------------------------------------------
359 class GfxDeviceRGBColorSpace: public GfxColorSpace {
360 public:
362 GfxDeviceRGBColorSpace();
363 virtual ~GfxDeviceRGBColorSpace();
364 virtual GfxColorSpace *copy();
365 virtual GfxColorSpaceMode getMode() { return csDeviceRGB; }
367 virtual void getGray(GfxColor *color, GfxGray *gray);
368 virtual void getRGB(GfxColor *color, GfxRGB *rgb);
369 virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
370 virtual void getDeviceN(GfxColor *color, GfxColor *deviceN);
371 virtual void getGrayLine(Guchar *in, Guchar *out, int length);
372 virtual void getRGBLine(Guchar *in, unsigned int *out, int length);
373 virtual void getRGBLine(Guchar *in, Guchar *out, int length);
374 virtual void getRGBXLine(Guchar *in, Guchar *out, int length);
375 virtual void getCMYKLine(Guchar *in, Guchar *out, int length);
376 virtual void getDeviceNLine(Guchar *in, Guchar *out, int length);
378 virtual GBool useGetRGBLine() { return gTrue; }
379 virtual GBool useGetGrayLine() { return gTrue; }
380 virtual GBool useGetCMYKLine() { return gTrue; }
381 virtual GBool useGetDeviceNLine() { return gTrue; }
383 virtual int getNComps() { return 3; }
384 virtual void getDefaultColor(GfxColor *color);
386 private:
389 //------------------------------------------------------------------------
390 // GfxCalRGBColorSpace
391 //------------------------------------------------------------------------
393 class GfxCalRGBColorSpace: public GfxColorSpace {
394 public:
396 GfxCalRGBColorSpace();
397 virtual ~GfxCalRGBColorSpace();
398 virtual GfxColorSpace *copy();
399 virtual GfxColorSpaceMode getMode() { return csCalRGB; }
401 // Construct a CalRGB color space. Returns NULL if unsuccessful.
402 static GfxColorSpace *parse(Array *arr, GfxState *state);
404 virtual void getGray(GfxColor *color, GfxGray *gray);
405 virtual void getRGB(GfxColor *color, GfxRGB *rgb);
406 virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
407 virtual void getDeviceN(GfxColor *color, GfxColor *deviceN);
409 virtual int getNComps() { return 3; }
410 virtual void getDefaultColor(GfxColor *color);
412 // CalRGB-specific access.
413 double getWhiteX() { return whiteX; }
414 double getWhiteY() { return whiteY; }
415 double getWhiteZ() { return whiteZ; }
416 double getBlackX() { return blackX; }
417 double getBlackY() { return blackY; }
418 double getBlackZ() { return blackZ; }
419 double getGammaR() { return gammaR; }
420 double getGammaG() { return gammaG; }
421 double getGammaB() { return gammaB; }
422 double *getMatrix() { return mat; }
424 private:
426 double whiteX, whiteY, whiteZ; // white point
427 double blackX, blackY, blackZ; // black point
428 double gammaR, gammaG, gammaB; // gamma values
429 double mat[9]; // ABC -> XYZ transform matrix
430 double kr, kg, kb; // gamut mapping mulitpliers
431 void getXYZ(GfxColor *color, double *pX, double *pY, double *pZ);
432 #ifdef USE_CMS
433 GfxColorTransform *transform;
434 #endif
437 //------------------------------------------------------------------------
438 // GfxDeviceCMYKColorSpace
439 //------------------------------------------------------------------------
441 class GfxDeviceCMYKColorSpace: public GfxColorSpace {
442 public:
444 GfxDeviceCMYKColorSpace();
445 virtual ~GfxDeviceCMYKColorSpace();
446 virtual GfxColorSpace *copy();
447 virtual GfxColorSpaceMode getMode() { return csDeviceCMYK; }
449 virtual void getGray(GfxColor *color, GfxGray *gray);
450 virtual void getRGB(GfxColor *color, GfxRGB *rgb);
451 virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
452 virtual void getDeviceN(GfxColor *color, GfxColor *deviceN);
453 virtual void getRGBLine(Guchar *in, unsigned int *out, int length);
454 virtual void getRGBLine(Guchar *, Guchar *out, int length);
455 virtual void getRGBXLine(Guchar *in, Guchar *out, int length);
456 virtual void getCMYKLine(Guchar *in, Guchar *out, int length);
457 virtual void getDeviceNLine(Guchar *in, Guchar *out, int length);
458 virtual GBool useGetRGBLine() { return gTrue; }
459 virtual GBool useGetCMYKLine() { return gTrue; }
460 virtual GBool useGetDeviceNLine() { return gTrue; }
462 virtual int getNComps() { return 4; }
463 virtual void getDefaultColor(GfxColor *color);
465 private:
468 //------------------------------------------------------------------------
469 // GfxLabColorSpace
470 //------------------------------------------------------------------------
472 class GfxLabColorSpace: public GfxColorSpace {
473 public:
475 GfxLabColorSpace();
476 virtual ~GfxLabColorSpace();
477 virtual GfxColorSpace *copy();
478 virtual GfxColorSpaceMode getMode() { return csLab; }
480 // Construct a Lab color space. Returns NULL if unsuccessful.
481 static GfxColorSpace *parse(Array *arr, GfxState *state);
483 virtual void getGray(GfxColor *color, GfxGray *gray);
484 virtual void getRGB(GfxColor *color, GfxRGB *rgb);
485 virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
486 virtual void getDeviceN(GfxColor *color, GfxColor *deviceN);
488 virtual int getNComps() { return 3; }
489 virtual void getDefaultColor(GfxColor *color);
491 virtual void getDefaultRanges(double *decodeLow, double *decodeRange,
492 int maxImgPixel);
494 // Lab-specific access.
495 double getWhiteX() { return whiteX; }
496 double getWhiteY() { return whiteY; }
497 double getWhiteZ() { return whiteZ; }
498 double getBlackX() { return blackX; }
499 double getBlackY() { return blackY; }
500 double getBlackZ() { return blackZ; }
501 double getAMin() { return aMin; }
502 double getAMax() { return aMax; }
503 double getBMin() { return bMin; }
504 double getBMax() { return bMax; }
506 private:
508 double whiteX, whiteY, whiteZ; // white point
509 double blackX, blackY, blackZ; // black point
510 double aMin, aMax, bMin, bMax; // range for the a and b components
511 double kr, kg, kb; // gamut mapping mulitpliers
512 void getXYZ(GfxColor *color, double *pX, double *pY, double *pZ);
513 #ifdef USE_CMS
514 GfxColorTransform *transform;
515 #endif
518 //------------------------------------------------------------------------
519 // GfxICCBasedColorSpace
520 //------------------------------------------------------------------------
522 class GfxICCBasedColorSpace: public GfxColorSpace {
523 public:
525 GfxICCBasedColorSpace(int nCompsA, GfxColorSpace *altA,
526 Ref *iccProfileStreamA);
527 virtual ~GfxICCBasedColorSpace();
528 virtual GfxColorSpace *copy();
529 virtual GfxColorSpaceMode getMode() { return csICCBased; }
531 // Construct an ICCBased color space. Returns NULL if unsuccessful.
532 static GfxColorSpace *parse(Array *arr, OutputDev *out, GfxState *state, int recursion);
534 virtual void getGray(GfxColor *color, GfxGray *gray);
535 virtual void getRGB(GfxColor *color, GfxRGB *rgb);
536 virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
537 virtual void getDeviceN(GfxColor *color, GfxColor *deviceN);
538 virtual void getRGBLine(Guchar *in, unsigned int *out, int length);
539 virtual void getRGBLine(Guchar *in, Guchar *out, int length);
540 virtual void getRGBXLine(Guchar *in, Guchar *out, int length);
541 virtual void getCMYKLine(Guchar *in, Guchar *out, int length);
542 virtual void getDeviceNLine(Guchar *in, Guchar *out, int length);
544 virtual GBool useGetRGBLine();
545 virtual GBool useGetCMYKLine();
546 virtual GBool useGetDeviceNLine();
548 virtual int getNComps() { return nComps; }
549 virtual void getDefaultColor(GfxColor *color);
551 virtual void getDefaultRanges(double *decodeLow, double *decodeRange,
552 int maxImgPixel);
554 // ICCBased-specific access.
555 GfxColorSpace *getAlt() { return alt; }
557 private:
559 int nComps; // number of color components (1, 3, or 4)
560 GfxColorSpace *alt; // alternate color space
561 double rangeMin[4]; // min values for each component
562 double rangeMax[4]; // max values for each component
563 Ref iccProfileStream; // the ICC profile
564 #ifdef USE_CMS
565 int getIntent() { return (transform != NULL) ? transform->getIntent() : 0; }
566 GfxColorTransform *transform;
567 GfxColorTransform *lineTransform; // color transform for line
568 std::map<unsigned int, unsigned int> cmsCache;
569 #endif
571 //------------------------------------------------------------------------
572 // GfxIndexedColorSpace
573 //------------------------------------------------------------------------
575 class GfxIndexedColorSpace: public GfxColorSpace {
576 public:
578 GfxIndexedColorSpace(GfxColorSpace *baseA, int indexHighA);
579 virtual ~GfxIndexedColorSpace();
580 virtual GfxColorSpace *copy();
581 virtual GfxColorSpaceMode getMode() { return csIndexed; }
583 // Construct an Indexed color space. Returns NULL if unsuccessful.
584 static GfxColorSpace *parse(GfxResources *res, Array *arr, OutputDev *out, GfxState *state, int recursion);
586 virtual void getGray(GfxColor *color, GfxGray *gray);
587 virtual void getRGB(GfxColor *color, GfxRGB *rgb);
588 virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
589 virtual void getDeviceN(GfxColor *color, GfxColor *deviceN);
590 virtual void getRGBLine(Guchar *in, unsigned int *out, int length);
591 virtual void getRGBLine(Guchar *in, Guchar *out, int length);
592 virtual void getRGBXLine(Guchar *in, Guchar *out, int length);
593 virtual void getCMYKLine(Guchar *in, Guchar *out, int length);
594 virtual void getDeviceNLine(Guchar *in, Guchar *out, int length);
596 virtual GBool useGetRGBLine() { return gTrue; }
597 virtual GBool useGetCMYKLine() { return gTrue; }
598 virtual GBool useGetDeviceNLine() { return gTrue; }
600 virtual int getNComps() { return 1; }
601 virtual void getDefaultColor(GfxColor *color);
603 virtual void getDefaultRanges(double *decodeLow, double *decodeRange,
604 int maxImgPixel);
606 // Indexed-specific access.
607 GfxColorSpace *getBase() { return base; }
608 int getIndexHigh() { return indexHigh; }
609 Guchar *getLookup() { return lookup; }
610 GfxColor *mapColorToBase(GfxColor *color, GfxColor *baseColor);
611 Guint getOverprintMask() { return base->getOverprintMask(); }
612 virtual void createMapping(GooList *separationList, int maxSepComps)
613 { base->createMapping(separationList, maxSepComps); }
616 private:
618 GfxColorSpace *base; // base color space
619 int indexHigh; // max pixel value
620 Guchar *lookup; // lookup table
623 //------------------------------------------------------------------------
624 // GfxSeparationColorSpace
625 //------------------------------------------------------------------------
627 class GfxSeparationColorSpace: public GfxColorSpace {
628 public:
630 GfxSeparationColorSpace(GooString *nameA, GfxColorSpace *altA,
631 Function *funcA);
632 virtual ~GfxSeparationColorSpace();
633 virtual GfxColorSpace *copy();
634 virtual GfxColorSpaceMode getMode() { return csSeparation; }
636 // Construct a Separation color space. Returns NULL if unsuccessful.
637 static GfxColorSpace *parse(GfxResources *res, Array *arr, OutputDev *out, GfxState *state, int recursion);
639 virtual void getGray(GfxColor *color, GfxGray *gray);
640 virtual void getRGB(GfxColor *color, GfxRGB *rgb);
641 virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
642 virtual void getDeviceN(GfxColor *color, GfxColor *deviceN);
644 virtual void createMapping(GooList *separationList, int maxSepComps);
646 virtual int getNComps() { return 1; }
647 virtual void getDefaultColor(GfxColor *color);
649 virtual GBool isNonMarking() { return nonMarking; }
651 // Separation-specific access.
652 GooString *getName() { return name; }
653 GfxColorSpace *getAlt() { return alt; }
654 Function *getFunc() { return func; }
656 private:
658 GfxSeparationColorSpace(GooString *nameA, GfxColorSpace *altA,
659 Function *funcA, GBool nonMarkingA,
660 Guint overprintMaskA, int *mappingA);
662 GooString *name; // colorant name
663 GfxColorSpace *alt; // alternate color space
664 Function *func; // tint transform (into alternate color space)
665 GBool nonMarking;
668 //------------------------------------------------------------------------
669 // GfxDeviceNColorSpace
670 //------------------------------------------------------------------------
672 class GfxDeviceNColorSpace: public GfxColorSpace {
673 public:
675 GfxDeviceNColorSpace(int nCompsA, GooString **namesA,
676 GfxColorSpace *alt, Function *func, GooList *sepsCS);
677 virtual ~GfxDeviceNColorSpace();
678 virtual GfxColorSpace *copy();
679 virtual GfxColorSpaceMode getMode() { return csDeviceN; }
681 // Construct a DeviceN color space. Returns NULL if unsuccessful.
682 static GfxColorSpace *parse(GfxResources *res, Array *arr, OutputDev *out, GfxState *state, int recursion);
684 virtual void getGray(GfxColor *color, GfxGray *gray);
685 virtual void getRGB(GfxColor *color, GfxRGB *rgb);
686 virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
687 virtual void getDeviceN(GfxColor *color, GfxColor *deviceN);
689 virtual void createMapping(GooList *separationList, int maxSepComps);
691 virtual int getNComps() { return nComps; }
692 virtual void getDefaultColor(GfxColor *color);
694 virtual GBool isNonMarking() { return nonMarking; }
696 // DeviceN-specific access.
697 GooString *getColorantName(int i) { return names[i]; }
698 GfxColorSpace *getAlt() { return alt; }
699 Function *getTintTransformFunc() { return func; }
701 private:
703 GfxDeviceNColorSpace(int nCompsA, GooString **namesA,
704 GfxColorSpace *alt, Function *func, GooList *sepsCSA,
705 int *mappingA, GBool nonMarkingA, Guint overprintMaskA);
707 int nComps; // number of components
708 GooString // colorant names
709 *names[gfxColorMaxComps];
710 GfxColorSpace *alt; // alternate color space
711 Function *func; // tint transform (into alternate color space)
712 GBool nonMarking;
713 GooList *sepsCS; // list of separation cs for spot colorants;
716 //------------------------------------------------------------------------
717 // GfxPatternColorSpace
718 //------------------------------------------------------------------------
720 class GfxPatternColorSpace: public GfxColorSpace {
721 public:
723 GfxPatternColorSpace(GfxColorSpace *underA);
724 virtual ~GfxPatternColorSpace();
725 virtual GfxColorSpace *copy();
726 virtual GfxColorSpaceMode getMode() { return csPattern; }
728 // Construct a Pattern color space. Returns NULL if unsuccessful.
729 static GfxColorSpace *parse(GfxResources *res, Array *arr, OutputDev *out, GfxState *state, int recursion);
731 virtual void getGray(GfxColor *color, GfxGray *gray);
732 virtual void getRGB(GfxColor *color, GfxRGB *rgb);
733 virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
734 virtual void getDeviceN(GfxColor *color, GfxColor *deviceN);
736 virtual int getNComps() { return 0; }
737 virtual void getDefaultColor(GfxColor *color);
739 // Pattern-specific access.
740 GfxColorSpace *getUnder() { return under; }
742 private:
744 GfxColorSpace *under; // underlying color space (for uncolored
745 // patterns)
748 //------------------------------------------------------------------------
749 // GfxPattern
750 //------------------------------------------------------------------------
752 class GfxPattern {
753 public:
755 GfxPattern(int typeA);
756 virtual ~GfxPattern();
758 static GfxPattern *parse(GfxResources *res, Object *obj, OutputDev *out, GfxState *state);
760 virtual GfxPattern *copy() = 0;
762 int getType() { return type; }
764 private:
766 int type;
769 //------------------------------------------------------------------------
770 // GfxTilingPattern
771 //------------------------------------------------------------------------
773 class GfxTilingPattern: public GfxPattern {
774 public:
776 static GfxTilingPattern *parse(Object *patObj);
777 virtual ~GfxTilingPattern();
779 virtual GfxPattern *copy();
781 int getPaintType() { return paintType; }
782 int getTilingType() { return tilingType; }
783 double *getBBox() { return bbox; }
784 double getXStep() { return xStep; }
785 double getYStep() { return yStep; }
786 Dict *getResDict()
787 { return resDict.isDict() ? resDict.getDict() : (Dict *)NULL; }
788 double *getMatrix() { return matrix; }
789 Object *getContentStream() { return &contentStream; }
791 private:
793 GfxTilingPattern(int paintTypeA, int tilingTypeA,
794 double *bboxA, double xStepA, double yStepA,
795 Object *resDictA, double *matrixA,
796 Object *contentStreamA);
798 int paintType;
799 int tilingType;
800 double bbox[4];
801 double xStep, yStep;
802 Object resDict;
803 double matrix[6];
804 Object contentStream;
807 //------------------------------------------------------------------------
808 // GfxShadingPattern
809 //------------------------------------------------------------------------
811 class GfxShadingPattern: public GfxPattern {
812 public:
814 static GfxShadingPattern *parse(GfxResources *res, Object *patObj, OutputDev *out, GfxState *state);
815 virtual ~GfxShadingPattern();
817 virtual GfxPattern *copy();
819 GfxShading *getShading() { return shading; }
820 double *getMatrix() { return matrix; }
822 private:
824 GfxShadingPattern(GfxShading *shadingA, double *matrixA);
826 GfxShading *shading;
827 double matrix[6];
830 //------------------------------------------------------------------------
831 // GfxShading
832 //------------------------------------------------------------------------
834 class GfxShading {
835 public:
837 GfxShading(int typeA);
838 GfxShading(GfxShading *shading);
839 virtual ~GfxShading();
841 static GfxShading *parse(GfxResources *res, Object *obj, OutputDev *out, GfxState *state);
843 virtual GfxShading *copy() = 0;
845 int getType() { return type; }
846 GfxColorSpace *getColorSpace() { return colorSpace; }
847 GfxColor *getBackground() { return &background; }
848 GBool getHasBackground() { return hasBackground; }
849 void getBBox(double *xMinA, double *yMinA, double *xMaxA, double *yMaxA)
850 { *xMinA = xMin; *yMinA = yMin; *xMaxA = xMax; *yMaxA = yMax; }
851 GBool getHasBBox() { return hasBBox; }
853 protected:
855 GBool init(GfxResources *res, Dict *dict, OutputDev *out, GfxState *state);
857 int type;
858 GfxColorSpace *colorSpace;
859 GfxColor background;
860 GBool hasBackground;
861 double xMin, yMin, xMax, yMax;
862 GBool hasBBox;
865 //------------------------------------------------------------------------
866 // GfxUnivariateShading
867 //------------------------------------------------------------------------
869 class GfxUnivariateShading: public GfxShading {
870 public:
872 GfxUnivariateShading(int typeA,
873 double t0A, double t1A,
874 Function **funcsA, int nFuncsA,
875 GBool extend0A, GBool extend1A);
876 GfxUnivariateShading(GfxUnivariateShading *shading);
877 virtual ~GfxUnivariateShading();
879 double getDomain0() { return t0; }
880 double getDomain1() { return t1; }
881 GBool getExtend0() { return extend0; }
882 GBool getExtend1() { return extend1; }
883 int getNFuncs() { return nFuncs; }
884 Function *getFunc(int i) { return funcs[i]; }
885 void getColor(double t, GfxColor *color);
887 void setupCache(const Matrix *ctm,
888 double xMin, double yMin,
889 double xMax, double yMax);
891 virtual void getParameterRange(double *lower, double *upper,
892 double xMin, double yMin,
893 double xMax, double yMax) = 0;
895 virtual double getDistance(double tMin, double tMax) = 0;
897 private:
899 double t0, t1;
900 Function *funcs[gfxColorMaxComps];
901 int nFuncs;
902 GBool extend0, extend1;
904 int cacheSize, lastMatch;
905 double *cacheBounds;
906 double *cacheCoeff;
907 double *cacheValues;
910 //------------------------------------------------------------------------
911 // GfxFunctionShading
912 //------------------------------------------------------------------------
914 class GfxFunctionShading: public GfxShading {
915 public:
917 GfxFunctionShading(double x0A, double y0A,
918 double x1A, double y1A,
919 double *matrixA,
920 Function **funcsA, int nFuncsA);
921 GfxFunctionShading(GfxFunctionShading *shading);
922 virtual ~GfxFunctionShading();
924 static GfxFunctionShading *parse(GfxResources *res, Dict *dict, OutputDev *out, GfxState *state);
926 virtual GfxShading *copy();
928 void getDomain(double *x0A, double *y0A, double *x1A, double *y1A)
929 { *x0A = x0; *y0A = y0; *x1A = x1; *y1A = y1; }
930 double *getMatrix() { return matrix; }
931 int getNFuncs() { return nFuncs; }
932 Function *getFunc(int i) { return funcs[i]; }
933 void getColor(double x, double y, GfxColor *color);
935 private:
937 double x0, y0, x1, y1;
938 double matrix[6];
939 Function *funcs[gfxColorMaxComps];
940 int nFuncs;
943 //------------------------------------------------------------------------
944 // GfxAxialShading
945 //------------------------------------------------------------------------
947 class GfxAxialShading: public GfxUnivariateShading {
948 public:
950 GfxAxialShading(double x0A, double y0A,
951 double x1A, double y1A,
952 double t0A, double t1A,
953 Function **funcsA, int nFuncsA,
954 GBool extend0A, GBool extend1A);
955 GfxAxialShading(GfxAxialShading *shading);
956 virtual ~GfxAxialShading();
958 static GfxAxialShading *parse(GfxResources *res, Dict *dict, OutputDev *out, GfxState *state);
960 virtual GfxShading *copy();
962 void getCoords(double *x0A, double *y0A, double *x1A, double *y1A)
963 { *x0A = x0; *y0A = y0; *x1A = x1; *y1A = y1; }
965 virtual void getParameterRange(double *lower, double *upper,
966 double xMin, double yMin,
967 double xMax, double yMax);
969 virtual double getDistance(double tMin, double tMax);
971 private:
973 double x0, y0, x1, y1;
976 //------------------------------------------------------------------------
977 // GfxRadialShading
978 //------------------------------------------------------------------------
980 class GfxRadialShading: public GfxUnivariateShading {
981 public:
983 GfxRadialShading(double x0A, double y0A, double r0A,
984 double x1A, double y1A, double r1A,
985 double t0A, double t1A,
986 Function **funcsA, int nFuncsA,
987 GBool extend0A, GBool extend1A);
988 GfxRadialShading(GfxRadialShading *shading);
989 virtual ~GfxRadialShading();
991 static GfxRadialShading *parse(GfxResources *res, Dict *dict, OutputDev *out, GfxState *state);
993 virtual GfxShading *copy();
995 void getCoords(double *x0A, double *y0A, double *r0A,
996 double *x1A, double *y1A, double *r1A)
997 { *x0A = x0; *y0A = y0; *r0A = r0; *x1A = x1; *y1A = y1; *r1A = r1; }
999 virtual void getParameterRange(double *lower, double *upper,
1000 double xMin, double yMin,
1001 double xMax, double yMax);
1003 virtual double getDistance(double tMin, double tMax);
1005 private:
1007 double x0, y0, r0, x1, y1, r1;
1010 //------------------------------------------------------------------------
1011 // GfxGouraudTriangleShading
1012 //------------------------------------------------------------------------
1014 struct GfxGouraudVertex {
1015 double x, y;
1016 GfxColor color;
1019 class GfxGouraudTriangleShading: public GfxShading {
1020 public:
1022 GfxGouraudTriangleShading(int typeA,
1023 GfxGouraudVertex *verticesA, int nVerticesA,
1024 int (*trianglesA)[3], int nTrianglesA,
1025 Function **funcsA, int nFuncsA);
1026 GfxGouraudTriangleShading(GfxGouraudTriangleShading *shading);
1027 virtual ~GfxGouraudTriangleShading();
1029 static GfxGouraudTriangleShading *parse(GfxResources *res, int typeA, Dict *dict, Stream *str, OutputDev *out, GfxState *state);
1031 virtual GfxShading *copy();
1033 int getNTriangles() { return nTriangles; }
1035 bool isParameterized() const { return nFuncs > 0; }
1038 * @precondition isParameterized() == true
1040 double getParameterDomainMin() const { assert(isParameterized()); return funcs[0]->getDomainMin(0); }
1043 * @precondition isParameterized() == true
1045 double getParameterDomainMax() const { assert(isParameterized()); return funcs[0]->getDomainMax(0); }
1048 * @precondition isParameterized() == false
1050 void getTriangle(int i, double *x0, double *y0, GfxColor *color0,
1051 double *x1, double *y1, GfxColor *color1,
1052 double *x2, double *y2, GfxColor *color2);
1055 * Variant for functions.
1057 * @precondition isParameterized() == true
1059 void getTriangle(int i, double *x0, double *y0, double *color0,
1060 double *x1, double *y1, double *color1,
1061 double *x2, double *y2, double *color2);
1063 void getParameterizedColor(double t, GfxColor *color);
1065 private:
1067 GfxGouraudVertex *vertices;
1068 int nVertices;
1069 int (*triangles)[3];
1070 int nTriangles;
1071 Function *funcs[gfxColorMaxComps];
1072 int nFuncs;
1075 //------------------------------------------------------------------------
1076 // GfxPatchMeshShading
1077 //------------------------------------------------------------------------
1080 * A tensor product cubic bezier patch consisting of 4x4 points and 4 color
1081 * values.
1083 * See the Shading Type 7 specifications. Note that Shading Type 6 is also
1084 * represented using GfxPatch.
1086 struct GfxPatch {
1088 * Represents a single color value for the patch.
1090 struct ColorValue {
1092 * For parameterized patches, only element 0 is valid; it contains
1093 * the single parameter.
1095 * For non-parameterized patches, c contains all color components
1096 * as decoded from the input stream. In this case, you will need to
1097 * use dblToCol() before assigning them to GfxColor.
1099 double c[gfxColorMaxComps];
1102 double x[4][4];
1103 double y[4][4];
1104 ColorValue color[2][2];
1107 class GfxPatchMeshShading: public GfxShading {
1108 public:
1110 GfxPatchMeshShading(int typeA, GfxPatch *patchesA, int nPatchesA,
1111 Function **funcsA, int nFuncsA);
1112 GfxPatchMeshShading(GfxPatchMeshShading *shading);
1113 virtual ~GfxPatchMeshShading();
1115 static GfxPatchMeshShading *parse(GfxResources *res, int typeA, Dict *dict, Stream *str, OutputDev *out, GfxState *state);
1117 virtual GfxShading *copy();
1119 int getNPatches() { return nPatches; }
1120 GfxPatch *getPatch(int i) { return &patches[i]; }
1122 bool isParameterized() const { return nFuncs > 0; }
1125 * @precondition isParameterized() == true
1127 double getParameterDomainMin() const { assert(isParameterized()); return funcs[0]->getDomainMin(0); }
1130 * @precondition isParameterized() == true
1132 double getParameterDomainMax() const { assert(isParameterized()); return funcs[0]->getDomainMax(0); }
1134 void getParameterizedColor(double t, GfxColor *color);
1136 private:
1138 GfxPatch *patches;
1139 int nPatches;
1140 Function *funcs[gfxColorMaxComps];
1141 int nFuncs;
1144 //------------------------------------------------------------------------
1145 // GfxImageColorMap
1146 //------------------------------------------------------------------------
1148 class GfxImageColorMap {
1149 public:
1151 // Constructor.
1152 GfxImageColorMap(int bitsA, Object *decode, GfxColorSpace *colorSpaceA);
1154 // Destructor.
1155 ~GfxImageColorMap();
1157 // Return a copy of this color map.
1158 GfxImageColorMap *copy() { return new GfxImageColorMap(this); }
1160 // Is color map valid?
1161 GBool isOk() { return ok; }
1163 // Get the color space.
1164 GfxColorSpace *getColorSpace() { return colorSpace; }
1166 // Get stream decoding info.
1167 int getNumPixelComps() { return nComps; }
1168 int getBits() { return bits; }
1170 // Get decode table.
1171 double getDecodeLow(int i) { return decodeLow[i]; }
1172 double getDecodeHigh(int i) { return decodeLow[i] + decodeRange[i]; }
1174 bool useRGBLine() { return (colorSpace2 && colorSpace2->useGetRGBLine ()) || (!colorSpace2 && colorSpace->useGetRGBLine ()); }
1175 bool useCMYKLine() { return (colorSpace2 && colorSpace2->useGetCMYKLine ()) || (!colorSpace2 && colorSpace->useGetCMYKLine ()); }
1176 bool useDeviceNLine() { return (colorSpace2 && colorSpace2->useGetDeviceNLine ()) || (!colorSpace2 && colorSpace->useGetDeviceNLine ()); }
1178 // Convert an image pixel to a color.
1179 void getGray(Guchar *x, GfxGray *gray);
1180 void getRGB(Guchar *x, GfxRGB *rgb);
1181 void getRGBLine(Guchar *in, unsigned int *out, int length);
1182 void getRGBLine(Guchar *in, Guchar *out, int length);
1183 void getRGBXLine(Guchar *in, Guchar *out, int length);
1184 void getGrayLine(Guchar *in, Guchar *out, int length);
1185 void getCMYKLine(Guchar *in, Guchar *out, int length);
1186 void getDeviceNLine(Guchar *in, Guchar *out, int length);
1187 void getCMYK(Guchar *x, GfxCMYK *cmyk);
1188 void getDeviceN(Guchar *x, GfxColor *deviceN);
1189 void getColor(Guchar *x, GfxColor *color);
1191 private:
1193 GfxImageColorMap(GfxImageColorMap *colorMap);
1195 GfxColorSpace *colorSpace; // the image color space
1196 int bits; // bits per component
1197 int nComps; // number of components in a pixel
1198 GfxColorSpace *colorSpace2; // secondary color space
1199 int nComps2; // number of components in colorSpace2
1200 GfxColorComp * // lookup table
1201 lookup[gfxColorMaxComps];
1202 GfxColorComp * // optimized case lookup table
1203 lookup2[gfxColorMaxComps];
1204 Guchar *byte_lookup;
1205 double // minimum values for each component
1206 decodeLow[gfxColorMaxComps];
1207 double // max - min value for each component
1208 decodeRange[gfxColorMaxComps];
1209 GBool ok;
1212 //------------------------------------------------------------------------
1213 // GfxSubpath and GfxPath
1214 //------------------------------------------------------------------------
1216 class GfxSubpath {
1217 public:
1219 // Constructor.
1220 GfxSubpath(double x1, double y1);
1222 // Destructor.
1223 ~GfxSubpath();
1225 // Copy.
1226 GfxSubpath *copy() { return new GfxSubpath(this); }
1228 // Get points.
1229 int getNumPoints() { return n; }
1230 double getX(int i) { return x[i]; }
1231 double getY(int i) { return y[i]; }
1232 GBool getCurve(int i) { return curve[i]; }
1234 void setX(int i, double a) { x[i] = a; }
1235 void setY(int i, double a) { y[i] = a; }
1237 // Get last point.
1238 double getLastX() { return x[n-1]; }
1239 double getLastY() { return y[n-1]; }
1241 // Add a line segment.
1242 void lineTo(double x1, double y1);
1244 // Add a Bezier curve.
1245 void curveTo(double x1, double y1, double x2, double y2,
1246 double x3, double y3);
1248 // Close the subpath.
1249 void close();
1250 GBool isClosed() { return closed; }
1252 // Add (<dx>, <dy>) to each point in the subpath.
1253 void offset(double dx, double dy);
1255 private:
1257 double *x, *y; // points
1258 GBool *curve; // curve[i] => point i is a control point
1259 // for a Bezier curve
1260 int n; // number of points
1261 int size; // size of x/y arrays
1262 GBool closed; // set if path is closed
1264 GfxSubpath(GfxSubpath *subpath);
1267 class GfxPath {
1268 public:
1270 // Constructor.
1271 GfxPath();
1273 // Destructor.
1274 ~GfxPath();
1276 // Copy.
1277 GfxPath *copy()
1278 { return new GfxPath(justMoved, firstX, firstY, subpaths, n, size); }
1280 // Is there a current point?
1281 GBool isCurPt() { return n > 0 || justMoved; }
1283 // Is the path non-empty, i.e., is there at least one segment?
1284 GBool isPath() { return n > 0; }
1286 // Get subpaths.
1287 int getNumSubpaths() { return n; }
1288 GfxSubpath *getSubpath(int i) { return subpaths[i]; }
1290 // Get last point on last subpath.
1291 double getLastX() { return subpaths[n-1]->getLastX(); }
1292 double getLastY() { return subpaths[n-1]->getLastY(); }
1294 // Move the current point.
1295 void moveTo(double x, double y);
1297 // Add a segment to the last subpath.
1298 void lineTo(double x, double y);
1300 // Add a Bezier curve to the last subpath
1301 void curveTo(double x1, double y1, double x2, double y2,
1302 double x3, double y3);
1304 // Close the last subpath.
1305 void close();
1307 // Append <path> to <this>.
1308 void append(GfxPath *path);
1310 // Add (<dx>, <dy>) to each point in the path.
1311 void offset(double dx, double dy);
1313 private:
1315 GBool justMoved; // set if a new subpath was just started
1316 double firstX, firstY; // first point in new subpath
1317 GfxSubpath **subpaths; // subpaths
1318 int n; // number of subpaths
1319 int size; // size of subpaths array
1321 GfxPath(GBool justMoved1, double firstX1, double firstY1,
1322 GfxSubpath **subpaths1, int n1, int size1);
1325 //------------------------------------------------------------------------
1326 // GfxState
1327 //------------------------------------------------------------------------
1329 class GfxState {
1330 public:
1332 * When GfxState::getReusablePath() is invoked, the currently active
1333 * path is taken per reference and its coordinates can be re-edited.
1335 * A ReusablePathIterator is intented to reduce overhead when the same
1336 * path type is used a lot of times, only with different coordinates. It
1337 * allows just to update the coordinates (occuring in the same order as
1338 * in the original path).
1340 class ReusablePathIterator {
1341 public:
1343 * Creates the ReusablePathIterator. This should only be done from
1344 * GfxState::getReusablePath().
1346 * @param path the path as it is used so far. Changing this path,
1347 * deleting it or starting a new path from scratch will most likely
1348 * invalidate the iterator (and may cause serious problems). Make
1349 * sure the path's memory structure is not changed during the
1350 * lifetime of the ReusablePathIterator.
1352 ReusablePathIterator( GfxPath* path );
1355 * Returns true if and only if the current iterator position is
1356 * beyond the last valid point.
1358 * A call to setCoord() will be undefined.
1360 bool isEnd() const;
1363 * Advances the iterator.
1365 void next();
1368 * Updates the coordinates associated to the current iterator
1369 * position.
1371 void setCoord( double x, double y );
1374 * Resets the iterator.
1376 void reset();
1377 private:
1378 GfxPath *path;
1379 int subPathOff;
1381 int coordOff;
1382 int numCoords;
1384 GfxSubpath *curSubPath;
1387 // Construct a default GfxState, for a device with resolution <hDPI>
1388 // x <vDPI>, page box <pageBox>, page rotation <rotateA>, and
1389 // coordinate system specified by <upsideDown>.
1390 GfxState(double hDPIA, double vDPIA, PDFRectangle *pageBox,
1391 int rotateA, GBool upsideDown);
1393 // Destructor.
1394 ~GfxState();
1396 // Copy.
1397 GfxState *copy(GBool copyPath = gFalse)
1398 { return new GfxState(this, copyPath); }
1400 // Accessors.
1401 double getHDPI() { return hDPI; }
1402 double getVDPI() { return vDPI; }
1403 double *getCTM() { return ctm; }
1404 void getCTM(Matrix *m) { memcpy (m->m, ctm, sizeof m->m); }
1405 double getX1() { return px1; }
1406 double getY1() { return py1; }
1407 double getX2() { return px2; }
1408 double getY2() { return py2; }
1409 double getPageWidth() { return pageWidth; }
1410 double getPageHeight() { return pageHeight; }
1411 int getRotate() { return rotate; }
1412 GfxColor *getFillColor() { return &fillColor; }
1413 GfxColor *getStrokeColor() { return &strokeColor; }
1414 void getFillGray(GfxGray *gray)
1415 { fillColorSpace->getGray(&fillColor, gray); }
1416 void getStrokeGray(GfxGray *gray)
1417 { strokeColorSpace->getGray(&strokeColor, gray); }
1418 void getFillRGB(GfxRGB *rgb)
1419 { fillColorSpace->getRGB(&fillColor, rgb); }
1420 void getStrokeRGB(GfxRGB *rgb)
1421 { strokeColorSpace->getRGB(&strokeColor, rgb); }
1422 void getFillCMYK(GfxCMYK *cmyk)
1423 { fillColorSpace->getCMYK(&fillColor, cmyk); }
1424 void getFillDeviceN(GfxColor *deviceN)
1425 { fillColorSpace->getDeviceN(&fillColor, deviceN); }
1426 void getStrokeCMYK(GfxCMYK *cmyk)
1427 { strokeColorSpace->getCMYK(&strokeColor, cmyk); }
1428 void getStrokeDeviceN(GfxColor *deviceN)
1429 { strokeColorSpace->getDeviceN(&strokeColor, deviceN); }
1430 GfxColorSpace *getFillColorSpace() { return fillColorSpace; }
1431 GfxColorSpace *getStrokeColorSpace() { return strokeColorSpace; }
1432 GfxPattern *getFillPattern() { return fillPattern; }
1433 GfxPattern *getStrokePattern() { return strokePattern; }
1434 GfxBlendMode getBlendMode() { return blendMode; }
1435 double getFillOpacity() { return fillOpacity; }
1436 double getStrokeOpacity() { return strokeOpacity; }
1437 GBool getFillOverprint() { return fillOverprint; }
1438 GBool getStrokeOverprint() { return strokeOverprint; }
1439 int getOverprintMode() { return overprintMode; }
1440 Function **getTransfer() { return transfer; }
1441 double getLineWidth() { return lineWidth; }
1442 void getLineDash(double **dash, int *length, double *start)
1443 { *dash = lineDash; *length = lineDashLength; *start = lineDashStart; }
1444 int getFlatness() { return flatness; }
1445 int getLineJoin() { return lineJoin; }
1446 int getLineCap() { return lineCap; }
1447 double getMiterLimit() { return miterLimit; }
1448 GBool getStrokeAdjust() { return strokeAdjust; }
1449 GBool getAlphaIsShape() { return alphaIsShape; }
1450 GBool getTextKnockout() { return textKnockout; }
1451 GfxFont *getFont() { return font; }
1452 double getFontSize() { return fontSize; }
1453 double *getTextMat() { return textMat; }
1454 double getCharSpace() { return charSpace; }
1455 double getWordSpace() { return wordSpace; }
1456 double getHorizScaling() { return horizScaling; }
1457 double getLeading() { return leading; }
1458 double getRise() { return rise; }
1459 int getRender() { return render; }
1460 char *getRenderingIntent() { return renderingIntent; }
1461 GfxPath *getPath() { return path; }
1462 void setPath(GfxPath *pathA);
1463 double getCurX() { return curX; }
1464 double getCurY() { return curY; }
1465 void getClipBBox(double *xMin, double *yMin, double *xMax, double *yMax)
1466 { *xMin = clipXMin; *yMin = clipYMin; *xMax = clipXMax; *yMax = clipYMax; }
1467 void getUserClipBBox(double *xMin, double *yMin, double *xMax, double *yMax);
1468 double getLineX() { return lineX; }
1469 double getLineY() { return lineY; }
1471 // Is there a current point/path?
1472 GBool isCurPt() { return path->isCurPt(); }
1473 GBool isPath() { return path->isPath(); }
1475 // Transforms.
1476 void transform(double x1, double y1, double *x2, double *y2)
1477 { *x2 = ctm[0] * x1 + ctm[2] * y1 + ctm[4];
1478 *y2 = ctm[1] * x1 + ctm[3] * y1 + ctm[5]; }
1479 void transformDelta(double x1, double y1, double *x2, double *y2)
1480 { *x2 = ctm[0] * x1 + ctm[2] * y1;
1481 *y2 = ctm[1] * x1 + ctm[3] * y1; }
1482 void textTransform(double x1, double y1, double *x2, double *y2)
1483 { *x2 = textMat[0] * x1 + textMat[2] * y1 + textMat[4];
1484 *y2 = textMat[1] * x1 + textMat[3] * y1 + textMat[5]; }
1485 void textTransformDelta(double x1, double y1, double *x2, double *y2)
1486 { *x2 = textMat[0] * x1 + textMat[2] * y1;
1487 *y2 = textMat[1] * x1 + textMat[3] * y1; }
1488 double transformWidth(double w);
1489 double getTransformedLineWidth()
1490 { return transformWidth(lineWidth); }
1491 double getTransformedFontSize();
1492 void getFontTransMat(double *m11, double *m12, double *m21, double *m22);
1494 // Change state parameters.
1495 void setCTM(double a, double b, double c,
1496 double d, double e, double f);
1497 void concatCTM(double a, double b, double c,
1498 double d, double e, double f);
1499 void shiftCTMAndClip(double tx, double ty);
1500 void setFillColorSpace(GfxColorSpace *colorSpace);
1501 void setStrokeColorSpace(GfxColorSpace *colorSpace);
1502 void setFillColor(GfxColor *color) { fillColor = *color; }
1503 void setStrokeColor(GfxColor *color) { strokeColor = *color; }
1504 void setFillPattern(GfxPattern *pattern);
1505 void setStrokePattern(GfxPattern *pattern);
1506 void setBlendMode(GfxBlendMode mode) { blendMode = mode; }
1507 void setFillOpacity(double opac) { fillOpacity = opac; }
1508 void setStrokeOpacity(double opac) { strokeOpacity = opac; }
1509 void setFillOverprint(GBool op) { fillOverprint = op; }
1510 void setStrokeOverprint(GBool op) { strokeOverprint = op; }
1511 void setOverprintMode(int op) { overprintMode = op; }
1512 void setTransfer(Function **funcs);
1513 void setLineWidth(double width) { lineWidth = width; }
1514 void setLineDash(double *dash, int length, double start);
1515 void setFlatness(int flatness1) { flatness = flatness1; }
1516 void setLineJoin(int lineJoin1) { lineJoin = lineJoin1; }
1517 void setLineCap(int lineCap1) { lineCap = lineCap1; }
1518 void setMiterLimit(double limit) { miterLimit = limit; }
1519 void setStrokeAdjust(GBool sa) { strokeAdjust = sa; }
1520 void setAlphaIsShape(GBool ais) { alphaIsShape = ais; }
1521 void setTextKnockout(GBool tk) { textKnockout = tk; }
1522 void setFont(GfxFont *fontA, double fontSizeA);
1523 void setTextMat(double a, double b, double c,
1524 double d, double e, double f)
1525 { textMat[0] = a; textMat[1] = b; textMat[2] = c;
1526 textMat[3] = d; textMat[4] = e; textMat[5] = f; }
1527 void setCharSpace(double space)
1528 { charSpace = space; }
1529 void setWordSpace(double space)
1530 { wordSpace = space; }
1531 void setHorizScaling(double scale)
1532 { horizScaling = 0.01 * scale; }
1533 void setLeading(double leadingA)
1534 { leading = leadingA; }
1535 void setRise(double riseA)
1536 { rise = riseA; }
1537 void setRender(int renderA)
1538 { render = renderA; }
1539 void setRenderingIntent(const char *intent)
1540 { strncpy(renderingIntent, intent, 31); }
1542 #ifdef USE_CMS
1543 void setDisplayProfile(void *localDisplayProfileA);
1544 void *getDisplayProfile() { return localDisplayProfile; }
1545 GfxColorTransform *getXYZ2DisplayTransform();
1546 #endif
1548 // Add to path.
1549 void moveTo(double x, double y)
1550 { path->moveTo(curX = x, curY = y); }
1551 void lineTo(double x, double y)
1552 { path->lineTo(curX = x, curY = y); }
1553 void curveTo(double x1, double y1, double x2, double y2,
1554 double x3, double y3)
1555 { path->curveTo(x1, y1, x2, y2, curX = x3, curY = y3); }
1556 void closePath()
1557 { path->close(); curX = path->getLastX(); curY = path->getLastY(); }
1558 void clearPath();
1560 // Update clip region.
1561 void clip();
1562 void clipToStrokePath();
1563 void clipToRect(double xMin, double yMin, double xMax, double yMax);
1565 // Text position.
1566 void textSetPos(double tx, double ty) { lineX = tx; lineY = ty; }
1567 void textMoveTo(double tx, double ty)
1568 { lineX = tx; lineY = ty; textTransform(tx, ty, &curX, &curY); }
1569 void textShift(double tx, double ty);
1570 void shift(double dx, double dy);
1572 // Push/pop GfxState on/off stack.
1573 GfxState *save();
1574 GfxState *restore();
1575 GBool hasSaves() { return saved != NULL; }
1576 GBool isParentState(GfxState *state) { return saved == state || (saved && saved->isParentState(state)); }
1578 // Misc
1579 GBool parseBlendMode(Object *obj, GfxBlendMode *mode);
1581 ReusablePathIterator *getReusablePath() { return new ReusablePathIterator(path); }
1582 private:
1584 double hDPI, vDPI; // resolution
1585 double ctm[6]; // coord transform matrix
1586 double px1, py1, px2, py2; // page corners (user coords)
1587 double pageWidth, pageHeight; // page size (pixels)
1588 int rotate; // page rotation angle
1590 GfxColorSpace *fillColorSpace; // fill color space
1591 GfxColorSpace *strokeColorSpace; // stroke color space
1592 GfxColor fillColor; // fill color
1593 GfxColor strokeColor; // stroke color
1594 GfxPattern *fillPattern; // fill pattern
1595 GfxPattern *strokePattern; // stroke pattern
1596 GfxBlendMode blendMode; // transparency blend mode
1597 double fillOpacity; // fill opacity
1598 double strokeOpacity; // stroke opacity
1599 GBool fillOverprint; // fill overprint
1600 GBool strokeOverprint; // stroke overprint
1601 int overprintMode; // overprint mode
1602 Function *transfer[4]; // transfer function (entries may be: all
1603 // NULL = identity; last three NULL =
1604 // single function; all four non-NULL =
1605 // R,G,B,gray functions)
1607 double lineWidth; // line width
1608 double *lineDash; // line dash
1609 int lineDashLength;
1610 double lineDashStart;
1611 int flatness; // curve flatness
1612 int lineJoin; // line join style
1613 int lineCap; // line cap style
1614 double miterLimit; // line miter limit
1615 GBool strokeAdjust; // stroke adjustment
1616 GBool alphaIsShape; // alpha is shape
1617 GBool textKnockout; // text knockout
1619 GfxFont *font; // font
1620 double fontSize; // font size
1621 double textMat[6]; // text matrix
1622 double charSpace; // character spacing
1623 double wordSpace; // word spacing
1624 double horizScaling; // horizontal scaling
1625 double leading; // text leading
1626 double rise; // text rise
1627 int render; // text rendering mode
1629 GfxPath *path; // array of path elements
1630 double curX, curY; // current point (user coords)
1631 double lineX, lineY; // start of current text line (text coords)
1633 double clipXMin, clipYMin, // bounding box for clip region
1634 clipXMax, clipYMax;
1635 char renderingIntent[32];
1637 GfxState *saved; // next GfxState on stack
1639 GfxState(GfxState *state, GBool copyPath);
1641 #ifdef USE_CMS
1642 void *localDisplayProfile;
1643 int displayProfileRef;
1644 GfxColorTransform *XYZ2DisplayTransformRelCol;
1645 GfxColorTransform *XYZ2DisplayTransformAbsCol;
1646 GfxColorTransform *XYZ2DisplayTransformSat;
1647 GfxColorTransform *XYZ2DisplayTransformPerc;
1648 #endif
1651 #endif