1use crate::{Expression, Value};
2
3macro_rules! define_property {
4 (
5 $(
6 $(#[$attr:meta])*
7 $variant:ident($value_ty:ident, $name:expr),
8 )+
9 ) => {
10 #[derive(Clone, Debug, PartialEq)]
11 #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
12 pub enum Property {
13 $(
14 $(#[$attr])*
15 $variant(Expression),
16 )+
17 Dynamic(String, Expression),
18 }
19
20 impl Property {
21 pub fn kind(&self) -> PropertyKind {
22 match self {
23 $(
24 Property::$variant(_) => PropertyKind::$variant,
25 )+
26 Property::Dynamic(s, _) => PropertyKind::Dynamic(s.clone()),
27 }
28 }
29 }
30
31 #[derive(Clone, Debug, PartialEq, Eq)]
32 #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
33 pub enum PropertyKind {
34 $(
35 $(#[$attr])*
36 $variant,
37 )+
38 Dynamic(String),
39 }
40
41 parse_enum! {
42 PropertyKind,
43 $(
44 ($variant, $name),
45 )+
46 |s| Ok(PropertyKind::Dynamic(s.into())),
47 }
48
49 impl PropertyKind {
50 pub fn make_property(self, expr: Expression) -> Property {
51 match self {
52 $(
53 PropertyKind::$variant => Property::$variant(expr),
54 )+
55 PropertyKind::Dynamic(name) => Property::Dynamic(name.clone(), expr),
56 }
57 }
58 }
59 };
60}
61
62define_property! {
63 Family(String, "family"),
65 FamilyLang(String, "familylang"),
67 Style(String, "style"),
69 StyleLang(String, "stylelang"),
71 FullName(String, "fullname"),
73 FullNameLang(String, "fullnamelang"),
75
76 Slant(Int, "slant"),
78 Weight(Int, "weight"),
80 Size(Double, "size"),
82 Width(Int, "width"),
84 Aspect(Double, "aspect"),
86 PixelSize(Double, "pixelsize"),
88 Spacing(Int, "spacing"),
90 Foundry(String, "foundry"),
92 Antialias(Bool, "antialias"),
94 Hinting(Bool, "hinting"),
96 HintStyle(Int, "hintstyle"),
98 VerticalLayout(Bool, "verticallayout"),
100 AutoHint(Bool, "autohint"),
102 GlobalAdvance(Bool, "globaladvance"),
104
105 File(String, "file"),
107 Index(Int, "index"),
109 Rasterizer(String, "rasterizer"),
114 Outline(Bool, "outline"),
116 Scalable(Bool, "scalable"),
118 Color(Bool, "color"),
120 Scale(Double, "scale"),
122 Dpi(Double, "dpi"),
124 Rgba(Int, "rgba"),
126 Lcdfilter(Int, "lcdfilter"),
128 Minspace(Bool, "minspace"),
130 Charset(CharSet, "charset"),
132 Lang(String, "lang"),
134 Fontversion(Int, "fontversion"),
136 Capability(String, "capability"),
138 Fontformat(String, "fontformat"),
140 Embolden(Bool, "embolden"),
142 Embeddedbitmap(Bool, "embeddedbitmap"),
144 Decorative(Bool, "decorative"),
146 Fontfeatures(String, "fontfeatures"),
148 Namelang(String, "namelang"),
150 Prgname(String, "prgname"),
152 Postscriptname(String, "postscriptname"),
154 Fonthashint(Bool, "fonthashint"),
156 Order(Int, "order"),
158
159 Matrix(Matrix, "matrix"),
162 PixelSizeFixupFactor(Double, "pixelsizefixupfactor"),
163 ScalingNotNeeded(Bool, "scalingnotneeded"),
164}
165
166impl Default for Property {
167 fn default() -> Self {
168 Property::Family(Expression::Simple(Value::String(String::default())))
169 }
170}
171
172impl Default for PropertyKind {
173 fn default() -> Self {
174 PropertyKind::Family
175 }
176}