s/--components/--composites/, s/hint-with-components/hint-composites/.
[ttfautohint.git] / lib / ta.h
blobc6054ef349c47e2e1a9643875e3ae6a997a9c49f
1 /* ta.h */
3 /*
4 * Copyright (C) 2011-2013 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>
32 #include <numberset.h>
35 #define TTFAUTOHINT_GLYPH ".ttfautohint"
36 #define TTFAUTOHINT_GLYPH_FIRST_BYTE "\x0C" /* first byte is string length */
37 #define TTFAUTOHINT_GLYPH_LEN 13
39 /* these macros convert 16bit and 32bit numbers into single bytes */
40 /* using the byte order needed within SFNT files */
42 #define HIGH(x) (FT_Byte)(((x) & 0xFF00) >> 8)
43 #define LOW(x) ((x) & 0x00FF)
45 #define BYTE1(x) (FT_Byte)(((x) & 0xFF000000UL) >> 24);
46 #define BYTE2(x) (FT_Byte)(((x) & 0x00FF0000UL) >> 16);
47 #define BYTE3(x) (FT_Byte)(((x) & 0x0000FF00UL) >> 8);
48 #define BYTE4(x) ((x) & 0x000000FFUL);
51 /* the length of a dummy `DSIG' table */
52 #define DSIG_LEN 8
54 /* the length of our `gasp' table */
55 #define GASP_LEN 8
57 /* an empty slot in the table info array */
58 #define MISSING (FT_ULong)~0
60 /* the offset to the loca table format in the `head' table */
61 #define LOCA_FORMAT_OFFSET 51
63 /* various offsets within the `maxp' table */
64 #define MAXP_NUM_GLYPHS 4
65 #define MAXP_MAX_COMPOSITE_POINTS 10
66 #define MAXP_MAX_COMPOSITE_CONTOURS 12
67 #define MAXP_MAX_ZONES_OFFSET 14
68 #define MAXP_MAX_TWILIGHT_POINTS_OFFSET 16
69 #define MAXP_MAX_STORAGE_OFFSET 18
70 #define MAXP_MAX_FUNCTION_DEFS_OFFSET 20
71 #define MAXP_MAX_INSTRUCTION_DEFS_OFFSET 22
72 #define MAXP_MAX_STACK_ELEMENTS_OFFSET 24
73 #define MAXP_MAX_INSTRUCTIONS_OFFSET 26
74 #define MAXP_MAX_COMPONENTS_OFFSET 28
76 #define MAXP_LEN 32
78 /* the offset of the type flags field in the `OS/2' table */
79 #define OS2_FSTYPE_OFFSET 8
82 /* flags in composite glyph records */
83 #define ARGS_ARE_WORDS 0x0001
84 #define ARGS_ARE_XY_VALUES 0x0002
85 #define WE_HAVE_A_SCALE 0x0008
86 #define MORE_COMPONENTS 0x0020
87 #define WE_HAVE_AN_XY_SCALE 0x0040
88 #define WE_HAVE_A_2X2 0x0080
89 #define WE_HAVE_INSTR 0x0100
91 /* flags in simple glyph records */
92 #define ON_CURVE 0x01
93 #define X_SHORT_VECTOR 0x02
94 #define Y_SHORT_VECTOR 0x04
95 #define REPEAT 0x08
96 #define SAME_X 0x10
97 #define SAME_Y 0x20
100 /* a single glyph */
101 typedef struct GLYPH_
103 FT_ULong len1; /* number of bytes before instruction related data */
104 FT_ULong len2; /* number of bytes after instruction related data; */
105 /* if zero, this indicates a composite glyph */
106 FT_Byte* buf; /* extracted glyph data (without instruction related data) */
107 FT_ULong flags_offset; /* offset to last flag in a composite glyph */
109 FT_ULong ins_len; /* number of new instructions */
110 FT_Byte* ins_buf; /* new instruction data */
112 FT_Short num_contours; /* >= 0 for simple glyphs */
113 FT_UShort num_points; /* number of points in a simple glyph */
115 FT_UShort num_components;
116 FT_UShort* components; /* the subglyph indices of a composite glyph */
118 FT_UShort num_pointsums;
119 FT_UShort* pointsums; /* the pointsums of all composite elements */
120 /* (after walking recursively over all subglyphs) */
122 FT_UShort num_composite_contours; /* after recursion */
123 } GLYPH;
125 /* a representation of the data in the `glyf' table */
126 typedef struct glyf_Data_
128 FT_UShort num_glyphs;
129 GLYPH* glyphs;
131 /* this index gives the `master' globals for a `glyf' table; */
132 /* see function `TA_sfnt_handle_coverage' */
133 TA_FaceGlobals master_globals;
135 /* if a `glyf' table gets used in more than one subfont, */
136 /* so do `cvt', `fpgm', and `prep' tables: */
137 /* these four tables are always handled in parallel */
138 FT_ULong cvt_idx;
139 FT_ULong fpgm_idx;
140 FT_ULong prep_idx;
141 } glyf_Data;
143 /* an SFNT table */
144 typedef struct SFNT_Table_
146 FT_ULong tag;
147 FT_ULong len;
148 FT_Byte* buf; /* the table data */
149 FT_ULong offset; /* from beginning of file */
150 FT_ULong checksum;
151 void* data; /* used e.g. for `glyf' table data */
152 FT_Bool processed;
153 } SFNT_Table;
155 /* we use indices into the SFNT table array to */
156 /* represent table info records of the TTF header */
157 typedef FT_ULong SFNT_Table_Info;
159 /* this structure is used to model a TTF or a subfont within a TTC */
160 typedef struct SFNT_
162 FT_Face face;
164 SFNT_Table_Info* table_infos;
165 FT_ULong num_table_infos;
167 /* various SFNT table indices */
168 FT_ULong glyf_idx;
169 FT_ULong loca_idx;
170 FT_ULong head_idx;
171 FT_ULong hmtx_idx;
172 FT_ULong maxp_idx;
173 FT_ULong name_idx;
174 FT_ULong post_idx;
175 FT_ULong OS2_idx;
176 FT_ULong GPOS_idx;
178 /* values necessary to update the `maxp' table */
179 FT_UShort max_composite_points;
180 FT_UShort max_composite_contours;
181 FT_UShort max_storage;
182 FT_UShort max_stack_elements;
183 FT_UShort max_twilight_points;
184 FT_UShort max_instructions;
185 FT_UShort max_components;
186 } SFNT;
188 /* our font object */
189 struct FONT_
191 FT_Library lib;
193 FT_Byte* in_buf;
194 size_t in_len;
196 FT_Byte* out_buf;
197 size_t out_len;
199 SFNT* sfnts;
200 FT_Long num_sfnts;
202 SFNT_Table* tables;
203 FT_ULong num_tables;
205 FT_Bool have_DSIG;
207 /* we have a single `gasp' table for all subfonts */
208 FT_ULong gasp_idx;
210 TA_LoaderRec loader[1]; /* the interface to the autohinter */
212 /* configuration options */
213 TA_Progress_Func progress;
214 void* progress_data;
215 TA_Info_Func info;
216 void* info_data;
217 FT_UInt hinting_range_min;
218 FT_UInt hinting_range_max;
219 FT_UInt hinting_limit;
220 FT_UInt increase_x_height;
221 number_range* x_height_snapping_exceptions;
222 FT_Bool gray_strong_stem_width;
223 FT_Bool gdi_cleartype_strong_stem_width;
224 FT_Bool dw_cleartype_strong_stem_width;
225 FT_Bool windows_compatibility;
226 FT_Bool pre_hinting;
227 FT_Bool hint_composites;
228 FT_Bool ignore_restrictions;
229 FT_UInt fallback_script;
230 FT_Bool symbol;
231 FT_Bool dehint;
232 FT_Bool debug;
236 #include "tatables.h"
237 #include "tabytecode.h"
240 const char*
241 TA_get_error_message(FT_Error error);
243 void
244 TA_get_current_time(FT_ULong* high,
245 FT_ULong* low);
247 FT_Byte*
248 TA_build_push(FT_Byte* bufp,
249 FT_UInt* args,
250 FT_UInt num_args,
251 FT_Bool need_words,
252 FT_Bool optimize);
254 FT_Error
255 TA_font_init(FONT* font);
256 void
257 TA_font_unload(FONT* font,
258 const char* in_buf,
259 char** out_bufp);
261 FT_Error
262 TA_font_file_read(FONT* font,
263 FILE* in_file);
264 FT_Error
265 TA_font_file_write(FONT* font,
266 FILE* out_file);
268 FT_Error
269 TA_sfnt_build_glyph_instructions(SFNT* sfnt,
270 FONT* font,
271 FT_Long idx);
273 FT_Error
274 TA_sfnt_split_into_SFNT_tables(SFNT* sfnt,
275 FONT* font);
277 FT_Error
278 TA_sfnt_build_cvt_table(SFNT* sfnt,
279 FONT* font);
281 FT_Error
282 TA_table_build_DSIG(FT_Byte** DSIG);
284 FT_Error
285 TA_sfnt_build_fpgm_table(SFNT* sfnt,
286 FONT* font);
288 FT_Error
289 TA_sfnt_build_gasp_table(SFNT* sfnt,
290 FONT* font);
292 FT_Error
293 TA_sfnt_split_glyf_table(SFNT* sfnt,
294 FONT* font);
295 FT_Error
296 TA_sfnt_build_glyf_table(SFNT* sfnt,
297 FONT* font);
298 FT_Error
299 TA_sfnt_create_glyf_data(SFNT* sfnt,
300 FONT* font);
301 FT_Error
302 TA_sfnt_handle_coverage(SFNT* sfnt,
303 FONT* font);
304 void
305 TA_sfnt_adjust_master_coverage(SFNT* sfnt,
306 FONT* font);
307 #if 0
308 void
309 TA_sfnt_copy_master_coverage(SFNT* sfnt,
310 FONT* font);
311 #endif
313 FT_Error
314 TA_sfnt_update_GPOS_table(SFNT* sfnt,
315 FONT* font);
317 FT_Error
318 TA_sfnt_update_hmtx_table(SFNT* sfnt,
319 FONT* font);
321 FT_Error
322 TA_sfnt_build_loca_table(SFNT* sfnt,
323 FONT* font);
325 FT_Error
326 TA_sfnt_update_maxp_table(SFNT* sfnt,
327 FONT* font);
329 FT_Error
330 TA_sfnt_update_post_table(SFNT* sfnt,
331 FONT* font);
333 FT_Error
334 TA_sfnt_update_name_table(SFNT* sfnt,
335 FONT* font);
337 FT_Error
338 TA_sfnt_build_prep_table(SFNT* sfnt,
339 FONT* font);
341 FT_Error
342 TA_sfnt_build_TTF_header(SFNT* sfnt,
343 FONT* font,
344 FT_Byte** header_buf,
345 FT_ULong* header_len,
346 FT_Int do_complete);
347 FT_Error
348 TA_font_build_TTF(FONT* font);
350 FT_Error
351 TA_font_build_TTC(FONT* font);
353 #endif /* __TA_H__ */
355 /* end of ta.h */