00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef XOUTPUTDEV_H
00010 #define XOUTPUTDEV_H
00011
00012 #include <aconf.h>
00013
00014 #ifdef USE_GCC_PRAGMAS
00015 #pragma interface
00016 #endif
00017
00018 #include <stddef.h>
00019 #include <X11/Xlib.h>
00020 #include <X11/Xutil.h>
00021 #include "config.h"
00022 #include "CharTypes.h"
00023 #include "GlobalParams.h"
00024 #include "OutputDev.h"
00025
00026 class GString;
00027 class GList;
00028 struct GfxRGB;
00029 class GfxFont;
00030 class GfxSubpath;
00031 class TextPage;
00032 class XOutputFontCache;
00033 struct T3FontCacheTag;
00034 class T3FontCache;
00035 struct T3GlyphStack;
00036 class XOutputDev;
00037 class Link;
00038 class Catalog;
00039 class DisplayFontParam;
00040 class UnicodeMap;
00041 class CharCodeToUnicode;
00042
00043 #if HAVE_T1LIB_H
00044 class T1FontEngine;
00045 class T1FontFile;
00046 class T1Font;
00047 #endif
00048
00049 #if FREETYPE2 && (HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H)
00050 class FTFontEngine;
00051 class FTFontFile;
00052 class FTFont;
00053 #endif
00054
00055 #if !FREETYPE2 && (HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H)
00056 class TTFontEngine;
00057 class TTFontFile;
00058 class TTFont;
00059 #endif
00060
00061
00062
00063
00064
00065 #define maxRGBCube 7 // max size of RGB color cube
00066
00067 #define numTmpPoints 256 // number of XPoints in temporary array
00068 #define numTmpSubpaths 16 // number of elements in temporary arrays
00069
00070
00071
00072
00073
00074
00075 struct BoundingRect {
00076 short xMin, xMax;
00077 short yMin, yMax;
00078 };
00079
00080
00081
00082
00083
00084 class XOutputFont {
00085 public:
00086
00087 XOutputFont(Ref *idA, double m11OrigA, double m12OrigA,
00088 double m21OrigA, double m22OrigA,
00089 double m11A, double m12A, double m21A, double m22A,
00090 Display *displayA, XOutputDev *xOutA);
00091
00092 virtual ~XOutputFont();
00093
00094
00095 GBool matches(Ref *idA, double m11OrigA, double m12OrigA,
00096 double m21OrigA, double m22OrigA)
00097 { return id.num == idA->num && id.gen == idA->gen &&
00098 m11Orig == m11OrigA && m12Orig == m12OrigA &&
00099 m21Orig == m21OrigA && m22Orig == m22OrigA; }
00100
00101
00102 virtual GBool isOk() = 0;
00103
00104
00105 virtual void updateGC(GC gc) = 0;
00106
00107
00108 virtual void drawChar(GfxState *state, Pixmap pixmap, int w, int h,
00109 GC gc, GfxRGB *rgb,
00110 double x, double y, double dx, double dy,
00111 CharCode c, Unicode *u, int uLen) = 0;
00112
00113
00114
00115 virtual GBool hasGetCharPath() { return gFalse; }
00116
00117
00118 virtual void getCharPath(GfxState *state,
00119 CharCode c, Unicode *u, int ulen);
00120
00121 protected:
00122
00123 Ref id;
00124 double m11Orig, m12Orig,
00125 m21Orig, m22Orig;
00126 double m11, m12, m21, m22;
00127
00128 Display *display;
00129 XOutputDev *xOut;
00130 };
00131
00132 #if HAVE_T1LIB_H
00133
00134
00135
00136
00137 class XOutputT1Font: public XOutputFont {
00138 public:
00139
00140 XOutputT1Font(Ref *idA, T1FontFile *fontFileA,
00141 double m11OrigA, double m12OrigA,
00142 double m21OrigA, double m22OrigA,
00143 double m11A, double m12A,
00144 double m21A, double m22A,
00145 Display *displayA, XOutputDev *xOutA);
00146
00147 virtual ~XOutputT1Font();
00148
00149
00150 virtual GBool isOk();
00151
00152
00153 virtual void updateGC(GC gc);
00154
00155
00156 virtual void drawChar(GfxState *state, Pixmap pixmap, int w, int h,
00157 GC gc, GfxRGB *rgb,
00158 double x, double y, double dx, double dy,
00159 CharCode c, Unicode *u, int uLen);
00160
00161
00162
00163 virtual GBool hasGetCharPath() { return gTrue; }
00164
00165
00166 virtual void getCharPath(GfxState *state,
00167 CharCode c, Unicode *u, int ulen);
00168
00169 private:
00170
00171 T1FontFile *fontFile;
00172 T1Font *font;
00173 };
00174 #endif // HAVE_T1LIB_H
00175
00176 #if FREETYPE2 && (HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H)
00177
00178
00179
00180
00181 class XOutputFTFont: public XOutputFont {
00182 public:
00183
00184 XOutputFTFont(Ref *idA, FTFontFile *fontFileA,
00185 double m11OrigA, double m12OrigA,
00186 double m21OrigA, double m22OrigA,
00187 double m11A, double m12A,
00188 double m21A, double m22A,
00189 Display *displayA, XOutputDev *xOutA);
00190
00191 virtual ~XOutputFTFont();
00192
00193
00194 virtual GBool isOk();
00195
00196
00197 virtual void updateGC(GC gc);
00198
00199
00200 virtual void drawChar(GfxState *state, Pixmap pixmap, int w, int h,
00201 GC gc, GfxRGB *rgb,
00202 double x, double y, double dx, double dy,
00203 CharCode c, Unicode *u, int uLen);
00204
00205
00206
00207 virtual GBool hasGetCharPath() { return gTrue; }
00208
00209
00210 virtual void getCharPath(GfxState *state,
00211 CharCode c, Unicode *u, int ulen);
00212
00213 private:
00214
00215 FTFontFile *fontFile;
00216 FTFont *font;
00217 };
00218 #endif // FREETYPE2 && (HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H)
00219
00220 #if !FREETYPE2 && (HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H)
00221
00222
00223
00224
00225 class XOutputTTFont: public XOutputFont {
00226 public:
00227
00228 XOutputTTFont(Ref *idA, TTFontFile *fontFileA,
00229 double m11OrigA, double m12OrigA,
00230 double m21OrigA, double m22OrigA,
00231 double m11A, double m12A,
00232 double m21A, double m22A,
00233 Display *displayA, XOutputDev *xOutA);
00234
00235 virtual ~XOutputTTFont();
00236
00237
00238 virtual GBool isOk();
00239
00240
00241 virtual void updateGC(GC gc);
00242
00243
00244 virtual void drawChar(GfxState *state, Pixmap pixmap, int w, int h,
00245 GC gc, GfxRGB *rgb,
00246 double x, double y, double dx, double dy,
00247 CharCode c, Unicode *u, int uLen);
00248
00249 private:
00250
00251 TTFontFile *fontFile;
00252 TTFont *font;
00253 };
00254 #endif // !FREETYPE2 && (HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H)
00255
00256
00257
00258
00259
00260 class XOutputServer8BitFont: public XOutputFont {
00261 public:
00262
00263 XOutputServer8BitFont(Ref *idA, GString *xlfdFmt,
00264 UnicodeMap *xUMapA, CharCodeToUnicode *fontUMap,
00265 double m11OrigA, double m12OrigA,
00266 double m21OrigA, double m22OrigA,
00267 double m11A, double m12A, double m21A, double m22A,
00268 Display *displayA, XOutputDev *xOutA);
00269
00270 virtual ~XOutputServer8BitFont();
00271
00272
00273 virtual GBool isOk();
00274
00275
00276 virtual void updateGC(GC gc);
00277
00278
00279 virtual void drawChar(GfxState *state, Pixmap pixmap, int w, int h,
00280 GC gc, GfxRGB *rgb,
00281 double x, double y, double dx, double dy,
00282 CharCode c, Unicode *u, int uLen);
00283
00284 private:
00285
00286 XFontStruct *xFont;
00287 Gushort map[256];
00288 UnicodeMap *xUMap;
00289 };
00290
00291
00292
00293
00294
00295 class XOutputServer16BitFont: public XOutputFont {
00296 public:
00297
00298 XOutputServer16BitFont(Ref *idA, GString *xlfdFmt,
00299 UnicodeMap *xUMapA, CharCodeToUnicode *fontUMap,
00300 double m11OrigA, double m12OrigA,
00301 double m21OrigA, double m22OrigA,
00302 double m11A, double m12A, double m21A, double m22A,
00303 Display *displayA, XOutputDev *xOutA);
00304
00305 virtual ~XOutputServer16BitFont();
00306
00307
00308 virtual GBool isOk();
00309
00310
00311 virtual void updateGC(GC gc);
00312
00313
00314 virtual void drawChar(GfxState *state, Pixmap pixmap, int w, int h,
00315 GC gc, GfxRGB *rgb,
00316 double x, double y, double dx, double dy,
00317 CharCode c, Unicode *u, int uLen);
00318
00319 private:
00320
00321 XFontStruct *xFont;
00322 UnicodeMap *xUMap;
00323 };
00324
00325
00326
00327
00328
00329 #if HAVE_T1LIB_H
00330 class XOutputT1FontFile {
00331 public:
00332 XOutputT1FontFile(int numA, int genA, GBool substA,
00333 T1FontFile *fontFileA, GString *tmpFileNameA)
00334 { num = numA; gen = genA; subst = substA;
00335 fontFile = fontFileA; tmpFileName = tmpFileNameA; }
00336 ~XOutputT1FontFile();
00337 int num, gen;
00338 GBool subst;
00339 T1FontFile *fontFile;
00340 GString *tmpFileName;
00341 };
00342 #endif
00343
00344 #if FREETYPE2 && (HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H)
00345 class XOutputFTFontFile {
00346 public:
00347 XOutputFTFontFile(int numA, int genA, GBool substA,
00348 FTFontFile *fontFileA, GString *tmpFileNameA)
00349 { num = numA; gen = genA; subst = substA;
00350 fontFile = fontFileA; tmpFileName = tmpFileNameA; }
00351 ~XOutputFTFontFile();
00352 int num, gen;
00353 GBool subst;
00354 FTFontFile *fontFile;
00355 GString *tmpFileName;
00356 };
00357 #endif
00358
00359 #if !FREETYPE2 && (HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H)
00360 class XOutputTTFontFile {
00361 public:
00362 XOutputTTFontFile(int numA, int genA, GBool substA,
00363 TTFontFile *fontFileA, GString *tmpFileNameA)
00364 { num = numA; gen = genA; subst = substA;
00365 fontFile = fontFileA; tmpFileName = tmpFileNameA; }
00366 ~XOutputTTFontFile();
00367 int num, gen;
00368 GBool subst;
00369 TTFontFile *fontFile;
00370 GString *tmpFileName;
00371 };
00372 #endif
00373
00374 class XOutputFontCache {
00375 public:
00376
00377
00378 XOutputFontCache(Display *displayA, Guint depthA,
00379 XOutputDev *xOutA,
00380 FontRastControl t1libControlA,
00381 FontRastControl freetypeControlA);
00382
00383
00384 ~XOutputFontCache();
00385
00386
00387 void startDoc(int screenNum, Visual *visual,
00388 Colormap colormap, GBool trueColor,
00389 int rMul, int gMul, int bMul,
00390 int rShift, int gShift, int bShift,
00391 Gulong *colors, int numColors);
00392
00393
00394 XOutputFont *getFont(XRef *xref, GfxFont *gfxFont, double m11, double m12,
00395 double m21, double m22);
00396
00397 private:
00398
00399 void delFonts();
00400 void clear();
00401 XOutputFont *tryGetFont(XRef *xref, DisplayFontParam *dfp, GfxFont *gfxFont,
00402 double m11Orig, double m12Orig,
00403 double m21Orig, double m22Orig,
00404 double m11, double m12, double m21, double m22,
00405 GBool subst);
00406 #if HAVE_T1LIB_H
00407 XOutputFont *tryGetT1Font(XRef *xref, GfxFont *gfxFont,
00408 double m11, double m12, double m21, double m22);
00409 XOutputFont *tryGetT1FontFromFile(XRef *xref, GString *fileName,
00410 GBool deleteFile, GfxFont *gfxFont,
00411 double m11Orig, double m12Orig,
00412 double m21Orig, double m22Orig,
00413 double m11, double m12,
00414 double m21, double m22, GBool subst);
00415 #endif
00416 #if FREETYPE2 && (HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H)
00417 XOutputFont *tryGetFTFont(XRef *xref, GfxFont *gfxFont,
00418 double m11, double m12, double m21, double m22);
00419 XOutputFont *tryGetFTFontFromFile(XRef *xref, GString *fileName,
00420 GBool deleteFile, GfxFont *gfxFont,
00421 double m11Orig, double m12Orig,
00422 double m21Orig, double m22Orig,
00423 double m11, double m12,
00424 double m21, double m22, GBool subst);
00425 #endif
00426 #if !FREETYPE2 && (HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H)
00427 XOutputFont *tryGetTTFont(XRef *xref, GfxFont *gfxFont,
00428 double m11, double m12, double m21, double m22);
00429 XOutputFont *tryGetTTFontFromFile(XRef *xref, GString *fileName,
00430 GBool deleteFile, GfxFont *gfxFont,
00431 double m11Orig, double m12Orig,
00432 double m21Orig, double m22Orig,
00433 double m11, double m12,
00434 double m21, double m22, GBool subst);
00435 #endif
00436 XOutputFont *tryGetServerFont(GString *xlfd, GString *encodingName,
00437 GfxFont *gfxFont,
00438 double m11Orig, double m12Orig,
00439 double m21Orig, double m22Orig,
00440 double m11, double m12,
00441 double m21, double m22);
00442
00443 Display *display;
00444 XOutputDev *xOut;
00445 Guint depth;
00446
00447 XOutputFont *
00448 fonts[xOutFontCacheSize];
00449 int nFonts;
00450
00451 #if HAVE_T1LIB_H
00452 FontRastControl t1libControl;
00453 T1FontEngine *t1Engine;
00454 GList *t1FontFiles;
00455
00456 #endif
00457
00458 #if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
00459 FontRastControl
00460 freetypeControl;
00461 #endif
00462 #if FREETYPE2 && (HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H)
00463 FTFontEngine *ftEngine;
00464 GList *ftFontFiles;
00465
00466 #endif
00467 #if !FREETYPE2 && (HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H)
00468 TTFontEngine *ttEngine;
00469 GList *ttFontFiles;
00470
00471 #endif
00472 };
00473
00474
00475
00476
00477
00478 struct XOutputState {
00479 GC strokeGC;
00480 GC fillGC;
00481 Region clipRegion;
00482 XOutputState *next;
00483 };
00484
00485
00486
00487
00488
00489 class XOutputDev: public OutputDev {
00490 public:
00491
00492
00493 XOutputDev(Display *displayA, int screenNumA,
00494 Visual *visualA, Colormap colormapA,
00495 GBool reverseVideoA, unsigned long paperColorA,
00496 GBool installCmap, int rgbCubeSize,
00497 int forceDepth = 0);
00498
00499
00500 virtual ~XOutputDev();
00501
00502
00503
00504
00505
00506 virtual GBool upsideDown() { return gTrue; }
00507
00508
00509 virtual GBool useDrawChar() { return gTrue; }
00510
00511
00512
00513 virtual GBool interpretType3Chars() { return gTrue; }
00514
00515
00516
00517
00518 virtual void startPage(int pageNum, GfxState *state);
00519
00520
00521 virtual void endPage();
00522
00523
00524 virtual void drawLink(Link *link, Catalog *catalog);
00525
00526
00527 virtual void saveState(GfxState *state);
00528 virtual void restoreState(GfxState *state);
00529
00530
00531 virtual void updateAll(GfxState *state);
00532 virtual void updateCTM(GfxState *state, double m11, double m12,
00533 double m21, double m22, double m31, double m32);
00534 virtual void updateLineDash(GfxState *state);
00535 virtual void updateFlatness(GfxState *state);
00536 virtual void updateLineJoin(GfxState *state);
00537 virtual void updateLineCap(GfxState *state);
00538 virtual void updateMiterLimit(GfxState *state);
00539 virtual void updateLineWidth(GfxState *state);
00540 virtual void updateFillColor(GfxState *state);
00541 virtual void updateStrokeColor(GfxState *state);
00542
00543
00544 virtual void updateFont(GfxState *state);
00545
00546
00547 virtual void stroke(GfxState *state);
00548 virtual void fill(GfxState *state);
00549 virtual void eoFill(GfxState *state);
00550
00551
00552 virtual void clip(GfxState *state);
00553 virtual void eoClip(GfxState *state);
00554
00555
00556 virtual void beginString(GfxState *state, GString *s);
00557 virtual void endString(GfxState *state);
00558 virtual void drawChar(GfxState *state, double x, double y,
00559 double dx, double dy,
00560 double originX, double originY,
00561 CharCode code, Unicode *u, int uLen);
00562 virtual GBool beginType3Char(GfxState *state,
00563 CharCode code, Unicode *u, int uLen);
00564 virtual void endType3Char(GfxState *state);
00565
00566
00567 virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
00568 int width, int height, GBool invert,
00569 GBool inlineImg);
00570 virtual void drawImage(GfxState *state, Object *ref, Stream *str,
00571 int width, int height, GfxImageColorMap *colorMap,
00572 int *maskColors, GBool inlineImg);
00573
00574
00575 virtual void type3D0(GfxState *state, double wx, double wy);
00576 virtual void type3D1(GfxState *state, double wx, double wy,
00577 double llx, double lly, double urx, double ury);
00578
00579
00580
00581
00582 void startDoc(XRef *xrefA);
00583
00584
00585
00586
00587
00588
00589 GBool findText(Unicode *s, int len, GBool top, GBool bottom,
00590 int *xMin, int *yMin, int *xMax, int *yMax);
00591
00592
00593 GString *getText(int xMin, int yMin, int xMax, int yMax);
00594
00595 GBool isReverseVideo() { return reverseVideo; }
00596
00597
00598 void setPixmap(Pixmap pixmapA, int pixmapWA, int pixmapHA)
00599 { pixmap = pixmapA; pixmapW = pixmapWA; pixmapH = pixmapHA; }
00600
00601
00602 Pixmap getPixmap() { return pixmap; }
00603 int getPixmapWidth() { return pixmapW; }
00604 int getPixmapHeight() { return pixmapH; }
00605 Display *getDisplay() { return display; }
00606 Guint getDepth() { return depth; }
00607
00608 Gulong findColor(GfxRGB *rgb);
00609
00610 private:
00611
00612 XRef *xref;
00613 Display *display;
00614 int screenNum;
00615 Pixmap pixmap;
00616 int pixmapW, pixmapH;
00617 Guint depth;
00618 Visual *visual;
00619 Colormap colormap;
00620 int flatness;
00621 GC paperGC;
00622 GC strokeGC;
00623 GC fillGC;
00624 Region clipRegion;
00625 GBool trueColor;
00626 int rMul, gMul, bMul;
00627 int rShift, gShift, bShift;
00628 Gulong
00629 colors[maxRGBCube * maxRGBCube * maxRGBCube];
00630 unsigned long paperColor;
00631 int numColors;
00632 double redMap[256];
00633 GBool reverseVideo;
00634 XPoint
00635 tmpPoints[numTmpPoints];
00636 int
00637 tmpLengths[numTmpSubpaths];
00638 BoundingRect
00639 tmpRects[numTmpSubpaths];
00640 GfxFont *gfxFont;
00641 XOutputFont *font;
00642 XOutputFontCache *fontCache;
00643 T3FontCache *
00644 t3FontCache[xOutT3FontCacheSize];
00645 int nT3Fonts;
00646 T3GlyphStack *t3GlyphStack;
00647 XOutputState *save;
00648
00649 TextPage *text;
00650
00651 void updateLineAttrs(GfxState *state, GBool updateDash);
00652 void doFill(GfxState *state, int rule);
00653 void doClip(GfxState *state, int rule);
00654 int convertPath(GfxState *state, XPoint **points, int *size,
00655 int *numPoints, int **lengths, GBool fillHack);
00656 void convertSubpath(GfxState *state, GfxSubpath *subpath,
00657 XPoint **points, int *size, int *n);
00658 void doCurve(XPoint **points, int *size, int *k,
00659 double x0, double y0, double x1, double y1,
00660 double x2, double y2, double x3, double y3);
00661 void addPoint(XPoint **points, int *size, int *k, int x, int y);
00662 void drawType3Glyph(T3FontCache *t3Font,
00663 T3FontCacheTag *tag, Guchar *data,
00664 double x, double y, GfxRGB *color);
00665 Gulong findColor(GfxRGB *x, GfxRGB *err);
00666 };
00667
00668 #endif