[doc] Increase description text size in `glyph-terms.svg'.
[ttfautohint.git] / lib / tatypes.h
blobd9c4636c46ee067ef92cdfe91842f69023b6a895
1 /* tatypes.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 /* originally file `aftypes.h' (2011-Mar-30) from FreeType */
18 /* heavily modified 2011 by Werner Lemberg <wl@gnu.org> */
20 #ifndef __TATYPES_H__
21 #define __TATYPES_H__
23 #include <ft2build.h>
25 #include FT_FREETYPE_H
26 #include FT_OUTLINE_H
28 #include "tablue.h"
31 /* enable one of the following three definitions for debugging */
32 /* #define TA_DEBUG */
33 /* #define TA_DEBUG_HORZ */
34 #define TA_DEBUG_VERT
36 #if defined TA_DEBUG_HORZ
37 # define TA_DEBUG_STARTDIM TA_DIMENSION_HORZ
38 # define TA_DEBUG_ENDDIM TA_DIMENSION_HORZ
39 # define TA_DEBUG
40 #elif defined TA_DEBUG_VERT
41 # define TA_DEBUG_STARTDIM TA_DIMENSION_VERT
42 # define TA_DEBUG_ENDDIM TA_DIMENSION_VERT
43 # define TA_DEBUG
44 #elif defined TA_DEBUG
45 # define TA_DEBUG_STARTDIM TA_DIMENSION_VERT
46 # define TA_DEBUG_ENDDIM TA_DIMENSION_HORZ
47 #endif
49 #ifdef TA_DEBUG
51 #define TA_LOG(x) \
52 do \
53 { \
54 if (_ta_debug) \
55 _ta_message x; \
56 } while (0)
58 #define TA_LOG_GLOBAL(x) \
59 do \
60 { \
61 if (_ta_debug_global) \
62 _ta_message x; \
63 } while (0)
65 void
66 _ta_message(const char* format,
67 ...);
69 extern int _ta_debug;
70 extern int _ta_debug_global;
71 extern int _ta_debug_disable_horz_hints;
72 extern int _ta_debug_disable_vert_hints;
73 extern int _ta_debug_disable_blue_hints;
74 extern void* _ta_debug_hints;
76 #else /* !TA_DEBUG */
78 #define TA_LOG(x) \
79 do { } while (0) /* nothing */
81 #define TA_LOG_GLOBAL(x) \
82 do { } while (0) /* nothing */
84 #endif /* !TA_DEBUG */
87 #define TA_ABS(a) ((a) < 0 ? -(a) : (a))
89 /* from file `ftobjs.h' from FreeType */
90 #define TA_PAD_FLOOR(x, n) ((x) & ~((n) - 1))
91 #define TA_PAD_ROUND(x, n) TA_PAD_FLOOR((x) + ((n) / 2), n)
92 #define TA_PAD_CEIL(x, n) TA_PAD_FLOOR((x) + ((n) - 1), n)
94 #define TA_PIX_FLOOR(x) ((x) & ~63)
95 #define TA_PIX_ROUND(x) TA_PIX_FLOOR((x) + 32)
96 #define TA_PIX_CEIL(x) TA_PIX_FLOOR((x) + 63)
99 typedef struct TA_WidthRec_
101 FT_Pos org; /* original position/width in font units */
102 FT_Pos cur; /* current/scaled position/width in device sub-pixels */
103 FT_Pos fit; /* current/fitted position/width in device sub-pixels */
104 } TA_WidthRec, *TA_Width;
107 /* the auto-hinter doesn't need a very high angular accuracy */
108 typedef FT_Int TA_Angle;
110 #define TA_ANGLE_PI 256
111 #define TA_ANGLE_2PI (TA_ANGLE_PI * 2)
112 #define TA_ANGLE_PI2 (TA_ANGLE_PI / 2)
113 #define TA_ANGLE_PI4 (TA_ANGLE_PI / 4)
115 #define TA_ANGLE_DIFF(result, angle1, angle2) \
116 do \
118 TA_Angle _delta = (angle2) - (angle1); \
121 _delta %= TA_ANGLE_2PI; \
122 if (_delta < 0) \
123 _delta += TA_ANGLE_2PI; \
125 if (_delta > TA_ANGLE_PI) \
126 _delta -= TA_ANGLE_2PI; \
128 result = _delta; \
129 } while (0)
132 /* opaque handle to glyph-specific hints -- */
133 /* see `tahints.h' for more details */
134 typedef struct TA_GlyphHintsRec_* TA_GlyphHints;
137 /* a scaler models the target pixel device that will receive */
138 /* the auto-hinted glyph image */
139 #define TA_SCALER_FLAG_NO_HORIZONTAL 0x01 /* disable horizontal hinting */
140 #define TA_SCALER_FLAG_NO_VERTICAL 0x02 /* disable vertical hinting */
141 #define TA_SCALER_FLAG_NO_ADVANCE 0x04 /* disable advance hinting */
143 typedef struct TA_ScalerRec_
145 FT_Face face; /* source font face */
146 FT_Fixed x_scale; /* from font units to 1/64th device pixels */
147 FT_Fixed y_scale; /* from font units to 1/64th device pixels */
148 FT_Pos x_delta; /* in 1/64th device pixels */
149 FT_Pos y_delta; /* in 1/64th device pixels */
150 FT_Render_Mode render_mode; /* monochrome, anti-aliased, LCD, etc.*/
151 FT_UInt32 flags; /* additional control flags, see above */
152 } TA_ScalerRec, *TA_Scaler;
154 #define TA_SCALER_EQUAL_SCALES(a, b) \
155 ((a)->x_scale == (b)->x_scale \
156 && (a)->y_scale == (b)->y_scale \
157 && (a)->x_delta == (b)->x_delta \
158 && (a)->y_delta == (b)->y_delta)
161 typedef struct TA_StyleMetricsRec_* TA_StyleMetrics;
163 /* this function parses an FT_Face to compute global metrics */
164 /* for a specific style */
165 typedef FT_Error
166 (*TA_WritingSystem_InitMetricsFunc)(TA_StyleMetrics metrics,
167 FT_Face face);
168 typedef void
169 (*TA_WritingSystem_ScaleMetricsFunc)(TA_StyleMetrics metrics,
170 TA_Scaler scaler);
171 typedef void
172 (*TA_WritingSystem_DoneMetricsFunc)(TA_StyleMetrics metrics);
173 typedef FT_Error
174 (*TA_WritingSystem_InitHintsFunc)(TA_GlyphHints hints,
175 TA_StyleMetrics metrics);
176 typedef void
177 (*TA_WritingSystem_ApplyHintsFunc)(TA_GlyphHints hints,
178 FT_Outline* outline,
179 TA_StyleMetrics metrics);
183 * For the auto-hinter, a writing system consists of multiple scripts that
184 * can be handled similarly *in a typographical way*; the relationship is
185 * not based on history. For example, both the Greek and the unrelated
186 * Armenian scripts share the same features like ascender, descender,
187 * x-height, etc. Essentially, a writing system is covered by a
188 * submodule of the auto-fitter; it contains
190 * - a specific global analyzer that computes global metrics specific to
191 * the script (based on script-specific characters to identify ascender
192 * height, x-height, etc.),
194 * - a specific glyph analyzer that computes segments and edges for each
195 * glyph covered by the script,
197 * - a specific grid-fitting algorithm that distorts the scaled glyph
198 * outline according to the results of the glyph analyzer.
201 #define __TAWRTSYS_H__ /* don't load header files */
202 #undef WRITING_SYSTEM
203 #define WRITING_SYSTEM(ws, WS) \
204 TA_WRITING_SYSTEM_ ## WS,
206 /* The list of known writing systems. */
207 typedef enum TA_WritingSystem_
209 #include "tawrtsys.h"
211 TA_WRITING_SYSTEM_MAX /* do not remove */
212 } TA_WritingSystem;
214 #undef __TAWRTSYS_H__
217 typedef struct TA_WritingSystemClassRec_
219 TA_WritingSystem writing_system;
221 FT_Offset style_metrics_size;
222 TA_WritingSystem_InitMetricsFunc style_metrics_init;
223 TA_WritingSystem_ScaleMetricsFunc style_metrics_scale;
224 TA_WritingSystem_DoneMetricsFunc style_metrics_done;
226 TA_WritingSystem_InitHintsFunc style_hints_init;
227 TA_WritingSystem_ApplyHintsFunc style_hints_apply;
228 } TA_WritingSystemClassRec;
230 typedef const TA_WritingSystemClassRec* TA_WritingSystemClass;
234 * Each script is associated with a set of Unicode ranges that gets used
235 * to test whether the font face supports the script.
237 * We use four-letter script tags from the OpenType specification,
238 * extended by `NONE', which indicates `no script'.
241 #undef SCRIPT
242 #define SCRIPT(s, S, d, h, dc) \
243 TA_SCRIPT_ ## S,
245 /* The list of known scripts. */
246 typedef enum TA_Script_
248 #include <ttfautohint-scripts.h>
250 TA_SCRIPT_MAX /* do not remove */
251 } TA_Script;
254 typedef struct TA_Script_UniRangeRec_
256 FT_UInt32 first;
257 FT_UInt32 last;
258 } TA_Script_UniRangeRec;
260 #define TA_UNIRANGE_REC(a, b) \
261 { (FT_UInt32)(a), (FT_UInt32)(b) }
263 typedef const TA_Script_UniRangeRec* TA_Script_UniRange;
265 typedef struct TA_ScriptClassRec_
267 TA_Script script;
269 TA_Script_UniRange script_uni_ranges; /* last must be { 0, 0 } */
270 FT_UInt32 standard_char; /* for default width and height */
271 } TA_ScriptClassRec;
273 typedef const TA_ScriptClassRec* TA_ScriptClass;
277 * Usually, a font contains more glyphs than can be addressed by its
278 * character map.
280 * In the PostScript font world, encoding vectors specific to a given
281 * task are used to select such glyphs, and these glyphs can be often
282 * recognized by having a suffix in its glyph names. For example, a
283 * superscript glyph `A' might be called `A.sup'. Unfortunately, this
284 * naming scheme is not standardized and thus unusable for us.
286 * In the OpenType world, a better solution was invented, namely
287 * `features', which cleanly separate a character's input encoding from
288 * the corresponding glyph's appearance, and which don't use glyph names
289 * at all. For our purposes, and slightly generalized, an OpenType
290 * feature is a name of a mapping that maps character codes to
291 * non-standard glyph indices (features get used for other things also).
292 * For example, the `sups' feature provides superscript glyphs, thus
293 * mapping character codes like `A' or `B' to superscript glyph
294 * representation forms. How this mapping happens is completely
295 * uninteresting to us.
297 * For the auto-hinter, a `coverage' represents all glyphs of an OpenType
298 * feature collected in a set (as listed below) that can be hinted
299 * together. To continue the above example, superscript glyphs must not
300 * be hinted together with normal glyphs because the blue zones
301 * completely differ.
303 * To compute coverages, we use the HarfBuzz library, which has many
304 * functions exactly for this purpose.
306 * TA_COVERAGE_DEFAULT is special: It should cover everything that isn't
307 * listed separately (including the glyphs addressable by the character
308 * map).
311 #undef COVERAGE
312 #define COVERAGE(name, NAME, description, \
313 tag1, tag2, tag3, tag4) \
314 TA_COVERAGE_ ## NAME,
316 typedef enum TA_Coverage_
318 #include "tacover.h"
320 TA_COVERAGE_DEFAULT
321 } TA_Coverage;
325 * The topmost structure for modelling the auto-hinter glyph input data
326 * is a `style class', grouping everything together.
329 #undef STYLE
330 #define STYLE(s, S, d, ws, sc, ss, c) \
331 TA_STYLE_ ## S,
333 /* The list of known styles. */
334 typedef enum TA_Style_
336 #include "tastyles.h"
338 TA_STYLE_MAX /* do not remove */
339 } TA_Style;
342 typedef struct TA_StyleClassRec_
344 TA_Style style;
346 TA_WritingSystem writing_system;
347 TA_Script script;
348 TA_Blue_Stringset blue_stringset;
349 TA_Coverage coverage;
350 } TA_StyleClassRec;
352 typedef const TA_StyleClassRec* TA_StyleClass;
355 typedef struct TA_FaceGlobalsRec_* TA_FaceGlobals;
357 /* This is the main structure that combines everything. Autofit modules */
358 /* specific to writing systems derive their structures from it, for */
359 /* example `TA_LatinMetrics'. */
361 typedef struct TA_StyleMetricsRec_
363 TA_StyleClass style_class;
364 TA_ScalerRec scaler;
365 FT_Bool digits_have_same_width;
367 TA_FaceGlobals globals; /* to access properties */
368 } TA_StyleMetricsRec;
370 #endif /* __TATYPES_H__ */
372 /* end of tatypes.h */