filters

FTFont.h

00001 //========================================================================
00002 //
00003 // FTFont.h
00004 //
00005 // An X wrapper for the FreeType font rasterizer.
00006 //
00007 // Copyright 2001-2002 Glyph & Cog, LLC
00008 //
00009 //========================================================================
00010 
00011 #ifndef FTFONT_H
00012 #define FTFONT_H
00013 
00014 #include <aconf.h>
00015 
00016 #if FREETYPE2 && (HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H)
00017 
00018 #ifdef USE_GCC_PRAGMAS
00019 #pragma interface
00020 #endif
00021 
00022 #include <freetype/freetype.h>
00023 #include "CharTypes.h"
00024 #include "SFont.h"
00025 
00026 //------------------------------------------------------------------------
00027 
00028 class FTFontEngine: public SFontEngine {
00029 public:
00030 
00031   FTFontEngine(Display *displayA, Visual *visualA, int depthA,
00032            Colormap colormapA, GBool aaA);
00033   GBool isOk() { return ok; }
00034   virtual ~FTFontEngine();
00035 
00036 private:
00037 
00038   FT_Library lib;
00039   GBool aa;
00040   Gulong palette[5];
00041   GBool ok;
00042 
00043   friend class FTFontFile;
00044   friend class FTFont;
00045 };
00046 
00047 //------------------------------------------------------------------------
00048 
00049 enum FTFontIndexMode {
00050   ftFontModeUnicode,
00051   ftFontModeCharCode,
00052   ftFontModeCharCodeOffset,
00053   ftFontModeCodeMap,
00054   ftFontModeCodeMapDirect,
00055   ftFontModeCIDToGIDMap,
00056   ftFontModeCFFCharset
00057 };
00058 
00059 class FTFontFile: public SFontFile {
00060 public:
00061 
00062   // 8-bit font, TrueType or Type 1/1C
00063   FTFontFile(FTFontEngine *engineA, char *fontFileName,
00064          char **fontEnc, GBool pdfFontHasEncoding);
00065 
00066   // CID font, TrueType
00067   FTFontFile(FTFontEngine *engineA, char *fontFileName,
00068          Gushort *cidToGIDA, int cidToGIDLenA);
00069 
00070   // CID font, Type 0C (CFF)
00071   FTFontFile(FTFontEngine *engineA, char *fontFileName);
00072 
00073   GBool isOk() { return ok; }
00074   virtual ~FTFontFile();
00075 
00076 private:
00077 
00078   FTFontEngine *engine;
00079   FT_Face face;
00080   FTFontIndexMode mode;
00081   int charMapOffset;
00082   Guint *codeMap;
00083   Gushort *cidToGID;
00084   int cidToGIDLen;
00085   GBool ok;
00086 
00087   friend class FTFont;
00088 };
00089 
00090 //------------------------------------------------------------------------
00091 
00092 struct FTFontCacheTag {
00093   Gushort code;
00094   Gushort mru;          // valid bit (0x8000) and MRU index
00095   int x, y, w, h;       // offset and size of glyph
00096 };
00097 
00098 class FTFont: public SFont {
00099 public:
00100 
00101   FTFont(FTFontFile *fontFileA, double *m);
00102   GBool isOk() { return ok; }
00103   virtual ~FTFont();
00104   virtual GBool drawChar(Drawable d, int w, int h, GC gc,
00105              int x, int y, int r, int g, int b,
00106              CharCode c, Unicode u);
00107   virtual GBool getCharPath(CharCode c, Unicode u, GfxState *state);
00108 
00109 private:
00110 
00111   Guchar *getGlyphPixmap(CharCode c, Unicode u,
00112              int *x, int *y, int *w, int *h);
00113   static int charPathMoveTo(FT_Vector *pt, void *state);
00114   static int charPathLineTo(FT_Vector *pt, void *state);
00115   static int charPathConicTo(FT_Vector *ctrl, FT_Vector *pt, void *state);
00116   static int charPathCubicTo(FT_Vector *ctrl1, FT_Vector *ctrl2,
00117                  FT_Vector *pt, void *state);
00118   FT_UInt getGlyphIndex(CharCode c, Unicode u);
00119 
00120   FTFontFile *fontFile;
00121   FT_Size sizeObj;
00122   XImage *image;
00123   FT_Matrix matrix;
00124   int glyphW, glyphH;       // size of glyph pixmaps
00125   int glyphSize;        // size of glyph pixmaps, in bytes
00126   Guchar *cache;        // glyph pixmap cache
00127   FTFontCacheTag *cacheTags;    // cache tags, i.e., char codes
00128   int cacheSets;        // number of sets in cache
00129   int cacheAssoc;       // cache associativity (glyphs per set)
00130   GBool ok;
00131 };
00132 
00133 #endif // FREETYPE2 && (HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H)
00134 
00135 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys