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