4 * Copyright (C) 2014-2017 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.
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
42 * which gives us the following ppem ranges for the three delta
50 #define CONTROL_DELTA_PPEM_MIN 6
51 #define CONTROL_DELTA_PPEM_MAX 53
58 typedef enum Control_Type_
60 Control_Delta_before_IUP
,
61 Control_Delta_after_IUP
,
62 Control_Single_Point_Segment_Left
,
63 Control_Single_Point_Segment_Right
,
64 Control_Single_Point_Segment_None
,
65 Control_Script_Feature
70 * A structure to hold control instructions. A linked list of it gets
71 * allocated by a successful call to `TA_control_parse_buffer'. Use
72 * `TA_control_free' to deallocate the list.
74 * `x_shift' and `y_shift' are in the range [-8;8] for delta exceptions
75 * and in the range [SHRT_MIN;SHRT_MAX] for one-point segment offsets.
77 * The `Control' typedef is in `ta.h'.
93 struct Control_
* next
;
98 * A structure to hold a single control instruction.
118 * This structure is used for communication with `TA_control_parse'.
121 typedef struct Control_Context_
123 /* The error code returned by the parser or lexer. */
126 /* If no error, this holds the parsing result. */
130 * The parser's or lexer's error message in case of error; might be the
136 * In case of error, `errline_num' gives the line number of the offending
137 * line in `font->control_buf', starting with value 1; `errline_pos_left'
138 * and `errline_pos_right' hold the left and right position of the
139 * offending token in this line, also starting with value 1. For
140 * allocation errors or internal parser or lexer errors those values are
141 * meaningless, though.
144 int errline_pos_left
;
145 int errline_pos_right
;
148 * The current font index, useful for `TA_Err_Control_Invalid_Font_Index'.
153 * The current glyph index, useful for
154 * `TA_Err_Control_Invalid_Glyph_Index'.
159 * If the returned error is `TA_Err_Control_Invalid_Range', these two
160 * values set up the allowed range.
165 /* private flex data */
170 /* private bison data */
176 * Create and initialize a `Control' object. In case of an allocation error,
177 * the return value is NULL. `point_set' and `ppem_set' are expected to be
178 * in reverse list order; `TA_control_new' then reverts them to normal order.
182 TA_control_new(Control_Type type
,
185 number_range
* point_set
,
188 number_range
* ppem_set
,
193 * Prepend `element' to `list' of `Control' objects. If `element' is NULL,
198 TA_control_prepend(Control
* list
,
203 * Reverse a list of `Control' objects.
207 TA_control_reverse(Control
* list
);
211 * Initialize the scanner data within a `Control_Context' object.
212 * `font->control_buf' is the control instructions buffer to be parsed,
213 * `font->control_len' its length.
215 * This function is defined in `tacontrol.flex'.
219 TA_control_scanner_init(Control_Context
* context
,
224 * Free the scanner data within a `Control_Context' object.
226 * This function is defined in `tacontrol.flex'.
230 TA_control_scanner_done(Control_Context
* context
);
234 * Parse buffer with ttfautohint control instructions, stored in
235 * `font->control_buf' with length `font->control_len'.
237 * The format of entries in such a control instructions buffer is given in
238 * `ttfautohint.h' (option `control-file'); the following describes more
239 * technical details, using the constants defined above.
241 * x shift and y shift values represent floating point numbers that get
242 * rounded to multiples of 1/(2^CONTROL_DELTA_SHIFT) pixels.
244 * Values for x and y shifts must be in the range
245 * [CONTROL_DELTA_SHIFT_MIN;CONTROL_DELTA_SHIFT_MAX]. Values for ppems must
246 * be in the range [CONTROL_DELTA_PPEM_MIN;CONTROL_DELTA_PPEM_MAX].
248 * The returned error codes are 0 (TA_Err_Ok) or in the range 0x200-0x2FF;
249 * see `ttfautohint-errors.h' for all possible values.
251 * `TA_control_parse_buffer' stores the parsed result in `font->control', to
252 * be freed with `TA_control_free' after use. If there is no control
253 * instructions data (for example, an empty string or whitespace only)
254 * nothing gets allocated, and `font->control' is set to NULL.
256 * In case of error, `error_string_p' holds an error message, `errlinenum_p'
257 * gives the line number in the control instructions buffer where the error
258 * occurred, `errline_p' the corresponding line, and `errpos_p' the position
259 * in this line. After use, `error_string_p' and `errline_p' must be
260 * deallocated by the user. Note that `errline_p' and `errpos_p' can be
261 * NULL even in case of an error. If there is no error, those four values
266 TA_control_parse_buffer(FONT
* font
,
267 char** error_string_p
,
268 unsigned int* errlinenum_p
,
274 * Apply coverage data from the control instructions file.
278 TA_control_apply_coverage(SFNT
* sfnt
,
282 * Free the allocated data in `control'.
286 TA_control_free(Control
* control
);
290 * Return a string representation of `font->control'. After use, the string
291 * should be deallocated with a call to `free'. In case of an allocation
292 * error, the return value is NULL.
296 TA_control_show(FONT
* font
);
300 * Build a tree providing sequential access to the control instructions data
301 * in `font->control'. This also sets `font->control_data_cur' to the first
302 * element (or NULL if there isn't one).
306 TA_control_build_tree(FONT
* font
);
310 * Free the control instructions data tree.
314 TA_control_free_tree(FONT
* font
);
318 * Get next control instruction and store it in `font->control_data_cur'.
322 TA_control_get_next(FONT
* font
);
326 * Access control instruction. Return NULL if there is no more data.
330 TA_control_get_ctrl(FONT
* font
);
334 * Collect one-point segment data for a given glyph index and store them in
335 * `font->control_segment_dirs'.
339 TA_control_segment_dir_collect(FONT
* font
,
344 * Access next one-point segment data. Returns 1 on success or 0 if no more
345 * data. In the latter case, it resets the internal iterator so that
346 * calling this function another time starts at the beginning again.
350 TA_control_segment_dir_get_next(FONT
* font
,
361 #endif /* TACONTROL_H_ */
363 /* end of control.h */