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