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
//! # Babelfont
//!
//! Babelfont is a library for working with font source files from different font editing software.
//! It provides a unified interface to load, examine, manipulate, and convert fonts between
//! various formats, abstracting over the differences between font editors' native representations.
//!
//! ## Supported Formats
//!
//! Babelfont supports the following font source formats (depending on enabled features):
//!
//! - **Glyphs** (feature: `glyphs`): Glyphs 2 and Glyphs 3 files (`.glyphs` and `.glyphspackage`) (saving and loading)
//! - **UFO/DesignSpace** (feature: `ufo`): Unified Font Object format and DesignSpace documents (loading only)
//! - **FontLab** (feature: `fontlab`): FontLab VFJ (JSON) format (in progress)
//! - **Fontra** (feature: `fontra`): Fontra format (in progress)
//! - **Babelfont JSON**: Native JSON serialization of Babelfont's internal representation
//!
//! Additionally, with the `fontir` feature enabled, fonts can be compiled to binary `.ttf` format.
//!
//! ## Core Concepts
//!
//! Babelfont represents fonts using a [`Font`] structure that contains:
//!
//! - **Glyphs**: The font's glyph set with their outlines and metadata
//! - **Masters**: Design masters for variable/multiple master fonts
//! - **Axes**: Variable font axes definitions
//! - **Instances**: Named instances (static font variants)
//! - **Features**: OpenType feature code
//! - **Metadata**: Font naming, version, dates, and other information
//!
//! ## JSON Serialization
//!
//! One of Babelfont's key features is its ability to serialize and deserialize its internal
//! representation to and from JSON. This provides a format-agnostic way to store and exchange
//! font data, and can be useful for:
//!
//! - Converting between different font editor formats
//! - Creating programmatic font workflows
//! - Debugging and inspecting font structures
//! - Storing intermediate build artifacts
//! - Keeping font sources in version control
//!
//! To save a font as JSON, use the `.babelfont` extension:
//!
//! ```no_run
//! # use babelfont::{load, BabelfontError};
//! # fn main() -> Result<(), BabelfontError> {
//! let font = load("MyFont.glyphs")?;
//! font.save("MyFont.babelfont")?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Font Filters
//!
//! Babelfont includes a set of filters for manipulating fonts. Filters implement the
//! [`filters::FontFilter`] trait and can be chained together to perform complex transformations:
//!
//! - [`filters::RetainGlyphs`]: Keep only specified glyphs, removing all others
//! - [`filters::DropAxis`]: Remove a variable font axis
//! - [`filters::DropInstances`]: Remove named instances
//! - [`filters::DropKerning`]: Remove kerning data
//! - [`filters::DropFeatures`]: Remove OpenType feature code
//! - [`filters::DropGuides`]: Remove guidelines
//! - [`filters::DropSparseMasters`]: Remove sparse masters
//! - [`filters::ResolveIncludes`]: Resolve feature file includes
//! - [`filters::ScaleUpem`]: Scale the units-per-em
//!
//! ## Example: Load, Filter, and Convert
//!
//! This example demonstrates loading a DesignSpace-based font, filtering it to retain only
//! specific glyphs, and saving it as a Glyphs file:
//!
//! ```no_run
//! use babelfont::{load, BabelfontError};
//! use babelfont::filters::{FontFilter, RetainGlyphs};
//!
//! fn main() -> Result<(), BabelfontError> {
//! // Load a DesignSpace file
//! let mut font = load("MyFont.designspace")?;
//!
//! // Create a filter to retain only certain glyphs
//! let filter = RetainGlyphs::new(vec![
//! "A".to_string(),
//! "B".to_string(),
//! "C".to_string(),
//! "space".to_string(),
//! ]);
//!
//! // Apply the filter
//! filter.apply(&mut font)?;
//!
//! // Save as a Glyphs file
//! font.save("MyFont-Subset.glyphs")?;
//!
//! Ok(())
//! }
//! ```
//!
//! ## Example: Working with Font Metadata
//!
//! ```no_run
//! # use babelfont::{load, BabelfontError};
//! # fn main() -> Result<(), BabelfontError> {
//! let font = load("MyFont.ufo")?;
//!
//! // Access font metadata
//! println!("Font family: {}", font.names.family_name);
//! println!("Units per em: {}", font.upm);
//! println!("Number of glyphs: {}", font.glyphs.len());
//!
//! // Iterate over axes in a variable font
//! for axis in &font.axes {
//! println!("Axis: {} ({}-{})", axis.name, axis.min, axis.max);
//! }
//!
//! // Access glyphs
//! if let Some(glyph) = font.glyphs.get("A") {
//! println!("Glyph 'A' has {} layers", glyph.layers.len());
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ## Feature Flags
//!
//! - `glyphs`: Enable support for Glyphs format files (default: enabled)
//! - `ufo`: Enable support for UFO and DesignSpace formats (default: enabled)
//! - `fontlab`: Enable support for FontLab VFJ format (default: enabled)
//! - `fontra`: Enable support for Fontra format (default: enabled)
//! - `fontir`: Enable compilation to binary font formats (default: enabled)
//! - `cli`: Enable command-line interface support
//! - `typescript`: Enable TypeScript type definition generation
extern crate serde_json_path_to_error as serde_json;
/// Convertors for various font file formats
/// Filters for font processing
pub use crate::;
pub use ;
use PathBuf;
// Ensure we export any types re-exported that we use in our public API
pub use Tag;
pub use Rect;
pub use NameId;
/// Load a Babelfont Font from a file
///
/// Which file formats are supported depends on which features are enabled:
/// - "ufo": UFO and DesignSpace files
/// - "glyphs": Glyphs files
/// - "fontlab": FontLab VFJ files