4 * Copyright (C) 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.
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 DELTA_SHIFT 3 /* 1/8px */
31 #define DELTA_FACTOR (1 << DELTA_SHIFT)
33 #define DELTA_SHIFT_MAX ((1.0 / DELTA_FACTOR) * 8)
34 #define DELTA_SHIFT_MIN -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 DELTA_PPEM_MIN 6
51 #define DELTA_PPEM_MAX 53
55 * A structure to hold delta exceptions for a glyph. A linked list of it
56 * gets allocated by a successful call to `TA_deltas_parse_buffer'. Use
57 * `TA_deltas_free' to deallocate the list.
59 * `x_shift' and `y_shift' are always in the range [-8;8].
61 * The `Deltas' typedef is in `ta.h'.
78 * A structure to hold a single delta exception.
94 * This structure is used for communication with `TA_deltas_parse'.
97 typedef struct Deltas_Context_
99 /* The error code returned by the parser or lexer. */
102 /* If no error, this holds the parsing result. */
106 * The parser's or lexer's error message in case of error; might be the
112 * In case of error, `errline_num' gives the line number of the offending
113 * line in `font->delta_buf', starting with value 1; `errline_pos_left'
114 * and `errline_pos_right' hold the left and right position of the
115 * offending token in this line, also starting with value 1. For
116 * allocation errors or internal parser or lexer errors those values are
117 * meaningless, though.
120 int errline_pos_left
;
121 int errline_pos_right
;
124 * The current font index, useful for `TA_Err_Deltas_Invalid_Font_Index'.
129 * The current glyph index, useful for
130 * `TA_Err_Deltas_Invalid_Glyph_Index'.
135 * If the returned error is `TA_Err_Deltas_Invalid_Range', these two
136 * values set up the allowed range.
141 /* private flex data */
146 /* private bison data */
152 * Create and initialize a `Deltas' object. In case of an allocation error,
153 * the return value is NULL. `point_set' and `ppem_set' are expected to be
154 * in reverse list order; `TA_deltas_new' then reverts them to normal order.
158 TA_deltas_new(long font_idx
,
160 number_range
* point_set
,
163 number_range
* ppem_set
);
167 * Prepend `element' to `list' of `Deltas' objects. If `element' is NULL,
172 TA_deltas_prepend(Deltas
* list
,
177 * Reverse a list of `Deltas' objects.
181 TA_deltas_reverse(Deltas
* list
);
185 * Initialize the scanner data within a `Deltas_Context' object.
186 * `font->delta_buf' is the delta exceptions buffer to be parsed,
187 * `font->delta_len' its length.
189 * This function is defined in `tadeltas.l'.
193 TA_deltas_scanner_init(Deltas_Context
* context
,
198 * Free the scanner data within a `Deltas_Context' object.
200 * This function is defined in `tadeltas.l'.
204 TA_deltas_scanner_done(Deltas_Context
* context
);
208 * Parse buffer with descriptions of delta exceptions, stored in
209 * `font->deltas_buf' with length `font->deltas_len'.
211 * The format of lines in such a delta exceptions buffer is given in
212 * `ttfautohint.h' (option `deltas-file'); the following describes more
213 * technical details, using the constants defined above.
215 * x shift and y shift values represent floating point numbers that get
216 * rounded to multiples of 1/(2^DELTA_SHIFT) pixels.
218 * Values for x and y shifts must be in the range
219 * [DELTA_SHIFT_MIN;DELTA_SHIFT_MAX]. Values for ppems must be in the range
220 * [DELTA_PPEM_MIN;DELTA_PPEM_MAX].
222 * The returned error codes are 0 (TA_Err_Ok) or in the range 0x200-0x2FF;
223 * see `ttfautohint-errors.h' for all possible values.
225 * `TA_deltas_parse_buffer' stores the parsed result in `font->deltas', to
226 * be freed with `TA_deltas_free' after use. If there is no delta
227 * exceptions data (for example, an empty string or whitespace only) nothing
228 * gets allocated, and `font->deltas' is set to NULL.
230 * In case of error, `error_string_p' holds an error message, `errlinenum_p'
231 * gives the line number in the delta exceptions buffer where the error
232 * occurred, `errline_p' the corresponding line, and `errpos_p' the position
233 * in this line. After use, `error_string_p' and `errline_p' must be
234 * deallocated by the user. Note that `errline_p' and `errpos_p' can be
235 * NULL even in case of an error. If there is no error, those four values
240 TA_deltas_parse_buffer(FONT
* font
,
241 char** error_string_p
,
242 unsigned int* errlinenum_p
,
248 * Free the allocated data in `deltas'.
252 TA_deltas_free(Deltas
* deltas
);
256 * Return a string representation of `font->deltas'. After use, the string
257 * should be deallocated with a call to `free'. In case of an allocation
258 * error, the return value is NULL.
262 TA_deltas_show(FONT
* font
);
266 * Build a tree providing sequential access to the delta exceptions data in
267 * `font->deltas'. This also sets `font->deltas_data_cur' to the first
268 * element (or NULL if there isn't one).
272 TA_deltas_build_tree(FONT
* font
);
276 * Free the delta exceptions data tree.
280 TA_deltas_free_tree(FONT
* font
);
284 * Get next delta exception and store it in `font->deltas_data_cur'.
288 TA_deltas_get_next(FONT
* font
);
292 * Access delta exception. Return NULL if there is no more data.
295 TA_deltas_get_delta(FONT
* font
);
301 #endif /* __DELTAS_H__ */
303 /* end of deltas.h */