]> www.fi.muni.cz Git - evince.git/blobdiff - pdf/xpdf/PSOutputDev.h
New file with some random thoughts.
[evince.git] / pdf / xpdf / PSOutputDev.h
index ba208dea439fcc4e4c00938e00ce6bb01dbe9bd9..fed328abe6756cc5ac7f462e8866845090752758 100644 (file)
@@ -2,19 +2,21 @@
 //
 // PSOutputDev.h
 //
-// Copyright 1996-2002 Glyph & Cog, LLC
+// Copyright 1996-2003 Glyph & Cog, LLC
 //
 //========================================================================
 
 #ifndef PSOUTPUTDEV_H
 #define PSOUTPUTDEV_H
 
-#ifdef __GNUC__
+#include <aconf.h>
+
+#ifdef USE_GCC_PRAGMAS
 #pragma interface
 #endif
 
 #include <stddef.h>
-#include "config.h"
+#include "xpdfconfig.h"
 #include "Object.h"
 #include "GlobalParams.h"
 #include "OutputDev.h"
@@ -23,6 +25,7 @@ class GfxPath;
 class GfxFont;
 class GfxColorSpace;
 class GfxSeparationColorSpace;
+class PDFRectangle;
 struct PSFont16Enc;
 class PSOutCustomColor;
 
@@ -39,15 +42,29 @@ enum PSOutMode {
 enum PSFileType {
   psFile,                      // write to file
   psPipe,                      // write to pipe
-  psStdout                     // write to stdout
+  psStdout,                    // write to stdout
+  psGeneric                    // write to a generic stream
 };
 
+typedef void (*PSOutputFunc)(void *stream, char *data, int len);
+
 class PSOutputDev: public OutputDev {
 public:
 
   // Open a PostScript output file, and write the prolog.
   PSOutputDev(char *fileName, XRef *xrefA, Catalog *catalog,
-             int firstPage, int lastPage, PSOutMode modeA);
+             int firstPage, int lastPage, PSOutMode modeA,
+             int imgLLXA = 0, int imgLLYA = 0,
+             int imgURXA = 0, int imgURYA = 0,
+             GBool manualCtrlA = gFalse);
+
+  // Open a PSOutputDev that will write to a generic stream.
+  PSOutputDev(PSOutputFunc outputFuncA, void *outputStreamA,
+             XRef *xrefA, Catalog *catalog,
+             int firstPage, int lastPage, PSOutMode modeA,
+             int imgLLXA = 0, int imgLLYA = 0,
+             int imgURXA = 0, int imgURYA = 0,
+             GBool manualCtrlA = gFalse);
 
   // Destructor -- writes the trailer and closes the file.
   virtual ~PSOutputDev();
@@ -68,6 +85,27 @@ public:
   // text in Type 3 fonts will be drawn with drawChar/drawString.
   virtual GBool interpretType3Chars() { return gFalse; }
 
+  //----- header/trailer (used only if manualCtrl is true)
+
+  // Write the document-level header.
+  void writeHeader(int firstPage, int lastPage,
+                  PDFRectangle *mediaBox, PDFRectangle *cropBox);
+
+  // Write the Xpdf procset.
+  void writeXpdfProcset();
+
+  // Write the document-level setup.
+  void writeDocSetup(Catalog *catalog, int firstPage, int lastPage);
+
+  // Write the setup for the current page.
+  void writePageSetup();
+
+  // Write the trailer for the current page.
+  void writePageTrailer();
+
+  // Write the document trailer.
+  void writeTrailer();
+
   //----- initialization and control
 
   // Start a page.
@@ -114,6 +152,7 @@ public:
 
   //----- text drawing
   virtual void drawString(GfxState *state, GString *s);
+  virtual void endTextObject(GfxState *state);
 
   //----- image drawing
   virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
@@ -137,25 +176,46 @@ public:
   //----- PostScript XObjects
   virtual void psXObject(Stream *psStream, Stream *level1Stream);
 
+  //----- miscellaneous
+  void setOffset(double x, double y)
+    { tx0 = x; ty0 = y; }
+  void setScale(double x, double y)
+    { xScale0 = x; yScale0 = y; }
+  void setRotate(int rotateA)
+    { rotate0 = rotateA; }
+  void setClip(double llx, double lly, double urx, double ury)
+    { clipLLX0 = llx; clipLLY0 = lly; clipURX0 = urx; clipURY0 = ury; }
+  void setUnderlayCbk(void (*cbk)(PSOutputDev *psOut, void *data),
+                     void *data)
+    { underlayCbk = cbk; underlayCbkData = data; }
+  void setOverlayCbk(void (*cbk)(PSOutputDev *psOut, void *data),
+                    void *data)
+    { overlayCbk = cbk; overlayCbkData = data; }
+
 private:
 
+  void init(PSOutputFunc outputFuncA, void *outputStreamA,
+           PSFileType fileTypeA, XRef *xrefA, Catalog *catalog,
+           int firstPage, int lastPage, PSOutMode modeA,
+           int imgLLXA, int imgLLYA, int imgURXA, int imgURYA,
+           GBool manualCtrlA);
   void setupResources(Dict *resDict);
   void setupFonts(Dict *resDict);
   void setupFont(GfxFont *font, Dict *parentResDict);
-  void setupEmbeddedType1Font(Ref *id, char *psName);
-  void setupExternalType1Font(GString *fileName, char *psName);
-  void setupEmbeddedType1CFont(GfxFont *font, Ref *id, char *psName);
-  void setupEmbeddedTrueTypeFont(GfxFont *font, Ref *id, char *psName);
-  void setupExternalTrueTypeFont(GfxFont *font, char *psName);
-  void setupEmbeddedCIDType0Font(GfxFont *font, Ref *id, char *psName);
-  void setupEmbeddedCIDTrueTypeFont(GfxFont *font, Ref *id, char *psName);
-  void setupType3Font(GfxFont *font, char *psName, Dict *parentResDict);
+  void setupEmbeddedType1Font(Ref *id, GString *psName);
+  void setupExternalType1Font(GString *fileName, GString *psName);
+  void setupEmbeddedType1CFont(GfxFont *font, Ref *id, GString *psName);
+  void setupEmbeddedTrueTypeFont(GfxFont *font, Ref *id, GString *psName);
+  void setupExternalTrueTypeFont(GfxFont *font, GString *psName);
+  void setupEmbeddedCIDType0Font(GfxFont *font, Ref *id, GString *psName);
+  void setupEmbeddedCIDTrueTypeFont(GfxFont *font, Ref *id, GString *psName);
+  void setupType3Font(GfxFont *font, GString *psName, Dict *parentResDict);
   void setupImages(Dict *resDict);
   void setupImage(Ref id, Stream *str);
   void addProcessColor(double c, double m, double y, double k);
   void addCustomColor(GfxSeparationColorSpace *sepCS);
   void doPath(GfxPath *path);
-  void doImageL1(GfxImageColorMap *colorMap,
+  void doImageL1(Object *ref, GfxImageColorMap *colorMap,
                 GBool invert, GBool inlineImg,
                 Stream *str, int width, int height, int len);
   void doImageL1Sep(GfxImageColorMap *colorMap,
@@ -172,19 +232,29 @@ private:
                    double *x1, double *y1);
   GBool getFileSpec(Object *fileSpec, Object *fileName);
 #endif
-  void writePS(const char *fmt, ...);
-  void writePSString(GString *s);
   void writePSChar(char c);
+  void writePS(char *s);
+  void writePSFmt(const char *fmt, ...);
+  void writePSString(GString *s);
+  void writePSName(char *s);
   GString *filterPSName(GString *name);
 
   PSLevel level;               // PostScript level (1, 2, separation)
   PSOutMode mode;              // PostScript mode (PS, EPS, form)
   int paperWidth;              // width of paper, in pts
   int paperHeight;             // height of paper, in pts
+  int imgLLX, imgLLY,          // imageable area, in pts
+      imgURX, imgURY;
 
-  FILE *f;                     // PostScript file
+  PSOutputFunc outputFunc;
+  void *outputStream;
   PSFileType fileType;         // file / pipe / stdout
+  GBool manualCtrl;
   int seqPage;                 // current sequential page number
+  void (*underlayCbk)(PSOutputDev *psOut, void *data);
+  void *underlayCbkData;
+  void (*overlayCbk)(PSOutputDev *psOut, void *data);
+  void *overlayCbkData;
 
   XRef *xref;                  // the xref table for this PDF file
 
@@ -197,13 +267,23 @@ private:
   GString **fontFileNames;     // list of names of all embedded external fonts
   int fontFileNameLen;         // number of entries in fontFileNames array
   int fontFileNameSize;                // size of fontFileNames array
+  int nextTrueTypeNum;         // next unique number to append to a TrueType
+                               //   font name
   PSFont16Enc *font16Enc;      // encodings for substitute 16-bit fonts
   int font16EncLen;            // number of entries in font16Enc array
   int font16EncSize;           // size of font16Enc array
-
-  double tx, ty;               // global translation
-  double xScale, yScale;       // global scaling
-  GBool landscape;             // true for landscape, false for portrait
+  GList *xobjStack;            // stack of XObject dicts currently being
+                               //   processed
+  int numSaves;                        // current number of gsaves
+
+  double tx0, ty0;             // global translation
+  double xScale0, yScale0;     // global scaling
+  int rotate0;                 // rotation angle (0, 90, 180, 270)
+  double clipLLX0, clipLLY0,
+         clipURX0, clipURY0;
+  double tx, ty;               // global translation for current page
+  double xScale, yScale;       // global scaling for current page
+  int rotate;                  // rotation angle for current page
 
   GString *embFontList;                // resource comments for embedded fonts
 
@@ -211,6 +291,9 @@ private:
   PSOutCustomColor             // used custom colors
     *customColors;
 
+  GBool haveTextClip;          // set if text has been drawn with a
+                               //   clipping render mode
+
   GBool inType3Char;           // inside a Type 3 CharProc
   GString *t3String;           // Type 3 content string
   double t3WX, t3WY,           // Type 3 character parameters
@@ -223,6 +306,9 @@ private:
 #endif
 
   GBool ok;                    // set up ok?
+
+
+  friend class WinPDFPrinter;
 };
 
 #endif