4 * Copyright (C) 2011-2015 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> */
25 #include FT_FREETYPE_H
35 /* enable one of the following three definitions for debugging */
36 /* #define TA_DEBUG */
37 /* #define TA_DEBUG_HORZ */
40 #if defined TA_DEBUG_HORZ
41 # define TA_DEBUG_STARTDIM TA_DIMENSION_HORZ
42 # define TA_DEBUG_ENDDIM TA_DIMENSION_HORZ
44 #elif defined TA_DEBUG_VERT
45 # define TA_DEBUG_STARTDIM TA_DIMENSION_VERT
46 # define TA_DEBUG_ENDDIM TA_DIMENSION_VERT
48 #elif defined TA_DEBUG
49 # define TA_DEBUG_STARTDIM TA_DIMENSION_VERT
50 # define TA_DEBUG_ENDDIM TA_DIMENSION_HORZ
62 #define TA_LOG_GLOBAL(x) \
65 if (_ta_debug_global) \
70 _ta_message(const char* format
,
74 extern int _ta_debug_global
;
75 extern int _ta_debug_disable_horz_hints
;
76 extern int _ta_debug_disable_vert_hints
;
77 extern int _ta_debug_disable_blue_hints
;
78 extern void* _ta_debug_hints
;
83 do { } while (0) /* nothing */
85 #define TA_LOG_GLOBAL(x) \
86 do { } while (0) /* nothing */
88 #endif /* !TA_DEBUG */
91 #define TA_ABS(a) ((a) < 0 ? -(a) : (a))
93 /* from file `ftconfig.h' (2015-03-02) from FreeType */
94 /* typeof condition taken from gnulib's `intprops.h' header file */
96 || defined(__IBM__TYPEOF__) \
97 || (__SUNPRO_C >= 0x5110 && !__STDC__))
98 #define TYPEOF(type) (__typeof__ (type))
100 #define TYPEOF(type) /* empty */
103 /* from file `ftobjs.h' from FreeType */
104 /* we use the TYPEOF macro to suppress signedness compilation warnings */
105 #define TA_PAD_FLOOR(x, n) ((x) & ~TYPEOF(x)((n) - 1))
106 #define TA_PAD_ROUND(x, n) TA_PAD_FLOOR((x) + ((n) / 2), n)
107 #define TA_PAD_CEIL(x, n) TA_PAD_FLOOR((x) + ((n) - 1), n)
109 #define TA_PIX_FLOOR(x) ((x) & ~TYPEOF(x)63)
110 #define TA_PIX_ROUND(x) TA_PIX_FLOOR((x) + 32)
111 #define TA_PIX_CEIL(x) TA_PIX_FLOOR((x) + 63)
114 typedef struct TA_WidthRec_
116 FT_Pos org
; /* original position/width in font units */
117 FT_Pos cur
; /* current/scaled position/width in device sub-pixels */
118 FT_Pos fit
; /* current/fitted position/width in device sub-pixels */
119 } TA_WidthRec
, *TA_Width
;
122 /* the auto-hinter doesn't need a very high angular accuracy */
123 typedef FT_Int TA_Angle
;
125 #define TA_ANGLE_PI 256
126 #define TA_ANGLE_2PI (TA_ANGLE_PI * 2)
127 #define TA_ANGLE_PI2 (TA_ANGLE_PI / 2)
128 #define TA_ANGLE_PI4 (TA_ANGLE_PI / 4)
130 #define TA_ANGLE_DIFF(result, angle1, angle2) \
133 TA_Angle _delta = (angle2) - (angle1); \
136 _delta %= TA_ANGLE_2PI; \
138 _delta += TA_ANGLE_2PI; \
140 if (_delta > TA_ANGLE_PI) \
141 _delta -= TA_ANGLE_2PI; \
147 /* opaque handle to glyph-specific hints -- */
148 /* see `tahints.h' for more details */
149 typedef struct TA_GlyphHintsRec_
* TA_GlyphHints
;
152 /* a scaler models the target pixel device that will receive */
153 /* the auto-hinted glyph image */
154 #define TA_SCALER_FLAG_NO_HORIZONTAL 0x01U /* disable horizontal hinting */
155 #define TA_SCALER_FLAG_NO_VERTICAL 0x02U /* disable vertical hinting */
156 #define TA_SCALER_FLAG_NO_ADVANCE 0x04U /* disable advance hinting */
158 typedef struct TA_ScalerRec_
160 FT_Face face
; /* source font face */
161 FT_Fixed x_scale
; /* from font units to 1/64th device pixels */
162 FT_Fixed y_scale
; /* from font units to 1/64th device pixels */
163 FT_Pos x_delta
; /* in 1/64th device pixels */
164 FT_Pos y_delta
; /* in 1/64th device pixels */
165 FT_Render_Mode render_mode
; /* monochrome, anti-aliased, LCD, etc.*/
166 FT_UInt32 flags
; /* additional control flags, see above */
167 } TA_ScalerRec
, *TA_Scaler
;
169 #define TA_SCALER_EQUAL_SCALES(a, b) \
170 ((a)->x_scale == (b)->x_scale \
171 && (a)->y_scale == (b)->y_scale \
172 && (a)->x_delta == (b)->x_delta \
173 && (a)->y_delta == (b)->y_delta)
176 typedef struct TA_StyleMetricsRec_
* TA_StyleMetrics
;
178 /* this function parses an FT_Face to compute global metrics */
179 /* for a specific style */
181 (*TA_WritingSystem_InitMetricsFunc
)(TA_StyleMetrics metrics
,
184 (*TA_WritingSystem_ScaleMetricsFunc
)(TA_StyleMetrics metrics
,
187 (*TA_WritingSystem_DoneMetricsFunc
)(TA_StyleMetrics metrics
);
189 (*TA_WritingSystem_InitHintsFunc
)(TA_GlyphHints hints
,
190 TA_StyleMetrics metrics
);
192 (*TA_WritingSystem_ApplyHintsFunc
)(TA_GlyphHints hints
,
194 TA_StyleMetrics metrics
);
198 * For the auto-hinter, a writing system consists of multiple scripts that
199 * can be handled similarly *in a typographical way*; the relationship is
200 * not 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 that 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 */
229 #undef __TAWRTSYS_H__
232 typedef struct TA_WritingSystemClassRec_
234 TA_WritingSystem writing_system
;
236 FT_Offset style_metrics_size
;
237 TA_WritingSystem_InitMetricsFunc style_metrics_init
;
238 TA_WritingSystem_ScaleMetricsFunc style_metrics_scale
;
239 TA_WritingSystem_DoneMetricsFunc style_metrics_done
;
241 TA_WritingSystem_InitHintsFunc style_hints_init
;
242 TA_WritingSystem_ApplyHintsFunc style_hints_apply
;
243 } TA_WritingSystemClassRec
;
245 typedef const TA_WritingSystemClassRec
* TA_WritingSystemClass
;
249 * Each script is associated with a set of Unicode ranges that gets used
250 * to test whether the font face supports the script.
252 * We use four-letter script tags from the OpenType specification,
253 * extended by `NONE', which indicates `no script'.
257 #define SCRIPT(s, S, d, h, sc1, sc2, sc3) \
260 /* The list of known scripts. */
261 typedef enum TA_Script_
263 #include <ttfautohint-scripts.h>
265 TA_SCRIPT_MAX
/* do not remove */
269 typedef struct TA_Script_UniRangeRec_
273 } TA_Script_UniRangeRec
;
275 #define TA_UNIRANGE_REC(a, b) \
276 { (FT_UInt32)(a), (FT_UInt32)(b) }
278 typedef const TA_Script_UniRangeRec
* TA_Script_UniRange
;
280 typedef struct TA_ScriptClassRec_
284 TA_Script_UniRange script_uni_ranges
; /* last must be { 0, 0 } */
286 FT_UInt32 standard_char1
; /* for default width and height */
287 FT_UInt32 standard_char2
; /* ditto */
288 FT_UInt32 standard_char3
; /* ditto */
291 typedef const TA_ScriptClassRec
* TA_ScriptClass
;
295 * Usually, a font contains more glyphs than can be addressed by its
298 * In the PostScript font world, encoding vectors specific to a given
299 * task are used to select such glyphs, and these glyphs can be often
300 * recognized by having a suffix in its glyph names. For example, a
301 * superscript glyph `A' might be called `A.sup'. Unfortunately, this
302 * naming scheme is not standardized and thus unusable for us.
304 * In the OpenType world, a better solution was invented, namely
305 * `features', which cleanly separate a character's input encoding from
306 * the corresponding glyph's appearance, and which don't use glyph names
307 * at all. For our purposes, and slightly generalized, an OpenType
308 * feature is a name of a mapping that maps character codes to
309 * non-standard glyph indices (features get used for other things also).
310 * For example, the `sups' feature provides superscript glyphs, thus
311 * mapping character codes like `A' or `B' to superscript glyph
312 * representation forms. How this mapping happens is completely
313 * uninteresting to us.
315 * For the auto-hinter, a `coverage' represents all glyphs of an OpenType
316 * feature collected in a set (as listed below) that can be hinted
317 * together. To continue the above example, superscript glyphs must not
318 * be hinted together with normal glyphs because the blue zones
321 * To compute coverages, we use the HarfBuzz library, which has many
322 * functions exactly for this purpose.
324 * TA_COVERAGE_DEFAULT is special: It should cover everything that isn't
325 * listed separately (including the glyphs addressable by the character
330 #define COVERAGE(name, NAME, description, \
331 tag1, tag2, tag3, tag4) \
332 TA_COVERAGE_ ## NAME,
334 typedef enum TA_Coverage_
343 * The topmost structure for modelling the auto-hinter glyph input data
344 * is a `style class', grouping everything together.
348 #define STYLE(s, S, d, ws, sc, ss, c) \
351 /* The list of known styles. */
352 typedef enum TA_Style_
354 #include "tastyles.h"
356 TA_STYLE_MAX
/* do not remove */
360 typedef struct TA_StyleClassRec_
364 TA_WritingSystem writing_system
;
366 TA_Blue_Stringset blue_stringset
;
367 TA_Coverage coverage
;
370 typedef const TA_StyleClassRec
* TA_StyleClass
;
373 typedef struct TA_FaceGlobalsRec_
* TA_FaceGlobals
;
375 /* This is the main structure that combines everything. Autofit modules */
376 /* specific to writing systems derive their structures from it, for */
377 /* example `TA_LatinMetrics'. */
379 typedef struct TA_StyleMetricsRec_
381 TA_StyleClass style_class
;
383 FT_Bool digits_have_same_width
;
385 TA_FaceGlobals globals
; /* to access properties */
386 } TA_StyleMetricsRec
;
392 #endif /* __TATYPES_H__ */
394 /* end of tatypes.h */