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