1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//! Drawing glyphs from fonts at a size, with hinting.
//!
//! A [`Font`] is a font at a location in its variation space. A
//! [`ScalerFont`] draws the font's glyph outlines at a size in pixels per em,
//! hinted or not.
//!
//! ```
//! use skrifa::{
//! font::{glyph::outline::SvgSink, Font},
//! DrawMemory, HintOptions, RasterTarget, ScalerFont,
//! };
//!
//! # fn wrapper(data: Vec<u8>) -> Result<(), skrifa::ScaleError> {
//! // Load the first font in the file and create a bold instance.
//! let font = Font::new(data, 0).unwrap();
//! let bold = font.instance_builder().variations([("wght", 700.0)]).build();
//!
//! // Find the glyph ID for the character 'A'.
//! let glyph_id = bold.charmap().map_unicode('A').unwrap_or_default();
//!
//! // Configure a scaler font for hinted drawing at 16 pixels per em, using
//! // the interpreter with a horizontal subpixel target.
//! let options = HintOptions::interpreter().with_target(RasterTarget::Lcd);
//! let scaler = ScalerFont::hinted(bold, 16.0, options);
//!
//! if let Some(outline) = scaler.outline(glyph_id) {
//! let mut path = SvgSink::new();
//! // Draw into the path and store the resulting metrics.
//! let metrics = outline.draw(DrawMemory::Scratch, &mut path)?;
//! println!("{path} advances by {:?}", metrics.h_advance);
//! }
//! # Ok(())
//! # }
//! ```
//!
//! # Drawing
//!
//! [`ScalerFont::outline`] returns a glyph's outline as a [`ScalerOutline`],
//! which draws into any [`PathSink`]. Drawing needs working memory. By
//! default it uses short-lived scratch memory, and a caller drawing many
//! glyphs can supply a reusable buffer instead.
//!
//! A scaler draws from the first outline table the font contains, in
//! [`GlyphSourceOrder::DEFAULT`]: `VARC` composites over `glyf`, `CFF2`,
//! `CFF` or Type 1 charstrings. To choose other tables, pass a
//! [`ScalerSource`] in place of the font. The scaler reports the tables it
//! draws from.
//!
//! A scaler with no size draws in font units.
//!
//! # Hinting
//!
//! Hinting fits an outline to the pixel grid at the scaler's size.
//! [`HintOptions`] configures it:
//!
//! - **Engine.** Run the font's own hints, either TrueType instructions or
//! PostScript hints; run the automatic hinter, which derives hints from
//! the outline; or pick based on the font, using its own hints where they
//! are worth running. A TrueType font that needs its instructions to draw
//! correct contours always runs them.
//! - **Target.** Monochrome, grayscale, light grayscale, or horizontal or
//! vertical subpixel rendering. Each target hints to suit the way its
//! pixels are drawn.
//! - **Linear metrics.** Hint only vertically, keeping the unhinted
//! horizontal shape and spacing.
//! - **ClearType compatibility.** Choose between the current ClearType
//! behavior of the TrueType interpreter, which follows the font's `gasp`
//! table, and the classic behavior, which grid fits every glyph.
//! - **Strictness.** Fail a draw when a glyph's instructions fail, instead of
//! keeping the outline as they left it.
//!
//! The scaler reports the engine that runs, and the rasterizer settings the
//! font requests at the size: whether to smooth along both axes, and the
//! dropout control a glyph asks of a monochrome rasterizer.
//!
//! # Metrics
//!
//! A scaler returns the font's line metrics and heights, its style metrics
//! such as the underline and italic angle, and the advance and bounds of each
//! glyph, all scaled linearly to its size. Hinting can change a glyph's
//! advance, so hinted glyph metrics come from drawing the outline.
//!
//! # The font model
//!
//! The [`font`] module holds everything else about a font: its character
//! map, names, variation axes and instances, and color and bitmap glyphs.
//!
//! # Need shaping?
//!
//! [HarfRust](https://docs.rs/harfrust) turns text into positioned glyphs.
//! It reads fonts through the same font model, so a [`Font`] can be shaped
//! with HarfRust and drawn with a [`ScalerFont`].
// Compiles the README's example.
compile_error!;
extern crate core as std;
extern crate alloc;
/// Expose our "raw" underlying parser crate.
pub extern crate read_fonts as raw;
pub use Font;
pub use ;
pub use ;
// The API that `ScalerFont` and the font model replace. It is kept so that
// existing code builds, and hidden from the documentation.
pub use ;
pub use ;
pub use MetadataProvider;
pub use ;
pub use ;
/// Useful collection of common types suitable for glob importing.
use MAX_OUTLINE_POINTS;