Introduce point hints and provide framework for them.
[ttfautohint.git] / src / tatypes.h
blobfb63ae12c72416a24f2b1708cd3f7c55f798133d
1 /* tatypes.h */
3 /* originally file `aftypes.h' (2011-Mar-30) from FreeType */
5 /* heavily modified 2011 by Werner Lemberg <wl@gnu.org> */
7 #ifndef __TATYPES_H__
8 #define __TATYPES_H__
10 #include <ft2build.h>
12 #include FT_FREETYPE_H
13 #include FT_OUTLINE_H
16 /* #define TA_DEBUG */
18 #ifdef TA_DEBUG
20 #include <stdlib.h>
22 #define TA_LOG(x) \
23 do { \
24 if (_ta_debug) \
25 printf x; \
26 } while (0)
28 extern int _ta_debug;
29 extern int _ta_debug_disable_horz_hints;
30 extern int _ta_debug_disable_vert_hints;
31 extern int _ta_debug_disable_blue_hints;
32 extern void* _ta_debug_hints;
34 #else /* !TA_DEBUG */
36 #define TA_LOG(x) \
37 do { } while (0) /* nothing */
39 #endif /* !TA_DEBUG */
42 #define TA_ABS(a) ((a) < 0 ? -(a) : (a))
44 /* from file `ftobjs.h' from FreeType */
45 #define TA_PAD_FLOOR(x, n) ((x) & ~((n) - 1))
46 #define TA_PAD_ROUND(x, n) TA_PAD_FLOOR((x) + ((n) / 2), n)
47 #define TA_PAD_CEIL(x, n) TA_PAD_FLOOR((x) + ((n) - 1), n)
49 #define TA_PIX_FLOOR(x) ((x) & ~63)
50 #define TA_PIX_ROUND(x) TA_PIX_FLOOR((x) + 32)
51 #define TA_PIX_CEIL(x) TA_PIX_FLOOR((x) + 63)
54 typedef struct TA_WidthRec_
56 FT_Pos org; /* original position/width in font units */
57 FT_Pos cur; /* current/scaled position/width in device sub-pixels */
58 FT_Pos fit; /* current/fitted position/width in device sub-pixels */
59 } TA_WidthRec, *TA_Width;
62 /* the auto-hinter doesn't need a very high angular accuracy */
63 typedef FT_Int TA_Angle;
65 #define TA_ANGLE_PI 256
66 #define TA_ANGLE_2PI (TA_ANGLE_PI * 2)
67 #define TA_ANGLE_PI2 (TA_ANGLE_PI / 2)
68 #define TA_ANGLE_PI4 (TA_ANGLE_PI / 4)
70 #define TA_ANGLE_DIFF(result, angle1, angle2) \
71 do { \
72 TA_Angle _delta = (angle2) - (angle1); \
75 _delta %= TA_ANGLE_2PI; \
76 if (_delta < 0) \
77 _delta += TA_ANGLE_2PI; \
79 if (_delta > TA_ANGLE_PI) \
80 _delta -= TA_ANGLE_2PI; \
82 result = _delta; \
83 } while (0)
86 /* opaque handle to glyph-specific hints -- */
87 /* see `tahints.h' for more details */
88 typedef struct TA_GlyphHintsRec_* TA_GlyphHints;
91 /* a scaler models the target pixel device that will receive */
92 /* the auto-hinted glyph image */
93 #define TA_SCALER_FLAG_NO_HORIZONTAL 1 /* disable horizontal hinting */
94 #define TA_SCALER_FLAG_NO_VERTICAL 2 /* disable vertical hinting */
95 #define TA_SCALER_FLAG_NO_ADVANCE 4 /* disable advance hinting */
97 typedef struct TA_ScalerRec_
99 FT_Face face; /* source font face */
100 FT_Fixed x_scale; /* from font units to 1/64th device pixels */
101 FT_Fixed y_scale; /* from font units to 1/64th device pixels */
102 FT_Pos x_delta; /* in 1/64th device pixels */
103 FT_Pos y_delta; /* in 1/64th device pixels */
104 FT_Render_Mode render_mode; /* monochrome, anti-aliased, LCD, etc.*/
105 FT_UInt32 flags; /* additional control flags, see above */
106 } TA_ScalerRec, *TA_Scaler;
108 #define TA_SCALER_EQUAL_SCALES(a, b) \
109 ((a)->x_scale == (b)->x_scale \
110 && (a)->y_scale == (b)->y_scale \
111 && (a)->x_delta == (b)->x_delta \
112 && (a)->y_delta == (b)->y_delta)
116 * The list of known scripts. Each different script corresponds to the
117 * following information:
119 * - A set of Unicode ranges to test whether the face supports the
120 * script.
122 * - A specific global analyzer that will compute global metrics
123 * specific to the script.
125 * - A specific glyph analyzer that will compute segments and
126 * edges for each glyph covered by the script.
128 * - A specific grid-fitting algorithm that will distort the
129 * scaled glyph outline according to the results of the glyph
130 * analyzer.
132 * Note that a given analyzer and/or grid-fitting algorithm can be
133 * used by more than one script.
136 typedef enum TA_Script_
138 TA_SCRIPT_NONE = 0,
139 TA_SCRIPT_LATIN = 1,
140 TA_SCRIPT_CJK = 2,
141 TA_SCRIPT_INDIC = 3,
142 #ifdef FT_OPTION_AUTOFIT2
143 TA_SCRIPT_LATIN2 = 4,
144 #endif
146 /* add new scripts here; */
147 /* don't forget to update the list in `taglobal.c' */
149 TA_SCRIPT_MAX /* do not remove */
150 } TA_Script;
152 typedef struct TA_ScriptClassRec_ const* TA_ScriptClass;
154 typedef struct TA_ScriptMetricsRec_
156 TA_ScriptClass clazz;
157 TA_ScalerRec scaler;
158 FT_Bool digits_have_same_width;
159 } TA_ScriptMetricsRec, *TA_ScriptMetrics;
162 /* this function parses an FT_Face to compute global metrics */
163 /* for a specific script */
164 typedef FT_Error
165 (*TA_Script_InitMetricsFunc)(TA_ScriptMetrics metrics,
166 FT_Face face);
167 typedef void
168 (*TA_Script_ScaleMetricsFunc)(TA_ScriptMetrics metrics,
169 TA_Scaler scaler);
170 typedef void
171 (*TA_Script_DoneMetricsFunc)(TA_ScriptMetrics metrics);
172 typedef FT_Error
173 (*TA_Script_InitHintsFunc)(TA_GlyphHints hints,
174 TA_ScriptMetrics metrics);
175 typedef void
176 (*TA_Script_ApplyHintsFunc)(TA_GlyphHints hints,
177 FT_Outline* outline,
178 TA_ScriptMetrics metrics);
181 typedef struct TA_Script_UniRangeRec_
183 FT_UInt32 first;
184 FT_UInt32 last;
185 } TA_Script_UniRangeRec;
187 #define TA_UNIRANGE_REC(a, b) \
188 { (FT_UInt32)(a), (FT_UInt32)(b) }
190 typedef const TA_Script_UniRangeRec *TA_Script_UniRange;
192 typedef struct TA_ScriptClassRec_
194 TA_Script script;
195 TA_Script_UniRange script_uni_ranges; /* last must be { 0, 0 } */
197 FT_Offset script_metrics_size;
198 TA_Script_InitMetricsFunc script_metrics_init;
199 TA_Script_ScaleMetricsFunc script_metrics_scale;
200 TA_Script_DoneMetricsFunc script_metrics_done;
202 TA_Script_InitHintsFunc script_hints_init;
203 TA_Script_ApplyHintsFunc script_hints_apply;
204 } TA_ScriptClassRec;
206 #endif /* __TATYPES_H__ */
208 /* end of tatypes.h */