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
105
106
107
108
109
110
111
112
113
114
115
use crate::error::SelectionError;
use crate::family_handle::FamilyHandle;
use crate::family_name::FamilyName;
use crate::handle::Handle;
use crate::properties::Properties;
use crate::source::Source;
#[allow(missing_debug_implementations)]
pub struct MultiSource {
subsources: Vec<Box<dyn Source>>,
}
impl MultiSource {
pub fn from_sources(subsources: Vec<Box<dyn Source>>) -> MultiSource {
MultiSource { subsources }
}
pub fn all_fonts(&self) -> Result<Vec<Handle>, SelectionError> {
let mut handles = vec![];
for subsource in &self.subsources {
handles.extend(subsource.all_fonts()?.into_iter())
}
Ok(handles)
}
pub fn all_families(&self) -> Result<Vec<String>, SelectionError> {
let mut families = vec![];
for subsource in &self.subsources {
families.extend(subsource.all_families()?.into_iter())
}
Ok(families)
}
pub fn select_family_by_name(&self, family_name: &str) -> Result<FamilyHandle, SelectionError> {
for subsource in &self.subsources {
match subsource.select_family_by_name(family_name) {
Ok(family) => return Ok(family),
Err(SelectionError::NotFound) => {}
Err(err) => return Err(err),
}
}
Err(SelectionError::NotFound)
}
pub fn select_by_postscript_name(
&self,
postscript_name: &str,
) -> Result<Handle, SelectionError> {
for subsource in &self.subsources {
match subsource.select_by_postscript_name(postscript_name) {
Ok(font) => return Ok(font),
Err(SelectionError::NotFound) => {}
Err(err) => return Err(err),
}
}
Err(SelectionError::NotFound)
}
#[inline]
pub fn select_best_match(
&self,
family_names: &[FamilyName],
properties: &Properties,
) -> Result<Handle, SelectionError> {
<Self as Source>::select_best_match(self, family_names, properties)
}
}
impl Source for MultiSource {
#[inline]
fn all_fonts(&self) -> Result<Vec<Handle>, SelectionError> {
self.all_fonts()
}
#[inline]
fn all_families(&self) -> Result<Vec<String>, SelectionError> {
self.all_families()
}
#[inline]
fn select_family_by_name(&self, family_name: &str) -> Result<FamilyHandle, SelectionError> {
self.select_family_by_name(family_name)
}
#[inline]
fn select_by_postscript_name(&self, postscript_name: &str) -> Result<Handle, SelectionError> {
self.select_by_postscript_name(postscript_name)
}
}