1
//========================================================================
5
// Copyright 1996-2003 Glyph & Cog, LLC
7
//========================================================================
9
//========================================================================
11
// Modified under the Poppler project - http://poppler.freedesktop.org
13
// All changes made under the Poppler project to this file are licensed
14
// under GPL version 2 or later
16
// Copyright (C) 2005 Kristian HĆøgsberg <krh@redhat.com>
17
// Copyright (C) 2006, 2007 Jeff Muizelaar <jeff@infidigm.net>
18
// Copyright (C) 2006 Carlos Garcia Campos <carlosgc@gnome.org>
19
// Copyright (C) 2009 Koji Otani <sho@bbr.jp>
20
// Copyright (C) 2009, 2010 Albert Astals Cid <aacid@kde.org>
21
// Copyright (C) 2010 Christian FeuersƤnger <cfeuersaenger@googlemail.com>
23
// To see a description of the changes please see the Changelog file that
24
// came with your tarball or type make ChangeLog if you are building from git
26
//========================================================================
31
#ifdef USE_GCC_PRAGMAS
35
#include "goo/gtypes.h"
52
GBool invertTo(Matrix *other);
53
void transform(double x, double y, double *tx, double *ty);
56
//------------------------------------------------------------------------
58
//------------------------------------------------------------------------
79
//------------------------------------------------------------------------
81
//------------------------------------------------------------------------
83
// 16.16 fixed point color component
84
typedef int GfxColorComp;
86
#define gfxColorComp1 0x10000
88
static inline GfxColorComp dblToCol(double x) {
89
return (GfxColorComp)(x * gfxColorComp1);
92
static inline double colToDbl(GfxColorComp x) {
93
return (double)x / (double)gfxColorComp1;
96
static inline GfxColorComp byteToCol(Guchar x) {
97
// (x / 255) << 16 = (0.0000000100000001... * x) << 16
98
// = ((x << 8) + (x) + (x >> 8) + ...) << 16
99
// = (x << 8) + (x) + (x >> 7)
101
return (GfxColorComp)((x << 8) + x + (x >> 7));
104
static inline Guchar colToByte(GfxColorComp x) {
105
// 255 * x + 0.5 = 256 * x - x + 0x8000
106
return (Guchar)(((x << 8) - x + 0x8000) >> 16);
109
//------------------------------------------------------------------------
111
//------------------------------------------------------------------------
113
#define gfxColorMaxComps funcMaxOutputs
116
GfxColorComp c[gfxColorMaxComps];
119
//------------------------------------------------------------------------
121
//------------------------------------------------------------------------
123
typedef GfxColorComp GfxGray;
125
//------------------------------------------------------------------------
127
//------------------------------------------------------------------------
130
GfxColorComp r, g, b;
133
//------------------------------------------------------------------------
135
//------------------------------------------------------------------------
138
GfxColorComp c, m, y, k;
141
//------------------------------------------------------------------------
143
//------------------------------------------------------------------------
145
// NB: The nGfxColorSpaceModes constant and the gfxColorSpaceModeNames
146
// array defined in GfxState.cc must match this enum.
147
enum GfxColorSpaceMode {
161
// wrapper of cmsHTRANSFORM to copy
162
class GfxColorTransform {
164
void doTransform(void *in, void *out, unsigned int size);
165
// transformA should be a cmsHTRANSFORM
166
GfxColorTransform(void *transformA);
167
~GfxColorTransform();
169
unsigned int unref();
171
GfxColorTransform() {}
173
unsigned int refCount;
176
class GfxColorSpace {
180
virtual ~GfxColorSpace();
181
virtual GfxColorSpace *copy() = 0;
182
virtual GfxColorSpaceMode getMode() = 0;
184
// Construct a color space. Returns NULL if unsuccessful.
185
static GfxColorSpace *parse(Object *csObj, Gfx *gfx);
187
// Convert to gray, RGB, or CMYK.
188
virtual void getGray(GfxColor *color, GfxGray *gray) = 0;
189
virtual void getRGB(GfxColor *color, GfxRGB *rgb) = 0;
190
virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk) = 0;
191
virtual void getGrayLine(Guchar * /*in*/, Guchar * /*out*/, int /*length*/) {}
192
virtual void getRGBLine(Guchar * /*in*/, unsigned int * /*out*/, int /*length*/) {}
194
// Does this ColorSpace use getRGBLine?
195
virtual GBool useGetRGBLine() { return gFalse; }
196
// Does this ColorSpace use getGrayLine?
197
virtual GBool useGetGrayLine() { return gFalse; }
199
// Return the number of color components.
200
virtual int getNComps() = 0;
202
// Get this color space's default color.
203
virtual void getDefaultColor(GfxColor *color) = 0;
205
// Return the default ranges for each component, assuming an image
206
// with a max pixel value of <maxImgPixel>.
207
virtual void getDefaultRanges(double *decodeLow, double *decodeRange,
210
// Returns true if painting operations in this color space never
211
// mark the page (e.g., the "None" colorant).
212
virtual GBool isNonMarking() { return gFalse; }
214
// Return the number of color space modes
215
static int getNumColorSpaceModes();
217
// Return the name of the <idx>th color space mode.
218
static char *getColorSpaceModeName(int idx);
221
static int setupColorProfiles();
222
// displayProfileA should be a cmsHPROFILE
223
static void setDisplayProfile(void *displayProfileA);
224
static void setDisplayProfileName(GooString *name);
225
// result will be a cmsHPROFILE
226
static void *getRGBProfile();
227
// result will be a cmsHPROFILE
228
static void *getDisplayProfile();
232
//------------------------------------------------------------------------
233
// GfxDeviceGrayColorSpace
234
//------------------------------------------------------------------------
236
class GfxDeviceGrayColorSpace: public GfxColorSpace {
239
GfxDeviceGrayColorSpace();
240
virtual ~GfxDeviceGrayColorSpace();
241
virtual GfxColorSpace *copy();
242
virtual GfxColorSpaceMode getMode() { return csDeviceGray; }
244
virtual void getGray(GfxColor *color, GfxGray *gray);
245
virtual void getRGB(GfxColor *color, GfxRGB *rgb);
246
virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
247
virtual void getGrayLine(Guchar *in, Guchar *out, int length);
248
virtual void getRGBLine(Guchar *in, unsigned int *out, int length);
250
virtual GBool useGetRGBLine() { return gTrue; }
251
virtual GBool useGetGrayLine() { return gTrue; }
253
virtual int getNComps() { return 1; }
254
virtual void getDefaultColor(GfxColor *color);
259
//------------------------------------------------------------------------
260
// GfxCalGrayColorSpace
261
//------------------------------------------------------------------------
263
class GfxCalGrayColorSpace: public GfxColorSpace {
266
GfxCalGrayColorSpace();
267
virtual ~GfxCalGrayColorSpace();
268
virtual GfxColorSpace *copy();
269
virtual GfxColorSpaceMode getMode() { return csCalGray; }
271
// Construct a CalGray color space. Returns NULL if unsuccessful.
272
static GfxColorSpace *parse(Array *arr);
274
virtual void getGray(GfxColor *color, GfxGray *gray);
275
virtual void getRGB(GfxColor *color, GfxRGB *rgb);
276
virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
278
virtual int getNComps() { return 1; }
279
virtual void getDefaultColor(GfxColor *color);
281
// CalGray-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 getGamma() { return gamma; }
292
double whiteX, whiteY, whiteZ; // white point
293
double blackX, blackY, blackZ; // black point
294
double gamma; // gamma value
295
double kr, kg, kb; // gamut mapping mulitpliers
296
void getXYZ(GfxColor *color, double *pX, double *pY, double *pZ);
299
//------------------------------------------------------------------------
300
// GfxDeviceRGBColorSpace
301
//------------------------------------------------------------------------
303
class GfxDeviceRGBColorSpace: public GfxColorSpace {
306
GfxDeviceRGBColorSpace();
307
virtual ~GfxDeviceRGBColorSpace();
308
virtual GfxColorSpace *copy();
309
virtual GfxColorSpaceMode getMode() { return csDeviceRGB; }
311
virtual void getGray(GfxColor *color, GfxGray *gray);
312
virtual void getRGB(GfxColor *color, GfxRGB *rgb);
313
virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
314
virtual void getGrayLine(Guchar *in, Guchar *out, int length);
315
virtual void getRGBLine(Guchar *in, unsigned int *out, int length);
317
virtual GBool useGetRGBLine() { return gTrue; }
318
virtual GBool useGetGrayLine() { return gTrue; }
320
virtual int getNComps() { return 3; }
321
virtual void getDefaultColor(GfxColor *color);
326
//------------------------------------------------------------------------
327
// GfxCalRGBColorSpace
328
//------------------------------------------------------------------------
330
class GfxCalRGBColorSpace: public GfxColorSpace {
333
GfxCalRGBColorSpace();
334
virtual ~GfxCalRGBColorSpace();
335
virtual GfxColorSpace *copy();
336
virtual GfxColorSpaceMode getMode() { return csCalRGB; }
338
// Construct a CalRGB color space. Returns NULL if unsuccessful.
339
static GfxColorSpace *parse(Array *arr);
341
virtual void getGray(GfxColor *color, GfxGray *gray);
342
virtual void getRGB(GfxColor *color, GfxRGB *rgb);
343
virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
345
virtual int getNComps() { return 3; }
346
virtual void getDefaultColor(GfxColor *color);
348
// CalRGB-specific access.
349
double getWhiteX() { return whiteX; }
350
double getWhiteY() { return whiteY; }
351
double getWhiteZ() { return whiteZ; }
352
double getBlackX() { return blackX; }
353
double getBlackY() { return blackY; }
354
double getBlackZ() { return blackZ; }
355
double getGammaR() { return gammaR; }
356
double getGammaG() { return gammaG; }
357
double getGammaB() { return gammaB; }
358
double *getMatrix() { return mat; }
362
double whiteX, whiteY, whiteZ; // white point
363
double blackX, blackY, blackZ; // black point
364
double gammaR, gammaG, gammaB; // gamma values
365
double mat[9]; // ABC -> XYZ transform matrix
366
double kr, kg, kb; // gamut mapping mulitpliers
367
void getXYZ(GfxColor *color, double *pX, double *pY, double *pZ);
370
//------------------------------------------------------------------------
371
// GfxDeviceCMYKColorSpace
372
//------------------------------------------------------------------------
374
class GfxDeviceCMYKColorSpace: public GfxColorSpace {
377
GfxDeviceCMYKColorSpace();
378
virtual ~GfxDeviceCMYKColorSpace();
379
virtual GfxColorSpace *copy();
380
virtual GfxColorSpaceMode getMode() { return csDeviceCMYK; }
382
virtual void getGray(GfxColor *color, GfxGray *gray);
383
virtual void getRGB(GfxColor *color, GfxRGB *rgb);
384
virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
386
virtual int getNComps() { return 4; }
387
virtual void getDefaultColor(GfxColor *color);
392
//------------------------------------------------------------------------
394
//------------------------------------------------------------------------
396
class GfxLabColorSpace: public GfxColorSpace {
400
virtual ~GfxLabColorSpace();
401
virtual GfxColorSpace *copy();
402
virtual GfxColorSpaceMode getMode() { return csLab; }
404
// Construct a Lab color space. Returns NULL if unsuccessful.
405
static GfxColorSpace *parse(Array *arr);
407
virtual void getGray(GfxColor *color, GfxGray *gray);
408
virtual void getRGB(GfxColor *color, GfxRGB *rgb);
409
virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
411
virtual int getNComps() { return 3; }
412
virtual void getDefaultColor(GfxColor *color);
414
virtual void getDefaultRanges(double *decodeLow, double *decodeRange,
417
// Lab-specific access.
418
double getWhiteX() { return whiteX; }
419
double getWhiteY() { return whiteY; }
420
double getWhiteZ() { return whiteZ; }
421
double getBlackX() { return blackX; }
422
double getBlackY() { return blackY; }
423
double getBlackZ() { return blackZ; }
424
double getAMin() { return aMin; }
425
double getAMax() { return aMax; }
426
double getBMin() { return bMin; }
427
double getBMax() { return bMax; }
431
double whiteX, whiteY, whiteZ; // white point
432
double blackX, blackY, blackZ; // black point
433
double aMin, aMax, bMin, bMax; // range for the a and b components
434
double kr, kg, kb; // gamut mapping mulitpliers
435
void getXYZ(GfxColor *color, double *pX, double *pY, double *pZ);
438
//------------------------------------------------------------------------
439
// GfxICCBasedColorSpace
440
//------------------------------------------------------------------------
442
class GfxICCBasedColorSpace: public GfxColorSpace {
445
GfxICCBasedColorSpace(int nCompsA, GfxColorSpace *altA,
446
Ref *iccProfileStreamA);
447
virtual ~GfxICCBasedColorSpace();
448
virtual GfxColorSpace *copy();
449
virtual GfxColorSpaceMode getMode() { return csICCBased; }
451
// Construct an ICCBased color space. Returns NULL if unsuccessful.
452
static GfxColorSpace *parse(Array *arr, Gfx *gfx);
454
virtual void getGray(GfxColor *color, GfxGray *gray);
455
virtual void getRGB(GfxColor *color, GfxRGB *rgb);
456
virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
457
virtual void getRGBLine(Guchar *in, unsigned int *out, int length);
459
virtual GBool useGetRGBLine();
461
virtual int getNComps() { return nComps; }
462
virtual void getDefaultColor(GfxColor *color);
464
virtual void getDefaultRanges(double *decodeLow, double *decodeRange,
467
// ICCBased-specific access.
468
GfxColorSpace *getAlt() { return alt; }
472
int nComps; // number of color components (1, 3, or 4)
473
GfxColorSpace *alt; // alternate color space
474
double rangeMin[4]; // min values for each component
475
double rangeMax[4]; // max values for each component
476
Ref iccProfileStream; // the ICC profile
478
GfxColorTransform *transform;
479
GfxColorTransform *lineTransform; // color transform for line
482
//------------------------------------------------------------------------
483
// GfxIndexedColorSpace
484
//------------------------------------------------------------------------
486
class GfxIndexedColorSpace: public GfxColorSpace {
489
GfxIndexedColorSpace(GfxColorSpace *baseA, int indexHighA);
490
virtual ~GfxIndexedColorSpace();
491
virtual GfxColorSpace *copy();
492
virtual GfxColorSpaceMode getMode() { return csIndexed; }
494
// Construct a Lab color space. Returns NULL if unsuccessful.
495
static GfxColorSpace *parse(Array *arr, Gfx *gfx);
497
virtual void getGray(GfxColor *color, GfxGray *gray);
498
virtual void getRGB(GfxColor *color, GfxRGB *rgb);
499
virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
500
virtual void getRGBLine(Guchar *in, unsigned int *out, int length);
502
virtual GBool useGetRGBLine() { return gTrue; }
504
virtual int getNComps() { return 1; }
505
virtual void getDefaultColor(GfxColor *color);
507
virtual void getDefaultRanges(double *decodeLow, double *decodeRange,
510
// Indexed-specific access.
511
GfxColorSpace *getBase() { return base; }
512
int getIndexHigh() { return indexHigh; }
513
Guchar *getLookup() { return lookup; }
514
GfxColor *mapColorToBase(GfxColor *color, GfxColor *baseColor);
518
GfxColorSpace *base; // base color space
519
int indexHigh; // max pixel value
520
Guchar *lookup; // lookup table
523
//------------------------------------------------------------------------
524
// GfxSeparationColorSpace
525
//------------------------------------------------------------------------
527
class GfxSeparationColorSpace: public GfxColorSpace {
530
GfxSeparationColorSpace(GooString *nameA, GfxColorSpace *altA,
532
virtual ~GfxSeparationColorSpace();
533
virtual GfxColorSpace *copy();
534
virtual GfxColorSpaceMode getMode() { return csSeparation; }
536
// Construct a Separation color space. Returns NULL if unsuccessful.
537
static GfxColorSpace *parse(Array *arr, Gfx *gfx);
539
virtual void getGray(GfxColor *color, GfxGray *gray);
540
virtual void getRGB(GfxColor *color, GfxRGB *rgb);
541
virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
543
virtual int getNComps() { return 1; }
544
virtual void getDefaultColor(GfxColor *color);
546
virtual GBool isNonMarking() { return nonMarking; }
548
// Separation-specific access.
549
GooString *getName() { return name; }
550
GfxColorSpace *getAlt() { return alt; }
551
Function *getFunc() { return func; }
555
GooString *name; // colorant name
556
GfxColorSpace *alt; // alternate color space
557
Function *func; // tint transform (into alternate color space)
561
//------------------------------------------------------------------------
562
// GfxDeviceNColorSpace
563
//------------------------------------------------------------------------
565
class GfxDeviceNColorSpace: public GfxColorSpace {
568
GfxDeviceNColorSpace(int nCompsA, GfxColorSpace *alt, Function *func);
569
virtual ~GfxDeviceNColorSpace();
570
virtual GfxColorSpace *copy();
571
virtual GfxColorSpaceMode getMode() { return csDeviceN; }
573
// Construct a DeviceN color space. Returns NULL if unsuccessful.
574
static GfxColorSpace *parse(Array *arr, Gfx *gfx);
576
virtual void getGray(GfxColor *color, GfxGray *gray);
577
virtual void getRGB(GfxColor *color, GfxRGB *rgb);
578
virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
580
virtual int getNComps() { return nComps; }
581
virtual void getDefaultColor(GfxColor *color);
583
virtual GBool isNonMarking() { return nonMarking; }
585
// DeviceN-specific access.
586
GooString *getColorantName(int i) { return names[i]; }
587
GfxColorSpace *getAlt() { return alt; }
588
Function *getTintTransformFunc() { return func; }
592
int nComps; // number of components
593
GooString // colorant names
594
*names[gfxColorMaxComps];
595
GfxColorSpace *alt; // alternate color space
596
Function *func; // tint transform (into alternate color space)
600
//------------------------------------------------------------------------
601
// GfxPatternColorSpace
602
//------------------------------------------------------------------------
604
class GfxPatternColorSpace: public GfxColorSpace {
607
GfxPatternColorSpace(GfxColorSpace *underA);
608
virtual ~GfxPatternColorSpace();
609
virtual GfxColorSpace *copy();
610
virtual GfxColorSpaceMode getMode() { return csPattern; }
612
// Construct a Pattern color space. Returns NULL if unsuccessful.
613
static GfxColorSpace *parse(Array *arr, Gfx *gfx);
615
virtual void getGray(GfxColor *color, GfxGray *gray);
616
virtual void getRGB(GfxColor *color, GfxRGB *rgb);
617
virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
619
virtual int getNComps() { return 0; }
620
virtual void getDefaultColor(GfxColor *color);
622
// Pattern-specific access.
623
GfxColorSpace *getUnder() { return under; }
627
GfxColorSpace *under; // underlying color space (for uncolored
631
//------------------------------------------------------------------------
633
//------------------------------------------------------------------------
638
GfxPattern(int typeA);
639
virtual ~GfxPattern();
641
static GfxPattern *parse(Object *obj, Gfx *gfx);
643
virtual GfxPattern *copy() = 0;
645
int getType() { return type; }
652
//------------------------------------------------------------------------
654
//------------------------------------------------------------------------
656
class GfxTilingPattern: public GfxPattern {
659
static GfxTilingPattern *parse(Object *patObj);
660
virtual ~GfxTilingPattern();
662
virtual GfxPattern *copy();
664
int getPaintType() { return paintType; }
665
int getTilingType() { return tilingType; }
666
double *getBBox() { return bbox; }
667
double getXStep() { return xStep; }
668
double getYStep() { return yStep; }
670
{ return resDict.isDict() ? resDict.getDict() : (Dict *)NULL; }
671
double *getMatrix() { return matrix; }
672
Object *getContentStream() { return &contentStream; }
676
GfxTilingPattern(int paintTypeA, int tilingTypeA,
677
double *bboxA, double xStepA, double yStepA,
678
Object *resDictA, double *matrixA,
679
Object *contentStreamA);
687
Object contentStream;
690
//------------------------------------------------------------------------
692
//------------------------------------------------------------------------
694
class GfxShadingPattern: public GfxPattern {
697
static GfxShadingPattern *parse(Object *patObj, Gfx *gfx);
698
virtual ~GfxShadingPattern();
700
virtual GfxPattern *copy();
702
GfxShading *getShading() { return shading; }
703
double *getMatrix() { return matrix; }
707
GfxShadingPattern(GfxShading *shadingA, double *matrixA);
713
//------------------------------------------------------------------------
715
//------------------------------------------------------------------------
720
GfxShading(int typeA);
721
GfxShading(GfxShading *shading);
722
virtual ~GfxShading();
724
static GfxShading *parse(Object *obj, Gfx *gfx);
726
virtual GfxShading *copy() = 0;
728
int getType() { return type; }
729
GfxColorSpace *getColorSpace() { return colorSpace; }
730
GfxColor *getBackground() { return &background; }
731
GBool getHasBackground() { return hasBackground; }
732
void getBBox(double *xMinA, double *yMinA, double *xMaxA, double *yMaxA)
733
{ *xMinA = xMin; *yMinA = yMin; *xMaxA = xMax; *yMaxA = yMax; }
734
GBool getHasBBox() { return hasBBox; }
738
GBool init(Dict *dict, Gfx *gfx);
741
GfxColorSpace *colorSpace;
744
double xMin, yMin, xMax, yMax;
748
//------------------------------------------------------------------------
749
// GfxFunctionShading
750
//------------------------------------------------------------------------
752
class GfxFunctionShading: public GfxShading {
755
GfxFunctionShading(double x0A, double y0A,
756
double x1A, double y1A,
758
Function **funcsA, int nFuncsA);
759
GfxFunctionShading(GfxFunctionShading *shading);
760
virtual ~GfxFunctionShading();
762
static GfxFunctionShading *parse(Dict *dict, Gfx *gfx);
764
virtual GfxShading *copy();
766
void getDomain(double *x0A, double *y0A, double *x1A, double *y1A)
767
{ *x0A = x0; *y0A = y0; *x1A = x1; *y1A = y1; }
768
double *getMatrix() { return matrix; }
769
int getNFuncs() { return nFuncs; }
770
Function *getFunc(int i) { return funcs[i]; }
771
void getColor(double x, double y, GfxColor *color);
775
double x0, y0, x1, y1;
777
Function *funcs[gfxColorMaxComps];
781
//------------------------------------------------------------------------
783
//------------------------------------------------------------------------
785
class GfxAxialShading: public GfxShading {
788
GfxAxialShading(double x0A, double y0A,
789
double x1A, double y1A,
790
double t0A, double t1A,
791
Function **funcsA, int nFuncsA,
792
GBool extend0A, GBool extend1A);
793
GfxAxialShading(GfxAxialShading *shading);
794
virtual ~GfxAxialShading();
796
static GfxAxialShading *parse(Dict *dict, Gfx *gfx);
798
virtual GfxShading *copy();
800
void getCoords(double *x0A, double *y0A, double *x1A, double *y1A)
801
{ *x0A = x0; *y0A = y0; *x1A = x1; *y1A = y1; }
802
double getDomain0() { return t0; }
803
double getDomain1() { return t1; }
804
GBool getExtend0() { return extend0; }
805
GBool getExtend1() { return extend1; }
806
int getNFuncs() { return nFuncs; }
807
Function *getFunc(int i) { return funcs[i]; }
808
void getColor(double t, GfxColor *color);
812
double x0, y0, x1, y1;
814
Function *funcs[gfxColorMaxComps];
816
GBool extend0, extend1;
819
//------------------------------------------------------------------------
821
//------------------------------------------------------------------------
823
class GfxRadialShading: public GfxShading {
826
GfxRadialShading(double x0A, double y0A, double r0A,
827
double x1A, double y1A, double r1A,
828
double t0A, double t1A,
829
Function **funcsA, int nFuncsA,
830
GBool extend0A, GBool extend1A);
831
GfxRadialShading(GfxRadialShading *shading);
832
virtual ~GfxRadialShading();
834
static GfxRadialShading *parse(Dict *dict, Gfx *gfx);
836
virtual GfxShading *copy();
838
void getCoords(double *x0A, double *y0A, double *r0A,
839
double *x1A, double *y1A, double *r1A)
840
{ *x0A = x0; *y0A = y0; *r0A = r0; *x1A = x1; *y1A = y1; *r1A = r1; }
841
double getDomain0() { return t0; }
842
double getDomain1() { return t1; }
843
GBool getExtend0() { return extend0; }
844
GBool getExtend1() { return extend1; }
845
int getNFuncs() { return nFuncs; }
846
Function *getFunc(int i) { return funcs[i]; }
847
void getColor(double t, GfxColor *color);
851
double x0, y0, r0, x1, y1, r1;
853
Function *funcs[gfxColorMaxComps];
855
GBool extend0, extend1;
858
//------------------------------------------------------------------------
859
// GfxGouraudTriangleShading
860
//------------------------------------------------------------------------
862
struct GfxGouraudVertex {
867
class GfxGouraudTriangleShading: public GfxShading {
870
GfxGouraudTriangleShading(int typeA,
871
GfxGouraudVertex *verticesA, int nVerticesA,
872
int (*trianglesA)[3], int nTrianglesA,
873
Function **funcsA, int nFuncsA);
874
GfxGouraudTriangleShading(GfxGouraudTriangleShading *shading);
875
virtual ~GfxGouraudTriangleShading();
877
static GfxGouraudTriangleShading *parse(int typeA, Dict *dict, Stream *str, Gfx *gfx);
879
virtual GfxShading *copy();
881
int getNTriangles() { return nTriangles; }
883
bool isParameterized() const { return nFuncs > 0; }
886
* @precondition isParameterized() == true
888
double getParameterDomainMin() const { assert(isParameterized()); return funcs[0]->getDomainMin(0); }
891
* @precondition isParameterized() == true
893
double getParameterDomainMax() const { assert(isParameterized()); return funcs[0]->getDomainMax(0); }
896
* @precondition isParameterized() == false
898
void getTriangle(int i, double *x0, double *y0, GfxColor *color0,
899
double *x1, double *y1, GfxColor *color1,
900
double *x2, double *y2, GfxColor *color2);
903
* Variant for functions.
905
* @precondition isParameterized() == true
907
void getTriangle(int i, double *x0, double *y0, double *color0,
908
double *x1, double *y1, double *color1,
909
double *x2, double *y2, double *color2);
911
void getParameterizedColor(double t, GfxColor *color);
915
GfxGouraudVertex *vertices;
919
Function *funcs[gfxColorMaxComps];
923
//------------------------------------------------------------------------
924
// GfxPatchMeshShading
925
//------------------------------------------------------------------------
928
* A tensor product cubic bezier patch consisting of 4x4 points and 4 color
931
* See the Shading Type 7 specifications. Note that Shading Type 6 is also
932
* represented using GfxPatch.
936
* Represents a single color value for the patch.
940
* For parameterized patches, only element 0 is valid; it contains
941
* the single parameter.
943
* For non-parameterized patches, c contains all color components
944
* as decoded from the input stream. In this case, you will need to
945
* use dblToCol() before assigning them to GfxColor.
947
double c[gfxColorMaxComps];
952
ColorValue color[2][2];
955
class GfxPatchMeshShading: public GfxShading {
958
GfxPatchMeshShading(int typeA, GfxPatch *patchesA, int nPatchesA,
959
Function **funcsA, int nFuncsA);
960
GfxPatchMeshShading(GfxPatchMeshShading *shading);
961
virtual ~GfxPatchMeshShading();
963
static GfxPatchMeshShading *parse(int typeA, Dict *dict, Stream *str, Gfx *gfx);
965
virtual GfxShading *copy();
967
int getNPatches() { return nPatches; }
968
GfxPatch *getPatch(int i) { return &patches[i]; }
970
bool isParameterized() const { return nFuncs > 0; }
973
* @precondition isParameterized() == true
975
double getParameterDomainMin() const { assert(isParameterized()); return funcs[0]->getDomainMin(0); }
978
* @precondition isParameterized() == true
980
double getParameterDomainMax() const { assert(isParameterized()); return funcs[0]->getDomainMax(0); }
982
void getParameterizedColor(double t, GfxColor *color);
988
Function *funcs[gfxColorMaxComps];
992
//------------------------------------------------------------------------
994
//------------------------------------------------------------------------
996
class GfxImageColorMap {
1000
GfxImageColorMap(int bitsA, Object *decode, GfxColorSpace *colorSpaceA);
1003
~GfxImageColorMap();
1005
// Return a copy of this color map.
1006
GfxImageColorMap *copy() { return new GfxImageColorMap(this); }
1008
// Is color map valid?
1009
GBool isOk() { return ok; }
1011
// Get the color space.
1012
GfxColorSpace *getColorSpace() { return colorSpace; }
1014
// Get stream decoding info.
1015
int getNumPixelComps() { return nComps; }
1016
int getBits() { return bits; }
1018
// Get decode table.
1019
double getDecodeLow(int i) { return decodeLow[i]; }
1020
double getDecodeHigh(int i) { return decodeLow[i] + decodeRange[i]; }
1022
bool useRGBLine() { return (colorSpace2 && colorSpace2->useGetRGBLine ()) || (!colorSpace2 && colorSpace->useGetRGBLine ()); }
1024
// Convert an image pixel to a color.
1025
void getGray(Guchar *x, GfxGray *gray);
1026
void getRGB(Guchar *x, GfxRGB *rgb);
1027
void getRGBLine(Guchar *in, unsigned int *out, int length);
1028
void getGrayLine(Guchar *in, Guchar *out, int length);
1029
void getCMYK(Guchar *x, GfxCMYK *cmyk);
1030
void getColor(Guchar *x, GfxColor *color);
1034
GfxImageColorMap(GfxImageColorMap *colorMap);
1036
GfxColorSpace *colorSpace; // the image color space
1037
int bits; // bits per component
1038
int nComps; // number of components in a pixel
1039
GfxColorSpace *colorSpace2; // secondary color space
1040
int nComps2; // number of components in colorSpace2
1041
GfxColorComp * // lookup table
1042
lookup[gfxColorMaxComps];
1043
Guchar *byte_lookup;
1044
double // minimum values for each component
1045
decodeLow[gfxColorMaxComps];
1046
double // max - min value for each component
1047
decodeRange[gfxColorMaxComps];
1051
//------------------------------------------------------------------------
1052
// GfxSubpath and GfxPath
1053
//------------------------------------------------------------------------
1059
GfxSubpath(double x1, double y1);
1065
GfxSubpath *copy() { return new GfxSubpath(this); }
1068
int getNumPoints() { return n; }
1069
double getX(int i) { return x[i]; }
1070
double getY(int i) { return y[i]; }
1071
GBool getCurve(int i) { return curve[i]; }
1073
void setX(int i, double a) { x[i] = a; }
1074
void setY(int i, double a) { y[i] = a; }
1077
double getLastX() { return x[n-1]; }
1078
double getLastY() { return y[n-1]; }
1080
// Add a line segment.
1081
void lineTo(double x1, double y1);
1083
// Add a Bezier curve.
1084
void curveTo(double x1, double y1, double x2, double y2,
1085
double x3, double y3);
1087
// Close the subpath.
1089
GBool isClosed() { return closed; }
1091
// Add (<dx>, <dy>) to each point in the subpath.
1092
void offset(double dx, double dy);
1096
double *x, *y; // points
1097
GBool *curve; // curve[i] => point i is a control point
1098
// for a Bezier curve
1099
int n; // number of points
1100
int size; // size of x/y arrays
1101
GBool closed; // set if path is closed
1103
GfxSubpath(GfxSubpath *subpath);
1117
{ return new GfxPath(justMoved, firstX, firstY, subpaths, n, size); }
1119
// Is there a current point?
1120
GBool isCurPt() { return n > 0 || justMoved; }
1122
// Is the path non-empty, i.e., is there at least one segment?
1123
GBool isPath() { return n > 0; }
1126
int getNumSubpaths() { return n; }
1127
GfxSubpath *getSubpath(int i) { return subpaths[i]; }
1129
// Get last point on last subpath.
1130
double getLastX() { return subpaths[n-1]->getLastX(); }
1131
double getLastY() { return subpaths[n-1]->getLastY(); }
1133
// Move the current point.
1134
void moveTo(double x, double y);
1136
// Add a segment to the last subpath.
1137
void lineTo(double x, double y);
1139
// Add a Bezier curve to the last subpath
1140
void curveTo(double x1, double y1, double x2, double y2,
1141
double x3, double y3);
1143
// Close the last subpath.
1146
// Append <path> to <this>.
1147
void append(GfxPath *path);
1149
// Add (<dx>, <dy>) to each point in the path.
1150
void offset(double dx, double dy);
1154
GBool justMoved; // set if a new subpath was just started
1155
double firstX, firstY; // first point in new subpath
1156
GfxSubpath **subpaths; // subpaths
1157
int n; // number of subpaths
1158
int size; // size of subpaths array
1160
GfxPath(GBool justMoved1, double firstX1, double firstY1,
1161
GfxSubpath **subpaths1, int n1, int size1);
1164
//------------------------------------------------------------------------
1166
//------------------------------------------------------------------------
1171
* When GfxState::getReusablePath() is invoked, the currently active
1172
* path is taken per reference and its coordinates can be re-edited.
1174
* A ReusablePathIterator is intented to reduce overhead when the same
1175
* path type is used a lot of times, only with different coordinates. It
1176
* allows just to update the coordinates (occuring in the same order as
1177
* in the original path).
1179
class ReusablePathIterator {
1182
* Creates the ReusablePathIterator. This should only be done from
1183
* GfxState::getReusablePath().
1185
* @param path the path as it is used so far. Changing this path,
1186
* deleting it or starting a new path from scratch will most likely
1187
* invalidate the iterator (and may cause serious problems). Make
1188
* sure the path's memory structure is not changed during the
1189
* lifetime of the ReusablePathIterator.
1191
ReusablePathIterator( GfxPath* path );
1194
* Returns true if and only if the current iterator position is
1195
* beyond the last valid point.
1197
* A call to setCoord() will be undefined.
1202
* Advances the iterator.
1207
* Updates the coordinates associated to the current iterator
1210
void setCoord( double x, double y );
1213
* Resets the iterator.
1223
GfxSubpath *curSubPath;
1226
// Construct a default GfxState, for a device with resolution <hDPI>
1227
// x <vDPI>, page box <pageBox>, page rotation <rotateA>, and
1228
// coordinate system specified by <upsideDown>.
1229
GfxState(double hDPIA, double vDPIA, PDFRectangle *pageBox,
1230
int rotateA, GBool upsideDown);
1236
GfxState *copy() { return new GfxState(this); }
1239
double getHDPI() { return hDPI; }
1240
double getVDPI() { return vDPI; }
1241
double *getCTM() { return ctm; }
1242
void getCTM(Matrix *m) { memcpy (m->m, ctm, sizeof m->m); }
1243
double getX1() { return px1; }
1244
double getY1() { return py1; }
1245
double getX2() { return px2; }
1246
double getY2() { return py2; }
1247
double getPageWidth() { return pageWidth; }
1248
double getPageHeight() { return pageHeight; }
1249
int getRotate() { return rotate; }
1250
GfxColor *getFillColor() { return &fillColor; }
1251
GfxColor *getStrokeColor() { return &strokeColor; }
1252
void getFillGray(GfxGray *gray)
1253
{ fillColorSpace->getGray(&fillColor, gray); }
1254
void getStrokeGray(GfxGray *gray)
1255
{ strokeColorSpace->getGray(&strokeColor, gray); }
1256
void getFillRGB(GfxRGB *rgb)
1257
{ fillColorSpace->getRGB(&fillColor, rgb); }
1258
void getStrokeRGB(GfxRGB *rgb)
1259
{ strokeColorSpace->getRGB(&strokeColor, rgb); }
1260
void getFillCMYK(GfxCMYK *cmyk)
1261
{ fillColorSpace->getCMYK(&fillColor, cmyk); }
1262
void getStrokeCMYK(GfxCMYK *cmyk)
1263
{ strokeColorSpace->getCMYK(&strokeColor, cmyk); }
1264
GfxColorSpace *getFillColorSpace() { return fillColorSpace; }
1265
GfxColorSpace *getStrokeColorSpace() { return strokeColorSpace; }
1266
GfxPattern *getFillPattern() { return fillPattern; }
1267
GfxPattern *getStrokePattern() { return strokePattern; }
1268
GfxBlendMode getBlendMode() { return blendMode; }
1269
double getFillOpacity() { return fillOpacity; }
1270
double getStrokeOpacity() { return strokeOpacity; }
1271
GBool getFillOverprint() { return fillOverprint; }
1272
GBool getStrokeOverprint() { return strokeOverprint; }
1273
Function **getTransfer() { return transfer; }
1274
double getLineWidth() { return lineWidth; }
1275
void getLineDash(double **dash, int *length, double *start)
1276
{ *dash = lineDash; *length = lineDashLength; *start = lineDashStart; }
1277
int getFlatness() { return flatness; }
1278
int getLineJoin() { return lineJoin; }
1279
int getLineCap() { return lineCap; }
1280
double getMiterLimit() { return miterLimit; }
1281
GBool getStrokeAdjust() { return strokeAdjust; }
1282
GBool getAlphaIsShape() { return alphaIsShape; }
1283
GBool getTextKnockout() { return textKnockout; }
1284
GfxFont *getFont() { return font; }
1285
double getFontSize() { return fontSize; }
1286
double *getTextMat() { return textMat; }
1287
double getCharSpace() { return charSpace; }
1288
double getWordSpace() { return wordSpace; }
1289
double getHorizScaling() { return horizScaling; }
1290
double getLeading() { return leading; }
1291
double getRise() { return rise; }
1292
int getRender() { return render; }
1293
GfxPath *getPath() { return path; }
1294
void setPath(GfxPath *pathA);
1295
double getCurX() { return curX; }
1296
double getCurY() { return curY; }
1297
void getClipBBox(double *xMin, double *yMin, double *xMax, double *yMax)
1298
{ *xMin = clipXMin; *yMin = clipYMin; *xMax = clipXMax; *yMax = clipYMax; }
1299
void getUserClipBBox(double *xMin, double *yMin, double *xMax, double *yMax);
1300
double getLineX() { return lineX; }
1301
double getLineY() { return lineY; }
1303
// Is there a current point/path?
1304
GBool isCurPt() { return path->isCurPt(); }
1305
GBool isPath() { return path->isPath(); }
1308
void transform(double x1, double y1, double *x2, double *y2)
1309
{ *x2 = ctm[0] * x1 + ctm[2] * y1 + ctm[4];
1310
*y2 = ctm[1] * x1 + ctm[3] * y1 + ctm[5]; }
1311
void transformDelta(double x1, double y1, double *x2, double *y2)
1312
{ *x2 = ctm[0] * x1 + ctm[2] * y1;
1313
*y2 = ctm[1] * x1 + ctm[3] * y1; }
1314
void textTransform(double x1, double y1, double *x2, double *y2)
1315
{ *x2 = textMat[0] * x1 + textMat[2] * y1 + textMat[4];
1316
*y2 = textMat[1] * x1 + textMat[3] * y1 + textMat[5]; }
1317
void textTransformDelta(double x1, double y1, double *x2, double *y2)
1318
{ *x2 = textMat[0] * x1 + textMat[2] * y1;
1319
*y2 = textMat[1] * x1 + textMat[3] * y1; }
1320
double transformWidth(double w);
1321
double getTransformedLineWidth()
1322
{ return transformWidth(lineWidth); }
1323
double getTransformedFontSize();
1324
void getFontTransMat(double *m11, double *m12, double *m21, double *m22);
1326
// Change state parameters.
1327
void setCTM(double a, double b, double c,
1328
double d, double e, double f);
1329
void concatCTM(double a, double b, double c,
1330
double d, double e, double f);
1331
void shiftCTM(double tx, double ty);
1332
void setFillColorSpace(GfxColorSpace *colorSpace);
1333
void setStrokeColorSpace(GfxColorSpace *colorSpace);
1334
void setFillColor(GfxColor *color) { fillColor = *color; }
1335
void setStrokeColor(GfxColor *color) { strokeColor = *color; }
1336
void setFillPattern(GfxPattern *pattern);
1337
void setStrokePattern(GfxPattern *pattern);
1338
void setBlendMode(GfxBlendMode mode) { blendMode = mode; }
1339
void setFillOpacity(double opac) { fillOpacity = opac; }
1340
void setStrokeOpacity(double opac) { strokeOpacity = opac; }
1341
void setFillOverprint(GBool op) { fillOverprint = op; }
1342
void setStrokeOverprint(GBool op) { strokeOverprint = op; }
1343
void setTransfer(Function **funcs);
1344
void setLineWidth(double width) { lineWidth = width; }
1345
void setLineDash(double *dash, int length, double start);
1346
void setFlatness(int flatness1) { flatness = flatness1; }
1347
void setLineJoin(int lineJoin1) { lineJoin = lineJoin1; }
1348
void setLineCap(int lineCap1) { lineCap = lineCap1; }
1349
void setMiterLimit(double limit) { miterLimit = limit; }
1350
void setStrokeAdjust(GBool sa) { strokeAdjust = sa; }
1351
void setAlphaIsShape(GBool ais) { alphaIsShape = ais; }
1352
void setTextKnockout(GBool tk) { textKnockout = tk; }
1353
void setFont(GfxFont *fontA, double fontSizeA);
1354
void setTextMat(double a, double b, double c,
1355
double d, double e, double f)
1356
{ textMat[0] = a; textMat[1] = b; textMat[2] = c;
1357
textMat[3] = d; textMat[4] = e; textMat[5] = f; }
1358
void setCharSpace(double space)
1359
{ charSpace = space; }
1360
void setWordSpace(double space)
1361
{ wordSpace = space; }
1362
void setHorizScaling(double scale)
1363
{ horizScaling = 0.01 * scale; }
1364
void setLeading(double leadingA)
1365
{ leading = leadingA; }
1366
void setRise(double riseA)
1368
void setRender(int renderA)
1369
{ render = renderA; }
1372
void moveTo(double x, double y)
1373
{ path->moveTo(curX = x, curY = y); }
1374
void lineTo(double x, double y)
1375
{ path->lineTo(curX = x, curY = y); }
1376
void curveTo(double x1, double y1, double x2, double y2,
1377
double x3, double y3)
1378
{ path->curveTo(x1, y1, x2, y2, curX = x3, curY = y3); }
1380
{ path->close(); curX = path->getLastX(); curY = path->getLastY(); }
1383
// Update clip region.
1385
void clipToStrokePath();
1388
void textSetPos(double tx, double ty) { lineX = tx; lineY = ty; }
1389
void textMoveTo(double tx, double ty)
1390
{ lineX = tx; lineY = ty; textTransform(tx, ty, &curX, &curY); }
1391
void textShift(double tx, double ty);
1392
void shift(double dx, double dy);
1394
// Push/pop GfxState on/off stack.
1396
GfxState *restore();
1397
GBool hasSaves() { return saved != NULL; }
1398
GBool isParentState(GfxState *state) { return saved == state || (saved && saved->isParentState(state)); }
1401
GBool parseBlendMode(Object *obj, GfxBlendMode *mode);
1403
ReusablePathIterator *getReusablePath() { return new ReusablePathIterator(path); }
1406
double hDPI, vDPI; // resolution
1407
double ctm[6]; // coord transform matrix
1408
double px1, py1, px2, py2; // page corners (user coords)
1409
double pageWidth, pageHeight; // page size (pixels)
1410
int rotate; // page rotation angle
1412
GfxColorSpace *fillColorSpace; // fill color space
1413
GfxColorSpace *strokeColorSpace; // stroke color space
1414
GfxColor fillColor; // fill color
1415
GfxColor strokeColor; // stroke color
1416
GfxPattern *fillPattern; // fill pattern
1417
GfxPattern *strokePattern; // stroke pattern
1418
GfxBlendMode blendMode; // transparency blend mode
1419
double fillOpacity; // fill opacity
1420
double strokeOpacity; // stroke opacity
1421
GBool fillOverprint; // fill overprint
1422
GBool strokeOverprint; // stroke overprint
1423
Function *transfer[4]; // transfer function (entries may be: all
1424
// NULL = identity; last three NULL =
1425
// single function; all four non-NULL =
1426
// R,G,B,gray functions)
1428
double lineWidth; // line width
1429
double *lineDash; // line dash
1431
double lineDashStart;
1432
int flatness; // curve flatness
1433
int lineJoin; // line join style
1434
int lineCap; // line cap style
1435
double miterLimit; // line miter limit
1436
GBool strokeAdjust; // stroke adjustment
1437
GBool alphaIsShape; // alpha is shape
1438
GBool textKnockout; // text knockout
1440
GfxFont *font; // font
1441
double fontSize; // font size
1442
double textMat[6]; // text matrix
1443
double charSpace; // character spacing
1444
double wordSpace; // word spacing
1445
double horizScaling; // horizontal scaling
1446
double leading; // text leading
1447
double rise; // text rise
1448
int render; // text rendering mode
1450
GfxPath *path; // array of path elements
1451
double curX, curY; // current point (user coords)
1452
double lineX, lineY; // start of current text line (text coords)
1454
double clipXMin, clipYMin, // bounding box for clip region
1457
GfxState *saved; // next GfxState on stack
1459
GfxState(GfxState *state);