Update `bootstrap' script from gnulib.
[ttfautohint.git] / lib / ttfautohint.h
blob0983a6add6dadcbeda26eebc567821ce95a11cc0
1 /* ttfautohint.h */
3 /*
4 * Copyright (C) 2011-2016 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>
20 #include <stdint.h>
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
28 * This file gets processed with a simple sed script to extract the
29 * documentation (written in pandoc's markdown format); code between the
30 * `pandoc' markers are retained, everything else is discarded. C comments
31 * are uncommented so that column 4 becomes column 1; empty lines outside of
32 * comments are removed.
36 /* pandoc-start */
39 * The ttfautohint API
40 * ===================
42 * This section documents the single function of the ttfautohint library,
43 * `TTF_autohint`, together with its callback functions, `TA_Progress_Func`
44 * and `TA_Info_Func`. All information has been directly extracted from the
45 * `ttfautohint.h` header file.
51 * Preprocessor Macros and Typedefs
52 * --------------------------------
54 * Some default values.
56 * ```C
59 #define TA_HINTING_RANGE_MIN 8
60 #define TA_HINTING_RANGE_MAX 50
61 #define TA_HINTING_LIMIT 200
62 #define TA_INCREASE_X_HEIGHT 14
65 *```
67 * An error type.
69 * ```C
72 typedef int TA_Error;
75 * ```
81 * Callback: `TA_Progress_Func`
82 * ----------------------------
84 * A callback function to get progress information. *curr_idx* gives the
85 * currently processed glyph index; if it is negative, an error has
86 * occurred. *num_glyphs* holds the total number of glyphs in the font
87 * (this value can't be larger than 65535).
89 * *curr_sfnt* gives the current subfont within a TrueType Collection (TTC),
90 * and *num_sfnts* the total number of subfonts.
92 * If the return value is non-zero, `TTF_autohint` aborts with
93 * `TA_Err_Canceled`. Use this for a 'Cancel' button or similar features in
94 * interactive use.
96 * *progress_data* is a void pointer to user-supplied data.
98 * ```C
101 typedef int
102 (*TA_Progress_Func)(long curr_idx,
103 long num_glyphs,
104 long curr_sfnt,
105 long num_sfnts,
106 void* progress_data);
109 * ```
115 * Callback: `TA_Error_Func`
116 * -------------------------
118 * A callback function to get error information.
120 * *error* is the value `TTF_autohint` returns. See file
121 * `ttfautohint-errors.h` for a list. Error codes not in this list are
122 * directly taken from FreeType; see the FreeType header file `fterrdef.h`
123 * for more.
125 * *error_string*, if non-NULL, is a pointer to an error message that
126 * represents *error*.
128 * The next three parameters help identify the origin of text string parsing
129 * errors. *linenum*, if non-zero, contains the line number. *line*, if
130 * non-NULL, is a pointer to the input line that can't be processed.
131 * *errpos*, if non-NULL, holds a pointer to the position in *line* where
132 * the problem occurs.
134 * *error_data* is a void pointer to user-supplied data.
136 * ```C
139 typedef void
140 (*TA_Error_Func)(TA_Error error,
141 const char* error_string,
142 unsigned int linenum,
143 const char* line,
144 const char* errpos,
145 void* error_data);
148 * ```
154 * Callback: `TA_Info_Func`
155 * ------------------------
157 * A callback function to access or modify strings in the `name` table; it
158 * is called in a loop that iterates over all `name` table entries. If
159 * defined, [`TA_Info_Post_Func`](#callback-ta_info_post_func) gets executed
160 * after this loop so that the collected data can be written back to the
161 * `name` table.
163 * *platform_id*, *encoding_id*, *language_id*, and *name_id* are the
164 * identifiers of a `name` table entry pointed to by *str* with a length
165 * pointed to by *str_len* (in bytes; the string has no trailing NULL byte).
166 * Please refer to the [OpenType specification of the `name` table] for a
167 * detailed description of the various parameters, in particular which
168 * encoding is used for a given platform and encoding ID.
170 * [OpenType specification of the `name` table]: http://www.microsoft.com/typography/otspec/name.htm
172 * The string *str* is allocated with `malloc`; the application should
173 * reallocate the data if necessary, ensuring that the string length doesn't
174 * exceed 0xFFFF.
176 * *info_data* is a void pointer to user-supplied data.
178 * If an error occurs, return a non-zero value and don't modify *str* and
179 * *str_len* (such errors are handled as non-fatal).
181 * ```C
184 typedef int
185 (*TA_Info_Func)(unsigned short platform_id,
186 unsigned short encoding_id,
187 unsigned short language_id,
188 unsigned short name_id,
189 unsigned short* str_len,
190 unsigned char** str,
191 void* info_data);
194 * ```
200 * Callback: `TA_Info_Post_Func`
201 * -----------------------------
203 * A callback function, giving the application the possibility to access or
204 * modify strings in the `name` table after
205 * [`TA_Info_Func`](#callback-ta_info_func) has iterated over all `name`
206 * table entries.
208 * It is expected that `TA_Info_Func` stores pointers to the `name` table
209 * entries it wants to access or modify; the only parameter is thus
210 * *info_data*, which is a void pointer to the user-supplied data already
211 * provided to `TA_Info_Func`. Obviously, calling `TA_Info_Post_Func` with
212 * `TA_Info_Func` undefined has no effect.
214 * The `name` table strings are allocated with `malloc`; the application
215 * should reallocate the data if necessary, ensuring that no string length
216 * exceeds 0xFFFF.
218 * If an error occurs, return a non-zero value and don't modify the affected
219 * string and string length (such errors are handled as non-fatal).
221 * ```C
224 typedef int
225 (*TA_Info_Post_Func)(void* info_data);
228 * ```
232 /* pandoc-end */
236 * Error values in addition to the FT_Err_XXX constants from FreeType.
238 * All error values specific to ttfautohint start with `TA_Err_'.
240 #include <ttfautohint-errors.h>
243 /* pandoc-start */
246 * Function: `TTF_autohint`
247 * ------------------------
250 * Read a TrueType font, remove existing bytecode (in the SFNT tables
251 * `prep`, `fpgm`, `cvt `, and `glyf`), and write a new TrueType font with
252 * new bytecode based on the autohinting of the FreeType library, optionally
253 * using a reference font to derive blue zones.
255 * It expects a format string *options* and a variable number of arguments,
256 * depending on the fields in *options*. The fields are comma separated;
257 * whitespace within the format string is not significant, a trailing comma
258 * is ignored. Fields are parsed from left to right; if a field occurs
259 * multiple times, the last field's argument wins. The same is true for
260 * fields that are mutually exclusive. Depending on the field, zero or one
261 * argument is expected.
263 * Note that fields marked as 'not implemented yet' are subject to change.
266 * ### I/O
268 * `in-file`
269 * : A pointer of type `FILE*` to the data stream of the input font,
270 * opened for binary reading. Mutually exclusive with `in-buffer`.
272 * `in-buffer`
273 * : A pointer of type `const char*` to a buffer that contains the input
274 * font. Needs `in-buffer-len`. Mutually exclusive with `in-file`.
276 * `in-buffer-len`
277 * : A value of type `size_t`, giving the length of the input buffer.
278 * Needs `in-buffer`.
280 * `out-file`
281 * : A pointer of type `FILE*` to the data stream of the output font,
282 * opened for binary writing. Mutually exclusive with `out-buffer`.
284 * `out-buffer`
285 * : A pointer of type `char**` to a buffer that contains the output
286 * font. Needs `out-buffer-len`. Mutually exclusive with `out-file`.
287 * Deallocate the memory with `free`.
289 * `out-buffer-len`
290 * : A pointer of type `size_t*` to a value giving the length of the
291 * output buffer. Needs `out-buffer`.
293 * `control-file`
294 * : A pointer of type `FILE*` to the data stream of control instructions.
295 * Mutually exclusive with `control-buffer`.
297 * See '[Control Instructions](#control-instructions)' for the syntax
298 * used in such a file or buffer.
300 * `control-buffer`
301 * : A pointer of type `const char*` to a buffer that contains control
302 * instructions. Needs `control-buffer-len`. Mutually exclusive with
303 * `control-file`.
305 * `control-buffer-len`
306 * : A value of type `size_t`, giving the length of the control
307 * instructions buffer. Needs `control-buffer`.
309 * `reference-file`
310 * : A pointer of type `FILE*` to the data stream of the reference font,
311 * opened for binary reading. Mutually exclusive with
312 * `reference-buffer`.
314 * `reference-buffer`
315 * : A pointer of type `const char*` to a buffer that contains the
316 * reference font. Needs `reference-buffer-len`. Mutually exclusive
317 * with `reference-file`.
319 * `reference-buffer-len`
320 * : A value of type `size_t`, giving the length of the reference buffer.
321 * Needs `reference-buffer`.
323 * `reference-index`
324 * : The face index to be used in the reference font. The default value
325 * is\ 0.
327 * `reference-name`
328 * : A string that specifies the name of the reference font. It is only
329 * used to emit a sensible value for the `TTFA` table if `TTFA-info` is
330 * set.
333 * ### Messages and Callbacks
335 * `progress-callback`
336 * : A pointer of type [`TA_Progress_Func`](#callback-ta_progress_func),
337 * specifying a callback function for progress reports. This function
338 * gets called after a single glyph has been processed. If this field
339 * is not set or set to NULL, no progress callback function is used.
341 * `progress-callback-data`
342 * : A pointer of type `void*` to user data that is passed to the
343 * progress callback function.
345 * `error-string`
346 * : A pointer of type `unsigned char**` to a string (in UTF-8 encoding)
347 * that verbally describes the error code. You must not change the
348 * returned value.
350 * `error-callback`
351 * : A pointer of type [`TA_Error_Func`](#callback-ta_error_func),
352 * specifying a callback function for error messages. This function
353 * gets called right before `TTF_autohint` exits. If this field is not
354 * set or set to NULL, no error callback function is used.
356 * Use it as a more sophisticated alternative to `error-string`.
358 * `error-callback-data`
359 * : A point of type `void*` to user data that is passed to the error
360 * callback function.
362 * `info-callback`
363 * : A pointer of type [`TA_Info_Func`](#callback-ta_info_func),
364 * specifying a callback function for manipulating the `name` table.
365 * This function gets called for each `name` table entry. If not set or
366 * set to NULL, `TA_Info_Func` is not called.
368 * `info-post-callback`
369 * : A pointer of type [`TA_Info_Post_Func`](#callback-ta_info_post_func),
370 * specifying a callback function for manipulating the `name` table. It
371 * is called after the function specified with `info-callback` has
372 * iterated over all `name` table entries. If not set or set to NULL,
373 * `TA_Info_Post_Func` is not called.
375 * `info-callback-data`
376 * : A pointer of type `void*` to user data that is passed to the info
377 * callback functions.
379 * `debug`
380 * : If this integer is set to\ 1, lots of debugging information is print
381 * to stderr. The default value is\ 0.
384 * ### General Hinting Options
386 * `hinting-range-min`
387 * : An integer (which must be larger than or equal to\ 2) giving the
388 * lowest PPEM value used for autohinting. If this field is not set, it
389 * defaults to `TA_HINTING_RANGE_MIN`.
391 * `hinting-range-max`
392 * : An integer (which must be larger than or equal to the value of
393 * `hinting-range-min`) giving the highest PPEM value used for
394 * autohinting. If this field is not set, it defaults to
395 * `TA_HINTING_RANGE_MAX`.
397 * `hinting-limit`
398 * : An integer (which must be larger than or equal to the value of
399 * `hinting-range-max`) that gives the largest PPEM value at which
400 * hinting is applied. For larger values, hinting is switched off. If
401 * this field is not set, it defaults to `TA_HINTING_LIMIT`. If it is
402 * set to\ 0, no hinting limit is added to the bytecode.
404 * `hint-composites`
405 * : If this integer is set to\ 1, composite glyphs get separate hints.
406 * This implies adding a special glyph to the font called
407 * ['.ttfautohint'](#the-.ttfautohint-glyph). Setting it to\ 0 (which
408 * is the default), the hints of the composite glyphs' components are
409 * used. Adding hints for composite glyphs increases the size of the
410 * resulting bytecode a lot, but it might deliver better hinting
411 * results. However, this depends on the processed font and must be
412 * checked by inspection.
414 * `adjust-subglyphs`
415 * : An integer (1\ for 'on' and 0\ for 'off', which is the default) to
416 * specify whether native TrueType hinting of the *input font* shall be
417 * applied to all glyphs before passing them to the (internal)
418 * autohinter. The used resolution is the em-size in font units; for
419 * most fonts this is 2048ppem. Use this only if the old hints move or
420 * scale subglyphs independently of the output resolution, for example
421 * some exotic CJK fonts.
423 * `pre-hinting` is a deprecated alias name for this option.
426 * ### Hinting Algorithms
428 * `gray-strong-stem-width`
429 * : An integer (1\ for 'on' and 0\ for 'off', which is the default) that
430 * specifies whether horizontal stems should be snapped and positioned
431 * to integer pixel values for normal grayscale rendering.
433 * `gdi-cleartype-strong-stem-width`
434 * : An integer (1\ for 'on', which is the default, and 0\ for 'off') that
435 * specifies whether horizontal stems should be snapped and positioned
436 * to integer pixel values for GDI ClearType rendering, this is, the
437 * rasterizer version (as returned by the GETINFO bytecode instruction)
438 * is in the range 36\ <= version <\ 38 and ClearType is enabled.
440 * `dw-cleartype-strong-stem-width`
441 * : An integer (1\ for 'on' and 0\ for 'off', which is the default) that
442 * specifies whether horizontal stems should be snapped and positioned
443 * to integer pixel values for DW ClearType rendering, this is, the
444 * rasterizer version (as returned by the GETINFO bytecode instruction)
445 * is >=\ 38, ClearType is enabled, and subpixel positioning is enabled
446 * also.
448 * `increase-x-height`
449 * : An integer. For PPEM values in the range 6\ <= PPEM
450 * <= `increase-x-height`, round up the font's x\ height much more often
451 * than normally (to use the terminology of TrueType's 'Super Round'
452 * bytecode instruction, the threshold gets increased from 5/8px to
453 * 13/16px). If it is set to\ 0, this feature is switched off. If this
454 * field is not set, it defaults to `TA_INCREASE_X_HEIGHT`. Use this
455 * flag to improve the legibility of small font sizes if necessary.
457 * `x-height-snapping-exceptions`
458 * : A pointer of type `const char*` to a null-terminated string that
459 * gives a list of comma separated PPEM values or value ranges at which
460 * no x\ height snapping shall be applied. A value range has the form
461 * *value*~1~`-`*value*~2~, meaning *value*~1~ <= PPEM <= *value*~2~.
462 * *value*~1~ or *value*~2~ (or both) can be missing; a missing value is
463 * replaced by the beginning or end of the whole interval of valid PPEM
464 * values, respectively. Whitespace is not significant; superfluous
465 * commas are ignored, and ranges must be specified in increasing order.
466 * For example, the string `"3, 5-7, 9-"` means the values 3, 5, 6, 7,
467 * 9, 10, 11, 12, etc. Consequently, if the supplied argument is `"-"`,
468 * no x\ height snapping takes place at all. The default is the empty
469 * string (`""`), meaning no snapping exceptions.
471 * `windows-compatibility`
472 * : If this integer is set to\ 1, two artificial blue zones are used,
473 * positioned at the `usWinAscent` and `usWinDescent` values (from the
474 * font's `OS/2` table). The idea is to help ttfautohint so that the
475 * hinted glyphs stay within this horizontal stripe since Windows clips
476 * everything falling outside. The default is\ 0.
479 * ### Scripts
481 * `default-script`
482 * : A string consisting of four lowercase characters that specifies the
483 * default script for OpenType features. After applying all features
484 * that are handled specially, use this value for the remaining
485 * features. The default value is `"latn"`; if set to `"none"`, no
486 * script is used. Valid values can be found in the header file
487 * `ttfautohint-scripts.h`.
489 * `fallback-script`
490 * : A string consisting of four lowercase characters, specifying the
491 * default script for glyphs that can't be mapped to a script
492 * automatically. By default, such glyphs are hinted; if option
493 * `fallback-scaling` is set, they are scaled only instead. Valid
494 * values can be found in the header file `ttfautohint-scripts.h`.
496 * Default value is `"none"`, which means hinting without using a
497 * script's blue zones if `fallback-scaling` isn't set. If
498 * `fallback_scaling` is set, value `"none"` implies no hinting for
499 * unmapped glyphs.
501 * `fallback-scaling`
502 * : Set this integer to\ 1 if glyphs handled by the fallback script
503 * should be scaled only with the fallback script's scaling value,
504 * instead of being hinted with the fallback script's hinting
505 * parameters.
507 * `symbol`
508 * : Set this integer to\ 1 if you want to process a font that ttfautohint
509 * would refuse otherwise because it can't find a single standard
510 * character for any of the supported scripts. ttfautohint then uses a
511 * default (hinting) value for the standard stem width instead of
512 * deriving it from a script's set of standard characters (for the latin
513 * script, one of them is character 'o'). The default value of this
514 * option is\ 0.
516 * `fallback-stem-width`
517 * : Set the horizontal stem width (hinting) value for all scripts that
518 * lack proper standard characters. The value is given in font units
519 * and must be a positive integer. If not set, or the value is zero,
520 * ttfautohint uses a hard-coded default (50\ units at 2048 units per
521 * EM, and linearly scaled for other UPEM values, for example 24\ units
522 * at 1000 UPEM).
524 * For symbol fonts (i.e., option `symbol` is given),
525 * `fallback-stem-width` has an effect only if `fallback-script` is set
526 * also.
529 * ### Miscellaneous
531 * `ignore-restrictions`
532 * : If the font has set bit\ 1 in the 'fsType' field of the `OS/2` table,
533 * the ttfautohint library refuses to process the font since a
534 * permission to do that is required from the font's legal owner. In
535 * case you have such a permission you might set the integer argument to
536 * value\ 1 to make ttfautohint handle the font. The default value
537 * is\ 0.
539 * `TTFA-info`
540 * : If set to\ 1, ttfautohint creates an SFNT table called `TTFA` and
541 * fills it with information on the parameters used while calling
542 * `TTF_autohint`. The format of the output data resembles the
543 * information at the very beginning of the dump emitted by option
544 * `debug`. The default value is\ 0.
546 * Main use of this option is for font editing purposes. For example,
547 * after a font editor has added some glyphs, a front-end to
548 * `TTF_autohint` can parse `TTFA` and feed the parameters into another
549 * call of `TTF_autohint`. The new glyphs are then hinted while hints
550 * of the old glyphs stay unchanged.
552 * If this option is not set, and the font to be processed contains a
553 * `TTFA` table, it gets removed.
555 * Note that such a `TTFA` table gets ignored by all font rendering
556 * engines. In TrueType Collections, the `TTFA` table is added to the
557 * first subfont.
559 * `dehint`
560 * : If set to\ 1, remove all hints from the font. All other hinting
561 * options are ignored.
563 * `epoch`
564 * : An integer of type `unsigned long long`, defined as the number of
565 * seconds (excluding leap seconds) since 01 Jan 1970 00:00:00 UTC. If
566 * set, or if the value is not equal to `ULLONG_MAX`, this epoch gets
567 * used instead of the current date and time for the 'modification time'
568 * field in the TTF header. Use this to get [reproducible
569 * builds](https://reproducible-builds.org/).
572 * ### Remarks
574 * * Obviously, it is necessary to have an input and an output data
575 * stream. All other options are optional.
577 * * `hinting-range-min` and `hinting-range-max` specify the range for
578 * which the autohinter generates optimized hinting code. If a PPEM
579 * value is smaller than the value of `hinting-range-min`, hinting still
580 * takes place but the configuration created for `hinting-range-min` is
581 * used. The analogous action is taken for `hinting-range-max`, only
582 * limited by the value given with `hinting-limit`. The font's `gasp`
583 * table is set up to always use grayscale rendering with grid-fitting
584 * for standard hinting, and symmetric grid-fitting and symmetric
585 * smoothing for horizontal subpixel hinting (ClearType).
587 * * ttfautohint can process its own output a second time only if option
588 * `hint-composites` is not set (or if the font doesn't contain
589 * composite glyphs at all). This limitation might change in the
590 * future.
592 * ```C
595 TA_Error
596 TTF_autohint(const char* options,
597 ...);
600 * ```
604 /* pandoc-end */
606 #ifdef __cplusplus
607 } /* extern "C" */
608 #endif
610 #endif /* TTFAUTOHINT_H_ */
612 /* end of ttfautohint.h */