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.
22 #include FT_FREETYPE_H
23 #include FT_TRUETYPE_TABLES_H
24 #include FT_TRUETYPE_TAGS_H
26 #include <ttfautohint.h>
28 #include <numberset.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 /* an SFNT tag for our information table */
53 #define TTAG_TTFA FT_MAKE_TAG('T', 'T', 'F', 'A')
55 /* the length of a dummy `DSIG' table */
58 /* the length of our `gasp' table */
61 /* an empty slot in the table info array */
62 #define MISSING (FT_ULong)~0
64 /* the offset to the loca table format in the `head' table */
65 #define LOCA_FORMAT_OFFSET 51
67 /* various offsets within the `maxp' table */
68 #define MAXP_NUM_GLYPHS 4
69 #define MAXP_MAX_COMPOSITE_POINTS 10
70 #define MAXP_MAX_COMPOSITE_CONTOURS 12
71 #define MAXP_MAX_ZONES_OFFSET 14
72 #define MAXP_MAX_TWILIGHT_POINTS_OFFSET 16
73 #define MAXP_MAX_STORAGE_OFFSET 18
74 #define MAXP_MAX_FUNCTION_DEFS_OFFSET 20
75 #define MAXP_MAX_INSTRUCTION_DEFS_OFFSET 22
76 #define MAXP_MAX_STACK_ELEMENTS_OFFSET 24
77 #define MAXP_MAX_INSTRUCTIONS_OFFSET 26
78 #define MAXP_MAX_COMPONENTS_OFFSET 28
82 /* the offset of the type flags field in the `OS/2' table */
83 #define OS2_FSTYPE_OFFSET 8
86 /* flags in composite glyph records */
87 #define ARGS_ARE_WORDS 0x0001
88 #define ARGS_ARE_XY_VALUES 0x0002
89 #define WE_HAVE_A_SCALE 0x0008
90 #define MORE_COMPONENTS 0x0020
91 #define WE_HAVE_AN_XY_SCALE 0x0040
92 #define WE_HAVE_A_2X2 0x0080
93 #define WE_HAVE_INSTR 0x0100
95 /* flags in simple glyph records */
97 #define X_SHORT_VECTOR 0x02
98 #define Y_SHORT_VECTOR 0x04
105 typedef struct GLYPH_
107 FT_ULong len1
; /* number of bytes before instruction related data */
108 FT_ULong len2
; /* number of bytes after instruction related data; */
109 /* if zero, this indicates a composite glyph */
110 FT_Byte
* buf
; /* extracted glyph data (without instruction related data) */
111 FT_ULong flags_offset
; /* offset to last flag in a composite glyph */
113 FT_ULong ins_len
; /* number of new instructions */
114 FT_Byte
* ins_buf
; /* new instruction data */
116 FT_Short num_contours
; /* >= 0 for simple glyphs */
117 FT_UShort num_points
; /* number of points in a simple glyph */
119 FT_UShort num_components
;
120 FT_UShort
* components
; /* the subglyph indices of a composite glyph */
122 FT_UShort num_pointsums
;
123 FT_UShort
* pointsums
; /* the pointsums of all composite elements */
124 /* (after walking recursively over all subglyphs) */
126 FT_UShort num_composite_contours
; /* after recursion */
129 /* a representation of the data in the `glyf' table */
130 typedef struct glyf_Data_
132 FT_UShort num_glyphs
;
135 /* this field gives the `master' globals for a `glyf' table; */
136 /* see function `TA_sfnt_handle_coverage' */
137 TA_FaceGlobals master_globals
;
138 /* for coverage bookkeeping */
141 /* if a `glyf' table gets used in more than one subfont, */
142 /* so do `cvt', `fpgm', and `prep' tables: */
143 /* these four tables are always handled in parallel */
148 /* styles present in a font get a running number */
149 FT_UInt style_ids
[TA_STYLE_MAX
];
150 FT_UInt num_used_styles
;
152 /* we have separate CVT data for each style */
153 FT_UInt cvt_offsets
[TA_STYLE_MAX
];
154 FT_UInt cvt_horz_width_sizes
[TA_STYLE_MAX
];
155 FT_UInt cvt_vert_width_sizes
[TA_STYLE_MAX
];
156 FT_UInt cvt_blue_zone_sizes
[TA_STYLE_MAX
];
157 FT_UInt cvt_blue_adjustment_offsets
[TA_STYLE_MAX
];
161 typedef struct SFNT_Table_
165 FT_Byte
* buf
; /* the table data */
166 FT_ULong offset
; /* from beginning of file */
168 void* data
; /* used e.g. for `glyf' table data */
172 /* we use indices into the SFNT table array to */
173 /* represent table info records of the TTF header */
174 typedef FT_ULong SFNT_Table_Info
;
176 /* this structure is used to model a TTF or a subfont within a TTC */
181 SFNT_Table_Info
* table_infos
;
182 FT_ULong num_table_infos
;
184 /* various SFNT table indices */
195 /* values necessary to update the `maxp' table */
196 FT_UShort max_composite_points
;
197 FT_UShort max_composite_contours
;
198 FT_UShort max_storage
;
199 FT_UShort max_stack_elements
;
200 FT_UShort max_twilight_points
;
201 FT_UShort max_instructions
;
202 FT_UShort max_components
;
205 typedef struct Control_ Control
;
207 /* our font object; the `FONT' typedef is in `taloader.h' */
229 /* we have a single `gasp' table for all subfonts */
232 /* the control instructions */
235 /* two generic pointers into the control instructions tree */
236 void* control_data_head
;
237 void* control_data_cur
;
239 /* two fields for handling one-point segment directions */
240 number_range
* control_segment_dirs
;
241 number_set_iter control_segment_dir_iter
;
243 TA_LoaderRec loader
[1]; /* the interface to the autohinter */
245 /* configuration options */
246 TA_Progress_Func progress
;
250 FT_UInt hinting_range_min
;
251 FT_UInt hinting_range_max
;
252 FT_UInt hinting_limit
;
253 FT_UInt increase_x_height
;
254 number_range
* x_height_snapping_exceptions
;
255 FT_UInt fallback_stem_width
;
256 FT_Bool gray_strong_stem_width
;
257 FT_Bool gdi_cleartype_strong_stem_width
;
258 FT_Bool dw_cleartype_strong_stem_width
;
259 FT_Bool windows_compatibility
;
260 FT_Bool adjust_subglyphs
;
261 FT_Bool hint_composites
;
262 FT_Bool ignore_restrictions
;
263 TA_Style fallback_style
;
264 TA_Script default_script
;
272 #include "tatables.h"
273 #include "tabytecode.h"
274 #include "tacontrol.h"
277 /* in file `tascript.c' */
278 extern const char* script_names
[];
282 TA_get_error_message(FT_Error error
);
285 TA_font_dump_parameters(FONT
* font
,
289 TA_get_current_time(FT_ULong
* high
,
293 TA_build_push(FT_Byte
* bufp
,
300 TA_font_init(FONT
* font
);
302 TA_font_unload(FONT
* font
,
305 const char* control_buf
);
308 TA_font_file_read(FONT
* font
,
311 TA_font_file_write(FONT
* font
,
314 TA_control_file_read(FONT
* font
,
318 TA_sfnt_build_glyph_instructions(SFNT
* sfnt
,
323 TA_sfnt_split_into_SFNT_tables(SFNT
* sfnt
,
327 TA_sfnt_build_cvt_table(SFNT
* sfnt
,
331 TA_table_build_TTFA(FT_Byte
** TTFA
,
336 TA_table_build_DSIG(FT_Byte
** DSIG
);
339 TA_sfnt_build_fpgm_table(SFNT
* sfnt
,
343 TA_sfnt_build_gasp_table(SFNT
* sfnt
,
347 TA_sfnt_split_glyf_table(SFNT
* sfnt
,
350 TA_sfnt_build_glyf_table(SFNT
* sfnt
,
353 TA_sfnt_create_glyf_data(SFNT
* sfnt
,
356 TA_sfnt_handle_coverage(SFNT
* sfnt
,
359 TA_sfnt_adjust_coverage(SFNT
* sfnt
,
363 TA_sfnt_copy_master_coverage(SFNT
* sfnt
,
368 TA_sfnt_update_GPOS_table(SFNT
* sfnt
,
372 TA_sfnt_update_hmtx_table(SFNT
* sfnt
,
376 TA_sfnt_build_loca_table(SFNT
* sfnt
,
380 TA_sfnt_update_maxp_table(SFNT
* sfnt
,
384 TA_sfnt_update_post_table(SFNT
* sfnt
,
388 TA_sfnt_update_name_table(SFNT
* sfnt
,
392 TA_sfnt_build_prep_table(SFNT
* sfnt
,
396 TA_sfnt_build_TTF_header(SFNT
* sfnt
,
398 FT_Byte
** header_buf
,
399 FT_ULong
* header_len
,
402 TA_font_build_TTF(FONT
* font
);
405 TA_font_build_TTC(FONT
* font
);
407 #endif /* __TA_H__ */