|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef GFXFONT_H |
|
#define GFXFONT_H |
|
|
|
#include <memory> |
|
#include <optional> |
|
|
|
#include "goo/GooString.h" |
|
#include "Object.h" |
|
#include "CharTypes.h" |
|
#include "poppler_private_export.h" |
|
|
|
class Dict; |
|
class CMap; |
|
class CharCodeToUnicode; |
|
class FoFiTrueType; |
|
class PSOutputDev; |
|
struct GfxFontCIDWidths; |
|
struct Base14FontMapEntry; |
|
class FNVHash; |
|
|
|
|
|
|
|
|
|
|
|
enum GfxFontType |
|
{ |
|
|
|
fontUnknownType, |
|
fontType1, |
|
fontType1C, |
|
fontType1COT, |
|
fontType3, |
|
fontTrueType, |
|
fontTrueTypeOT, |
|
|
|
fontCIDType0, |
|
fontCIDType0C, |
|
fontCIDType0COT, |
|
fontCIDType2, |
|
fontCIDType2OT |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
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; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
enum GfxFontLocType |
|
{ |
|
gfxFontLocEmbedded, |
|
gfxFontLocExternal, |
|
gfxFontLocResident |
|
}; |
|
|
|
class POPPLER_PRIVATE_EXPORT GfxFontLoc |
|
{ |
|
public: |
|
GfxFontLoc(); |
|
~GfxFontLoc(); |
|
|
|
GfxFontLoc(const GfxFontLoc &) = delete; |
|
GfxFontLoc(GfxFontLoc &&) noexcept; |
|
GfxFontLoc &operator=(const GfxFontLoc &) = delete; |
|
GfxFontLoc &operator=(GfxFontLoc &&other) noexcept; |
|
|
|
|
|
|
|
void setPath(GooString *pathA); |
|
const GooString *pathAsGooString() const; |
|
|
|
GfxFontLocType locType; |
|
GfxFontType fontType; |
|
Ref embFontID; |
|
|
|
std::string path; |
|
|
|
|
|
|
|
int fontNum; |
|
|
|
int substIdx; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
#define fontFixedWidth (1 << 0) |
|
#define fontSerif (1 << 1) |
|
#define fontSymbolic (1 << 2) |
|
#define fontItalic (1 << 6) |
|
#define fontBold (1 << 18) |
|
|
|
class POPPLER_PRIVATE_EXPORT GfxFont |
|
{ |
|
public: |
|
enum Stretch |
|
{ |
|
StretchNotDefined, |
|
UltraCondensed, |
|
ExtraCondensed, |
|
Condensed, |
|
SemiCondensed, |
|
Normal, |
|
SemiExpanded, |
|
Expanded, |
|
ExtraExpanded, |
|
UltraExpanded |
|
}; |
|
|
|
enum Weight |
|
{ |
|
WeightNotDefined, |
|
W100, |
|
W200, |
|
W300, |
|
W400, |
|
W500, |
|
W600, |
|
W700, |
|
W800, |
|
W900 |
|
}; |
|
|
|
|
|
static std::unique_ptr<GfxFont> makeFont(XRef *xref, const char *tagA, Ref idA, Dict *fontDict); |
|
|
|
GfxFont(const GfxFont &) = delete; |
|
GfxFont &operator=(const GfxFont &other) = delete; |
|
virtual ~GfxFont(); |
|
|
|
bool isOk() const { return ok; } |
|
|
|
|
|
const std::string &getTag() const { return tag; } |
|
|
|
|
|
const Ref *getID() const { return &id; } |
|
|
|
|
|
bool matches(const char *tagA) const { return tag == tagA; } |
|
|
|
|
|
GooString *getFamily() const { return family; } |
|
|
|
|
|
Stretch getStretch() const { return stretch; } |
|
|
|
|
|
Weight getWeight() const { return weight; } |
|
|
|
|
|
|
|
const std::optional<std::string> &getName() const { return name; } |
|
|
|
bool isSubset() const; |
|
|
|
|
|
std::string getNameWithoutSubsetTag() const; |
|
|
|
|
|
GfxFontType getType() const { return type; } |
|
virtual bool isCIDFont() const { return false; } |
|
|
|
|
|
|
|
bool getEmbeddedFontID(Ref *embID) const |
|
{ |
|
*embID = embFontID; |
|
return embFontID != Ref::INVALID(); |
|
} |
|
|
|
|
|
|
|
bool invalidateEmbeddedFont() |
|
{ |
|
if (embFontID != Ref::INVALID()) { |
|
embFontID = Ref::INVALID(); |
|
return true; |
|
} |
|
return false; |
|
} |
|
|
|
|
|
|
|
const GooString *getEmbeddedFontName() const { return embFontName; } |
|
|
|
|
|
int getFlags() const { return flags; } |
|
bool isFixedWidth() const { return flags & fontFixedWidth; } |
|
bool isSerif() const { return flags & fontSerif; } |
|
bool isSymbolic() const { return flags & fontSymbolic; } |
|
bool isItalic() const { return flags & fontItalic; } |
|
bool isBold() const { return flags & fontBold; } |
|
|
|
|
|
virtual const CharCodeToUnicode *getToUnicode() const = 0; |
|
|
|
|
|
const double *getFontMatrix() const { return fontMat; } |
|
|
|
|
|
const double *getFontBBox() const { return fontBBox; } |
|
|
|
|
|
double getAscent() const { return ascent; } |
|
double getDescent() const { return descent; } |
|
|
|
|
|
virtual int getWMode() const { return 0; } |
|
|
|
|
|
|
|
|
|
std::optional<GfxFontLoc> locateFont(XRef *xref, PSOutputDev *ps, GooString *substituteFontName = nullptr); |
|
|
|
|
|
std::optional<std::vector<unsigned char>> readEmbFontFile(XRef *xref); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
virtual int getNextChar(const char *s, int len, CharCode *code, Unicode const **u, int *uLen, double *dx, double *dy, double *ox, double *oy) const = 0; |
|
|
|
|
|
bool hasToUnicodeCMap() const { return hasToUnicode; } |
|
|
|
|
|
const std::string &getEncodingName() const { return encodingName; } |
|
|
|
|
|
|
|
|
|
static const char *getAlternateName(const char *name); |
|
|
|
protected: |
|
GfxFont(const char *tagA, Ref idA, std::optional<std::string> &&nameA, GfxFontType typeA, Ref embFontIDA); |
|
|
|
static GfxFontType getFontType(XRef *xref, Dict *fontDict, Ref *embID); |
|
void readFontDescriptor(XRef *xref, Dict *fontDict); |
|
CharCodeToUnicode *readToUnicodeCMap(Dict *fontDict, int nBits, CharCodeToUnicode *ctu); |
|
static std::optional<GfxFontLoc> getExternalFont(GooString *path, bool cid); |
|
|
|
const std::string tag; |
|
const Ref id; |
|
std::optional<std::string> name; |
|
GooString *family; |
|
Stretch stretch; |
|
Weight weight; |
|
const GfxFontType type; |
|
int flags; |
|
GooString *embFontName; |
|
Ref embFontID; |
|
double fontMat[6]; |
|
double fontBBox[4]; |
|
double missingWidth; |
|
double ascent; |
|
double descent; |
|
bool ok; |
|
bool hasToUnicode; |
|
std::string encodingName; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
class POPPLER_PRIVATE_EXPORT Gfx8BitFont : public GfxFont |
|
{ |
|
public: |
|
Gfx8BitFont(XRef *xref, const char *tagA, Ref idA, std::optional<std::string> &&nameA, GfxFontType typeA, Ref embFontIDA, Dict *fontDict); |
|
|
|
int getNextChar(const char *s, int len, CharCode *code, Unicode const **u, int *uLen, double *dx, double *dy, double *ox, double *oy) const override; |
|
|
|
|
|
char **getEncoding() { return enc; } |
|
|
|
|
|
const CharCodeToUnicode *getToUnicode() const override; |
|
|
|
|
|
const char *getCharName(int code) const { return enc[code]; } |
|
|
|
|
|
bool getHasEncoding() const { return hasEncoding; } |
|
|
|
|
|
bool getUsesMacRomanEnc() const { return usesMacRomanEnc; } |
|
|
|
|
|
double getWidth(unsigned char c) const { return widths[c]; } |
|
|
|
|
|
|
|
int *getCodeToGIDMap(FoFiTrueType *ff); |
|
|
|
|
|
Dict *getCharProcs(); |
|
|
|
|
|
Object getCharProc(int code); |
|
Object getCharProcNF(int code); |
|
|
|
|
|
Dict *getResources(); |
|
|
|
private: |
|
~Gfx8BitFont() override; |
|
|
|
const Base14FontMapEntry *base14; |
|
char *enc[256]; |
|
char encFree[256]; |
|
|
|
CharCodeToUnicode *ctu; |
|
bool hasEncoding; |
|
bool usesMacRomanEnc; |
|
double widths[256]; |
|
Object charProcs; |
|
Object resources; |
|
|
|
friend class GfxFont; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
class POPPLER_PRIVATE_EXPORT GfxCIDFont : public GfxFont |
|
{ |
|
public: |
|
GfxCIDFont(XRef *xref, const char *tagA, Ref idA, std::optional<std::string> &&nameA, GfxFontType typeA, Ref embFontIDA, Dict *fontDict); |
|
|
|
bool isCIDFont() const override { return true; } |
|
|
|
int getNextChar(const char *s, int len, CharCode *code, Unicode const **u, int *uLen, double *dx, double *dy, double *ox, double *oy) const override; |
|
|
|
|
|
int getWMode() const override; |
|
|
|
|
|
const CharCodeToUnicode *getToUnicode() const override; |
|
|
|
|
|
const GooString *getCollection() const; |
|
|
|
|
|
|
|
int *getCIDToGID() const { return cidToGID; } |
|
unsigned int getCIDToGIDLen() const { return cidToGIDLen; } |
|
|
|
int *getCodeToGIDMap(FoFiTrueType *ff, int *codeToGIDLen); |
|
|
|
double getWidth(char *s, int len) const; |
|
|
|
private: |
|
~GfxCIDFont() override; |
|
|
|
int mapCodeToGID(FoFiTrueType *ff, int cmapi, Unicode unicode, bool wmode); |
|
double getWidth(CID cid) const; |
|
|
|
GooString *collection; |
|
std::shared_ptr<CMap> cMap; |
|
CharCodeToUnicode *ctu; |
|
bool ctuUsesCharCode; |
|
|
|
GfxFontCIDWidths widths; |
|
int *cidToGID; |
|
|
|
unsigned int cidToGIDLen; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
class GfxFontDict |
|
{ |
|
public: |
|
|
|
GfxFontDict(XRef *xref, Ref *fontDictRef, Dict *fontDict); |
|
|
|
GfxFontDict(const GfxFontDict &) = delete; |
|
GfxFontDict &operator=(const GfxFontDict &) = delete; |
|
|
|
|
|
std::shared_ptr<GfxFont> lookup(const char *tag) const; |
|
|
|
|
|
int getNumFonts() const { return fonts.size(); } |
|
const std::shared_ptr<GfxFont> &getFont(int i) const { return fonts[i]; } |
|
|
|
private: |
|
int hashFontObject(Object *obj); |
|
void hashFontObject1(const Object *obj, FNVHash *h); |
|
|
|
std::vector<std::shared_ptr<GfxFont>> fonts; |
|
}; |
|
|
|
#endif |
|
|