pub trait VariableFont {
    // Required methods
    fn set_variation(&mut self, tag: &[u8; 4], value: f32) -> bool;
    fn variations(&self) -> Vec<VariationAxis, Global>;
}
Expand description

Logic for variable fonts.

Requires feature variable-fonts (enabled by default).

Required Methods§

fn set_variation(&mut self, tag: &[u8; 4], value: f32) -> bool

Sets a variation axis coordinate value by it’s tag.

Returns false if there is no such axis tag.

Example
use ab_glyph::{FontRef, VariableFont};

let mut font = FontRef::try_from_slice(include_bytes!("../../dev/fonts/Cantarell-VF.otf"))?;

// set weight to 600
assert!(font.set_variation(b"wght", 600.0));

// no such variation tag "foob" so return false
assert!(!font.set_variation(b"foob", 200.0));

fn variations(&self) -> Vec<VariationAxis, Global>

Returns variation axes.

Example
use ab_glyph::{FontRef, VariableFont};

let font = FontRef::try_from_slice(include_bytes!("../../dev/fonts/Cantarell-VF.otf"))?;
let var = &font.variations()[0];

assert_eq!(var.tag, *b"wght");
assert_eq!(var.name.as_deref(), Some("Weight"));
assert!((var.min_value - 100.0).abs() < f32::EPSILON);
assert!((var.default_value - 400.0).abs() < f32::EPSILON);
assert!((var.max_value - 800.0).abs() < f32::EPSILON);
assert!(!var.hidden);

Implementors§