font_kit/family_handle.rs
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 Default for FamilyHandle {
22 fn default() -> Self {
23 Self::new()
24 }
25}
26
27impl FamilyHandle {
28 /// Creates an empty set of family handles.
29 #[inline]
30 pub fn new() -> FamilyHandle {
31 FamilyHandle { fonts: vec![] }
32 }
33
34 /// Creates a set of font family handles.
35 #[inline]
36 pub fn from_font_handles<I>(fonts: I) -> FamilyHandle
37 where
38 I: Iterator<Item = Handle>,
39 {
40 FamilyHandle {
41 fonts: fonts.collect::<Vec<Handle>>(),
42 }
43 }
44
45 /// Adds a new handle to this set.
46 #[inline]
47 pub fn push(&mut self, font: Handle) {
48 self.fonts.push(font)
49 }
50
51 /// Returns true if and only if this set has no fonts in it.
52 #[inline]
53 pub fn is_empty(&self) -> bool {
54 self.fonts.is_empty()
55 }
56
57 /// Returns all the handles in this set.
58 #[inline]
59 pub fn fonts(&self) -> &[Handle] {
60 &self.fonts
61 }
62}