Coverage Report

Created: 2025-11-16 06:56

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fontations/skrifa/src/provider.rs
Line
Count
Source
1
use crate::{color::ColorPalettes, GlyphNames};
2
3
use 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
};
14
use crate::bitmap::BitmapStrikes;
15
16
/// Interface for types that can provide font metadata.
17
pub 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 color palettes for color glyphs.
57
    fn color_palettes(&self) -> ColorPalettes<'a>;
58
59
    /// Returns a collection of bitmap strikes.
60
    fn bitmap_strikes(&self) -> BitmapStrikes<'a>;
61
}
62
63
impl<'a> MetadataProvider<'a> for FontRef<'a> {
64
    /// Returns the primary attributes for font classification-- stretch,
65
    /// style and weight.
66
350k
    fn attributes(&self) -> Attributes {
67
350k
        Attributes::new(self)
68
350k
    }
69
70
    /// Returns the collection of variation axes.
71
668k
    fn axes(&self) -> AxisCollection<'a> {
72
668k
        AxisCollection::new(self)
73
668k
    }
74
75
    /// Returns the collection of named variation instances.
76
0
    fn named_instances(&self) -> NamedInstanceCollection<'a> {
77
0
        NamedInstanceCollection::new(self)
78
0
    }
79
80
    /// Returns an iterator over the collection of localized strings for the
81
    /// given informational string identifier.
82
0
    fn localized_strings(&self, id: StringId) -> LocalizedStrings<'a> {
83
0
        LocalizedStrings::new(self, id)
84
0
    }
85
86
    /// Returns the mapping from glyph identifiers to names.
87
0
    fn glyph_names(&self) -> GlyphNames<'a> {
88
0
        GlyphNames::new(self)
89
0
    }
90
91
    /// Returns the global font metrics for the specified size and location in
92
    /// normalized variation space.
93
0
    fn metrics(&self, size: Size, location: impl Into<LocationRef<'a>>) -> Metrics {
94
0
        Metrics::new(self, size, location)
95
0
    }
96
97
    /// Returns the glyph specific metrics for the specified size and location
98
    /// in normalized variation space.
99
369k
    fn glyph_metrics(&self, size: Size, location: impl Into<LocationRef<'a>>) -> GlyphMetrics<'a> {
100
369k
        GlyphMetrics::new(self, size, location)
101
369k
    }
Unexecuted instantiation: <read_fonts::FontRef as skrifa::provider::MetadataProvider>::glyph_metrics::<skrifa::instance::LocationRef>
<read_fonts::FontRef as skrifa::provider::MetadataProvider>::glyph_metrics::<&[font_types::fixed::F2Dot14]>
Line
Count
Source
99
369k
    fn glyph_metrics(&self, size: Size, location: impl Into<LocationRef<'a>>) -> GlyphMetrics<'a> {
100
369k
        GlyphMetrics::new(self, size, location)
101
369k
    }
102
103
    /// Returns the character to nominal glyph identifier mapping.
104
3.42M
    fn charmap(&self) -> Charmap<'a> {
105
3.42M
        Charmap::new(self)
106
3.42M
    }
107
108
    /// Returns the collection of scalable glyph outlines.
109
    ///
110
    /// If the font contains multiple outline sources, this method prioritizes
111
    /// `glyf`, `CFF2` and `CFF` in that order. To select a specific outline
112
    /// source, use the [`OutlineGlyphCollection::with_format`] method.
113
3.75M
    fn outline_glyphs(&self) -> OutlineGlyphCollection<'a> {
114
3.75M
        OutlineGlyphCollection::new(self)
115
3.75M
    }
116
117
    // Returns a collection of paintable color glyphs.
118
214k
    fn color_glyphs(&self) -> ColorGlyphCollection<'a> {
119
214k
        ColorGlyphCollection::new(self)
120
214k
    }
121
122
    /// Returns a collection of color palettes for color glyphs.
123
0
    fn color_palettes(&self) -> ColorPalettes<'a> {
124
0
        ColorPalettes::new(self)
125
0
    }
126
127
    /// Returns a collection of bitmap strikes.
128
0
    fn bitmap_strikes(&self) -> BitmapStrikes<'a> {
129
0
        BitmapStrikes::new(self)
130
0
    }
131
}