Improve comment.
[ttfautohint.git] / lib / ttfautohint.h
1 /* ttfautohint.h */
2
3 /*
4  * Copyright (C) 2011-2013 by Werner Lemberg.
5  *
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.
10  *
11  * The file `COPYING' mentioned in the previous paragraph is distributed
12  * with the ttfautohint library.
13  */
14
15
16 #ifndef __TTFAUTOHINT_H__
17 #define __TTFAUTOHINT_H__
18
19 #include <stdarg.h>
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25
26 /*
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.
32  */
33
34
35 /* pandoc-start */
36
37 /*
38  * The ttfautohint API
39  * ===================
40  *
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.
45  *
46  */
47
48
49 /*
50  * Preprocessor Macros and Typedefs
51  * --------------------------------
52  *
53  * Some default values.
54  *
55  * ```C
56  */
57
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
62
63 /*
64  *```
65  *
66  * An error type.
67  *
68  * ```C
69  */
70
71 typedef int TA_Error;
72
73 /*
74  * ```
75  *
76  */
77
78
79 /*
80  * Callback: `TA_Progress_Func`
81  * ----------------------------
82  *
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).
87  *
88  * *curr_sfnt* gives the current subfont within a TrueType Collection (TTC),
89  * and *num_sfnts* the total number of subfonts.
90  *
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.
94  *
95  * *progress_data* is a void pointer to user supplied data.
96  *
97  * ```C
98  */
99
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);
106
107 /*
108  * ```
109  *
110  */
111
112
113 /*
114  * Callback: `TA_Info_Func`
115  * ------------------------
116  *
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.
124  *
125  * [OpenType specification]: http://www.microsoft.com/typography/otspec/name.htm
126  *
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.
130  *
131  * *info_data* is a void pointer to user supplied data.
132  *
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).
135  *
136  * ```C
137  */
138
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);
147
148 /*
149  * ```
150  *
151  */
152
153 /* pandoc-end */
154
155
156 /*
157  * Error values in addition to the FT_Err_XXX constants from FreeType.
158  *
159  * All error values specific to ttfautohint start with `TA_Err_'.
160  */
161 #include <ttfautohint-errors.h>
162
163
164 /* pandoc-start */
165
166 /*
167  * Function: `TTF_autohint`
168  * ------------------------
169  *
170  *
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.
174  *
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 which are mutually exclusive.  Depending on the field, zero or one
181  * argument is expected.
182  *
183  * Note that fields marked as 'not implemented yet' are subject to change.
184  *
185  *
186  * ### I/O
187  *
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`.
191  *
192  * `in-buffer`
193  * :   A pointer of type `const char*` to a buffer which contains the input
194  *     font.  Needs `in-buffer-len`.  Mutually exclusive with `in-file`.
195  *
196  * `in-buffer-len`
197  * :   A value of type `size_t`, giving the length of the input buffer.
198  *     Needs `in-buffer`.
199  *
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`.
203  *
204  * `out-buffer`
205  * :   A pointer of type `char**` to a buffer which contains the output
206  *     font.  Needs `out-buffer-len`.  Mutually exclusive with `out-file`.
207  *     Deallocate the memory with `free`.
208  *
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`.
212  *
213  *
214  * ### Messages and Callbacks
215  *
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.
221  *
222  * `progress-callback-data`
223  * :   A pointer of type `void*` to user data which is passed to the
224  *     progress callback function.
225  *
226  * `error-string`
227  * :   A pointer of type `unsigned char**` to a string (in UTF-8 encoding)
228  *     which verbally describes the error code.  You must not change the
229  *     returned value.
230  *
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.
236  *
237  * `info-callback-data`
238  * :   A pointer of type `void*` to user data which is passed to the info
239  *     callback function.
240  *
241  * `debug`
242  * :   If this integer is set to\ 1, lots of debugging information is print
243  *     to stderr.  The default value is\ 0.
244  *
245  *
246  * ### General Hinting Options
247  *
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`.
252  *
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`.
258  *
259  * `hinting-limit`
260  * :   An integer (which must be larger than or equal to the value of
261  *     `hinting-range-max`) which 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.
265  *
266  * `hint-with-components`
267  * :   If this integer is set to\ 1 (which is the default), ttfautohint
268  *     handles composite glyphs as a whole.  This implies adding a special
269  *     glyph to the font, as documented [here](#the-.ttfautohint-glyph).
270  *     Setting it to\ 0, the components of composite glyphs are hinted
271  *     separately.  While separate hinting of subglyphs makes the resulting
272  *     bytecode much smaller, it might deliver worse results.  However, this
273  *     depends on the processed font and must be checked by inspection.
274  *
275  * `pre-hinting`
276  * :   An integer (1\ for 'on' and 0\ for 'off', which is the default) to
277  *     specify whether native TrueType hinting shall be applied to all
278  *     glyphs before passing them to the (internal) autohinter.  The used
279  *     resolution is the em-size in font units; for most fonts this is
280  *     2048ppem.  Use this if the hints move or scale subglyphs
281  *     independently of the output resolution.
282  *
283  *
284  * ### Hinting Algorithms
285  *
286  * `gray-strong-stem-width`
287  * :   An integer (1\ for 'on' and 0\ for 'off', which is the default) which
288  *     specifies whether horizontal stems should be snapped and positioned
289  *     to integer pixel values for normal grayscale rendering.
290  *
291  * `gdi-cleartype-strong-stem-width`
292  * :   An integer (1\ for 'on', which is the default, and 0\ for 'off') which
293  *     specifies whether horizontal stems should be snapped and positioned
294  *     to integer pixel values for GDI ClearType rendering, this is, the
295  *     rasterizer version (as returned by the GETINFO bytecode instruction)
296  *     is in the range 36\ <= version <\ 38 and ClearType is enabled.
297  *
298  * `dw-cleartype-strong-stem-width`
299  * :   An integer (1\ for 'on' and 0\ for 'off', which is the default) which
300  *     specifies whether horizontal stems should be snapped and positioned
301  *     to integer pixel values for DW ClearType rendering, this is, the
302  *     rasterizer version (as returned by the GETINFO bytecode instruction)
303  *     is >=\ 38, ClearType is enabled, and subpixel positioning is enabled
304  *     also.
305  *
306  * `increase-x-height`
307  * :   An integer.  For PPEM values in the range 6\ <= PPEM
308  *     <=\ `increase-x-height`, round up the font's x\ height much more often
309  *     than normally.  If it is set to\ 0, this feature is switched off.  If
310  *     this field is not set, it defaults to `TA_INCREASE_X_HEIGHT`.  Use
311  *     this flag to improve the legibility of small font sizes if necessary.
312  *
313  * `x-height-snapping-exceptions`
314  * :   A pointer of type `const char*` to a null-terminated string which
315  *     gives a list of comma separated PPEM values or value ranges at which
316  *     no x-height snapping shall be applied.  A value range has the form
317  *     *value1*`-`*value2*, meaning *value1* <= PPEM <= *value2*.  *value1*
318  *     or *value2* (or both) can be missing; a missing value is replaced by
319  *     the beginning or end of the whole interval of valid PPEM values,
320  *     respectively.  Whitespace is not significant; superfluous commas are
321  *     ignored, and ranges must be specified in increasing order.  For
322  *     example, the string `"3, 5-7, 9-"` means the values 3, 5, 6, 7, 9,
323  *     10, 11, 12, etc.  Consequently, if the supplied argument is `"-"`, no
324  *     x-height snapping takes place at all.  The default is the empty
325  *     string (`""`), meaning no snapping exceptions.
326  *
327  * `windows-compatibility`
328  * :   If this integer is set to\ 1, two artificial blue zones are used,
329  *     positioned at the `usWinAscent` and `usWinDescent` values (from the
330  *     font's `OS/2` table).  The idea is to help ttfautohint so that the
331  *     hinted glyphs stay within this horizontal stripe since Windows clips
332  *     everything falling outside.  The default is\ 0.
333  *
334  *
335  * ### Scripts
336  *
337  * `fallback-script`
338  * :   An integer which specifies the default script for glyphs not in the
339  *     'latin' range.  If set to\ 1, the 'latin' script is used (other
340  *     scripts are not supported yet).  By default, no script is used
341  *     (value\ 0; this disables autohinting for such glyphs).
342  *
343  * `symbol`
344  * :   Set this integer to\ 1 if you want to process a font which lacks the
345  *     characters of a supported script, for example, a symbol font.
346  *     ttfautohint then uses default values for the standard stem width and
347  *     height instead of deriving these values from a script's key character
348  *     (for the latin script, it is character 'o').  The default value
349  *     is\ 0.
350  *
351  *
352  * ### Miscellaneous
353  *
354  * `ignore-restrictions`
355  * :   If the font has set bit\ 1 in the 'fsType' field of the `OS/2` table,
356  *     the ttfautohint library refuses to process the font since a
357  *     permission to do that is required from the font's legal owner.  In
358  *     case you have such a permission you might set the integer argument to
359  *     value\ 1 to make ttfautohint handle the font.  The default value
360  *     is\ 0.
361  *
362  * `dehint`
363  * :   If set to\ 1, remove all hints from the font.  All other hinting
364  *     options are ignored.
365  *
366  *
367  * ### Remarks
368  *
369  *   * Obviously, it is necessary to have an input and an output data
370  *     stream.  All other options are optional.
371  *
372  *   * `hinting-range-min` and `hinting-range-max` specify the range for
373  *     which the autohinter generates optimized hinting code.  If a PPEM
374  *     value is smaller than the value of `hinting-range-min`, hinting still
375  *     takes place but the configuration created for `hinting-range-min` is
376  *     used.  The analogous action is taken for `hinting-range-max`, only
377  *     limited by the value given with `hinting-limit`.  The font's `gasp`
378  *     table is set up to always use grayscale rendering with grid-fitting
379  *     for standard hinting, and symmetric grid-fitting and symmetric
380  *     smoothing for horizontal subpixel hinting (ClearType).
381  *
382  *   * ttfautohint can't process a font a second time (well, it can, if the
383  *     font doesn't contain composite glyphs).  Just think of ttfautohint as
384  *     being a compiler, a tool which also can't process its created output
385  *     again.
386  *
387  * ```C
388  */
389
390 TA_Error
391 TTF_autohint(const char* options,
392              ...);
393
394 /*
395  * ```
396  *
397  */
398
399 /* pandoc-end */
400
401 #ifdef __cplusplus
402 } /* extern "C" */
403 #endif
404
405 #endif /* __TTFAUTOHINT_H__ */
406
407 /* end of ttfautohint.h */