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