4 * Copyright (C) 2011-2022 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_MIN(a, b) ((a) < (b) ? (a) : (b))
92 #define TA_MAX(a, b) ((a) > (b) ? (a) : (b))
94 #define TA_ABS(a) ((a) < 0 ? -(a) : (a))
96 /* from file `ftconfig.h' (2015-03-02) from FreeType */
97 /* typeof condition taken from gnulib's `intprops.h' header file */
99 || defined(__IBM__TYPEOF__) \
100 || (__SUNPRO_C >= 0x5110 && !__STDC__))
101 #define TYPEOF(type) (__typeof__ (type))
103 #define TYPEOF(type) /* empty */
106 /* from file `ftobjs.h' from FreeType */
107 /* we use the TYPEOF macro to suppress signedness compilation warnings */
108 #define TA_PAD_FLOOR(x, n) ((x) & ~TYPEOF(x)((n) - 1))
109 #define TA_PAD_ROUND(x, n) TA_PAD_FLOOR((x) + ((n) / 2), n)
110 #define TA_PAD_CEIL(x, n) TA_PAD_FLOOR((x) + ((n) - 1), n)
112 #define TA_PIX_FLOOR(x) ((x) & ~TYPEOF(x)63)
113 #define TA_PIX_ROUND(x) TA_PIX_FLOOR((x) + 32)
114 #define TA_PIX_CEIL(x) TA_PIX_FLOOR((x) + 63)
117 typedef struct TA_WidthRec_
119 FT_Pos org
; /* original position/width in font units */
120 FT_Pos cur
; /* current/scaled position/width in device subpixels */
121 FT_Pos fit
; /* current/fitted position/width in device subpixels */
122 } TA_WidthRec
, *TA_Width
;
125 /* the auto-hinter doesn't need a very high angular accuracy */
126 typedef FT_Int TA_Angle
;
128 #define TA_ANGLE_PI 256
129 #define TA_ANGLE_2PI (TA_ANGLE_PI * 2)
130 #define TA_ANGLE_PI2 (TA_ANGLE_PI / 2)
131 #define TA_ANGLE_PI4 (TA_ANGLE_PI / 4)
133 #define TA_ANGLE_DIFF(result, angle1, angle2) \
136 TA_Angle _delta = (angle2) - (angle1); \
139 while (_delta <= -TA_ANGLE_PI) \
140 _delta += TA_ANGLE_2PI; \
142 if (_delta > TA_ANGLE_PI) \
143 _delta -= TA_ANGLE_2PI; \
149 /* opaque handle to glyph-specific hints -- */
150 /* see `tahints.h' for more details */
151 typedef struct TA_GlyphHintsRec_
* TA_GlyphHints
;
154 /* a scaler models the target pixel device that will receive */
155 /* the auto-hinted glyph image */
156 #define TA_SCALER_FLAG_NO_HORIZONTAL 0x01U /* disable horizontal hinting */
157 #define TA_SCALER_FLAG_NO_VERTICAL 0x02U /* disable vertical hinting */
158 #define TA_SCALER_FLAG_NO_ADVANCE 0x04U /* disable advance hinting */
159 #define TA_SCALER_FLAG_NO_WARPER 0x08U /* disable warper */
162 typedef struct TA_ScalerRec_
164 FT_Face face
; /* source font face */
165 FT_Fixed x_scale
; /* from font units to 1/64 device pixels */
166 FT_Fixed y_scale
; /* from font units to 1/64 device pixels */
167 FT_Pos x_delta
; /* in 1/64 device pixels */
168 FT_Pos y_delta
; /* in 1/64 device pixels */
169 FT_Render_Mode render_mode
; /* monochrome, anti-aliased, LCD, etc.*/
170 FT_UInt32 flags
; /* additional control flags, see above */
171 } TA_ScalerRec
, *TA_Scaler
;
173 #define TA_SCALER_EQUAL_SCALES(a, b) \
174 ((a)->x_scale == (b)->x_scale \
175 && (a)->y_scale == (b)->y_scale \
176 && (a)->x_delta == (b)->x_delta \
177 && (a)->y_delta == (b)->y_delta)
180 typedef struct TA_StyleMetricsRec_
* TA_StyleMetrics
;
182 /* this function parses an FT_Face to compute global metrics */
183 /* for a specific style, optionally using another FT_Face to */
184 /* derive blue zones */
186 (*TA_WritingSystem_InitMetricsFunc
)(TA_StyleMetrics metrics
,
190 (*TA_WritingSystem_ScaleMetricsFunc
)(TA_StyleMetrics metrics
,
193 (*TA_WritingSystem_DoneMetricsFunc
)(TA_StyleMetrics metrics
);
195 (*TA_WritingSystem_InitHintsFunc
)(TA_GlyphHints hints
,
196 TA_StyleMetrics metrics
);
198 (*TA_WritingSystem_ApplyHintsFunc
)(FT_UInt glyph_index
,
201 TA_StyleMetrics metrics
);
205 * For the auto-hinter, a writing system consists of multiple scripts that
206 * can be handled similarly *in a typographical way*; the relationship is
207 * not based on history. For example, both the Greek and the unrelated
208 * Armenian scripts share the same features like ascender, descender,
209 * x-height, etc. Essentially, a writing system is covered by a
210 * submodule of the auto-fitter; it contains
212 * - a specific global analyzer that computes global metrics specific to
213 * the script (based on script-specific characters to identify ascender
214 * height, x-height, etc.),
216 * - a specific glyph analyzer that computes segments and edges for each
217 * glyph covered by the script,
219 * - a specific grid-fitting algorithm that distorts the scaled glyph
220 * outline according to the results of the glyph analyzer.
223 #define TAWRTSYS_H_ /* don't load header files */
224 #undef WRITING_SYSTEM
225 #define WRITING_SYSTEM(ws, WS) \
226 TA_WRITING_SYSTEM_ ## WS,
228 /* The list of known writing systems. */
229 typedef enum TA_WritingSystem_
231 #include "tawrtsys.h"
233 TA_WRITING_SYSTEM_MAX
/* do not remove */
239 typedef struct TA_WritingSystemClassRec_
241 TA_WritingSystem writing_system
;
243 FT_Offset style_metrics_size
;
244 TA_WritingSystem_InitMetricsFunc style_metrics_init
;
245 TA_WritingSystem_ScaleMetricsFunc style_metrics_scale
;
246 TA_WritingSystem_DoneMetricsFunc style_metrics_done
;
248 TA_WritingSystem_InitHintsFunc style_hints_init
;
249 TA_WritingSystem_ApplyHintsFunc style_hints_apply
;
250 } TA_WritingSystemClassRec
;
252 typedef const TA_WritingSystemClassRec
* TA_WritingSystemClass
;
256 * Each script is associated with two sets of Unicode ranges to test
257 * whether the font face supports the script, and which base characters
258 * the script contains.
260 * We use four-letter script tags from the OpenType specification,
261 * extended by `NONE', which indicates `no script'.
265 #define SCRIPT(s, S, d, h, H, ss) \
268 /* The list of known scripts. */
269 typedef enum TA_Script_
271 #include <ttfautohint-scripts.h>
273 TA_SCRIPT_MAX
/* do not remove */
277 typedef struct TA_Script_UniRangeRec_
281 } TA_Script_UniRangeRec
;
283 #define TA_UNIRANGE_REC(a, b) \
284 { (FT_UInt32)(a), (FT_UInt32)(b) }
286 #define TA_HINTING_BOTTOM_TO_TOP 0
287 #define TA_HINTING_TOP_TO_BOTTOM 1
289 typedef const TA_Script_UniRangeRec
* TA_Script_UniRange
;
291 typedef struct TA_ScriptClassRec_
295 /* last element in the ranges must be { 0, 0 } */
296 TA_Script_UniRange script_uni_ranges
;
297 TA_Script_UniRange script_uni_nonbase_ranges
;
299 FT_Bool top_to_bottom_hinting
;
301 const char* standard_charstring
; /* for default width and height */
304 typedef const TA_ScriptClassRec
* TA_ScriptClass
;
308 * Usually, a font contains more glyphs than can be addressed by its
311 * In the PostScript font world, encoding vectors specific to a given
312 * task are used to select such glyphs, and these glyphs can be often
313 * recognized by having a suffix in its glyph names. For example, a
314 * superscript glyph `A' might be called `A.sup'. Unfortunately, this
315 * naming scheme is not standardized and thus unusable for us.
317 * In the OpenType world, a better solution was invented, namely
318 * `features', which cleanly separate a character's input encoding from
319 * the corresponding glyph's appearance, and which don't use glyph names
320 * at all. For our purposes, and slightly generalized, an OpenType
321 * feature is a name of a mapping that maps character codes to
322 * non-standard glyph indices (features get used for other things also).
323 * For example, the `sups' feature provides superscript glyphs, thus
324 * mapping character codes like `A' or `B' to superscript glyph
325 * representation forms. How this mapping happens is completely
326 * uninteresting to us.
328 * For the auto-hinter, a `coverage' represents all glyphs of an OpenType
329 * feature collected in a set (as listed below) that can be hinted
330 * together. To continue the above example, superscript glyphs must not
331 * be hinted together with normal glyphs because the blue zones
334 * To compute coverages, we use the HarfBuzz library, which has many
335 * functions exactly for this purpose.
337 * TA_COVERAGE_DEFAULT is special: It should cover everything that isn't
338 * listed separately (including the glyphs addressable by the character
343 #define COVERAGE(name, NAME, description, \
344 tag, tag1, tag2, tag3, tag4) \
345 TA_COVERAGE_ ## NAME,
347 typedef enum TA_Coverage_
349 #include "ttfautohint-coverages.h"
356 * The topmost structure for modelling the auto-hinter glyph input data
357 * is a `style class', grouping everything together.
361 #define STYLE(s, S, d, ws, sc, ss, c) \
364 /* The list of known styles. */
365 typedef enum TA_Style_
367 #include "tastyles.h"
369 TA_STYLE_MAX
/* do not remove */
373 typedef struct TA_StyleClassRec_
377 TA_WritingSystem writing_system
;
379 TA_Blue_Stringset blue_stringset
;
380 TA_Coverage coverage
;
383 typedef const TA_StyleClassRec
* TA_StyleClass
;
386 typedef struct TA_FaceGlobalsRec_
* TA_FaceGlobals
;
388 /* This is the main structure that combines everything. Autofit modules */
389 /* specific to writing systems derive their structures from it, for */
390 /* example `TA_LatinMetrics'. */
392 typedef struct TA_StyleMetricsRec_
394 TA_StyleClass style_class
;
396 FT_Bool digits_have_same_width
;
398 TA_FaceGlobals globals
; /* to access properties */
399 } TA_StyleMetricsRec
;
405 #endif /* TATYPES_H_ */
407 /* end of tatypes.h */