Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

PSOutputDev.h

Go to the documentation of this file.
00001 //========================================================================
00002 //
00003 // PSOutputDev.h
00004 //
00005 // Copyright 1996-2003 Glyph & Cog, LLC
00006 //
00007 //========================================================================
00008 
00009 #ifndef PSOUTPUTDEV_H
00010 #define PSOUTPUTDEV_H
00011 
00012 #include <aconf.h>
00013 
00014 #ifdef USE_GCC_PRAGMAS
00015 #pragma interface
00016 #endif
00017 
00018 #include <stddef.h>
00019 #include "config.h"
00020 #include "Object.h"
00021 #include "GlobalParams.h"
00022 #include "OutputDev.h"
00023 
00024 class GfxPath;
00025 class GfxFont;
00026 class GfxColorSpace;
00027 class GfxSeparationColorSpace;
00028 class PDFRectangle;
00029 struct PSFont16Enc;
00030 class PSOutCustomColor;
00031 
00032 //------------------------------------------------------------------------
00033 // PSOutputDev
00034 //------------------------------------------------------------------------
00035 
00036 enum PSOutMode {
00037   psModePS,
00038   psModeEPS,
00039   psModeForm
00040 };
00041 
00042 enum PSFileType {
00043   psFile,                       // write to file
00044   psPipe,                       // write to pipe
00045   psStdout,                     // write to stdout
00046   psGeneric                     // write to a generic stream
00047 };
00048 
00049 typedef void (*PSOutputFunc)(void *stream, char *data, int len);
00050 
00051 class PSOutputDev: public OutputDev {
00052 public:
00053 
00054   // Open a PostScript output file, and write the prolog.
00055   PSOutputDev(char *fileName, XRef *xrefA, Catalog *catalog,
00056               int firstPage, int lastPage, PSOutMode modeA,
00057               int imgLLXA = 0, int imgLLYA = 0,
00058               int imgURXA = 0, int imgURYA = 0,
00059               GBool manualCtrlA = gFalse);
00060 
00061   // Open a PSOutputDev that will write to a generic stream.
00062   PSOutputDev(PSOutputFunc outputFuncA, void *outputStreamA,
00063               XRef *xrefA, Catalog *catalog,
00064               int firstPage, int lastPage, PSOutMode modeA,
00065               int imgLLXA = 0, int imgLLYA = 0,
00066               int imgURXA = 0, int imgURYA = 0,
00067               GBool manualCtrlA = gFalse);
00068 
00069   // Destructor -- writes the trailer and closes the file.
00070   virtual ~PSOutputDev();
00071 
00072   // Check if file was successfully created.
00073   virtual GBool isOk() { return ok; }
00074 
00075   //---- get info about output device
00076 
00077   // Does this device use upside-down coordinates?
00078   // (Upside-down means (0,0) is the top left corner of the page.)
00079   virtual GBool upsideDown() { return gFalse; }
00080 
00081   // Does this device use drawChar() or drawString()?
00082   virtual GBool useDrawChar() { return gFalse; }
00083 
00084   // Does this device use beginType3Char/endType3Char?  Otherwise,
00085   // text in Type 3 fonts will be drawn with drawChar/drawString.
00086   virtual GBool interpretType3Chars() { return gFalse; }
00087 
00088   //----- header/trailer (used only if manualCtrl is true)
00089 
00090   // Write the document-level header.
00091   void writeHeader(int firstPage, int lastPage,
00092                    PDFRectangle *mediaBox, PDFRectangle *cropBox);
00093 
00094   // Write the Xpdf procset.
00095   void writeXpdfProcset();
00096 
00097   // Write the document-level setup.
00098   void writeDocSetup(Catalog *catalog, int firstPage, int lastPage);
00099 
00100   // Write the setup for the current page.
00101   void writePageSetup();
00102 
00103   // Write the trailer for the current page.
00104   void writePageTrailer();
00105 
00106   // Write the document trailer.
00107   void writeTrailer();
00108 
00109   //----- initialization and control
00110 
00111   // Start a page.
00112   virtual void startPage(int pageNum, GfxState *state);
00113 
00114   // End a page.
00115   virtual void endPage();
00116 
00117   //----- save/restore graphics state
00118   virtual void saveState(GfxState *state);
00119   virtual void restoreState(GfxState *state);
00120 
00121   //----- update graphics state
00122   virtual void updateCTM(GfxState *state, double m11, double m12,
00123                          double m21, double m22, double m31, double m32);
00124   virtual void updateLineDash(GfxState *state);
00125   virtual void updateFlatness(GfxState *state);
00126   virtual void updateLineJoin(GfxState *state);
00127   virtual void updateLineCap(GfxState *state);
00128   virtual void updateMiterLimit(GfxState *state);
00129   virtual void updateLineWidth(GfxState *state);
00130   virtual void updateFillColor(GfxState *state);
00131   virtual void updateStrokeColor(GfxState *state);
00132 
00133   //----- update text state
00134   virtual void updateFont(GfxState *state);
00135   virtual void updateTextMat(GfxState *state);
00136   virtual void updateCharSpace(GfxState *state);
00137   virtual void updateRender(GfxState *state);
00138   virtual void updateRise(GfxState *state);
00139   virtual void updateWordSpace(GfxState *state);
00140   virtual void updateHorizScaling(GfxState *state);
00141   virtual void updateTextPos(GfxState *state);
00142   virtual void updateTextShift(GfxState *state, double shift);
00143 
00144   //----- path painting
00145   virtual void stroke(GfxState *state);
00146   virtual void fill(GfxState *state);
00147   virtual void eoFill(GfxState *state);
00148 
00149   //----- path clipping
00150   virtual void clip(GfxState *state);
00151   virtual void eoClip(GfxState *state);
00152 
00153   //----- text drawing
00154   virtual void drawString(GfxState *state, GString *s);
00155   virtual void endTextObject(GfxState *state);
00156 
00157   //----- image drawing
00158   virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
00159                              int width, int height, GBool invert,
00160                              GBool inlineImg);
00161   virtual void drawImage(GfxState *state, Object *ref, Stream *str,
00162                          int width, int height, GfxImageColorMap *colorMap,
00163                          int *maskColors, GBool inlineImg);
00164 
00165 #if OPI_SUPPORT
00166   //----- OPI functions
00167   virtual void opiBegin(GfxState *state, Dict *opiDict);
00168   virtual void opiEnd(GfxState *state, Dict *opiDict);
00169 #endif
00170 
00171   //----- Type 3 font operators
00172   virtual void type3D0(GfxState *state, double wx, double wy);
00173   virtual void type3D1(GfxState *state, double wx, double wy,
00174                        double llx, double lly, double urx, double ury);
00175 
00176   //----- PostScript XObjects
00177   virtual void psXObject(Stream *psStream, Stream *level1Stream);
00178 
00179   //----- miscellaneous
00180   void setOffset(double x, double y)
00181     { tx0 = x; ty0 = y; }
00182   void setScale(double x, double y)
00183     { xScale0 = x; yScale0 = y; }
00184   void setRotate(int rotateA)
00185     { rotate0 = rotateA; }
00186   void setClip(double llx, double lly, double urx, double ury)
00187     { clipLLX0 = llx; clipLLY0 = lly; clipURX0 = urx; clipURY0 = ury; }
00188   void setUnderlayCbk(void (*cbk)(PSOutputDev *psOut, void *data),
00189                       void *data)
00190     { underlayCbk = cbk; underlayCbkData = data; }
00191   void setOverlayCbk(void (*cbk)(PSOutputDev *psOut, void *data),
00192                      void *data)
00193     { overlayCbk = cbk; overlayCbkData = data; }
00194 
00195 private:
00196 
00197   void init(PSOutputFunc outputFuncA, void *outputStreamA,
00198             PSFileType fileTypeA, XRef *xrefA, Catalog *catalog,
00199             int firstPage, int lastPage, PSOutMode modeA,
00200             int imgLLXA, int imgLLYA, int imgURXA, int imgURYA,
00201             GBool manualCtrlA);
00202   void setupResources(Dict *resDict);
00203   void setupFonts(Dict *resDict);
00204   void setupFont(GfxFont *font, Dict *parentResDict);
00205   void setupEmbeddedType1Font(Ref *id, GString *psName);
00206   void setupExternalType1Font(GString *fileName, GString *psName);
00207   void setupEmbeddedType1CFont(GfxFont *font, Ref *id, GString *psName);
00208   void setupEmbeddedTrueTypeFont(GfxFont *font, Ref *id, GString *psName);
00209   void setupExternalTrueTypeFont(GfxFont *font, GString *psName);
00210   void setupEmbeddedCIDType0Font(GfxFont *font, Ref *id, GString *psName);
00211   void setupEmbeddedCIDTrueTypeFont(GfxFont *font, Ref *id, GString *psName);
00212   void setupType3Font(GfxFont *font, GString *psName, Dict *parentResDict);
00213   void setupImages(Dict *resDict);
00214   void setupImage(Ref id, Stream *str);
00215   void addProcessColor(double c, double m, double y, double k);
00216   void addCustomColor(GfxSeparationColorSpace *sepCS);
00217   void doPath(GfxPath *path);
00218   void doImageL1(Object *ref, GfxImageColorMap *colorMap,
00219                  GBool invert, GBool inlineImg,
00220                  Stream *str, int width, int height, int len);
00221   void doImageL1Sep(GfxImageColorMap *colorMap,
00222                     GBool invert, GBool inlineImg,
00223                     Stream *str, int width, int height, int len);
00224   void doImageL2(Object *ref, GfxImageColorMap *colorMap,
00225                  GBool invert, GBool inlineImg,
00226                  Stream *str, int width, int height, int len);
00227   void dumpColorSpaceL2(GfxColorSpace *colorSpace);
00228 #if OPI_SUPPORT
00229   void opiBegin20(GfxState *state, Dict *dict);
00230   void opiBegin13(GfxState *state, Dict *dict);
00231   void opiTransform(GfxState *state, double x0, double y0,
00232                     double *x1, double *y1);
00233   GBool getFileSpec(Object *fileSpec, Object *fileName);
00234 #endif
00235   void writePSChar(char c);
00236   void writePS(char *s);
00237   void writePSFmt(const char *fmt, ...);
00238   void writePSString(GString *s);
00239   void writePSName(char *s);
00240   GString *filterPSName(GString *name);
00241 
00242   PSLevel level;                // PostScript level (1, 2, separation)
00243   PSOutMode mode;               // PostScript mode (PS, EPS, form)
00244   int paperWidth;               // width of paper, in pts
00245   int paperHeight;              // height of paper, in pts
00246   int imgLLX, imgLLY,           // imageable area, in pts
00247       imgURX, imgURY;
00248 
00249   PSOutputFunc outputFunc;
00250   void *outputStream;
00251   PSFileType fileType;          // file / pipe / stdout
00252   GBool manualCtrl;
00253   int seqPage;                  // current sequential page number
00254   void (*underlayCbk)(PSOutputDev *psOut, void *data);
00255   void *underlayCbkData;
00256   void (*overlayCbk)(PSOutputDev *psOut, void *data);
00257   void *overlayCbkData;
00258 
00259   XRef *xref;                   // the xref table for this PDF file
00260 
00261   Ref *fontIDs;                 // list of object IDs of all used fonts
00262   int fontIDLen;                // number of entries in fontIDs array
00263   int fontIDSize;               // size of fontIDs array
00264   Ref *fontFileIDs;             // list of object IDs of all embedded fonts
00265   int fontFileIDLen;            // number of entries in fontFileIDs array
00266   int fontFileIDSize;           // size of fontFileIDs array
00267   GString **fontFileNames;      // list of names of all embedded external fonts
00268   int fontFileNameLen;          // number of entries in fontFileNames array
00269   int fontFileNameSize;         // size of fontFileNames array
00270   int nextTrueTypeNum;          // next unique number to append to a TrueType
00271                                 //   font name
00272   PSFont16Enc *font16Enc;       // encodings for substitute 16-bit fonts
00273   int font16EncLen;             // number of entries in font16Enc array
00274   int font16EncSize;            // size of font16Enc array
00275   GList *xobjStack;             // stack of XObject dicts currently being
00276                                 //   processed
00277   int numSaves;                 // current number of gsaves
00278 
00279   double tx0, ty0;              // global translation
00280   double xScale0, yScale0;      // global scaling
00281   int rotate0;                  // rotation angle (0, 90, 180, 270)
00282   double clipLLX0, clipLLY0,
00283          clipURX0, clipURY0;
00284   double tx, ty;                // global translation for current page
00285   double xScale, yScale;        // global scaling for current page
00286   int rotate;                   // rotation angle for current page
00287 
00288   GString *embFontList;         // resource comments for embedded fonts
00289 
00290   int processColors;            // used process colors
00291   PSOutCustomColor              // used custom colors
00292     *customColors;
00293 
00294   GBool haveTextClip;           // set if text has been drawn with a
00295                                 //   clipping render mode
00296 
00297   GBool inType3Char;            // inside a Type 3 CharProc
00298   GString *t3String;            // Type 3 content string
00299   double t3WX, t3WY,            // Type 3 character parameters
00300          t3LLX, t3LLY, t3URX, t3URY;
00301   GBool t3Cacheable;            // cleared if char is not cacheable
00302 
00303 #if OPI_SUPPORT
00304   int opi13Nest;                // nesting level of OPI 1.3 objects
00305   int opi20Nest;                // nesting level of OPI 2.0 objects
00306 #endif
00307 
00308   GBool ok;                     // set up ok?
00309 
00310 
00311   friend class WinPDFPrinter;
00312 };
00313 
00314 #endif

Generated on Wed Nov 3 12:59:02 2004 for Lemur Toolkit by doxygen1.2.18