#ifndef GFXFONT_H
#define GFXFONT_H
#include <config.h>
#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif
#include "gtypes.h"
#include "GString.h"
#include "Object.h"
#include "CharTypes.h"
class Dict;
class CMap;
class CharCodeToUnicode;
class FoFiTrueType;
struct GfxFontCIDWidths;
enum GfxFontType {
fontUnknownType,
fontType1,
fontType1C,
fontType3,
fontTrueType,
fontCIDType0,
fontCIDType0C,
fontCIDType2
};
struct GfxFontCIDWidthExcep {
CID first; CID last; double width; };
struct GfxFontCIDWidthExcepV {
CID first; CID last; double height; double vx, vy; };
struct GfxFontCIDWidths {
double defWidth; double defHeight; double defVY; GfxFontCIDWidthExcep *exceps; int nExceps; GfxFontCIDWidthExcepV * excepsV;
int nExcepsV; };
#define fontFixedWidth (1 << 0)
#define fontSerif (1 << 1)
#define fontSymbolic (1 << 2)
#define fontItalic (1 << 6)
#define fontBold (1 << 18)
class GfxFont {
public:
static GfxFont *makeFont(XRef *xref, char *tagA, Ref idA, Dict *fontDict);
GfxFont(char *tagA, Ref idA, GString *nameA);
virtual ~GfxFont();
GBool isOk() { return ok; }
GString *getTag() { return tag; }
Ref *getID() { return &id; }
GBool matches(char *tagA) { return !tag->cmp(tagA); }
GString *getName() { return name; }
GString *getOrigName() { return origName; }
GfxFontType getType() { return type; }
virtual GBool isCIDFont() { return gFalse; }
GBool getEmbeddedFontID(Ref *embID)
{ *embID = embFontID; return embFontID.num >= 0; }
GString *getEmbeddedFontName() { return embFontName; }
GString *getExtFontFile() { return extFontFile; }
GBool isFixedWidth() { return flags & fontFixedWidth; }
GBool isSerif() { return flags & fontSerif; }
GBool isSymbolic() { return flags & fontSymbolic; }
GBool isItalic() { return flags & fontItalic; }
GBool isBold() { return flags & fontBold; }
double *getFontMatrix() { return fontMat; }
double *getFontBBox() { return fontBBox; }
double getAscent() { return ascent; }
double getDescent() { return descent; }
virtual int getWMode() { return 0; }
char *readExtFontFile(int *len);
char *readEmbFontFile(XRef *xref, int *len);
virtual int getNextChar(char *s, int len, CharCode *code,
Unicode *u, int uSize, int *uLen,
double *dx, double *dy, double *ox, double *oy) = 0;
protected:
void readFontDescriptor(XRef *xref, Dict *fontDict);
CharCodeToUnicode *readToUnicodeCMap(Dict *fontDict, int nBits,
CharCodeToUnicode *ctu);
void findExtFontFile();
GString *tag; Ref id; GString *name; GString *origName; GfxFontType type; int flags; GString *embFontName; Ref embFontID; GString *extFontFile; double fontMat[6]; double fontBBox[4]; double missingWidth; double ascent; double descent; GBool ok;
};
class Gfx8BitFont: public GfxFont {
public:
Gfx8BitFont(XRef *xref, char *tagA, Ref idA, GString *nameA,
GfxFontType typeA, Dict *fontDict);
virtual ~Gfx8BitFont();
virtual int getNextChar(char *s, int len, CharCode *code,
Unicode *u, int uSize, int *uLen,
double *dx, double *dy, double *ox, double *oy);
char **getEncoding() { return enc; }
CharCodeToUnicode *getToUnicode();
char *getCharName(int code) { return enc[code]; }
GBool getHasEncoding() { return hasEncoding; }
GBool getUsesMacRomanEnc() { return usesMacRomanEnc; }
double getWidth(Guchar c) { return widths[c]; }
Gushort *getCodeToGIDMap(FoFiTrueType *ff);
Dict *getCharProcs();
Object *getCharProc(int code, Object *proc);
Dict *getResources();
private:
char *enc[256]; char encFree[256]; CharCodeToUnicode *ctu; GBool hasEncoding;
GBool usesMacRomanEnc;
double widths[256]; Object charProcs; Object resources; };
class GfxCIDFont: public GfxFont {
public:
GfxCIDFont(XRef *xref, char *tagA, Ref idA, GString *nameA,
Dict *fontDict);
virtual ~GfxCIDFont();
virtual GBool isCIDFont() { return gTrue; }
virtual int getNextChar(char *s, int len, CharCode *code,
Unicode *u, int uSize, int *uLen,
double *dx, double *dy, double *ox, double *oy);
virtual int getWMode();
CharCodeToUnicode *getToUnicode();
GString *getCollection();
Gushort *getCIDToGID() { return cidToGID; }
int getCIDToGIDLen() { return cidToGIDLen; }
private:
CMap *cMap; CharCodeToUnicode *ctu; GfxFontCIDWidths widths; Gushort *cidToGID; int cidToGIDLen;
};
class GfxFontDict {
public:
GfxFontDict(XRef *xref, Ref *fontDictRef, Dict *fontDict);
~GfxFontDict();
GfxFont *lookup(char *tag);
int getNumFonts() { return numFonts; }
GfxFont *getFont(int i) { return fonts[i]; }
private:
GfxFont **fonts; int numFonts; };
#endif