Now switch delta exceptions parser to bison/flex combination.
[ttfautohint.git] / lib / ttfautohint.h
blob3041498f97be129fb981c04c19e6f974f5914308
1 /* ttfautohint.h */
3 /*
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.
16 #ifndef __TTFAUTOHINT_H__
17 #define __TTFAUTOHINT_H__
19 #include <stdarg.h>
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
27 * This file gets processed with a simple sed script to extract the
28 * documentation (written in pandoc's markdown format); code between the
29 * `pandoc' markers are retained, everything else is discarded. C comments
30 * are uncommented so that column 4 becomes column 1; empty lines outside of
31 * comments are removed.
35 /* pandoc-start */
38 * The ttfautohint API
39 * ===================
41 * This section documents the single function of the ttfautohint library,
42 * `TTF_autohint`, together with its callback functions, `TA_Progress_Func`
43 * and `TA_Info_Func`. All information has been directly extracted from the
44 * `ttfautohint.h` header file.
50 * Preprocessor Macros and Typedefs
51 * --------------------------------
53 * Some default values.
55 * ```C
58 #define TA_HINTING_RANGE_MIN 8
59 #define TA_HINTING_RANGE_MAX 50
60 #define TA_HINTING_LIMIT 200
61 #define TA_INCREASE_X_HEIGHT 14
64 *```
66 * An error type.
68 * ```C
71 typedef int TA_Error;
74 * ```
80 * Callback: `TA_Progress_Func`
81 * ----------------------------
83 * A callback function to get progress information. *curr_idx* gives the
84 * currently processed glyph index; if it is negative, an error has
85 * occurred. *num_glyphs* holds the total number of glyphs in the font
86 * (this value can't be larger than 65535).
88 * *curr_sfnt* gives the current subfont within a TrueType Collection (TTC),
89 * and *num_sfnts* the total number of subfonts.
91 * If the return value is non-zero, `TTF_autohint` aborts with
92 * `TA_Err_Canceled`. Use this for a 'Cancel' button or similar features in
93 * interactive use.
95 * *progress_data* is a void pointer to user-supplied data.
97 * ```C
100 typedef int
101 (*TA_Progress_Func)(long curr_idx,
102 long num_glyphs,
103 long curr_sfnt,
104 long num_sfnts,
105 void* progress_data);
108 * ```
114 * Callback: `TA_Error_Func`
115 * -------------------------
117 * A callback function to get error information.
119 * *error* is the value `TTF_autohint` returns. See file
120 * `ttfautohint-errors.h` for a list. Error codes not in this list are
121 * directly taken from FreeType; see the FreeType header file `fterrdef.h`
122 * for more.
124 * *error_string*, if non-NULL, is a pointer to an error message that
125 * represents *error*.
127 * The next three parameters help identify the origin of text string parsing
128 * errors. *linenum*, if non-zero, contains the line number. *line*, if
129 * non-NULL, is a pointer to the input line that can't be processed.
130 * *errpos*, if non-NULL, holds a pointer to the position in *line* where
131 * the problem occurs.
133 * *error_data* is a void pointer to user-supplied data.
135 * ```C
138 typedef void
139 (*TA_Error_Func)(TA_Error error,
140 const char* error_string,
141 unsigned int linenum,
142 const char* line,
143 const char* errpos,
144 void* error_data);
147 * ```
153 * Callback: `TA_Info_Func`
154 * ------------------------
156 * A callback function to manipulate strings in the `name` table.
157 * *platform_id*, *encoding_id*, *language_id*, and *name_id* are the
158 * identifiers of a `name` table entry pointed to by *str* with a length
159 * pointed to by *str_len* (in bytes; the string has no trailing NULL byte).
160 * Please refer to the [OpenType specification of the `name` table] for a
161 * detailed description of the various parameters, in particular which
162 * encoding is used for a given platform and encoding ID.
164 * [OpenType specification of the `name` table]: http://www.microsoft.com/typography/otspec/name.htm
166 * The string *str* is allocated with `malloc`; the application should
167 * reallocate the data if necessary, ensuring that the string length doesn't
168 * exceed 0xFFFF.
170 * *info_data* is a void pointer to user-supplied data.
172 * If an error occurs, return a non-zero value and don't modify *str* and
173 * *str_len* (such errors are handled as non-fatal).
175 * ```C
178 typedef int
179 (*TA_Info_Func)(unsigned short platform_id,
180 unsigned short encoding_id,
181 unsigned short language_id,
182 unsigned short name_id,
183 unsigned short* str_len,
184 unsigned char** str,
185 void* info_data);
188 * ```
192 /* pandoc-end */
196 * Error values in addition to the FT_Err_XXX constants from FreeType.
198 * All error values specific to ttfautohint start with `TA_Err_'.
200 #include <ttfautohint-errors.h>
203 /* pandoc-start */
206 * Function: `TTF_autohint`
207 * ------------------------
210 * Read a TrueType font, remove existing bytecode (in the SFNT tables
211 * `prep`, `fpgm`, `cvt `, and `glyf`), and write a new TrueType font with
212 * new bytecode based on the autohinting of the FreeType library.
214 * It expects a format string *options* and a variable number of arguments,
215 * depending on the fields in *options*. The fields are comma separated;
216 * whitespace within the format string is not significant, a trailing comma
217 * is ignored. Fields are parsed from left to right; if a field occurs
218 * multiple times, the last field's argument wins. The same is true for
219 * fields that are mutually exclusive. Depending on the field, zero or one
220 * argument is expected.
222 * Note that fields marked as 'not implemented yet' are subject to change.
225 * ### I/O
227 * `in-file`
228 * : A pointer of type `FILE*` to the data stream of the input font,
229 * opened for binary reading. Mutually exclusive with `in-buffer`.
231 * `in-buffer`
232 * : A pointer of type `const char*` to a buffer that contains the input
233 * font. Needs `in-buffer-len`. Mutually exclusive with `in-file`.
235 * `in-buffer-len`
236 * : A value of type `size_t`, giving the length of the input buffer.
237 * Needs `in-buffer`.
239 * `out-file`
240 * : A pointer of type `FILE*` to the data stream of the output font,
241 * opened for binary writing. Mutually exclusive with `out-buffer`.
243 * `out-buffer`
244 * : A pointer of type `char**` to a buffer that contains the output
245 * font. Needs `out-buffer-len`. Mutually exclusive with `out-file`.
246 * Deallocate the memory with `free`.
248 * `out-buffer-len`
249 * : A pointer of type `size_t*` to a value giving the length of the
250 * output buffer. Needs `out-buffer`.
252 * `deltas-file`
253 * : A pointer of type `FILE*` to the data stream of delta exceptions,
254 * opened for reading in *binary* mode. Mutually exclusive with
255 * `deltas-buffer`.
257 * An entry in a delta exceptions file or buffer has the following
258 * syntax:
260 * > *\[* font-idx *\]* glyph-id *`p`* points *\[* *`x`* x-shift *\]* *\[* *`y`* y-shift *\]* *`@`* ppems
262 * *font-idx* gives the index of the font in a TrueType Collection. If
263 * missing, it is set to zero. For normal TrueType fonts, only value
264 * zero is valid. If starting with `0x` the number is interpreted as
265 * hexadecimal. If starting with `0` it gets interpreted as an octal
266 * value, and as a decimal value otherwise.
268 * *glyph-id* is a glyph's name as listed in the `post` SFNT table or a
269 * glyph index. A glyph name consists of characters from the set
270 * '`A-Za-z0-9._`' only and does not start with a digit or period, with
271 * the exceptions of the names '`.notdef`' and '`.null`'. A glyph index
272 * can be specified in decimal, octal, or hexadecimal format, the latter
273 * two indicated by the prefixes `0` and `0x`, respectively.
275 * Both *points* and *ppems* are number ranges, similar to the
276 * `x-height-snapping-exceptions` syntax.
278 * *x-shift* and *y-shift* represent floating point numbers that get
279 * rounded to multiples of 1/8 pixels. The entries for `x` and `y` are
280 * optional; if missing, the corresponding value is set to zero.
282 * Values for *x-shift* and *y-shift* must be in the range [-1.0;1.0].
283 * Values for *ppems* must be in the range [6;53]. Values for *points*
284 * are limited by the number of points in the glyph.
286 * Delta exceptions entries can be either separated with newlines or
287 * with character '`;`'. Additionally, a line can be continued on the
288 * next line by ending it with backslash character ('`\`'). A backslash
289 * followed by a newline gets treated similar to a whitespace character.
291 * A comment starts with character `#`; the rest of the line is ignored.
292 * An empty line is ignored also.
294 * Note that only character '`.`' is recognized as a decimal point, and
295 * a thousands separator is not accepted.
297 * `deltas-buffer`
298 * : A pointer of type `const char*` to a buffer that contains delta
299 * exceptions. Needs `deltas-buffer-len`. Mutually exclusive with
300 * `deltas-file`.
302 * `deltas-buffer-len`
303 * : A value of type `size_t`, giving the length of the delta exceptions
304 * buffer. Needs `deltas-buffer`.
307 * ### Messages and Callbacks
309 * `progress-callback`
310 * : A pointer of type [`TA_Progress_Func`](#callback-ta_progress_func),
311 * specifying a callback function for progress reports. This function
312 * gets called after a single glyph has been processed. If this field
313 * is not set or set to NULL, no progress callback function is used.
315 * `progress-callback-data`
316 * : A pointer of type `void*` to user data that is passed to the
317 * progress callback function.
319 * `error-string`
320 * : A pointer of type `unsigned char**` to a string (in UTF-8 encoding)
321 * that verbally describes the error code. You must not change the
322 * returned value.
324 * `error-callback`
325 * : A pointer of type [`TA_Error_Func`](#callback-ta_error_func),
326 * specifying a callback function for error messages. This function
327 * gets called right before `TTF_autohint` exits. If this field is not
328 * set or set to NULL, no error callback function is used.
330 * Use it as a more sophisticated alternative to `error-string`.
332 * `error-callback-data`
333 * : A point of type `void*` to user data that is passed to the error
334 * callback function.
336 * `info-callback`
337 * : A pointer of type [`TA_Info_Func`](#callback-ta_info_func),
338 * specifying a callback function for manipulating the `name` table.
339 * This function gets called for each `name` table entry. If not set or
340 * set to NULL, the table data stays unmodified.
342 * `info-callback-data`
343 * : A pointer of type `void*` to user data that is passed to the info
344 * callback function.
346 * `debug`
347 * : If this integer is set to\ 1, lots of debugging information is print
348 * to stderr. The default value is\ 0.
351 * ### General Hinting Options
353 * `hinting-range-min`
354 * : An integer (which must be larger than or equal to\ 2) giving the
355 * lowest PPEM value used for autohinting. If this field is not set, it
356 * defaults to `TA_HINTING_RANGE_MIN`.
358 * `hinting-range-max`
359 * : An integer (which must be larger than or equal to the value of
360 * `hinting-range-min`) giving the highest PPEM value used for
361 * autohinting. If this field is not set, it defaults to
362 * `TA_HINTING_RANGE_MAX`.
364 * `hinting-limit`
365 * : An integer (which must be larger than or equal to the value of
366 * `hinting-range-max`) that gives the largest PPEM value at which
367 * hinting is applied. For larger values, hinting is switched off. If
368 * this field is not set, it defaults to `TA_HINTING_LIMIT`. If it is
369 * set to\ 0, no hinting limit is added to the bytecode.
371 * `hint-composites`
372 * : If this integer is set to\ 1, composite glyphs get separate hints.
373 * This implies adding a special glyph to the font called
374 * ['.ttfautohint'](#the-.ttfautohint-glyph). Setting it to\ 0 (which
375 * is the default), the hints of the composite glyphs' components are
376 * used. Adding hints for composite glyphs increases the size of the
377 * resulting bytecode a lot, but it might deliver better hinting
378 * results. However, this depends on the processed font and must be
379 * checked by inspection.
381 * `adjust-subglyphs`
382 * : An integer (1\ for 'on' and 0\ for 'off', which is the default) to
383 * specify whether native TrueType hinting of the *input font* shall be
384 * applied to all glyphs before passing them to the (internal)
385 * autohinter. The used resolution is the em-size in font units; for
386 * most fonts this is 2048ppem. Use this only if the old hints move or
387 * scale subglyphs independently of the output resolution, for example
388 * some exotic CJK fonts.
390 * `pre-hinting` is a deprecated alias name for this option.
393 * ### Hinting Algorithms
395 * `gray-strong-stem-width`
396 * : An integer (1\ for 'on' and 0\ for 'off', which is the default) that
397 * specifies whether horizontal stems should be snapped and positioned
398 * to integer pixel values for normal grayscale rendering.
400 * `gdi-cleartype-strong-stem-width`
401 * : An integer (1\ for 'on', which is the default, and 0\ for 'off') that
402 * specifies whether horizontal stems should be snapped and positioned
403 * to integer pixel values for GDI ClearType rendering, this is, the
404 * rasterizer version (as returned by the GETINFO bytecode instruction)
405 * is in the range 36\ <= version <\ 38 and ClearType is enabled.
407 * `dw-cleartype-strong-stem-width`
408 * : An integer (1\ for 'on' and 0\ for 'off', which is the default) that
409 * specifies whether horizontal stems should be snapped and positioned
410 * to integer pixel values for DW ClearType rendering, this is, the
411 * rasterizer version (as returned by the GETINFO bytecode instruction)
412 * is >=\ 38, ClearType is enabled, and subpixel positioning is enabled
413 * also.
415 * `increase-x-height`
416 * : An integer. For PPEM values in the range 6\ <= PPEM
417 * <= `increase-x-height`, round up the font's x\ height much more often
418 * than normally (to use the terminology of TrueType's 'Super Round'
419 * bytecode instruction, the threshold gets increased from 5/8px to
420 * 13/16px). If it is set to\ 0, this feature is switched off. If this
421 * field is not set, it defaults to `TA_INCREASE_X_HEIGHT`. Use this
422 * flag to improve the legibility of small font sizes if necessary.
424 * `x-height-snapping-exceptions`
425 * : A pointer of type `const char*` to a null-terminated string that
426 * gives a list of comma separated PPEM values or value ranges at which
427 * no x\ height snapping shall be applied. A value range has the form
428 * *value*~1~`-`*value*~2~, meaning *value*~1~ <= PPEM <= *value*~2~.
429 * *value*~1~ or *value*~2~ (or both) can be missing; a missing value is
430 * replaced by the beginning or end of the whole interval of valid PPEM
431 * values, respectively. Whitespace is not significant; superfluous
432 * commas are ignored, and ranges must be specified in increasing order.
433 * For example, the string `"3, 5-7, 9-"` means the values 3, 5, 6, 7,
434 * 9, 10, 11, 12, etc. Consequently, if the supplied argument is `"-"`,
435 * no x\ height snapping takes place at all. The default is the empty
436 * string (`""`), meaning no snapping exceptions.
438 * `windows-compatibility`
439 * : If this integer is set to\ 1, two artificial blue zones are used,
440 * positioned at the `usWinAscent` and `usWinDescent` values (from the
441 * font's `OS/2` table). The idea is to help ttfautohint so that the
442 * hinted glyphs stay within this horizontal stripe since Windows clips
443 * everything falling outside. The default is\ 0.
446 * ### Scripts
448 * `default-script`
449 * : A string consisting of four lowercase characters that specifies the
450 * default script for OpenType features. After applying all features
451 * that are handled specially, use this value for the remaining
452 * features. The default value is `"latn"`; if set to `"none"`, no
453 * script is used. Valid values can be found in the header file
454 * `ttfautohint-scripts.h`.
456 * `fallback-script`
457 * : A string consisting of four lowercase characters that specifies the
458 * default script for glyphs that can't be mapped to a script
459 * automatically. If set to `"none"` (which is the default), no script
460 * is used. Valid values can be found in the header file
461 * `ttfautohint-scripts.h`.
463 * `symbol`
464 * : Set this integer to\ 1 if you want to process a font that ttfautohint
465 * would refuse otherwise because it can't find a single standard
466 * character for any of the supported scripts. ttfautohint then uses a
467 * default (hinting) value for the standard stem width instead of
468 * deriving it from a script's set of standard characters (for the latin
469 * script, one of them is character 'o'). The default value of this
470 * option is\ 0.
472 * `fallback-stem-width`
473 * : Set the horizontal stem width (hinting) value for all scripts that
474 * lack proper standard characters. The value is given in font units
475 * and must be a positive integer. If not set, or the value is zero,
476 * ttfautohint uses a hard-coded default (50\ units at 2048 units per
477 * EM, and linearly scaled for other UPEM values, for example 24\ units
478 * at 1000 UPEM).
480 * For symbol fonts (i.e., option `symbol` is given),
481 * `fallback-stem-width` has an effect only if `fallback-script` is set
482 * also.
485 * ### Miscellaneous
487 * `ignore-restrictions`
488 * : If the font has set bit\ 1 in the 'fsType' field of the `OS/2` table,
489 * the ttfautohint library refuses to process the font since a
490 * permission to do that is required from the font's legal owner. In
491 * case you have such a permission you might set the integer argument to
492 * value\ 1 to make ttfautohint handle the font. The default value
493 * is\ 0.
495 * `dehint`
496 * : If set to\ 1, remove all hints from the font. All other hinting
497 * options are ignored.
500 * ### Remarks
502 * * Obviously, it is necessary to have an input and an output data
503 * stream. All other options are optional.
505 * * `hinting-range-min` and `hinting-range-max` specify the range for
506 * which the autohinter generates optimized hinting code. If a PPEM
507 * value is smaller than the value of `hinting-range-min`, hinting still
508 * takes place but the configuration created for `hinting-range-min` is
509 * used. The analogous action is taken for `hinting-range-max`, only
510 * limited by the value given with `hinting-limit`. The font's `gasp`
511 * table is set up to always use grayscale rendering with grid-fitting
512 * for standard hinting, and symmetric grid-fitting and symmetric
513 * smoothing for horizontal subpixel hinting (ClearType).
515 * * ttfautohint can process its own output a second time only if option
516 * `hint-composites` is not set (or if the font doesn't contain
517 * composite glyphs at all). This limitation might change in the
518 * future.
520 * ```C
523 TA_Error
524 TTF_autohint(const char* options,
525 ...);
528 * ```
532 /* pandoc-end */
534 #ifdef __cplusplus
535 } /* extern "C" */
536 #endif
538 #endif /* __TTFAUTOHINT_H__ */
540 /* end of ttfautohint.h */