sdk-world
v2026.11.05
PS2 SDK - world tier (copyleft-allowed, non-essential packages)
Toggle main menu visibility
Loading...
Searching...
No Matches
aftypes.h
Go to the documentation of this file.
1
/****************************************************************************
2
*
3
* aftypes.h
4
*
5
* Auto-fitter types (specification only).
6
*
7
* Copyright (C) 2003-2025 by
8
* David Turner, Robert Wilhelm, and Werner Lemberg.
9
*
10
* This file is part of the FreeType project, and may only be used,
11
* modified, and distributed under the terms of the FreeType project
12
* license, LICENSE.TXT. By continuing to use, modify, or distribute
13
* this file you indicate that you have read the license and
14
* understand and accept it fully.
15
*
16
*/
17
18
19
/*************************************************************************
20
*
21
* The auto-fitter is a complete rewrite of the old auto-hinter.
22
* Its main feature is the ability to differentiate between different
23
* writing systems and scripts in order to apply specific rules.
24
*
25
* The code has also been compartmentalized into several entities that
26
* should make algorithmic experimentation easier than with the old
27
* code.
28
*
29
*************************************************************************/
30
31
36
#ifndef AFTYPES_H_
37
#define AFTYPES_H_
38
39
40
#include <
freetype/freetype.h
>
41
#include <
freetype/ftoutln.h
>
42
#include <
freetype/internal/fthash.h
>
43
#include <
freetype/internal/ftobjs.h
>
44
#include <
freetype/internal/ftdebug.h
>
45
46
#include "
afblue.h
"
47
48
#ifdef FT_DEBUG_AUTOFIT
49
#include FT_CONFIG_STANDARD_LIBRARY_H
50
#endif
51
52
53
FT_BEGIN_HEADER
54
55
/*************************************************************************/
56
/*************************************************************************/
57
/***** *****/
58
/***** D E B U G G I N G *****/
59
/***** *****/
60
/*************************************************************************/
61
/*************************************************************************/
62
63
#ifdef FT_DEBUG_AUTOFIT
64
65
extern
int
af_debug_disable_horz_hints_;
66
extern
int
af_debug_disable_vert_hints_;
67
extern
int
af_debug_disable_blue_hints_;
68
extern
void
* af_debug_hints_;
69
70
#endif
/* FT_DEBUG_AUTOFIT */
71
72
73
/*************************************************************************/
74
/*************************************************************************/
75
/***** *****/
76
/***** U T I L I T Y S T U F F *****/
77
/***** *****/
78
/*************************************************************************/
79
/*************************************************************************/
80
81
typedef
struct
AF_WidthRec_
82
{
83
FT_Pos org;
/* original position/width in font units */
84
FT_Pos cur;
/* current/scaled position/width in device subpixels */
85
FT_Pos fit;
/* current/fitted position/width in device subpixels */
86
87
} AF_WidthRec, *AF_Width;
88
89
90
FT_LOCAL(
void
)
91
af_sort_pos( FT_UInt count,
92
FT_Pos* table );
93
94
FT_LOCAL(
void
)
95
af_sort_and_quantize_widths( FT_UInt* count,
96
AF_Width widths,
97
FT_Pos threshold );
98
99
100
/*
101
* opaque handle to glyph-specific hints -- see `afhints.h' for more
102
* details
103
*/
104
typedef
struct
AF_GlyphHintsRec_
* AF_GlyphHints;
105
106
107
/*************************************************************************/
108
/*************************************************************************/
109
/***** *****/
110
/***** S C A L E R S *****/
111
/***** *****/
112
/*************************************************************************/
113
/*************************************************************************/
114
115
/*
116
* A scaler models the target pixel device that will receive the
117
* auto-hinted glyph image.
118
*/
119
120
#define AF_SCALER_FLAG_NO_HORIZONTAL 1U
/* disable horizontal hinting */
121
#define AF_SCALER_FLAG_NO_VERTICAL 2U
/* disable vertical hinting */
122
#define AF_SCALER_FLAG_NO_ADVANCE 4U
/* disable advance hinting */
123
124
125
typedef
struct
AF_ScalerRec_
126
{
127
FT_Face face;
/* source font face */
128
FT_Fixed x_scale;
/* from font units to 1/64 device pixels */
129
FT_Fixed y_scale;
/* from font units to 1/64 device pixels */
130
FT_Pos x_delta;
/* in 1/64 device pixels */
131
FT_Pos y_delta;
/* in 1/64 device pixels */
132
FT_Render_Mode render_mode;
/* monochrome, anti-aliased, LCD, etc. */
133
FT_UInt32 flags;
/* additional control flags, see above */
134
135
} AF_ScalerRec, *AF_Scaler;
136
137
138
#define AF_SCALER_EQUAL_SCALES( a, b ) \
139
( (a)->x_scale == (b)->x_scale && \
140
(a)->y_scale == (b)->y_scale && \
141
(a)->x_delta == (b)->x_delta && \
142
(a)->y_delta == (b)->y_delta )
143
144
145
typedef
struct
AF_StyleMetricsRec_
* AF_StyleMetrics;
146
147
/*
148
* This function parses an FT_Face to compute global metrics for
149
* a specific style.
150
*/
151
typedef
FT_Error
152
(*AF_WritingSystem_InitMetricsFunc)( AF_StyleMetrics metrics,
153
FT_Face face );
154
155
typedef
void
156
(*AF_WritingSystem_ScaleMetricsFunc)( AF_StyleMetrics metrics,
157
AF_Scaler scaler );
158
159
typedef
void
160
(*AF_WritingSystem_DoneMetricsFunc)( AF_StyleMetrics metrics );
161
162
typedef
void
163
(*AF_WritingSystem_GetStdWidthsFunc)( AF_StyleMetrics metrics,
164
FT_Pos* stdHW,
165
FT_Pos* stdVW );
166
167
168
typedef
FT_Error
169
(*AF_WritingSystem_InitHintsFunc)( AF_GlyphHints hints,
170
AF_StyleMetrics metrics );
171
172
typedef
FT_Error
173
(*AF_WritingSystem_ApplyHintsFunc)( FT_UInt glyph_index,
174
AF_GlyphHints hints,
175
FT_Outline* outline,
176
AF_StyleMetrics metrics );
177
178
179
/*************************************************************************/
180
/*************************************************************************/
181
/***** *****/
182
/***** W R I T I N G S Y S T E M S *****/
183
/***** *****/
184
/*************************************************************************/
185
/*************************************************************************/
186
187
/*
188
* For the auto-hinter, a writing system consists of multiple scripts that
189
* can be handled similarly *in a typographical way*; the relationship is
190
* not based on history. For example, both the Greek and the unrelated
191
* Armenian scripts share the same features like ascender, descender,
192
* x-height, etc. Essentially, a writing system is covered by a
193
* submodule of the auto-fitter; it contains
194
*
195
* - a specific global analyzer that computes global metrics specific to
196
* the script (based on script-specific characters to identify ascender
197
* height, x-height, etc.),
198
*
199
* - a specific glyph analyzer that computes segments and edges for each
200
* glyph covered by the script,
201
*
202
* - a specific grid-fitting algorithm that distorts the scaled glyph
203
* outline according to the results of the glyph analyzer.
204
*/
205
206
#undef WRITING_SYSTEM
207
#define WRITING_SYSTEM( ws, WS ) \
208
AF_WRITING_SYSTEM_ ## WS,
209
210
/* The list of known writing systems. */
211
typedef
enum
AF_WritingSystem_
212
{
213
214
#include "
afws-iter.h
"
215
216
AF_WRITING_SYSTEM_MAX
/* do not remove */
217
218
} AF_WritingSystem;
219
220
221
typedef
struct
AF_WritingSystemClassRec_
222
{
223
AF_WritingSystem writing_system;
224
225
FT_Offset style_metrics_size;
226
AF_WritingSystem_InitMetricsFunc style_metrics_init;
227
AF_WritingSystem_ScaleMetricsFunc style_metrics_scale;
228
AF_WritingSystem_DoneMetricsFunc style_metrics_done;
229
AF_WritingSystem_GetStdWidthsFunc style_metrics_getstdw;
230
231
AF_WritingSystem_InitHintsFunc style_hints_init;
232
AF_WritingSystem_ApplyHintsFunc style_hints_apply;
233
234
} AF_WritingSystemClassRec;
235
236
typedef
const
AF_WritingSystemClassRec* AF_WritingSystemClass;
237
238
239
/*************************************************************************/
240
/*************************************************************************/
241
/***** *****/
242
/***** S C R I P T S *****/
243
/***** *****/
244
/*************************************************************************/
245
/*************************************************************************/
246
247
/*
248
* Each script is associated with two sets of Unicode ranges to test
249
* whether the font face supports the script, and which non-base
250
* characters the script contains.
251
*
252
* We use four-letter script tags from the OpenType specification,
253
* extended by `NONE', which indicates `no script'.
254
*/
255
256
#undef SCRIPT
257
#define SCRIPT( s, S, d, h, H, ss ) \
258
AF_SCRIPT_ ## S,
259
260
/* The list of known scripts. */
261
typedef
enum
AF_Script_
262
{
263
264
#include "
afscript.h
"
265
266
AF_SCRIPT_MAX
/* do not remove */
267
268
} AF_Script;
269
270
271
typedef
struct
AF_Script_UniRangeRec_
272
{
273
FT_UInt32 first;
274
FT_UInt32 last;
275
276
} AF_Script_UniRangeRec;
277
278
#define AF_UNIRANGE_REC( a, b ) { (FT_UInt32)(a), (FT_UInt32)(b) }
279
280
typedef
const
AF_Script_UniRangeRec* AF_Script_UniRange;
281
282
283
typedef
struct
AF_ScriptClassRec_
284
{
285
AF_Script script;
286
287
/* last element in the ranges must be { 0, 0 } */
288
AF_Script_UniRange script_uni_ranges;
289
AF_Script_UniRange script_uni_nonbase_ranges;
290
291
FT_Bool top_to_bottom_hinting;
292
293
const
char
* standard_charstring;
/* for default width and height */
294
295
} AF_ScriptClassRec;
296
297
typedef
const
AF_ScriptClassRec* AF_ScriptClass;
298
299
300
/*************************************************************************/
301
/*************************************************************************/
302
/***** *****/
303
/***** C O V E R A G E S *****/
304
/***** *****/
305
/*************************************************************************/
306
/*************************************************************************/
307
308
/*
309
* Usually, a font contains more glyphs than can be addressed by its
310
* character map.
311
*
312
* In the PostScript font world, encoding vectors specific to a given
313
* task are used to select such glyphs, and these glyphs can be often
314
* recognized by having a suffix in its glyph names. For example, a
315
* superscript glyph `A' might be called `A.sup'. Unfortunately, this
316
* naming scheme is not standardized and thus unusable for us.
317
*
318
* In the OpenType world, a better solution was invented, namely
319
* `features', which cleanly separate a character's input encoding from
320
* the corresponding glyph's appearance, and which don't use glyph names
321
* at all. For our purposes, and slightly generalized, an OpenType
322
* feature is a name of a mapping that maps character codes to
323
* non-standard glyph indices (features get used for other things also).
324
* For example, the `sups' feature provides superscript glyphs, thus
325
* mapping character codes like `A' or `B' to superscript glyph
326
* representation forms. How this mapping happens is completely
327
* uninteresting to us.
328
*
329
* For the auto-hinter, a `coverage' represents all glyphs of an OpenType
330
* feature collected in a set (as listed below) that can be hinted
331
* together. To continue the above example, superscript glyphs must not
332
* be hinted together with normal glyphs because the blue zones
333
* completely differ.
334
*
335
* Note that FreeType itself doesn't compute coverages; it only provides
336
* the glyphs addressable by the default Unicode character map. Instead,
337
* we use the HarfBuzz library (if available), which has many functions
338
* exactly for this purpose.
339
*
340
* AF_COVERAGE_DEFAULT is special: It should cover everything that isn't
341
* listed separately (including the glyphs addressable by the character
342
* map). In case HarfBuzz isn't available, it exactly covers the glyphs
343
* addressable by the character map.
344
*
345
*/
346
347
#undef COVERAGE
348
#define COVERAGE( name, NAME, description, \
349
tag1, tag2, tag3, tag4 ) \
350
AF_COVERAGE_ ## NAME,
351
352
353
typedef
enum
AF_Coverage_
354
{
355
#include "
afcover.h
"
356
357
AF_COVERAGE_DEFAULT
358
359
} AF_Coverage;
360
361
362
/*************************************************************************/
363
/*************************************************************************/
364
/***** *****/
365
/***** S T Y L E S *****/
366
/***** *****/
367
/*************************************************************************/
368
/*************************************************************************/
369
370
/*
371
* The topmost structure for modelling the auto-hinter glyph input data
372
* is a `style class', grouping everything together.
373
*/
374
375
#undef STYLE
376
#define STYLE( s, S, d, ws, sc, ss, c ) \
377
AF_STYLE_ ## S,
378
379
/* The list of known styles. */
380
typedef
enum
AF_Style_
381
{
382
383
#include "
afstyles.h
"
384
385
AF_STYLE_MAX
/* do not remove */
386
387
} AF_Style;
388
389
390
typedef
struct
AF_StyleClassRec_
391
{
392
AF_Style style;
393
394
AF_WritingSystem writing_system;
395
AF_Script script;
396
AF_Blue_Stringset blue_stringset;
397
AF_Coverage coverage;
398
399
} AF_StyleClassRec;
400
401
typedef
const
AF_StyleClassRec* AF_StyleClass;
402
403
404
/*************************************************************************/
405
/*************************************************************************/
406
/***** *****/
407
/***** S T Y L E M E T R I C S *****/
408
/***** *****/
409
/*************************************************************************/
410
/*************************************************************************/
411
412
typedef
struct
AF_FaceGlobalsRec_
* AF_FaceGlobals;
413
414
415
/* This is the main structure that combines everything. Autofit modules */
416
/* specific to writing systems derive their structures from it, for */
417
/* example `AF_LatinMetrics'. */
418
419
typedef
struct
AF_StyleMetricsRec_
420
{
421
AF_StyleClass style_class;
422
AF_ScalerRec scaler;
423
FT_Bool digits_have_same_width;
424
425
AF_FaceGlobals globals;
/* to access properties */
426
427
FT_Hash reverse_charmap;
428
429
} AF_StyleMetricsRec;
430
431
432
#define AF_HINTING_BOTTOM_TO_TOP 0
433
#define AF_HINTING_TOP_TO_BOTTOM 1
434
435
436
/* Declare and define vtables for classes */
437
#define AF_DECLARE_WRITING_SYSTEM_CLASS( writing_system_class ) \
438
FT_CALLBACK_TABLE const AF_WritingSystemClassRec \
439
writing_system_class;
440
441
#define AF_DEFINE_WRITING_SYSTEM_CLASS( \
442
writing_system_class, \
443
system, \
444
m_size, \
445
m_init, \
446
m_scale, \
447
m_done, \
448
m_stdw, \
449
h_init, \
450
h_apply ) \
451
FT_CALLBACK_TABLE_DEF \
452
const AF_WritingSystemClassRec writing_system_class = \
453
{ \
454
system, \
455
\
456
m_size, \
457
\
458
m_init, \
459
m_scale, \
460
m_done, \
461
m_stdw, \
462
\
463
h_init, \
464
h_apply \
465
};
466
467
468
#define AF_DECLARE_SCRIPT_CLASS( script_class ) \
469
FT_CALLBACK_TABLE const AF_ScriptClassRec \
470
script_class;
471
472
#define AF_DEFINE_SCRIPT_CLASS( \
473
script_class, \
474
script, \
475
ranges, \
476
nonbase_ranges, \
477
top_to_bottom, \
478
std_charstring ) \
479
FT_CALLBACK_TABLE_DEF \
480
const AF_ScriptClassRec script_class = \
481
{ \
482
script, \
483
ranges, \
484
nonbase_ranges, \
485
top_to_bottom, \
486
std_charstring, \
487
};
488
489
490
#define AF_DECLARE_STYLE_CLASS( style_class ) \
491
FT_CALLBACK_TABLE const AF_StyleClassRec \
492
style_class;
493
494
#define AF_DEFINE_STYLE_CLASS( \
495
style_class, \
496
style, \
497
writing_system, \
498
script, \
499
blue_stringset, \
500
coverage ) \
501
FT_CALLBACK_TABLE_DEF \
502
const AF_StyleClassRec style_class = \
503
{ \
504
style, \
505
writing_system, \
506
script, \
507
blue_stringset, \
508
coverage \
509
};
510
511
/* */
512
513
514
FT_END_HEADER
515
516
#endif
/* AFTYPES_H_ */
517
518
519
/* END */
afblue.h
afcover.h
afscript.h
afstyles.h
afws-iter.h
freetype.h
ftdebug.h
fthash.h
ftobjs.h
ftoutln.h
AF_FaceGlobalsRec_
Definition
afglobal.h:112
AF_GlyphHintsRec_
Definition
afhints.h:345
AF_ScalerRec_
Definition
aftypes.h:126
AF_ScriptClassRec_
Definition
aftypes.h:284
AF_Script_UniRangeRec_
Definition
aftypes.h:272
AF_StyleClassRec_
Definition
aftypes.h:391
AF_StyleMetricsRec_
Definition
aftypes.h:420
AF_WidthRec_
Definition
aftypes.h:82
AF_WritingSystemClassRec_
Definition
aftypes.h:222
freetype
src
autofit
aftypes.h
Generated by
1.18.0