]> www.fi.muni.cz Git - evince.git/blob - pdf/xpdf/XOutputDev.h
Upgraded to Bonobo-0.7 -miguel
[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 #if HAVE_T1LIB_H
20 #include <t1lib.h>
21 #include <t1libx.h>
22 #endif
23 #include "config.h"
24 #include "OutputDev.h"
25
26 class GString;
27 class GfxColor;
28 class GfxFont;
29 class GfxSubpath;
30 class TextPage;
31 struct RGBColor;
32 class FontEncoding;
33 class XOutputFontCache;
34
35 //------------------------------------------------------------------------
36 // Constants
37 //------------------------------------------------------------------------
38
39 #define maxRGBCube 8            // max size of RGB color cube
40
41 #define numTmpPoints 256        // number of XPoints in temporary array
42 #define numTmpSubpaths 16       // number of elements in temporary arrays
43                                 //   for fill/clip
44
45 //------------------------------------------------------------------------
46 // Misc types
47 //------------------------------------------------------------------------
48
49 struct BoundingRect {
50   short xMin, xMax;             // min/max x values
51   short yMin, yMax;             // min/max y values
52 };
53
54 struct RGBColor {
55   double r, g, b;
56 };
57
58 //------------------------------------------------------------------------
59 // Parameters
60 //------------------------------------------------------------------------
61
62 // Install a private colormap.
63 extern GBool installCmap;
64
65 // Size of RGB color cube.
66 extern int rgbCubeSize;
67
68 #if HAVE_T1LIB_H
69 // Type of t1lib font rendering to use:
70 //     "none"   -- don't use t1lib
71 //     "plain"  -- t1lib, without anti-aliasing
72 //     "low"    -- t1lib, with low-level anti-aliasing
73 //     "high"   -- t1lib, with high-level anti-aliasing
74 extern GString *t1libControl;
75 #endif
76
77 // If any of these are set, xpdf will use t1lib to render those font(s)
78 // instead of using the X server font(s).
79 extern GString *t1Courier;
80 extern GString *t1CourierBold;
81 extern GString *t1CourierBoldOblique;
82 extern GString *t1CourierOblique;
83 extern GString *t1Helvetica;
84 extern GString *t1HelveticaBold;
85 extern GString *t1HelveticaBoldOblique;
86 extern GString *t1HelveticaOblique;
87 extern GString *t1Symbol;
88 extern GString *t1TimesBold;
89 extern GString *t1TimesBoldItalic;
90 extern GString *t1TimesItalic;
91 extern GString *t1TimesRoman;
92 extern GString *t1ZapfDingbats;
93
94 // Use the EUC-JP encoding.
95 extern GBool useEUCJP;
96
97 #if JAPANESE_SUPPORT
98 // X font name pattern to use for Japanese text.
99 extern GString *japan12Font;
100 #endif
101
102 //------------------------------------------------------------------------
103 // XOutputFont
104 //------------------------------------------------------------------------
105
106 class XOutputFont {
107 public:
108
109   XOutputFont(GfxFont *gfxFont, double m11, double m12,
110               double m21, double m22, Display *display,
111               XOutputFontCache *cache);
112
113   virtual ~XOutputFont();
114
115   // Does this font match the ID and transform?
116   GBool matches(Ref id1, double m11, double m12, double m21, double m22)
117     { return id.num == id1.num && id.gen == id1.gen &&
118              m11 == tm11 && m12 == tm12 && m21 == tm21 && m22 == tm22; }
119
120   // Was font created successfully?
121   virtual GBool isOk() = 0;
122
123   // Update <gc> with this font.
124   virtual void updateGC(GC gc) = 0;
125
126   // Draw character <c> at <x>,<y>.
127   virtual void drawChar(GfxState *state, Pixmap pixmap, GC gc,
128                         double x, double y, int c) = 0;
129
130   // Does this font use hex char codes?
131   GBool isHex() { return hex; }
132
133 protected:
134
135   Ref id;                       // font ID
136   double tm11, tm12,            // original transform matrix
137          tm21, tm22;
138   Display *display;             // X display
139   GBool hex;                    // subsetted font with hex char codes
140                                 //   (this flag is used for text output)
141 };
142
143 #if HAVE_T1LIB_H
144 //------------------------------------------------------------------------
145 // XOutputT1Font
146 //------------------------------------------------------------------------
147
148 class XOutputT1Font: public XOutputFont {
149 public:
150
151   XOutputT1Font(GfxFont *gfxFont, GString *pdfBaseFont,
152                 double m11, double m12, double m21, double m22,
153                 double size, double ntm11, double ntm12,
154                 double ntm21, double ntm22,
155                 Display *display, XOutputFontCache *cache);
156
157   virtual ~XOutputT1Font();
158
159   // Was font created successfully?
160   virtual GBool isOk();
161
162   // Update <gc> with this font.
163   virtual void updateGC(GC gc);
164
165   // Draw character <c> at <x>,<y>.
166   virtual void drawChar(GfxState *state, Pixmap pixmap, GC gc,
167                         double x, double y, int c);
168
169 private:
170
171   float size;                   // font size
172   int t1ID;                     // t1lib font ID
173   GBool t1libAA;                // true for anti-aliased fonts
174 };
175 #endif
176
177 //------------------------------------------------------------------------
178 // XOutputServerFont
179 //------------------------------------------------------------------------
180
181 class XOutputServerFont: public XOutputFont {
182 public:
183
184   XOutputServerFont(GfxFont *gfxFont, char *fontNameFmt,
185                     FontEncoding *encoding,
186                     double m11, double m12, double m21, double m22,
187                     double size, double ntm11, double ntm12,
188                     double ntm21, double ntm22,
189                     Display *display, XOutputFontCache *cache);
190
191   virtual ~XOutputServerFont();
192
193   // Was font created successfully?
194   virtual GBool isOk();
195
196   // Update <gc> with this font.
197   virtual void updateGC(GC gc);
198
199   // Draw character <c> at <x>,<y>.
200   virtual void drawChar(GfxState *state, Pixmap pixmap, GC gc,
201                         double x, double y, int c);
202
203 private:
204
205   XFontStruct *xFont;           // the X font
206   Gushort map[256];             // forward map (PDF code -> font code)
207   Guchar revMap[256];           // reverese map (font code -> PDF code)
208 };
209
210 //------------------------------------------------------------------------
211 // XOutputFontCache
212 //------------------------------------------------------------------------
213
214 #if HAVE_T1LIB_H
215 struct XOutputT1BaseFont {
216   int num, gen;
217   int t1ID;
218   char **enc;
219   char *encStr;
220 };
221 #endif
222
223 class XOutputFontCache {
224 public:
225
226   // Constructor.
227   XOutputFontCache(Display *display);
228
229   // Destructor.
230   ~XOutputFontCache();
231
232   // Initialize (or re-initialize) the font cache for a new document.
233   void startDoc(int screenNum, Guint depth,
234                 Colormap colormap);
235
236   // Get a font.  This creates a new font if necessary.
237   XOutputFont *getFont(GfxFont *gfxFont, double m11, double m12,
238                        double m21, double m22);
239
240 #if HAVE_T1LIB_H
241   // Get a t1lib font.
242   int getT1Font(GfxFont *gfxFont, GString *pdfBaseFont);
243
244   // Use anti-aliased Type 1 fonts?
245   GBool getT1libAA() { return t1libAA; }
246 #endif
247
248 private:
249
250   void delFonts();
251   void clear();
252
253   Display *display;             // X display pointer
254
255 #if HAVE_T1LIB_H
256   GBool useT1lib;               // if false, t1lib is not used at all
257   GBool t1libAA;                // true for anti-aliased fonts
258   GBool t1libAAHigh;            // low or high-level anti-aliasing
259   GBool t1Init;                 // set when t1lib has been initialized
260   XOutputT1Font *               // Type 1 fonts in reverse-LRU order
261     t1Fonts[t1FontCacheSize];
262   int nT1Fonts;                 // number of valid entries in t1Fonts[]
263   XOutputT1BaseFont *           // list of t1lib base fonts
264     t1BaseFonts;
265   int t1BaseFontsSize;          // size of t1BaseFonts array
266 #endif
267
268   XOutputServerFont *           // X server fonts in reverse-LRU order
269     serverFonts[serverFontCacheSize];
270   int nServerFonts;             // number of valid entries in serverFonts[]
271 };
272
273 //------------------------------------------------------------------------
274 // XOutputState
275 //------------------------------------------------------------------------
276
277 struct XOutputState {
278   GC strokeGC;
279   GC fillGC;
280   Region clipRegion;
281   XOutputState *next;
282 };
283
284 //------------------------------------------------------------------------
285 // XOutputDev
286 //------------------------------------------------------------------------
287
288 class XOutputDev: public OutputDev {
289 public:
290
291   // Constructor.
292   XOutputDev(Display *display1, Pixmap pixmap1, Guint depth1,
293              Colormap colormap, unsigned long paperColor);
294
295   // Destructor.
296   virtual ~XOutputDev();
297
298   //---- get info about output device
299
300   // Does this device use upside-down coordinates?
301   // (Upside-down means (0,0) is the top left corner of the page.)
302   virtual GBool upsideDown() { return gTrue; }
303
304   // Does this device use drawChar() or drawString()?
305   virtual GBool useDrawChar() { return gTrue; }
306
307   //----- initialization and control
308
309   // Start a page.
310   virtual void startPage(int pageNum, GfxState *state);
311
312   // End a page.
313   virtual void endPage();
314
315   //----- link borders
316   virtual void drawLinkBorder(double x1, double y1, double x2, double y2,
317                               double w);
318
319   //----- save/restore graphics state
320   virtual void saveState(GfxState *state);
321   virtual void restoreState(GfxState *state);
322
323   //----- update graphics state
324   virtual void updateAll(GfxState *state);
325   virtual void updateCTM(GfxState *state, double m11, double m12,
326                          double m21, double m22, double m31, double m32);
327   virtual void updateLineDash(GfxState *state);
328   virtual void updateFlatness(GfxState *state);
329   virtual void updateLineJoin(GfxState *state);
330   virtual void updateLineCap(GfxState *state);
331   virtual void updateMiterLimit(GfxState *state);
332   virtual void updateLineWidth(GfxState *state);
333   virtual void updateFillColor(GfxState *state);
334   virtual void updateStrokeColor(GfxState *state);
335
336   //----- update text state
337   virtual void updateFont(GfxState *state);
338
339   //----- path painting
340   virtual void stroke(GfxState *state);
341   virtual void fill(GfxState *state);
342   virtual void eoFill(GfxState *state);
343
344   //----- path clipping
345   virtual void clip(GfxState *state);
346   virtual void eoClip(GfxState *state);
347
348   //----- text drawing
349   virtual void beginString(GfxState *state, GString *s);
350   virtual void endString(GfxState *state);
351   virtual void drawChar(GfxState *state, double x, double y,
352                         double dx, double dy, Guchar c);
353   virtual void drawChar16(GfxState *state, double x, double y,
354                           double dx, double dy, int c);
355
356   //----- image drawing
357   virtual void drawImageMask(GfxState *state, Stream *str,
358                              int width, int height, GBool invert,
359                              GBool inlineImg);
360   virtual void drawImage(GfxState *state, Stream *str, int width,
361                          int height, GfxImageColorMap *colorMap,
362                          GBool inlineImg);
363
364   //----- special access
365
366   // Called to indicate that a new PDF document has been loaded.
367   void startDoc();
368
369   // Find a string.  If <top> is true, starts looking at <xMin>,<yMin>;
370   // otherwise starts looking at top of page.  If <bottom> is true,
371   // stops looking at <xMax>,<yMax>; otherwise stops looking at bottom
372   // of page.  If found, sets the text bounding rectange and returns
373   // true; otherwise returns false.
374   GBool findText(char *s, GBool top, GBool bottom,
375                  int *xMin, int *yMin, int *xMax, int *yMax);
376
377   // Get the text which is inside the specified rectangle.
378   GString *getText(int xMin, int yMin, int xMax, int yMax);
379
380 protected:
381
382   // Update pixmap ID after a page change.
383   void setPixmap(Pixmap pixmap1, int pixmapW1, int pixmapH1)
384     { pixmap = pixmap1; pixmapW = pixmapW1; pixmapH = pixmapH1; }
385
386 private:
387
388   Display *display;             // X display pointer
389   int screenNum;                // X screen number
390   Pixmap pixmap;                // pixmap to draw into
391   int pixmapW, pixmapH;         // size of pixmap
392   Guint depth;                  // pixmap depth
393   Colormap colormap;            // X colormap
394   int flatness;                 // line flatness
395   GC paperGC;                   // GC for background
396   GC strokeGC;                  // GC with stroke color
397   GC fillGC;                    // GC with fill color
398   Region clipRegion;            // clipping region
399   GBool trueColor;              // set if using a TrueColor visual
400   int rMul, gMul, bMul;         // RGB multipliers (for TrueColor)
401   int rShift, gShift, bShift;   // RGB shifts (for TrueColor)
402   Gulong                        // color cube
403     colors[maxRGBCube * maxRGBCube * maxRGBCube];
404   int numColors;                // size of color cube
405   XPoint                        // temporary points array
406     tmpPoints[numTmpPoints];
407   int                           // temporary arrays for fill/clip
408     tmpLengths[numTmpSubpaths];
409   BoundingRect
410     tmpRects[numTmpSubpaths];
411   GfxFont *gfxFont;             // current PDF font
412   XOutputFont *font;            // current font
413   XOutputFontCache *fontCache;  // font cache
414   XOutputState *save;           // stack of saved states
415   TextPage *text;               // text from the current page
416
417   void updateLineAttrs(GfxState *state, GBool updateDash);
418   void doFill(GfxState *state, int rule);
419   void doClip(GfxState *state, int rule);
420   int convertPath(GfxState *state, XPoint **points, int *size,
421                   int *numPoints, int **lengths, GBool fillHack);
422   void convertSubpath(GfxState *state, GfxSubpath *subpath,
423                       XPoint **points, int *size, int *n);
424   void doCurve(XPoint **points, int *size, int *k,
425                double x0, double y0, double x1, double y1,
426                double x2, double y2, double x3, double y3);
427   void addPoint(XPoint **points, int *size, int *k, int x, int y);
428   Gulong findColor(GfxColor *color);
429   Gulong findColor(RGBColor *x, RGBColor *err);
430 };
431
432 #endif