1 | //======================================================================== |
2 | // |
3 | // FoFiTrueType.h |
4 | // |
5 | // Copyright 1999-2003 Glyph & Cog, LLC |
6 | // |
7 | //======================================================================== |
8 | |
9 | //======================================================================== |
10 | // |
11 | // Modified under the Poppler project - http://poppler.freedesktop.org |
12 | // |
13 | // All changes made under the Poppler project to this file are licensed |
14 | // under GPL version 2 or later |
15 | // |
16 | // Copyright (C) 2006 Takashi Iwai <tiwai@suse.de> |
17 | // Copyright (C) 2007 Koji Otani <sho@bbr.jp> |
18 | // Copyright (C) 2011, 2012, 2018-2020 Albert Astals Cid <aacid@kde.org> |
19 | // Copyright (C) 2012 Suzuki Toshiya <mpsuzuki@hiroshima-u.ac.jp> |
20 | // Copyright (C) 2016 William Bader <williambader@hotmail.com> |
21 | // Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de> |
22 | // Copyright (C) 2022 Oliver Sander <oliver.sander@tu-dresden.de> |
23 | // |
24 | // To see a description of the changes please see the Changelog file that |
25 | // came with your tarball or type make ChangeLog if you are building from git |
26 | // |
27 | //======================================================================== |
28 | |
29 | #ifndef FOFITRUETYPE_H |
30 | #define FOFITRUETYPE_H |
31 | |
32 | #include <cstddef> |
33 | #include <memory> |
34 | #include <unordered_map> |
35 | #include <string> |
36 | #include "FoFiBase.h" |
37 | #include "poppler_private_export.h" |
38 | |
39 | class GooString; |
40 | struct TrueTypeTable; |
41 | struct TrueTypeCmap; |
42 | |
43 | //------------------------------------------------------------------------ |
44 | // FoFiTrueType |
45 | //------------------------------------------------------------------------ |
46 | |
47 | class POPPLER_PRIVATE_EXPORT FoFiTrueType : public FoFiBase |
48 | { |
49 | public: |
50 | // Create a FoFiTrueType object from a memory buffer. |
51 | static std::unique_ptr<FoFiTrueType> make(const unsigned char *fileA, int lenA, int faceIndexA = 0); |
52 | |
53 | // Create a FoFiTrueType object from a file on disk. |
54 | static std::unique_ptr<FoFiTrueType> load(const char *fileName, int faceIndexA = 0); |
55 | |
56 | ~FoFiTrueType() override; |
57 | |
58 | // Returns true if this an OpenType font containing CFF data, false |
59 | // if it's a TrueType font (or OpenType font with TrueType data). |
60 | bool isOpenTypeCFF() const { return openTypeCFF; } |
61 | |
62 | // Return the number of cmaps defined by this font. |
63 | int getNumCmaps() const; |
64 | |
65 | // Return the platform ID of the <i>th cmap. |
66 | int getCmapPlatform(int i) const; |
67 | |
68 | // Return the encoding ID of the <i>th cmap. |
69 | int getCmapEncoding(int i) const; |
70 | |
71 | // Return the index of the cmap for <platform>, <encoding>. Returns |
72 | // -1 if there is no corresponding cmap. |
73 | int findCmap(int platform, int encoding) const; |
74 | |
75 | // Return the GID corresponding to <c> according to the <i>th cmap. |
76 | int mapCodeToGID(int i, unsigned int c) const; |
77 | |
78 | // map gid to vertical glyph gid if exist. |
79 | // if not exist return original gid |
80 | unsigned int mapToVertGID(unsigned int orgGID); |
81 | |
82 | // Returns the GID corresponding to <name> according to the post |
83 | // table. Returns 0 if there is no mapping for <name> or if the |
84 | // font does not have a post table. |
85 | int mapNameToGID(const char *name) const; |
86 | |
87 | // Return the mapping from CIDs to GIDs, and return the number of |
88 | // CIDs in *<nCIDs>. This is only useful for CID fonts. (Only |
89 | // useful for OpenType CFF fonts.) |
90 | int *getCIDToGIDMap(int *nCIDs) const; |
91 | |
92 | // Returns the least restrictive embedding licensing right (as |
93 | // defined by the TrueType spec): |
94 | // * 4: OS/2 table is missing or invalid |
95 | // * 3: installable embedding |
96 | // * 2: editable embedding |
97 | // * 1: preview & print embedding |
98 | // * 0: restricted license embedding |
99 | int getEmbeddingRights() const; |
100 | |
101 | // Return the font matrix as an array of six numbers. (Only useful |
102 | // for OpenType CFF fonts.) |
103 | void getFontMatrix(double *mat) const; |
104 | |
105 | // Convert to a Type 42 font, suitable for embedding in a PostScript |
106 | // file. <psName> will be used as the PostScript font name (so we |
107 | // don't need to depend on the 'name' table in the font). The |
108 | // <encoding> array specifies the mapping from char codes to names. |
109 | // If <encoding> is NULL, the encoding is unknown or undefined. The |
110 | // <codeToGID> array specifies the mapping from char codes to GIDs. |
111 | // (Not useful for OpenType CFF fonts.) |
112 | void convertToType42(const char *psName, char **encoding, int *codeToGID, FoFiOutputFunc outputFunc, void *outputStream) const; |
113 | |
114 | // Convert to a Type 1 font, suitable for embedding in a PostScript |
115 | // file. This is only useful with 8-bit fonts. If <newEncoding> is |
116 | // not NULL, it will be used in place of the encoding in the Type 1C |
117 | // font. If <ascii> is true the eexec section will be hex-encoded, |
118 | // otherwise it will be left as binary data. If <psName> is |
119 | // non-NULL, it will be used as the PostScript font name. (Only |
120 | // useful for OpenType CFF fonts.) |
121 | void convertToType1(const char *psName, const char **newEncoding, bool ascii, FoFiOutputFunc outputFunc, void *outputStream) const; |
122 | |
123 | // Convert to a Type 2 CIDFont, suitable for embedding in a |
124 | // PostScript file. <psName> will be used as the PostScript font |
125 | // name (so we don't need to depend on the 'name' table in the |
126 | // font). The <cidMap> array maps CIDs to GIDs; it has <nCIDs> |
127 | // entries. (Not useful for OpenType CFF fonts.) |
128 | void convertToCIDType2(const char *psName, const int *cidMap, int nCIDs, bool needVerticalMetrics, FoFiOutputFunc outputFunc, void *outputStream) const; |
129 | |
130 | // Convert to a Type 0 CIDFont, suitable for embedding in a |
131 | // PostScript file. <psName> will be used as the PostScript font |
132 | // name. (Only useful for OpenType CFF fonts.) |
133 | void convertToCIDType0(const char *psName, int *cidMap, int nCIDs, FoFiOutputFunc outputFunc, void *outputStream) const; |
134 | |
135 | // Convert to a Type 0 (but non-CID) composite font, suitable for |
136 | // embedding in a PostScript file. <psName> will be used as the |
137 | // PostScript font name (so we don't need to depend on the 'name' |
138 | // table in the font). The <cidMap> array maps CIDs to GIDs; it has |
139 | // <nCIDs> entries. (Not useful for OpenType CFF fonts.) |
140 | void convertToType0(const char *psName, int *cidMap, int nCIDs, bool needVerticalMetrics, int *maxValidGlyph, FoFiOutputFunc outputFunc, void *outputStream) const; |
141 | |
142 | // Convert to a Type 0 (but non-CID) composite font, suitable for |
143 | // embedding in a PostScript file. <psName> will be used as the |
144 | // PostScript font name. (Only useful for OpenType CFF fonts.) |
145 | void convertToType0(const char *psName, int *cidMap, int nCIDs, FoFiOutputFunc outputFunc, void *outputStream) const; |
146 | |
147 | // Returns a pointer to the CFF font embedded in this OpenType font. |
148 | // If successful, sets *<start> and *<length>, and returns true. |
149 | // Otherwise returns false. (Only useful for OpenType CFF fonts). |
150 | bool getCFFBlock(char **start, int *length) const; |
151 | |
152 | // setup vert/vrt2 GSUB for default lang |
153 | int setupGSUB(const char *scriptName); |
154 | |
155 | // setup vert/vrt2 GSUB for specified lang |
156 | int setupGSUB(const char *scriptName, const char *languageName); |
157 | |
158 | private: |
159 | FoFiTrueType(const unsigned char *fileA, int lenA, bool freeFileDataA, int faceIndexA); |
160 | void cvtEncoding(char **encoding, FoFiOutputFunc outputFunc, void *outputStream) const; |
161 | void cvtCharStrings(char **encoding, const int *codeToGID, FoFiOutputFunc outputFunc, void *outputStream) const; |
162 | void cvtSfnts(FoFiOutputFunc outputFunc, void *outputStream, const GooString *name, bool needVerticalMetrics, int *maxUsedGlyph) const; |
163 | void dumpString(const unsigned char *s, int length, FoFiOutputFunc outputFunc, void *outputStream) const; |
164 | unsigned int computeTableChecksum(const unsigned char *data, int length) const; |
165 | void parse(); |
166 | void readPostTable(); |
167 | int seekTable(const char *tag) const; |
168 | unsigned int charToTag(const char *tagName); |
169 | unsigned int doMapToVertGID(unsigned int orgGID); |
170 | unsigned int scanLookupList(unsigned int listIndex, unsigned int orgGID); |
171 | unsigned int scanLookupSubTable(unsigned int subTable, unsigned int orgGID); |
172 | int checkGIDInCoverage(unsigned int coverage, unsigned int orgGID); |
173 | |
174 | TrueTypeTable *tables; |
175 | int nTables; |
176 | TrueTypeCmap *cmaps; |
177 | int nCmaps; |
178 | int nGlyphs; |
179 | int locaFmt; |
180 | int bbox[4]; |
181 | std::unordered_map<std::string, int> nameToGID; |
182 | bool openTypeCFF; |
183 | |
184 | bool parsedOk; |
185 | int faceIndex; |
186 | unsigned int gsubFeatureTable; |
187 | unsigned int gsubLookupList; |
188 | }; |
189 | |
190 | #endif |
191 | |