1// font-kit/src/family_handle.rs
2//
3// Copyright © 2018 The Pathfinder Project Developers.
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10
11//! Encapsulates the information needed to locate and open the fonts in a family.
12
13use crate::handle::Handle;
14
15/// Encapsulates the information needed to locate and open the fonts in a family.
16#[derive(Debug)]
17pub struct FamilyHandle {
18 pub(crate) fonts: Vec<Handle>,
19}
20
21impl FamilyHandle {
22 /// Creates an empty set of family handles.
23 #[inline]
24 pub fn new() -> FamilyHandle {
25 FamilyHandle { fonts: vec![] }
26 }
27
28 /// Creates a set of font family handles.
29 #[inline]
30 pub fn from_font_handles<I>(fonts: I) -> FamilyHandle
31 where
32 I: Iterator<Item = Handle>,
33 {
34 FamilyHandle {
35 fonts: fonts.collect::<Vec<Handle>>(),
36 }
37 }
38
39 /// Adds a new handle to this set.
40 #[inline]
41 pub fn push(&mut self, font: Handle) {
42 self.fonts.push(font)
43 }
44
45 /// Returns true if and only if this set has no fonts in it.
46 #[inline]
47 pub fn is_empty(&self) -> bool {
48 self.fonts.is_empty()
49 }
50
51 /// Returns all the handles in this set.
52 #[inline]
53 pub fn fonts(&self) -> &[Handle] {
54 &self.fonts
55 }
56}
57