1 //========================================================================
5 // Copyright 1996 Derek B. Noonburg
7 //========================================================================
18 #include <X11/Xutil.h>
24 #include "OutputDev.h"
33 class XOutputFontCache;
35 //------------------------------------------------------------------------
37 //------------------------------------------------------------------------
39 #define maxRGBCube 8 // max size of RGB color cube
41 #define numTmpPoints 256 // number of XPoints in temporary array
42 #define numTmpSubpaths 16 // number of elements in temporary arrays
45 //------------------------------------------------------------------------
47 //------------------------------------------------------------------------
50 short xMin, xMax; // min/max x values
51 short yMin, yMax; // min/max y values
58 //------------------------------------------------------------------------
60 //------------------------------------------------------------------------
62 // Install a private colormap.
63 extern GBool installCmap;
65 // Size of RGB color cube.
66 extern int rgbCubeSize;
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;
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;
94 // Use the EUC-JP encoding.
95 extern GBool useEUCJP;
98 // X font name pattern to use for Japanese text.
99 extern GString *japan12Font;
102 //------------------------------------------------------------------------
104 //------------------------------------------------------------------------
109 XOutputFont(GfxFont *gfxFont, double m11, double m12,
110 double m21, double m22, Display *display,
111 XOutputFontCache *cache);
113 virtual ~XOutputFont();
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; }
120 // Was font created successfully?
121 virtual GBool isOk() = 0;
123 // Update <gc> with this font.
124 virtual void updateGC(GC gc) = 0;
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;
130 // Does this font use hex char codes?
131 GBool isHex() { return hex; }
136 double tm11, tm12, // original transform matrix
138 Display *display; // X display
139 GBool hex; // subsetted font with hex char codes
140 // (this flag is used for text output)
144 //------------------------------------------------------------------------
146 //------------------------------------------------------------------------
148 class XOutputT1Font: public XOutputFont {
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);
157 virtual ~XOutputT1Font();
159 // Was font created successfully?
160 virtual GBool isOk();
162 // Update <gc> with this font.
163 virtual void updateGC(GC gc);
165 // Draw character <c> at <x>,<y>.
166 virtual void drawChar(GfxState *state, Pixmap pixmap, GC gc,
167 double x, double y, int c);
171 float size; // font size
172 int t1ID; // t1lib font ID
173 GBool t1libAA; // true for anti-aliased fonts
177 //------------------------------------------------------------------------
179 //------------------------------------------------------------------------
181 class XOutputServerFont: public XOutputFont {
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);
191 virtual ~XOutputServerFont();
193 // Was font created successfully?
194 virtual GBool isOk();
196 // Update <gc> with this font.
197 virtual void updateGC(GC gc);
199 // Draw character <c> at <x>,<y>.
200 virtual void drawChar(GfxState *state, Pixmap pixmap, GC gc,
201 double x, double y, int c);
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)
210 //------------------------------------------------------------------------
212 //------------------------------------------------------------------------
215 struct XOutputT1BaseFont {
223 class XOutputFontCache {
227 XOutputFontCache(Display *display);
232 // Initialize (or re-initialize) the font cache for a new document.
233 void startDoc(int screenNum, Guint depth,
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);
242 int getT1Font(GfxFont *gfxFont, GString *pdfBaseFont);
244 // Use anti-aliased Type 1 fonts?
245 GBool getT1libAA() { return t1libAA; }
253 Display *display; // X display pointer
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
265 int t1BaseFontsSize; // size of t1BaseFonts array
268 XOutputServerFont * // X server fonts in reverse-LRU order
269 serverFonts[serverFontCacheSize];
270 int nServerFonts; // number of valid entries in serverFonts[]
273 //------------------------------------------------------------------------
275 //------------------------------------------------------------------------
277 struct XOutputState {
284 //------------------------------------------------------------------------
286 //------------------------------------------------------------------------
288 class XOutputDev: public OutputDev {
292 XOutputDev(Display *display1, Pixmap pixmap1, Guint depth1,
293 Colormap colormap, unsigned long paperColor);
296 virtual ~XOutputDev();
298 //---- get info about output device
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; }
304 // Does this device use drawChar() or drawString()?
305 virtual GBool useDrawChar() { return gTrue; }
307 //----- initialization and control
310 virtual void startPage(int pageNum, GfxState *state);
313 virtual void endPage();
316 virtual void drawLinkBorder(double x1, double y1, double x2, double y2,
319 //----- save/restore graphics state
320 virtual void saveState(GfxState *state);
321 virtual void restoreState(GfxState *state);
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);
336 //----- update text state
337 virtual void updateFont(GfxState *state);
339 //----- path painting
340 virtual void stroke(GfxState *state);
341 virtual void fill(GfxState *state);
342 virtual void eoFill(GfxState *state);
344 //----- path clipping
345 virtual void clip(GfxState *state);
346 virtual void eoClip(GfxState *state);
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);
356 //----- image drawing
357 virtual void drawImageMask(GfxState *state, Stream *str,
358 int width, int height, GBool invert,
360 virtual void drawImage(GfxState *state, Stream *str, int width,
361 int height, GfxImageColorMap *colorMap,
364 //----- special access
366 // Called to indicate that a new PDF document has been loaded.
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);
377 // Get the text which is inside the specified rectangle.
378 GString *getText(int xMin, int yMin, int xMax, int yMax);
382 // Update pixmap ID after a page change.
383 void setPixmap(Pixmap pixmap1, int pixmapW1, int pixmapH1)
384 { pixmap = pixmap1; pixmapW = pixmapW1; pixmapH = pixmapH1; }
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)
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];
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
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);