1 //========================================================================
5 // Copyright 1996 Derek B. Noonburg
7 //========================================================================
18 #include <X11/Xutil.h>
20 #include "OutputDev.h"
28 class XOutputFontCache;
38 #if HAVE_FREETYPE_FREETYPE_H | HAVE_FREETYPE_H
44 //------------------------------------------------------------------------
46 //------------------------------------------------------------------------
48 #define maxRGBCube 8 // max size of RGB color cube
50 #define numTmpPoints 256 // number of XPoints in temporary array
51 #define numTmpSubpaths 16 // number of elements in temporary arrays
54 //------------------------------------------------------------------------
56 //------------------------------------------------------------------------
59 short xMin, xMax; // min/max x values
60 short yMin, yMax; // min/max y values
63 //------------------------------------------------------------------------
65 //------------------------------------------------------------------------
67 // Install a private colormap.
68 extern GBool installCmap;
70 // Size of RGB color cube.
71 extern int rgbCubeSize;
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;
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;
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;
107 // Use the EUC-JP encoding.
108 extern GBool useEUCJP;
111 // X font name pattern to use for Japanese text.
112 extern GString *japan12Font;
115 #if CHINESE_GB_SUPPORT
116 // X font name pattern to use for Chinese GB text.
117 extern GString *gb12Font;
120 #if CHINESE_CNS_SUPPORT
121 // X font name pattern to use for Chinese CNS text.
122 extern GString *cns13Font;
125 //------------------------------------------------------------------------
127 //------------------------------------------------------------------------
132 XOutputFont(GfxFont *gfxFont, double m11, double m12,
133 double m21, double m22, Display *display,
134 XOutputFontCache *cache);
136 virtual ~XOutputFont();
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; }
143 // Was font created successfully?
144 virtual GBool isOk() = 0;
146 // Update <gc> with this font.
147 virtual void updateGC(GC gc) = 0;
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;
153 // Does this font use hex char codes?
154 GBool isHex() { return hex; }
159 double tm11, tm12, // original transform matrix
161 Display *display; // X display
162 GBool hex; // subsetted font with hex char codes
163 // (this flag is used for text output)
167 //------------------------------------------------------------------------
169 //------------------------------------------------------------------------
171 class XOutputT1Font: public XOutputFont {
174 XOutputT1Font(GfxFont *gfxFont, GString *pdfBaseFont,
175 double m11, double m12, double m21, double m22,
176 Display *display, XOutputFontCache *cache);
178 virtual ~XOutputT1Font();
180 // Was font created successfully?
181 virtual GBool isOk();
183 // Update <gc> with this font.
184 virtual void updateGC(GC gc);
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);
192 T1FontFile *fontFile;
197 #if HAVE_FREETYPE_FREETYPE_H | HAVE_FREETYPE_H
198 //------------------------------------------------------------------------
200 //------------------------------------------------------------------------
202 class XOutputTTFont: public XOutputFont {
205 XOutputTTFont(GfxFont *gfxFont, double m11, double m12,
206 double m21, double m22, Display *display,
207 XOutputFontCache *cache);
209 virtual ~XOutputTTFont();
211 // Was font created successfully?
212 virtual GBool isOk();
214 // Update <gc> with this font.
215 virtual void updateGC(GC gc);
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);
223 TTFontFile *fontFile;
228 //------------------------------------------------------------------------
230 //------------------------------------------------------------------------
232 class XOutputServerFont: public XOutputFont {
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);
242 virtual ~XOutputServerFont();
244 // Was font created successfully?
245 virtual GBool isOk();
247 // Update <gc> with this font.
248 virtual void updateGC(GC gc);
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);
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)
261 //------------------------------------------------------------------------
263 //------------------------------------------------------------------------
266 struct XOutputT1FontFile {
268 T1FontFile *fontFile;
272 #if HAVE_FREETYPE_FREETYPE_H | HAVE_FREETYPE_H
273 struct XOutputTTFontFile {
275 TTFontFile *fontFile;
279 class XOutputFontCache {
283 XOutputFontCache(Display *display, Guint depth);
288 // Initialize (or re-initialize) the font cache for a new document.
289 void startDoc(int screenNum, Colormap colormap,
291 int rMul, int gMul, int bMul,
292 int rShift, int gShift, int bShift,
293 Gulong *colors, int numColors);
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);
300 // Get a t1lib font file.
301 T1FontFile *getT1Font(GfxFont *gfxFont, GString *pdfBaseFont);
303 // Use anti-aliased Type 1 fonts?
304 GBool getT1libAA() { return t1libAA; }
307 #if HAVE_FREETYPE_FREETYPE_H | HAVE_FREETYPE_H
308 // Get a FreeType font file.
309 TTFontFile *getTTFont(GfxFont *gfxFont);
317 Display *display; // X display pointer
318 Guint depth; // pixmap depth
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
330 int t1FontFilesSize; // size of t1FontFiles array
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
342 int ttFontFilesSize; // size of ttFontFiles array
345 XOutputServerFont * // X server fonts in reverse-LRU order
346 serverFonts[serverFontCacheSize];
347 int nServerFonts; // number of valid entries in serverFonts[]
350 //------------------------------------------------------------------------
352 //------------------------------------------------------------------------
354 struct XOutputState {
361 //------------------------------------------------------------------------
363 //------------------------------------------------------------------------
365 class XOutputDev: public OutputDev {
369 XOutputDev(Display *display1, Pixmap pixmap1, Guint depth1,
370 Colormap colormap, unsigned long paperColor);
373 virtual ~XOutputDev();
375 //---- get info about output device
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; }
381 // Does this device use drawChar() or drawString()?
382 virtual GBool useDrawChar() { return gTrue; }
384 //----- initialization and control
387 virtual void startPage(int pageNum, GfxState *state);
390 virtual void endPage();
393 virtual void drawLink(Link *link, Catalog *catalog);
395 //----- save/restore graphics state
396 virtual void saveState(GfxState *state);
397 virtual void restoreState(GfxState *state);
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);
412 //----- update text state
413 virtual void updateFont(GfxState *state);
415 //----- path painting
416 virtual void stroke(GfxState *state);
417 virtual void fill(GfxState *state);
418 virtual void eoFill(GfxState *state);
420 //----- path clipping
421 virtual void clip(GfxState *state);
422 virtual void eoClip(GfxState *state);
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);
432 //----- image drawing
433 virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
434 int width, int height, GBool invert,
436 virtual void drawImage(GfxState *state, Object *ref, Stream *str,
437 int width, int height, GfxImageColorMap *colorMap,
440 //----- special access
442 // Called to indicate that a new PDF document has been loaded.
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);
453 // Get the text which is inside the specified rectangle.
454 GString *getText(int xMin, int yMin, int xMax, int yMax);
458 // Update pixmap ID after a page change.
459 void setPixmap(Pixmap pixmap1, int pixmapW1, int pixmapH1)
460 { pixmap = pixmap1; pixmapW = pixmapW1; pixmapH = pixmapH1; }
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)
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];
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
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);