~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/poppler/poppler/GfxState.h

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//========================================================================
 
2
//
 
3
// GfxState.h
 
4
//
 
5
// Copyright 1996-2003 Glyph & Cog, LLC
 
6
//
 
7
//========================================================================
 
8
 
 
9
//========================================================================
 
10
//
 
11
// Modified under the Poppler project - http://poppler.freedesktop.org
 
12
//
 
13
// All changes made under the Poppler project to this file are licensed
 
14
// under GPL version 2 or later
 
15
//
 
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>
 
22
//
 
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
 
25
//
 
26
//========================================================================
 
27
 
 
28
#ifndef GFXSTATE_H
 
29
#define GFXSTATE_H
 
30
 
 
31
#ifdef USE_GCC_PRAGMAS
 
32
#pragma interface
 
33
#endif
 
34
 
 
35
#include "goo/gtypes.h"
 
36
#include "Object.h"
 
37
#include "Function.h"
 
38
 
 
39
#include <assert.h>
 
40
 
 
41
class Array;
 
42
class Gfx;
 
43
class GfxFont;
 
44
class PDFRectangle;
 
45
class GfxShading;
 
46
class PopplerCache;
 
47
 
 
48
class Matrix {
 
49
public:
 
50
  double m[6];
 
51
 
 
52
  GBool invertTo(Matrix *other);
 
53
  void transform(double x, double y, double *tx, double *ty);
 
54
};
 
55
 
 
56
//------------------------------------------------------------------------
 
57
// GfxBlendMode
 
58
//------------------------------------------------------------------------
 
59
 
 
60
enum GfxBlendMode {
 
61
  gfxBlendNormal,
 
62
  gfxBlendMultiply,
 
63
  gfxBlendScreen,
 
64
  gfxBlendOverlay,
 
65
  gfxBlendDarken,
 
66
  gfxBlendLighten,
 
67
  gfxBlendColorDodge,
 
68
  gfxBlendColorBurn,
 
69
  gfxBlendHardLight,
 
70
  gfxBlendSoftLight,
 
71
  gfxBlendDifference,
 
72
  gfxBlendExclusion,
 
73
  gfxBlendHue,
 
74
  gfxBlendSaturation,
 
75
  gfxBlendColor,
 
76
  gfxBlendLuminosity
 
77
};
 
78
 
 
79
//------------------------------------------------------------------------
 
80
// GfxColorComp
 
81
//------------------------------------------------------------------------
 
82
 
 
83
// 16.16 fixed point color component
 
84
typedef int GfxColorComp;
 
85
 
 
86
#define gfxColorComp1 0x10000
 
87
 
 
88
static inline GfxColorComp dblToCol(double x) {
 
89
  return (GfxColorComp)(x * gfxColorComp1);
 
90
}
 
91
 
 
92
static inline double colToDbl(GfxColorComp x) {
 
93
  return (double)x / (double)gfxColorComp1;
 
94
}
 
95
 
 
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)
 
100
  //                                      [for rounding]
 
101
  return (GfxColorComp)((x << 8) + x + (x >> 7));
 
102
}
 
103
 
 
104
static inline Guchar colToByte(GfxColorComp x) {
 
105
  // 255 * x + 0.5  =  256 * x - x + 0x8000
 
106
  return (Guchar)(((x << 8) - x + 0x8000) >> 16);
 
107
}
 
108
 
 
109
//------------------------------------------------------------------------
 
110
// GfxColor
 
111
//------------------------------------------------------------------------
 
112
 
 
113
#define gfxColorMaxComps funcMaxOutputs
 
114
 
 
115
struct GfxColor {
 
116
  GfxColorComp c[gfxColorMaxComps];
 
117
};
 
118
 
 
119
//------------------------------------------------------------------------
 
120
// GfxGray
 
121
//------------------------------------------------------------------------
 
122
 
 
123
typedef GfxColorComp GfxGray;
 
124
 
 
125
//------------------------------------------------------------------------
 
126
// GfxRGB
 
127
//------------------------------------------------------------------------
 
128
 
 
129
struct GfxRGB {
 
130
  GfxColorComp r, g, b;
 
131
};
 
132
 
 
133
//------------------------------------------------------------------------
 
134
// GfxCMYK
 
135
//------------------------------------------------------------------------
 
136
 
 
137
struct GfxCMYK {
 
138
  GfxColorComp c, m, y, k;
 
139
};
 
140
 
 
141
//------------------------------------------------------------------------
 
142
// GfxColorSpace
 
143
//------------------------------------------------------------------------
 
144
 
 
145
// NB: The nGfxColorSpaceModes constant and the gfxColorSpaceModeNames
 
146
// array defined in GfxState.cc must match this enum.
 
147
enum GfxColorSpaceMode {
 
148
  csDeviceGray,
 
149
  csCalGray,
 
150
  csDeviceRGB,
 
151
  csCalRGB,
 
152
  csDeviceCMYK,
 
153
  csLab,
 
154
  csICCBased,
 
155
  csIndexed,
 
156
  csSeparation,
 
157
  csDeviceN,
 
158
  csPattern
 
159
};
 
160
 
 
161
// wrapper of cmsHTRANSFORM to copy
 
162
class GfxColorTransform {
 
163
public:
 
164
  void doTransform(void *in, void *out, unsigned int size);
 
165
  // transformA should be a cmsHTRANSFORM
 
166
  GfxColorTransform(void *transformA);
 
167
  ~GfxColorTransform();
 
168
  void ref();
 
169
  unsigned int unref();
 
170
private:
 
171
  GfxColorTransform() {}
 
172
  void *transform;
 
173
  unsigned int refCount;
 
174
};
 
175
 
 
176
class GfxColorSpace {
 
177
public:
 
178
 
 
179
  GfxColorSpace();
 
180
  virtual ~GfxColorSpace();
 
181
  virtual GfxColorSpace *copy() = 0;
 
182
  virtual GfxColorSpaceMode getMode() = 0;
 
183
 
 
184
  // Construct a color space.  Returns NULL if unsuccessful.
 
185
  static GfxColorSpace *parse(Object *csObj, Gfx *gfx);
 
186
 
 
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*/) {}
 
193
 
 
194
  // Does this ColorSpace use getRGBLine?
 
195
  virtual GBool useGetRGBLine() { return gFalse; }
 
196
  // Does this ColorSpace use getGrayLine?
 
197
  virtual GBool useGetGrayLine() { return gFalse; }
 
198
 
 
199
  // Return the number of color components.
 
200
  virtual int getNComps() = 0;
 
201
 
 
202
  // Get this color space's default color.
 
203
  virtual void getDefaultColor(GfxColor *color) = 0;
 
204
 
 
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,
 
208
                                int maxImgPixel);
 
209
 
 
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; }
 
213
 
 
214
  // Return the number of color space modes
 
215
  static int getNumColorSpaceModes();
 
216
 
 
217
  // Return the name of the <idx>th color space mode.
 
218
  static char *getColorSpaceModeName(int idx);
 
219
 
 
220
#ifdef USE_CMS
 
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();
 
229
#endif
 
230
};
 
231
 
 
232
//------------------------------------------------------------------------
 
233
// GfxDeviceGrayColorSpace
 
234
//------------------------------------------------------------------------
 
235
 
 
236
class GfxDeviceGrayColorSpace: public GfxColorSpace {
 
237
public:
 
238
 
 
239
  GfxDeviceGrayColorSpace();
 
240
  virtual ~GfxDeviceGrayColorSpace();
 
241
  virtual GfxColorSpace *copy();
 
242
  virtual GfxColorSpaceMode getMode() { return csDeviceGray; }
 
243
 
 
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);
 
249
 
 
250
  virtual GBool useGetRGBLine() { return gTrue; }
 
251
  virtual GBool useGetGrayLine() { return gTrue; }
 
252
 
 
253
  virtual int getNComps() { return 1; }
 
254
  virtual void getDefaultColor(GfxColor *color);
 
255
 
 
256
private:
 
257
};
 
258
 
 
259
//------------------------------------------------------------------------
 
260
// GfxCalGrayColorSpace
 
261
//------------------------------------------------------------------------
 
262
 
 
263
class GfxCalGrayColorSpace: public GfxColorSpace {
 
264
public:
 
265
 
 
266
  GfxCalGrayColorSpace();
 
267
  virtual ~GfxCalGrayColorSpace();
 
268
  virtual GfxColorSpace *copy();
 
269
  virtual GfxColorSpaceMode getMode() { return csCalGray; }
 
270
 
 
271
  // Construct a CalGray color space.  Returns NULL if unsuccessful.
 
272
  static GfxColorSpace *parse(Array *arr);
 
273
 
 
274
  virtual void getGray(GfxColor *color, GfxGray *gray);
 
275
  virtual void getRGB(GfxColor *color, GfxRGB *rgb);
 
276
  virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
 
277
 
 
278
  virtual int getNComps() { return 1; }
 
279
  virtual void getDefaultColor(GfxColor *color);
 
280
 
 
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; }
 
289
 
 
290
private:
 
291
 
 
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);
 
297
};
 
298
 
 
299
//------------------------------------------------------------------------
 
300
// GfxDeviceRGBColorSpace
 
301
//------------------------------------------------------------------------
 
302
 
 
303
class GfxDeviceRGBColorSpace: public GfxColorSpace {
 
304
public:
 
305
 
 
306
  GfxDeviceRGBColorSpace();
 
307
  virtual ~GfxDeviceRGBColorSpace();
 
308
  virtual GfxColorSpace *copy();
 
309
  virtual GfxColorSpaceMode getMode() { return csDeviceRGB; }
 
310
 
 
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);
 
316
 
 
317
  virtual GBool useGetRGBLine() { return gTrue; }
 
318
  virtual GBool useGetGrayLine() { return gTrue; }
 
319
 
 
320
  virtual int getNComps() { return 3; }
 
321
  virtual void getDefaultColor(GfxColor *color);
 
322
 
 
323
private:
 
324
};
 
325
 
 
326
//------------------------------------------------------------------------
 
327
// GfxCalRGBColorSpace
 
328
//------------------------------------------------------------------------
 
329
 
 
330
class GfxCalRGBColorSpace: public GfxColorSpace {
 
331
public:
 
332
 
 
333
  GfxCalRGBColorSpace();
 
334
  virtual ~GfxCalRGBColorSpace();
 
335
  virtual GfxColorSpace *copy();
 
336
  virtual GfxColorSpaceMode getMode() { return csCalRGB; }
 
337
 
 
338
  // Construct a CalRGB color space.  Returns NULL if unsuccessful.
 
339
  static GfxColorSpace *parse(Array *arr);
 
340
 
 
341
  virtual void getGray(GfxColor *color, GfxGray *gray);
 
342
  virtual void getRGB(GfxColor *color, GfxRGB *rgb);
 
343
  virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
 
344
 
 
345
  virtual int getNComps() { return 3; }
 
346
  virtual void getDefaultColor(GfxColor *color);
 
347
 
 
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; }
 
359
 
 
360
private:
 
361
 
 
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);
 
368
};
 
369
 
 
370
//------------------------------------------------------------------------
 
371
// GfxDeviceCMYKColorSpace
 
372
//------------------------------------------------------------------------
 
373
 
 
374
class GfxDeviceCMYKColorSpace: public GfxColorSpace {
 
375
public:
 
376
 
 
377
  GfxDeviceCMYKColorSpace();
 
378
  virtual ~GfxDeviceCMYKColorSpace();
 
379
  virtual GfxColorSpace *copy();
 
380
  virtual GfxColorSpaceMode getMode() { return csDeviceCMYK; }
 
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 int getNComps() { return 4; }
 
387
  virtual void getDefaultColor(GfxColor *color);
 
388
 
 
389
private:
 
390
};
 
391
 
 
392
//------------------------------------------------------------------------
 
393
// GfxLabColorSpace
 
394
//------------------------------------------------------------------------
 
395
 
 
396
class GfxLabColorSpace: public GfxColorSpace {
 
397
public:
 
398
 
 
399
  GfxLabColorSpace();
 
400
  virtual ~GfxLabColorSpace();
 
401
  virtual GfxColorSpace *copy();
 
402
  virtual GfxColorSpaceMode getMode() { return csLab; }
 
403
 
 
404
  // Construct a Lab color space.  Returns NULL if unsuccessful.
 
405
  static GfxColorSpace *parse(Array *arr);
 
406
 
 
407
  virtual void getGray(GfxColor *color, GfxGray *gray);
 
408
  virtual void getRGB(GfxColor *color, GfxRGB *rgb);
 
409
  virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
 
410
 
 
411
  virtual int getNComps() { return 3; }
 
412
  virtual void getDefaultColor(GfxColor *color);
 
413
 
 
414
  virtual void getDefaultRanges(double *decodeLow, double *decodeRange,
 
415
                                int maxImgPixel);
 
416
 
 
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; }
 
428
 
 
429
private:
 
430
 
 
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);
 
436
};
 
437
 
 
438
//------------------------------------------------------------------------
 
439
// GfxICCBasedColorSpace
 
440
//------------------------------------------------------------------------
 
441
 
 
442
class GfxICCBasedColorSpace: public GfxColorSpace {
 
443
public:
 
444
 
 
445
  GfxICCBasedColorSpace(int nCompsA, GfxColorSpace *altA,
 
446
                        Ref *iccProfileStreamA);
 
447
  virtual ~GfxICCBasedColorSpace();
 
448
  virtual GfxColorSpace *copy();
 
449
  virtual GfxColorSpaceMode getMode() { return csICCBased; }
 
450
 
 
451
  // Construct an ICCBased color space.  Returns NULL if unsuccessful.
 
452
  static GfxColorSpace *parse(Array *arr, Gfx *gfx);
 
453
 
 
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);
 
458
 
 
459
  virtual GBool useGetRGBLine();
 
460
 
 
461
  virtual int getNComps() { return nComps; }
 
462
  virtual void getDefaultColor(GfxColor *color);
 
463
 
 
464
  virtual void getDefaultRanges(double *decodeLow, double *decodeRange,
 
465
                                int maxImgPixel);
 
466
 
 
467
  // ICCBased-specific access.
 
468
  GfxColorSpace *getAlt() { return alt; }
 
469
 
 
470
private:
 
471
 
 
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
 
477
#ifdef USE_CMS
 
478
  GfxColorTransform *transform;
 
479
  GfxColorTransform *lineTransform; // color transform for line
 
480
#endif
 
481
};
 
482
//------------------------------------------------------------------------
 
483
// GfxIndexedColorSpace
 
484
//------------------------------------------------------------------------
 
485
 
 
486
class GfxIndexedColorSpace: public GfxColorSpace {
 
487
public:
 
488
 
 
489
  GfxIndexedColorSpace(GfxColorSpace *baseA, int indexHighA);
 
490
  virtual ~GfxIndexedColorSpace();
 
491
  virtual GfxColorSpace *copy();
 
492
  virtual GfxColorSpaceMode getMode() { return csIndexed; }
 
493
 
 
494
  // Construct a Lab color space.  Returns NULL if unsuccessful.
 
495
  static GfxColorSpace *parse(Array *arr, Gfx *gfx);
 
496
 
 
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);
 
501
 
 
502
  virtual GBool useGetRGBLine() { return gTrue; }
 
503
 
 
504
  virtual int getNComps() { return 1; }
 
505
  virtual void getDefaultColor(GfxColor *color);
 
506
 
 
507
  virtual void getDefaultRanges(double *decodeLow, double *decodeRange,
 
508
                                int maxImgPixel);
 
509
 
 
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);
 
515
 
 
516
private:
 
517
 
 
518
  GfxColorSpace *base;          // base color space
 
519
  int indexHigh;                // max pixel value
 
520
  Guchar *lookup;               // lookup table
 
521
};
 
522
 
 
523
//------------------------------------------------------------------------
 
524
// GfxSeparationColorSpace
 
525
//------------------------------------------------------------------------
 
526
 
 
527
class GfxSeparationColorSpace: public GfxColorSpace {
 
528
public:
 
529
 
 
530
  GfxSeparationColorSpace(GooString *nameA, GfxColorSpace *altA,
 
531
                          Function *funcA);
 
532
  virtual ~GfxSeparationColorSpace();
 
533
  virtual GfxColorSpace *copy();
 
534
  virtual GfxColorSpaceMode getMode() { return csSeparation; }
 
535
 
 
536
  // Construct a Separation color space.  Returns NULL if unsuccessful.
 
537
  static GfxColorSpace *parse(Array *arr, Gfx *gfx);
 
538
 
 
539
  virtual void getGray(GfxColor *color, GfxGray *gray);
 
540
  virtual void getRGB(GfxColor *color, GfxRGB *rgb);
 
541
  virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
 
542
 
 
543
  virtual int getNComps() { return 1; }
 
544
  virtual void getDefaultColor(GfxColor *color);
 
545
 
 
546
  virtual GBool isNonMarking() { return nonMarking; }
 
547
 
 
548
  // Separation-specific access.
 
549
  GooString *getName() { return name; }
 
550
  GfxColorSpace *getAlt() { return alt; }
 
551
  Function *getFunc() { return func; }
 
552
 
 
553
private:
 
554
 
 
555
  GooString *name;              // colorant name
 
556
  GfxColorSpace *alt;           // alternate color space
 
557
  Function *func;               // tint transform (into alternate color space)
 
558
  GBool nonMarking;
 
559
};
 
560
 
 
561
//------------------------------------------------------------------------
 
562
// GfxDeviceNColorSpace
 
563
//------------------------------------------------------------------------
 
564
 
 
565
class GfxDeviceNColorSpace: public GfxColorSpace {
 
566
public:
 
567
 
 
568
  GfxDeviceNColorSpace(int nCompsA, GfxColorSpace *alt, Function *func);
 
569
  virtual ~GfxDeviceNColorSpace();
 
570
  virtual GfxColorSpace *copy();
 
571
  virtual GfxColorSpaceMode getMode() { return csDeviceN; }
 
572
 
 
573
  // Construct a DeviceN color space.  Returns NULL if unsuccessful.
 
574
  static GfxColorSpace *parse(Array *arr, Gfx *gfx);
 
575
 
 
576
  virtual void getGray(GfxColor *color, GfxGray *gray);
 
577
  virtual void getRGB(GfxColor *color, GfxRGB *rgb);
 
578
  virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
 
579
 
 
580
  virtual int getNComps() { return nComps; }
 
581
  virtual void getDefaultColor(GfxColor *color);
 
582
 
 
583
  virtual GBool isNonMarking() { return nonMarking; }
 
584
 
 
585
  // DeviceN-specific access.
 
586
  GooString *getColorantName(int i) { return names[i]; }
 
587
  GfxColorSpace *getAlt() { return alt; }
 
588
  Function *getTintTransformFunc() { return func; }
 
589
 
 
590
private:
 
591
 
 
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)
 
597
  GBool nonMarking;
 
598
};
 
599
 
 
600
//------------------------------------------------------------------------
 
601
// GfxPatternColorSpace
 
602
//------------------------------------------------------------------------
 
603
 
 
604
class GfxPatternColorSpace: public GfxColorSpace {
 
605
public:
 
606
 
 
607
  GfxPatternColorSpace(GfxColorSpace *underA);
 
608
  virtual ~GfxPatternColorSpace();
 
609
  virtual GfxColorSpace *copy();
 
610
  virtual GfxColorSpaceMode getMode() { return csPattern; }
 
611
 
 
612
  // Construct a Pattern color space.  Returns NULL if unsuccessful.
 
613
  static GfxColorSpace *parse(Array *arr, Gfx *gfx);
 
614
 
 
615
  virtual void getGray(GfxColor *color, GfxGray *gray);
 
616
  virtual void getRGB(GfxColor *color, GfxRGB *rgb);
 
617
  virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
 
618
 
 
619
  virtual int getNComps() { return 0; }
 
620
  virtual void getDefaultColor(GfxColor *color);
 
621
 
 
622
  // Pattern-specific access.
 
623
  GfxColorSpace *getUnder() { return under; }
 
624
 
 
625
private:
 
626
 
 
627
  GfxColorSpace *under;         // underlying color space (for uncolored
 
628
                                //   patterns)
 
629
};
 
630
 
 
631
//------------------------------------------------------------------------
 
632
// GfxPattern
 
633
//------------------------------------------------------------------------
 
634
 
 
635
class GfxPattern {
 
636
public:
 
637
 
 
638
  GfxPattern(int typeA);
 
639
  virtual ~GfxPattern();
 
640
 
 
641
  static GfxPattern *parse(Object *obj, Gfx *gfx);
 
642
 
 
643
  virtual GfxPattern *copy() = 0;
 
644
 
 
645
  int getType() { return type; }
 
646
 
 
647
private:
 
648
 
 
649
  int type;
 
650
};
 
651
 
 
652
//------------------------------------------------------------------------
 
653
// GfxTilingPattern
 
654
//------------------------------------------------------------------------
 
655
 
 
656
class GfxTilingPattern: public GfxPattern {
 
657
public:
 
658
 
 
659
  static GfxTilingPattern *parse(Object *patObj);
 
660
  virtual ~GfxTilingPattern();
 
661
 
 
662
  virtual GfxPattern *copy();
 
663
 
 
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; }
 
669
  Dict *getResDict()
 
670
    { return resDict.isDict() ? resDict.getDict() : (Dict *)NULL; }
 
671
  double *getMatrix() { return matrix; }
 
672
  Object *getContentStream() { return &contentStream; }
 
673
 
 
674
private:
 
675
 
 
676
  GfxTilingPattern(int paintTypeA, int tilingTypeA,
 
677
                   double *bboxA, double xStepA, double yStepA,
 
678
                   Object *resDictA, double *matrixA,
 
679
                   Object *contentStreamA);
 
680
 
 
681
  int paintType;
 
682
  int tilingType;
 
683
  double bbox[4];
 
684
  double xStep, yStep;
 
685
  Object resDict;
 
686
  double matrix[6];
 
687
  Object contentStream;
 
688
};
 
689
 
 
690
//------------------------------------------------------------------------
 
691
// GfxShadingPattern
 
692
//------------------------------------------------------------------------
 
693
 
 
694
class GfxShadingPattern: public GfxPattern {
 
695
public:
 
696
 
 
697
  static GfxShadingPattern *parse(Object *patObj, Gfx *gfx);
 
698
  virtual ~GfxShadingPattern();
 
699
 
 
700
  virtual GfxPattern *copy();
 
701
 
 
702
  GfxShading *getShading() { return shading; }
 
703
  double *getMatrix() { return matrix; }
 
704
 
 
705
private:
 
706
 
 
707
  GfxShadingPattern(GfxShading *shadingA, double *matrixA);
 
708
 
 
709
  GfxShading *shading;
 
710
  double matrix[6];
 
711
};
 
712
 
 
713
//------------------------------------------------------------------------
 
714
// GfxShading
 
715
//------------------------------------------------------------------------
 
716
 
 
717
class GfxShading {
 
718
public:
 
719
 
 
720
  GfxShading(int typeA);
 
721
  GfxShading(GfxShading *shading);
 
722
  virtual ~GfxShading();
 
723
 
 
724
  static GfxShading *parse(Object *obj, Gfx *gfx);
 
725
 
 
726
  virtual GfxShading *copy() = 0;
 
727
 
 
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; }
 
735
 
 
736
protected:
 
737
 
 
738
  GBool init(Dict *dict, Gfx *gfx);
 
739
 
 
740
  int type;
 
741
  GfxColorSpace *colorSpace;
 
742
  GfxColor background;
 
743
  GBool hasBackground;
 
744
  double xMin, yMin, xMax, yMax;
 
745
  GBool hasBBox;
 
746
};
 
747
 
 
748
//------------------------------------------------------------------------
 
749
// GfxFunctionShading
 
750
//------------------------------------------------------------------------
 
751
 
 
752
class GfxFunctionShading: public GfxShading {
 
753
public:
 
754
 
 
755
  GfxFunctionShading(double x0A, double y0A,
 
756
                     double x1A, double y1A,
 
757
                     double *matrixA,
 
758
                     Function **funcsA, int nFuncsA);
 
759
  GfxFunctionShading(GfxFunctionShading *shading);
 
760
  virtual ~GfxFunctionShading();
 
761
 
 
762
  static GfxFunctionShading *parse(Dict *dict, Gfx *gfx);
 
763
 
 
764
  virtual GfxShading *copy();
 
765
 
 
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);
 
772
 
 
773
private:
 
774
 
 
775
  double x0, y0, x1, y1;
 
776
  double matrix[6];
 
777
  Function *funcs[gfxColorMaxComps];
 
778
  int nFuncs;
 
779
};
 
780
 
 
781
//------------------------------------------------------------------------
 
782
// GfxAxialShading
 
783
//------------------------------------------------------------------------
 
784
 
 
785
class GfxAxialShading: public GfxShading {
 
786
public:
 
787
 
 
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();
 
795
 
 
796
  static GfxAxialShading *parse(Dict *dict, Gfx *gfx);
 
797
 
 
798
  virtual GfxShading *copy();
 
799
 
 
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);
 
809
 
 
810
private:
 
811
 
 
812
  double x0, y0, x1, y1;
 
813
  double t0, t1;
 
814
  Function *funcs[gfxColorMaxComps];
 
815
  int nFuncs;
 
816
  GBool extend0, extend1;
 
817
};
 
818
 
 
819
//------------------------------------------------------------------------
 
820
// GfxRadialShading
 
821
//------------------------------------------------------------------------
 
822
 
 
823
class GfxRadialShading: public GfxShading {
 
824
public:
 
825
 
 
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();
 
833
 
 
834
  static GfxRadialShading *parse(Dict *dict, Gfx *gfx);
 
835
 
 
836
  virtual GfxShading *copy();
 
837
 
 
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);
 
848
 
 
849
private:
 
850
 
 
851
  double x0, y0, r0, x1, y1, r1;
 
852
  double t0, t1;
 
853
  Function *funcs[gfxColorMaxComps];
 
854
  int nFuncs;
 
855
  GBool extend0, extend1;
 
856
};
 
857
 
 
858
//------------------------------------------------------------------------
 
859
// GfxGouraudTriangleShading
 
860
//------------------------------------------------------------------------
 
861
 
 
862
struct GfxGouraudVertex {
 
863
  double x, y;
 
864
  GfxColor color;
 
865
};
 
866
 
 
867
class GfxGouraudTriangleShading: public GfxShading {
 
868
public:
 
869
 
 
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();
 
876
 
 
877
  static GfxGouraudTriangleShading *parse(int typeA, Dict *dict, Stream *str, Gfx *gfx);
 
878
 
 
879
  virtual GfxShading *copy();
 
880
 
 
881
  int getNTriangles() { return nTriangles; }
 
882
 
 
883
  bool isParameterized() const { return nFuncs > 0; }
 
884
 
 
885
  /**
 
886
   * @precondition isParameterized() == true
 
887
   */
 
888
  double getParameterDomainMin() const { assert(isParameterized()); return funcs[0]->getDomainMin(0); }
 
889
 
 
890
  /**
 
891
   * @precondition isParameterized() == true
 
892
   */
 
893
  double getParameterDomainMax() const { assert(isParameterized()); return funcs[0]->getDomainMax(0); }
 
894
 
 
895
  /**
 
896
   * @precondition isParameterized() == false
 
897
   */
 
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);
 
901
 
 
902
  /**
 
903
   * Variant for functions.
 
904
   *
 
905
   * @precondition isParameterized() == true
 
906
   */
 
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);
 
910
 
 
911
  void getParameterizedColor(double t, GfxColor *color);
 
912
 
 
913
private:
 
914
 
 
915
  GfxGouraudVertex *vertices;
 
916
  int nVertices;
 
917
  int (*triangles)[3];
 
918
  int nTriangles;
 
919
  Function *funcs[gfxColorMaxComps];
 
920
  int nFuncs;
 
921
};
 
922
 
 
923
//------------------------------------------------------------------------
 
924
// GfxPatchMeshShading
 
925
//------------------------------------------------------------------------
 
926
 
 
927
/**
 
928
 * A tensor product cubic bezier patch consisting of 4x4 points and 4 color
 
929
 * values.
 
930
 *
 
931
 * See the Shading Type 7 specifications. Note that Shading Type 6 is also
 
932
 * represented using GfxPatch.
 
933
 */
 
934
struct GfxPatch {
 
935
  /**
 
936
   * Represents a single color value for the patch.
 
937
   */
 
938
  struct ColorValue {
 
939
    /**
 
940
     * For parameterized patches, only element 0 is valid; it contains
 
941
     * the single parameter.
 
942
     *
 
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.
 
946
     */
 
947
    double c[gfxColorMaxComps];
 
948
  };
 
949
 
 
950
  double x[4][4];
 
951
  double y[4][4];
 
952
  ColorValue color[2][2];
 
953
};
 
954
 
 
955
class GfxPatchMeshShading: public GfxShading {
 
956
public:
 
957
 
 
958
  GfxPatchMeshShading(int typeA, GfxPatch *patchesA, int nPatchesA,
 
959
                      Function **funcsA, int nFuncsA);
 
960
  GfxPatchMeshShading(GfxPatchMeshShading *shading);
 
961
  virtual ~GfxPatchMeshShading();
 
962
 
 
963
  static GfxPatchMeshShading *parse(int typeA, Dict *dict, Stream *str, Gfx *gfx);
 
964
 
 
965
  virtual GfxShading *copy();
 
966
 
 
967
  int getNPatches() { return nPatches; }
 
968
  GfxPatch *getPatch(int i) { return &patches[i]; }
 
969
 
 
970
  bool isParameterized() const { return nFuncs > 0; }
 
971
 
 
972
  /**
 
973
   * @precondition isParameterized() == true
 
974
   */
 
975
  double getParameterDomainMin() const { assert(isParameterized()); return funcs[0]->getDomainMin(0); }
 
976
 
 
977
  /**
 
978
   * @precondition isParameterized() == true
 
979
   */
 
980
  double getParameterDomainMax() const { assert(isParameterized()); return funcs[0]->getDomainMax(0); }
 
981
 
 
982
  void getParameterizedColor(double t, GfxColor *color);
 
983
 
 
984
private:
 
985
 
 
986
  GfxPatch *patches;
 
987
  int nPatches;
 
988
  Function *funcs[gfxColorMaxComps];
 
989
  int nFuncs;
 
990
};
 
991
 
 
992
//------------------------------------------------------------------------
 
993
// GfxImageColorMap
 
994
//------------------------------------------------------------------------
 
995
 
 
996
class GfxImageColorMap {
 
997
public:
 
998
 
 
999
  // Constructor.
 
1000
  GfxImageColorMap(int bitsA, Object *decode, GfxColorSpace *colorSpaceA);
 
1001
 
 
1002
  // Destructor.
 
1003
  ~GfxImageColorMap();
 
1004
 
 
1005
  // Return a copy of this color map.
 
1006
  GfxImageColorMap *copy() { return new GfxImageColorMap(this); }
 
1007
 
 
1008
  // Is color map valid?
 
1009
  GBool isOk() { return ok; }
 
1010
 
 
1011
  // Get the color space.
 
1012
  GfxColorSpace *getColorSpace() { return colorSpace; }
 
1013
 
 
1014
  // Get stream decoding info.
 
1015
  int getNumPixelComps() { return nComps; }
 
1016
  int getBits() { return bits; }
 
1017
 
 
1018
  // Get decode table.
 
1019
  double getDecodeLow(int i) { return decodeLow[i]; }
 
1020
  double getDecodeHigh(int i) { return decodeLow[i] + decodeRange[i]; }
 
1021
  
 
1022
  bool useRGBLine() { return (colorSpace2 && colorSpace2->useGetRGBLine ()) || (!colorSpace2 && colorSpace->useGetRGBLine ()); }
 
1023
 
 
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);
 
1031
 
 
1032
private:
 
1033
 
 
1034
  GfxImageColorMap(GfxImageColorMap *colorMap);
 
1035
 
 
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];
 
1048
  GBool ok;
 
1049
};
 
1050
 
 
1051
//------------------------------------------------------------------------
 
1052
// GfxSubpath and GfxPath
 
1053
//------------------------------------------------------------------------
 
1054
 
 
1055
class GfxSubpath {
 
1056
public:
 
1057
 
 
1058
  // Constructor.
 
1059
  GfxSubpath(double x1, double y1);
 
1060
 
 
1061
  // Destructor.
 
1062
  ~GfxSubpath();
 
1063
 
 
1064
  // Copy.
 
1065
  GfxSubpath *copy() { return new GfxSubpath(this); }
 
1066
 
 
1067
  // Get points.
 
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]; }
 
1072
 
 
1073
  void setX(int i, double a) { x[i] = a; }
 
1074
  void setY(int i, double a) { y[i] = a; }
 
1075
 
 
1076
  // Get last point.
 
1077
  double getLastX() { return x[n-1]; }
 
1078
  double getLastY() { return y[n-1]; }
 
1079
 
 
1080
  // Add a line segment.
 
1081
  void lineTo(double x1, double y1);
 
1082
 
 
1083
  // Add a Bezier curve.
 
1084
  void curveTo(double x1, double y1, double x2, double y2,
 
1085
               double x3, double y3);
 
1086
 
 
1087
  // Close the subpath.
 
1088
  void close();
 
1089
  GBool isClosed() { return closed; }
 
1090
 
 
1091
  // Add (<dx>, <dy>) to each point in the subpath.
 
1092
  void offset(double dx, double dy);
 
1093
 
 
1094
private:
 
1095
 
 
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
 
1102
 
 
1103
  GfxSubpath(GfxSubpath *subpath);
 
1104
};
 
1105
 
 
1106
class GfxPath {
 
1107
public:
 
1108
 
 
1109
  // Constructor.
 
1110
  GfxPath();
 
1111
 
 
1112
  // Destructor.
 
1113
  ~GfxPath();
 
1114
 
 
1115
  // Copy.
 
1116
  GfxPath *copy()
 
1117
    { return new GfxPath(justMoved, firstX, firstY, subpaths, n, size); }
 
1118
 
 
1119
  // Is there a current point?
 
1120
  GBool isCurPt() { return n > 0 || justMoved; }
 
1121
 
 
1122
  // Is the path non-empty, i.e., is there at least one segment?
 
1123
  GBool isPath() { return n > 0; }
 
1124
 
 
1125
  // Get subpaths.
 
1126
  int getNumSubpaths() { return n; }
 
1127
  GfxSubpath *getSubpath(int i) { return subpaths[i]; }
 
1128
 
 
1129
  // Get last point on last subpath.
 
1130
  double getLastX() { return subpaths[n-1]->getLastX(); }
 
1131
  double getLastY() { return subpaths[n-1]->getLastY(); }
 
1132
 
 
1133
  // Move the current point.
 
1134
  void moveTo(double x, double y);
 
1135
 
 
1136
  // Add a segment to the last subpath.
 
1137
  void lineTo(double x, double y);
 
1138
 
 
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);
 
1142
 
 
1143
  // Close the last subpath.
 
1144
  void close();
 
1145
 
 
1146
  // Append <path> to <this>.
 
1147
  void append(GfxPath *path);
 
1148
 
 
1149
  // Add (<dx>, <dy>) to each point in the path.
 
1150
  void offset(double dx, double dy);
 
1151
 
 
1152
private:
 
1153
 
 
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
 
1159
 
 
1160
  GfxPath(GBool justMoved1, double firstX1, double firstY1,
 
1161
          GfxSubpath **subpaths1, int n1, int size1);
 
1162
};
 
1163
 
 
1164
//------------------------------------------------------------------------
 
1165
// GfxState
 
1166
//------------------------------------------------------------------------
 
1167
 
 
1168
class GfxState {
 
1169
public:
 
1170
  /**
 
1171
   * When GfxState::getReusablePath() is invoked, the currently active
 
1172
   * path is taken per reference and its coordinates can be re-edited.
 
1173
   *
 
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).
 
1178
   */
 
1179
  class ReusablePathIterator {
 
1180
  public:
 
1181
    /**
 
1182
     * Creates the ReusablePathIterator. This should only be done from
 
1183
     * GfxState::getReusablePath().
 
1184
     *
 
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.
 
1190
     */
 
1191
    ReusablePathIterator( GfxPath* path );
 
1192
 
 
1193
    /**
 
1194
     * Returns true if and only if the current iterator position is
 
1195
     * beyond the last valid point.
 
1196
     *
 
1197
     * A call to setCoord() will be undefined.
 
1198
     */
 
1199
    bool isEnd() const;
 
1200
 
 
1201
    /**
 
1202
     * Advances the iterator.
 
1203
     */
 
1204
    void next();
 
1205
 
 
1206
     /**
 
1207
     * Updates the coordinates associated to the current iterator
 
1208
     * position.
 
1209
     */
 
1210
     void setCoord( double x, double y );
 
1211
 
 
1212
    /**
 
1213
     * Resets the iterator.
 
1214
     */
 
1215
    void reset();
 
1216
  private:
 
1217
    GfxPath *path;
 
1218
    int subPathOff;
 
1219
 
 
1220
    int coordOff;
 
1221
    int numCoords;
 
1222
 
 
1223
    GfxSubpath *curSubPath;
 
1224
  };
 
1225
 
 
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);
 
1231
 
 
1232
  // Destructor.
 
1233
  ~GfxState();
 
1234
 
 
1235
  // Copy.
 
1236
  GfxState *copy() { return new GfxState(this); }
 
1237
 
 
1238
  // Accessors.
 
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; }
 
1302
 
 
1303
  // Is there a current point/path?
 
1304
  GBool isCurPt() { return path->isCurPt(); }
 
1305
  GBool isPath() { return path->isPath(); }
 
1306
 
 
1307
  // Transforms.
 
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);
 
1325
 
 
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)
 
1367
    { rise = riseA; }
 
1368
  void setRender(int renderA)
 
1369
    { render = renderA; }
 
1370
 
 
1371
  // Add to path.
 
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); }
 
1379
  void closePath()
 
1380
    { path->close(); curX = path->getLastX(); curY = path->getLastY(); }
 
1381
  void clearPath();
 
1382
 
 
1383
  // Update clip region.
 
1384
  void clip();
 
1385
  void clipToStrokePath();
 
1386
 
 
1387
  // Text position.
 
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);
 
1393
 
 
1394
  // Push/pop GfxState on/off stack.
 
1395
  GfxState *save();
 
1396
  GfxState *restore();
 
1397
  GBool hasSaves() { return saved != NULL; }
 
1398
  GBool isParentState(GfxState *state) { return saved == state || (saved && saved->isParentState(state)); }
 
1399
 
 
1400
  // Misc
 
1401
  GBool parseBlendMode(Object *obj, GfxBlendMode *mode);
 
1402
 
 
1403
  ReusablePathIterator *getReusablePath() { return new ReusablePathIterator(path); }
 
1404
private:
 
1405
 
 
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
 
1411
 
 
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)
 
1427
 
 
1428
  double lineWidth;             // line width
 
1429
  double *lineDash;             // line dash
 
1430
  int lineDashLength;
 
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
 
1439
 
 
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
 
1449
 
 
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)
 
1453
 
 
1454
  double clipXMin, clipYMin,    // bounding box for clip region
 
1455
         clipXMax, clipYMax;
 
1456
 
 
1457
  GfxState *saved;              // next GfxState on stack
 
1458
 
 
1459
  GfxState(GfxState *state);
 
1460
};
 
1461
 
 
1462
#endif