lewp_css/domain/at_rules/font_face/
font_face.rs

1// This file is part of css. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/css/master/COPYRIGHT. No part of predicator, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2// Copyright © 2017 The developers of css. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/css/master/COPYRIGHT.
3
4use {
5    super::{
6        FamilyName,
7        FontDisplay,
8        FontFaceAtRule,
9        FontFeatureSettings,
10        FontLanguageOverride,
11        FontStretch,
12        FontStyle,
13        FontWeight,
14        Source,
15    },
16    cssparser::UnicodeRange,
17};
18
19/// A @font-face rule that is known to have font-family and src declarations.
20pub struct FontFace<'a>(pub &'a FontFaceAtRule);
21
22impl<'a> FontFace<'a> {
23    /// The name of this font face
24    pub fn family(&self) -> &FamilyName {
25        self.0.family.as_ref().unwrap()
26    }
27
28    /// The alternative sources for this font face.
29    pub fn sources(&self) -> &Vec<Source> {
30        self.0.sources.as_ref().unwrap()
31    }
32
33    /// The style of this font face
34    pub fn style(&self) -> FontStyle {
35        if let Some(ref value) = self.0.style {
36            *value
37        } else {
38            FontStyle::normal
39        }
40    }
41
42    /// The style of this font face
43    pub fn weight(&self) -> FontWeight {
44        if let Some(ref value) = self.0.weight {
45            *value
46        } else {
47            FontWeight::normal
48        }
49    }
50
51    /// The stretch of this font face
52    pub fn stretch(&self) -> FontStretch {
53        if let Some(ref value) = self.0.stretch {
54            *value
55        } else {
56            FontStretch::normal
57        }
58    }
59
60    /// The display of this font face
61    pub fn display(&self) -> FontDisplay {
62        if let Some(ref value) = self.0.display {
63            *value
64        } else {
65            FontDisplay::auto
66        }
67    }
68
69    /// The ranges of code points outside of which this font face should not be used.
70    pub fn unicode_range(&self) -> Vec<UnicodeRange> {
71        if let Some(ref value) = self.0.unicode_range {
72            value.clone()
73        } else {
74            vec![UnicodeRange {
75                start: 0,
76                end: 0x10FFFF,
77            }]
78        }
79    }
80
81    /// The feature settings of this font face.
82    pub fn feature_settings(&self) -> FontFeatureSettings {
83        if let Some(ref value) = self.0.feature_settings {
84            value.clone()
85        } else {
86            FontFeatureSettings::normal()
87        }
88    }
89
90    /// The language override of this font face.
91    pub fn language_override(&self) -> FontLanguageOverride {
92        if let Some(ref value) = self.0.language_override {
93            *value
94        } else {
95            FontLanguageOverride::normal
96        }
97    }
98}