1 use super::{ 2 attribute::Attributes, 3 charmap::Charmap, 4 color::ColorGlyphCollection, 5 instance::{LocationRef, Size}, 6 metrics::{GlyphMetrics, Metrics}, 7 outline::OutlineGlyphCollection, 8 string::{LocalizedStrings, StringId}, 9 variation::{AxisCollection, NamedInstanceCollection}, 10 }; 11 12 /// Interface for types that can provide font metadata. 13 pub trait MetadataProvider<'a>: raw::TableProvider<'a> + Sized { 14 /// Returns the primary attributes for font classification-- stretch, 15 /// style and weight. attributes(&self) -> Attributes16 fn attributes(&self) -> Attributes { 17 Attributes::new(self) 18 } 19 20 /// Returns the collection of variation axes. axes(&self) -> AxisCollection<'a>21 fn axes(&self) -> AxisCollection<'a> { 22 AxisCollection::new(self) 23 } 24 25 /// Returns the collection of named variation instances. named_instances(&self) -> NamedInstanceCollection<'a>26 fn named_instances(&self) -> NamedInstanceCollection<'a> { 27 NamedInstanceCollection::new(self) 28 } 29 30 /// Returns an iterator over the collection of localized strings for the 31 /// given informational string identifier. localized_strings(&self, id: StringId) -> LocalizedStrings<'a>32 fn localized_strings(&self, id: StringId) -> LocalizedStrings<'a> { 33 LocalizedStrings::new(self, id) 34 } 35 36 /// Returns the global font metrics for the specified size and location in 37 /// normalized variation space. metrics(&self, size: Size, location: impl Into<LocationRef<'a>>) -> Metrics38 fn metrics(&self, size: Size, location: impl Into<LocationRef<'a>>) -> Metrics { 39 Metrics::new(self, size, location) 40 } 41 42 /// Returns the glyph specific metrics for the specified size and location 43 /// in normalized variation space. glyph_metrics(&self, size: Size, location: impl Into<LocationRef<'a>>) -> GlyphMetrics<'a>44 fn glyph_metrics(&self, size: Size, location: impl Into<LocationRef<'a>>) -> GlyphMetrics<'a> { 45 GlyphMetrics::new(self, size, location) 46 } 47 48 /// Returns the character to nominal glyph identifier mapping. charmap(&self) -> Charmap<'a>49 fn charmap(&self) -> Charmap<'a> { 50 Charmap::new(self) 51 } 52 53 /// Returns the collection of scalable glyph outlines. 54 /// 55 /// If the font contains multiple outline sources, this method prioritizes 56 /// `glyf`, `CFF2` and `CFF` in that order. To select a specific outline 57 /// source, use the [`OutlineGlyphCollection::with_format`] method. outline_glyphs(&self) -> OutlineGlyphCollection<'a>58 fn outline_glyphs(&self) -> OutlineGlyphCollection<'a> { 59 OutlineGlyphCollection::new(self) 60 } 61 62 // Returns a collection of paintable color glyphs. color_glyphs(&self) -> ColorGlyphCollection<'a>63 fn color_glyphs(&self) -> ColorGlyphCollection<'a> { 64 ColorGlyphCollection::new(self) 65 } 66 } 67 68 /// Blanket implementation of `MetadataProvider` for any type that implements 69 /// `TableProvider`. 70 impl<'a, T> MetadataProvider<'a> for T where T: raw::TableProvider<'a> {} 71