Add support for SOURCE_DATE_EPOCH environment variable.
[ttfautohint.git] / lib / ttfautohint.h
blob1f1276fc2fc0d21579ae1f87fa44b0caa721113f
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.
254 * It expects a format string *options* and a variable number of arguments,
255 * depending on the fields in *options*. The fields are comma separated;
256 * whitespace within the format string is not significant, a trailing comma
257 * is ignored. Fields are parsed from left to right; if a field occurs
258 * multiple times, the last field's argument wins. The same is true for
259 * fields that are mutually exclusive. Depending on the field, zero or one
260 * argument is expected.
262 * Note that fields marked as 'not implemented yet' are subject to change.
265 * ### I/O
267 * `in-file`
268 * : A pointer of type `FILE*` to the data stream of the input font,
269 * opened for binary reading. Mutually exclusive with `in-buffer`.
271 * `in-buffer`
272 * : A pointer of type `const char*` to a buffer that contains the input
273 * font. Needs `in-buffer-len`. Mutually exclusive with `in-file`.
275 * `in-buffer-len`
276 * : A value of type `size_t`, giving the length of the input buffer.
277 * Needs `in-buffer`.
279 * `out-file`
280 * : A pointer of type `FILE*` to the data stream of the output font,
281 * opened for binary writing. Mutually exclusive with `out-buffer`.
283 * `out-buffer`
284 * : A pointer of type `char**` to a buffer that contains the output
285 * font. Needs `out-buffer-len`. Mutually exclusive with `out-file`.
286 * Deallocate the memory with `free`.
288 * `out-buffer-len`
289 * : A pointer of type `size_t*` to a value giving the length of the
290 * output buffer. Needs `out-buffer`.
292 * `control-file`
293 * : A pointer of type `FILE*` to the data stream of control instructions.
294 * Mutually exclusive with `control-buffer`.
296 * See '[Control Instructions](#control-instructions)' for the syntax
297 * used in such a file or buffer.
299 * `control-buffer`
300 * : A pointer of type `const char*` to a buffer that contains control
301 * instructions. Needs `control-buffer-len`. Mutually exclusive with
302 * `control-file`.
304 * `control-buffer-len`
305 * : A value of type `size_t`, giving the length of the control
306 * instructions buffer. Needs `control-buffer`.
309 * ### Messages and Callbacks
311 * `progress-callback`
312 * : A pointer of type [`TA_Progress_Func`](#callback-ta_progress_func),
313 * specifying a callback function for progress reports. This function
314 * gets called after a single glyph has been processed. If this field
315 * is not set or set to NULL, no progress callback function is used.
317 * `progress-callback-data`
318 * : A pointer of type `void*` to user data that is passed to the
319 * progress callback function.
321 * `error-string`
322 * : A pointer of type `unsigned char**` to a string (in UTF-8 encoding)
323 * that verbally describes the error code. You must not change the
324 * returned value.
326 * `error-callback`
327 * : A pointer of type [`TA_Error_Func`](#callback-ta_error_func),
328 * specifying a callback function for error messages. This function
329 * gets called right before `TTF_autohint` exits. If this field is not
330 * set or set to NULL, no error callback function is used.
332 * Use it as a more sophisticated alternative to `error-string`.
334 * `error-callback-data`
335 * : A point of type `void*` to user data that is passed to the error
336 * callback function.
338 * `info-callback`
339 * : A pointer of type [`TA_Info_Func`](#callback-ta_info_func),
340 * specifying a callback function for manipulating the `name` table.
341 * This function gets called for each `name` table entry. If not set or
342 * set to NULL, `TA_Info_Func` is not called.
344 * `info-post-callback`
345 * : A pointer of type [`TA_Info_Post_Func`](#callback-ta_info_post_func),
346 * specifying a callback function for manipulating the `name` table. It
347 * is called after the function specified with `info-callback` has
348 * iterated over all `name` table entries. If not set or set to NULL,
349 * `TA_Info_Post_Func` is not called.
351 * `info-callback-data`
352 * : A pointer of type `void*` to user data that is passed to the info
353 * callback functions.
355 * `debug`
356 * : If this integer is set to\ 1, lots of debugging information is print
357 * to stderr. The default value is\ 0.
360 * ### General Hinting Options
362 * `hinting-range-min`
363 * : An integer (which must be larger than or equal to\ 2) giving the
364 * lowest PPEM value used for autohinting. If this field is not set, it
365 * defaults to `TA_HINTING_RANGE_MIN`.
367 * `hinting-range-max`
368 * : An integer (which must be larger than or equal to the value of
369 * `hinting-range-min`) giving the highest PPEM value used for
370 * autohinting. If this field is not set, it defaults to
371 * `TA_HINTING_RANGE_MAX`.
373 * `hinting-limit`
374 * : An integer (which must be larger than or equal to the value of
375 * `hinting-range-max`) that gives the largest PPEM value at which
376 * hinting is applied. For larger values, hinting is switched off. If
377 * this field is not set, it defaults to `TA_HINTING_LIMIT`. If it is
378 * set to\ 0, no hinting limit is added to the bytecode.
380 * `hint-composites`
381 * : If this integer is set to\ 1, composite glyphs get separate hints.
382 * This implies adding a special glyph to the font called
383 * ['.ttfautohint'](#the-.ttfautohint-glyph). Setting it to\ 0 (which
384 * is the default), the hints of the composite glyphs' components are
385 * used. Adding hints for composite glyphs increases the size of the
386 * resulting bytecode a lot, but it might deliver better hinting
387 * results. However, this depends on the processed font and must be
388 * checked by inspection.
390 * `adjust-subglyphs`
391 * : An integer (1\ for 'on' and 0\ for 'off', which is the default) to
392 * specify whether native TrueType hinting of the *input font* shall be
393 * applied to all glyphs before passing them to the (internal)
394 * autohinter. The used resolution is the em-size in font units; for
395 * most fonts this is 2048ppem. Use this only if the old hints move or
396 * scale subglyphs independently of the output resolution, for example
397 * some exotic CJK fonts.
399 * `pre-hinting` is a deprecated alias name for this option.
402 * ### Hinting Algorithms
404 * `gray-strong-stem-width`
405 * : An integer (1\ for 'on' and 0\ for 'off', which is the default) that
406 * specifies whether horizontal stems should be snapped and positioned
407 * to integer pixel values for normal grayscale rendering.
409 * `gdi-cleartype-strong-stem-width`
410 * : An integer (1\ for 'on', which is the default, and 0\ for 'off') that
411 * specifies whether horizontal stems should be snapped and positioned
412 * to integer pixel values for GDI ClearType rendering, this is, the
413 * rasterizer version (as returned by the GETINFO bytecode instruction)
414 * is in the range 36\ <= version <\ 38 and ClearType is enabled.
416 * `dw-cleartype-strong-stem-width`
417 * : An integer (1\ for 'on' and 0\ for 'off', which is the default) that
418 * specifies whether horizontal stems should be snapped and positioned
419 * to integer pixel values for DW ClearType rendering, this is, the
420 * rasterizer version (as returned by the GETINFO bytecode instruction)
421 * is >=\ 38, ClearType is enabled, and subpixel positioning is enabled
422 * also.
424 * `increase-x-height`
425 * : An integer. For PPEM values in the range 6\ <= PPEM
426 * <= `increase-x-height`, round up the font's x\ height much more often
427 * than normally (to use the terminology of TrueType's 'Super Round'
428 * bytecode instruction, the threshold gets increased from 5/8px to
429 * 13/16px). If it is set to\ 0, this feature is switched off. If this
430 * field is not set, it defaults to `TA_INCREASE_X_HEIGHT`. Use this
431 * flag to improve the legibility of small font sizes if necessary.
433 * `x-height-snapping-exceptions`
434 * : A pointer of type `const char*` to a null-terminated string that
435 * gives a list of comma separated PPEM values or value ranges at which
436 * no x\ height snapping shall be applied. A value range has the form
437 * *value*~1~`-`*value*~2~, meaning *value*~1~ <= PPEM <= *value*~2~.
438 * *value*~1~ or *value*~2~ (or both) can be missing; a missing value is
439 * replaced by the beginning or end of the whole interval of valid PPEM
440 * values, respectively. Whitespace is not significant; superfluous
441 * commas are ignored, and ranges must be specified in increasing order.
442 * For example, the string `"3, 5-7, 9-"` means the values 3, 5, 6, 7,
443 * 9, 10, 11, 12, etc. Consequently, if the supplied argument is `"-"`,
444 * no x\ height snapping takes place at all. The default is the empty
445 * string (`""`), meaning no snapping exceptions.
447 * `windows-compatibility`
448 * : If this integer is set to\ 1, two artificial blue zones are used,
449 * positioned at the `usWinAscent` and `usWinDescent` values (from the
450 * font's `OS/2` table). The idea is to help ttfautohint so that the
451 * hinted glyphs stay within this horizontal stripe since Windows clips
452 * everything falling outside. The default is\ 0.
455 * ### Scripts
457 * `default-script`
458 * : A string consisting of four lowercase characters that specifies the
459 * default script for OpenType features. After applying all features
460 * that are handled specially, use this value for the remaining
461 * features. The default value is `"latn"`; if set to `"none"`, no
462 * script is used. Valid values can be found in the header file
463 * `ttfautohint-scripts.h`.
465 * `fallback-script`
466 * : A string consisting of four lowercase characters, specifying the
467 * default script for glyphs that can't be mapped to a script
468 * automatically. By default, such glyphs are hinted; if option
469 * `fallback-scaling` is set, they are scaled only instead. Valid
470 * values can be found in the header file `ttfautohint-scripts.h`.
472 * Default value is `"none"`, which means hinting without using a
473 * script's blue zones if `fallback-scaling` isn't set. If
474 * `fallback_scaling` is set, value `"none"` implies no hinting for
475 * unmapped glyphs.
477 * `fallback-scaling`
478 * : Set this integer to\ 1 if glyphs handled by the fallback script
479 * should be scaled only with the fallback script's scaling value,
480 * instead of being hinted with the fallback script's hinting
481 * parameters.
483 * `symbol`
484 * : Set this integer to\ 1 if you want to process a font that ttfautohint
485 * would refuse otherwise because it can't find a single standard
486 * character for any of the supported scripts. ttfautohint then uses a
487 * default (hinting) value for the standard stem width instead of
488 * deriving it from a script's set of standard characters (for the latin
489 * script, one of them is character 'o'). The default value of this
490 * option is\ 0.
492 * `fallback-stem-width`
493 * : Set the horizontal stem width (hinting) value for all scripts that
494 * lack proper standard characters. The value is given in font units
495 * and must be a positive integer. If not set, or the value is zero,
496 * ttfautohint uses a hard-coded default (50\ units at 2048 units per
497 * EM, and linearly scaled for other UPEM values, for example 24\ units
498 * at 1000 UPEM).
500 * For symbol fonts (i.e., option `symbol` is given),
501 * `fallback-stem-width` has an effect only if `fallback-script` is set
502 * also.
505 * ### Miscellaneous
507 * `ignore-restrictions`
508 * : If the font has set bit\ 1 in the 'fsType' field of the `OS/2` table,
509 * the ttfautohint library refuses to process the font since a
510 * permission to do that is required from the font's legal owner. In
511 * case you have such a permission you might set the integer argument to
512 * value\ 1 to make ttfautohint handle the font. The default value
513 * is\ 0.
515 * `TTFA-info`
516 * : If set to\ 1, ttfautohint creates an SFNT table called `TTFA` and
517 * fills it with information on the parameters used while calling
518 * `TTF_autohint`. The format of the output data resembles the
519 * information at the very beginning of the dump emitted by option
520 * `debug`. The default value is\ 0.
522 * Main use of this option is for font editing purposes. For example,
523 * after a font editor has added some glyphs, a front-end to
524 * `TTF_autohint` can parse `TTFA` and feed the parameters into another
525 * call of `TTF_autohint`. The new glyphs are then hinted while hints
526 * of the old glyphs stay unchanged.
528 * If this option is not set, and the font to be processed contains a
529 * `TTFA` table, it gets removed.
531 * Note that such a `TTFA` table gets ignored by all font rendering
532 * engines. In TrueType Collections, the `TTFA` table is added to the
533 * first subfont.
535 * `dehint`
536 * : If set to\ 1, remove all hints from the font. All other hinting
537 * options are ignored.
539 * `epoch`
540 * : An integer of type `unsigned long long`, defined as the number of
541 * seconds (excluding leap seconds) since 01 Jan 1970 00:00:00 UTC. If
542 * set, or if the value is not equal to `ULLONG_MAX`, this epoch gets
543 * used instead of the current date and time for the 'modification time'
544 * field in the TTF header. Use this to get [reproducible
545 * builds](https://reproducible-builds.org/).
548 * ### Remarks
550 * * Obviously, it is necessary to have an input and an output data
551 * stream. All other options are optional.
553 * * `hinting-range-min` and `hinting-range-max` specify the range for
554 * which the autohinter generates optimized hinting code. If a PPEM
555 * value is smaller than the value of `hinting-range-min`, hinting still
556 * takes place but the configuration created for `hinting-range-min` is
557 * used. The analogous action is taken for `hinting-range-max`, only
558 * limited by the value given with `hinting-limit`. The font's `gasp`
559 * table is set up to always use grayscale rendering with grid-fitting
560 * for standard hinting, and symmetric grid-fitting and symmetric
561 * smoothing for horizontal subpixel hinting (ClearType).
563 * * ttfautohint can process its own output a second time only if option
564 * `hint-composites` is not set (or if the font doesn't contain
565 * composite glyphs at all). This limitation might change in the
566 * future.
568 * ```C
571 TA_Error
572 TTF_autohint(const char* options,
573 ...);
576 * ```
580 /* pandoc-end */
582 #ifdef __cplusplus
583 } /* extern "C" */
584 #endif
586 #endif /* TTFAUTOHINT_H_ */
588 /* end of ttfautohint.h */