Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

GfxState.h

Go to the documentation of this file.
00001 //========================================================================
00002 //
00003 // GfxState.h
00004 //
00005 // Copyright 1996-2002 Glyph & Cog, LLC
00006 //
00007 //========================================================================
00008 
00009 #ifndef GFXSTATE_H
00010 #define GFXSTATE_H
00011 
00012 #ifdef __GNUC__
00013 #pragma interface
00014 #endif
00015 
00016 #include "gtypes.h"
00017 #include "Object.h"
00018 #include "Function.h"
00019 
00020 class Array;
00021 class GfxFont;
00022 struct PDFRectangle;
00023 
00024 //------------------------------------------------------------------------
00025 // GfxColor
00026 //------------------------------------------------------------------------
00027 
00028 #define gfxColorMaxComps funcMaxOutputs
00029 
00030 struct GfxColor {
00031   fouble c[gfxColorMaxComps];
00032 };
00033 
00034 //------------------------------------------------------------------------
00035 // GfxRGB
00036 //------------------------------------------------------------------------
00037 
00038 struct GfxRGB {
00039   fouble r, g, b;
00040 };
00041 
00042 //------------------------------------------------------------------------
00043 // GfxCMYK
00044 //------------------------------------------------------------------------
00045 
00046 struct GfxCMYK {
00047   fouble c, m, y, k;
00048 };
00049 
00050 //------------------------------------------------------------------------
00051 // GfxColorSpace
00052 //------------------------------------------------------------------------
00053 
00054 enum GfxColorSpaceMode {
00055   csDeviceGray,
00056   csCalGray,
00057   csDeviceRGB,
00058   csCalRGB,
00059   csDeviceCMYK,
00060   csLab,
00061   csICCBased,
00062   csIndexed,
00063   csSeparation,
00064   csDeviceN,
00065   csPattern
00066 };
00067 
00068 class GfxColorSpace {
00069 public:
00070 
00071   GfxColorSpace();
00072   virtual ~GfxColorSpace();
00073   virtual GfxColorSpace *copy() = 0;
00074   virtual GfxColorSpaceMode getMode() = 0;
00075 
00076   // Construct a color space.  Returns NULL if unsuccessful.
00077   static GfxColorSpace *parse(Object *csObj);
00078 
00079   // Convert to gray, RGB, or CMYK.
00080   virtual void getGray(GfxColor *color, fouble *gray) = 0;
00081   virtual void getRGB(GfxColor *color, GfxRGB *rgb) = 0;
00082   virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk) = 0;
00083 
00084   // Return the number of color components.
00085   virtual int getNComps() = 0;
00086 
00087   // Return the default ranges for each component, assuming an image
00088   // with a max pixel value of <maxImgPixel>.
00089   virtual void getDefaultRanges(fouble *decodeLow, fouble *decodeRange,
00090                                 int maxImgPixel);
00091 
00092 private:
00093 };
00094 
00095 //------------------------------------------------------------------------
00096 // GfxDeviceGrayColorSpace
00097 //------------------------------------------------------------------------
00098 
00099 class GfxDeviceGrayColorSpace: public GfxColorSpace {
00100 public:
00101 
00102   GfxDeviceGrayColorSpace();
00103   virtual ~GfxDeviceGrayColorSpace();
00104   virtual GfxColorSpace *copy();
00105   virtual GfxColorSpaceMode getMode() { return csDeviceGray; }
00106 
00107   virtual void getGray(GfxColor *color, fouble *gray);
00108   virtual void getRGB(GfxColor *color, GfxRGB *rgb);
00109   virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
00110 
00111   virtual int getNComps() { return 1; }
00112 
00113 private:
00114 };
00115 
00116 //------------------------------------------------------------------------
00117 // GfxCalGrayColorSpace
00118 //------------------------------------------------------------------------
00119 
00120 class GfxCalGrayColorSpace: public GfxColorSpace {
00121 public:
00122 
00123   GfxCalGrayColorSpace();
00124   virtual ~GfxCalGrayColorSpace();
00125   virtual GfxColorSpace *copy();
00126   virtual GfxColorSpaceMode getMode() { return csCalGray; }
00127 
00128   // Construct a CalGray color space.  Returns NULL if unsuccessful.
00129   static GfxColorSpace *parse(Array *arr);
00130 
00131   virtual void getGray(GfxColor *color, fouble *gray);
00132   virtual void getRGB(GfxColor *color, GfxRGB *rgb);
00133   virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
00134 
00135   virtual int getNComps() { return 1; }
00136 
00137   // CalGray-specific access.
00138   fouble getWhiteX() { return whiteX; }
00139   fouble getWhiteY() { return whiteY; }
00140   fouble getWhiteZ() { return whiteZ; }
00141   fouble getBlackX() { return blackX; }
00142   fouble getBlackY() { return blackY; }
00143   fouble getBlackZ() { return blackZ; }
00144   fouble getGamma() { return gamma; }
00145 
00146 private:
00147 
00148   fouble whiteX, whiteY, whiteZ;    // white point
00149   fouble blackX, blackY, blackZ;    // black point
00150   fouble gamma;                     // gamma value
00151 };
00152 
00153 //------------------------------------------------------------------------
00154 // GfxDeviceRGBColorSpace
00155 //------------------------------------------------------------------------
00156 
00157 class GfxDeviceRGBColorSpace: public GfxColorSpace {
00158 public:
00159 
00160   GfxDeviceRGBColorSpace();
00161   virtual ~GfxDeviceRGBColorSpace();
00162   virtual GfxColorSpace *copy();
00163   virtual GfxColorSpaceMode getMode() { return csDeviceRGB; }
00164 
00165   virtual void getGray(GfxColor *color, fouble *gray);
00166   virtual void getRGB(GfxColor *color, GfxRGB *rgb);
00167   virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
00168 
00169   virtual int getNComps() { return 3; }
00170 
00171 private:
00172 };
00173 
00174 //------------------------------------------------------------------------
00175 // GfxCalRGBColorSpace
00176 //------------------------------------------------------------------------
00177 
00178 class GfxCalRGBColorSpace: public GfxColorSpace {
00179 public:
00180 
00181   GfxCalRGBColorSpace();
00182   virtual ~GfxCalRGBColorSpace();
00183   virtual GfxColorSpace *copy();
00184   virtual GfxColorSpaceMode getMode() { return csCalRGB; }
00185 
00186   // Construct a CalRGB color space.  Returns NULL if unsuccessful.
00187   static GfxColorSpace *parse(Array *arr);
00188 
00189   virtual void getGray(GfxColor *color, fouble *gray);
00190   virtual void getRGB(GfxColor *color, GfxRGB *rgb);
00191   virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
00192 
00193   virtual int getNComps() { return 3; }
00194 
00195   // CalRGB-specific access.
00196   fouble getWhiteX() { return whiteX; }
00197   fouble getWhiteY() { return whiteY; }
00198   fouble getWhiteZ() { return whiteZ; }
00199   fouble getBlackX() { return blackX; }
00200   fouble getBlackY() { return blackY; }
00201   fouble getBlackZ() { return blackZ; }
00202   fouble getGammaR() { return gammaR; }
00203   fouble getGammaG() { return gammaG; }
00204   fouble getGammaB() { return gammaB; }
00205   fouble *getMatrix() { return mat; }
00206 
00207 private:
00208 
00209   fouble whiteX, whiteY, whiteZ;    // white point
00210   fouble blackX, blackY, blackZ;    // black point
00211   fouble gammaR, gammaG, gammaB;    // gamma values
00212   fouble mat[9];                // ABC -> XYZ transform matrix
00213 };
00214 
00215 //------------------------------------------------------------------------
00216 // GfxDeviceCMYKColorSpace
00217 //------------------------------------------------------------------------
00218 
00219 class GfxDeviceCMYKColorSpace: public GfxColorSpace {
00220 public:
00221 
00222   GfxDeviceCMYKColorSpace();
00223   virtual ~GfxDeviceCMYKColorSpace();
00224   virtual GfxColorSpace *copy();
00225   virtual GfxColorSpaceMode getMode() { return csDeviceCMYK; }
00226 
00227   virtual void getGray(GfxColor *color, fouble *gray);
00228   virtual void getRGB(GfxColor *color, GfxRGB *rgb);
00229   virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
00230 
00231   virtual int getNComps() { return 4; }
00232 
00233 private:
00234 };
00235 
00236 //------------------------------------------------------------------------
00237 // GfxLabColorSpace
00238 //------------------------------------------------------------------------
00239 
00240 class GfxLabColorSpace: public GfxColorSpace {
00241 public:
00242 
00243   GfxLabColorSpace();
00244   virtual ~GfxLabColorSpace();
00245   virtual GfxColorSpace *copy();
00246   virtual GfxColorSpaceMode getMode() { return csLab; }
00247 
00248   // Construct a Lab color space.  Returns NULL if unsuccessful.
00249   static GfxColorSpace *parse(Array *arr);
00250 
00251   virtual void getGray(GfxColor *color, fouble *gray);
00252   virtual void getRGB(GfxColor *color, GfxRGB *rgb);
00253   virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
00254 
00255   virtual int getNComps() { return 3; }
00256 
00257   virtual void getDefaultRanges(fouble *decodeLow, fouble *decodeRange,
00258                                 int maxImgPixel);
00259 
00260   // Lab-specific access.
00261   fouble getWhiteX() { return whiteX; }
00262   fouble getWhiteY() { return whiteY; }
00263   fouble getWhiteZ() { return whiteZ; }
00264   fouble getBlackX() { return blackX; }
00265   fouble getBlackY() { return blackY; }
00266   fouble getBlackZ() { return blackZ; }
00267   fouble getAMin() { return aMin; }
00268   fouble getAMax() { return aMax; }
00269   fouble getBMin() { return bMin; }
00270   fouble getBMax() { return bMax; }
00271 
00272 private:
00273 
00274   fouble whiteX, whiteY, whiteZ;    // white point
00275   fouble blackX, blackY, blackZ;    // black point
00276   fouble aMin, aMax, bMin, bMax;    // range for the a and b components
00277   fouble kr, kg, kb;                // gamut mapping mulitpliers
00278 };
00279 
00280 //------------------------------------------------------------------------
00281 // GfxICCBasedColorSpace
00282 //------------------------------------------------------------------------
00283 
00284 class GfxICCBasedColorSpace: public GfxColorSpace {
00285 public:
00286 
00287   GfxICCBasedColorSpace(int nCompsA, GfxColorSpace *altA,
00288                         Ref *iccProfileStreamA);
00289   virtual ~GfxICCBasedColorSpace();
00290   virtual GfxColorSpace *copy();
00291   virtual GfxColorSpaceMode getMode() { return csICCBased; }
00292 
00293   // Construct an ICCBased color space.  Returns NULL if unsuccessful.
00294   static GfxColorSpace *parse(Array *arr);
00295 
00296   virtual void getGray(GfxColor *color, fouble *gray);
00297   virtual void getRGB(GfxColor *color, GfxRGB *rgb);
00298   virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
00299 
00300   virtual int getNComps() { return nComps; }
00301 
00302   virtual void getDefaultRanges(fouble *decodeLow, fouble *decodeRange,
00303                                 int maxImgPixel);
00304 
00305   // ICCBased-specific access.
00306   GfxColorSpace *getAlt() { return alt; }
00307 
00308 private:
00309 
00310   int nComps;                   // number of color components (1, 3, or 4)
00311   GfxColorSpace *alt;           // alternate color space
00312   fouble rangeMin[4];           // min values for each component
00313   fouble rangeMax[4];           // max values for each component
00314   Ref iccProfileStream;         // the ICC profile
00315 };
00316 
00317 //------------------------------------------------------------------------
00318 // GfxIndexedColorSpace
00319 //------------------------------------------------------------------------
00320 
00321 class GfxIndexedColorSpace: public GfxColorSpace {
00322 public:
00323 
00324   GfxIndexedColorSpace(GfxColorSpace *baseA, int indexHighA);
00325   virtual ~GfxIndexedColorSpace();
00326   virtual GfxColorSpace *copy();
00327   virtual GfxColorSpaceMode getMode() { return csIndexed; }
00328 
00329   // Construct a Lab color space.  Returns NULL if unsuccessful.
00330   static GfxColorSpace *parse(Array *arr);
00331 
00332   virtual void getGray(GfxColor *color, fouble *gray);
00333   virtual void getRGB(GfxColor *color, GfxRGB *rgb);
00334   virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
00335 
00336   virtual int getNComps() { return 1; }
00337 
00338   virtual void getDefaultRanges(fouble *decodeLow, fouble *decodeRange,
00339                                 int maxImgPixel);
00340 
00341   // Indexed-specific access.
00342   GfxColorSpace *getBase() { return base; }
00343   int getIndexHigh() { return indexHigh; }
00344   Guchar *getLookup() { return lookup; }
00345 
00346 private:
00347 
00348   GfxColorSpace *base;          // base color space
00349   int indexHigh;                // max pixel value
00350   Guchar *lookup;               // lookup table
00351 };
00352 
00353 //------------------------------------------------------------------------
00354 // GfxSeparationColorSpace
00355 //------------------------------------------------------------------------
00356 
00357 class GfxSeparationColorSpace: public GfxColorSpace {
00358 public:
00359 
00360   GfxSeparationColorSpace(GString *nameA, GfxColorSpace *altA,
00361                           Function *funcA);
00362   virtual ~GfxSeparationColorSpace();
00363   virtual GfxColorSpace *copy();
00364   virtual GfxColorSpaceMode getMode() { return csSeparation; }
00365 
00366   // Construct a Separation color space.  Returns NULL if unsuccessful.
00367   static GfxColorSpace *parse(Array *arr);
00368 
00369   virtual void getGray(GfxColor *color, fouble *gray);
00370   virtual void getRGB(GfxColor *color, GfxRGB *rgb);
00371   virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
00372 
00373   virtual int getNComps() { return 1; }
00374 
00375   // Separation-specific access.
00376   GString *getName() { return name; }
00377   GfxColorSpace *getAlt() { return alt; }
00378   Function *getFunc() { return func; }
00379 
00380 private:
00381 
00382   GString *name;                // colorant name
00383   GfxColorSpace *alt;           // alternate color space
00384   Function *func;               // tint transform (into alternate color space)
00385 };
00386 
00387 //------------------------------------------------------------------------
00388 // GfxDeviceNColorSpace
00389 //------------------------------------------------------------------------
00390 
00391 class GfxDeviceNColorSpace: public GfxColorSpace {
00392 public:
00393 
00394   GfxDeviceNColorSpace(int nComps, GfxColorSpace *alt, Function *func);
00395   virtual ~GfxDeviceNColorSpace();
00396   virtual GfxColorSpace *copy();
00397   virtual GfxColorSpaceMode getMode() { return csDeviceN; }
00398 
00399   // Construct a DeviceN color space.  Returns NULL if unsuccessful.
00400   static GfxColorSpace *parse(Array *arr);
00401 
00402   virtual void getGray(GfxColor *color, fouble *gray);
00403   virtual void getRGB(GfxColor *color, GfxRGB *rgb);
00404   virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
00405 
00406   virtual int getNComps() { return nComps; }
00407 
00408   // DeviceN-specific access.
00409   GfxColorSpace *getAlt() { return alt; }
00410 
00411 private:
00412 
00413   int nComps;                   // number of components
00414   GString                       // colorant names
00415     *names[gfxColorMaxComps];
00416   GfxColorSpace *alt;           // alternate color space
00417   Function *func;               // tint transform (into alternate color space)
00418   
00419 };
00420 
00421 //------------------------------------------------------------------------
00422 // GfxPatternColorSpace
00423 //------------------------------------------------------------------------
00424 
00425 class GfxPatternColorSpace: public GfxColorSpace {
00426 public:
00427 
00428   GfxPatternColorSpace(GfxColorSpace *underA);
00429   virtual ~GfxPatternColorSpace();
00430   virtual GfxColorSpace *copy();
00431   virtual GfxColorSpaceMode getMode() { return csPattern; }
00432 
00433   // Construct a Pattern color space.  Returns NULL if unsuccessful.
00434   static GfxColorSpace *parse(Array *arr);
00435 
00436   virtual void getGray(GfxColor *color, fouble *gray);
00437   virtual void getRGB(GfxColor *color, GfxRGB *rgb);
00438   virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
00439 
00440   virtual int getNComps() { return 0; }
00441 
00442   // Pattern-specific access.
00443   GfxColorSpace *getUnder() { return under; }
00444 
00445 private:
00446 
00447   GfxColorSpace *under;         // underlying color space (for uncolored
00448                                 //   patterns)
00449 };
00450 
00451 //------------------------------------------------------------------------
00452 // GfxPattern
00453 //------------------------------------------------------------------------
00454 
00455 class GfxPattern {
00456 public:
00457 
00458   GfxPattern(int typeA);
00459   virtual ~GfxPattern();
00460 
00461   static GfxPattern *parse(Object *obj);
00462 
00463   virtual GfxPattern *copy() = 0;
00464 
00465   int getType() { return type; }
00466 
00467 private:
00468 
00469   int type;
00470 };
00471 
00472 //------------------------------------------------------------------------
00473 // GfxTilingPattern
00474 //------------------------------------------------------------------------
00475 
00476 class GfxTilingPattern: public GfxPattern {
00477 public:
00478 
00479   GfxTilingPattern(Dict *streamDict, Object *stream);
00480   virtual ~GfxTilingPattern();
00481 
00482   virtual GfxPattern *copy();
00483 
00484   int getPaintType() { return paintType; }
00485   int getTilingType() { return tilingType; }
00486   fouble *getBBox() { return bbox; }
00487   fouble getXStep() { return xStep; }
00488   fouble getYStep() { return yStep; }
00489   Dict *getResDict()
00490     { return resDict.isDict() ? resDict.getDict() : (Dict *)NULL; }
00491   fouble *getMatrix() { return matrix; }
00492   Object *getContentStream() { return &contentStream; }
00493 
00494 private:
00495 
00496   GfxTilingPattern(GfxTilingPattern *pat);
00497 
00498   int paintType;
00499   int tilingType;
00500   fouble bbox[4];
00501   fouble xStep, yStep;
00502   Object resDict;
00503   fouble matrix[6];
00504   Object contentStream;
00505 };
00506 
00507 //------------------------------------------------------------------------
00508 // GfxShading
00509 //------------------------------------------------------------------------
00510 
00511 class GfxShading {
00512 public:
00513 
00514   GfxShading();
00515   virtual ~GfxShading();
00516 
00517   static GfxShading *parse(Object *obj);
00518 
00519   int getType() { return type; }
00520   GfxColorSpace *getColorSpace() { return colorSpace; }
00521   GfxColor *getBackground() { return &background; }
00522   GBool getHasBackground() { return hasBackground; }
00523   void getBBox(fouble *xMinA, fouble *yMinA, fouble *xMaxA, fouble *yMaxA)
00524     { *xMinA = xMin; *yMinA = yMin; *xMaxA = xMax; *yMaxA = yMax; }
00525   GBool getHasBBox() { return hasBBox; }
00526 
00527 private:
00528 
00529   int type;
00530   GfxColorSpace *colorSpace;
00531   GfxColor background;
00532   GBool hasBackground;
00533   fouble xMin, yMin, xMax, yMax;
00534   GBool hasBBox;
00535 };
00536 
00537 //------------------------------------------------------------------------
00538 // GfxAxialShading
00539 //------------------------------------------------------------------------
00540 
00541 class GfxAxialShading: public GfxShading {
00542 public:
00543 
00544   GfxAxialShading(fouble x0A, fouble y0A,
00545                   fouble x1A, fouble y1A,
00546                   fouble t0A, fouble t1A,
00547                   Function **funcsA, int nFuncsA,
00548                   GBool extend0A, GBool extend1A);
00549   virtual ~GfxAxialShading();
00550 
00551   static GfxAxialShading *parse(Dict *dict);
00552 
00553   void getCoords(fouble *x0A, fouble *y0A, fouble *x1A, fouble *y1A)
00554     { *x0A = x0; *y0A = y0; *x1A = x1; *y1A = y1; }
00555   fouble getDomain0() { return t0; }
00556   fouble getDomain1() { return t1; }
00557   void getColor(fouble t, GfxColor *color);
00558   GBool getExtend0() { return extend0; }
00559   GBool getExtend1() { return extend1; }
00560 
00561 private:
00562 
00563   fouble x0, y0, x1, y1;
00564   fouble t0, t1;
00565   Function *funcs[gfxColorMaxComps];
00566   int nFuncs;
00567   GBool extend0, extend1;
00568 };
00569 
00570 //------------------------------------------------------------------------
00571 // GfxRadialShading
00572 //------------------------------------------------------------------------
00573 
00574 class GfxRadialShading: public GfxShading {
00575 public:
00576 
00577   GfxRadialShading(fouble x0A, fouble y0A, fouble r0A,
00578                    fouble x1A, fouble y1A, fouble r1A,
00579                    fouble t0A, fouble t1A,
00580                    Function **funcsA, int nFuncsA,
00581                    GBool extend0A, GBool extend1A);
00582   virtual ~GfxRadialShading();
00583 
00584   static GfxRadialShading *parse(Dict *dict);
00585 
00586   void getCoords(fouble *x0A, fouble *y0A, fouble *r0A,
00587                  fouble *x1A, fouble *y1A, fouble *r1A)
00588     { *x0A = x0; *y0A = y0; *r0A = r0; *x1A = x1; *y1A = y1; *r1A = r1; }
00589   fouble getDomain0() { return t0; }
00590   fouble getDomain1() { return t1; }
00591   void getColor(fouble t, GfxColor *color);
00592   GBool getExtend0() { return extend0; }
00593   GBool getExtend1() { return extend1; }
00594 
00595 private:
00596 
00597   fouble x0, y0, r0, x1, y1, r1;
00598   fouble t0, t1;
00599   Function *funcs[gfxColorMaxComps];
00600   int nFuncs;
00601   GBool extend0, extend1;
00602 };
00603 
00604 //------------------------------------------------------------------------
00605 // GfxImageColorMap
00606 //------------------------------------------------------------------------
00607 
00608 class GfxImageColorMap {
00609 public:
00610 
00611   // Constructor.
00612   GfxImageColorMap(int bitsA, Object *decode, GfxColorSpace *colorSpaceA);
00613 
00614   // Destructor.
00615   ~GfxImageColorMap();
00616 
00617   // Is color map valid?
00618   GBool isOk() { return ok; }
00619 
00620   // Get the color space.
00621   GfxColorSpace *getColorSpace() { return colorSpace; }
00622 
00623   // Get stream decoding info.
00624   int getNumPixelComps() { return nComps; }
00625   int getBits() { return bits; }
00626 
00627   // Get decode table.
00628   fouble getDecodeLow(int i) { return decodeLow[i]; }
00629   fouble getDecodeHigh(int i) { return decodeLow[i] + decodeRange[i]; }
00630 
00631   // Convert an image pixel to a color.
00632   void getGray(Guchar *x, fouble *gray);
00633   void getRGB(Guchar *x, GfxRGB *rgb);
00634   void getCMYK(Guchar *x, GfxCMYK *cmyk);
00635 
00636 private:
00637 
00638   GfxColorSpace *colorSpace;    // the image color space
00639   int bits;                     // bits per component
00640   int nComps;                   // number of components in a pixel
00641   GfxColorSpace *colorSpace2;   // secondary color space
00642   int nComps2;                  // number of components in colorSpace2
00643   fouble *lookup;               // lookup table
00644   fouble                        // minimum values for each component
00645     decodeLow[gfxColorMaxComps];
00646   fouble                        // max - min value for each component
00647     decodeRange[gfxColorMaxComps];
00648   GBool ok;
00649 };
00650 
00651 //------------------------------------------------------------------------
00652 // GfxSubpath and GfxPath
00653 //------------------------------------------------------------------------
00654 
00655 class GfxSubpath {
00656 public:
00657 
00658   // Constructor.
00659   GfxSubpath(fouble x1, fouble y1);
00660 
00661   // Destructor.
00662   ~GfxSubpath();
00663 
00664   // Copy.
00665   GfxSubpath *copy() { return new GfxSubpath(this); }
00666 
00667   // Get points.
00668   int getNumPoints() { return n; }
00669   fouble getX(int i) { return x[i]; }
00670   fouble getY(int i) { return y[i]; }
00671   GBool getCurve(int i) { return curve[i]; }
00672 
00673   // Get last point.
00674   fouble getLastX() { return x[n-1]; }
00675   fouble getLastY() { return y[n-1]; }
00676 
00677   // Add a line segment.
00678   void lineTo(fouble x1, fouble y1);
00679 
00680   // Add a Bezier curve.
00681   void curveTo(fouble x1, fouble y1, fouble x2, fouble y2,
00682                fouble x3, fouble y3);
00683 
00684   // Close the subpath.
00685   void close();
00686   GBool isClosed() { return closed; }
00687 
00688 private:
00689 
00690   fouble *x, *y;                // points
00691   GBool *curve;                 // curve[i] => point i is a control point
00692                                 //   for a Bezier curve
00693   int n;                        // number of points
00694   int size;                     // size of x/y arrays
00695   GBool closed;                 // set if path is closed
00696 
00697   GfxSubpath(GfxSubpath *subpath);
00698 };
00699 
00700 class GfxPath {
00701 public:
00702 
00703   // Constructor.
00704   GfxPath();
00705 
00706   // Destructor.
00707   ~GfxPath();
00708 
00709   // Copy.
00710   GfxPath *copy()
00711     { return new GfxPath(justMoved, firstX, firstY, subpaths, n, size); }
00712 
00713   // Is there a current point?
00714   GBool isCurPt() { return n > 0 || justMoved; }
00715 
00716   // Is the path non-empty, i.e., is there at least one segment?
00717   GBool isPath() { return n > 0; }
00718 
00719   // Get subpaths.
00720   int getNumSubpaths() { return n; }
00721   GfxSubpath *getSubpath(int i) { return subpaths[i]; }
00722 
00723   // Get last point on last subpath.
00724   fouble getLastX() { return subpaths[n-1]->getLastX(); }
00725   fouble getLastY() { return subpaths[n-1]->getLastY(); }
00726 
00727   // Move the current point.
00728   void moveTo(fouble x, fouble y);
00729 
00730   // Add a segment to the last subpath.
00731   void lineTo(fouble x, fouble y);
00732 
00733   // Add a Bezier curve to the last subpath
00734   void curveTo(fouble x1, fouble y1, fouble x2, fouble y2,
00735                fouble x3, fouble y3);
00736 
00737   // Close the last subpath.
00738   void close();
00739 
00740 private:
00741 
00742   GBool justMoved;              // set if a new subpath was just started
00743   fouble firstX, firstY;        // first point in new subpath
00744   GfxSubpath **subpaths;        // subpaths
00745   int n;                        // number of subpaths
00746   int size;                     // size of subpaths array
00747 
00748   GfxPath(GBool justMoved1, fouble firstX1, fouble firstY1,
00749           GfxSubpath **subpaths1, int n1, int size1);
00750 };
00751 
00752 //------------------------------------------------------------------------
00753 // GfxState
00754 //------------------------------------------------------------------------
00755 
00756 class GfxState {
00757 public:
00758 
00759   // Construct a default GfxState, for a device with resolution <dpi>,
00760   // page box <pageBox>, page rotation <rotate>, and coordinate system
00761   // specified by <upsideDown>.
00762   GfxState(fouble dpi, PDFRectangle *pageBox, int rotate,
00763            GBool upsideDown);
00764 
00765   // Destructor.
00766   ~GfxState();
00767 
00768   // Copy.
00769   GfxState *copy() { return new GfxState(this); }
00770 
00771   // Accessors.
00772   fouble *getCTM() { return ctm; }
00773   fouble getX1() { return px1; }
00774   fouble getY1() { return py1; }
00775   fouble getX2() { return px2; }
00776   fouble getY2() { return py2; }
00777   fouble getPageWidth() { return pageWidth; }
00778   fouble getPageHeight() { return pageHeight; }
00779   GfxColor *getFillColor() { return &fillColor; }
00780   GfxColor *getStrokeColor() { return &strokeColor; }
00781   void getFillGray(fouble *gray)
00782     { fillColorSpace->getGray(&fillColor, gray); }
00783   void getStrokeGray(fouble *gray)
00784     { strokeColorSpace->getGray(&fillColor, gray); }
00785   void getFillRGB(GfxRGB *rgb)
00786     { fillColorSpace->getRGB(&fillColor, rgb); }
00787   void getStrokeRGB(GfxRGB *rgb)
00788     { strokeColorSpace->getRGB(&strokeColor, rgb); }
00789   void getFillCMYK(GfxCMYK *cmyk)
00790     { fillColorSpace->getCMYK(&fillColor, cmyk); }
00791   void getStrokeCMYK(GfxCMYK *cmyk)
00792     { strokeColorSpace->getCMYK(&strokeColor, cmyk); }
00793   GfxColorSpace *getFillColorSpace() { return fillColorSpace; }
00794   GfxColorSpace *getStrokeColorSpace() { return strokeColorSpace; }
00795   GfxPattern *getFillPattern() { return fillPattern; }
00796   GfxPattern *getStrokePattern() { return strokePattern; }
00797   fouble getFillOpacity() { return fillOpacity; }
00798   fouble getStrokeOpacity() { return strokeOpacity; }
00799   fouble getLineWidth() { return lineWidth; }
00800   void getLineDash(fouble **dash, int *length, fouble *start)
00801     { *dash = lineDash; *length = lineDashLength; *start = lineDashStart; }
00802   int getFlatness() { return flatness; }
00803   int getLineJoin() { return lineJoin; }
00804   int getLineCap() { return lineCap; }
00805   fouble getMiterLimit() { return miterLimit; }
00806   GfxFont *getFont() { return font; }
00807   fouble getFontSize() { return fontSize; }
00808   fouble *getTextMat() { return textMat; }
00809   fouble getCharSpace() { return charSpace; }
00810   fouble getWordSpace() { return wordSpace; }
00811   fouble getHorizScaling() { return horizScaling; }
00812   fouble getLeading() { return leading; }
00813   fouble getRise() { return rise; }
00814   int getRender() { return render; }
00815   GfxPath *getPath() { return path; }
00816   fouble getCurX() { return curX; }
00817   fouble getCurY() { return curY; }
00818   void getClipBBox(fouble *xMin, fouble *yMin, fouble *xMax, fouble *yMax)
00819     { *xMin = clipXMin; *yMin = clipYMin; *xMax = clipXMax; *yMax = clipYMax; }
00820   void getUserClipBBox(fouble *xMin, fouble *yMin, fouble *xMax, fouble *yMax);
00821   fouble getLineX() { return lineX; }
00822   fouble getLineY() { return lineY; }
00823 
00824   // Is there a current point/path?
00825   GBool isCurPt() { return path->isCurPt(); }
00826   GBool isPath() { return path->isPath(); }
00827 
00828   // Transforms.
00829   void transform(fouble x1, fouble y1, fouble *x2, fouble *y2)
00830     { *x2 = ctm[0] * x1 + ctm[2] * y1 + ctm[4];
00831       *y2 = ctm[1] * x1 + ctm[3] * y1 + ctm[5]; }
00832   void transformDelta(fouble x1, fouble y1, fouble *x2, fouble *y2)
00833     { *x2 = ctm[0] * x1 + ctm[2] * y1;
00834       *y2 = ctm[1] * x1 + ctm[3] * y1; }
00835   void textTransform(fouble x1, fouble y1, fouble *x2, fouble *y2)
00836     { *x2 = textMat[0] * x1 + textMat[2] * y1 + textMat[4];
00837       *y2 = textMat[1] * x1 + textMat[3] * y1 + textMat[5]; }
00838   void textTransformDelta(fouble x1, fouble y1, fouble *x2, fouble *y2)
00839     { *x2 = textMat[0] * x1 + textMat[2] * y1;
00840       *y2 = textMat[1] * x1 + textMat[3] * y1; }
00841   fouble transformWidth(fouble w);
00842   fouble getTransformedLineWidth()
00843     { return transformWidth(lineWidth); }
00844   fouble getTransformedFontSize();
00845   void getFontTransMat(fouble *m11, fouble *m12, fouble *m21, fouble *m22);
00846 
00847   // Change state parameters.
00848   void setCTM(fouble a, fouble b, fouble c,
00849               fouble d, fouble e, fouble f);
00850   void concatCTM(fouble a, fouble b, fouble c,
00851                  fouble d, fouble e, fouble f);
00852   void setFillColorSpace(GfxColorSpace *colorSpace);
00853   void setStrokeColorSpace(GfxColorSpace *colorSpace);
00854   void setFillColor(GfxColor *color) { fillColor = *color; }
00855   void setStrokeColor(GfxColor *color) { strokeColor = *color; }
00856   void setFillPattern(GfxPattern *pattern);
00857   void setStrokePattern(GfxPattern *pattern);
00858   void setFillOpacity(fouble opac) { fillOpacity = opac; }
00859   void setStrokeOpacity(fouble opac) { strokeOpacity = opac; }
00860   void setLineWidth(fouble width) { lineWidth = width; }
00861   void setLineDash(fouble *dash, int length, fouble start);
00862   void setFlatness(int flatness1) { flatness = flatness1; }
00863   void setLineJoin(int lineJoin1) { lineJoin = lineJoin1; }
00864   void setLineCap(int lineCap1) { lineCap = lineCap1; }
00865   void setMiterLimit(fouble limit) { miterLimit = limit; }
00866   void setFont(GfxFont *fontA, fouble fontSizeA)
00867     { font = fontA; fontSize = fontSizeA; }
00868   void setTextMat(fouble a, fouble b, fouble c,
00869                   fouble d, fouble e, fouble f)
00870     { textMat[0] = a; textMat[1] = b; textMat[2] = c;
00871       textMat[3] = d; textMat[4] = e; textMat[5] = f; }
00872   void setCharSpace(fouble space)
00873     { charSpace = space; }
00874   void setWordSpace(fouble space)
00875     { wordSpace = space; }
00876   void setHorizScaling(fouble scale)
00877     { horizScaling = 0.01 * scale; }
00878   void setLeading(fouble leadingA)
00879     { leading = leadingA; }
00880   void setRise(fouble riseA)
00881     { rise = riseA; }
00882   void setRender(int renderA)
00883     { render = renderA; }
00884 
00885   // Add to path.
00886   void moveTo(fouble x, fouble y)
00887     { path->moveTo(curX = x, curY = y); }
00888   void lineTo(fouble x, fouble y)
00889     { path->lineTo(curX = x, curY = y); }
00890   void curveTo(fouble x1, fouble y1, fouble x2, fouble y2,
00891                fouble x3, fouble y3)
00892     { path->curveTo(x1, y1, x2, y2, curX = x3, curY = y3); }
00893   void closePath()
00894     { path->close(); curX = path->getLastX(); curY = path->getLastY(); }
00895   void clearPath();
00896 
00897   // Update clip region.
00898   void clip();
00899 
00900   // Text position.
00901   void textMoveTo(fouble tx, fouble ty)
00902     { lineX = tx; lineY = ty; textTransform(tx, ty, &curX, &curY); }
00903   void textShift(fouble tx, fouble ty);
00904   void shift(fouble dx, fouble dy);
00905 
00906   // Push/pop GfxState on/off stack.
00907   GfxState *save();
00908   GfxState *restore();
00909   GBool hasSaves() { return saved != NULL; }
00910 
00911 private:
00912 
00913   fouble ctm[6];                // coord transform matrix
00914   fouble px1, py1, px2, py2;    // page corners (user coords)
00915   fouble pageWidth, pageHeight; // page size (pixels)
00916 
00917   GfxColorSpace *fillColorSpace;   // fill color space
00918   GfxColorSpace *strokeColorSpace; // stroke color space
00919   GfxColor fillColor;           // fill color
00920   GfxColor strokeColor;         // stroke color
00921   GfxPattern *fillPattern;      // fill pattern
00922   GfxPattern *strokePattern;    // stroke pattern
00923   fouble fillOpacity;           // fill opacity
00924   fouble strokeOpacity;         // stroke opacity
00925 
00926   fouble lineWidth;             // line width
00927   fouble *lineDash;             // line dash
00928   int lineDashLength;
00929   fouble lineDashStart;
00930   int flatness;                 // curve flatness
00931   int lineJoin;                 // line join style
00932   int lineCap;                  // line cap style
00933   fouble miterLimit;            // line miter limit
00934 
00935   GfxFont *font;                // font
00936   fouble fontSize;              // font size
00937   fouble textMat[6];            // text matrix
00938   fouble charSpace;             // character spacing
00939   fouble wordSpace;             // word spacing
00940   fouble horizScaling;          // horizontal scaling
00941   fouble leading;               // text leading
00942   fouble rise;                  // text rise
00943   int render;                   // text rendering mode
00944 
00945   GfxPath *path;                // array of path elements
00946   fouble curX, curY;            // current point (user coords)
00947   fouble lineX, lineY;          // start of current text line (text coords)
00948 
00949   fouble clipXMin, clipYMin,    // bounding box for clip region
00950          clipXMax, clipYMax;
00951 
00952   GfxState *saved;              // next GfxState on stack
00953 
00954   GfxState(GfxState *state);
00955 };
00956 
00957 #endif

Generated on Sat Nov 5 16:18:15 2005 for OPIE by  doxygen 1.4.2