00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef GFXFONT_H
00010 #define GFXFONT_H
00011
00012 #include <aconf.h>
00013
00014 #ifdef USE_GCC_PRAGMAS
00015 #pragma interface
00016 #endif
00017
00018 #include "gtypes.h"
00019 #include "GString.h"
00020 #include "Object.h"
00021 #include "CharTypes.h"
00022
00023 class Dict;
00024 class CMap;
00025 class CharCodeToUnicode;
00026 class FoFiTrueType;
00027 struct GfxFontCIDWidths;
00028
00029
00030
00031
00032
00033 enum GfxFontType {
00034
00035 fontUnknownType,
00036 fontType1,
00037 fontType1C,
00038 fontType3,
00039 fontTrueType,
00040
00041 fontCIDType0,
00042 fontCIDType0C,
00043 fontCIDType2
00044 };
00045
00046
00047
00048
00049
00050 struct GfxFontCIDWidthExcep {
00051 CID first;
00052 CID last;
00053 double width;
00054 };
00055
00056 struct GfxFontCIDWidthExcepV {
00057 CID first;
00058 CID last;
00059 double height;
00060 double vx, vy;
00061 };
00062
00063 struct GfxFontCIDWidths {
00064 double defWidth;
00065 double defHeight;
00066 double defVY;
00067 GfxFontCIDWidthExcep *exceps;
00068 int nExceps;
00069 GfxFontCIDWidthExcepV *
00070 excepsV;
00071 int nExcepsV;
00072 };
00073
00074
00075
00076
00077
00078 #define fontFixedWidth (1 << 0)
00079 #define fontSerif (1 << 1)
00080 #define fontSymbolic (1 << 2)
00081 #define fontItalic (1 << 6)
00082 #define fontBold (1 << 18)
00083
00084 class GfxFont {
00085 public:
00086
00087
00088 static GfxFont *makeFont(XRef *xref, char *tagA, Ref idA, Dict *fontDict);
00089
00090 GfxFont(char *tagA, Ref idA, GString *nameA);
00091
00092 virtual ~GfxFont();
00093
00094 GBool isOk() { return ok; }
00095
00096
00097 GString *getTag() { return tag; }
00098
00099
00100 Ref *getID() { return &id; }
00101
00102
00103 GBool matches(char *tagA) { return !tag->cmp(tagA); }
00104
00105
00106 GString *getName() { return name; }
00107
00108
00109
00110 GString *getOrigName() { return origName; }
00111
00112
00113 GfxFontType getType() { return type; }
00114 virtual GBool isCIDFont() { return gFalse; }
00115
00116
00117
00118 GBool getEmbeddedFontID(Ref *embID)
00119 { *embID = embFontID; return embFontID.num >= 0; }
00120
00121
00122
00123 GString *getEmbeddedFontName() { return embFontName; }
00124
00125
00126
00127 GString *getExtFontFile() { return extFontFile; }
00128
00129
00130 GBool isFixedWidth() { return flags & fontFixedWidth; }
00131 GBool isSerif() { return flags & fontSerif; }
00132 GBool isSymbolic() { return flags & fontSymbolic; }
00133 GBool isItalic() { return flags & fontItalic; }
00134 GBool isBold() { return flags & fontBold; }
00135
00136
00137 double *getFontMatrix() { return fontMat; }
00138
00139
00140 double *getFontBBox() { return fontBBox; }
00141
00142
00143 double getAscent() { return ascent; }
00144 double getDescent() { return descent; }
00145
00146
00147 virtual int getWMode() { return 0; }
00148
00149
00150 char *readExtFontFile(int *len);
00151 char *readEmbFontFile(XRef *xref, int *len);
00152
00153
00154
00155
00156
00157
00158
00159 virtual int getNextChar(char *s, int len, CharCode *code,
00160 Unicode *u, int uSize, int *uLen,
00161 double *dx, double *dy, double *ox, double *oy) = 0;
00162
00163 protected:
00164
00165 void readFontDescriptor(XRef *xref, Dict *fontDict);
00166 CharCodeToUnicode *readToUnicodeCMap(Dict *fontDict, int nBits,
00167 CharCodeToUnicode *ctu);
00168 void findExtFontFile();
00169
00170 GString *tag;
00171 Ref id;
00172 GString *name;
00173 GString *origName;
00174 GfxFontType type;
00175 int flags;
00176 GString *embFontName;
00177 Ref embFontID;
00178 GString *extFontFile;
00179 double fontMat[6];
00180 double fontBBox[4];
00181 double missingWidth;
00182 double ascent;
00183 double descent;
00184 GBool ok;
00185 };
00186
00187
00188
00189
00190
00191 class Gfx8BitFont: public GfxFont {
00192 public:
00193
00194 Gfx8BitFont(XRef *xref, char *tagA, Ref idA, GString *nameA,
00195 GfxFontType typeA, Dict *fontDict);
00196
00197 virtual ~Gfx8BitFont();
00198
00199 virtual int getNextChar(char *s, int len, CharCode *code,
00200 Unicode *u, int uSize, int *uLen,
00201 double *dx, double *dy, double *ox, double *oy);
00202
00203
00204 char **getEncoding() { return enc; }
00205
00206
00207 CharCodeToUnicode *getToUnicode();
00208
00209
00210 char *getCharName(int code) { return enc[code]; }
00211
00212
00213 GBool getHasEncoding() { return hasEncoding; }
00214
00215
00216 GBool getUsesMacRomanEnc() { return usesMacRomanEnc; }
00217
00218
00219 double getWidth(Guchar c) { return widths[c]; }
00220
00221
00222
00223 Gushort *getCodeToGIDMap(FoFiTrueType *ff);
00224
00225
00226 Dict *getCharProcs();
00227
00228
00229 Object *getCharProc(int code, Object *proc);
00230
00231
00232 Dict *getResources();
00233
00234 private:
00235
00236 char *enc[256];
00237 char encFree[256];
00238
00239 CharCodeToUnicode *ctu;
00240 GBool hasEncoding;
00241 GBool usesMacRomanEnc;
00242 double widths[256];
00243 Object charProcs;
00244 Object resources;
00245 };
00246
00247
00248
00249
00250
00251 class GfxCIDFont: public GfxFont {
00252 public:
00253
00254 GfxCIDFont(XRef *xref, char *tagA, Ref idA, GString *nameA,
00255 Dict *fontDict);
00256
00257 virtual ~GfxCIDFont();
00258
00259 virtual GBool isCIDFont() { return gTrue; }
00260
00261 virtual int getNextChar(char *s, int len, CharCode *code,
00262 Unicode *u, int uSize, int *uLen,
00263 double *dx, double *dy, double *ox, double *oy);
00264
00265
00266 virtual int getWMode();
00267
00268
00269 CharCodeToUnicode *getToUnicode();
00270
00271
00272 GString *getCollection();
00273
00274
00275
00276 Gushort *getCIDToGID() { return cidToGID; }
00277 int getCIDToGIDLen() { return cidToGIDLen; }
00278
00279 private:
00280
00281 CMap *cMap;
00282 CharCodeToUnicode *ctu;
00283 GfxFontCIDWidths widths;
00284 Gushort *cidToGID;
00285
00286 int cidToGIDLen;
00287 };
00288
00289
00290
00291
00292
00293 class GfxFontDict {
00294 public:
00295
00296
00297 GfxFontDict(XRef *xref, Ref *fontDictRef, Dict *fontDict);
00298
00299
00300 ~GfxFontDict();
00301
00302
00303 GfxFont *lookup(char *tag);
00304
00305
00306 int getNumFonts() { return numFonts; }
00307 GfxFont *getFont(int i) { return fonts[i]; }
00308
00309 private:
00310
00311 GfxFont **fonts;
00312 int numFonts;
00313 };
00314
00315 #endif