~ubuntu-branches/ubuntu/hoary/libextractor/hoary

« back to all changes in this revision

Viewing changes to src/plugins/pdf/GfxState.h

  • Committer: Bazaar Package Importer
  • Author(s): Glenn McGrath
  • Date: 2004-06-26 12:59:02 UTC
  • Revision ID: james.westby@ubuntu.com-20040626125902-w97jpn43hsk7tcde
Tags: upstream-0.3.3
ImportĀ upstreamĀ versionĀ 0.3.3

Show diffs side-by-side

added added

removed removed

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