Crates.io | smufl |
lib.rs | smufl |
version | 0.2.1 |
source | src |
created_at | 2023-02-26 12:52:56.54723 |
updated_at | 2023-03-25 12:31:04.370903 |
description | Parse SMuFL (Standard Music Font Layout) metadata. |
homepage | https://github.com/peterstuart/smufl/ |
repository | https://github.com/peterstuart/smufl/ |
max_upload_size | |
id | 795019 |
size | 676,150 |
Parse SMuFL (Standard Music Font Layout) metadata.
SMuFL-compliant fonts can provide a metadata file in JSON format in their distribution package. The metadata file allows the designer to provide information that cannot easily (or in some cases at all) be encoded within or retrieved from the font software itself, including recommendations for how to draw the elements of music notation not provided directly by the font itself (such as staff lines, barlines, hairpins, etc.) in a manner complementary to the design of the font, and important glyph-specific metrics, such as the precise coordinates at which a stem should connect to a notehead.
See the SMuFL documentation for more details.
This crate supports version 1.40 of the SMuFL specification.
The font metadata can be read into the Metadata
struct:
use std::{fs::File, io::BufReader};
use smufl::{Glyph, Metadata, StaffSpaces};
let file = File::open("submodules/bravura/redist/bravura_metadata.json")?;
let reader = BufReader::new(file);
let metadata = Metadata::from_reader(reader)?;
assert_eq!(metadata.font_name, "Bravura");
assert_eq!(
metadata.engraving_defaults.staff_line_thickness.unwrap(),
StaffSpaces(0.13)
);
assert_eq!(
metadata.advance_widths.get(Glyph::NoteheadWhole).unwrap(),
StaffSpaces(1.688)
);
assert_eq!(
metadata
.anchors
.get(Glyph::NoteheadBlack)
.unwrap()
.stem_up_se
.unwrap()
.x(),
StaffSpaces(1.18)
);
assert_eq!(
metadata
.bounding_boxes
.get(Glyph::NoteheadBlack)
.unwrap()
.ne
.x(),
StaffSpaces(1.18)
);
This project uses the MIT License. Much of the documentation text is taken from the SMuFL spec, as allowed by its license.