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