X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=pdf%2Fxpdf%2FFontFile.h;h=a71653c2646a898d1742561a1e2a94e92e901e6d;hb=884f739665dc56e66f51e104350f2affd33f2dd8;hp=ec625ef28bd75a3e4222b7d0a300f103e92494a7;hpb=d99fb4f4acd14fcdbda968abd907547dcc7af40c;p=evince.git diff --git a/pdf/xpdf/FontFile.h b/pdf/xpdf/FontFile.h index ec625ef2..a71653c2 100644 --- a/pdf/xpdf/FontFile.h +++ b/pdf/xpdf/FontFile.h @@ -2,21 +2,29 @@ // // FontFile.h // -// Copyright 1999 Derek B. Noonburg +// Copyright 1999-2003 Glyph & Cog, LLC // //======================================================================== #ifndef FONTFILE_H #define FONTFILE_H -#ifdef __GNUC__ +#include + +#ifdef USE_GCC_PRAGMAS #pragma interface #endif #include #include "gtypes.h" #include "GString.h" -#include "FontEncoding.h" +#include "CharTypes.h" + +class CharCodeToUnicode; + +//------------------------------------------------------------------------ + +typedef void (*FontFileOutputFunc)(void *stream, char *data, int len); //------------------------------------------------------------------------ // FontFile @@ -32,10 +40,9 @@ public: // Returns NULL if no name is available. virtual char *getName() = 0; - // Returns the custom font encoding, or NULL if the encoding is - // not available. If is set, the caller of this function - // will be responsible for freeing the encoding object. - virtual FontEncoding *getEncoding(GBool taken) = 0; + // Returns the custom font encoding, or NULL if the encoding is not + // available. + virtual char **getEncoding() = 0; }; //------------------------------------------------------------------------ @@ -48,63 +55,91 @@ public: Type1FontFile(char *file, int len); virtual ~Type1FontFile(); virtual char *getName() { return name; } - virtual FontEncoding *getEncoding(GBool taken); + virtual char **getEncoding() { return encoding; } private: char *name; - FontEncoding *encoding; - GBool freeEnc; + char **encoding; }; //------------------------------------------------------------------------ // Type1CFontFile //------------------------------------------------------------------------ +struct Type1CTopDict; +struct Type1CPrivateDict; + class Type1CFontFile: public FontFile { public: - Type1CFontFile(char *file, int len); + Type1CFontFile(char *fileA, int lenA); virtual ~Type1CFontFile(); - virtual char *getName() { return name; } - virtual FontEncoding *getEncoding(GBool taken); + GBool isOk() { return ok; } -private: + virtual char *getName(); + virtual char **getEncoding(); - char *name; - FontEncoding *encoding; - GBool freeEnc; -}; - -//------------------------------------------------------------------------ -// Type1CFontConverter -//------------------------------------------------------------------------ + // Convert to a Type 1 font, suitable for embedding in a PostScript + // file. The name will be used as the PostScript font name. + void convertToType1(FontFileOutputFunc outputFuncA, void *outputStreamA); -class Type1CFontConverter { -public: + // Convert to a Type 0 CIDFont, suitable for embedding in a + // PostScript file. The name will be used as the PostScript font + // name. + void convertToCIDType0(char *psName, + FontFileOutputFunc outputFuncA, void *outputStreamA); - Type1CFontConverter(char *file, int len, FILE *out); - ~Type1CFontConverter(); - void convert(); + // Convert to a Type 0 (but non-CID) composite font, suitable for + // embedding in a PostScript file. The name will be used as the + // PostScript font name. + void convertToType0(char *psName, + FontFileOutputFunc outputFuncA, void *outputStreamA); private: + void readEncoding(); + void readTopDict(Type1CTopDict *dict); + void readPrivateDict(Type1CPrivateDict *privateDict, + int offset, int size); + Gushort *readCharset(int charset, int nGlyphs); void eexecWrite(char *s); - void cvtGlyph(char *name, Guchar *s, int n); + void eexecCvtGlyph(char *glyphName, int pos, int n); + void cvtGlyph(int pos, int n, GBool top); void cvtGlyphWidth(GBool useOp); - void eexecDumpNum(double x, GBool fp); - void eexecDumpOp1(int op); - void eexecDumpOp2(int op); + void eexecDumpNum(double x, GBool fpA); + void eexecDumpOp1(int opA); + void eexecDumpOp2(int opA); void eexecWriteCharstring(Guchar *s, int n); - void getDeltaInt(char *buf, char *name, double *op, int n); - void getDeltaReal(char *buf, char *name, double *op, int n); - - char *file; + void getDeltaInt(char *buf, char *key, double *opA, int n); + void getDeltaReal(char *buf, char *key, double *opA, int n); + int getIndexLen(int indexPos); + int getIndexValPos(int indexPos, int i, int *valLen); + int getIndexEnd(int indexPos); + Guint getWord(int pos, int size); + double getNum(int *pos, GBool *fp); + char *getString(int sid, char *buf); + + Guchar *file; int len; - FILE *out; + + GString *name; + char **encoding; + + int topDictIdxPos; + int stringIdxPos; + int gsubrIdxPos; + int subrIdxPos; + int gsubrBias; + int subrBias; + + FontFileOutputFunc outputFunc; + void *outputStream; double op[48]; // operands GBool fp[48]; // true if operand is fixed point int nOps; // number of operands + int nHints; // number of hints for the current glyph + GBool firstOp; // true if we haven't hit the first op yet double defaultWidthX; // default glyph width double nominalWidthX; // nominal glyph width GBool defaultWidthXFP; // true if defaultWidthX is fixed point @@ -112,6 +147,92 @@ private: Gushort r1; // eexec encryption key GString *charBuf; // charstring output buffer int line; // number of eexec chars on current line + + GBool ok; +}; + +//------------------------------------------------------------------------ +// TrueTypeFontFile +//------------------------------------------------------------------------ + +struct TTFontTableHdr; + +class TrueTypeFontFile: public FontFile { +public: + + TrueTypeFontFile(char *fileA, int lenA); + ~TrueTypeFontFile(); + + // This always returns NULL, since it's probably better to trust the + // font name in the PDF file rather than the one in the TrueType + // font file. + virtual char *getName(); + + virtual char **getEncoding(); + + // Convert to a Type 42 font, suitable for embedding in a PostScript + // file. The name will be used as the PostScript font name (so we + // don't need to depend on the 'name' table in the font). The + // encoding is needed because the PDF Font object can modify the + // encoding. + void convertToType42(char *name, char **encodingA, + CharCodeToUnicode *toUnicode, + GBool pdfFontHasEncoding, + GBool pdfFontIsSymbolic, + FontFileOutputFunc outputFunc, void *outputStream); + + // Convert to a Type 2 CIDFont, suitable for embedding in a + // PostScript file. The name will be used as the PostScript font + // name (so we don't need to depend on the 'name' table in the + // font). + void convertToCIDType2(char *name, Gushort *cidMap, int nCIDs, + FontFileOutputFunc outputFunc, void *outputStream); + + // Convert to a Type 0 (but non-CID) composite font, suitable for + // embedding in a PostScript file. The name will be used as the + // PostScript font name (so we don't need to depend on the 'name' + // table in the font). + void convertToType0(char *name, Gushort *cidMap, int nCIDs, + FontFileOutputFunc outputFunc, void *outputStream); + + // Write a TTF file, filling in any missing tables that are required + // by the TrueType spec. If the font already has all the required + // tables, it will be written unmodified. + void writeTTF(FILE *out); + +private: + + char *file; + int len; + + char **encoding; + + TTFontTableHdr *tableHdrs; + int nTables; + int bbox[4]; + int locaFmt; + int nGlyphs; + GBool mungedCmapSize; + + int getByte(int pos); + int getChar(int pos); + int getUShort(int pos); + int getShort(int pos); + Guint getULong(int pos); + double getFixed(int pos); + int seekTable(char *tag); + int seekTableIdx(char *tag); + void cvtEncoding(char **encodingA, GBool pdfFontHasEncoding, + FontFileOutputFunc outputFunc, void *outputStream); + void cvtCharStrings(char **encodingA, CharCodeToUnicode *toUnicode, + GBool pdfFontHasEncoding, GBool pdfFontIsSymbolic, + FontFileOutputFunc outputFunc, void *outputStream); + int getCmapEntry(int cmapFmt, int pos, int code); + void cvtSfnts(FontFileOutputFunc outputFunc, void *outputStream, + GString *name); + void dumpString(char *s, int length, + FontFileOutputFunc outputFunc, void *outputStream); + Guint computeTableChecksum(char *data, int length); }; #endif