1 //========================================================================
5 // Copyright 1996-2003 Glyph & Cog, LLC
7 //========================================================================
12 #ifdef USE_GCC_PRAGMAS
16 #include "goo/gtypes.h"
29 GBool
invertTo(Matrix
*other
);
30 void transform(double x
, double y
, double *tx
, double *ty
);
33 //------------------------------------------------------------------------
35 //------------------------------------------------------------------------
56 //------------------------------------------------------------------------
58 //------------------------------------------------------------------------
60 // 16.16 fixed point color component
61 typedef int GfxColorComp
;
63 #define gfxColorComp1 0x10000
65 static inline GfxColorComp
dblToCol(double x
) {
66 return (GfxColorComp
)(x
* gfxColorComp1
);
69 static inline double colToDbl(GfxColorComp x
) {
70 return (double)x
/ (double)gfxColorComp1
;
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)
78 return (GfxColorComp
)((x
<< 8) + x
+ (x
>> 7));
81 static inline Guchar
colToByte(GfxColorComp x
) {
82 // 255 * x + 0.5 = 256 * x - x + 0x8000
83 return (Guchar
)(((x
<< 8) - x
+ 0x8000) >> 16);
86 //------------------------------------------------------------------------
88 //------------------------------------------------------------------------
90 #define gfxColorMaxComps funcMaxOutputs
93 GfxColorComp c
[gfxColorMaxComps
];
96 //------------------------------------------------------------------------
98 //------------------------------------------------------------------------
100 typedef GfxColorComp GfxGray
;
102 //------------------------------------------------------------------------
104 //------------------------------------------------------------------------
107 GfxColorComp r
, g
, b
;
110 //------------------------------------------------------------------------
112 //------------------------------------------------------------------------
115 GfxColorComp c
, m
, y
, k
;
118 //------------------------------------------------------------------------
120 //------------------------------------------------------------------------
122 // NB: The nGfxColorSpaceModes constant and the gfxColorSpaceModeNames
123 // array defined in GfxState.cc must match this enum.
124 enum GfxColorSpaceMode
{
138 class GfxColorSpace
{
142 virtual ~GfxColorSpace();
143 virtual GfxColorSpace
*copy() = 0;
144 virtual GfxColorSpaceMode
getMode() = 0;
146 // Construct a color space. Returns NULL if unsuccessful.
147 static GfxColorSpace
*parse(Object
*csObj
);
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
);
156 // Return the number of color components.
157 virtual int getNComps() = 0;
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
,
164 // Return the number of color space modes
165 static int getNumColorSpaceModes();
167 // Return the name of the <idx>th color space mode.
168 static char *getColorSpaceModeName(int idx
);
173 //------------------------------------------------------------------------
174 // GfxDeviceGrayColorSpace
175 //------------------------------------------------------------------------
177 class GfxDeviceGrayColorSpace
: public GfxColorSpace
{
180 GfxDeviceGrayColorSpace();
181 virtual ~GfxDeviceGrayColorSpace();
182 virtual GfxColorSpace
*copy();
183 virtual GfxColorSpaceMode
getMode() { return csDeviceGray
; }
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
);
191 virtual int getNComps() { return 1; }
196 //------------------------------------------------------------------------
197 // GfxCalGrayColorSpace
198 //------------------------------------------------------------------------
200 class GfxCalGrayColorSpace
: public GfxColorSpace
{
203 GfxCalGrayColorSpace();
204 virtual ~GfxCalGrayColorSpace();
205 virtual GfxColorSpace
*copy();
206 virtual GfxColorSpaceMode
getMode() { return csCalGray
; }
208 // Construct a CalGray color space. Returns NULL if unsuccessful.
209 static GfxColorSpace
*parse(Array
*arr
);
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
);
217 virtual int getNComps() { return 1; }
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
; }
230 double whiteX
, whiteY
, whiteZ
; // white point
231 double blackX
, blackY
, blackZ
; // black point
232 double gamma
; // gamma value
235 //------------------------------------------------------------------------
236 // GfxDeviceRGBColorSpace
237 //------------------------------------------------------------------------
239 class GfxDeviceRGBColorSpace
: public GfxColorSpace
{
242 GfxDeviceRGBColorSpace();
243 virtual ~GfxDeviceRGBColorSpace();
244 virtual GfxColorSpace
*copy();
245 virtual GfxColorSpaceMode
getMode() { return csDeviceRGB
; }
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
);
253 virtual int getNComps() { return 3; }
258 //------------------------------------------------------------------------
259 // GfxCalRGBColorSpace
260 //------------------------------------------------------------------------
262 class GfxCalRGBColorSpace
: public GfxColorSpace
{
265 GfxCalRGBColorSpace();
266 virtual ~GfxCalRGBColorSpace();
267 virtual GfxColorSpace
*copy();
268 virtual GfxColorSpaceMode
getMode() { return csCalRGB
; }
270 // Construct a CalRGB color space. Returns NULL if unsuccessful.
271 static GfxColorSpace
*parse(Array
*arr
);
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
);
279 virtual int getNComps() { return 3; }
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
; }
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
301 //------------------------------------------------------------------------
302 // GfxDeviceCMYKColorSpace
303 //------------------------------------------------------------------------
305 class GfxDeviceCMYKColorSpace
: public GfxColorSpace
{
308 GfxDeviceCMYKColorSpace();
309 virtual ~GfxDeviceCMYKColorSpace();
310 virtual GfxColorSpace
*copy();
311 virtual GfxColorSpaceMode
getMode() { return csDeviceCMYK
; }
313 virtual void getGray(GfxColor
*color
, GfxGray
*gray
);
314 virtual void getRGB(GfxColor
*color
, GfxRGB
*rgb
);
315 virtual void getCMYK(GfxColor
*color
, GfxCMYK
*cmyk
);
317 virtual int getNComps() { return 4; }
322 //------------------------------------------------------------------------
324 //------------------------------------------------------------------------
326 class GfxLabColorSpace
: public GfxColorSpace
{
330 virtual ~GfxLabColorSpace();
331 virtual GfxColorSpace
*copy();
332 virtual GfxColorSpaceMode
getMode() { return csLab
; }
334 // Construct a Lab color space. Returns NULL if unsuccessful.
335 static GfxColorSpace
*parse(Array
*arr
);
337 virtual void getGray(GfxColor
*color
, GfxGray
*gray
);
338 virtual void getRGB(GfxColor
*color
, GfxRGB
*rgb
);
339 virtual void getCMYK(GfxColor
*color
, GfxCMYK
*cmyk
);
341 virtual int getNComps() { return 3; }
343 virtual void getDefaultRanges(double *decodeLow
, double *decodeRange
,
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
; }
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
366 //------------------------------------------------------------------------
367 // GfxICCBasedColorSpace
368 //------------------------------------------------------------------------
370 class GfxICCBasedColorSpace
: public GfxColorSpace
{
373 GfxICCBasedColorSpace(int nCompsA
, GfxColorSpace
*altA
,
374 Ref
*iccProfileStreamA
);
375 virtual ~GfxICCBasedColorSpace();
376 virtual GfxColorSpace
*copy();
377 virtual GfxColorSpaceMode
getMode() { return csICCBased
; }
379 // Construct an ICCBased color space. Returns NULL if unsuccessful.
380 static GfxColorSpace
*parse(Array
*arr
);
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 void getRGBLine(Guchar
*in
, unsigned int *out
, int length
);
387 virtual int getNComps() { return nComps
; }
389 virtual void getDefaultRanges(double *decodeLow
, double *decodeRange
,
392 // ICCBased-specific access.
393 GfxColorSpace
*getAlt() { return alt
; }
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
404 //------------------------------------------------------------------------
405 // GfxIndexedColorSpace
406 //------------------------------------------------------------------------
408 class GfxIndexedColorSpace
: public GfxColorSpace
{
411 GfxIndexedColorSpace(GfxColorSpace
*baseA
, int indexHighA
);
412 virtual ~GfxIndexedColorSpace();
413 virtual GfxColorSpace
*copy();
414 virtual GfxColorSpaceMode
getMode() { return csIndexed
; }
416 // Construct a Lab color space. Returns NULL if unsuccessful.
417 static GfxColorSpace
*parse(Array
*arr
);
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
);
424 virtual int getNComps() { return 1; }
426 virtual void getDefaultRanges(double *decodeLow
, double *decodeRange
,
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
);
437 GfxColorSpace
*base
; // base color space
438 int indexHigh
; // max pixel value
439 Guchar
*lookup
; // lookup table
442 //------------------------------------------------------------------------
443 // GfxSeparationColorSpace
444 //------------------------------------------------------------------------
446 class GfxSeparationColorSpace
: public GfxColorSpace
{
449 GfxSeparationColorSpace(GooString
*nameA
, GfxColorSpace
*altA
,
451 virtual ~GfxSeparationColorSpace();
452 virtual GfxColorSpace
*copy();
453 virtual GfxColorSpaceMode
getMode() { return csSeparation
; }
455 // Construct a Separation color space. Returns NULL if unsuccessful.
456 static GfxColorSpace
*parse(Array
*arr
);
458 virtual void getGray(GfxColor
*color
, GfxGray
*gray
);
459 virtual void getRGB(GfxColor
*color
, GfxRGB
*rgb
);
460 virtual void getCMYK(GfxColor
*color
, GfxCMYK
*cmyk
);
462 virtual int getNComps() { return 1; }
464 // Separation-specific access.
465 GooString
*getName() { return name
; }
466 GfxColorSpace
*getAlt() { return alt
; }
467 Function
*getFunc() { return func
; }
471 GooString
*name
; // colorant name
472 GfxColorSpace
*alt
; // alternate color space
473 Function
*func
; // tint transform (into alternate color space)
476 //------------------------------------------------------------------------
477 // GfxDeviceNColorSpace
478 //------------------------------------------------------------------------
480 class GfxDeviceNColorSpace
: public GfxColorSpace
{
483 GfxDeviceNColorSpace(int nCompsA
, GfxColorSpace
*alt
, Function
*func
);
484 virtual ~GfxDeviceNColorSpace();
485 virtual GfxColorSpace
*copy();
486 virtual GfxColorSpaceMode
getMode() { return csDeviceN
; }
488 // Construct a DeviceN color space. Returns NULL if unsuccessful.
489 static GfxColorSpace
*parse(Array
*arr
);
491 virtual void getGray(GfxColor
*color
, GfxGray
*gray
);
492 virtual void getRGB(GfxColor
*color
, GfxRGB
*rgb
);
493 virtual void getCMYK(GfxColor
*color
, GfxCMYK
*cmyk
);
495 virtual int getNComps() { return nComps
; }
497 // DeviceN-specific access.
498 GooString
*getColorantName(int i
) { return names
[i
]; }
499 GfxColorSpace
*getAlt() { return alt
; }
500 Function
*getTintTransformFunc() { return func
; }
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)
511 //------------------------------------------------------------------------
512 // GfxPatternColorSpace
513 //------------------------------------------------------------------------
515 class GfxPatternColorSpace
: public GfxColorSpace
{
518 GfxPatternColorSpace(GfxColorSpace
*underA
);
519 virtual ~GfxPatternColorSpace();
520 virtual GfxColorSpace
*copy();
521 virtual GfxColorSpaceMode
getMode() { return csPattern
; }
523 // Construct a Pattern color space. Returns NULL if unsuccessful.
524 static GfxColorSpace
*parse(Array
*arr
);
526 virtual void getGray(GfxColor
*color
, GfxGray
*gray
);
527 virtual void getRGB(GfxColor
*color
, GfxRGB
*rgb
);
528 virtual void getCMYK(GfxColor
*color
, GfxCMYK
*cmyk
);
530 virtual int getNComps() { return 0; }
532 // Pattern-specific access.
533 GfxColorSpace
*getUnder() { return under
; }
537 GfxColorSpace
*under
; // underlying color space (for uncolored
541 //------------------------------------------------------------------------
543 //------------------------------------------------------------------------
548 GfxPattern(int typeA
);
549 virtual ~GfxPattern();
551 static GfxPattern
*parse(Object
*obj
);
553 virtual GfxPattern
*copy() = 0;
555 int getType() { return type
; }
562 //------------------------------------------------------------------------
564 //------------------------------------------------------------------------
566 class GfxTilingPattern
: public GfxPattern
{
569 static GfxTilingPattern
*parse(Object
*patObj
);
570 virtual ~GfxTilingPattern();
572 virtual GfxPattern
*copy();
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
; }
580 { return resDict
.isDict() ? resDict
.getDict() : (Dict
*)NULL
; }
581 double *getMatrix() { return matrix
; }
582 Object
*getContentStream() { return &contentStream
; }
586 GfxTilingPattern(int paintTypeA
, int tilingTypeA
,
587 double *bboxA
, double xStepA
, double yStepA
,
588 Object
*resDictA
, double *matrixA
,
589 Object
*contentStreamA
);
597 Object contentStream
;
600 //------------------------------------------------------------------------
602 //------------------------------------------------------------------------
604 class GfxShadingPattern
: public GfxPattern
{
607 static GfxShadingPattern
*parse(Object
*patObj
);
608 virtual ~GfxShadingPattern();
610 virtual GfxPattern
*copy();
612 GfxShading
*getShading() { return shading
; }
613 double *getMatrix() { return matrix
; }
617 GfxShadingPattern(GfxShading
*shadingA
, double *matrixA
);
623 //------------------------------------------------------------------------
625 //------------------------------------------------------------------------
630 GfxShading(int typeA
);
631 GfxShading(GfxShading
*shading
);
632 virtual ~GfxShading();
634 static GfxShading
*parse(Object
*obj
);
636 virtual GfxShading
*copy() = 0;
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
; }
648 GBool
init(Dict
*dict
);
651 GfxColorSpace
*colorSpace
;
654 double xMin
, yMin
, xMax
, yMax
;
658 //------------------------------------------------------------------------
659 // GfxFunctionShading
660 //------------------------------------------------------------------------
662 class GfxFunctionShading
: public GfxShading
{
665 GfxFunctionShading(double x0A
, double y0A
,
666 double x1A
, double y1A
,
668 Function
**funcsA
, int nFuncsA
);
669 GfxFunctionShading(GfxFunctionShading
*shading
);
670 virtual ~GfxFunctionShading();
672 static GfxFunctionShading
*parse(Dict
*dict
);
674 virtual GfxShading
*copy();
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
);
685 double x0
, y0
, x1
, y1
;
687 Function
*funcs
[gfxColorMaxComps
];
691 //------------------------------------------------------------------------
693 //------------------------------------------------------------------------
695 class GfxAxialShading
: public GfxShading
{
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();
706 static GfxAxialShading
*parse(Dict
*dict
);
708 virtual GfxShading
*copy();
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
);
722 double x0
, y0
, x1
, y1
;
724 Function
*funcs
[gfxColorMaxComps
];
726 GBool extend0
, extend1
;
729 //------------------------------------------------------------------------
731 //------------------------------------------------------------------------
733 class GfxRadialShading
: public GfxShading
{
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();
744 static GfxRadialShading
*parse(Dict
*dict
);
746 virtual GfxShading
*copy();
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
);
761 double x0
, y0
, r0
, x1
, y1
, r1
;
763 Function
*funcs
[gfxColorMaxComps
];
765 GBool extend0
, extend1
;
768 //------------------------------------------------------------------------
769 // GfxGouraudTriangleShading
770 //------------------------------------------------------------------------
772 struct GfxGouraudVertex
{
777 class GfxGouraudTriangleShading
: public GfxShading
{
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();
787 static GfxGouraudTriangleShading
*parse(int typeA
, Dict
*dict
, Stream
*str
);
789 virtual GfxShading
*copy();
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
);
798 GfxGouraudVertex
*vertices
;
802 Function
*funcs
[gfxColorMaxComps
];
806 //------------------------------------------------------------------------
807 // GfxPatchMeshShading
808 //------------------------------------------------------------------------
813 GfxColor color
[2][2];
816 class GfxPatchMeshShading
: public GfxShading
{
819 GfxPatchMeshShading(int typeA
, GfxPatch
*patchesA
, int nPatchesA
,
820 Function
**funcsA
, int nFuncsA
);
821 GfxPatchMeshShading(GfxPatchMeshShading
*shading
);
822 virtual ~GfxPatchMeshShading();
824 static GfxPatchMeshShading
*parse(int typeA
, Dict
*dict
, Stream
*str
);
826 virtual GfxShading
*copy();
828 int getNPatches() { return nPatches
; }
829 GfxPatch
*getPatch(int i
) { return &patches
[i
]; }
835 Function
*funcs
[gfxColorMaxComps
];
839 //------------------------------------------------------------------------
841 //------------------------------------------------------------------------
843 class GfxImageColorMap
{
847 GfxImageColorMap(int bitsA
, Object
*decode
, GfxColorSpace
*colorSpaceA
);
852 // Return a copy of this color map.
853 GfxImageColorMap
*copy() { return new GfxImageColorMap(this); }
855 // Is color map valid?
856 GBool
isOk() { return ok
; }
858 // Get the color space.
859 GfxColorSpace
*getColorSpace() { return colorSpace
; }
861 // Get stream decoding info.
862 int getNumPixelComps() { return nComps
; }
863 int getBits() { return bits
; }
866 double getDecodeLow(int i
) { return decodeLow
[i
]; }
867 double getDecodeHigh(int i
) { return decodeLow
[i
] + decodeRange
[i
]; }
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
);
879 GfxImageColorMap(GfxImageColorMap
*colorMap
);
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
];
890 double // minimum values for each component
891 decodeLow
[gfxColorMaxComps
];
892 double // max - min value for each component
893 decodeRange
[gfxColorMaxComps
];
897 //------------------------------------------------------------------------
898 // GfxSubpath and GfxPath
899 //------------------------------------------------------------------------
905 GfxSubpath(double x1
, double y1
);
911 GfxSubpath
*copy() { return new GfxSubpath(this); }
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
]; }
920 double getLastX() { return x
[n
-1]; }
921 double getLastY() { return y
[n
-1]; }
923 // Add a line segment.
924 void lineTo(double x1
, double y1
);
926 // Add a Bezier curve.
927 void curveTo(double x1
, double y1
, double x2
, double y2
,
928 double x3
, double y3
);
930 // Close the subpath.
932 GBool
isClosed() { return closed
; }
934 // Add (<dx>, <dy>) to each point in the subpath.
935 void offset(double dx
, double dy
);
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
946 GfxSubpath(GfxSubpath
*subpath
);
960 { return new GfxPath(justMoved
, firstX
, firstY
, subpaths
, n
, size
); }
962 // Is there a current point?
963 GBool
isCurPt() { return n
> 0 || justMoved
; }
965 // Is the path non-empty, i.e., is there at least one segment?
966 GBool
isPath() { return n
> 0; }
969 int getNumSubpaths() { return n
; }
970 GfxSubpath
*getSubpath(int i
) { return subpaths
[i
]; }
972 // Get last point on last subpath.
973 double getLastX() { return subpaths
[n
-1]->getLastX(); }
974 double getLastY() { return subpaths
[n
-1]->getLastY(); }
976 // Move the current point.
977 void moveTo(double x
, double y
);
979 // Add a segment to the last subpath.
980 void lineTo(double x
, double y
);
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
);
986 // Close the last subpath.
989 // Append <path> to <this>.
990 void append(GfxPath
*path
);
992 // Add (<dx>, <dy>) to each point in the path.
993 void offset(double dx
, double dy
);
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
1003 GfxPath(GBool justMoved1
, double firstX1
, double firstY1
,
1004 GfxSubpath
**subpaths1
, int n1
, int size1
);
1007 //------------------------------------------------------------------------
1009 //------------------------------------------------------------------------
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
);
1024 GfxState
*copy() { return new GfxState(this); }
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
; }
1085 // Is there a current point/path?
1086 GBool
isCurPt() { return path
->isCurPt(); }
1087 GBool
isPath() { return path
->isPath(); }
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
);
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
)
1145 void setRender(int renderA
)
1146 { render
= renderA
; }
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
); }
1157 { path
->close(); curX
= path
->getLastX(); curY
= path
->getLastY(); }
1160 // Update clip region.
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
);
1170 // Push/pop GfxState on/off stack.
1172 GfxState
*restore();
1173 GBool
hasSaves() { return saved
!= NULL
; }
1176 GBool
parseBlendMode(Object
*obj
, GfxBlendMode
*mode
);
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
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
1197 double lineWidth
; // line width
1198 double *lineDash
; // line dash
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
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
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)
1220 double clipXMin
, clipYMin
, // bounding box for clip region
1223 GfxState
*saved
; // next GfxState on stack
1225 GfxState(GfxState
*state
);