Add missing file to `make dist'.
[ttfautohint.git] / lib / tacontrol.h
blob15616311c158eb10cb45376dbac47fbb841d4dfa
1 /* tacontrol.h */
3 /*
4 * Copyright (C) 2014-2015 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 __TACONTROL_H__
17 #define __TACONTROL_H__
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
23 #include <setjmp.h> /* for flex error handling */
26 /* see the section `Managing exceptions' in chapter 6 */
27 /* (`The TrueType Instruction Set') of the OpenType reference */
28 /* how `delta_shift' works */
30 #define CONTROL_DELTA_SHIFT 3 /* 1/8px */
31 #define CONTROL_DELTA_FACTOR (1 << CONTROL_DELTA_SHIFT)
33 #define CONTROL_DELTA_SHIFT_MAX ((1.0 / CONTROL_DELTA_FACTOR) * 8)
34 #define CONTROL_DELTA_SHIFT_MIN -CONTROL_DELTA_SHIFT_MAX
38 * For the generated TrueType bytecode, we use
40 * delta_base = 6 ,
42 * which gives us the following ppem ranges for the three delta
43 * instructions:
45 * DELTAP1 6-21ppem
46 * DELTAP2 22-37ppem
47 * DELTAP3 38-53ppem .
50 #define CONTROL_DELTA_PPEM_MIN 6
51 #define CONTROL_DELTA_PPEM_MAX 53
55 * The control type.
58 typedef enum Control_Type_
60 Control_Delta_before_IUP,
61 Control_Delta_after_IUP,
62 Control_Segment_Left,
63 Control_Segment_Right,
64 Control_Segment_None
65 } Control_Type;
69 * A structure to hold control instructions for a glyph. A linked list of it
70 * gets allocated by a successful call to `TA_control_parse_buffer'. Use
71 * `TA_control_free' to deallocate the list.
73 * `x_shift' and `y_shift' are in the range [-8;8] for delta exceptions
74 * and in the range [SHRT_MIN;SHRT_MAX] for one-point segment offsets.
76 * The `Control' typedef is in `ta.h'.
79 struct Control_
81 Control_Type type;
83 long font_idx;
84 long glyph_idx;
85 number_range* points;
86 int x_shift;
87 int y_shift;
88 number_range* ppems;
90 struct Control_* next;
95 * A structure to hold a single control instruction.
98 typedef struct Ctrl_
100 Control_Type type;
102 long font_idx;
103 long glyph_idx;
104 int ppem;
105 int point_idx;
107 int x_shift;
108 int y_shift;
109 } Ctrl;
113 * This structure is used for communication with `TA_control_parse'.
116 typedef struct Control_Context_
118 /* The error code returned by the parser or lexer. */
119 TA_Error error;
121 /* If no error, this holds the parsing result. */
122 Control* result;
125 * The parser's or lexer's error message in case of error; might be the
126 * empty string.
128 char errmsg[256];
131 * In case of error, `errline_num' gives the line number of the offending
132 * line in `font->control_buf', starting with value 1; `errline_pos_left'
133 * and `errline_pos_right' hold the left and right position of the
134 * offending token in this line, also starting with value 1. For
135 * allocation errors or internal parser or lexer errors those values are
136 * meaningless, though.
138 int errline_num;
139 int errline_pos_left;
140 int errline_pos_right;
143 * The current font index, useful for `TA_Err_Control_Invalid_Font_Index'.
145 long font_idx;
148 * The current glyph index, useful for
149 * `TA_Err_Control_Invalid_Glyph_Index'.
151 long glyph_idx;
154 * If the returned error is `TA_Err_Control_Invalid_Range', these two
155 * values set up the allowed range.
157 long number_set_min;
158 long number_set_max;
160 /* private flex data */
161 void* scanner;
162 int eof;
163 jmp_buf jump_buffer;
165 /* private bison data */
166 FONT* font;
167 } Control_Context;
171 * Create and initialize a `Control' object. In case of an allocation error,
172 * the return value is NULL. `point_set' and `ppem_set' are expected to be
173 * in reverse list order; `TA_control_new' then reverts them to normal order.
176 Control*
177 TA_control_new(Control_Type type,
178 long font_idx,
179 long glyph_idx,
180 number_range* point_set,
181 double x_shift,
182 double y_shift,
183 number_range* ppem_set);
187 * Prepend `element' to `list' of `Control' objects. If `element' is NULL,
188 * return `list.
191 Control*
192 TA_control_prepend(Control* list,
193 Control* element);
197 * Reverse a list of `Control' objects.
200 Control*
201 TA_control_reverse(Control* list);
205 * Initialize the scanner data within a `Control_Context' object.
206 * `font->control_buf' is the control instructions buffer to be parsed,
207 * `font->control_len' its length.
209 * This function is defined in `tacontrol.flex'.
212 void
213 TA_control_scanner_init(Control_Context* context,
214 FONT* font);
218 * Free the scanner data within a `Control_Context' object.
220 * This function is defined in `tacontrol.flex'.
223 void
224 TA_control_scanner_done(Control_Context* context);
228 * Parse buffer with ttfautohint control instructions, stored in
229 * `font->control_buf' with length `font->control_len'.
231 * The format of entries in such a control instructions buffer is given in
232 * `ttfautohint.h' (option `control-file'); the following describes more
233 * technical details, using the constants defined above.
235 * x shift and y shift values represent floating point numbers that get
236 * rounded to multiples of 1/(2^CONTROL_DELTA_SHIFT) pixels.
238 * Values for x and y shifts must be in the range
239 * [CONTROL_DELTA_SHIFT_MIN;CONTROL_DELTA_SHIFT_MAX]. Values for ppems must
240 * be in the range [CONTROL_DELTA_PPEM_MIN;CONTROL_DELTA_PPEM_MAX].
242 * The returned error codes are 0 (TA_Err_Ok) or in the range 0x200-0x2FF;
243 * see `ttfautohint-errors.h' for all possible values.
245 * `TA_control_parse_buffer' stores the parsed result in `font->control', to
246 * be freed with `TA_control_free' after use. If there is no control
247 * instructions data (for example, an empty string or whitespace only)
248 * nothing gets allocated, and `font->control' is set to NULL.
250 * In case of error, `error_string_p' holds an error message, `errlinenum_p'
251 * gives the line number in the control instructions buffer where the error
252 * occurred, `errline_p' the corresponding line, and `errpos_p' the position
253 * in this line. After use, `error_string_p' and `errline_p' must be
254 * deallocated by the user. Note that `errline_p' and `errpos_p' can be
255 * NULL even in case of an error. If there is no error, those four values
256 * are undefined.
259 TA_Error
260 TA_control_parse_buffer(FONT* font,
261 char** error_string_p,
262 unsigned int* errlinenum_p,
263 char** errline_p,
264 char** errpos_p);
268 * Free the allocated data in `control'.
271 void
272 TA_control_free(Control* control);
276 * Return a string representation of `font->control'. After use, the string
277 * should be deallocated with a call to `free'. In case of an allocation
278 * error, the return value is NULL.
281 char*
282 TA_control_show(FONT* font);
286 * Build a tree providing sequential access to the control instructions data
287 * in `font->control'. This also sets `font->control_data_cur' to the first
288 * element (or NULL if there isn't one).
291 TA_Error
292 TA_control_build_tree(FONT* font);
296 * Free the control instructions data tree.
299 void
300 TA_control_free_tree(FONT* font);
304 * Get next control instruction and store it in `font->control_data_cur'.
307 void
308 TA_control_get_next(FONT* font);
312 * Access control instruction. Return NULL if there is no more data.
315 const Ctrl*
316 TA_control_get_ctrl(FONT* font);
320 * Collect one-point segment data for a given glyph index and store them in
321 * `font->control_segment_dirs'.
324 TA_Error
325 TA_control_segment_dir_collect(FONT* font,
326 long font_idx,
327 long glyph_idx);
330 * Access next one-point segment data. Returns 1 on success or 0 if no more
331 * data. In the latter case, it resets the internal iterator so that
332 * calling this function another time starts at the beginning again.
336 TA_control_segment_dir_get_next(FONT* font,
337 int* point_idx,
338 TA_Direction* dir,
339 int* left_offset,
340 int* right_offset);
343 #ifdef __cplusplus
344 } /* extern "C" */
345 #endif
347 #endif /* __TACONTROL_H__ */
349 /* end of control.h */