Rename `tascript.h' to `ttfautohint-scripts.h'.
[ttfautohint.git] / lib / tatypes.h
blob6c54f770d0045cf5584305c396a40b15c74a7e6e
1 /* tatypes.h */
3 /*
4 * Copyright (C) 2011-2013 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 /* This is the main structure which combines writing systems and script */
162 /* data (for a given face object, see below). */
164 typedef struct TA_WritingSystemClassRec_ const* TA_WritingSystemClass;
165 typedef struct TA_ScriptClassRec_ const* TA_ScriptClass;
166 typedef struct TA_FaceGlobalsRec_* TA_FaceGlobals;
168 typedef struct TA_ScriptMetricsRec_
170 TA_ScriptClass script_class;
171 TA_ScalerRec scaler;
172 FT_Bool digits_have_same_width;
174 TA_FaceGlobals globals; /* to access properties */
175 } TA_ScriptMetricsRec, *TA_ScriptMetrics;
178 /* this function parses an FT_Face to compute global metrics */
179 /* for a specific script */
180 typedef FT_Error
181 (*TA_Script_InitMetricsFunc)(TA_ScriptMetrics metrics,
182 FT_Face face);
183 typedef void
184 (*TA_Script_ScaleMetricsFunc)(TA_ScriptMetrics metrics,
185 TA_Scaler scaler);
186 typedef void
187 (*TA_Script_DoneMetricsFunc)(TA_ScriptMetrics metrics);
188 typedef FT_Error
189 (*TA_Script_InitHintsFunc)(TA_GlyphHints hints,
190 TA_ScriptMetrics metrics);
191 typedef void
192 (*TA_Script_ApplyHintsFunc)(TA_GlyphHints hints,
193 FT_Outline* outline,
194 TA_ScriptMetrics metrics);
198 * In FreeType, a writing system consists of multiple scripts which can
199 * be handled similarly *in a typographical way*; the relationship is not
200 * based on history. For example, both the Greek and the unrelated
201 * Armenian scripts share the same features like ascender, descender,
202 * x-height, etc. Essentially, a writing system is covered by a
203 * submodule of the auto-fitter; it contains
205 * - a specific global analyzer which computes global metrics specific to
206 * the script (based on script-specific characters to identify ascender
207 * height, x-height, etc.),
209 * - a specific glyph analyzer that computes segments and edges for each
210 * glyph covered by the script,
212 * - a specific grid-fitting algorithm that distorts the scaled glyph
213 * outline according to the results of the glyph analyzer.
216 #define __TAWRTSYS_H__ /* don't load header files */
217 #undef WRITING_SYSTEM
218 #define WRITING_SYSTEM(ws, WS) \
219 TA_WRITING_SYSTEM_ ## WS,
221 /* The list of known writing systems. */
222 typedef enum TA_WritingSystem_
224 #include "tawrtsys.h"
226 TA_WRITING_SYSTEM_MAX /* do not remove */
227 } TA_WritingSystem;
229 #undef __TAWRTSYS_H__
232 typedef struct TA_WritingSystemClassRec_
234 TA_WritingSystem writing_system;
236 FT_Offset script_metrics_size;
237 TA_Script_InitMetricsFunc script_metrics_init;
238 TA_Script_ScaleMetricsFunc script_metrics_scale;
239 TA_Script_DoneMetricsFunc script_metrics_done;
241 TA_Script_InitHintsFunc script_hints_init;
242 TA_Script_ApplyHintsFunc script_hints_apply;
243 } TA_WritingSystemClassRec;
247 * Each script is associated with a set of Unicode ranges which gets used
248 * to test whether the font face supports the script. It also references
249 * the writing system it belongs to.
251 * We use four-letter script tags from the OpenType specification.
254 #undef SCRIPT
255 #define SCRIPT(s, S, d) \
256 TA_SCRIPT_ ## S,
258 /* The list of known scripts. */
259 typedef enum TA_Script_
261 #include <ttfautohint-scripts.h>
263 TA_SCRIPT_MAX /* do not remove */
264 } TA_Script;
267 typedef struct TA_Script_UniRangeRec_
269 FT_UInt32 first;
270 FT_UInt32 last;
271 } TA_Script_UniRangeRec;
273 #define TA_UNIRANGE_REC(a, b) \
274 { (FT_UInt32)(a), (FT_UInt32)(b) }
276 typedef const TA_Script_UniRangeRec* TA_Script_UniRange;
278 typedef struct TA_ScriptClassRec_
280 TA_Script script;
281 TA_Blue_Stringset blue_stringset;
282 TA_WritingSystem writing_system;
284 TA_Script_UniRange script_uni_ranges; /* last must be { 0, 0 } */
285 FT_UInt32 standard_char; /* for default width and height */
286 } TA_ScriptClassRec;
288 #endif /* __TATYPES_H__ */
290 /* end of tatypes.h */