Add option `TTFA-info' to library.
[ttfautohint.git] / lib / ta.h
blobe2f4c6884b047096995e2fd26b735395bafa7f35
1 /* ta.h */
3 /*
4 * Copyright (C) 2011-2014 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 <numberset.h>
29 #include "taloader.h"
30 #include "taglobal.h"
31 #include "tadummy.h"
32 #include "talatin.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 /* an SFNT tag for our information table */
52 #define TTAG_TTFA FT_MAKE_TAG('T', 'T', 'F', 'A')
54 /* the length of a dummy `DSIG' table */
55 #define DSIG_LEN 8
57 /* the length of our `gasp' table */
58 #define GASP_LEN 8
60 /* an empty slot in the table info array */
61 #define MISSING (FT_ULong)~0
63 /* the offset to the loca table format in the `head' table */
64 #define LOCA_FORMAT_OFFSET 51
66 /* various offsets within the `maxp' table */
67 #define MAXP_NUM_GLYPHS 4
68 #define MAXP_MAX_COMPOSITE_POINTS 10
69 #define MAXP_MAX_COMPOSITE_CONTOURS 12
70 #define MAXP_MAX_ZONES_OFFSET 14
71 #define MAXP_MAX_TWILIGHT_POINTS_OFFSET 16
72 #define MAXP_MAX_STORAGE_OFFSET 18
73 #define MAXP_MAX_FUNCTION_DEFS_OFFSET 20
74 #define MAXP_MAX_INSTRUCTION_DEFS_OFFSET 22
75 #define MAXP_MAX_STACK_ELEMENTS_OFFSET 24
76 #define MAXP_MAX_INSTRUCTIONS_OFFSET 26
77 #define MAXP_MAX_COMPONENTS_OFFSET 28
79 #define MAXP_LEN 32
81 /* the offset of the type flags field in the `OS/2' table */
82 #define OS2_FSTYPE_OFFSET 8
85 /* flags in composite glyph records */
86 #define ARGS_ARE_WORDS 0x0001
87 #define ARGS_ARE_XY_VALUES 0x0002
88 #define WE_HAVE_A_SCALE 0x0008
89 #define MORE_COMPONENTS 0x0020
90 #define WE_HAVE_AN_XY_SCALE 0x0040
91 #define WE_HAVE_A_2X2 0x0080
92 #define WE_HAVE_INSTR 0x0100
94 /* flags in simple glyph records */
95 #define ON_CURVE 0x01
96 #define X_SHORT_VECTOR 0x02
97 #define Y_SHORT_VECTOR 0x04
98 #define REPEAT 0x08
99 #define SAME_X 0x10
100 #define SAME_Y 0x20
103 /* a single glyph */
104 typedef struct GLYPH_
106 FT_ULong len1; /* number of bytes before instruction related data */
107 FT_ULong len2; /* number of bytes after instruction related data; */
108 /* if zero, this indicates a composite glyph */
109 FT_Byte* buf; /* extracted glyph data (without instruction related data) */
110 FT_ULong flags_offset; /* offset to last flag in a composite glyph */
112 FT_ULong ins_len; /* number of new instructions */
113 FT_Byte* ins_buf; /* new instruction data */
115 FT_Short num_contours; /* >= 0 for simple glyphs */
116 FT_UShort num_points; /* number of points in a simple glyph */
118 FT_UShort num_components;
119 FT_UShort* components; /* the subglyph indices of a composite glyph */
121 FT_UShort num_pointsums;
122 FT_UShort* pointsums; /* the pointsums of all composite elements */
123 /* (after walking recursively over all subglyphs) */
125 FT_UShort num_composite_contours; /* after recursion */
126 } GLYPH;
128 /* a representation of the data in the `glyf' table */
129 typedef struct glyf_Data_
131 FT_UShort num_glyphs;
132 GLYPH* glyphs;
134 /* this field gives the `master' globals for a `glyf' table; */
135 /* see function `TA_sfnt_handle_coverage' */
136 TA_FaceGlobals master_globals;
137 /* for coverage bookkeeping */
138 FT_Bool adjusted;
140 /* if a `glyf' table gets used in more than one subfont, */
141 /* so do `cvt', `fpgm', and `prep' tables: */
142 /* these four tables are always handled in parallel */
143 FT_ULong cvt_idx;
144 FT_ULong fpgm_idx;
145 FT_ULong prep_idx;
147 /* styles present in a font get a running number */
148 FT_UInt style_ids[TA_STYLE_MAX];
149 FT_UInt num_used_styles;
151 /* we have separate CVT data for each style */
152 FT_UInt cvt_offsets[TA_STYLE_MAX];
153 FT_UInt cvt_horz_width_sizes[TA_STYLE_MAX];
154 FT_UInt cvt_vert_width_sizes[TA_STYLE_MAX];
155 FT_UInt cvt_blue_zone_sizes[TA_STYLE_MAX];
156 FT_UInt cvt_blue_adjustment_offsets[TA_STYLE_MAX];
157 } glyf_Data;
159 /* an SFNT table */
160 typedef struct SFNT_Table_
162 FT_ULong tag;
163 FT_ULong len;
164 FT_Byte* buf; /* the table data */
165 FT_ULong offset; /* from beginning of file */
166 FT_ULong checksum;
167 void* data; /* used e.g. for `glyf' table data */
168 FT_Bool processed;
169 } SFNT_Table;
171 /* we use indices into the SFNT table array to */
172 /* represent table info records of the TTF header */
173 typedef FT_ULong SFNT_Table_Info;
175 /* this structure is used to model a TTF or a subfont within a TTC */
176 typedef struct SFNT_
178 FT_Face face;
180 SFNT_Table_Info* table_infos;
181 FT_ULong num_table_infos;
183 /* various SFNT table indices */
184 FT_ULong glyf_idx;
185 FT_ULong loca_idx;
186 FT_ULong head_idx;
187 FT_ULong hmtx_idx;
188 FT_ULong maxp_idx;
189 FT_ULong name_idx;
190 FT_ULong post_idx;
191 FT_ULong OS2_idx;
192 FT_ULong GPOS_idx;
194 /* values necessary to update the `maxp' table */
195 FT_UShort max_composite_points;
196 FT_UShort max_composite_contours;
197 FT_UShort max_storage;
198 FT_UShort max_stack_elements;
199 FT_UShort max_twilight_points;
200 FT_UShort max_instructions;
201 FT_UShort max_components;
202 } SFNT;
204 typedef struct Deltas_ Deltas;
206 /* our font object; the `FONT' typedef is in `taloader.h' */
207 struct FONT_
209 FT_Library lib;
211 FT_Byte* in_buf;
212 size_t in_len;
214 FT_Byte* out_buf;
215 size_t out_len;
217 char* deltas_buf;
218 size_t deltas_len;
220 SFNT* sfnts;
221 FT_Long num_sfnts;
223 SFNT_Table* tables;
224 FT_ULong num_tables;
226 FT_Bool have_DSIG;
228 /* we have a single `gasp' table for all subfonts */
229 FT_ULong gasp_idx;
231 /* the delta exceptions data */
232 Deltas* deltas;
234 /* two generic pointers into the the delta exceptions tree */
235 void* deltas_data_head;
236 void* deltas_data_cur;
238 TA_LoaderRec loader[1]; /* the interface to the autohinter */
240 /* configuration options */
241 TA_Progress_Func progress;
242 void* progress_data;
243 TA_Info_Func info;
244 void* info_data;
245 FT_UInt hinting_range_min;
246 FT_UInt hinting_range_max;
247 FT_UInt hinting_limit;
248 FT_UInt increase_x_height;
249 number_range* x_height_snapping_exceptions;
250 FT_UInt fallback_stem_width;
251 FT_Bool gray_strong_stem_width;
252 FT_Bool gdi_cleartype_strong_stem_width;
253 FT_Bool dw_cleartype_strong_stem_width;
254 FT_Bool windows_compatibility;
255 FT_Bool adjust_subglyphs;
256 FT_Bool hint_composites;
257 FT_Bool ignore_restrictions;
258 TA_Style fallback_style;
259 TA_Script default_script;
260 FT_Bool symbol;
261 FT_Bool dehint;
262 FT_Bool debug;
263 FT_Bool TTFA_info;
267 #include "tatables.h"
268 #include "tabytecode.h"
269 #include "tadeltas.h"
272 /* in file `tascript.c' */
273 extern const char* script_names[];
276 const char*
277 TA_get_error_message(FT_Error error);
279 char*
280 TA_font_dump_parameters(FONT* font,
281 FT_Bool format);
283 void
284 TA_get_current_time(FT_ULong* high,
285 FT_ULong* low);
287 FT_Byte*
288 TA_build_push(FT_Byte* bufp,
289 FT_UInt* args,
290 FT_UInt num_args,
291 FT_Bool need_words,
292 FT_Bool optimize);
294 FT_Error
295 TA_font_init(FONT* font);
296 void
297 TA_font_unload(FONT* font,
298 const char* in_buf,
299 char** out_bufp,
300 const char* deltas_buf);
302 FT_Error
303 TA_font_file_read(FONT* font,
304 FILE* in_file);
305 FT_Error
306 TA_font_file_write(FONT* font,
307 FILE* out_file);
308 FT_Error
309 TA_deltas_file_read(FONT* font,
310 FILE* deltas_file);
312 FT_Error
313 TA_sfnt_build_glyph_instructions(SFNT* sfnt,
314 FONT* font,
315 FT_Long idx);
317 FT_Error
318 TA_sfnt_split_into_SFNT_tables(SFNT* sfnt,
319 FONT* font);
321 FT_Error
322 TA_sfnt_build_cvt_table(SFNT* sfnt,
323 FONT* font);
325 FT_Error
326 TA_table_build_TTFA(FT_Byte** TTFA,
327 FT_ULong* TTFA_len,
328 FONT* font);
330 FT_Error
331 TA_table_build_DSIG(FT_Byte** DSIG);
333 FT_Error
334 TA_sfnt_build_fpgm_table(SFNT* sfnt,
335 FONT* font);
337 FT_Error
338 TA_sfnt_build_gasp_table(SFNT* sfnt,
339 FONT* font);
341 FT_Error
342 TA_sfnt_split_glyf_table(SFNT* sfnt,
343 FONT* font);
344 FT_Error
345 TA_sfnt_build_glyf_table(SFNT* sfnt,
346 FONT* font);
347 FT_Error
348 TA_sfnt_create_glyf_data(SFNT* sfnt,
349 FONT* font);
350 FT_Error
351 TA_sfnt_handle_coverage(SFNT* sfnt,
352 FONT* font);
353 void
354 TA_sfnt_adjust_coverage(SFNT* sfnt,
355 FONT* font);
356 #if 0
357 void
358 TA_sfnt_copy_master_coverage(SFNT* sfnt,
359 FONT* font);
360 #endif
362 FT_Error
363 TA_sfnt_update_GPOS_table(SFNT* sfnt,
364 FONT* font);
366 FT_Error
367 TA_sfnt_update_hmtx_table(SFNT* sfnt,
368 FONT* font);
370 FT_Error
371 TA_sfnt_build_loca_table(SFNT* sfnt,
372 FONT* font);
374 FT_Error
375 TA_sfnt_update_maxp_table(SFNT* sfnt,
376 FONT* font);
378 FT_Error
379 TA_sfnt_update_post_table(SFNT* sfnt,
380 FONT* font);
382 FT_Error
383 TA_sfnt_update_name_table(SFNT* sfnt,
384 FONT* font);
386 FT_Error
387 TA_sfnt_build_prep_table(SFNT* sfnt,
388 FONT* font);
390 FT_Error
391 TA_sfnt_build_TTF_header(SFNT* sfnt,
392 FONT* font,
393 FT_Byte** header_buf,
394 FT_ULong* header_len,
395 FT_Int do_complete);
396 FT_Error
397 TA_font_build_TTF(FONT* font);
399 FT_Error
400 TA_font_build_TTC(FONT* font);
402 #endif /* __TA_H__ */
404 /* end of ta.h */