filters

Gfx.h

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