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