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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
//! # 
//!
//! Raster Font is a declarative font format for authoring and using image-backed fonts.
//!
//! ## Design
//!
//! General-purpose text engines are designed to solve many problems at once: shaping,
//! font fallback, layout, rasterization, editing, and platform integration across
//! many scripts and font formats. In game development, working with vector fonts can be burdensome:
//! if all you want is an authored set of glyphs, explicit ligatures, and pixel-perfect rendering,
//! adopting standard font formats and text engines can be a tall order. You may find yourself
//! fighting the shaping model of a text engine, or trying to shoehorn your assets into a format
//! that prioritizes other use cases.
//!
//! Raster Font takes a narrower approach. Instead of deriving glyphs from codepoints
//! through a runtime text pipeline, glyph resolution is baked into the font itself. A font
//! declares the exact input sequences it accepts and the glyph each sequence resolves to.
//! Input patterns are precompiled into efficient matching structures that can be used in a variety
//! of game engines and rendering systems.
//!
//! `raster_font` is not a general-purpose text engine, and it does not attempt to provide the
//! shaping and script support of a full typography stack. It is designed for fonts whose glyph set,
//! ligatures, spacing, and visual behavior are authored explicitly ahead of time. In return,
//! "raster fonts" stay simple to define, predictable to resolve, and easy to
//! render with crisp scaling and exact control over glyph mapping.
//!
//! ## Authoring
//!
//! The Raster Font format supports multi-character sequences, unions of sequences bound to
//! shared glyphs, per-glyph overrides, and manual glyph extraction.
//!
//! Creating a pixel-perfect font is a simple as opening your favorite image editor, drawing some
//! glyphs, and writing a simple TOML file to describe your font's layout and behavior.
//!
//! See the [meta documentation](meta) and [layout documentation](layout) for details on the font
//! format and authoring process.
//!
//! ## Resolution
//!
//! A [`RasterFont`] maps input text to valid glyphs using the [`InputResolver`](tree::InputResolver)
//! API. [`valid`] produces an iterator of leftmost-longest matches, silently skipping unmatched input.
//!
//! ```rust
//! use raster_font::{backend::prelude::*, tree::InputResolver};
//!
//! fn resolve<B: Backend<Resources: SpriteSheet>>(font: &RasterFont<B>) {
//! let glyphs = font.valid("Hello -> world :)").collect::<Vec<_>>();
//! // use glyphs...
//! }
//! ```
//!
//! ---
//!
//! ## First-party backends
//!
//! These crates have a stable release cycle and are considered reasonable for `raster_font` to
//! maintain integration with:
//!
//! | Backend | Feature | Description |
//! | :----------------: | :----------: | :---------- |
//! | [Bevy game engine] | `bevy` | Enables integration with Bevy’s asset system by providing `Asset` implementations for `RasterFont` and the `RasterFontAssetLoaderPlugin`. |
//!
//! ## Example backends
//!
//! The following examples are available in the crate repository.
//!
//! | Example | Description |
//! | :----------- | :---------- |
//! | `bevy_asset` | Demonstrates using the first-party bevy backend to load raster fonts as assets. |
//! | `macroquad` | Demonstrates implementing a custom backend for [Macroquad] and loading a font using the [builder API](crate::builder). |
//!
//! Open an issue if you'd like to see an integration example for a specific engine or framework.
//!
//! ---
//!
//! ## Bevy integration
//!
//! Enable the `bevy` feature to use the built-in Bevy backend.
//!
//! ```no_run
//! # #[cfg(feature = "bevy")]
//! use bevy::prelude::*;
//! use raster_font::prelude::*;
//!
//! fn main() {
//! # #[cfg(feature = "bevy")]
//! App::new()
//! .add_plugins((DefaultPlugins, RasterFontAssetLoaderPlugin))
//! .add_systems(Startup, load_font)
//! .run();
//! }
//!
//! # #[cfg(feature = "bevy")]
//! fn load_font(asset_server: Res<AssetServer>) {
//! let _font: Handle<RasterFont> =
//! asset_server.load("font.toml");
//! }
//! ```
//!
//! ---
//!
//! ## Common modules
//!
//! - Use [`prelude`] for common types and traits for consuming fonts.
//! - Use [`backend`] if implementing your own integration.
//! - Use [`core`] for core types like [`Sequence`], [`Token`], and [`AtlasIndex`].
//!
//!
//! ## Feature flags
//!
//! | Feature | Description |
//! | :-----------------: | :------------------------------------------------------ |
//! | `bevy` | Enables Bevy asset loading and integration |
//! | `font_sequence_map` | Enables direct sequence lookup via `RasterFont::get` |
//!
//! [`AtlasIndex`]: crate::core::AtlasIndex
//! [`Sequence`]: crate::token::Sequence
//! [`Token`]: crate::token::Token
//! [`RasterFont`]: crate::prelude::RasterFont
//! [`RasterFont::upgrade`]: crate::prelude::RasterFont::upgrade
//! [`SpriteSheet`]: crate::backend::SpriteSheet
//! [`FontResourceProvider`]: crate::backend::FontResourceProvider
//! [`valid`]: crate::tree::InputResolver::valid
//! [`valid_stream`]: crate::tree::InputResolver::valid_stream
//! [Bevy game engine]: https://bevyengine.org/
//! [Macroquad]: https://macroquad.rs/
// pub mod traits;
/// Provides `HashMap` and `HashSet` type aliases that switch between `std` and `bevy` collections
/// based on feature flags.
/// Common imports for using Raster Font.
///
/// This module is intended for **font consumers**: code that loads fonts, resolves
/// input into glyphs, and renders or otherwise uses the resulting data.
///
/// In other words, this prelude is for the *use-site* of a font, not for backend
/// authors or low-level integration code.
///
/// # When to use this
///
/// Import this when writing gameplay, UI, tools, or examples that *consume* a font:
///
/// ```rust,no_run
/// use raster_font::prelude::*;
/// ```
///
/// If you are implementing a custom backend or working with the lower-level builder
/// and backend traits, prefer importing from those modules directly instead of this
/// prelude. See [`backend`], [`core`], and backend-authoring examples in the crate repository.
///
/// [`RasterFont`]: crate::backend::RasterFont
/// [`InputResolver`]: crate::tree::InputResolver
/// [`LigatureTree`]: crate::tree::LigatureTree