Close input and output files in demo program.
[ttfautohint.git] / src / ta.h
blob960e91e4ba29f5be4e0ddb444651ee2fd9a87c3d
1 /* ta.h */
3 /*
4 * Copyright (C) 2011 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_MAX_ZONES_OFFSET 14
59 #define MAXP_MAX_TWILIGHT_POINTS_OFFSET 16
60 #define MAXP_MAX_STORAGE_OFFSET 18
61 #define MAXP_MAX_FUNCTION_DEFS_OFFSET 20
62 #define MAXP_MAX_INSTRUCTION_DEFS_OFFSET 22
63 #define MAXP_MAX_STACK_ELEMENTS_OFFSET 24
64 #define MAXP_MAX_INSTRUCTIONS_OFFSET 26
66 #define MAXP_LEN 32
68 /* the offset of the type flags field in the `OS/2' table */
69 #define OS2_FSTYPE_OFFSET 8
72 /* flags in composite glyph records */
73 #define ARGS_ARE_WORDS 0x0001
74 #define ARGS_ARE_XY_VALUES 0x0002
75 #define WE_HAVE_A_SCALE 0x0008
76 #define MORE_COMPONENTS 0x0020
77 #define WE_HAVE_AN_XY_SCALE 0x0040
78 #define WE_HAVE_A_2X2 0x0080
79 #define WE_HAVE_INSTR 0x0100
81 /* flags in simple glyph records */
82 #define ON_CURVE 0x01
83 #define X_SHORT_VECTOR 0x02
84 #define Y_SHORT_VECTOR 0x04
85 #define REPEAT 0x08
86 #define SAME_X 0x10
87 #define SAME_Y 0x20
90 /* a single glyph */
91 typedef struct GLYPH_
93 FT_ULong len1; /* number of bytes before instruction related data */
94 FT_ULong len2; /* number of bytes after instruction related data; */
95 /* if zero, this indicates a composite glyph */
96 FT_Byte* buf; /* extracted glyph data (without instruction related data) */
97 FT_ULong flags_offset; /* offset to last flag in a composite glyph */
99 FT_ULong ins_len; /* number of new instructions */
100 FT_Byte* ins_buf; /* new instruction data */
102 FT_UShort num_components;
103 FT_UShort* components; /* the subglyph indices of a composite glyph */
104 FT_UShort depth; /* the number of the composite's nesting levels */
105 } GLYPH;
107 /* a representation of the data in the `glyf' table */
108 typedef struct glyf_Data_
110 FT_UShort num_glyphs;
111 GLYPH* glyphs;
112 } glyf_Data;
114 /* an SFNT table */
115 typedef struct SFNT_Table_ {
116 FT_ULong tag;
117 FT_ULong len;
118 FT_Byte* buf; /* the table data */
119 FT_ULong offset; /* from beginning of file */
120 FT_ULong checksum;
121 void* data; /* used e.g. for `glyf' table data */
122 FT_Bool processed;
123 } SFNT_Table;
125 /* we use indices into the SFNT table array to */
126 /* represent table info records of the TTF header */
127 typedef FT_ULong SFNT_Table_Info;
129 /* this structure is used to model a TTF or a subfont within a TTC */
130 typedef struct SFNT_ {
131 FT_Face face;
133 SFNT_Table_Info* table_infos;
134 FT_ULong num_table_infos;
136 /* various SFNT table indices */
137 FT_ULong glyf_idx;
138 FT_ULong loca_idx;
139 FT_ULong head_idx;
140 FT_ULong maxp_idx;
141 FT_ULong OS2_idx;
142 FT_ULong GPOS_idx;
144 /* values necessary to update the `maxp' table */
145 FT_UShort max_storage;
146 FT_UShort max_stack_elements;
147 FT_UShort max_twilight_points;
148 FT_UShort max_instructions;
149 } SFNT;
151 /* our font object */
152 typedef struct FONT_ {
153 FT_Library lib;
155 FT_Byte* in_buf;
156 size_t in_len;
158 FT_Byte* out_buf;
159 size_t out_len;
161 SFNT* sfnts;
162 FT_Long num_sfnts;
164 SFNT_Table* tables;
165 FT_ULong num_tables;
167 FT_Bool have_DSIG;
169 TA_LoaderRec loader[1]; /* the interface to the autohinter */
171 /* configuration options */
172 TA_Progress_Func progress;
173 void *progress_data;
174 FT_UInt hinting_range_min;
175 FT_UInt hinting_range_max;
176 FT_Bool pre_hinting;
177 FT_Bool no_x_height_snapping;
178 FT_Byte* x_height_snapping_exceptions;
179 FT_Bool ignore_permissions;
180 FT_UInt fallback_script;
181 } FONT;
184 #include "tatables.h"
185 #include "tabytecode.h"
188 const char*
189 TA_get_error_message(FT_Error error);
191 void
192 TA_get_current_time(FT_ULong *high,
193 FT_ULong *low);
195 FT_Error
196 TA_font_init(FONT* font);
197 void
198 TA_font_unload(FONT* font,
199 const char *in_buf,
200 char** out_bufp);
202 FT_Error
203 TA_font_file_read(FONT* font,
204 FILE* in_file);
205 FT_Error
206 TA_font_file_write(FONT* font,
207 FILE* out_file);
209 FT_Error
210 TA_sfnt_build_glyph_instructions(SFNT* sfnt,
211 FONT* font,
212 FT_Long idx);
214 FT_Error
215 TA_sfnt_split_into_SFNT_tables(SFNT* sfnt,
216 FONT* font);
218 FT_Error
219 TA_sfnt_build_cvt_table(SFNT* sfnt,
220 FONT* font);
222 FT_Error
223 TA_table_build_DSIG(FT_Byte** DSIG);
225 FT_Error
226 TA_sfnt_build_fpgm_table(SFNT* sfnt,
227 FONT* font);
229 FT_Error
230 TA_sfnt_build_gasp_table(SFNT* sfnt,
231 FONT* font);
233 FT_Error
234 TA_sfnt_build_glyf_hints(SFNT* sfnt,
235 FONT* font);
236 FT_Error
237 TA_sfnt_split_glyf_table(SFNT* sfnt,
238 FONT* font);
239 FT_Error
240 TA_sfnt_build_glyf_table(SFNT* sfnt,
241 FONT* font);
242 FT_Error
243 TA_sfnt_create_glyf_data(SFNT* sfnt,
244 FONT* font);
246 FT_Error
247 TA_sfnt_build_loca_table(SFNT* sfnt,
248 FONT* font);
250 FT_Error
251 TA_sfnt_update_maxp_table(SFNT* sfnt,
252 FONT* font);
254 FT_Error
255 TA_sfnt_build_prep_table(SFNT* sfnt,
256 FONT* font);
258 FT_Error
259 TA_sfnt_build_TTF_header(SFNT* sfnt,
260 FONT* font,
261 FT_Byte** header_buf,
262 FT_ULong* header_len,
263 FT_Int do_complete);
264 FT_Error
265 TA_font_build_TTF(FONT* font);
267 FT_Error
268 TA_font_build_TTC(FONT* font);
270 #endif /* __TA_H__ */
272 /* end of ta.h */