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
use crate::attrmap2::AttrMap2;
use crate::style::units::{
    FontFamilyGeneric, FontPitch, FontStretch, FontStyle, FontVariant, FontWeight,
};
use crate::style::StyleOrigin;

/// The <style:font-face> element represents a font face declaration which documents the
/// properties of a font used in a document.
///
/// OpenDocument font face declarations directly correspond to the @font-face font description of
/// CSS2 (see §15.3.1) and the font-face element of SVG (see §20.8.3).
///
/// OpenDocument font face declarations may have an unique name. This name can be used inside
/// styles (as an attribute of <style:text-properties> element) as value of the style:fontname attribute to select a font face declaration. If a font face declaration is referenced by name,
/// the font-matching algorithms for selecting a font declaration based on the font-family, font-style,
/// font-variant, font-weight and font-size descriptors are not used but the referenced font face
/// declaration is used directly. (See §15.5 CSS2)
///
/// Consumers should implement the CSS2 font-matching algorithm with the OpenDocument font
/// face extensions. They may implement variations of the CSS2 font-matching algorithm. They may
/// implement a font-matching based only on the font face declarations, that is, a font-matching that is
/// not applied to every character independently but only once for each font face declaration. (See
/// §15.5 CSS2)
///
/// Font face declarations support the font descriptor attributes and elements described in §20.8.3 of
/// SVG.
#[derive(Clone, Debug, Default)]
pub struct FontFaceDecl {
    name: String,
    /// From where did we get this style.
    origin: StyleOrigin,
    /// All other attributes.
    attr: AttrMap2,
}

impl FontFaceDecl {
    /// New, empty.
    pub fn new_empty() -> Self {
        Self {
            name: "".to_string(),
            origin: Default::default(),
            attr: Default::default(),
        }
    }

    /// New, with a name.
    pub fn new<S: Into<String>>(name: S) -> Self {
        Self {
            name: name.into(),
            origin: StyleOrigin::Content,
            attr: Default::default(),
        }
    }

    /// New with a name.
    #[deprecated]
    pub fn new_with_name<S: Into<String>>(name: S) -> Self {
        Self::new(name)
    }

    /// Set the name.
    pub fn set_name<V: Into<String>>(&mut self, name: V) {
        self.name = name.into();
    }

    /// Returns the name.
    pub fn name(&self) -> &String {
        &self.name
    }

    /// Origin of the style
    pub fn set_origin(&mut self, origin: StyleOrigin) {
        self.origin = origin;
    }

    /// Origin of the style
    pub fn origin(&self) -> StyleOrigin {
        self.origin
    }

    /// General attributes.
    pub fn attrmap(&self) -> &AttrMap2 {
        &self.attr
    }

    /// General attributes.
    pub fn attrmap_mut(&mut self) -> &mut AttrMap2 {
        &mut self.attr
    }

    style_font_family_generic!(attr);
    style_font_pitch!(attr);
    svg_font_family!(attr);
    svg_font_stretch!(attr);
    svg_font_style!(attr);
    svg_font_variant!(attr);
    svg_font_weight!(attr);
}