Trait ab_glyph::VariableFont
source · pub trait VariableFont {
// Required methods
fn set_variation(&mut self, tag: &[u8; 4], value: f32) -> bool;
fn variations(&self) -> Vec<VariationAxis>;
}
Expand description
Logic for variable fonts.
Requires feature variable-fonts
(enabled by default).
Required Methods§
sourcefn set_variation(&mut self, tag: &[u8; 4], value: f32) -> bool
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));
sourcefn variations(&self) -> Vec<VariationAxis>
fn variations(&self) -> Vec<VariationAxis>
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);