Update file `no-copyright' and run `update-copyright'.
[ttfautohint.git] / lib / ttfautohint.h
blob395c4a42fcdb786debc6bb504c5e71281531dd33
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_Info_Func`
115 * ------------------------
117 * A callback function to manipulate strings in the `name` table.
118 * *platform_id*, *encoding_id*, *language_id*, and *name_id* are the
119 * identifiers of a `name` table entry pointed to by *str* with a length
120 * pointed to by *str_len* (in bytes; the string has no trailing NULL byte).
121 * Please refer to the [OpenType specification] for a detailed description
122 * of the various parameters, in particular which encoding is used for a
123 * given platform and encoding ID.
125 * [OpenType specification]: http://www.microsoft.com/typography/otspec/name.htm
127 * The string *str* is allocated with `malloc`; the application should
128 * reallocate the data if necessary, ensuring that the string length doesn't
129 * exceed 0xFFFF.
131 * *info_data* is a void pointer to user-supplied data.
133 * If an error occurs, return a non-zero value and don't modify *str* and
134 * *str_len* (such errors are handled as non-fatal).
136 * ```C
139 typedef int
140 (*TA_Info_Func)(unsigned short platform_id,
141 unsigned short encoding_id,
142 unsigned short language_id,
143 unsigned short name_id,
144 unsigned short* str_len,
145 unsigned char** str,
146 void* info_data);
149 * ```
153 /* pandoc-end */
157 * Error values in addition to the FT_Err_XXX constants from FreeType.
159 * All error values specific to ttfautohint start with `TA_Err_'.
161 #include <ttfautohint-errors.h>
164 /* pandoc-start */
167 * Function: `TTF_autohint`
168 * ------------------------
171 * Read a TrueType font, remove existing bytecode (in the SFNT tables
172 * `prep`, `fpgm`, `cvt `, and `glyf`), and write a new TrueType font with
173 * new bytecode based on the autohinting of the FreeType library.
175 * It expects a format string *options* and a variable number of arguments,
176 * depending on the fields in *options*. The fields are comma separated;
177 * whitespace within the format string is not significant, a trailing comma
178 * is ignored. Fields are parsed from left to right; if a field occurs
179 * multiple times, the last field's argument wins. The same is true for
180 * fields that are mutually exclusive. Depending on the field, zero or one
181 * argument is expected.
183 * Note that fields marked as 'not implemented yet' are subject to change.
186 * ### I/O
188 * `in-file`
189 * : A pointer of type `FILE*` to the data stream of the input font,
190 * opened for binary reading. Mutually exclusive with `in-buffer`.
192 * `in-buffer`
193 * : A pointer of type `const char*` to a buffer that contains the input
194 * font. Needs `in-buffer-len`. Mutually exclusive with `in-file`.
196 * `in-buffer-len`
197 * : A value of type `size_t`, giving the length of the input buffer.
198 * Needs `in-buffer`.
200 * `out-file`
201 * : A pointer of type `FILE*` to the data stream of the output font,
202 * opened for binary writing. Mutually exclusive with `out-buffer`.
204 * `out-buffer`
205 * : A pointer of type `char**` to a buffer that contains the output
206 * font. Needs `out-buffer-len`. Mutually exclusive with `out-file`.
207 * Deallocate the memory with `free`.
209 * `out-buffer-len`
210 * : A pointer of type `size_t*` to a value giving the length of the
211 * output buffer. Needs `out-buffer`.
214 * ### Messages and Callbacks
216 * `progress-callback`
217 * : A pointer of type [`TA_Progress_Func`](#callback-ta_progress_func),
218 * specifying a callback function for progress reports. This function
219 * gets called after a single glyph has been processed. If this field
220 * is not set or set to NULL, no progress callback function is used.
222 * `progress-callback-data`
223 * : A pointer of type `void*` to user data that is passed to the
224 * progress callback function.
226 * `error-string`
227 * : A pointer of type `unsigned char**` to a string (in UTF-8 encoding)
228 * that verbally describes the error code. You must not change the
229 * returned value.
231 * `info-callback`
232 * : A pointer of type [`TA_Info_Func`](#callback-ta_info_func),
233 * specifying a callback function for manipulating the `name` table.
234 * This function gets called for each `name` table entry. If not set or
235 * set to NULL, the table data stays unmodified.
237 * `info-callback-data`
238 * : A pointer of type `void*` to user data that is passed to the info
239 * callback function.
241 * `debug`
242 * : If this integer is set to\ 1, lots of debugging information is print
243 * to stderr. The default value is\ 0.
246 * ### General Hinting Options
248 * `hinting-range-min`
249 * : An integer (which must be larger than or equal to\ 2) giving the
250 * lowest PPEM value used for autohinting. If this field is not set, it
251 * defaults to `TA_HINTING_RANGE_MIN`.
253 * `hinting-range-max`
254 * : An integer (which must be larger than or equal to the value of
255 * `hinting-range-min`) giving the highest PPEM value used for
256 * autohinting. If this field is not set, it defaults to
257 * `TA_HINTING_RANGE_MAX`.
259 * `hinting-limit`
260 * : An integer (which must be larger than or equal to the value of
261 * `hinting-range-max`) that gives the largest PPEM value at which
262 * hinting is applied. For larger values, hinting is switched off. If
263 * this field is not set, it defaults to `TA_HINTING_LIMIT`. If it is
264 * set to\ 0, no hinting limit is added to the bytecode.
266 * `hint-composites`
267 * : If this integer is set to\ 1, composite glyphs get separate hints.
268 * This implies adding a special glyph to the font called
269 * ['.ttfautohint'](#the-.ttfautohint-glyph). Setting it to\ 0 (which
270 * is the default), the hints of the composite glyphs' components are
271 * used. Adding hints for composite glyphs increases the size of the
272 * resulting bytecode a lot, but it might deliver better hinting
273 * results. However, this depends on the processed font and must be
274 * checked by inspection.
276 * `pre-hinting`
277 * : An integer (1\ for 'on' and 0\ for 'off', which is the default) to
278 * specify whether native TrueType hinting shall be applied to all
279 * glyphs before passing them to the (internal) autohinter. The used
280 * resolution is the em-size in font units; for most fonts this is
281 * 2048ppem. Use this if the hints move or scale subglyphs
282 * independently of the output resolution.
285 * ### Hinting Algorithms
287 * `gray-strong-stem-width`
288 * : An integer (1\ for 'on' and 0\ for 'off', which is the default) that
289 * specifies whether horizontal stems should be snapped and positioned
290 * to integer pixel values for normal grayscale rendering.
292 * `gdi-cleartype-strong-stem-width`
293 * : An integer (1\ for 'on', which is the default, and 0\ for 'off') that
294 * specifies whether horizontal stems should be snapped and positioned
295 * to integer pixel values for GDI ClearType rendering, this is, the
296 * rasterizer version (as returned by the GETINFO bytecode instruction)
297 * is in the range 36\ <= version <\ 38 and ClearType is enabled.
299 * `dw-cleartype-strong-stem-width`
300 * : An integer (1\ for 'on' and 0\ for 'off', which is the default) that
301 * specifies whether horizontal stems should be snapped and positioned
302 * to integer pixel values for DW ClearType rendering, this is, the
303 * rasterizer version (as returned by the GETINFO bytecode instruction)
304 * is >=\ 38, ClearType is enabled, and subpixel positioning is enabled
305 * also.
307 * `increase-x-height`
308 * : An integer. For PPEM values in the range 6\ <= PPEM
309 * <=\ `increase-x-height`, round up the font's x\ height much more often
310 * than normally. If it is set to\ 0, this feature is switched off. If
311 * this field is not set, it defaults to `TA_INCREASE_X_HEIGHT`. Use
312 * this flag to improve the legibility of small font sizes if necessary.
314 * `x-height-snapping-exceptions`
315 * : A pointer of type `const char*` to a null-terminated string that
316 * gives a list of comma separated PPEM values or value ranges at which
317 * no x-height snapping shall be applied. A value range has the form
318 * *value1*`-`*value2*, meaning *value1* <= PPEM <= *value2*. *value1*
319 * or *value2* (or both) can be missing; a missing value is replaced by
320 * the beginning or end of the whole interval of valid PPEM values,
321 * respectively. Whitespace is not significant; superfluous commas are
322 * ignored, and ranges must be specified in increasing order. For
323 * example, the string `"3, 5-7, 9-"` means the values 3, 5, 6, 7, 9,
324 * 10, 11, 12, etc. Consequently, if the supplied argument is `"-"`, no
325 * x-height snapping takes place at all. The default is the empty
326 * string (`""`), meaning no snapping exceptions.
328 * `windows-compatibility`
329 * : If this integer is set to\ 1, two artificial blue zones are used,
330 * positioned at the `usWinAscent` and `usWinDescent` values (from the
331 * font's `OS/2` table). The idea is to help ttfautohint so that the
332 * hinted glyphs stay within this horizontal stripe since Windows clips
333 * everything falling outside. The default is\ 0.
336 * ### Scripts
338 * `fallback-script`
339 * : A string consisting of four lowercase characters that specifies the
340 * default script for glyphs which can't be mapped to a script
341 * automatically. If set to `"none"` (which is the default), no script
342 * is used. Valid values can be found in the header file
343 * `ttfautohint-scripts.h`.
345 * `symbol`
346 * : Set this integer to\ 1 if you want to process a font that lacks the
347 * characters of a supported script, for example, a symbol font.
348 * ttfautohint then uses default values for the standard stem width and
349 * height instead of deriving these values from a script's key character
350 * (for the latin script, it is character 'o'). The default value
351 * is\ 0.
354 * ### Miscellaneous
356 * `ignore-restrictions`
357 * : If the font has set bit\ 1 in the 'fsType' field of the `OS/2` table,
358 * the ttfautohint library refuses to process the font since a
359 * permission to do that is required from the font's legal owner. In
360 * case you have such a permission you might set the integer argument to
361 * value\ 1 to make ttfautohint handle the font. The default value
362 * is\ 0.
364 * `dehint`
365 * : If set to\ 1, remove all hints from the font. All other hinting
366 * options are ignored.
369 * ### Remarks
371 * * Obviously, it is necessary to have an input and an output data
372 * stream. All other options are optional.
374 * * `hinting-range-min` and `hinting-range-max` specify the range for
375 * which the autohinter generates optimized hinting code. If a PPEM
376 * value is smaller than the value of `hinting-range-min`, hinting still
377 * takes place but the configuration created for `hinting-range-min` is
378 * used. The analogous action is taken for `hinting-range-max`, only
379 * limited by the value given with `hinting-limit`. The font's `gasp`
380 * table is set up to always use grayscale rendering with grid-fitting
381 * for standard hinting, and symmetric grid-fitting and symmetric
382 * smoothing for horizontal subpixel hinting (ClearType).
384 * * ttfautohint can process its own output a second time only if option
385 * `hint-composites` is not set (or if the font doesn't contain
386 * composite glyphs at all). This limitation might change in the
387 * future.
389 * ```C
392 TA_Error
393 TTF_autohint(const char* options,
394 ...);
397 * ```
401 /* pandoc-end */
403 #ifdef __cplusplus
404 } /* extern "C" */
405 #endif
407 #endif /* __TTFAUTOHINT_H__ */
409 /* end of ttfautohint.h */