]> git.donarmstrong.com Git - xournal.git/blob - src/ttsubset/ttcr.h
Print via gtk-print instead of libgnomeprint
[xournal.git] / src / ttsubset / ttcr.h
1 /*
2  * Copyright © 2002, 2003 Sun Microsystems, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
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.
15  *
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.
19  *
20  * This software is provided "AS IS," without a warranty of any kind.
21  *
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.
33  *
34  */
35
36 /* $Id$ */
37 /* @(#)ttcr.h 1.6 03/01/08 SMI */
38
39 /*
40  * @file ttcr.h
41  * @brief TrueType font creator
42  * @author Alexander Gelfenbain <adg@sun.com>
43  * @version 1.1
44  *
45  */
46
47
48 #ifndef __TTCR_H
49 #define __TTCR_H
50
51 #include "sft.h"
52 #include "list.h"
53
54 #ifdef __cplusplus
55 extern "C"{
56 #endif
57
58 typedef struct _TrueTypeCreator TrueTypeCreator;
59
60 /* TrueType data types */
61 typedef struct {
62     guint16 aw;
63     gint16  lsb;
64 } longHorMetrics;
65
66 /* A generic base class for all TrueType tables */
67 typedef struct {
68     guint32 tag;                         /* table tag                                                */
69     guint8   *rawdata;                    /* raw data allocated by GetRawData_*()                     */
70     void   *data;                       /* table specific data                                      */
71 } TrueTypeTable;
72
73 /** Error codes for most functions */
74 enum TTCRErrCodes {                     
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                   */
82 };
83
84 /* ============================================================================
85  *
86  * TrueTypeCreator methods
87  *
88  * ============================================================================ */
89
90 /*
91  * TrueTypeCreator constructor.
92  * Allocates all internal structures.
93  */
94 void TrueTypeCreatorNewEmpty(guint32 tag, TrueTypeCreator **_this);
95
96 /*
97  * TrueTypeCreator destructor. It calls destructors for all TrueTypeTables added to it.
98  */
99 void TrueTypeCreatorDispose(TrueTypeCreator *_this);
100
101 /*
102  * Adds a TrueType table to the TrueType creator.
103  * SF_TABLEFORMAT value.
104  * @return value of SFErrCodes type
105  */
106 int AddTable(TrueTypeCreator *_this, TrueTypeTable *table);
107
108 /*
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
114  */
115 void RemoveTable(TrueTypeCreator *_this, guint32 tag);
116
117
118
119 /*
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
124  */
125 int StreamToMemory(TrueTypeCreator *_this, guint8 **ptr, guint32 *length);
126
127 /*
128  * Writes a TrueType font  generated by the TrueTypeCreator to a file
129  * @return value of SFErrCodes type
130  */
131 int StreamToFile(TrueTypeCreator *_this, const char* fname);
132
133
134 /* ============================================================================
135  *
136  * TrueTypeTable methods
137  *
138  * ============================================================================ */
139
140 /*
141  * Destructor for the TrueTypeTable object.
142  */
143 void TrueTypeTableDispose(TrueTypeTable *);
144
145 /*
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
151  *
152  */
153
154 int GetRawData(TrueTypeTable *, guint8 **ptr, guint32 *len, guint32 *tag);
155
156 /*
157  *
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.
163  */
164 TrueTypeTable *TrueTypeTableNew(guint32 tag,
165                                 guint32 nbytes,
166                                 guint8 *ptr);
167
168 /*
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
172  * to the font.
173  */
174 TrueTypeTable *TrueTypeTableNew_head(guint32 fontRevision,
175                                      guint16 flags,
176                                      guint16 unitsPerEm,
177                                      guint8  *created,
178                                      guint16 macStyle,
179                                      guint16 lowestRecPPEM,
180                                      gint16  fontDirectionHint);
181
182 /*
183  * Creates a new 'hhea' table for a TrueType font.
184  * Allocates memory for it and stores it in the hhea pointer.
185  */
186 TrueTypeTable *TrueTypeTableNew_hhea(gint16  ascender,
187                                      gint16  descender,
188                                      gint16  linegap,
189                                      gint16  caretSlopeRise,
190                                      gint16  caretSlopeRun);
191
192 /*
193  * Creates a new empty 'loca' table for a TrueType font.
194  *
195  * INTERNAL: gets called only from ProcessTables();
196  */
197 TrueTypeTable *TrueTypeTableNew_loca(void);
198
199 /*
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
204  */
205 TrueTypeTable *TrueTypeTableNew_maxp(guint8 *maxp, int size);
206
207 /*
208  * Creates a new empty 'glyf' table.
209  */
210 TrueTypeTable *TrueTypeTableNew_glyf(void);
211
212 /*
213  * Creates a new empty 'cmap' table.
214  */
215 TrueTypeTable *TrueTypeTableNew_cmap(void);
216
217 /*
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.
222  */
223 TrueTypeTable *TrueTypeTableNew_name(int n, NameRecord *nr);
224
225 /*
226  * Creates a new 'post' table of one of the supported formats
227  */
228 TrueTypeTable *TrueTypeTableNew_post(guint32 format,
229                                      guint32 italicAngle,
230                                      gint16 underlinePosition,
231                                      gint16 underlineThickness,
232                                      guint32 isFixedPitch);
233
234
235 /*------------------------------------------------------------------------------
236  *
237  *  Table manipulation functions
238  *
239  *------------------------------------------------------------------------------*/
240  
241
242 /*
243  * Add a character/glyph pair to a cmap table
244  */
245 void cmapAdd(TrueTypeTable *, guint32 id, guint32 c, guint32 g);
246
247 /*
248  * Add a glyph to a glyf table.
249  *
250  * @return glyphID of the glyph in the new font
251  *
252  * NOTE: This function does not duplicate GlyphData, so memory will be
253  * deallocated in the table destructor
254  */
255 guint32 glyfAdd(TrueTypeTable *, GlyphData *glyphdata, TrueTypeFont *fnt);
256
257 /*
258  * Query the number of glyphs currently stored in the 'glyf' table
259  *
260  */
261 guint32 glyfCount(const TrueTypeTable *);
262
263 /*
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)
267  */
268 void nameAdd(TrueTypeTable *, NameRecord *nr);
269
270                    
271
272 /*
273  * Private Data Types
274  */
275
276 struct _TrueTypeCreator {
277     guint32 tag;                         /**< TrueType file tag */
278     list   tables;                      /**< List of table tags and pointers */
279 };
280
281
282
283 #ifdef __cplusplus
284 }
285 #endif
286
287 #endif /* __TTCR_H */