Add NUMBERSET_NOT_ASCENDING error code.
[ttfautohint.git] / lib / ta.h
blobeab02f3b392b32c7a02922b4d9c8a0c6e5eb5fec
1 /* ta.h */
3 /*
4 * Copyright (C) 2011-2012 by Werner Lemberg.
6 * This file is part of the ttfautohint library, and may only be used,
7 * modified, and distributed under the terms given in `COPYING'. By
8 * continuing to use, modify, or distribute this file you indicate that you
9 * have read `COPYING' and understand and accept it fully.
11 * The file `COPYING' mentioned in the previous paragraph is distributed
12 * with the ttfautohint library.
16 #ifndef __TA_H__
17 #define __TA_H__
19 #include <config.h>
21 #include <ft2build.h>
22 #include FT_FREETYPE_H
23 #include FT_TRUETYPE_TABLES_H
24 #include FT_TRUETYPE_TAGS_H
26 #include "taloader.h"
27 #include "taglobal.h"
28 #include "tadummy.h"
29 #include "talatin.h"
31 #include <ttfautohint.h>
34 #define TTFAUTOHINT_GLYPH ".ttfautohint"
35 #define TTFAUTOHINT_GLYPH_FIRST_BYTE "\x0C" /* first byte is string length */
36 #define TTFAUTOHINT_GLYPH_LEN 13
38 /* these macros convert 16bit and 32bit numbers into single bytes */
39 /* using the byte order needed within SFNT files */
41 #define HIGH(x) (FT_Byte)(((x) & 0xFF00) >> 8)
42 #define LOW(x) ((x) & 0x00FF)
44 #define BYTE1(x) (FT_Byte)(((x) & 0xFF000000UL) >> 24);
45 #define BYTE2(x) (FT_Byte)(((x) & 0x00FF0000UL) >> 16);
46 #define BYTE3(x) (FT_Byte)(((x) & 0x0000FF00UL) >> 8);
47 #define BYTE4(x) ((x) & 0x000000FFUL);
50 /* the length of a dummy `DSIG' table */
51 #define DSIG_LEN 8
53 /* the length of our `gasp' table */
54 #define GASP_LEN 8
56 /* an empty slot in the table info array */
57 #define MISSING (FT_ULong)~0
59 /* the offset to the loca table format in the `head' table */
60 #define LOCA_FORMAT_OFFSET 51
62 /* various offsets within the `maxp' table */
63 #define MAXP_NUM_GLYPHS 4
64 #define MAXP_MAX_COMPOSITE_POINTS 10
65 #define MAXP_MAX_COMPOSITE_CONTOURS 12
66 #define MAXP_MAX_ZONES_OFFSET 14
67 #define MAXP_MAX_TWILIGHT_POINTS_OFFSET 16
68 #define MAXP_MAX_STORAGE_OFFSET 18
69 #define MAXP_MAX_FUNCTION_DEFS_OFFSET 20
70 #define MAXP_MAX_INSTRUCTION_DEFS_OFFSET 22
71 #define MAXP_MAX_STACK_ELEMENTS_OFFSET 24
72 #define MAXP_MAX_INSTRUCTIONS_OFFSET 26
73 #define MAXP_MAX_COMPONENTS_OFFSET 28
75 #define MAXP_LEN 32
77 /* the offset of the type flags field in the `OS/2' table */
78 #define OS2_FSTYPE_OFFSET 8
81 /* flags in composite glyph records */
82 #define ARGS_ARE_WORDS 0x0001
83 #define ARGS_ARE_XY_VALUES 0x0002
84 #define WE_HAVE_A_SCALE 0x0008
85 #define MORE_COMPONENTS 0x0020
86 #define WE_HAVE_AN_XY_SCALE 0x0040
87 #define WE_HAVE_A_2X2 0x0080
88 #define WE_HAVE_INSTR 0x0100
90 /* flags in simple glyph records */
91 #define ON_CURVE 0x01
92 #define X_SHORT_VECTOR 0x02
93 #define Y_SHORT_VECTOR 0x04
94 #define REPEAT 0x08
95 #define SAME_X 0x10
96 #define SAME_Y 0x20
99 /* a single glyph */
100 typedef struct GLYPH_
102 FT_ULong len1; /* number of bytes before instruction related data */
103 FT_ULong len2; /* number of bytes after instruction related data; */
104 /* if zero, this indicates a composite glyph */
105 FT_Byte* buf; /* extracted glyph data (without instruction related data) */
106 FT_ULong flags_offset; /* offset to last flag in a composite glyph */
108 FT_ULong ins_len; /* number of new instructions */
109 FT_Byte* ins_buf; /* new instruction data */
111 FT_Short num_contours; /* >= 0 for simple glyphs */
112 FT_UShort num_points; /* number of points in a simple glyph */
114 FT_UShort num_components;
115 FT_UShort* components; /* the subglyph indices of a composite glyph */
117 FT_UShort num_pointsums;
118 FT_UShort* pointsums; /* the pointsums of all composite elements */
119 /* (after walking recursively over all subglyphs) */
121 FT_UShort num_composite_contours; /* after recursion */
122 } GLYPH;
124 /* a representation of the data in the `glyf' table */
125 typedef struct glyf_Data_
127 FT_UShort num_glyphs;
128 GLYPH* glyphs;
130 /* this index gives the `master' globals for a `glyf' table; */
131 /* see function `TA_sfnt_handle_coverage' */
132 TA_FaceGlobals master_globals;
134 /* if a `glyf' table gets used in more than one subfont, */
135 /* so do `cvt', `fpgm', and `prep' tables: */
136 /* these four tables are always handled in parallel */
137 FT_ULong cvt_idx;
138 FT_ULong fpgm_idx;
139 FT_ULong prep_idx;
140 } glyf_Data;
142 /* an SFNT table */
143 typedef struct SFNT_Table_
145 FT_ULong tag;
146 FT_ULong len;
147 FT_Byte* buf; /* the table data */
148 FT_ULong offset; /* from beginning of file */
149 FT_ULong checksum;
150 void* data; /* used e.g. for `glyf' table data */
151 FT_Bool processed;
152 } SFNT_Table;
154 /* we use indices into the SFNT table array to */
155 /* represent table info records of the TTF header */
156 typedef FT_ULong SFNT_Table_Info;
158 /* this structure is used to model a TTF or a subfont within a TTC */
159 typedef struct SFNT_
161 FT_Face face;
163 SFNT_Table_Info* table_infos;
164 FT_ULong num_table_infos;
166 /* various SFNT table indices */
167 FT_ULong glyf_idx;
168 FT_ULong loca_idx;
169 FT_ULong head_idx;
170 FT_ULong hmtx_idx;
171 FT_ULong maxp_idx;
172 FT_ULong name_idx;
173 FT_ULong post_idx;
174 FT_ULong OS2_idx;
175 FT_ULong GPOS_idx;
177 /* values necessary to update the `maxp' table */
178 FT_UShort max_composite_points;
179 FT_UShort max_composite_contours;
180 FT_UShort max_storage;
181 FT_UShort max_stack_elements;
182 FT_UShort max_twilight_points;
183 FT_UShort max_instructions;
184 FT_UShort max_components;
185 } SFNT;
187 /* our font object */
188 struct FONT_
190 FT_Library lib;
192 FT_Byte* in_buf;
193 size_t in_len;
195 FT_Byte* out_buf;
196 size_t out_len;
198 SFNT* sfnts;
199 FT_Long num_sfnts;
201 SFNT_Table* tables;
202 FT_ULong num_tables;
204 FT_Bool have_DSIG;
206 /* we have a single `gasp' table for all subfonts */
207 FT_ULong gasp_idx;
209 TA_LoaderRec loader[1]; /* the interface to the autohinter */
211 /* configuration options */
212 TA_Progress_Func progress;
213 void* progress_data;
214 TA_Info_Func info;
215 void* info_data;
216 FT_UInt hinting_range_min;
217 FT_UInt hinting_range_max;
218 FT_UInt hinting_limit;
219 FT_UInt increase_x_height;
220 FT_Bool gray_strong_stem_width;
221 FT_Bool gdi_cleartype_strong_stem_width;
222 FT_Bool dw_cleartype_strong_stem_width;
223 FT_Bool windows_compatibility;
224 FT_Bool pre_hinting;
225 FT_Bool hint_with_components;
226 FT_Bool no_x_height_snapping;
227 FT_Byte* x_height_snapping_exceptions;
228 FT_Bool ignore_restrictions;
229 FT_UInt fallback_script;
230 FT_Bool symbol;
231 FT_Bool debug;
235 #include "tatables.h"
236 #include "tabytecode.h"
239 const char*
240 TA_get_error_message(FT_Error error);
242 void
243 TA_get_current_time(FT_ULong* high,
244 FT_ULong* low);
246 FT_Byte*
247 TA_build_push(FT_Byte* bufp,
248 FT_UInt* args,
249 FT_UInt num_args,
250 FT_Bool need_words,
251 FT_Bool optimize);
253 FT_Error
254 TA_font_init(FONT* font);
255 void
256 TA_font_unload(FONT* font,
257 const char* in_buf,
258 char** out_bufp);
260 FT_Error
261 TA_font_file_read(FONT* font,
262 FILE* in_file);
263 FT_Error
264 TA_font_file_write(FONT* font,
265 FILE* out_file);
267 FT_Error
268 TA_sfnt_build_glyph_instructions(SFNT* sfnt,
269 FONT* font,
270 FT_Long idx);
272 FT_Error
273 TA_sfnt_split_into_SFNT_tables(SFNT* sfnt,
274 FONT* font);
276 FT_Error
277 TA_sfnt_build_cvt_table(SFNT* sfnt,
278 FONT* font);
280 FT_Error
281 TA_table_build_DSIG(FT_Byte** DSIG);
283 FT_Error
284 TA_sfnt_build_fpgm_table(SFNT* sfnt,
285 FONT* font);
287 FT_Error
288 TA_sfnt_build_gasp_table(SFNT* sfnt,
289 FONT* font);
291 FT_Error
292 TA_sfnt_split_glyf_table(SFNT* sfnt,
293 FONT* font);
294 FT_Error
295 TA_sfnt_build_glyf_table(SFNT* sfnt,
296 FONT* font);
297 FT_Error
298 TA_sfnt_create_glyf_data(SFNT* sfnt,
299 FONT* font);
300 FT_Error
301 TA_sfnt_handle_coverage(SFNT* sfnt,
302 FONT* font);
303 void
304 TA_sfnt_adjust_master_coverage(SFNT* sfnt,
305 FONT* font);
306 #if 0
307 void
308 TA_sfnt_copy_master_coverage(SFNT* sfnt,
309 FONT* font);
310 #endif
312 FT_Error
313 TA_sfnt_update_GPOS_table(SFNT* sfnt,
314 FONT* font);
316 FT_Error
317 TA_sfnt_update_hmtx_table(SFNT* sfnt,
318 FONT* font);
320 FT_Error
321 TA_sfnt_build_loca_table(SFNT* sfnt,
322 FONT* font);
324 FT_Error
325 TA_sfnt_update_maxp_table(SFNT* sfnt,
326 FONT* font);
328 FT_Error
329 TA_sfnt_update_post_table(SFNT* sfnt,
330 FONT* font);
332 FT_Error
333 TA_sfnt_update_name_table(SFNT* sfnt,
334 FONT* font);
336 FT_Error
337 TA_sfnt_build_prep_table(SFNT* sfnt,
338 FONT* font);
340 FT_Error
341 TA_sfnt_build_TTF_header(SFNT* sfnt,
342 FONT* font,
343 FT_Byte** header_buf,
344 FT_ULong* header_len,
345 FT_Int do_complete);
346 FT_Error
347 TA_font_build_TTF(FONT* font);
349 FT_Error
350 TA_font_build_TTC(FONT* font);
352 #endif /* __TA_H__ */
354 /* end of ta.h */