X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;ds=sidebyside;f=pdf%2Fxpdf%2FGfxFont.h;h=62dfd0881ad24b9842f61e3cdf52d221ebb95825;hb=5932479cc8c371a385616b5909df558a091b7111;hp=30bcf1a572ddd958b841826ef277b2d94a449323;hpb=50e9d31c05e9ca11ad43cc570556094782c1b956;p=evince.git diff --git a/pdf/xpdf/GfxFont.h b/pdf/xpdf/GfxFont.h index 30bcf1a5..62dfd088 100644 --- a/pdf/xpdf/GfxFont.h +++ b/pdf/xpdf/GfxFont.h @@ -2,75 +2,73 @@ // // GfxFont.h // -// Copyright 1996 Derek B. Noonburg +// Copyright 1996-2003 Glyph & Cog, LLC // //======================================================================== #ifndef GFXFONT_H #define GFXFONT_H -#ifdef __GNUC__ +#include + +#ifdef USE_GCC_PRAGMAS #pragma interface #endif #include "gtypes.h" #include "GString.h" #include "Object.h" -#include "FontEncoding.h" +#include "CharTypes.h" class Dict; -struct BuiltinFont; - -//------------------------------------------------------------------------ -// GfxFontCharSet16 -//------------------------------------------------------------------------ - -enum GfxFontCharSet16 { - font16AdobeJapan12 // Adobe-Japan1-2 -}; +class CMap; +class CharCodeToUnicode; +class FoFiTrueType; +struct GfxFontCIDWidths; //------------------------------------------------------------------------ -// GfxFontEncoding16 +// GfxFontType //------------------------------------------------------------------------ -struct GfxFontEncoding16 { - int wMode; // writing mode (0=horizontal, 1=vertical) - Guchar codeLen[256]; // length of codes, in bytes, indexed by - // first byte of code - Gushort map1[256]; // one-byte code mapping: - // map1[code] --> 16-bit char selector - Gushort *map2; // two-byte code mapping - // map2[2*i] --> first code in range - // map2[2*i+1] --> 16-bit char selector - // for map2[2*i] - int map2Len; // length of map2 array (divided by 2) +enum GfxFontType { + //----- Gfx8BitFont + fontUnknownType, + fontType1, + fontType1C, + fontType3, + fontTrueType, + //----- GfxCIDFont + fontCIDType0, + fontCIDType0C, + fontCIDType2 }; //------------------------------------------------------------------------ -// GfxFontWidths16 +// GfxFontCIDWidths //------------------------------------------------------------------------ -struct GfxFontWidthExcep { - int first; // this record applies to - int last; // chars .. +struct GfxFontCIDWidthExcep { + CID first; // this record applies to + CID last; // CIDs .. double width; // char width }; -struct GfxFontWidthExcepV { - int first; // this record applies to - int last; // chars .. +struct GfxFontCIDWidthExcepV { + CID first; // this record applies to + CID last; // CIDs .. double height; // char height double vx, vy; // origin position }; -struct GfxFontWidths16 { +struct GfxFontCIDWidths { double defWidth; // default char width double defHeight; // default char height double defVY; // default origin position - GfxFontWidthExcep *exceps; // exceptions - int numExceps; // number of valid entries in exceps - GfxFontWidthExcepV *excepsV; // exceptions for vertical font - int numExcepsV; // number of valid entries in excepsV + GfxFontCIDWidthExcep *exceps; // exceptions + int nExceps; // number of valid entries in exceps + GfxFontCIDWidthExcepV * // exceptions for vertical font + excepsV; + int nExcepsV; // number of valid entries in excepsV }; //------------------------------------------------------------------------ @@ -83,41 +81,37 @@ struct GfxFontWidths16 { #define fontItalic (1 << 6) #define fontBold (1 << 18) -enum GfxFontType { - fontUnknownType, - fontType1, - fontType1C, - fontType3, - fontTrueType, - fontType0 -}; - class GfxFont { public: - // Constructor. - GfxFont(char *tag1, Ref id1, Dict *fontDict); + // Build a GfxFont object. + static GfxFont *makeFont(XRef *xref, char *tagA, Ref idA, Dict *fontDict); - // Destructor. - ~GfxFont(); + GfxFont(char *tagA, Ref idA, GString *nameA); + + virtual ~GfxFont(); + + GBool isOk() { return ok; } // Get font tag. GString *getTag() { return tag; } // Get font dictionary ID. - Ref getID() { return id; } + Ref *getID() { return &id; } // Does this font match the tag? - GBool matches(char *tag1) { return !tag->cmp(tag1); } + GBool matches(char *tagA) { return !tag->cmp(tagA); } // Get base font name. GString *getName() { return name; } + // Get the original font name (ignornig any munging that might have + // been done to map to a canonical Base-14 font name). + GString *getOrigName() { return origName; } + // Get font type. GfxFontType getType() { return type; } - - // Does this font use 16-bit characters? - GBool is16Bit() { return is16; } + virtual GBool isCIDFont() { return gFalse; } // Get embedded font ID, i.e., a ref for the font file stream. // Returns false if there is no embedded font. @@ -126,13 +120,11 @@ public: // Get the PostScript font name for the embedded font. Returns // NULL if there is no embedded font. - char *getEmbeddedFontName() - { return embFontName ? embFontName->getCString() : (char *)NULL; } + GString *getEmbeddedFontName() { return embFontName; } // Get the name of the external font file. Returns NULL if there // is no external font file. - char *getExtFontFile() - { return extFontFile ? extFontFile->getCString() : (char *)NULL; } + GString *getExtFontFile() { return extFontFile; } // Get font descriptor flags. GBool isFixedWidth() { return flags & fontFixedWidth; } @@ -141,68 +133,157 @@ public: GBool isItalic() { return flags & fontItalic; } GBool isBold() { return flags & fontBold; } - // Get width of a character or string. - double getWidth(Guchar c) { return widths[c]; } - double getWidth(GString *s); - - // Get character metrics for 16-bit font. - double getWidth16(int c); - double getHeight16(int c); - double getOriginX16(int c); - double getOriginY16(int c); - - // Return the encoding. - FontEncoding *getEncoding() { return encoding; } - - // Return the character name associated with . - char *getCharName(int code) { return encoding->getCharName(code); } - - // Return the code associated with . - int getCharCode(char *charName) { return encoding->getCharCode(charName); } + // Return the font matrix. + double *getFontMatrix() { return fontMat; } - // Return the 16-bit character set and encoding. - GfxFontCharSet16 getCharSet16() { return enc16.charSet; } - GfxFontEncoding16 *getEncoding16() { return enc16.enc; } + // Return the font bounding box. + double *getFontBBox() { return fontBBox; } - // Get the writing mode (0=horizontal, 1=vertical). - int getWMode16() { return enc16.enc->wMode; } + // Return the ascent and descent values. + double getAscent() { return ascent; } + double getDescent() { return descent; } - // Return the font matrix. - double *getFontMatrix() { return fontMat; } + // Return the writing mode (0=horizontal, 1=vertical). + virtual int getWMode() { return 0; } // Read an external or embedded font file into a buffer. char *readExtFontFile(int *len); - char *readEmbFontFile(int *len); - -private: - - void getEncAndWidths(Dict *fontDict, BuiltinFont *builtinFont); + char *readEmbFontFile(XRef *xref, int *len); + + // Get the next char from a string of bytes, returning the + // char , its Unicode mapping , its displacement vector + // (, ), and its origin offset vector (, ). + // is the number of entries available in , and is set to + // the number actually used. Returns the number of bytes used by + // the char code. + 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(); - void makeWidths(Dict *fontDict, FontEncoding *builtinEncoding, - Gushort *builtinWidths); - void getType0EncAndWidths(Dict *fontDict); GString *tag; // PDF font tag Ref id; // reference (used as unique ID) GString *name; // font name - int flags; // font descriptor flags + GString *origName; // original font name GfxFontType type; // type of font - GBool is16; // set if font uses 16-bit chars + int flags; // font descriptor flags GString *embFontName; // name of embedded font Ref embFontID; // ref to embedded font file stream GString *extFontFile; // external font file name - double fontMat[6]; // font matrix - union { - FontEncoding *encoding; // 8-bit font encoding - struct { - GfxFontCharSet16 charSet; // 16-bit character set - GfxFontEncoding16 *enc; // 16-bit encoding (CMap) - } enc16; - }; - union { - double widths[256]; // width of each char for 8-bit font - GfxFontWidths16 widths16; // char widths for 16-bit font - }; + double fontMat[6]; // font matrix (Type 3 only) + double fontBBox[4]; // font bounding box (Type 3 only) + double missingWidth; // "default" width + double ascent; // max height above baseline + double descent; // max depth below baseline + GBool ok; +}; + +//------------------------------------------------------------------------ +// Gfx8BitFont +//------------------------------------------------------------------------ + +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); + + // Return the encoding. + char **getEncoding() { return enc; } + + // Return the Unicode map. + CharCodeToUnicode *getToUnicode(); + + // Return the character name associated with . + char *getCharName(int code) { return enc[code]; } + + // Returns true if the PDF font specified an encoding. + GBool getHasEncoding() { return hasEncoding; } + + // Returns true if the PDF font specified MacRomanEncoding. + GBool getUsesMacRomanEnc() { return usesMacRomanEnc; } + + // Get width of a character. + double getWidth(Guchar c) { return widths[c]; } + + // Return a char code-to-GID mapping for the provided font file. + // (This is only useful for TrueType fonts.) + Gushort *getCodeToGIDMap(FoFiTrueType *ff); + + // Return the Type 3 CharProc dictionary, or NULL if none. + Dict *getCharProcs(); + + // Return the Type 3 CharProc for the character associated with . + Object *getCharProc(int code, Object *proc); + + // Return the Type 3 Resources dictionary, or NULL if none. + Dict *getResources(); + +private: + + char *enc[256]; // char code --> char name + char encFree[256]; // boolean for each char name: if set, + // the string is malloc'ed + CharCodeToUnicode *ctu; // char code --> Unicode + GBool hasEncoding; + GBool usesMacRomanEnc; + double widths[256]; // character widths + Object charProcs; // Type 3 CharProcs dictionary + Object resources; // Type 3 Resources dictionary +}; + +//------------------------------------------------------------------------ +// GfxCIDFont +//------------------------------------------------------------------------ + +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); + + // Return the writing mode (0=horizontal, 1=vertical). + virtual int getWMode(); + + // Return the Unicode map. + CharCodeToUnicode *getToUnicode(); + + // Get the collection name (-). + GString *getCollection(); + + // Return the CID-to-GID mapping table. These should only be called + // if type is fontCIDType2. + Gushort *getCIDToGID() { return cidToGID; } + int getCIDToGIDLen() { return cidToGIDLen; } + +private: + + CMap *cMap; // char code --> CID + CharCodeToUnicode *ctu; // CID --> Unicode + GfxFontCIDWidths widths; // character widths + Gushort *cidToGID; // CID --> GID mapping (for embedded + // TrueType fonts) + int cidToGIDLen; }; //------------------------------------------------------------------------ @@ -213,7 +294,7 @@ class GfxFontDict { public: // Build the font dictionary, given the PDF font dictionary. - GfxFontDict(Dict *fontDict); + GfxFontDict(XRef *xref, Ref *fontDictRef, Dict *fontDict); // Destructor. ~GfxFontDict();