1 //========================================================================
5 // Copyright 1999-2003 Glyph & Cog, LLC
7 //========================================================================
10 #define FOFITRUETYPE_H
14 #ifdef USE_GCC_PRAGMAS
26 //------------------------------------------------------------------------
28 //------------------------------------------------------------------------
30 class FoFiTrueType: public FoFiBase {
33 // Create a FoFiTrueType object from a memory buffer.
34 static FoFiTrueType *make(char *fileA, int lenA);
36 // Create a FoFiTrueType object from a file on disk.
37 static FoFiTrueType *load(char *fileName);
39 virtual ~FoFiTrueType();
41 // Return the number of cmaps defined by this font.
44 // Return the platform ID of the <i>th cmap.
45 int getCmapPlatform(int i);
47 // Return the encoding ID of the <i>th cmap.
48 int getCmapEncoding(int i);
50 // Return the index of the cmap for <platform>, <encoding>. Returns
51 // -1 if there is no corresponding cmap.
52 int findCmap(int platform, int encoding);
54 // Return the GID corresponding to <c> according to the <i>th cmap.
55 Gushort mapCodeToGID(int i, int c);
57 // Returns the GID corresponding to <name> according to the post
58 // table. Returns 0 if there is no mapping for <name> or if the
59 // font does not have a post table.
60 int mapNameToGID(char *name);
62 // Returns the least restrictive embedding licensing right (as
63 // defined by the TrueType spec):
64 // * 4: OS/2 table is missing or invalid
65 // * 3: installable embedding
66 // * 2: editable embedding
67 // * 1: preview & print embedding
68 // * 0: restricted license embedding
69 int getEmbeddingRights();
71 // Convert to a Type 42 font, suitable for embedding in a PostScript
72 // file. <psName> will be used as the PostScript font name (so we
73 // don't need to depend on the 'name' table in the font). The
74 // <encoding> array specifies the mapping from char codes to names.
75 // If <encoding> is NULL, the encoding is unknown or undefined. The
76 // <codeToGID> array specifies the mapping from char codes to GIDs.
77 void convertToType42(char *psName, char **encoding,
79 FoFiOutputFunc outputFunc, void *outputStream);
81 // Convert to a Type 2 CIDFont, suitable for embedding in a
82 // PostScript file. <psName> will be used as the PostScript font
83 // name (so we don't need to depend on the 'name' table in the
84 // font). The <cidMap> array maps CIDs to GIDs; it has <nCIDs>
86 void convertToCIDType2(char *psName, Gushort *cidMap, int nCIDs,
87 GBool needVerticalMetrics,
88 FoFiOutputFunc outputFunc, void *outputStream);
90 // Convert to a Type 0 (but non-CID) composite font, suitable for
91 // embedding in a PostScript file. <psName> will be used as the
92 // PostScript font name (so we don't need to depend on the 'name'
93 // table in the font). The <cidMap> array maps CIDs to GIDs; it has
95 void convertToType0(char *psName, Gushort *cidMap, int nCIDs,
96 GBool needVerticalMetrics,
97 FoFiOutputFunc outputFunc, void *outputStream);
99 // Write a clean TTF file, filling in missing tables and correcting
100 // various other errors. If <name> is non-NULL, the font is renamed
101 // to <name>. If <codeToGID> is non-NULL, the font is re-encoded,
102 // using a Windows Unicode cmap. If <name> is NULL and the font is
103 // complete and correct, it will be written unmodified.
104 void writeTTF(FoFiOutputFunc outputFunc, void *outputStream,
105 char *name = NULL, Gushort *codeToGID = NULL);
109 FoFiTrueType(char *fileA, int lenA, GBool freeFileDataA);
110 void cvtEncoding(char **encoding,
111 FoFiOutputFunc outputFunc,
113 void cvtCharStrings(char **encoding,
115 FoFiOutputFunc outputFunc,
117 void cvtSfnts(FoFiOutputFunc outputFunc,
118 void *outputStream, GString *name,
119 GBool needVerticalMetrics);
120 void dumpString(Guchar *s, int length,
121 FoFiOutputFunc outputFunc,
123 Guint computeTableChecksum(Guchar *data, int length);
125 void readPostTable();
126 int seekTable(char *tag);
128 TrueTypeTable *tables;