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