]> www.fi.muni.cz Git - evince.git/blob - pdf/xpdf/GfxState.h
kill traces of ltk, incorporate new sources
[evince.git] / pdf / xpdf / GfxState.h
1 //========================================================================
2 //
3 // GfxState.h
4 //
5 // Copyright 1996-2002 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
26 //------------------------------------------------------------------------
27 // GfxColor
28 //------------------------------------------------------------------------
29
30 #define gfxColorMaxComps funcMaxOutputs
31
32 struct GfxColor {
33   double c[gfxColorMaxComps];
34 };
35
36 //------------------------------------------------------------------------
37 // GfxRGB
38 //------------------------------------------------------------------------
39
40 struct GfxRGB {
41   double r, g, b;
42 };
43
44 //------------------------------------------------------------------------
45 // GfxCMYK
46 //------------------------------------------------------------------------
47
48 struct GfxCMYK {
49   double c, m, y, k;
50 };
51
52 //------------------------------------------------------------------------
53 // GfxColorSpace
54 //------------------------------------------------------------------------
55
56 enum GfxColorSpaceMode {
57   csDeviceGray,
58   csCalGray,
59   csDeviceRGB,
60   csCalRGB,
61   csDeviceCMYK,
62   csLab,
63   csICCBased,
64   csIndexed,
65   csSeparation,
66   csDeviceN,
67   csPattern
68 };
69
70 class GfxColorSpace {
71 public:
72
73   GfxColorSpace();
74   virtual ~GfxColorSpace();
75   virtual GfxColorSpace *copy() = 0;
76   virtual GfxColorSpaceMode getMode() = 0;
77
78   // Construct a color space.  Returns NULL if unsuccessful.
79   static GfxColorSpace *parse(Object *csObj);
80
81   // Convert to gray, RGB, or CMYK.
82   virtual void getGray(GfxColor *color, double *gray) = 0;
83   virtual void getRGB(GfxColor *color, GfxRGB *rgb) = 0;
84   virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk) = 0;
85
86   // Return the number of color components.
87   virtual int getNComps() = 0;
88
89   // Return the default ranges for each component, assuming an image
90   // with a max pixel value of <maxImgPixel>.
91   virtual void getDefaultRanges(double *decodeLow, double *decodeRange,
92                                 int maxImgPixel);
93
94 private:
95 };
96
97 //------------------------------------------------------------------------
98 // GfxDeviceGrayColorSpace
99 //------------------------------------------------------------------------
100
101 class GfxDeviceGrayColorSpace: public GfxColorSpace {
102 public:
103
104   GfxDeviceGrayColorSpace();
105   virtual ~GfxDeviceGrayColorSpace();
106   virtual GfxColorSpace *copy();
107   virtual GfxColorSpaceMode getMode() { return csDeviceGray; }
108
109   virtual void getGray(GfxColor *color, double *gray);
110   virtual void getRGB(GfxColor *color, GfxRGB *rgb);
111   virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
112
113   virtual int getNComps() { return 1; }
114
115 private:
116 };
117
118 //------------------------------------------------------------------------
119 // GfxCalGrayColorSpace
120 //------------------------------------------------------------------------
121
122 class GfxCalGrayColorSpace: public GfxColorSpace {
123 public:
124
125   GfxCalGrayColorSpace();
126   virtual ~GfxCalGrayColorSpace();
127   virtual GfxColorSpace *copy();
128   virtual GfxColorSpaceMode getMode() { return csCalGray; }
129
130   // Construct a CalGray color space.  Returns NULL if unsuccessful.
131   static GfxColorSpace *parse(Array *arr);
132
133   virtual void getGray(GfxColor *color, double *gray);
134   virtual void getRGB(GfxColor *color, GfxRGB *rgb);
135   virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
136
137   virtual int getNComps() { return 1; }
138
139   // CalGray-specific access.
140   double getWhiteX() { return whiteX; }
141   double getWhiteY() { return whiteY; }
142   double getWhiteZ() { return whiteZ; }
143   double getBlackX() { return blackX; }
144   double getBlackY() { return blackY; }
145   double getBlackZ() { return blackZ; }
146   double getGamma() { return gamma; }
147
148 private:
149
150   double whiteX, whiteY, whiteZ;    // white point
151   double blackX, blackY, blackZ;    // black point
152   double gamma;                     // gamma value
153 };
154
155 //------------------------------------------------------------------------
156 // GfxDeviceRGBColorSpace
157 //------------------------------------------------------------------------
158
159 class GfxDeviceRGBColorSpace: public GfxColorSpace {
160 public:
161
162   GfxDeviceRGBColorSpace();
163   virtual ~GfxDeviceRGBColorSpace();
164   virtual GfxColorSpace *copy();
165   virtual GfxColorSpaceMode getMode() { return csDeviceRGB; }
166
167   virtual void getGray(GfxColor *color, double *gray);
168   virtual void getRGB(GfxColor *color, GfxRGB *rgb);
169   virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
170
171   virtual int getNComps() { return 3; }
172
173 private:
174 };
175
176 //------------------------------------------------------------------------
177 // GfxCalRGBColorSpace
178 //------------------------------------------------------------------------
179
180 class GfxCalRGBColorSpace: public GfxColorSpace {
181 public:
182
183   GfxCalRGBColorSpace();
184   virtual ~GfxCalRGBColorSpace();
185   virtual GfxColorSpace *copy();
186   virtual GfxColorSpaceMode getMode() { return csCalRGB; }
187
188   // Construct a CalRGB color space.  Returns NULL if unsuccessful.
189   static GfxColorSpace *parse(Array *arr);
190
191   virtual void getGray(GfxColor *color, double *gray);
192   virtual void getRGB(GfxColor *color, GfxRGB *rgb);
193   virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
194
195   virtual int getNComps() { return 3; }
196
197   // CalRGB-specific access.
198   double getWhiteX() { return whiteX; }
199   double getWhiteY() { return whiteY; }
200   double getWhiteZ() { return whiteZ; }
201   double getBlackX() { return blackX; }
202   double getBlackY() { return blackY; }
203   double getBlackZ() { return blackZ; }
204   double getGammaR() { return gammaR; }
205   double getGammaG() { return gammaG; }
206   double getGammaB() { return gammaB; }
207   double *getMatrix() { return mat; }
208
209 private:
210
211   double whiteX, whiteY, whiteZ;    // white point
212   double blackX, blackY, blackZ;    // black point
213   double gammaR, gammaG, gammaB;    // gamma values
214   double mat[9];                // ABC -> XYZ transform matrix
215 };
216
217 //------------------------------------------------------------------------
218 // GfxDeviceCMYKColorSpace
219 //------------------------------------------------------------------------
220
221 class GfxDeviceCMYKColorSpace: public GfxColorSpace {
222 public:
223
224   GfxDeviceCMYKColorSpace();
225   virtual ~GfxDeviceCMYKColorSpace();
226   virtual GfxColorSpace *copy();
227   virtual GfxColorSpaceMode getMode() { return csDeviceCMYK; }
228
229   virtual void getGray(GfxColor *color, double *gray);
230   virtual void getRGB(GfxColor *color, GfxRGB *rgb);
231   virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
232
233   virtual int getNComps() { return 4; }
234
235 private:
236 };
237
238 //------------------------------------------------------------------------
239 // GfxLabColorSpace
240 //------------------------------------------------------------------------
241
242 class GfxLabColorSpace: public GfxColorSpace {
243 public:
244
245   GfxLabColorSpace();
246   virtual ~GfxLabColorSpace();
247   virtual GfxColorSpace *copy();
248   virtual GfxColorSpaceMode getMode() { return csLab; }
249
250   // Construct a Lab color space.  Returns NULL if unsuccessful.
251   static GfxColorSpace *parse(Array *arr);
252
253   virtual void getGray(GfxColor *color, double *gray);
254   virtual void getRGB(GfxColor *color, GfxRGB *rgb);
255   virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
256
257   virtual int getNComps() { return 3; }
258
259   virtual void getDefaultRanges(double *decodeLow, double *decodeRange,
260                                 int maxImgPixel);
261
262   // Lab-specific access.
263   double getWhiteX() { return whiteX; }
264   double getWhiteY() { return whiteY; }
265   double getWhiteZ() { return whiteZ; }
266   double getBlackX() { return blackX; }
267   double getBlackY() { return blackY; }
268   double getBlackZ() { return blackZ; }
269   double getAMin() { return aMin; }
270   double getAMax() { return aMax; }
271   double getBMin() { return bMin; }
272   double getBMax() { return bMax; }
273
274 private:
275
276   double whiteX, whiteY, whiteZ;    // white point
277   double blackX, blackY, blackZ;    // black point
278   double aMin, aMax, bMin, bMax;    // range for the a and b components
279   double kr, kg, kb;                // gamut mapping mulitpliers
280 };
281
282 //------------------------------------------------------------------------
283 // GfxICCBasedColorSpace
284 //------------------------------------------------------------------------
285
286 class GfxICCBasedColorSpace: public GfxColorSpace {
287 public:
288
289   GfxICCBasedColorSpace(int nCompsA, GfxColorSpace *altA,
290                         Ref *iccProfileStreamA);
291   virtual ~GfxICCBasedColorSpace();
292   virtual GfxColorSpace *copy();
293   virtual GfxColorSpaceMode getMode() { return csICCBased; }
294
295   // Construct an ICCBased color space.  Returns NULL if unsuccessful.
296   static GfxColorSpace *parse(Array *arr);
297
298   virtual void getGray(GfxColor *color, double *gray);
299   virtual void getRGB(GfxColor *color, GfxRGB *rgb);
300   virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
301
302   virtual int getNComps() { return nComps; }
303
304   virtual void getDefaultRanges(double *decodeLow, double *decodeRange,
305                                 int maxImgPixel);
306
307   // ICCBased-specific access.
308   GfxColorSpace *getAlt() { return alt; }
309
310 private:
311
312   int nComps;                   // number of color components (1, 3, or 4)
313   GfxColorSpace *alt;           // alternate color space
314   double rangeMin[4];           // min values for each component
315   double rangeMax[4];           // max values for each component
316   Ref iccProfileStream;         // the ICC profile
317 };
318
319 //------------------------------------------------------------------------
320 // GfxIndexedColorSpace
321 //------------------------------------------------------------------------
322
323 class GfxIndexedColorSpace: public GfxColorSpace {
324 public:
325
326   GfxIndexedColorSpace(GfxColorSpace *baseA, int indexHighA);
327   virtual ~GfxIndexedColorSpace();
328   virtual GfxColorSpace *copy();
329   virtual GfxColorSpaceMode getMode() { return csIndexed; }
330
331   // Construct a Lab color space.  Returns NULL if unsuccessful.
332   static GfxColorSpace *parse(Array *arr);
333
334   virtual void getGray(GfxColor *color, double *gray);
335   virtual void getRGB(GfxColor *color, GfxRGB *rgb);
336   virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
337
338   virtual int getNComps() { return 1; }
339
340   virtual void getDefaultRanges(double *decodeLow, double *decodeRange,
341                                 int maxImgPixel);
342
343   // Indexed-specific access.
344   GfxColorSpace *getBase() { return base; }
345   int getIndexHigh() { return indexHigh; }
346   Guchar *getLookup() { return lookup; }
347
348 private:
349
350   GfxColorSpace *base;          // base color space
351   int indexHigh;                // max pixel value
352   Guchar *lookup;               // lookup table
353 };
354
355 //------------------------------------------------------------------------
356 // GfxSeparationColorSpace
357 //------------------------------------------------------------------------
358
359 class GfxSeparationColorSpace: public GfxColorSpace {
360 public:
361
362   GfxSeparationColorSpace(GString *nameA, GfxColorSpace *altA,
363                           Function *funcA);
364   virtual ~GfxSeparationColorSpace();
365   virtual GfxColorSpace *copy();
366   virtual GfxColorSpaceMode getMode() { return csSeparation; }
367
368   // Construct a Separation color space.  Returns NULL if unsuccessful.
369   static GfxColorSpace *parse(Array *arr);
370
371   virtual void getGray(GfxColor *color, double *gray);
372   virtual void getRGB(GfxColor *color, GfxRGB *rgb);
373   virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
374
375   virtual int getNComps() { return 1; }
376
377   // Separation-specific access.
378   GString *getName() { return name; }
379   GfxColorSpace *getAlt() { return alt; }
380   Function *getFunc() { return func; }
381
382 private:
383
384   GString *name;                // colorant name
385   GfxColorSpace *alt;           // alternate color space
386   Function *func;               // tint transform (into alternate color space)
387 };
388
389 //------------------------------------------------------------------------
390 // GfxDeviceNColorSpace
391 //------------------------------------------------------------------------
392
393 class GfxDeviceNColorSpace: public GfxColorSpace {
394 public:
395
396   GfxDeviceNColorSpace(int nComps, GfxColorSpace *alt, Function *func);
397   virtual ~GfxDeviceNColorSpace();
398   virtual GfxColorSpace *copy();
399   virtual GfxColorSpaceMode getMode() { return csDeviceN; }
400
401   // Construct a DeviceN color space.  Returns NULL if unsuccessful.
402   static GfxColorSpace *parse(Array *arr);
403
404   virtual void getGray(GfxColor *color, double *gray);
405   virtual void getRGB(GfxColor *color, GfxRGB *rgb);
406   virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
407
408   virtual int getNComps() { return nComps; }
409
410   // DeviceN-specific access.
411   GString *getColorantName(int i) { return names[i]; }
412   GfxColorSpace *getAlt() { return alt; }
413   Function *getTintTransformFunc() { return func; }
414
415 private:
416
417   int nComps;                   // number of components
418   GString                       // colorant names
419     *names[gfxColorMaxComps];
420   GfxColorSpace *alt;           // alternate color space
421   Function *func;               // tint transform (into alternate color space)
422   
423 };
424
425 //------------------------------------------------------------------------
426 // GfxPatternColorSpace
427 //------------------------------------------------------------------------
428
429 class GfxPatternColorSpace: public GfxColorSpace {
430 public:
431
432   GfxPatternColorSpace(GfxColorSpace *underA);
433   virtual ~GfxPatternColorSpace();
434   virtual GfxColorSpace *copy();
435   virtual GfxColorSpaceMode getMode() { return csPattern; }
436
437   // Construct a Pattern color space.  Returns NULL if unsuccessful.
438   static GfxColorSpace *parse(Array *arr);
439
440   virtual void getGray(GfxColor *color, double *gray);
441   virtual void getRGB(GfxColor *color, GfxRGB *rgb);
442   virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
443
444   virtual int getNComps() { return 0; }
445
446   // Pattern-specific access.
447   GfxColorSpace *getUnder() { return under; }
448
449 private:
450
451   GfxColorSpace *under;         // underlying color space (for uncolored
452                                 //   patterns)
453 };
454
455 //------------------------------------------------------------------------
456 // GfxPattern
457 //------------------------------------------------------------------------
458
459 class GfxPattern {
460 public:
461
462   GfxPattern(int typeA);
463   virtual ~GfxPattern();
464
465   static GfxPattern *parse(Object *obj);
466
467   virtual GfxPattern *copy() = 0;
468
469   int getType() { return type; }
470
471 private:
472
473   int type;
474 };
475
476 //------------------------------------------------------------------------
477 // GfxTilingPattern
478 //------------------------------------------------------------------------
479
480 class GfxTilingPattern: public GfxPattern {
481 public:
482
483   GfxTilingPattern(Dict *streamDict, Object *stream);
484   virtual ~GfxTilingPattern();
485
486   virtual GfxPattern *copy();
487
488   int getPaintType() { return paintType; }
489   int getTilingType() { return tilingType; }
490   double *getBBox() { return bbox; }
491   double getXStep() { return xStep; }
492   double getYStep() { return yStep; }
493   Dict *getResDict()
494     { return resDict.isDict() ? resDict.getDict() : (Dict *)NULL; }
495   double *getMatrix() { return matrix; }
496   Object *getContentStream() { return &contentStream; }
497
498 private:
499
500   GfxTilingPattern(GfxTilingPattern *pat);
501
502   int paintType;
503   int tilingType;
504   double bbox[4];
505   double xStep, yStep;
506   Object resDict;
507   double matrix[6];
508   Object contentStream;
509 };
510
511 //------------------------------------------------------------------------
512 // GfxShading
513 //------------------------------------------------------------------------
514
515 class GfxShading {
516 public:
517
518   GfxShading();
519   virtual ~GfxShading();
520
521   static GfxShading *parse(Object *obj);
522
523   int getType() { return type; }
524   GfxColorSpace *getColorSpace() { return colorSpace; }
525   GfxColor *getBackground() { return &background; }
526   GBool getHasBackground() { return hasBackground; }
527   void getBBox(double *xMinA, double *yMinA, double *xMaxA, double *yMaxA)
528     { *xMinA = xMin; *yMinA = yMin; *xMaxA = xMax; *yMaxA = yMax; }
529   GBool getHasBBox() { return hasBBox; }
530
531 private:
532
533   int type;
534   GfxColorSpace *colorSpace;
535   GfxColor background;
536   GBool hasBackground;
537   double xMin, yMin, xMax, yMax;
538   GBool hasBBox;
539 };
540
541 //------------------------------------------------------------------------
542 // GfxAxialShading
543 //------------------------------------------------------------------------
544
545 class GfxAxialShading: public GfxShading {
546 public:
547
548   GfxAxialShading(double x0A, double y0A,
549                   double x1A, double y1A,
550                   double t0A, double t1A,
551                   Function **funcsA, int nFuncsA,
552                   GBool extend0A, GBool extend1A);
553   virtual ~GfxAxialShading();
554
555   static GfxAxialShading *parse(Dict *dict);
556
557   void getCoords(double *x0A, double *y0A, double *x1A, double *y1A)
558     { *x0A = x0; *y0A = y0; *x1A = x1; *y1A = y1; }
559   double getDomain0() { return t0; }
560   double getDomain1() { return t1; }
561   void getColor(double t, GfxColor *color);
562   GBool getExtend0() { return extend0; }
563   GBool getExtend1() { return extend1; }
564
565 private:
566
567   double x0, y0, x1, y1;
568   double t0, t1;
569   Function *funcs[gfxColorMaxComps];
570   int nFuncs;
571   GBool extend0, extend1;
572 };
573
574 //------------------------------------------------------------------------
575 // GfxRadialShading
576 //------------------------------------------------------------------------
577
578 class GfxRadialShading: public GfxShading {
579 public:
580
581   GfxRadialShading(double x0A, double y0A, double r0A,
582                    double x1A, double y1A, double r1A,
583                    double t0A, double t1A,
584                    Function **funcsA, int nFuncsA,
585                    GBool extend0A, GBool extend1A);
586   virtual ~GfxRadialShading();
587
588   static GfxRadialShading *parse(Dict *dict);
589
590   void getCoords(double *x0A, double *y0A, double *r0A,
591                  double *x1A, double *y1A, double *r1A)
592     { *x0A = x0; *y0A = y0; *r0A = r0; *x1A = x1; *y1A = y1; *r1A = r1; }
593   double getDomain0() { return t0; }
594   double getDomain1() { return t1; }
595   void getColor(double t, GfxColor *color);
596   GBool getExtend0() { return extend0; }
597   GBool getExtend1() { return extend1; }
598
599 private:
600
601   double x0, y0, r0, x1, y1, r1;
602   double t0, t1;
603   Function *funcs[gfxColorMaxComps];
604   int nFuncs;
605   GBool extend0, extend1;
606 };
607
608 //------------------------------------------------------------------------
609 // GfxImageColorMap
610 //------------------------------------------------------------------------
611
612 class GfxImageColorMap {
613 public:
614
615   // Constructor.
616   GfxImageColorMap(int bitsA, Object *decode, GfxColorSpace *colorSpaceA);
617
618   // Destructor.
619   ~GfxImageColorMap();
620
621   // Is color map valid?
622   GBool isOk() { return ok; }
623
624   // Get the color space.
625   GfxColorSpace *getColorSpace() { return colorSpace; }
626
627   // Get stream decoding info.
628   int getNumPixelComps() { return nComps; }
629   int getBits() { return bits; }
630
631   // Get decode table.
632   double getDecodeLow(int i) { return decodeLow[i]; }
633   double getDecodeHigh(int i) { return decodeLow[i] + decodeRange[i]; }
634
635   // Convert an image pixel to a color.
636   void getGray(Guchar *x, double *gray);
637   void getRGB(Guchar *x, GfxRGB *rgb);
638   void getCMYK(Guchar *x, GfxCMYK *cmyk);
639
640 private:
641
642   GfxColorSpace *colorSpace;    // the image color space
643   int bits;                     // bits per component
644   int nComps;                   // number of components in a pixel
645   GfxColorSpace *colorSpace2;   // secondary color space
646   int nComps2;                  // number of components in colorSpace2
647   double *lookup;               // lookup table
648   double                        // minimum values for each component
649     decodeLow[gfxColorMaxComps];
650   double                        // max - min value for each component
651     decodeRange[gfxColorMaxComps];
652   GBool ok;
653 };
654
655 //------------------------------------------------------------------------
656 // GfxSubpath and GfxPath
657 //------------------------------------------------------------------------
658
659 class GfxSubpath {
660 public:
661
662   // Constructor.
663   GfxSubpath(double x1, double y1);
664
665   // Destructor.
666   ~GfxSubpath();
667
668   // Copy.
669   GfxSubpath *copy() { return new GfxSubpath(this); }
670
671   // Get points.
672   int getNumPoints() { return n; }
673   double getX(int i) { return x[i]; }
674   double getY(int i) { return y[i]; }
675   GBool getCurve(int i) { return curve[i]; }
676
677   // Get last point.
678   double getLastX() { return x[n-1]; }
679   double getLastY() { return y[n-1]; }
680
681   // Add a line segment.
682   void lineTo(double x1, double y1);
683
684   // Add a Bezier curve.
685   void curveTo(double x1, double y1, double x2, double y2,
686                double x3, double y3);
687
688   // Close the subpath.
689   void close();
690   GBool isClosed() { return closed; }
691
692 private:
693
694   double *x, *y;                // points
695   GBool *curve;                 // curve[i] => point i is a control point
696                                 //   for a Bezier curve
697   int n;                        // number of points
698   int size;                     // size of x/y arrays
699   GBool closed;                 // set if path is closed
700
701   GfxSubpath(GfxSubpath *subpath);
702 };
703
704 class GfxPath {
705 public:
706
707   // Constructor.
708   GfxPath();
709
710   // Destructor.
711   ~GfxPath();
712
713   // Copy.
714   GfxPath *copy()
715     { return new GfxPath(justMoved, firstX, firstY, subpaths, n, size); }
716
717   // Is there a current point?
718   GBool isCurPt() { return n > 0 || justMoved; }
719
720   // Is the path non-empty, i.e., is there at least one segment?
721   GBool isPath() { return n > 0; }
722
723   // Get subpaths.
724   int getNumSubpaths() { return n; }
725   GfxSubpath *getSubpath(int i) { return subpaths[i]; }
726
727   // Get last point on last subpath.
728   double getLastX() { return subpaths[n-1]->getLastX(); }
729   double getLastY() { return subpaths[n-1]->getLastY(); }
730
731   // Move the current point.
732   void moveTo(double x, double y);
733
734   // Add a segment to the last subpath.
735   void lineTo(double x, double y);
736
737   // Add a Bezier curve to the last subpath
738   void curveTo(double x1, double y1, double x2, double y2,
739                double x3, double y3);
740
741   // Close the last subpath.
742   void close();
743
744 private:
745
746   GBool justMoved;              // set if a new subpath was just started
747   double firstX, firstY;        // first point in new subpath
748   GfxSubpath **subpaths;        // subpaths
749   int n;                        // number of subpaths
750   int size;                     // size of subpaths array
751
752   GfxPath(GBool justMoved1, double firstX1, double firstY1,
753           GfxSubpath **subpaths1, int n1, int size1);
754 };
755
756 //------------------------------------------------------------------------
757 // GfxState
758 //------------------------------------------------------------------------
759
760 class GfxState {
761 public:
762
763   // Construct a default GfxState, for a device with resolution <dpi>,
764   // page box <pageBox>, page rotation <rotate>, and coordinate system
765   // specified by <upsideDown>.
766   GfxState(double dpi, PDFRectangle *pageBox, int rotate,
767            GBool upsideDown);
768
769   // Destructor.
770   ~GfxState();
771
772   // Copy.
773   GfxState *copy() { return new GfxState(this); }
774
775   // Accessors.
776   double *getCTM() { return ctm; }
777   double getX1() { return px1; }
778   double getY1() { return py1; }
779   double getX2() { return px2; }
780   double getY2() { return py2; }
781   double getPageWidth() { return pageWidth; }
782   double getPageHeight() { return pageHeight; }
783   GfxColor *getFillColor() { return &fillColor; }
784   GfxColor *getStrokeColor() { return &strokeColor; }
785   void getFillGray(double *gray)
786     { fillColorSpace->getGray(&fillColor, gray); }
787   void getStrokeGray(double *gray)
788     { strokeColorSpace->getGray(&fillColor, gray); }
789   void getFillRGB(GfxRGB *rgb)
790     { fillColorSpace->getRGB(&fillColor, rgb); }
791   void getStrokeRGB(GfxRGB *rgb)
792     { strokeColorSpace->getRGB(&strokeColor, rgb); }
793   void getFillCMYK(GfxCMYK *cmyk)
794     { fillColorSpace->getCMYK(&fillColor, cmyk); }
795   void getStrokeCMYK(GfxCMYK *cmyk)
796     { strokeColorSpace->getCMYK(&strokeColor, cmyk); }
797   GfxColorSpace *getFillColorSpace() { return fillColorSpace; }
798   GfxColorSpace *getStrokeColorSpace() { return strokeColorSpace; }
799   GfxPattern *getFillPattern() { return fillPattern; }
800   GfxPattern *getStrokePattern() { return strokePattern; }
801   double getFillOpacity() { return fillOpacity; }
802   double getStrokeOpacity() { return strokeOpacity; }
803   double getLineWidth() { return lineWidth; }
804   void getLineDash(double **dash, int *length, double *start)
805     { *dash = lineDash; *length = lineDashLength; *start = lineDashStart; }
806   int getFlatness() { return flatness; }
807   int getLineJoin() { return lineJoin; }
808   int getLineCap() { return lineCap; }
809   double getMiterLimit() { return miterLimit; }
810   GfxFont *getFont() { return font; }
811   double getFontSize() { return fontSize; }
812   double *getTextMat() { return textMat; }
813   double getCharSpace() { return charSpace; }
814   double getWordSpace() { return wordSpace; }
815   double getHorizScaling() { return horizScaling; }
816   double getLeading() { return leading; }
817   double getRise() { return rise; }
818   int getRender() { return render; }
819   GfxPath *getPath() { return path; }
820   double getCurX() { return curX; }
821   double getCurY() { return curY; }
822   void getClipBBox(double *xMin, double *yMin, double *xMax, double *yMax)
823     { *xMin = clipXMin; *yMin = clipYMin; *xMax = clipXMax; *yMax = clipYMax; }
824   void getUserClipBBox(double *xMin, double *yMin, double *xMax, double *yMax);
825   double getLineX() { return lineX; }
826   double getLineY() { return lineY; }
827
828   // Is there a current point/path?
829   GBool isCurPt() { return path->isCurPt(); }
830   GBool isPath() { return path->isPath(); }
831
832   // Transforms.
833   void transform(double x1, double y1, double *x2, double *y2)
834     { *x2 = ctm[0] * x1 + ctm[2] * y1 + ctm[4];
835       *y2 = ctm[1] * x1 + ctm[3] * y1 + ctm[5]; }
836   void transformDelta(double x1, double y1, double *x2, double *y2)
837     { *x2 = ctm[0] * x1 + ctm[2] * y1;
838       *y2 = ctm[1] * x1 + ctm[3] * y1; }
839   void textTransform(double x1, double y1, double *x2, double *y2)
840     { *x2 = textMat[0] * x1 + textMat[2] * y1 + textMat[4];
841       *y2 = textMat[1] * x1 + textMat[3] * y1 + textMat[5]; }
842   void textTransformDelta(double x1, double y1, double *x2, double *y2)
843     { *x2 = textMat[0] * x1 + textMat[2] * y1;
844       *y2 = textMat[1] * x1 + textMat[3] * y1; }
845   double transformWidth(double w);
846   double getTransformedLineWidth()
847     { return transformWidth(lineWidth); }
848   double getTransformedFontSize();
849   void getFontTransMat(double *m11, double *m12, double *m21, double *m22);
850
851   // Change state parameters.
852   void setCTM(double a, double b, double c,
853               double d, double e, double f);
854   void concatCTM(double a, double b, double c,
855                  double d, double e, double f);
856   void setFillColorSpace(GfxColorSpace *colorSpace);
857   void setStrokeColorSpace(GfxColorSpace *colorSpace);
858   void setFillColor(GfxColor *color) { fillColor = *color; }
859   void setStrokeColor(GfxColor *color) { strokeColor = *color; }
860   void setFillPattern(GfxPattern *pattern);
861   void setStrokePattern(GfxPattern *pattern);
862   void setFillOpacity(double opac) { fillOpacity = opac; }
863   void setStrokeOpacity(double opac) { strokeOpacity = opac; }
864   void setLineWidth(double width) { lineWidth = width; }
865   void setLineDash(double *dash, int length, double start);
866   void setFlatness(int flatness1) { flatness = flatness1; }
867   void setLineJoin(int lineJoin1) { lineJoin = lineJoin1; }
868   void setLineCap(int lineCap1) { lineCap = lineCap1; }
869   void setMiterLimit(double limit) { miterLimit = limit; }
870   void setFont(GfxFont *fontA, double fontSizeA)
871     { font = fontA; fontSize = fontSizeA; }
872   void setTextMat(double a, double b, double c,
873                   double d, double e, double f)
874     { textMat[0] = a; textMat[1] = b; textMat[2] = c;
875       textMat[3] = d; textMat[4] = e; textMat[5] = f; }
876   void setCharSpace(double space)
877     { charSpace = space; }
878   void setWordSpace(double space)
879     { wordSpace = space; }
880   void setHorizScaling(double scale)
881     { horizScaling = 0.01 * scale; }
882   void setLeading(double leadingA)
883     { leading = leadingA; }
884   void setRise(double riseA)
885     { rise = riseA; }
886   void setRender(int renderA)
887     { render = renderA; }
888
889   // Add to path.
890   void moveTo(double x, double y)
891     { path->moveTo(curX = x, curY = y); }
892   void lineTo(double x, double y)
893     { path->lineTo(curX = x, curY = y); }
894   void curveTo(double x1, double y1, double x2, double y2,
895                double x3, double y3)
896     { path->curveTo(x1, y1, x2, y2, curX = x3, curY = y3); }
897   void closePath()
898     { path->close(); curX = path->getLastX(); curY = path->getLastY(); }
899   void clearPath();
900
901   // Update clip region.
902   void clip();
903
904   // Text position.
905   void textMoveTo(double tx, double ty)
906     { lineX = tx; lineY = ty; textTransform(tx, ty, &curX, &curY); }
907   void textShift(double tx, double ty);
908   void shift(double dx, double dy);
909
910   // Push/pop GfxState on/off stack.
911   GfxState *save();
912   GfxState *restore();
913   GBool hasSaves() { return saved != NULL; }
914
915 private:
916
917   double ctm[6];                // coord transform matrix
918   double px1, py1, px2, py2;    // page corners (user coords)
919   double pageWidth, pageHeight; // page size (pixels)
920
921   GfxColorSpace *fillColorSpace;   // fill color space
922   GfxColorSpace *strokeColorSpace; // stroke color space
923   GfxColor fillColor;           // fill color
924   GfxColor strokeColor;         // stroke color
925   GfxPattern *fillPattern;      // fill pattern
926   GfxPattern *strokePattern;    // stroke pattern
927   double fillOpacity;           // fill opacity
928   double strokeOpacity;         // stroke opacity
929
930   double lineWidth;             // line width
931   double *lineDash;             // line dash
932   int lineDashLength;
933   double lineDashStart;
934   int flatness;                 // curve flatness
935   int lineJoin;                 // line join style
936   int lineCap;                  // line cap style
937   double miterLimit;            // line miter limit
938
939   GfxFont *font;                // font
940   double fontSize;              // font size
941   double textMat[6];            // text matrix
942   double charSpace;             // character spacing
943   double wordSpace;             // word spacing
944   double horizScaling;          // horizontal scaling
945   double leading;               // text leading
946   double rise;                  // text rise
947   int render;                   // text rendering mode
948
949   GfxPath *path;                // array of path elements
950   double curX, curY;            // current point (user coords)
951   double lineX, lineY;          // start of current text line (text coords)
952
953   double clipXMin, clipYMin,    // bounding box for clip region
954          clipXMax, clipYMax;
955
956   GfxState *saved;              // next GfxState on stack
957
958   GfxState(GfxState *state);
959 };
960
961 #endif