verovio_data/lib.rs
1//! SMuFL font and resource files for the [Verovio](https://www.verovio.org/)
2//! music notation engraver.
3//!
4//! Verovio refuses to parse any input until `Resources::Ok()` returns true,
5//! which requires the font data on disk at the path passed to
6//! `Toolkit::SetResourcePath`. This crate bundles the resource tree at compile
7//! time and offers [`extract`] to stage it onto a real filesystem so Verovio
8//! can read it.
9//!
10//! The bundled contents are an exact mirror of the `data/` directory in the
11//! Verovio source tree pinned by the `verovio-sys` crate. Both Bravura
12//! (mandatory) and Leipzig (eager-loaded) are included, plus the optional
13//! Gootville, Leland, Petaluma, and Liberation fonts.
14
15use include_dir::{include_dir, Dir};
16use std::io;
17use std::path::Path;
18
19/// Bundled resource directory — a compile-time snapshot of Verovio's
20/// `data/`.
21pub const DATA: Dir<'static> =
22 include_dir!("$CARGO_MANIFEST_DIR/data");
23
24/// Extract all bundled resource files into `dest`. The destination is
25/// expected to already exist (e.g. a freshly-created tempdir). Any files
26/// already present at the same paths are overwritten.
27pub fn extract(dest: &Path) -> io::Result<()> {
28 DATA.extract(dest)
29}
30
31/// SMuFL font families bundled in this crate, as Verovio's `font`
32/// option understands them. Useful for populating a font picker in a UI
33/// without hard-coding the list at the call site.
34///
35/// The first entry (Bravura) is Verovio's default and the SMuFL
36/// reference font.
37pub const AVAILABLE_FONTS: &[&str] = &["Bravura", "Leipzig", "Gootville", "Leland", "Petaluma"];