Synchronize with FreeType [4/4].
[ttfautohint.git] / lib / ta.h
blob085c98e779925fdbda25b7989f38952467f68628
1 /* ta.h */
3 /*
4 * Copyright (C) 2011-2015 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 <ttfautohint.h>
27 #include <sds.h>
28 #include <numberset.h>
30 #include "taloader.h"
31 #include "taglobal.h"
32 #include "tadummy.h"
33 #include "talatin.h"
36 #define TTFAUTOHINT_GLYPH ".ttfautohint"
37 #define TTFAUTOHINT_GLYPH_FIRST_BYTE "\x0C" /* first byte is string length */
38 #define TTFAUTOHINT_GLYPH_LEN 13
40 /* these macros convert 16bit and 32bit numbers into single bytes */
41 /* using the byte order needed within SFNT files */
43 #define HIGH(x) (FT_Byte)(((x) & 0xFF00) >> 8)
44 #define LOW(x) ((x) & 0x00FF)
46 #define BYTE1(x) (FT_Byte)(((x) & 0xFF000000UL) >> 24);
47 #define BYTE2(x) (FT_Byte)(((x) & 0x00FF0000UL) >> 16);
48 #define BYTE3(x) (FT_Byte)(((x) & 0x0000FF00UL) >> 8);
49 #define BYTE4(x) ((x) & 0x000000FFUL);
52 /* an SFNT tag for our information table */
53 #define TTAG_TTFA FT_MAKE_TAG('T', 'T', 'F', 'A')
55 /* the length of a dummy `DSIG' table */
56 #define DSIG_LEN 8
58 /* the length of our `gasp' table */
59 #define GASP_LEN 8
61 /* an empty slot in the table info array */
62 #define MISSING (FT_ULong)~0
64 /* the offset to the loca table format in the `head' table */
65 #define LOCA_FORMAT_OFFSET 51
67 /* various offsets within the `maxp' table */
68 #define MAXP_NUM_GLYPHS 4
69 #define MAXP_MAX_COMPOSITE_POINTS 10
70 #define MAXP_MAX_COMPOSITE_CONTOURS 12
71 #define MAXP_MAX_ZONES_OFFSET 14
72 #define MAXP_MAX_TWILIGHT_POINTS_OFFSET 16
73 #define MAXP_MAX_STORAGE_OFFSET 18
74 #define MAXP_MAX_FUNCTION_DEFS_OFFSET 20
75 #define MAXP_MAX_INSTRUCTION_DEFS_OFFSET 22
76 #define MAXP_MAX_STACK_ELEMENTS_OFFSET 24
77 #define MAXP_MAX_INSTRUCTIONS_OFFSET 26
78 #define MAXP_MAX_COMPONENTS_OFFSET 28
80 #define MAXP_LEN 32
82 /* the offset of the type flags field in the `OS/2' table */
83 #define OS2_FSTYPE_OFFSET 8
86 /* flags in composite glyph records */
87 #define ARGS_ARE_WORDS 0x0001
88 #define ARGS_ARE_XY_VALUES 0x0002
89 #define WE_HAVE_A_SCALE 0x0008
90 #define MORE_COMPONENTS 0x0020
91 #define WE_HAVE_AN_XY_SCALE 0x0040
92 #define WE_HAVE_A_2X2 0x0080
93 #define WE_HAVE_INSTR 0x0100
95 /* flags in simple glyph records */
96 #define ON_CURVE 0x01
97 #define X_SHORT_VECTOR 0x02
98 #define Y_SHORT_VECTOR 0x04
99 #define REPEAT 0x08
100 #define SAME_X 0x10
101 #define SAME_Y 0x20
104 /* a single glyph */
105 typedef struct GLYPH_
107 FT_ULong len1; /* number of bytes before instruction related data */
108 FT_ULong len2; /* number of bytes after instruction related data; */
109 /* if zero, this indicates a composite glyph */
110 FT_Byte* buf; /* extracted glyph data (without instruction related data) */
111 FT_ULong flags_offset; /* offset to last flag in a composite glyph */
113 FT_Byte ins_extra_len; /* number of extra instructions; */
114 /* see `ins_extra_buf' in `tabytecode.h' */
115 FT_ULong ins_len; /* number of new instructions */
116 FT_Byte* ins_buf; /* new instruction data */
118 FT_Short num_contours; /* >= 0 for simple glyphs */
119 FT_UShort num_points; /* number of points in a simple glyph */
121 FT_UShort num_components;
122 FT_UShort* components; /* the subglyph indices of a composite glyph */
124 FT_UShort num_pointsums;
125 FT_UShort* pointsums; /* the pointsums of all composite elements */
126 /* (after walking recursively over all subglyphs) */
128 FT_UShort num_composite_contours; /* after recursion */
129 } GLYPH;
131 /* a representation of the data in the `glyf' table */
132 typedef struct glyf_Data_
134 FT_UShort num_glyphs;
135 GLYPH* glyphs;
137 /* this field gives the `master' globals for a `glyf' table; */
138 /* see function `TA_sfnt_handle_coverage' */
139 TA_FaceGlobals master_globals;
140 /* for coverage bookkeeping */
141 FT_Bool adjusted;
143 /* if a `glyf' table gets used in more than one subfont, */
144 /* so do `cvt', `fpgm', and `prep' tables: */
145 /* these four tables are always handled in parallel */
146 FT_ULong cvt_idx;
147 FT_ULong fpgm_idx;
148 FT_ULong prep_idx;
150 /* styles present in a font get a running number */
151 FT_UInt style_ids[TA_STYLE_MAX];
152 FT_UInt num_used_styles;
154 /* we have separate CVT data for each style */
155 FT_UInt cvt_offsets[TA_STYLE_MAX];
156 FT_UInt cvt_horz_width_sizes[TA_STYLE_MAX];
157 FT_UInt cvt_vert_width_sizes[TA_STYLE_MAX];
158 FT_UInt cvt_blue_zone_sizes[TA_STYLE_MAX];
159 FT_UInt cvt_blue_adjustment_offsets[TA_STYLE_MAX];
160 } glyf_Data;
162 /* an SFNT table */
163 typedef struct SFNT_Table_
165 FT_ULong tag;
166 FT_ULong len;
167 FT_Byte* buf; /* the table data */
168 FT_ULong offset; /* from beginning of file */
169 FT_ULong checksum;
170 void* data; /* used e.g. for `glyf' table data */
171 FT_Bool processed;
172 } SFNT_Table;
174 /* we use indices into the SFNT table array to */
175 /* represent table info records of the TTF header */
176 typedef FT_ULong SFNT_Table_Info;
178 /* this structure is used to model a TTF or a subfont within a TTC */
179 typedef struct SFNT_
181 FT_Face face;
183 SFNT_Table_Info* table_infos;
184 FT_ULong num_table_infos;
186 /* various SFNT table indices */
187 FT_ULong glyf_idx;
188 FT_ULong loca_idx;
189 FT_ULong head_idx;
190 FT_ULong hmtx_idx;
191 FT_ULong maxp_idx;
192 FT_ULong name_idx;
193 FT_ULong post_idx;
194 FT_ULong OS2_idx;
195 FT_ULong GPOS_idx;
197 /* values necessary to update the `maxp' table */
198 FT_UShort max_composite_points;
199 FT_UShort max_composite_contours;
200 FT_UShort max_storage;
201 FT_UShort max_stack_elements;
202 FT_UShort max_twilight_points;
203 FT_UShort max_instructions;
204 FT_UShort max_components;
205 } SFNT;
207 typedef struct Control_ Control;
209 /* our font object; the `FONT' typedef is in `taloader.h' */
210 struct FONT_
212 FT_Library lib;
214 FT_Byte* in_buf;
215 size_t in_len;
217 FT_Byte* out_buf;
218 size_t out_len;
220 char* control_buf;
221 size_t control_len;
223 SFNT* sfnts;
224 FT_Long num_sfnts;
226 SFNT_Table* tables;
227 FT_ULong num_tables;
229 FT_Bool have_DSIG;
231 /* we have a single `gasp' table for all subfonts */
232 FT_ULong gasp_idx;
234 /* the control instructions */
235 Control* control;
237 /* two generic pointers into the control instructions tree */
238 void* control_data_head;
239 void* control_data_cur;
241 /* two fields for handling one-point segment directions */
242 /* of the current glyph */
243 void* control_segment_dirs_head;
244 void* control_segment_dirs_cur;
246 TA_LoaderRec loader[1]; /* the interface to the autohinter */
248 /* configuration options */
249 TA_Progress_Func progress;
250 void* progress_data;
251 TA_Info_Func info;
252 TA_Info_Post_Func info_post;
253 void* info_data;
254 FT_UInt hinting_range_min;
255 FT_UInt hinting_range_max;
256 FT_UInt hinting_limit;
257 FT_UInt increase_x_height;
258 number_range* x_height_snapping_exceptions;
259 FT_UInt fallback_stem_width;
260 FT_Bool gray_strong_stem_width;
261 FT_Bool gdi_cleartype_strong_stem_width;
262 FT_Bool dw_cleartype_strong_stem_width;
263 FT_Bool windows_compatibility;
264 FT_Bool adjust_subglyphs;
265 FT_Bool hint_composites;
266 FT_Bool ignore_restrictions;
267 TA_Style fallback_style;
268 TA_Script default_script;
269 FT_Bool symbol;
270 FT_Bool dehint;
271 FT_Bool debug;
272 FT_Bool TTFA_info;
276 #include "tatables.h"
277 #include "tabytecode.h"
278 #include "tacontrol.h"
281 /* in file `tascript.c' */
282 extern const char* script_names[];
285 const char*
286 TA_get_error_message(FT_Error error);
288 char*
289 TA_font_dump_parameters(FONT* font,
290 FT_Bool format);
292 void
293 TA_get_current_time(FT_ULong* high,
294 FT_ULong* low);
296 FT_Byte*
297 TA_build_push(FT_Byte* bufp,
298 FT_UInt* args,
299 FT_UInt num_args,
300 FT_Bool need_words,
301 FT_Bool optimize);
303 FT_Error
304 TA_font_init(FONT* font);
305 void
306 TA_font_unload(FONT* font,
307 const char* in_buf,
308 char** out_bufp,
309 const char* control_buf);
311 FT_Error
312 TA_font_file_read(FONT* font,
313 FILE* in_file);
314 FT_Error
315 TA_font_file_write(FONT* font,
316 FILE* out_file);
317 FT_Error
318 TA_control_file_read(FONT* font,
319 FILE* control_file);
321 FT_Error
322 TA_sfnt_build_glyph_instructions(SFNT* sfnt,
323 FONT* font,
324 FT_Long idx);
326 FT_Error
327 TA_sfnt_split_into_SFNT_tables(SFNT* sfnt,
328 FONT* font);
330 FT_Error
331 TA_sfnt_build_cvt_table(SFNT* sfnt,
332 FONT* font);
334 FT_Error
335 TA_table_build_TTFA(FT_Byte** TTFA,
336 FT_ULong* TTFA_len,
337 FONT* font);
339 FT_Error
340 TA_table_build_DSIG(FT_Byte** DSIG);
342 FT_Error
343 TA_sfnt_build_fpgm_table(SFNT* sfnt,
344 FONT* font);
346 FT_Error
347 TA_sfnt_build_gasp_table(SFNT* sfnt,
348 FONT* font);
350 FT_Error
351 TA_sfnt_split_glyf_table(SFNT* sfnt,
352 FONT* font);
353 FT_Error
354 TA_sfnt_build_glyf_table(SFNT* sfnt,
355 FONT* font);
356 FT_Error
357 TA_sfnt_create_glyf_data(SFNT* sfnt,
358 FONT* font);
359 FT_Error
360 TA_sfnt_handle_coverage(SFNT* sfnt,
361 FONT* font);
362 void
363 TA_sfnt_adjust_coverage(SFNT* sfnt,
364 FONT* font);
365 #if 0
366 void
367 TA_sfnt_copy_master_coverage(SFNT* sfnt,
368 FONT* font);
369 #endif
371 FT_Error
372 TA_sfnt_update_GPOS_table(SFNT* sfnt,
373 FONT* font);
375 FT_Error
376 TA_sfnt_update_hmtx_table(SFNT* sfnt,
377 FONT* font);
379 FT_Error
380 TA_sfnt_build_loca_table(SFNT* sfnt,
381 FONT* font);
383 FT_Error
384 TA_sfnt_update_maxp_table(SFNT* sfnt,
385 FONT* font);
387 FT_Error
388 TA_sfnt_update_post_table(SFNT* sfnt,
389 FONT* font);
391 FT_Error
392 TA_sfnt_update_name_table(SFNT* sfnt,
393 FONT* font);
395 FT_Error
396 TA_sfnt_build_prep_table(SFNT* sfnt,
397 FONT* font);
399 FT_Error
400 TA_sfnt_build_TTF_header(SFNT* sfnt,
401 FONT* font,
402 FT_Byte** header_buf,
403 FT_ULong* header_len,
404 FT_Int do_complete);
405 FT_Error
406 TA_font_build_TTF(FONT* font);
408 FT_Error
409 TA_font_build_TTC(FONT* font);
411 #endif /* __TA_H__ */
413 /* end of ta.h */