Skip to main content

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> = include_dir!("$VEROVIO_DATA_DIR");
22
23/// Extract all bundled resource files into `dest`. The destination is
24/// expected to already exist (e.g. a freshly-created tempdir). Any files
25/// already present at the same paths are overwritten.
26pub fn extract(dest: &Path) -> io::Result<()> {
27    DATA.extract(dest)
28}
29
30/// SMuFL font families bundled in this crate, as Verovio's `font`
31/// option understands them. Useful for populating a font picker in a UI
32/// without hard-coding the list at the call site.
33///
34/// The first entry (Bravura) is Verovio's default and the SMuFL
35/// reference font.
36pub const AVAILABLE_FONTS: &[&str] = &["Bravura", "Leipzig", "Gootville", "Leland", "Petaluma"];