2 * Copyright © 2002, 2003 Sun Microsystems, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of Sun Microsystems, Inc. nor the names of
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
20 * This software is provided "AS IS," without a warranty of any kind.
22 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
23 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
24 * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
25 * SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES OR
26 * LIABILITIES SUFFERED BY LICENSEE AS A RESULT OF OR RELATING TO USE,
27 * MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR ITS DERIVATIVES.
28 * IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE,
29 * PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
30 * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE
31 * THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE
32 * SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
37 /* @(#)ttcr.h 1.6 03/01/08 SMI */
41 * @brief TrueType font creator
42 * @author Alexander Gelfenbain <adg@sun.com>
58 typedef struct _TrueTypeCreator TrueTypeCreator;
60 /* TrueType data types */
66 /* A generic base class for all TrueType tables */
68 guint32 tag; /* table tag */
69 guint8 *rawdata; /* raw data allocated by GetRawData_*() */
70 void *data; /* table specific data */
73 /** Error codes for most functions */
75 TTCR_OK = 0, /**< no error */
76 TTCR_ZEROGLYPHS = 1, /**< At least one glyph should be defined */
77 TTCR_UNKNOWN = 2, /**< Unknown TrueType table */
78 TTCR_GLYPHSEQ = 3, /**< Glyph IDs are not sequential in the glyf table */
79 TTCR_NONAMES = 4, /**< 'name' table does not contain any names */
80 TTCR_NAMETOOLONG = 5, /**< 'name' table is too long (string data > 64K) */
81 TTCR_POSTFORMAT = 6 /**< unsupported format of a 'post' table */
84 /* ============================================================================
86 * TrueTypeCreator methods
88 * ============================================================================ */
91 * TrueTypeCreator constructor.
92 * Allocates all internal structures.
94 void TrueTypeCreatorNewEmpty(guint32 tag, TrueTypeCreator **_this);
97 * TrueTypeCreator destructor. It calls destructors for all TrueTypeTables added to it.
99 void TrueTypeCreatorDispose(TrueTypeCreator *_this);
102 * Adds a TrueType table to the TrueType creator.
103 * SF_TABLEFORMAT value.
104 * @return value of SFErrCodes type
106 int AddTable(TrueTypeCreator *_this, TrueTypeTable *table);
109 * Removes a TrueType table from the TrueType creator if it is stored there.
110 * It also calls a TrueTypeTable destructor.
111 * Note: all generic tables (with tag 0) will be removed if this function is
112 * called with the second argument of 0.
113 * @return value of SFErrCodes type
115 void RemoveTable(TrueTypeCreator *_this, guint32 tag);
120 * Writes a TrueType font generated by the TrueTypeCreator to a segment of
121 * memory that this method allocates. When it is not needed anymore the caller
122 * is supposed to call free() on it.
123 * @return value of SFErrCodes type
125 int StreamToMemory(TrueTypeCreator *_this, guint8 **ptr, guint32 *length);
128 * Writes a TrueType font generated by the TrueTypeCreator to a file
129 * @return value of SFErrCodes type
131 int StreamToFile(TrueTypeCreator *_this, const char* fname);
134 /* ============================================================================
136 * TrueTypeTable methods
138 * ============================================================================ */
141 * Destructor for the TrueTypeTable object.
143 void TrueTypeTableDispose(TrueTypeTable *);
146 * This function converts the data of a TrueType table to a raw array of bytes.
147 * It may allocates the memory for it and returns the size of the raw data in bytes.
148 * If memory is allocated it does not need to be freed by the caller of this function,
149 * since the pointer to it is stored in the TrueTypeTable and it is freed by the destructor
150 * @return TTCRErrCode
154 int GetRawData(TrueTypeTable *, guint8 **ptr, guint32 *len, guint32 *tag);
158 * Creates a new raw TrueType table. The difference between this constructor and
159 * TrueTypeTableNew_tag constructors is that the latter create structured tables
160 * while this constructor just copies memory pointed to by ptr to its buffer
161 * and stores its length. This constructor is suitable for data that is not
162 * supposed to be processed in any way, just written to the resulting TTF file.
164 TrueTypeTable *TrueTypeTableNew(guint32 tag,
169 * Creates a new 'head' table for a TrueType font.
170 * Allocates memory for it. Since a lot of values in the 'head' table depend on the
171 * rest of the tables in the TrueType font this table should be the last one added
174 TrueTypeTable *TrueTypeTableNew_head(guint32 fontRevision,
179 guint16 lowestRecPPEM,
180 gint16 fontDirectionHint);
183 * Creates a new 'hhea' table for a TrueType font.
184 * Allocates memory for it and stores it in the hhea pointer.
186 TrueTypeTable *TrueTypeTableNew_hhea(gint16 ascender,
189 gint16 caretSlopeRise,
190 gint16 caretSlopeRun);
193 * Creates a new empty 'loca' table for a TrueType font.
195 * INTERNAL: gets called only from ProcessTables();
197 TrueTypeTable *TrueTypeTableNew_loca(void);
200 * Creates a new 'maxp' table based on an existing maxp table.
201 * If maxp is 0, a new empty maxp table is created
202 * size specifies the size of existing maxp table for
203 * error-checking purposes
205 TrueTypeTable *TrueTypeTableNew_maxp(guint8 *maxp, int size);
208 * Creates a new empty 'glyf' table.
210 TrueTypeTable *TrueTypeTableNew_glyf(void);
213 * Creates a new empty 'cmap' table.
215 TrueTypeTable *TrueTypeTableNew_cmap(void);
218 * Creates a new 'name' table. If n != 0 the table gets populated by
219 * the Name Records stored in the nr array. This function allocates
220 * memory for its own copy of NameRecords, so nr array has to
221 * be explicitly deallocated when it is not needed.
223 TrueTypeTable *TrueTypeTableNew_name(int n, NameRecord *nr);
226 * Creates a new 'post' table of one of the supported formats
228 TrueTypeTable *TrueTypeTableNew_post(guint32 format,
230 gint16 underlinePosition,
231 gint16 underlineThickness,
232 guint32 isFixedPitch);
235 /*------------------------------------------------------------------------------
237 * Table manipulation functions
239 *------------------------------------------------------------------------------*/
243 * Add a character/glyph pair to a cmap table
245 void cmapAdd(TrueTypeTable *, guint32 id, guint32 c, guint32 g);
248 * Add a glyph to a glyf table.
250 * @return glyphID of the glyph in the new font
252 * NOTE: This function does not duplicate GlyphData, so memory will be
253 * deallocated in the table destructor
255 guint32 glyfAdd(TrueTypeTable *, GlyphData *glyphdata, TrueTypeFont *fnt);
258 * Query the number of glyphs currently stored in the 'glyf' table
261 guint32 glyfCount(const TrueTypeTable *);
264 * Add a Name Record to a name table.
265 * NOTE: This function duplicates NameRecord, so the argument
266 * has to be deallocated by the caller (unlike glyfAdd)
268 void nameAdd(TrueTypeTable *, NameRecord *nr);
276 struct _TrueTypeCreator {
277 guint32 tag; /**< TrueType file tag */
278 list tables; /**< List of table tags and pointers */
287 #endif /* __TTCR_H */