Add options `deltas-file', `deltas-buffer', and `deltas-buffer-len'.
[ttfautohint.git] / lib / ta.h
blob9947628f9ad0bf3f33b60b91c73fe8b14ebe8e4b
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 "taloader.h"
27 #include "taglobal.h"
28 #include "tadummy.h"
29 #include "talatin.h"
31 #include <ttfautohint.h>
32 #include <numberset.h>
33 #include <tadeltas.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 /* the length of a dummy `DSIG' table */
53 #define DSIG_LEN 8
55 /* the length of our `gasp' table */
56 #define GASP_LEN 8
58 /* an empty slot in the table info array */
59 #define MISSING (FT_ULong)~0
61 /* the offset to the loca table format in the `head' table */
62 #define LOCA_FORMAT_OFFSET 51
64 /* various offsets within the `maxp' table */
65 #define MAXP_NUM_GLYPHS 4
66 #define MAXP_MAX_COMPOSITE_POINTS 10
67 #define MAXP_MAX_COMPOSITE_CONTOURS 12
68 #define MAXP_MAX_ZONES_OFFSET 14
69 #define MAXP_MAX_TWILIGHT_POINTS_OFFSET 16
70 #define MAXP_MAX_STORAGE_OFFSET 18
71 #define MAXP_MAX_FUNCTION_DEFS_OFFSET 20
72 #define MAXP_MAX_INSTRUCTION_DEFS_OFFSET 22
73 #define MAXP_MAX_STACK_ELEMENTS_OFFSET 24
74 #define MAXP_MAX_INSTRUCTIONS_OFFSET 26
75 #define MAXP_MAX_COMPONENTS_OFFSET 28
77 #define MAXP_LEN 32
79 /* the offset of the type flags field in the `OS/2' table */
80 #define OS2_FSTYPE_OFFSET 8
83 /* flags in composite glyph records */
84 #define ARGS_ARE_WORDS 0x0001
85 #define ARGS_ARE_XY_VALUES 0x0002
86 #define WE_HAVE_A_SCALE 0x0008
87 #define MORE_COMPONENTS 0x0020
88 #define WE_HAVE_AN_XY_SCALE 0x0040
89 #define WE_HAVE_A_2X2 0x0080
90 #define WE_HAVE_INSTR 0x0100
92 /* flags in simple glyph records */
93 #define ON_CURVE 0x01
94 #define X_SHORT_VECTOR 0x02
95 #define Y_SHORT_VECTOR 0x04
96 #define REPEAT 0x08
97 #define SAME_X 0x10
98 #define SAME_Y 0x20
101 /* a single glyph */
102 typedef struct GLYPH_
104 FT_ULong len1; /* number of bytes before instruction related data */
105 FT_ULong len2; /* number of bytes after instruction related data; */
106 /* if zero, this indicates a composite glyph */
107 FT_Byte* buf; /* extracted glyph data (without instruction related data) */
108 FT_ULong flags_offset; /* offset to last flag in a composite glyph */
110 FT_ULong ins_len; /* number of new instructions */
111 FT_Byte* ins_buf; /* new instruction data */
113 FT_Short num_contours; /* >= 0 for simple glyphs */
114 FT_UShort num_points; /* number of points in a simple glyph */
116 FT_UShort num_components;
117 FT_UShort* components; /* the subglyph indices of a composite glyph */
119 FT_UShort num_pointsums;
120 FT_UShort* pointsums; /* the pointsums of all composite elements */
121 /* (after walking recursively over all subglyphs) */
123 FT_UShort num_composite_contours; /* after recursion */
124 } GLYPH;
126 /* a representation of the data in the `glyf' table */
127 typedef struct glyf_Data_
129 FT_UShort num_glyphs;
130 GLYPH* glyphs;
132 /* this field gives the `master' globals for a `glyf' table; */
133 /* see function `TA_sfnt_handle_coverage' */
134 TA_FaceGlobals master_globals;
135 /* for coverage bookkeeping */
136 FT_Bool adjusted;
138 /* if a `glyf' table gets used in more than one subfont, */
139 /* so do `cvt', `fpgm', and `prep' tables: */
140 /* these four tables are always handled in parallel */
141 FT_ULong cvt_idx;
142 FT_ULong fpgm_idx;
143 FT_ULong prep_idx;
145 /* styles present in a font get a running number */
146 FT_UInt style_ids[TA_STYLE_MAX];
147 FT_UInt num_used_styles;
149 /* we have separate CVT data for each style */
150 FT_UInt cvt_offsets[TA_STYLE_MAX];
151 FT_UInt cvt_horz_width_sizes[TA_STYLE_MAX];
152 FT_UInt cvt_vert_width_sizes[TA_STYLE_MAX];
153 FT_UInt cvt_blue_zone_sizes[TA_STYLE_MAX];
154 FT_UInt cvt_blue_adjustment_offsets[TA_STYLE_MAX];
155 } glyf_Data;
157 /* an SFNT table */
158 typedef struct SFNT_Table_
160 FT_ULong tag;
161 FT_ULong len;
162 FT_Byte* buf; /* the table data */
163 FT_ULong offset; /* from beginning of file */
164 FT_ULong checksum;
165 void* data; /* used e.g. for `glyf' table data */
166 FT_Bool processed;
167 } SFNT_Table;
169 /* we use indices into the SFNT table array to */
170 /* represent table info records of the TTF header */
171 typedef FT_ULong SFNT_Table_Info;
173 /* this structure is used to model a TTF or a subfont within a TTC */
174 typedef struct SFNT_
176 FT_Face face;
178 SFNT_Table_Info* table_infos;
179 FT_ULong num_table_infos;
181 /* various SFNT table indices */
182 FT_ULong glyf_idx;
183 FT_ULong loca_idx;
184 FT_ULong head_idx;
185 FT_ULong hmtx_idx;
186 FT_ULong maxp_idx;
187 FT_ULong name_idx;
188 FT_ULong post_idx;
189 FT_ULong OS2_idx;
190 FT_ULong GPOS_idx;
192 /* values necessary to update the `maxp' table */
193 FT_UShort max_composite_points;
194 FT_UShort max_composite_contours;
195 FT_UShort max_storage;
196 FT_UShort max_stack_elements;
197 FT_UShort max_twilight_points;
198 FT_UShort max_instructions;
199 FT_UShort max_components;
200 } SFNT;
202 /* our font object */
203 struct FONT_
205 FT_Library lib;
207 FT_Byte* in_buf;
208 size_t in_len;
210 FT_Byte* out_buf;
211 size_t out_len;
213 char* deltas_buf;
214 size_t deltas_len;
216 SFNT* sfnts;
217 FT_Long num_sfnts;
219 SFNT_Table* tables;
220 FT_ULong num_tables;
222 FT_Bool have_DSIG;
224 /* we have a single `gasp' table for all subfonts */
225 FT_ULong gasp_idx;
227 /* two generic pointers into the the delta exceptions tree */
228 void* deltas_data_head;
229 void* deltas_data_cur;
231 TA_LoaderRec loader[1]; /* the interface to the autohinter */
233 /* configuration options */
234 TA_Progress_Func progress;
235 void* progress_data;
236 TA_Info_Func info;
237 void* info_data;
238 FT_UInt hinting_range_min;
239 FT_UInt hinting_range_max;
240 FT_UInt hinting_limit;
241 FT_UInt increase_x_height;
242 number_range* x_height_snapping_exceptions;
243 FT_UInt fallback_stem_width;
244 FT_Bool gray_strong_stem_width;
245 FT_Bool gdi_cleartype_strong_stem_width;
246 FT_Bool dw_cleartype_strong_stem_width;
247 FT_Bool windows_compatibility;
248 FT_Bool adjust_subglyphs;
249 FT_Bool hint_composites;
250 FT_Bool ignore_restrictions;
251 TA_Style fallback_style;
252 TA_Script default_script;
253 FT_Bool symbol;
254 FT_Bool dehint;
255 FT_Bool debug;
259 #include "tatables.h"
260 #include "tabytecode.h"
263 const char*
264 TA_get_error_message(FT_Error error);
266 void
267 TA_get_current_time(FT_ULong* high,
268 FT_ULong* low);
270 FT_Byte*
271 TA_build_push(FT_Byte* bufp,
272 FT_UInt* args,
273 FT_UInt num_args,
274 FT_Bool need_words,
275 FT_Bool optimize);
277 FT_Error
278 TA_font_init(FONT* font);
279 void
280 TA_font_unload(FONT* font,
281 const char* in_buf,
282 char** out_bufp,
283 const char* deltas_buf);
285 FT_Error
286 TA_font_file_read(FONT* font,
287 FILE* in_file);
288 FT_Error
289 TA_font_file_write(FONT* font,
290 FILE* out_file);
291 FT_Error
292 TA_deltas_file_read(FONT* font,
293 FILE* deltas_file);
295 FT_Error
296 TA_sfnt_build_glyph_instructions(SFNT* sfnt,
297 FONT* font,
298 FT_Long idx);
300 FT_Error
301 TA_sfnt_split_into_SFNT_tables(SFNT* sfnt,
302 FONT* font);
304 FT_Error
305 TA_sfnt_build_cvt_table(SFNT* sfnt,
306 FONT* font);
308 FT_Error
309 TA_table_build_DSIG(FT_Byte** DSIG);
311 FT_Error
312 TA_sfnt_build_fpgm_table(SFNT* sfnt,
313 FONT* font);
315 FT_Error
316 TA_sfnt_build_gasp_table(SFNT* sfnt,
317 FONT* font);
319 FT_Error
320 TA_sfnt_split_glyf_table(SFNT* sfnt,
321 FONT* font);
322 FT_Error
323 TA_sfnt_build_glyf_table(SFNT* sfnt,
324 FONT* font);
325 FT_Error
326 TA_sfnt_create_glyf_data(SFNT* sfnt,
327 FONT* font);
328 FT_Error
329 TA_sfnt_handle_coverage(SFNT* sfnt,
330 FONT* font);
331 void
332 TA_sfnt_adjust_coverage(SFNT* sfnt,
333 FONT* font);
334 #if 0
335 void
336 TA_sfnt_copy_master_coverage(SFNT* sfnt,
337 FONT* font);
338 #endif
340 FT_Error
341 TA_sfnt_update_GPOS_table(SFNT* sfnt,
342 FONT* font);
344 FT_Error
345 TA_sfnt_update_hmtx_table(SFNT* sfnt,
346 FONT* font);
348 FT_Error
349 TA_sfnt_build_loca_table(SFNT* sfnt,
350 FONT* font);
352 FT_Error
353 TA_sfnt_update_maxp_table(SFNT* sfnt,
354 FONT* font);
356 FT_Error
357 TA_sfnt_update_post_table(SFNT* sfnt,
358 FONT* font);
360 FT_Error
361 TA_sfnt_update_name_table(SFNT* sfnt,
362 FONT* font);
364 FT_Error
365 TA_sfnt_build_prep_table(SFNT* sfnt,
366 FONT* font);
368 FT_Error
369 TA_sfnt_build_TTF_header(SFNT* sfnt,
370 FONT* font,
371 FT_Byte** header_buf,
372 FT_ULong* header_len,
373 FT_Int do_complete);
374 FT_Error
375 TA_font_build_TTF(FONT* font);
377 FT_Error
378 TA_font_build_TTC(FONT* font);
380 #endif /* __TA_H__ */
382 /* end of ta.h */