home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 110 / EnigmaAmiga110CD.iso / indispensabili / utility / apdf / xpdf-0.80 / xpdf / aoutputdev.h < prev    next >
C/C++ Source or Header  |  1999-05-19  |  9KB  |  309 lines

  1. //========================================================================
  2. //
  3. // AOutputDev.h
  4. //
  5. // adapted from XOutputDev.h - Copyright 1996 Derek B. Noonburg
  6. //
  7. // changes are copyright 1999 Emmanuel Lesueur
  8. //
  9. //========================================================================
  10.  
  11. #ifndef AOUTPUTDEV_H
  12. #define AOUTPUTDEV_H
  13.  
  14. #ifdef __GNUC__
  15. #pragma interface
  16. #endif
  17.  
  18. #include <stddef.h>
  19. #include <math.h>
  20. #if defined(__SASC) && defined(_M68000)
  21. #   include <m68881.h>
  22. #endif
  23.  
  24. #include "config.h"
  25. #include "OutputDev.h"
  26. #include "AGfx.h"
  27.  
  28. class GString;
  29. class GfxColor;
  30. class GfxFont;
  31. class GfxSubpath;
  32. class TextPage;
  33. struct RGBColor;
  34.  
  35. //------------------------------------------------------------------------
  36. // Constants
  37. //------------------------------------------------------------------------
  38.  
  39. static const int maxRGBCube=8;      // max size of RGB color cube
  40.  
  41. static const int numTmpPoints=256;  // number of XPoints in temporary array
  42. static const int numTmpSubpaths=16; // number of elements in temporary arrays
  43.                     //   for fill/clip
  44. static const int penColor=0;
  45. static const int paperColor=1;
  46.  
  47. static const int WindingRule=0;
  48. static const int EvenOddRule=1;
  49.  
  50. //------------------------------------------------------------------------
  51. // Misc types
  52. //------------------------------------------------------------------------
  53.  
  54. enum CapStyle {
  55.     CapButt, CapRound, CapProjecting
  56. };
  57.  
  58. enum JoinStyle {
  59.     JoinMiter, JoinRound, JoinBevel
  60. };
  61.  
  62. struct BoundingRect {
  63.   short xMin, xMax;             // min/max x values
  64.   short yMin, yMax;             // min/max y values
  65. };
  66.  
  67. struct RGBColor {
  68.   double r, g, b;
  69. };
  70.  
  71. //------------------------------------------------------------------------
  72. // Parameters
  73. //------------------------------------------------------------------------
  74.  
  75. // Install a private colormap.
  76. //extern GBool installCmap;
  77.  
  78. // Size of RGB color cube.
  79. //extern int rgbCubeSize;
  80.  
  81. //------------------------------------------------------------------------
  82. // ColorTable
  83. //------------------------------------------------------------------------
  84.  
  85. class ColorTable {
  86. public:
  87.   ColorTable() : num(0),entries(NULL), maxEntries(0) {}
  88.   ~ColorTable() { gfree(entries); }
  89.   Gulong find(Gulong) const;
  90.   Gulong find_rgb(Gulong n) const;
  91.   Gulong add(Gulong);
  92.   void clear() { num = 0; }
  93. private:
  94.   ColorTable(const ColorTable&);
  95.   ColorTable& operator = (const ColorTable&);
  96.   Gulong num;
  97.   struct entry {
  98.       Gulong n;
  99.       Gulong val;
  100.   };
  101.   entry* entries;
  102.   Gulong maxEntries;
  103. };
  104.  
  105. //------------------------------------------------------------------------
  106. // AOutputFont
  107. //------------------------------------------------------------------------
  108.  
  109. class AOutputFont {
  110. public:
  111.  
  112.   // Constructor.
  113.   AOutputFont(AGfx&, GfxFont *gfxFont, double m11, double m12,
  114.           double m21, double m22);
  115.  
  116.   // Destructor.
  117.   ~AOutputFont();
  118.  
  119.   // Does this font match the ID, size, and angle?
  120.   GBool matches(Ref id1, double m11, double m12, double m21, double m22)
  121.     { return id.num == id1.num && id.gen == id1.gen &&
  122.     fabs(mat11-m11) + fabs(mat12-m12) + fabs(mat21-m21) +
  123.     fabs(mat22-m22) < 0.01; }
  124.  
  125.   // Get font.
  126.   int getTextFont() { return xFont; }
  127.  
  128.   // Get character mapping.
  129.   Gushort mapChar(Guchar c) { return map[c]; }
  130.  
  131.   // Reverse map a character.
  132.   Guchar revMapChar(Gushort c) { return revMap[c]; }
  133.  
  134.   // Does this font use hex char codes?
  135.   GBool isHex() { return hex; }
  136.  
  137.   static void reset() { xFontCount=0; }
  138.  
  139. private:
  140.   AGfx& gfx;
  141.   Ref id;
  142.   double mat11, mat12, mat21, mat22;
  143.   int xFont;
  144.   static int xFontCount;
  145.   GBool hex;                    // subsetted font with hex char codes
  146.   Gushort map[256];
  147.   Guchar revMap[256];
  148. };
  149.  
  150. //------------------------------------------------------------------------
  151. // AOutputFontCache
  152. //------------------------------------------------------------------------
  153.  
  154. class AOutputFontCache {
  155. public:
  156.  
  157.   // Constructor.
  158.   AOutputFontCache(AGfx&);
  159.  
  160.   // Destructor.
  161.   ~AOutputFontCache();
  162.  
  163.   // Get a font.  This creates a new font if necessary.
  164.   AOutputFont *getFont(GfxFont *gfxFont, double m11, double m12,
  165.                double m21, double m22);
  166.  
  167. private:
  168.  
  169.   AOutputFont *                 // fonts in reverse-LRU order
  170.     fonts[fontCacheSize];
  171.   int numFonts;                 // number of valid entries
  172.   AGfx& gfx;
  173. };
  174.  
  175. //------------------------------------------------------------------------
  176. // AOutputDev
  177. //------------------------------------------------------------------------
  178.  
  179. class AOutputDev: public OutputDev {
  180. public:
  181.  
  182.   // Constructor.
  183.   AOutputDev(AGfx& g1, Guint depth1, ColorMap* colormap1);
  184.  
  185.   // Destructor.
  186.   virtual ~AOutputDev();
  187.  
  188.   // Check if file was successfully created.
  189.   virtual GBool isOk() { return gTrue; }
  190.  
  191.   //---- get info about output device
  192.  
  193.   // Does this device use upside-down coordinates?
  194.   // (Upside-down means (0,0) is the top left corner of the page.)
  195.   virtual GBool upsideDown() { return gTrue; }
  196.  
  197.   // Does this device use drawChar() or drawString()?
  198.   virtual GBool useDrawChar() { return gTrue; }
  199.  
  200.   //----- initialization and control
  201.  
  202.   // Start a page.
  203.   virtual void startPage(int pageNum, GfxState *state);
  204.  
  205.   // End a page.
  206.   virtual void endPage();
  207.  
  208.   //----- link borders
  209.   virtual void drawLinkBorder(double x1, double y1, double x2, double y2,
  210.                   double w);
  211.  
  212.   //----- save/restore graphics state
  213.   virtual void saveState(GfxState *state);
  214.   virtual void restoreState(GfxState *state);
  215.  
  216.   //----- update graphics state
  217.   virtual void updateAll(GfxState *state);
  218.   virtual void updateCTM(GfxState *state, double m11, double m12,
  219.              double m21, double m22, double m31, double m32);
  220.   virtual void updateLineDash(GfxState *state);
  221.   virtual void updateFlatness(GfxState *state);
  222.   virtual void updateLineJoin(GfxState *state);
  223.   virtual void updateLineCap(GfxState *state);
  224.   virtual void updateMiterLimit(GfxState *state);
  225.   virtual void updateLineWidth(GfxState *state);
  226.   virtual void updateFillColor(GfxState *state);
  227.   virtual void updateStrokeColor(GfxState *state);
  228.  
  229.   //----- update text state
  230.   virtual void updateFont(GfxState *state);
  231.  
  232.   //----- path painting
  233.   virtual void stroke(GfxState *state);
  234.   virtual void fill(GfxState *state);
  235.   virtual void eoFill(GfxState *state);
  236.  
  237.   //----- path clipping
  238.   virtual void clip(GfxState *state);
  239.   virtual void eoClip(GfxState *state);
  240.  
  241.   //----- text drawing
  242.   virtual void beginString(GfxState *state, GString *s);
  243.   virtual void endString(GfxState *state);
  244.   virtual void drawChar(GfxState *state, double x, double y,
  245.             double dx, double dy, Guchar c);
  246.   virtual void drawChar16(GfxState *state, double x, double y,
  247.               double dx, double dy, int c);
  248.  
  249.   //----- image drawing
  250.   virtual void drawImageMask(GfxState *state, Stream *str,
  251.                  int width, int height, GBool invert,
  252.                  GBool inlineImg);
  253.   virtual void drawImage(GfxState *state, Stream *str, int width,
  254.              int height, GfxImageColorMap *colorMap,
  255.              GBool inlineImg);
  256.  
  257.   //----- special access
  258.  
  259.   // Find a string.  If <top> is true, starts looking at <xMin>,<yMin>;
  260.   // otherwise starts looking at top of page.  If <bottom> is true,
  261.   // stops looking at <xMax>,<yMax>; otherwise stops looking at bottom
  262.   // of page.  If found, sets the text bounding rectange and returns
  263.   // true; otherwise returns false.
  264.   GBool findText(char *s, GBool top, GBool bottom,
  265.          int *xMin, int *yMin, int *xMax, int *yMax);
  266.  
  267.   // Get the text which is inside the specified rectangle.
  268.   GString *getText(int xMin, int yMin, int xMax, int yMax);
  269.  
  270. private:
  271.  
  272.   AGfx& gfx;
  273.   ColorMap *colormap;
  274.   Guint depth;                  // pixmap depth
  275.   int flatness;                 // line flatness
  276.   double lineWidth;
  277.   CapStyle capStyle;
  278.   JoinStyle joinStyle;
  279.   Gulong strokeColor;
  280.   Gulong fillColor;
  281.   Gulong curColor;
  282.   Gulong linkColor;
  283.   ColorTable colorTable;
  284.   Gulong colorMask;
  285.   GBool trueColor;              // set if using a TrueColor visual
  286.   int rMul, gMul, bMul;         // RGB multipliers (for TrueColor)
  287.   int rShift, gShift, bShift;   // RGB shifts (for TrueColor)
  288.   GfxFont *gfxFont;             // current PDF font
  289.   AOutputFont *font;            // current font
  290.   AOutputFontCache *fontCache;  // font cache
  291.   TextPage *text;               // text from the current page
  292.   PArea<double> clipRegion;
  293.   array<PArea<double> > clipStack;
  294.  
  295.   void updateLineAttrs(GfxState *state, GBool updateDash);
  296.   void doFill(GfxState *state, int rule);
  297.   void doClip(GfxState *state, int rule);
  298.   void installClip();
  299.   PArea<double> convertPath(GfxState *state);
  300.   Polygon<double> convertSubpath(GfxState *state, GfxSubpath *subpath);
  301.   void doCurve(Polygon<double>&,
  302.            double x0, double y0, double x1, double y1,
  303.            double x2, double y2, double x3, double y3);
  304.   Gulong findColor(GfxColor *color);
  305.   Gulong findColor(RGBColor *x, RGBColor *err);
  306. };
  307.  
  308. #endif
  309.