s/lower_upper/upper_lower/.
[ttfautohint.git] / lib / ta.h
blob550001685ce8567e8cbf6d94fe84b8f7c802ba8a
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 "tadummy.h"
28 #include "talatin.h"
30 #include <ttfautohint.h>
33 #define TTFAUTOHINT_GLYPH ".ttfautohint"
34 #define TTFAUTOHINT_GLYPH_FIRST_BYTE "\x0C" /* first byte is string length */
35 #define TTFAUTOHINT_GLYPH_LEN 13
37 /* these macros convert 16bit and 32bit numbers into single bytes */
38 /* using the byte order needed within SFNT files */
40 #define HIGH(x) (FT_Byte)(((x) & 0xFF00) >> 8)
41 #define LOW(x) ((x) & 0x00FF)
43 #define BYTE1(x) (FT_Byte)(((x) & 0xFF000000UL) >> 24);
44 #define BYTE2(x) (FT_Byte)(((x) & 0x00FF0000UL) >> 16);
45 #define BYTE3(x) (FT_Byte)(((x) & 0x0000FF00UL) >> 8);
46 #define BYTE4(x) ((x) & 0x000000FFUL);
49 /* the length of a dummy `DSIG' table */
50 #define DSIG_LEN 8
52 /* the length of our `gasp' table */
53 #define GASP_LEN 8
55 /* an empty slot in the table info array */
56 #define MISSING (FT_ULong)~0
58 /* the offset to the loca table format in the `head' table */
59 #define LOCA_FORMAT_OFFSET 51
61 /* various offsets within the `maxp' table */
62 #define MAXP_NUM_GLYPHS 4
63 #define MAXP_MAX_COMPOSITE_POINTS 10
64 #define MAXP_MAX_COMPOSITE_CONTOURS 12
65 #define MAXP_MAX_ZONES_OFFSET 14
66 #define MAXP_MAX_TWILIGHT_POINTS_OFFSET 16
67 #define MAXP_MAX_STORAGE_OFFSET 18
68 #define MAXP_MAX_FUNCTION_DEFS_OFFSET 20
69 #define MAXP_MAX_INSTRUCTION_DEFS_OFFSET 22
70 #define MAXP_MAX_STACK_ELEMENTS_OFFSET 24
71 #define MAXP_MAX_INSTRUCTIONS_OFFSET 26
72 #define MAXP_MAX_COMPONENTS_OFFSET 28
74 #define MAXP_LEN 32
76 /* the offset of the type flags field in the `OS/2' table */
77 #define OS2_FSTYPE_OFFSET 8
80 /* flags in composite glyph records */
81 #define ARGS_ARE_WORDS 0x0001
82 #define ARGS_ARE_XY_VALUES 0x0002
83 #define WE_HAVE_A_SCALE 0x0008
84 #define MORE_COMPONENTS 0x0020
85 #define WE_HAVE_AN_XY_SCALE 0x0040
86 #define WE_HAVE_A_2X2 0x0080
87 #define WE_HAVE_INSTR 0x0100
89 /* flags in simple glyph records */
90 #define ON_CURVE 0x01
91 #define X_SHORT_VECTOR 0x02
92 #define Y_SHORT_VECTOR 0x04
93 #define REPEAT 0x08
94 #define SAME_X 0x10
95 #define SAME_Y 0x20
98 /* a single glyph */
99 typedef struct GLYPH_
101 FT_ULong len1; /* number of bytes before instruction related data */
102 FT_ULong len2; /* number of bytes after instruction related data; */
103 /* if zero, this indicates a composite glyph */
104 FT_Byte* buf; /* extracted glyph data (without instruction related data) */
105 FT_ULong flags_offset; /* offset to last flag in a composite glyph */
107 FT_ULong ins_len; /* number of new instructions */
108 FT_Byte* ins_buf; /* new instruction data */
110 FT_Short num_contours; /* >= 0 for simple glyphs */
111 FT_UShort num_points; /* number of points in a simple glyph */
113 FT_UShort num_components;
114 FT_UShort* components; /* the subglyph indices of a composite glyph */
116 FT_UShort num_pointsums;
117 FT_UShort* pointsums; /* the pointsums of all composite elements */
118 /* (after walking recursively over all subglyphs) */
120 FT_UShort num_composite_contours; /* after recursion */
121 } GLYPH;
123 /* a representation of the data in the `glyf' table */
124 typedef struct glyf_Data_
126 FT_UShort num_glyphs;
127 GLYPH* glyphs;
128 } glyf_Data;
130 /* an SFNT table */
131 typedef struct SFNT_Table_
133 FT_ULong tag;
134 FT_ULong len;
135 FT_Byte* buf; /* the table data */
136 FT_ULong offset; /* from beginning of file */
137 FT_ULong checksum;
138 void* data; /* used e.g. for `glyf' table data */
139 FT_Bool processed;
140 } SFNT_Table;
142 /* we use indices into the SFNT table array to */
143 /* represent table info records of the TTF header */
144 typedef FT_ULong SFNT_Table_Info;
146 /* this structure is used to model a TTF or a subfont within a TTC */
147 typedef struct SFNT_
149 FT_Face face;
151 SFNT_Table_Info* table_infos;
152 FT_ULong num_table_infos;
154 /* various SFNT table indices */
155 FT_ULong glyf_idx;
156 FT_ULong loca_idx;
157 FT_ULong head_idx;
158 FT_ULong hmtx_idx;
159 FT_ULong maxp_idx;
160 FT_ULong name_idx;
161 FT_ULong post_idx;
162 FT_ULong OS2_idx;
163 FT_ULong GPOS_idx;
165 /* values necessary to update the `maxp' table */
166 FT_UShort max_composite_points;
167 FT_UShort max_composite_contours;
168 FT_UShort max_storage;
169 FT_UShort max_stack_elements;
170 FT_UShort max_twilight_points;
171 FT_UShort max_instructions;
172 FT_UShort max_components;
173 } SFNT;
175 /* our font object */
176 typedef struct FONT_
178 FT_Library lib;
180 FT_Byte* in_buf;
181 size_t in_len;
183 FT_Byte* out_buf;
184 size_t out_len;
186 SFNT* sfnts;
187 FT_Long num_sfnts;
189 SFNT_Table* tables;
190 FT_ULong num_tables;
192 FT_Bool have_DSIG;
194 TA_LoaderRec loader[1]; /* the interface to the autohinter */
196 /* configuration options */
197 TA_Progress_Func progress;
198 void* progress_data;
199 TA_Info_Func info;
200 void* info_data;
201 FT_UInt hinting_range_min;
202 FT_UInt hinting_range_max;
203 FT_UInt hinting_limit;
204 FT_Bool pre_hinting;
205 FT_Bool increase_x_height;
206 FT_Bool no_x_height_snapping;
207 FT_Byte* x_height_snapping_exceptions;
208 FT_Bool ignore_permissions;
209 FT_UInt fallback_script;
210 FT_Bool symbol;
211 } FONT;
214 #include "tatables.h"
215 #include "tabytecode.h"
218 const char*
219 TA_get_error_message(FT_Error error);
221 void
222 TA_get_current_time(FT_ULong* high,
223 FT_ULong* low);
225 FT_Error
226 TA_font_init(FONT* font);
227 void
228 TA_font_unload(FONT* font,
229 const char* in_buf,
230 char** out_bufp);
232 FT_Error
233 TA_font_file_read(FONT* font,
234 FILE* in_file);
235 FT_Error
236 TA_font_file_write(FONT* font,
237 FILE* out_file);
239 FT_Error
240 TA_sfnt_build_glyph_instructions(SFNT* sfnt,
241 FONT* font,
242 FT_Long idx);
244 FT_Error
245 TA_sfnt_split_into_SFNT_tables(SFNT* sfnt,
246 FONT* font);
248 FT_Error
249 TA_sfnt_build_cvt_table(SFNT* sfnt,
250 FONT* font);
252 FT_Error
253 TA_table_build_DSIG(FT_Byte** DSIG);
255 FT_Error
256 TA_sfnt_build_fpgm_table(SFNT* sfnt,
257 FONT* font);
259 FT_Error
260 TA_sfnt_build_gasp_table(SFNT* sfnt,
261 FONT* font);
263 FT_Error
264 TA_sfnt_build_glyf_hints(SFNT* sfnt,
265 FONT* font);
266 FT_Error
267 TA_sfnt_split_glyf_table(SFNT* sfnt,
268 FONT* font);
269 FT_Error
270 TA_sfnt_build_glyf_table(SFNT* sfnt,
271 FONT* font);
272 FT_Error
273 TA_sfnt_create_glyf_data(SFNT* sfnt,
274 FONT* font);
276 FT_Error
277 TA_sfnt_update_GPOS_table(SFNT* sfnt,
278 FONT* font);
280 FT_Error
281 TA_sfnt_update_hmtx_table(SFNT* sfnt,
282 FONT* font);
284 FT_Error
285 TA_sfnt_build_loca_table(SFNT* sfnt,
286 FONT* font);
288 FT_Error
289 TA_sfnt_update_maxp_table(SFNT* sfnt,
290 FONT* font);
292 FT_Error
293 TA_sfnt_update_post_table(SFNT* sfnt,
294 FONT* font);
296 FT_Error
297 TA_sfnt_update_name_table(SFNT* sfnt,
298 FONT* font);
300 FT_Error
301 TA_sfnt_build_prep_table(SFNT* sfnt,
302 FONT* font);
304 FT_Error
305 TA_sfnt_build_TTF_header(SFNT* sfnt,
306 FONT* font,
307 FT_Byte** header_buf,
308 FT_ULong* header_len,
309 FT_Int do_complete);
310 FT_Error
311 TA_font_build_TTF(FONT* font);
313 FT_Error
314 TA_font_build_TTC(FONT* font);
316 #endif /* __TA_H__ */
318 /* end of ta.h */