]> www.fi.muni.cz Git - evince.git/blob - pdf/xpdf/XOutputDev.h
48454212e2f95a48a0d66695c3d524b75f42344c
[evince.git] / pdf / xpdf / XOutputDev.h
1 //========================================================================
2 //
3 // XOutputDev.h
4 //
5 // Copyright 1996 Derek B. Noonburg
6 //
7 //========================================================================
8
9 #ifndef XOUTPUTDEV_H
10 #define XOUTPUTDEV_H
11
12 #ifdef __GNUC__
13 #pragma interface
14 #endif
15
16 #include <stddef.h>
17 #include <X11/Xlib.h>
18 #include <X11/Xutil.h>
19 #include "config.h"
20 #include "OutputDev.h"
21
22 class GString;
23 class GfxColor;
24 class GfxFont;
25 class GfxSubpath;
26 class TextPage;
27 struct RGBColor;
28
29 //------------------------------------------------------------------------
30 // Constants
31 //------------------------------------------------------------------------
32
33 #define maxRGBCube 8            // max size of RGB color cube
34
35 #define numTmpPoints 256        // number of XPoints in temporary array
36 #define numTmpSubpaths 16       // number of elements in temporary arrays
37                                 //   for fill/clip
38
39 //------------------------------------------------------------------------
40 // Misc types
41 //------------------------------------------------------------------------
42
43 struct BoundingRect {
44   short xMin, xMax;             // min/max x values
45   short yMin, yMax;             // min/max y values
46 };
47
48 struct RGBColor {
49   double r, g, b;
50 };
51
52 //------------------------------------------------------------------------
53 // Parameters
54 //------------------------------------------------------------------------
55
56 // Install a private colormap.
57 extern GBool installCmap;
58
59 // Size of RGB color cube.
60 extern int rgbCubeSize;
61
62 //------------------------------------------------------------------------
63 // XOutputFont
64 //------------------------------------------------------------------------
65
66 class XOutputFont {
67 public:
68
69   // Constructor.
70   XOutputFont(GfxFont *gfxFont, double m11, double m12,
71               double m21, double m22, Display *display1);
72
73   // Destructor.
74   ~XOutputFont();
75
76   // Does this font match the ID, size, and angle?
77   GBool matches(Ref id1, double m11, double m12, double m21, double m22)
78     { return id.num == id1.num && id.gen == id1.gen &&
79              mat11 == m11 && mat12 == m12 && mat21 == m21 && mat22 == m22; }
80
81   // Get X font.
82   XFontStruct *getXFont() { return xFont; }
83
84   // Get character mapping.
85   Gushort mapChar(Guchar c) { return map[c]; }
86
87   // Reverse map a character.
88   Guchar revMapChar(Gushort c) { return revMap[c]; }
89
90   // Does this font use hex char codes?
91   GBool isHex() { return hex; }
92
93 private:
94
95   Ref id;
96   double mat11, mat12, mat21, mat22;
97   Display *display;
98   XFontStruct *xFont;
99   GBool hex;                    // subsetted font with hex char codes
100   Gushort map[256];
101   Guchar revMap[256];
102 };
103
104 //------------------------------------------------------------------------
105 // XOutputFontCache
106 //------------------------------------------------------------------------
107
108 class XOutputFontCache {
109 public:
110
111   // Constructor.
112   XOutputFontCache(Display *display1);
113
114   // Destructor.
115   ~XOutputFontCache();
116
117   // Get a font.  This creates a new font if necessary.
118   XOutputFont *getFont(GfxFont *gfxFont, double m11, double m12,
119                        double m21, double m22);
120
121 private:
122
123   Display *display;             // X display pointer
124   XOutputFont *                 // fonts in reverse-LRU order
125     fonts[fontCacheSize];
126   int numFonts;                 // number of valid entries
127 };
128
129 //------------------------------------------------------------------------
130 // XOutputState
131 //------------------------------------------------------------------------
132
133 struct XOutputState {
134   GC strokeGC;
135   GC fillGC;
136   Region clipRegion;
137   XOutputState *next;
138 };
139
140 //------------------------------------------------------------------------
141 // XOutputDev
142 //------------------------------------------------------------------------
143
144 class XOutputDev: public OutputDev {
145 public:
146
147   // Constructor.
148   XOutputDev(Display *display1, Pixmap pixmap1, Guint depth1,
149              Colormap colormap, unsigned long paperColor);
150
151   // Destructor.
152   virtual ~XOutputDev();
153
154   //---- get info about output device
155
156   // Does this device use upside-down coordinates?
157   // (Upside-down means (0,0) is the top left corner of the page.)
158   virtual GBool upsideDown() { return gTrue; }
159
160   // Does this device use drawChar() or drawString()?
161   virtual GBool useDrawChar() { return gTrue; }
162
163   //----- initialization and control
164
165   // Start a page.
166   virtual void startPage(int pageNum, GfxState *state);
167
168   // End a page.
169   virtual void endPage();
170
171   //----- link borders
172   virtual void drawLinkBorder(double x1, double y1, double x2, double y2,
173                               double w);
174
175   //----- save/restore graphics state
176   virtual void saveState(GfxState *state);
177   virtual void restoreState(GfxState *state);
178
179   //----- update graphics state
180   virtual void updateAll(GfxState *state);
181   virtual void updateCTM(GfxState *state, double m11, double m12,
182                          double m21, double m22, double m31, double m32);
183   virtual void updateLineDash(GfxState *state);
184   virtual void updateFlatness(GfxState *state);
185   virtual void updateLineJoin(GfxState *state);
186   virtual void updateLineCap(GfxState *state);
187   virtual void updateMiterLimit(GfxState *state);
188   virtual void updateLineWidth(GfxState *state);
189   virtual void updateFillColor(GfxState *state);
190   virtual void updateStrokeColor(GfxState *state);
191
192   //----- update text state
193   virtual void updateFont(GfxState *state);
194
195   //----- path painting
196   virtual void stroke(GfxState *state);
197   virtual void fill(GfxState *state);
198   virtual void eoFill(GfxState *state);
199
200   //----- path clipping
201   virtual void clip(GfxState *state);
202   virtual void eoClip(GfxState *state);
203
204   //----- text drawing
205   virtual void beginString(GfxState *state, GString *s);
206   virtual void endString(GfxState *state);
207   virtual void drawChar(GfxState *state, double x, double y,
208                         double dx, double dy, Guchar c);
209   virtual void drawChar16(GfxState *state, double x, double y,
210                           double dx, double dy, int c);
211
212   //----- image drawing
213   virtual void drawImageMask(GfxState *state, Stream *str,
214                              int width, int height, GBool invert,
215                              GBool inlineImg);
216   virtual void drawImage(GfxState *state, Stream *str, int width,
217                          int height, GfxImageColorMap *colorMap,
218                          GBool inlineImg);
219
220   //----- special access
221
222   // Find a string.  If <top> is true, starts looking at <xMin>,<yMin>;
223   // otherwise starts looking at top of page.  If <bottom> is true,
224   // stops looking at <xMax>,<yMax>; otherwise stops looking at bottom
225   // of page.  If found, sets the text bounding rectange and returns
226   // true; otherwise returns false.
227   GBool findText(char *s, GBool top, GBool bottom,
228                  int *xMin, int *yMin, int *xMax, int *yMax);
229
230   // Get the text which is inside the specified rectangle.
231   GString *getText(int xMin, int yMin, int xMax, int yMax);
232
233 protected:
234
235   // Update pixmap ID after a page change.
236   void setPixmap(Pixmap pixmap1, int pixmapW1, int pixmapH1)
237     { pixmap = pixmap1; pixmapW = pixmapW1; pixmapH = pixmapH1; }
238
239 private:
240
241   Display *display;             // X display pointer
242   int screenNum;                // X screen number
243   Pixmap pixmap;                // pixmap to draw into
244   int pixmapW, pixmapH;         // size of pixmap
245   Guint depth;                  // pixmap depth
246   int flatness;                 // line flatness
247   GC paperGC;                   // GC for background
248   GC strokeGC;                  // GC with stroke color
249   GC fillGC;                    // GC with fill color
250   Region clipRegion;            // clipping region
251   GBool trueColor;              // set if using a TrueColor visual
252   int rMul, gMul, bMul;         // RGB multipliers (for TrueColor)
253   int rShift, gShift, bShift;   // RGB shifts (for TrueColor)
254   Gulong                        // color cube
255     colors[maxRGBCube * maxRGBCube * maxRGBCube];
256   int numColors;                // size of color cube
257   XPoint                        // temporary points array
258     tmpPoints[numTmpPoints];
259   int                           // temporary arrays for fill/clip
260     tmpLengths[numTmpSubpaths];
261   BoundingRect
262     tmpRects[numTmpSubpaths];
263   GfxFont *gfxFont;             // current PDF font
264   XOutputFont *font;            // current font
265   XOutputFontCache *fontCache;  // font cache
266   XOutputState *save;           // stack of saved states
267   TextPage *text;               // text from the current page
268
269   void updateLineAttrs(GfxState *state, GBool updateDash);
270   void doFill(GfxState *state, int rule);
271   void doClip(GfxState *state, int rule);
272   int convertPath(GfxState *state, XPoint **points, int *size,
273                   int *numPoints, int **lengths, GBool fillHack);
274   void convertSubpath(GfxState *state, GfxSubpath *subpath,
275                       XPoint **points, int *size, int *n);
276   void doCurve(XPoint **points, int *size, int *k,
277                double x0, double y0, double x1, double y1,
278                double x2, double y2, double x3, double y3);
279   void addPoint(XPoint **points, int *size, int *k, int x, int y);
280   Gulong findColor(GfxColor *color);
281   Gulong findColor(RGBColor *x, RGBColor *err);
282 };
283
284 #endif