Remove limits of `increase-x-height' option.
[ttfautohint.git] / lib / tatypes.h
blob2f818da7ddc4419f142863022f6b35be3592cebe
1 /* tatypes.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 /* 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
29 /* enable one of the following three definitions for debugging */
30 /* #define TA_DEBUG */
31 /* #define TA_DEBUG_HORZ */
32 #define TA_DEBUG_VERT
34 #if defined TA_DEBUG_HORZ
35 # define TA_DEBUG_STARTDIM TA_DIMENSION_HORZ
36 # define TA_DEBUG_ENDDIM TA_DIMENSION_HORZ
37 # define TA_DEBUG
38 #elif defined TA_DEBUG_VERT
39 # define TA_DEBUG_STARTDIM TA_DIMENSION_VERT
40 # define TA_DEBUG_ENDDIM TA_DIMENSION_VERT
41 # define TA_DEBUG
42 #elif defined TA_DEBUG
43 # define TA_DEBUG_STARTDIM TA_DIMENSION_VERT
44 # define TA_DEBUG_ENDDIM TA_DIMENSION_HORZ
45 #endif
47 #ifdef TA_DEBUG
49 #define TA_LOG(x) \
50 do { \
51 if (_ta_debug) \
52 _ta_message x; \
53 } while (0)
55 void
56 _ta_message(const char *format,
57 ...);
59 extern int _ta_debug;
60 extern int _ta_debug_disable_horz_hints;
61 extern int _ta_debug_disable_vert_hints;
62 extern int _ta_debug_disable_blue_hints;
63 extern void* _ta_debug_hints;
65 #else /* !TA_DEBUG */
67 #define TA_LOG(x) \
68 do { } while (0) /* nothing */
70 #endif /* !TA_DEBUG */
73 #define TA_ABS(a) ((a) < 0 ? -(a) : (a))
75 /* from file `ftobjs.h' from FreeType */
76 #define TA_PAD_FLOOR(x, n) ((x) & ~((n) - 1))
77 #define TA_PAD_ROUND(x, n) TA_PAD_FLOOR((x) + ((n) / 2), n)
78 #define TA_PAD_CEIL(x, n) TA_PAD_FLOOR((x) + ((n) - 1), n)
80 #define TA_PIX_FLOOR(x) ((x) & ~63)
81 #define TA_PIX_ROUND(x) TA_PIX_FLOOR((x) + 32)
82 #define TA_PIX_CEIL(x) TA_PIX_FLOOR((x) + 63)
85 typedef struct TA_WidthRec_
87 FT_Pos org; /* original position/width in font units */
88 FT_Pos cur; /* current/scaled position/width in device sub-pixels */
89 FT_Pos fit; /* current/fitted position/width in device sub-pixels */
90 } TA_WidthRec, *TA_Width;
93 /* the auto-hinter doesn't need a very high angular accuracy */
94 typedef FT_Int TA_Angle;
96 #define TA_ANGLE_PI 256
97 #define TA_ANGLE_2PI (TA_ANGLE_PI * 2)
98 #define TA_ANGLE_PI2 (TA_ANGLE_PI / 2)
99 #define TA_ANGLE_PI4 (TA_ANGLE_PI / 4)
101 #define TA_ANGLE_DIFF(result, angle1, angle2) \
102 do { \
103 TA_Angle _delta = (angle2) - (angle1); \
106 _delta %= TA_ANGLE_2PI; \
107 if (_delta < 0) \
108 _delta += TA_ANGLE_2PI; \
110 if (_delta > TA_ANGLE_PI) \
111 _delta -= TA_ANGLE_2PI; \
113 result = _delta; \
114 } while (0)
117 /* opaque handle to glyph-specific hints -- */
118 /* see `tahints.h' for more details */
119 typedef struct TA_GlyphHintsRec_* TA_GlyphHints;
122 /* a scaler models the target pixel device that will receive */
123 /* the auto-hinted glyph image */
124 #define TA_SCALER_FLAG_NO_HORIZONTAL 0x01 /* disable horizontal hinting */
125 #define TA_SCALER_FLAG_NO_VERTICAL 0x02 /* disable vertical hinting */
126 #define TA_SCALER_FLAG_NO_ADVANCE 0x04 /* disable advance hinting */
128 typedef struct TA_ScalerRec_
130 FT_Face face; /* source font face */
131 FT_Fixed x_scale; /* from font units to 1/64th device pixels */
132 FT_Fixed y_scale; /* from font units to 1/64th device pixels */
133 FT_Pos x_delta; /* in 1/64th device pixels */
134 FT_Pos y_delta; /* in 1/64th device pixels */
135 FT_Render_Mode render_mode; /* monochrome, anti-aliased, LCD, etc.*/
136 FT_UInt32 flags; /* additional control flags, see above */
137 } TA_ScalerRec, *TA_Scaler;
139 #define TA_SCALER_EQUAL_SCALES(a, b) \
140 ((a)->x_scale == (b)->x_scale \
141 && (a)->y_scale == (b)->y_scale \
142 && (a)->x_delta == (b)->x_delta \
143 && (a)->y_delta == (b)->y_delta)
147 * The list of known scripts. Each different script corresponds to the
148 * following information:
150 * - A set of Unicode ranges to test whether the face supports the
151 * script.
153 * - A specific global analyzer that will compute global metrics
154 * specific to the script.
156 * - A specific glyph analyzer that will compute segments and
157 * edges for each glyph covered by the script.
159 * - A specific grid-fitting algorithm that will distort the
160 * scaled glyph outline according to the results of the glyph
161 * analyzer.
163 * Note that a given analyzer and/or grid-fitting algorithm can be
164 * used by more than one script.
167 typedef enum TA_Script_
169 TA_SCRIPT_NONE = 0,
170 TA_SCRIPT_LATIN = 1,
171 TA_SCRIPT_CJK = 2,
172 TA_SCRIPT_INDIC = 3,
173 #ifdef FT_OPTION_AUTOFIT2
174 TA_SCRIPT_LATIN2 = 4,
175 #endif
177 /* add new scripts here; */
178 /* don't forget to update the list in `taglobal.c' */
180 TA_SCRIPT_MAX /* do not remove */
181 } TA_Script;
183 typedef struct TA_ScriptClassRec_ const* TA_ScriptClass;
184 typedef struct TA_FaceGlobalsRec_* TA_FaceGlobals;
186 typedef struct TA_ScriptMetricsRec_
188 TA_ScriptClass clazz;
189 TA_ScalerRec scaler;
190 FT_Bool digits_have_same_width;
192 TA_FaceGlobals globals; /* to access properties */
193 } TA_ScriptMetricsRec, *TA_ScriptMetrics;
196 /* this function parses an FT_Face to compute global metrics */
197 /* for a specific script */
198 typedef FT_Error
199 (*TA_Script_InitMetricsFunc)(TA_ScriptMetrics metrics,
200 FT_Face face);
201 typedef void
202 (*TA_Script_ScaleMetricsFunc)(TA_ScriptMetrics metrics,
203 TA_Scaler scaler);
204 typedef void
205 (*TA_Script_DoneMetricsFunc)(TA_ScriptMetrics metrics);
206 typedef FT_Error
207 (*TA_Script_InitHintsFunc)(TA_GlyphHints hints,
208 TA_ScriptMetrics metrics);
209 typedef void
210 (*TA_Script_ApplyHintsFunc)(TA_GlyphHints hints,
211 FT_Outline* outline,
212 TA_ScriptMetrics metrics);
215 typedef struct TA_Script_UniRangeRec_
217 FT_UInt32 first;
218 FT_UInt32 last;
219 } TA_Script_UniRangeRec;
221 #define TA_UNIRANGE_REC(a, b) \
222 { (FT_UInt32)(a), (FT_UInt32)(b) }
224 typedef const TA_Script_UniRangeRec* TA_Script_UniRange;
226 typedef struct TA_ScriptClassRec_
228 TA_Script script;
229 TA_Script_UniRange script_uni_ranges; /* last must be { 0, 0 } */
231 FT_Offset script_metrics_size;
232 TA_Script_InitMetricsFunc script_metrics_init;
233 TA_Script_ScaleMetricsFunc script_metrics_scale;
234 TA_Script_DoneMetricsFunc script_metrics_done;
236 TA_Script_InitHintsFunc script_hints_init;
237 TA_Script_ApplyHintsFunc script_hints_apply;
238 } TA_ScriptClassRec;
240 #endif /* __TATYPES_H__ */
242 /* end of tatypes.h */