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