Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-11 10:26:09

0001 //========================================================================
0002 //
0003 // FoFiType1C.h
0004 //
0005 // Copyright 1999-2003 Glyph & Cog, LLC
0006 //
0007 //========================================================================
0008 
0009 //========================================================================
0010 //
0011 // Modified under the Poppler project - http://poppler.freedesktop.org
0012 //
0013 // All changes made under the Poppler project to this file are licensed
0014 // under GPL version 2 or later
0015 //
0016 // Copyright (C) 2006 Takashi Iwai <tiwai@suse.de>
0017 // Copyright (C) 2012 Thomas Freitag <Thomas.Freitag@alfa.de>
0018 // Copyright (C) 2018-2020 Albert Astals Cid <aacid@kde.org>
0019 // Copyright (C) 2022 Oliver Sander <oliver.sander@tu-dresden.de>
0020 //
0021 // To see a description of the changes please see the Changelog file that
0022 // came with your tarball or type make ChangeLog if you are building from git
0023 //
0024 //========================================================================
0025 
0026 #ifndef FOFITYPE1C_H
0027 #define FOFITYPE1C_H
0028 
0029 #include "FoFiBase.h"
0030 
0031 #include "poppler_private_export.h"
0032 
0033 #include <set>
0034 
0035 class GooString;
0036 
0037 //------------------------------------------------------------------------
0038 
0039 struct Type1CIndex
0040 {
0041     int pos; // absolute position in file
0042     int len; // length (number of entries)
0043     int offSize; // offset size
0044     int startPos; // position of start of index data - 1
0045     int endPos; // position one byte past end of the index
0046 };
0047 
0048 struct Type1CIndexVal
0049 {
0050     int pos; // absolute position in file
0051     int len; // length, in bytes
0052 };
0053 
0054 struct Type1CTopDict
0055 {
0056     int firstOp;
0057 
0058     int versionSID;
0059     int noticeSID;
0060     int copyrightSID;
0061     int fullNameSID;
0062     int familyNameSID;
0063     int weightSID;
0064     int isFixedPitch;
0065     double italicAngle;
0066     double underlinePosition;
0067     double underlineThickness;
0068     int paintType;
0069     int charstringType;
0070     double fontMatrix[6];
0071     bool hasFontMatrix; // CID fonts are allowed to put their
0072                         //   FontMatrix in the FD instead of the
0073                         //   top dict
0074     int uniqueID;
0075     double fontBBox[4];
0076     double strokeWidth;
0077     int charsetOffset;
0078     int encodingOffset;
0079     int charStringsOffset;
0080     int privateSize;
0081     int privateOffset;
0082 
0083     // CIDFont entries
0084     int registrySID;
0085     int orderingSID;
0086     int supplement;
0087     int fdArrayOffset;
0088     int fdSelectOffset;
0089 };
0090 
0091 #define type1CMaxBlueValues 14
0092 #define type1CMaxOtherBlues 10
0093 #define type1CMaxStemSnap 12
0094 
0095 struct Type1CPrivateDict
0096 {
0097     double fontMatrix[6];
0098     bool hasFontMatrix;
0099     int blueValues[type1CMaxBlueValues];
0100     int nBlueValues;
0101     int otherBlues[type1CMaxOtherBlues];
0102     int nOtherBlues;
0103     int familyBlues[type1CMaxBlueValues];
0104     int nFamilyBlues;
0105     int familyOtherBlues[type1CMaxOtherBlues];
0106     int nFamilyOtherBlues;
0107     double blueScale;
0108     int blueShift;
0109     int blueFuzz;
0110     double stdHW;
0111     bool hasStdHW;
0112     double stdVW;
0113     bool hasStdVW;
0114     double stemSnapH[type1CMaxStemSnap];
0115     int nStemSnapH;
0116     double stemSnapV[type1CMaxStemSnap];
0117     int nStemSnapV;
0118     bool forceBold;
0119     bool hasForceBold;
0120     double forceBoldThreshold;
0121     int languageGroup;
0122     double expansionFactor;
0123     int initialRandomSeed;
0124     int subrsOffset;
0125     double defaultWidthX;
0126     bool defaultWidthXFP;
0127     double nominalWidthX;
0128     bool nominalWidthXFP;
0129 };
0130 
0131 struct Type1COp
0132 {
0133     bool isNum = true; // true -> number, false -> operator
0134     bool isFP = false; // true -> floating point number, false -> int
0135     union {
0136         double num = 0; // if num is true
0137         int op; // if num is false
0138     };
0139 };
0140 
0141 struct Type1CEexecBuf
0142 {
0143     FoFiOutputFunc outputFunc;
0144     void *outputStream;
0145     bool ascii; // ASCII encoding?
0146     unsigned short r1; // eexec encryption key
0147     int line; // number of eexec chars left on current line
0148 };
0149 
0150 //------------------------------------------------------------------------
0151 // FoFiType1C
0152 //------------------------------------------------------------------------
0153 
0154 class POPPLER_PRIVATE_EXPORT FoFiType1C : public FoFiBase
0155 {
0156 public:
0157     // Create a FoFiType1C object from a memory buffer.
0158     static FoFiType1C *make(const unsigned char *fileA, int lenA);
0159 
0160     // Create a FoFiType1C object from a file on disk.
0161     static FoFiType1C *load(const char *fileName);
0162 
0163     ~FoFiType1C() override;
0164 
0165     // Return the font name.
0166     const char *getName() const;
0167 
0168     // Return the encoding, as an array of 256 names (any of which may
0169     // be NULL).  This is only useful with 8-bit fonts.
0170     char **getEncoding() const;
0171 
0172     // Get the glyph names.
0173     int getNumGlyphs() const { return nGlyphs; }
0174     GooString *getGlyphName(int gid) const;
0175 
0176     // Return the mapping from CIDs to GIDs, and return the number of
0177     // CIDs in *<nCIDs>.  This is only useful for CID fonts.
0178     int *getCIDToGIDMap(int *nCIDs) const;
0179 
0180     // Return the font matrix as an array of six numbers.
0181     void getFontMatrix(double *mat) const;
0182 
0183     // Convert to a Type 1 font, suitable for embedding in a PostScript
0184     // file.  This is only useful with 8-bit fonts.  If <newEncoding> is
0185     // not NULL, it will be used in place of the encoding in the Type 1C
0186     // font.  If <ascii> is true the eexec section will be hex-encoded,
0187     // otherwise it will be left as binary data.  If <psName> is non-NULL,
0188     // it will be used as the PostScript font name.
0189     void convertToType1(const char *psName, const char **newEncoding, bool ascii, FoFiOutputFunc outputFunc, void *outputStream);
0190 
0191     // Convert to a Type 0 CIDFont, suitable for embedding in a
0192     // PostScript file.  <psName> will be used as the PostScript font
0193     // name.  There are three cases for the CID-to-GID mapping:
0194     // (1) if <codeMap> is non-NULL, then it is the CID-to-GID mapping
0195     // (2) if <codeMap> is NULL and this is a CID CFF font, then the
0196     //     font's internal CID-to-GID mapping is used
0197     // (3) is <codeMap> is NULL and this is an 8-bit CFF font, then
0198     //     the identity CID-to-GID mapping is used
0199     void convertToCIDType0(const char *psName, const int *codeMap, int nCodes, FoFiOutputFunc outputFunc, void *outputStream);
0200 
0201     // Convert to a Type 0 (but non-CID) composite font, suitable for
0202     // embedding in a PostScript file.  <psName> will be used as the
0203     // PostScript font name.  There are three cases for the CID-to-GID
0204     // mapping:
0205     // (1) if <codeMap> is non-NULL, then it is the CID-to-GID mapping
0206     // (2) if <codeMap> is NULL and this is a CID CFF font, then the
0207     //     font's internal CID-to-GID mapping is used
0208     // (3) is <codeMap> is NULL and this is an 8-bit CFF font, then
0209     //     the identity CID-to-GID mapping is used
0210     void convertToType0(const char *psName, const int *codeMap, int nCodes, FoFiOutputFunc outputFunc, void *outputStream);
0211 
0212 private:
0213     FoFiType1C(const unsigned char *fileA, int lenA, bool freeFileDataA);
0214     void eexecCvtGlyph(Type1CEexecBuf *eb, const char *glyphName, int offset, int nBytes, const Type1CIndex *subrIdx, const Type1CPrivateDict *pDict);
0215     void cvtGlyph(int offset, int nBytes, GooString *charBuf, const Type1CIndex *subrIdx, const Type1CPrivateDict *pDict, bool top, std::set<int> &offsetBeingParsed);
0216     void cvtGlyphWidth(bool useOp, GooString *charBuf, const Type1CPrivateDict *pDict);
0217     void cvtNum(double x, bool isFP, GooString *charBuf) const;
0218     void eexecWrite(Type1CEexecBuf *eb, const char *s) const;
0219     void eexecWriteCharstring(Type1CEexecBuf *eb, const unsigned char *s, int n) const;
0220     void writePSString(const char *s, FoFiOutputFunc outputFunc, void *outputStream) const;
0221     bool parse();
0222     void readTopDict();
0223     void readFD(int offset, int length, Type1CPrivateDict *pDict);
0224     void readPrivateDict(int offset, int length, Type1CPrivateDict *pDict);
0225     void readFDSelect();
0226     void buildEncoding();
0227     bool readCharset();
0228     int getOp(int pos, bool charstring, bool *ok);
0229     int getDeltaIntArray(int *arr, int maxLen) const;
0230     int getDeltaFPArray(double *arr, int maxLen) const;
0231     void getIndex(int pos, Type1CIndex *idx, bool *ok) const;
0232     void getIndexVal(const Type1CIndex *idx, int i, Type1CIndexVal *val, bool *ok) const;
0233     char *getString(int sid, char *buf, bool *ok) const;
0234 
0235     GooString *name;
0236     char **encoding;
0237 
0238     Type1CIndex nameIdx;
0239     Type1CIndex topDictIdx;
0240     Type1CIndex stringIdx;
0241     Type1CIndex gsubrIdx;
0242     Type1CIndex charStringsIdx;
0243 
0244     Type1CTopDict topDict;
0245     Type1CPrivateDict *privateDicts;
0246 
0247     int nGlyphs;
0248     int nFDs;
0249     unsigned char *fdSelect;
0250     const unsigned short *charset;
0251     unsigned short charsetLength;
0252     int gsubrBias;
0253 
0254     bool parsedOk;
0255 
0256     Type1COp ops[49]; // operands and operator
0257     int nOps; // number of operands
0258     int nHints; // number of hints for the current glyph
0259     bool firstOp; // true if we haven't hit the first op yet
0260     bool openPath; // true if there is an unclosed path
0261 };
0262 
0263 #endif