skrifa/provider.rs
1use crate::GlyphNames;
2
3use super::{
4 attribute::Attributes,
5 charmap::Charmap,
6 color::ColorGlyphCollection,
7 instance::{LocationRef, Size},
8 metrics::{GlyphMetrics, Metrics},
9 outline::OutlineGlyphCollection,
10 string::{LocalizedStrings, StringId},
11 variation::{AxisCollection, NamedInstanceCollection},
12 FontRef,
13};
14use crate::bitmap::BitmapStrikes;
15
16/// Interface for types that can provide font metadata.
17pub trait MetadataProvider<'a>: Sized {
18 /// Returns the primary attributes for font classification-- stretch,
19 /// style and weight.
20 fn attributes(&self) -> Attributes;
21
22 /// Returns the collection of variation axes.
23 fn axes(&self) -> AxisCollection<'a>;
24
25 /// Returns the collection of named variation instances.
26 fn named_instances(&self) -> NamedInstanceCollection<'a>;
27
28 /// Returns an iterator over the collection of localized strings for the
29 /// given informational string identifier.
30 fn localized_strings(&self, id: StringId) -> LocalizedStrings<'a>;
31
32 /// Returns the mapping from glyph identifiers to names.
33 fn glyph_names(&self) -> GlyphNames<'a>;
34
35 /// Returns the global font metrics for the specified size and location in
36 /// normalized variation space.
37 fn metrics(&self, size: Size, location: impl Into<LocationRef<'a>>) -> Metrics;
38
39 /// Returns the glyph specific metrics for the specified size and location
40 /// in normalized variation space.
41 fn glyph_metrics(&self, size: Size, location: impl Into<LocationRef<'a>>) -> GlyphMetrics<'a>;
42
43 /// Returns the character to nominal glyph identifier mapping.
44 fn charmap(&self) -> Charmap<'a>;
45
46 /// Returns the collection of scalable glyph outlines.
47 ///
48 /// If the font contains multiple outline sources, this method prioritizes
49 /// `glyf`, `CFF2` and `CFF` in that order. To select a specific outline
50 /// source, use the [`OutlineGlyphCollection::with_format`] method.
51 fn outline_glyphs(&self) -> OutlineGlyphCollection<'a>;
52
53 // Returns a collection of paintable color glyphs.
54 fn color_glyphs(&self) -> ColorGlyphCollection<'a>;
55
56 /// Returns a collection of bitmap strikes.
57 fn bitmap_strikes(&self) -> BitmapStrikes<'a>;
58}
59
60impl<'a> MetadataProvider<'a> for FontRef<'a> {
61 /// Returns the primary attributes for font classification-- stretch,
62 /// style and weight.
63 fn attributes(&self) -> Attributes {
64 Attributes::new(self)
65 }
66
67 /// Returns the collection of variation axes.
68 fn axes(&self) -> AxisCollection<'a> {
69 AxisCollection::new(self)
70 }
71
72 /// Returns the collection of named variation instances.
73 fn named_instances(&self) -> NamedInstanceCollection<'a> {
74 NamedInstanceCollection::new(self)
75 }
76
77 /// Returns an iterator over the collection of localized strings for the
78 /// given informational string identifier.
79 fn localized_strings(&self, id: StringId) -> LocalizedStrings<'a> {
80 LocalizedStrings::new(self, id)
81 }
82
83 /// Returns the mapping from glyph identifiers to names.
84 fn glyph_names(&self) -> GlyphNames<'a> {
85 GlyphNames::new(self)
86 }
87
88 /// Returns the global font metrics for the specified size and location in
89 /// normalized variation space.
90 fn metrics(&self, size: Size, location: impl Into<LocationRef<'a>>) -> Metrics {
91 Metrics::new(self, size, location)
92 }
93
94 /// Returns the glyph specific metrics for the specified size and location
95 /// in normalized variation space.
96 fn glyph_metrics(&self, size: Size, location: impl Into<LocationRef<'a>>) -> GlyphMetrics<'a> {
97 GlyphMetrics::new(self, size, location)
98 }
99
100 /// Returns the character to nominal glyph identifier mapping.
101 fn charmap(&self) -> Charmap<'a> {
102 Charmap::new(self)
103 }
104
105 /// Returns the collection of scalable glyph outlines.
106 ///
107 /// If the font contains multiple outline sources, this method prioritizes
108 /// `glyf`, `CFF2` and `CFF` in that order. To select a specific outline
109 /// source, use the [`OutlineGlyphCollection::with_format`] method.
110 fn outline_glyphs(&self) -> OutlineGlyphCollection<'a> {
111 OutlineGlyphCollection::new(self)
112 }
113
114 // Returns a collection of paintable color glyphs.
115 fn color_glyphs(&self) -> ColorGlyphCollection<'a> {
116 ColorGlyphCollection::new(self)
117 }
118
119 /// Returns a collection of bitmap strikes.
120 fn bitmap_strikes(&self) -> BitmapStrikes<'a> {
121 BitmapStrikes::new(self)
122 }
123}