spreadsheet_ods/style/fontface.rs
1use crate::attrmap2::AttrMap2;
2use crate::style::units::{
3 FontFamilyGeneric, FontPitch, FontStretch, FontStyle, FontVariant, FontWeight,
4};
5use crate::style::StyleOrigin;
6use get_size2::GetSize;
7
8/// The <style:font-face> element represents a font face declaration which documents the
9/// properties of a font used in a document.
10///
11/// OpenDocument font face declarations directly correspond to the @font-face font description of
12/// CSS2 (see §15.3.1) and the font-face element of SVG (see §20.8.3).
13///
14/// OpenDocument font face declarations may have an unique name. This name can be used inside
15/// 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,
16/// the font-matching algorithms for selecting a font declaration based on the font-family, font-style,
17/// font-variant, font-weight and font-size descriptors are not used but the referenced font face
18/// declaration is used directly. (See §15.5 CSS2)
19///
20/// Consumers should implement the CSS2 font-matching algorithm with the OpenDocument font
21/// face extensions. They may implement variations of the CSS2 font-matching algorithm. They may
22/// implement a font-matching based only on the font face declarations, that is, a font-matching that is
23/// not applied to every character independently but only once for each font face declaration. (See
24/// §15.5 CSS2)
25///
26/// Font face declarations support the font descriptor attributes and elements described in §20.8.3 of
27/// SVG.
28#[derive(Clone, Debug, Default, GetSize)]
29pub struct FontFaceDecl {
30 name: String,
31 /// From where did we get this style.
32 origin: StyleOrigin,
33 /// All other attributes.
34 attr: AttrMap2,
35}
36
37impl FontFaceDecl {
38 /// New, empty.
39 pub fn new_empty() -> Self {
40 Self {
41 name: "".to_string(),
42 origin: Default::default(),
43 attr: Default::default(),
44 }
45 }
46
47 /// New, with a name.
48 pub fn new<S: AsRef<str>>(name: S) -> Self {
49 Self {
50 name: name.as_ref().to_string(),
51 origin: StyleOrigin::Content,
52 attr: Default::default(),
53 }
54 }
55
56 /// New with a name.
57 #[deprecated]
58 pub fn new_with_name<S: AsRef<str>>(name: S) -> Self {
59 Self::new(name)
60 }
61
62 /// Set the name.
63 pub fn set_name<V: AsRef<str>>(&mut self, name: V) {
64 self.name = name.as_ref().to_string();
65 }
66
67 /// Returns the name.
68 pub fn name(&self) -> &String {
69 &self.name
70 }
71
72 /// Origin of the style
73 pub fn set_origin(&mut self, origin: StyleOrigin) {
74 self.origin = origin;
75 }
76
77 /// Origin of the style
78 pub fn origin(&self) -> StyleOrigin {
79 self.origin
80 }
81
82 /// General attributes.
83 pub fn attrmap(&self) -> &AttrMap2 {
84 &self.attr
85 }
86
87 /// General attributes.
88 pub fn attrmap_mut(&mut self) -> &mut AttrMap2 {
89 &mut self.attr
90 }
91
92 style_font_family_generic!(attr);
93 style_font_pitch!(attr);
94 svg_font_family!(attr);
95 svg_font_stretch!(attr);
96 svg_font_style!(attr);
97 svg_font_variant!(attr);
98 svg_font_weight!(attr);
99}