1 //========================================================================
5 // Copyright 1996 Derek B. Noonburg
7 //========================================================================
18 #include <X11/Xutil.h>
20 #include "OutputDev.h"
29 //------------------------------------------------------------------------
31 //------------------------------------------------------------------------
33 #define maxRGBCube 8 // max size of RGB color cube
35 #define numTmpPoints 256 // number of XPoints in temporary array
36 #define numTmpSubpaths 16 // number of elements in temporary arrays
39 //------------------------------------------------------------------------
41 //------------------------------------------------------------------------
44 short xMin, xMax; // min/max x values
45 short yMin, yMax; // min/max y values
52 //------------------------------------------------------------------------
54 //------------------------------------------------------------------------
56 // Install a private colormap.
57 extern GBool installCmap;
59 // Size of RGB color cube.
60 extern int rgbCubeSize;
62 //------------------------------------------------------------------------
64 //------------------------------------------------------------------------
70 XOutputFont(GfxFont *gfxFont, double m11, double m12,
71 double m21, double m22, Display *display1);
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; }
82 XFontStruct *getXFont() { return xFont; }
84 // Get character mapping.
85 Gushort mapChar(Guchar c) { return map[c]; }
87 // Reverse map a character.
88 Guchar revMapChar(Gushort c) { return revMap[c]; }
90 // Does this font use hex char codes?
91 GBool isHex() { return hex; }
96 double mat11, mat12, mat21, mat22;
99 GBool hex; // subsetted font with hex char codes
104 //------------------------------------------------------------------------
106 //------------------------------------------------------------------------
108 class XOutputFontCache {
112 XOutputFontCache(Display *display1);
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);
123 Display *display; // X display pointer
124 XOutputFont * // fonts in reverse-LRU order
125 fonts[fontCacheSize];
126 int numFonts; // number of valid entries
129 //------------------------------------------------------------------------
131 //------------------------------------------------------------------------
133 struct XOutputState {
140 //------------------------------------------------------------------------
142 //------------------------------------------------------------------------
144 class XOutputDev: public OutputDev {
148 XOutputDev(Display *display1, Pixmap pixmap1, Guint depth1,
149 Colormap colormap, unsigned long paperColor);
152 virtual ~XOutputDev();
154 //---- get info about output device
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; }
160 // Does this device use drawChar() or drawString()?
161 virtual GBool useDrawChar() { return gTrue; }
163 //----- initialization and control
166 virtual void startPage(int pageNum, GfxState *state);
169 virtual void endPage();
172 virtual void drawLinkBorder(double x1, double y1, double x2, double y2,
175 //----- save/restore graphics state
176 virtual void saveState(GfxState *state);
177 virtual void restoreState(GfxState *state);
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);
192 //----- update text state
193 virtual void updateFont(GfxState *state);
195 //----- path painting
196 virtual void stroke(GfxState *state);
197 virtual void fill(GfxState *state);
198 virtual void eoFill(GfxState *state);
200 //----- path clipping
201 virtual void clip(GfxState *state);
202 virtual void eoClip(GfxState *state);
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);
212 //----- image drawing
213 virtual void drawImageMask(GfxState *state, Stream *str,
214 int width, int height, GBool invert,
216 virtual void drawImage(GfxState *state, Stream *str, int width,
217 int height, GfxImageColorMap *colorMap,
220 //----- special access
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);
230 // Get the text which is inside the specified rectangle.
231 GString *getText(int xMin, int yMin, int xMax, int yMax);
235 // Update pixmap ID after a page change.
236 void setPixmap(Pixmap pixmap1, int pixmapW1, int pixmapH1)
237 { pixmap = pixmap1; pixmapW = pixmapW1; pixmapH = pixmapH1; }
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)
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];
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
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);