`number_set_parse': Improve diagnostics.
[ttfautohint.git] / lib / ttfautohint.h
blob2ef83f40d2109c1fd6763e3ac4982cfe2b672126
1 /* ttfautohint.h */
3 /*
4 * Copyright (C) 2011-2012 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 * ------------------------
170 * Read a TrueType font, remove existing bytecode (in the SFNT tables
171 * `prep`, `fpgm`, `cvt `, and `glyf`), and write a new TrueType font with
172 * new bytecode based on the autohinting of the FreeType library.
174 * It expects a format string *options* and a variable number of arguments,
175 * depending on the fields in *options*. The fields are comma separated;
176 * whitespace within the format string is not significant, a trailing comma
177 * is ignored. Fields are parsed from left to right; if a field occurs
178 * multiple times, the last field's argument wins. The same is true for
179 * fields which are mutually exclusive. Depending on the field, zero or one
180 * argument is expected.
182 * Note that fields marked as 'not implemented yet' are subject to change.
184 * `in-file`
185 * : A pointer of type `FILE*` to the data stream of the input font,
186 * opened for binary reading. Mutually exclusive with `in-buffer`.
188 * `in-buffer`
189 * : A pointer of type `const char*` to a buffer which contains the input
190 * font. Needs `in-buffer-len`. Mutually exclusive with `in-file`.
192 * `in-buffer-len`
193 * : A value of type `size_t`, giving the length of the input buffer.
194 * Needs `in-buffer`.
196 * `out-file`
197 * : A pointer of type `FILE*` to the data stream of the output font,
198 * opened for binary writing. Mutually exclusive with `out-buffer`.
200 * `out-buffer`
201 * : A pointer of type `char**` to a buffer which contains the output
202 * font. Needs `out-buffer-len`. Mutually exclusive with `out-file`.
203 * Deallocate the memory with `free`.
205 * `out-buffer-len`
206 * : A pointer of type `size_t*` to a value giving the length of the
207 * output buffer. Needs `out-buffer`.
209 * `progress-callback`
210 * : A pointer of type [`TA_Progress_Func`](#callback-ta_progress_func),
211 * specifying a callback function for progress reports. This function
212 * gets called after a single glyph has been processed. If this field
213 * is not set or set to NULL, no progress callback function is used.
215 * `progress-callback-data`
216 * : A pointer of type `void*` to user data which is passed to the
217 * progress callback function.
219 * `error-string`
220 * : A pointer of type `unsigned char**` to a string (in UTF-8 encoding)
221 * which verbally describes the error code. You must not change the
222 * returned value.
224 * `hinting-range-min`
225 * : An integer (which must be larger than or equal to\ 2) giving the
226 * lowest PPEM value used for autohinting. If this field is not set, it
227 * defaults to `TA_HINTING_RANGE_MIN`.
229 * `hinting-range-max`
230 * : An integer (which must be larger than or equal to the value of
231 * `hinting-range-min`) giving the highest PPEM value used for
232 * autohinting. If this field is not set, it defaults to
233 * `TA_HINTING_RANGE_MAX`.
235 * `hinting-limit`
236 * : An integer (which must be larger than or equal to the value of
237 * `hinting-range-max`) which gives the largest PPEM value at which
238 * hinting is applied. For larger values, hinting is switched off. If
239 * this field is not set, it defaults to `TA_HINTING_LIMIT`. If it is
240 * set to\ 0, no hinting limit is added to the bytecode.
242 * `gray-strong-stem-width`
243 * : An integer (1\ for 'on' and 0\ for 'off', which is the default) which
244 * specifies whether horizontal stems should be snapped and positioned
245 * to integer pixel values for normal grayscale rendering.
247 * `gdi-cleartype-strong-stem-width`
248 * : An integer (1\ for 'on', which is the default, and 0\ for 'off') which
249 * specifies whether horizontal stems should be snapped and positioned
250 * to integer pixel values for GDI ClearType rendering, this is, the
251 * rasterizer version (as returned by the GETINFO bytecode instruction)
252 * is in the range 36\ <= version <\ 38 and ClearType is enabled.
254 * `dw-cleartype-strong-stem-width`
255 * : An integer (1\ for 'on' and 0\ for 'off', which is the default) which
256 * specifies whether horizontal stems should be snapped and positioned
257 * to integer pixel values for DW ClearType rendering, this is, the
258 * rasterizer version (as returned by the GETINFO bytecode instruction)
259 * is >=\ 38, ClearType is enabled, and subpixel positioning is enabled
260 * also.
262 * `increase-x-height`
263 * : An integer. For PPEM values in the range 6\ <= PPEM
264 * <=\ `increase-x-height`, round up the font's x\ height much more often
265 * than normally. If it is set to\ 0, this feature is switched off. If
266 * this field is not set, it defaults to `TA_INCREASE_X_HEIGHT`. Use
267 * this flag to improve the legibility of small font sizes if necessary.
269 * `hint-with-components`
270 * : If this integer is set to\ 1 (which is the default), ttfautohint
271 * handles composite glyphs as a whole. This implies adding a special
272 * glyph to the font, as documented [here](#the-.ttfautohint-glyph).
273 * Setting it to\ 0, the components of composite glyphs are hinted
274 * separately. While separate hinting of subglyphs makes the resulting
275 * bytecode much smaller, it might deliver worse results. However, this
276 * depends on the processed font and must be checked by inspection.
278 * `pre-hinting`
279 * : An integer (1\ for 'on' and 0\ for 'off', which is the default) to
280 * specify whether native TrueType hinting shall be applied to all
281 * glyphs before passing them to the (internal) autohinter. The used
282 * resolution is the em-size in font units; for most fonts this is
283 * 2048ppem. Use this if the hints move or scale subglyphs
284 * independently of the output resolution.
286 * `info-callback`
287 * : A pointer of type [`TA_Info_Func`](#callback-ta_info_func),
288 * specifying a callback function for manipulating the `name` table.
289 * This function gets called for each `name` table entry. If not set or
290 * set to NULL, the table data stays unmodified.
292 * `info-callback-data`
293 * : A pointer of type `void*` to user data which is passed to the info
294 * callback function.
296 * `x-height-snapping-exceptions`
297 * : A pointer of type `const char*` to a null-terminated string which
298 * gives a list of comma separated PPEM values or value ranges at which
299 * no x-height snapping shall be applied. A value range has the form
300 * *value1*`-`*value2*, meaning *value1* <= PPEM <= *value2*.
301 * Whitespace is not significant; a trailing comma is ignored. If the
302 * supplied argument is NULL, no x-height snapping takes place at all.
303 * By default, there are no snapping exceptions. Not implemented yet.
305 * `windows-compatibility`
306 * : If this integer is set to\ 1, two artificial blue zones are used,
307 * positioned at the `usWinAscent` and `usWinDescent` values (from the
308 * font's `OS/2` table). The idea is to help ttfautohint so that the
309 * hinted glyphs stay within this horizontal stripe since Windows clips
310 * everything falling outside. The default is\ 0.
312 * `ignore-restrictions`
313 * : If the font has set bit\ 1 in the 'fsType' field of the `OS/2` table,
314 * the ttfautohint library refuses to process the font since a
315 * permission to do that is required from the font's legal owner. In
316 * case you have such a permission you might set the integer argument to
317 * value\ 1 to make ttfautohint handle the font. The default value
318 * is\ 0.
320 * `fallback-script`
321 * : An integer which specifies the default script for glyphs not in the
322 * 'latin' range. If set to\ 1, the 'latin' script is used (other
323 * scripts are not supported yet). By default, no script is used
324 * (value\ 0; this disables autohinting for such glyphs).
326 * `symbol`
327 * : Set this integer to\ 1 if you want to process a font which lacks the
328 * characters of a supported script, for example, a symbol font.
329 * ttfautohint then uses default values for the standard stem width and
330 * height instead of deriving these values from a script's key character
331 * (for the latin script, it is character 'o'). The default value
332 * is\ 0.
334 * `debug`
335 * : If this integer is set to\ 1, lots of debugging information is print
336 * to stderr. The default value is\ 0.
338 * Remarks:
340 * * Obviously, it is necessary to have an input and an output data
341 * stream. All other options are optional.
343 * * `hinting-range-min` and `hinting-range-max` specify the range for
344 * which the autohinter generates optimized hinting code. If a PPEM
345 * value is smaller than the value of `hinting-range-min`, hinting still
346 * takes place but the configuration created for `hinting-range-min` is
347 * used. The analogous action is taken for `hinting-range-max`, only
348 * limited by the value given with `hinting-limit`. The font's `gasp`
349 * table is set up to always use grayscale rendering with grid-fitting
350 * for standard hinting, and symmetric grid-fitting and symmetric
351 * smoothing for horizontal subpixel hinting (ClearType).
353 * * ttfautohint can't process a font a second time (well, it can, if the
354 * font doesn't contain composite glyphs). Just think of ttfautohint as
355 * being a compiler, a tool which also can't process its created output
356 * again.
358 * ```C
361 TA_Error
362 TTF_autohint(const char* options,
363 ...);
366 * ```
370 /* pandoc-end */
372 #ifdef __cplusplus
373 } /* extern "C" */
374 #endif
376 #endif /* __TTFAUTOHINT_H__ */
378 /* end of ttfautohint.h */