Version 0.6.1.
[ttfautohint.git] / src / ta.h
blobf780ca7a06089552ca549dc0102d933d02c03175
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 /* these macros convert 16bit and 32bit numbers into single bytes */
34 /* using the byte order needed within SFNT files */
36 #define HIGH(x) (FT_Byte)(((x) & 0xFF00) >> 8)
37 #define LOW(x) ((x) & 0x00FF)
39 #define BYTE1(x) (FT_Byte)(((x) & 0xFF000000UL) >> 24);
40 #define BYTE2(x) (FT_Byte)(((x) & 0x00FF0000UL) >> 16);
41 #define BYTE3(x) (FT_Byte)(((x) & 0x0000FF00UL) >> 8);
42 #define BYTE4(x) ((x) & 0x000000FFUL);
45 /* the length of a dummy `DSIG' table */
46 #define DSIG_LEN 8
48 /* the length of our `gasp' table */
49 #define GASP_LEN 8
51 /* an empty slot in the table info array */
52 #define MISSING (FT_ULong)~0
54 /* the offset to the loca table format in the `head' table */
55 #define LOCA_FORMAT_OFFSET 51
57 /* various offsets within the `maxp' table */
58 #define MAXP_NUM_GLYPHS 4
59 #define MAXP_MAX_COMPOSITE_POINTS 10
60 #define MAXP_MAX_COMPOSITE_CONTOURS 12
61 #define MAXP_MAX_ZONES_OFFSET 14
62 #define MAXP_MAX_TWILIGHT_POINTS_OFFSET 16
63 #define MAXP_MAX_STORAGE_OFFSET 18
64 #define MAXP_MAX_FUNCTION_DEFS_OFFSET 20
65 #define MAXP_MAX_INSTRUCTION_DEFS_OFFSET 22
66 #define MAXP_MAX_STACK_ELEMENTS_OFFSET 24
67 #define MAXP_MAX_INSTRUCTIONS_OFFSET 26
68 #define MAXP_MAX_COMPONENTS_OFFSET 28
70 #define MAXP_LEN 32
72 /* the offset of the type flags field in the `OS/2' table */
73 #define OS2_FSTYPE_OFFSET 8
76 /* flags in composite glyph records */
77 #define ARGS_ARE_WORDS 0x0001
78 #define ARGS_ARE_XY_VALUES 0x0002
79 #define WE_HAVE_A_SCALE 0x0008
80 #define MORE_COMPONENTS 0x0020
81 #define WE_HAVE_AN_XY_SCALE 0x0040
82 #define WE_HAVE_A_2X2 0x0080
83 #define WE_HAVE_INSTR 0x0100
85 /* flags in simple glyph records */
86 #define ON_CURVE 0x01
87 #define X_SHORT_VECTOR 0x02
88 #define Y_SHORT_VECTOR 0x04
89 #define REPEAT 0x08
90 #define SAME_X 0x10
91 #define SAME_Y 0x20
94 /* a single glyph */
95 typedef struct GLYPH_
97 FT_ULong len1; /* number of bytes before instruction related data */
98 FT_ULong len2; /* number of bytes after instruction related data; */
99 /* if zero, this indicates a composite glyph */
100 FT_Byte* buf; /* extracted glyph data (without instruction related data) */
101 FT_ULong flags_offset; /* offset to last flag in a composite glyph */
103 FT_ULong ins_len; /* number of new instructions */
104 FT_Byte* ins_buf; /* new instruction data */
106 FT_Short num_contours; /* >= 0 for simple glyphs */
107 FT_UShort num_points; /* number of points in a simple glyph */
109 FT_UShort num_components;
110 FT_UShort* components; /* the subglyph indices of a composite glyph */
112 FT_UShort num_pointsums;
113 FT_UShort* pointsums; /* the pointsums of all composite elements */
114 /* (after walking recursively over all subglyphs) */
116 FT_UShort num_composite_contours; /* after recursion */
117 } GLYPH;
119 /* a representation of the data in the `glyf' table */
120 typedef struct glyf_Data_
122 FT_UShort num_glyphs;
123 GLYPH* glyphs;
124 } glyf_Data;
126 /* an SFNT table */
127 typedef struct SFNT_Table_ {
128 FT_ULong tag;
129 FT_ULong len;
130 FT_Byte* buf; /* the table data */
131 FT_ULong offset; /* from beginning of file */
132 FT_ULong checksum;
133 void* data; /* used e.g. for `glyf' table data */
134 FT_Bool processed;
135 } SFNT_Table;
137 /* we use indices into the SFNT table array to */
138 /* represent table info records of the TTF header */
139 typedef FT_ULong SFNT_Table_Info;
141 /* this structure is used to model a TTF or a subfont within a TTC */
142 typedef struct SFNT_ {
143 FT_Face face;
145 SFNT_Table_Info* table_infos;
146 FT_ULong num_table_infos;
148 /* various SFNT table indices */
149 FT_ULong glyf_idx;
150 FT_ULong loca_idx;
151 FT_ULong head_idx;
152 FT_ULong hmtx_idx;
153 FT_ULong maxp_idx;
154 FT_ULong post_idx;
155 FT_ULong OS2_idx;
156 FT_ULong GPOS_idx;
158 /* values necessary to update the `maxp' table */
159 FT_UShort max_composite_points;
160 FT_UShort max_composite_contours;
161 FT_UShort max_storage;
162 FT_UShort max_stack_elements;
163 FT_UShort max_twilight_points;
164 FT_UShort max_instructions;
165 FT_UShort max_components;
166 } SFNT;
168 /* our font object */
169 typedef struct FONT_ {
170 FT_Library lib;
172 FT_Byte* in_buf;
173 size_t in_len;
175 FT_Byte* out_buf;
176 size_t out_len;
178 SFNT* sfnts;
179 FT_Long num_sfnts;
181 SFNT_Table* tables;
182 FT_ULong num_tables;
184 FT_Bool have_DSIG;
186 TA_LoaderRec loader[1]; /* the interface to the autohinter */
188 /* configuration options */
189 TA_Progress_Func progress;
190 void *progress_data;
191 FT_UInt hinting_range_min;
192 FT_UInt hinting_range_max;
193 FT_Bool pre_hinting;
194 FT_Bool no_x_height_snapping;
195 FT_Byte* x_height_snapping_exceptions;
196 FT_Bool ignore_permissions;
197 FT_UInt fallback_script;
198 } FONT;
201 #include "tatables.h"
202 #include "tabytecode.h"
205 const char*
206 TA_get_error_message(FT_Error error);
208 void
209 TA_get_current_time(FT_ULong *high,
210 FT_ULong *low);
212 FT_Error
213 TA_font_init(FONT* font);
214 void
215 TA_font_unload(FONT* font,
216 const char *in_buf,
217 char** out_bufp);
219 FT_Error
220 TA_font_file_read(FONT* font,
221 FILE* in_file);
222 FT_Error
223 TA_font_file_write(FONT* font,
224 FILE* out_file);
226 FT_Error
227 TA_sfnt_build_glyph_instructions(SFNT* sfnt,
228 FONT* font,
229 FT_Long idx);
231 FT_Error
232 TA_sfnt_split_into_SFNT_tables(SFNT* sfnt,
233 FONT* font);
235 FT_Error
236 TA_sfnt_build_cvt_table(SFNT* sfnt,
237 FONT* font);
239 FT_Error
240 TA_table_build_DSIG(FT_Byte** DSIG);
242 FT_Error
243 TA_sfnt_build_fpgm_table(SFNT* sfnt,
244 FONT* font);
246 FT_Error
247 TA_sfnt_build_gasp_table(SFNT* sfnt,
248 FONT* font);
250 FT_Error
251 TA_sfnt_build_glyf_hints(SFNT* sfnt,
252 FONT* font);
253 FT_Error
254 TA_sfnt_split_glyf_table(SFNT* sfnt,
255 FONT* font);
256 FT_Error
257 TA_sfnt_build_glyf_table(SFNT* sfnt,
258 FONT* font);
259 FT_Error
260 TA_sfnt_create_glyf_data(SFNT* sfnt,
261 FONT* font);
263 FT_Error
264 TA_sfnt_update_GPOS_table(SFNT* sfnt,
265 FONT* font);
267 FT_Error
268 TA_sfnt_update_hmtx_table(SFNT* sfnt,
269 FONT* font);
271 FT_Error
272 TA_sfnt_build_loca_table(SFNT* sfnt,
273 FONT* font);
275 FT_Error
276 TA_sfnt_update_maxp_table(SFNT* sfnt,
277 FONT* font);
279 FT_Error
280 TA_sfnt_update_post_table(SFNT* sfnt,
281 FONT* font);
283 FT_Error
284 TA_sfnt_build_prep_table(SFNT* sfnt,
285 FONT* font);
287 FT_Error
288 TA_sfnt_build_TTF_header(SFNT* sfnt,
289 FONT* font,
290 FT_Byte** header_buf,
291 FT_ULong* header_len,
292 FT_Int do_complete);
293 FT_Error
294 TA_font_build_TTF(FONT* font);
296 FT_Error
297 TA_font_build_TTC(FONT* font);
299 #endif /* __TA_H__ */
301 /* end of ta.h */