Back to index

tetex-bin  3.0
Gfx.h
Go to the documentation of this file.
00001 //========================================================================
00002 //
00003 // Gfx.h
00004 //
00005 // Copyright 1996-2003 Glyph & Cog, LLC
00006 //
00007 //========================================================================
00008 
00009 #ifndef GFX_H
00010 #define GFX_H
00011 
00012 #include <aconf.h>
00013 
00014 #ifdef USE_GCC_PRAGMAS
00015 #pragma interface
00016 #endif
00017 
00018 #include "gtypes.h"
00019 
00020 class GString;
00021 class XRef;
00022 class Array;
00023 class Stream;
00024 class Parser;
00025 class Dict;
00026 class OutputDev;
00027 class GfxFontDict;
00028 class GfxFont;
00029 class GfxPattern;
00030 class GfxTilingPattern;
00031 class GfxShadingPattern;
00032 class GfxShading;
00033 class GfxFunctionShading;
00034 class GfxAxialShading;
00035 class GfxRadialShading;
00036 class GfxState;
00037 struct GfxColor;
00038 class Gfx;
00039 class PDFRectangle;
00040 
00041 //------------------------------------------------------------------------
00042 // Gfx
00043 //------------------------------------------------------------------------
00044 
00045 enum GfxClipType {
00046   clipNone,
00047   clipNormal,
00048   clipEO
00049 };
00050 
00051 enum TchkType {
00052   tchkBool,                 // boolean
00053   tchkInt,                  // integer
00054   tchkNum,                  // number (integer or real)
00055   tchkString,               // string
00056   tchkName,                 // name
00057   tchkArray,                // array
00058   tchkProps,                // properties (dictionary or name)
00059   tchkSCN,                  // scn/SCN args (number of name)
00060   tchkNone                  // used to avoid empty initializer lists
00061 };
00062 
00063 #define maxArgs 8
00064 
00065 struct Operator {
00066   char name[4];
00067   int numArgs;
00068   TchkType tchk[maxArgs];
00069   void (Gfx::*func)(Object args[], int numArgs);
00070 };
00071 
00072 class GfxResources {
00073 public:
00074 
00075   GfxResources(XRef *xref, Dict *resDict, GfxResources *nextA);
00076   ~GfxResources();
00077 
00078   GfxFont *lookupFont(char *name);
00079   GBool lookupXObject(char *name, Object *obj);
00080   GBool lookupXObjectNF(char *name, Object *obj);
00081   void lookupColorSpace(char *name, Object *obj);
00082   GfxPattern *lookupPattern(char *name);
00083   GfxShading *lookupShading(char *name);
00084   GBool lookupGState(char *name, Object *obj);
00085 
00086   GfxResources *getNext() { return next; }
00087 
00088 private:
00089 
00090   GfxFontDict *fonts;
00091   Object xObjDict;
00092   Object colorSpaceDict;
00093   Object patternDict;
00094   Object shadingDict;
00095   Object gStateDict;
00096   GfxResources *next;
00097 };
00098 
00099 class Gfx {
00100 public:
00101 
00102   // Constructor for regular output.
00103   Gfx(XRef *xrefA, OutputDev *outA, int pageNum, Dict *resDict,
00104       double hDPI, double vDPI, PDFRectangle *box, GBool crop,
00105       PDFRectangle *cropBox, int rotate,
00106       GBool (*abortCheckCbkA)(void *data) = NULL,
00107       void *abortCheckCbkDataA = NULL);
00108 
00109   // Constructor for a sub-page object.
00110   Gfx(XRef *xrefA, OutputDev *outA, Dict *resDict,
00111       PDFRectangle *box, GBool crop, PDFRectangle *cropBox,
00112       GBool (*abortCheckCbkA)(void *data) = NULL,
00113       void *abortCheckCbkDataA = NULL);
00114 
00115   ~Gfx();
00116 
00117   // Interpret a stream or array of streams.
00118   void display(Object *obj, GBool topLevel = gTrue);
00119 
00120   // Display an annotation, given its appearance (a Form XObject) and
00121   // bounding box (in default user space).
00122   void doAnnot(Object *str, double xMin, double yMin,
00123               double xMax, double yMax);
00124 
00125   // Save graphics state.
00126   void saveState();
00127 
00128   // Restore graphics state.
00129   void restoreState();
00130 
00131 private:
00132 
00133   XRef *xref;               // the xref table for this PDF file
00134   OutputDev *out;           // output device
00135   GBool subPage;            // is this a sub-page object?
00136   GBool printCommands;             // print the drawing commands (for debugging)
00137   GfxResources *res;        // resource stack
00138   int updateLevel;
00139 
00140   GfxState *state;          // current graphics state
00141   GBool fontChanged;        // set if font or text matrix has changed
00142   GfxClipType clip;         // do a clip?
00143   int ignoreUndef;          // current BX/EX nesting level
00144   double baseMatrix[6];            // default matrix for most recent
00145                             //   page/form/pattern
00146   int formDepth;
00147 
00148   Parser *parser;           // parser for page content stream(s)
00149 
00150   GBool                            // callback to check for an abort
00151     (*abortCheckCbk)(void *data);
00152   void *abortCheckCbkData;
00153 
00154   static Operator opTab[];  // table of operators
00155 
00156   void go(GBool topLevel);
00157   void execOp(Object *cmd, Object args[], int numArgs);
00158   Operator *findOp(char *name);
00159   GBool checkArg(Object *arg, TchkType type);
00160   int getPos();
00161 
00162   // graphics state operators
00163   void opSave(Object args[], int numArgs);
00164   void opRestore(Object args[], int numArgs);
00165   void opConcat(Object args[], int numArgs);
00166   void opSetDash(Object args[], int numArgs);
00167   void opSetFlat(Object args[], int numArgs);
00168   void opSetLineJoin(Object args[], int numArgs);
00169   void opSetLineCap(Object args[], int numArgs);
00170   void opSetMiterLimit(Object args[], int numArgs);
00171   void opSetLineWidth(Object args[], int numArgs);
00172   void opSetExtGState(Object args[], int numArgs);
00173   void opSetRenderingIntent(Object args[], int numArgs);
00174 
00175   // color operators
00176   void opSetFillGray(Object args[], int numArgs);
00177   void opSetStrokeGray(Object args[], int numArgs);
00178   void opSetFillCMYKColor(Object args[], int numArgs);
00179   void opSetStrokeCMYKColor(Object args[], int numArgs);
00180   void opSetFillRGBColor(Object args[], int numArgs);
00181   void opSetStrokeRGBColor(Object args[], int numArgs);
00182   void opSetFillColorSpace(Object args[], int numArgs);
00183   void opSetStrokeColorSpace(Object args[], int numArgs);
00184   void opSetFillColor(Object args[], int numArgs);
00185   void opSetStrokeColor(Object args[], int numArgs);
00186   void opSetFillColorN(Object args[], int numArgs);
00187   void opSetStrokeColorN(Object args[], int numArgs);
00188 
00189   // path segment operators
00190   void opMoveTo(Object args[], int numArgs);
00191   void opLineTo(Object args[], int numArgs);
00192   void opCurveTo(Object args[], int numArgs);
00193   void opCurveTo1(Object args[], int numArgs);
00194   void opCurveTo2(Object args[], int numArgs);
00195   void opRectangle(Object args[], int numArgs);
00196   void opClosePath(Object args[], int numArgs);
00197 
00198   // path painting operators
00199   void opEndPath(Object args[], int numArgs);
00200   void opStroke(Object args[], int numArgs);
00201   void opCloseStroke(Object args[], int numArgs);
00202   void opFill(Object args[], int numArgs);
00203   void opEOFill(Object args[], int numArgs);
00204   void opFillStroke(Object args[], int numArgs);
00205   void opCloseFillStroke(Object args[], int numArgs);
00206   void opEOFillStroke(Object args[], int numArgs);
00207   void opCloseEOFillStroke(Object args[], int numArgs);
00208   void doPatternFill(GBool eoFill);
00209   void doTilingPatternFill(GfxTilingPattern *tPat, GBool eoFill);
00210   void doShadingPatternFill(GfxShadingPattern *sPat, GBool eoFill);
00211   void opShFill(Object args[], int numArgs);
00212   void doFunctionShFill(GfxFunctionShading *shading);
00213   void doFunctionShFill1(GfxFunctionShading *shading,
00214                       double x0, double y0,
00215                       double x1, double y1,
00216                       GfxColor *colors, int depth);
00217   void doAxialShFill(GfxAxialShading *shading);
00218   void doRadialShFill(GfxRadialShading *shading);
00219   void doEndPath();
00220 
00221   // path clipping operators
00222   void opClip(Object args[], int numArgs);
00223   void opEOClip(Object args[], int numArgs);
00224 
00225   // text object operators
00226   void opBeginText(Object args[], int numArgs);
00227   void opEndText(Object args[], int numArgs);
00228 
00229   // text state operators
00230   void opSetCharSpacing(Object args[], int numArgs);
00231   void opSetFont(Object args[], int numArgs);
00232   void opSetTextLeading(Object args[], int numArgs);
00233   void opSetTextRender(Object args[], int numArgs);
00234   void opSetTextRise(Object args[], int numArgs);
00235   void opSetWordSpacing(Object args[], int numArgs);
00236   void opSetHorizScaling(Object args[], int numArgs);
00237 
00238   // text positioning operators
00239   void opTextMove(Object args[], int numArgs);
00240   void opTextMoveSet(Object args[], int numArgs);
00241   void opSetTextMatrix(Object args[], int numArgs);
00242   void opTextNextLine(Object args[], int numArgs);
00243 
00244   // text string operators
00245   void opShowText(Object args[], int numArgs);
00246   void opMoveShowText(Object args[], int numArgs);
00247   void opMoveSetShowText(Object args[], int numArgs);
00248   void opShowSpaceText(Object args[], int numArgs);
00249   void doShowText(GString *s);
00250 
00251   // XObject operators
00252   void opXObject(Object args[], int numArgs);
00253   void doImage(Object *ref, Stream *str, GBool inlineImg);
00254   void doForm(Object *str);
00255   void doForm1(Object *str, Dict *resDict, double *matrix, double *bbox);
00256 
00257   // in-line image operators
00258   void opBeginImage(Object args[], int numArgs);
00259   Stream *buildImageStream();
00260   void opImageData(Object args[], int numArgs);
00261   void opEndImage(Object args[], int numArgs);
00262 
00263   // type 3 font operators
00264   void opSetCharWidth(Object args[], int numArgs);
00265   void opSetCacheDevice(Object args[], int numArgs);
00266 
00267   // compatibility operators
00268   void opBeginIgnoreUndef(Object args[], int numArgs);
00269   void opEndIgnoreUndef(Object args[], int numArgs);
00270 
00271   // marked content operators
00272   void opBeginMarkedContent(Object args[], int numArgs);
00273   void opEndMarkedContent(Object args[], int numArgs);
00274   void opMarkPoint(Object args[], int numArgs);
00275 
00276   void pushResources(Dict *resDict);
00277   void popResources();
00278 };
00279 
00280 #endif