skrifa/
provider.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
use super::{
    attribute::Attributes,
    charmap::Charmap,
    color::ColorGlyphCollection,
    instance::{LocationRef, Size},
    metrics::{GlyphMetrics, Metrics},
    outline::OutlineGlyphCollection,
    string::{LocalizedStrings, StringId},
    variation::{AxisCollection, NamedInstanceCollection},
    FontRef,
};

/// Interface for types that can provide font metadata.
pub trait MetadataProvider<'a>: Sized {
    /// Returns the primary attributes for font classification-- stretch,
    /// style and weight.
    fn attributes(&self) -> Attributes;

    /// Returns the collection of variation axes.
    fn axes(&self) -> AxisCollection<'a>;

    /// Returns the collection of named variation instances.
    fn named_instances(&self) -> NamedInstanceCollection<'a>;

    /// Returns an iterator over the collection of localized strings for the
    /// given informational string identifier.
    fn localized_strings(&self, id: StringId) -> LocalizedStrings<'a>;

    /// Returns the global font metrics for the specified size and location in
    /// normalized variation space.
    fn metrics(&self, size: Size, location: impl Into<LocationRef<'a>>) -> Metrics;

    /// Returns the glyph specific metrics for the specified size and location
    /// in normalized variation space.
    fn glyph_metrics(&self, size: Size, location: impl Into<LocationRef<'a>>) -> GlyphMetrics<'a>;

    /// Returns the character to nominal glyph identifier mapping.
    fn charmap(&self) -> Charmap<'a>;

    /// Returns the collection of scalable glyph outlines.
    ///
    /// If the font contains multiple outline sources, this method prioritizes
    /// `glyf`, `CFF2` and `CFF` in that order. To select a specific outline
    /// source, use the [`OutlineGlyphCollection::with_format`] method.
    fn outline_glyphs(&self) -> OutlineGlyphCollection<'a>;

    // Returns a collection of paintable color glyphs.
    fn color_glyphs(&self) -> ColorGlyphCollection<'a>;
}

impl<'a> MetadataProvider<'a> for FontRef<'a> {
    /// Returns the primary attributes for font classification-- stretch,
    /// style and weight.
    fn attributes(&self) -> Attributes {
        Attributes::new(self)
    }

    /// Returns the collection of variation axes.
    fn axes(&self) -> AxisCollection<'a> {
        AxisCollection::new(self)
    }

    /// Returns the collection of named variation instances.
    fn named_instances(&self) -> NamedInstanceCollection<'a> {
        NamedInstanceCollection::new(self)
    }

    /// Returns an iterator over the collection of localized strings for the
    /// given informational string identifier.
    fn localized_strings(&self, id: StringId) -> LocalizedStrings<'a> {
        LocalizedStrings::new(self, id)
    }

    /// Returns the global font metrics for the specified size and location in
    /// normalized variation space.
    fn metrics(&self, size: Size, location: impl Into<LocationRef<'a>>) -> Metrics {
        Metrics::new(self, size, location)
    }

    /// Returns the glyph specific metrics for the specified size and location
    /// in normalized variation space.
    fn glyph_metrics(&self, size: Size, location: impl Into<LocationRef<'a>>) -> GlyphMetrics<'a> {
        GlyphMetrics::new(self, size, location)
    }

    /// Returns the character to nominal glyph identifier mapping.
    fn charmap(&self) -> Charmap<'a> {
        Charmap::new(self)
    }

    /// Returns the collection of scalable glyph outlines.
    ///
    /// If the font contains multiple outline sources, this method prioritizes
    /// `glyf`, `CFF2` and `CFF` in that order. To select a specific outline
    /// source, use the [`OutlineGlyphCollection::with_format`] method.
    fn outline_glyphs(&self) -> OutlineGlyphCollection<'a> {
        OutlineGlyphCollection::new(self)
    }

    // Returns a collection of paintable color glyphs.
    fn color_glyphs(&self) -> ColorGlyphCollection<'a> {
        ColorGlyphCollection::new(self)
    }
}