Crate smufl

source ·
Expand description

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)
);

Structs

  • Anchor data for glyphs.
  • The smallest rectangle that encloses every part of the glyph’s path.
  • X, Y coordinates in staff spaces.
  • Recommended defaults for line widths, etc.
  • A map of Glyph to some data (T).
  • Representation of the metadata file provided with a SMuFL font.
  • The primary unit of measurement for SMuFL fonts.

Enums

Type Definitions