Synchronize with FreeType. [2/2]
[ttfautohint.git] / lib / tatypes.h
blobf827cd2e1e5070a1270945dbfaffe25dc5cba127
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 void
59 _ta_message(const char* format,
60 ...);
62 extern int _ta_debug;
63 extern int _ta_debug_disable_horz_hints;
64 extern int _ta_debug_disable_vert_hints;
65 extern int _ta_debug_disable_blue_hints;
66 extern void* _ta_debug_hints;
68 #else /* !TA_DEBUG */
70 #define TA_LOG(x) \
71 do { } while (0) /* nothing */
73 #endif /* !TA_DEBUG */
76 #define TA_ABS(a) ((a) < 0 ? -(a) : (a))
78 /* from file `ftobjs.h' from FreeType */
79 #define TA_PAD_FLOOR(x, n) ((x) & ~((n) - 1))
80 #define TA_PAD_ROUND(x, n) TA_PAD_FLOOR((x) + ((n) / 2), n)
81 #define TA_PAD_CEIL(x, n) TA_PAD_FLOOR((x) + ((n) - 1), n)
83 #define TA_PIX_FLOOR(x) ((x) & ~63)
84 #define TA_PIX_ROUND(x) TA_PIX_FLOOR((x) + 32)
85 #define TA_PIX_CEIL(x) TA_PIX_FLOOR((x) + 63)
88 typedef struct TA_WidthRec_
90 FT_Pos org; /* original position/width in font units */
91 FT_Pos cur; /* current/scaled position/width in device sub-pixels */
92 FT_Pos fit; /* current/fitted position/width in device sub-pixels */
93 } TA_WidthRec, *TA_Width;
96 /* the auto-hinter doesn't need a very high angular accuracy */
97 typedef FT_Int TA_Angle;
99 #define TA_ANGLE_PI 256
100 #define TA_ANGLE_2PI (TA_ANGLE_PI * 2)
101 #define TA_ANGLE_PI2 (TA_ANGLE_PI / 2)
102 #define TA_ANGLE_PI4 (TA_ANGLE_PI / 4)
104 #define TA_ANGLE_DIFF(result, angle1, angle2) \
105 do \
107 TA_Angle _delta = (angle2) - (angle1); \
110 _delta %= TA_ANGLE_2PI; \
111 if (_delta < 0) \
112 _delta += TA_ANGLE_2PI; \
114 if (_delta > TA_ANGLE_PI) \
115 _delta -= TA_ANGLE_2PI; \
117 result = _delta; \
118 } while (0)
121 /* opaque handle to glyph-specific hints -- */
122 /* see `tahints.h' for more details */
123 typedef struct TA_GlyphHintsRec_* TA_GlyphHints;
126 /* a scaler models the target pixel device that will receive */
127 /* the auto-hinted glyph image */
128 #define TA_SCALER_FLAG_NO_HORIZONTAL 0x01 /* disable horizontal hinting */
129 #define TA_SCALER_FLAG_NO_VERTICAL 0x02 /* disable vertical hinting */
130 #define TA_SCALER_FLAG_NO_ADVANCE 0x04 /* disable advance hinting */
132 typedef struct TA_ScalerRec_
134 FT_Face face; /* source font face */
135 FT_Fixed x_scale; /* from font units to 1/64th device pixels */
136 FT_Fixed y_scale; /* from font units to 1/64th device pixels */
137 FT_Pos x_delta; /* in 1/64th device pixels */
138 FT_Pos y_delta; /* in 1/64th device pixels */
139 FT_Render_Mode render_mode; /* monochrome, anti-aliased, LCD, etc.*/
140 FT_UInt32 flags; /* additional control flags, see above */
141 } TA_ScalerRec, *TA_Scaler;
143 #define TA_SCALER_EQUAL_SCALES(a, b) \
144 ((a)->x_scale == (b)->x_scale \
145 && (a)->y_scale == (b)->y_scale \
146 && (a)->x_delta == (b)->x_delta \
147 && (a)->y_delta == (b)->y_delta)
150 /* This is the main structure which combines writing systems and script */
151 /* data (for a given face object, see below). */
153 typedef struct TA_WritingSystemClassRec_ const* TA_WritingSystemClass;
154 typedef struct TA_ScriptClassRec_ const* TA_ScriptClass;
155 typedef struct TA_FaceGlobalsRec_* TA_FaceGlobals;
157 typedef struct TA_ScriptMetricsRec_
159 TA_ScriptClass script_class;
160 TA_ScalerRec scaler;
161 FT_Bool digits_have_same_width;
163 TA_FaceGlobals globals; /* to access properties */
164 } TA_ScriptMetricsRec, *TA_ScriptMetrics;
167 /* this function parses an FT_Face to compute global metrics */
168 /* for a specific script */
169 typedef FT_Error
170 (*TA_Script_InitMetricsFunc)(TA_ScriptMetrics metrics,
171 FT_Face face);
172 typedef void
173 (*TA_Script_ScaleMetricsFunc)(TA_ScriptMetrics metrics,
174 TA_Scaler scaler);
175 typedef void
176 (*TA_Script_DoneMetricsFunc)(TA_ScriptMetrics metrics);
177 typedef FT_Error
178 (*TA_Script_InitHintsFunc)(TA_GlyphHints hints,
179 TA_ScriptMetrics metrics);
180 typedef void
181 (*TA_Script_ApplyHintsFunc)(TA_GlyphHints hints,
182 FT_Outline* outline,
183 TA_ScriptMetrics metrics);
187 * In FreeType, a writing system consists of multiple scripts which can
188 * be handled similarly *in a typographical way*; the relationship is not
189 * based on history. For example, both the Greek and the unrelated
190 * Armenian scripts share the same features like ascender, descender,
191 * x-height, etc. Essentially, a writing system is covered by a
192 * submodule of the auto-fitter; it contains
194 * - a specific global analyzer which computes global metrics specific to
195 * the script (based on script-specific characters to identify ascender
196 * height, x-height, etc.),
198 * - a specific glyph analyzer that computes segments and edges for each
199 * glyph covered by the script,
201 * - a specific grid-fitting algorithm that distorts the scaled glyph
202 * outline according to the results of the glyph analyzer.
205 #define __TAWRTSYS_H__ /* don't load header files */
206 #undef WRITING_SYSTEM
207 #define WRITING_SYSTEM(ws, WS) \
208 TA_WRITING_SYSTEM_ ## WS,
210 /* The list of known writing systems. */
211 typedef enum TA_WritingSystem_
213 #include "tawrtsys.h"
215 TA_WRITING_SYSTEM_MAX /* do not remove */
216 } TA_WritingSystem;
218 #undef __TAWRTSYS_H__
221 typedef struct TA_WritingSystemClassRec_
223 TA_WritingSystem writing_system;
225 FT_Offset script_metrics_size;
226 TA_Script_InitMetricsFunc script_metrics_init;
227 TA_Script_ScaleMetricsFunc script_metrics_scale;
228 TA_Script_DoneMetricsFunc script_metrics_done;
230 TA_Script_InitHintsFunc script_hints_init;
231 TA_Script_ApplyHintsFunc script_hints_apply;
232 } TA_WritingSystemClassRec;
236 * Each script is associated with a set of Unicode ranges which gets used
237 * to test whether the font face supports the script. It also references
238 * the writing system it belongs to.
240 * We use four-letter script tags from the OpenType specification.
243 #undef SCRIPT
244 #define SCRIPT(s, S) \
245 TA_SCRIPT_ ## S,
247 /* The list of known scripts. */
248 typedef enum TA_Script_
250 #include "tascript.h"
252 TA_SCRIPT_MAX /* do not remove */
253 } TA_Script;
256 typedef struct TA_Script_UniRangeRec_
258 FT_UInt32 first;
259 FT_UInt32 last;
260 } TA_Script_UniRangeRec;
262 #define TA_UNIRANGE_REC(a, b) \
263 { (FT_UInt32)(a), (FT_UInt32)(b) }
265 typedef const TA_Script_UniRangeRec* TA_Script_UniRange;
267 typedef struct TA_ScriptClassRec_
269 TA_Script script;
270 TA_Blue_Stringset blue_stringset;
271 TA_WritingSystem writing_system;
273 TA_Script_UniRange script_uni_ranges; /* last must be { 0, 0 } */
274 FT_UInt32 standard_char; /* for default width and height */
275 } TA_ScriptClassRec;
277 #endif /* __TATYPES_H__ */
279 /* end of tatypes.h */