fontconfig_parser/types/
property.rs

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    /// Font family names
64    Family(String, "family"),
65    /// Languages corresponding to each family
66    FamilyLang(String, "familylang"),
67    /// Font style. Overrides weight and slant
68    Style(String, "style"),
69    /// Languages corresponding to each style
70    StyleLang(String, "stylelang"),
71    /// Font full names (often includes style)
72    FullName(String, "fullname"),
73    /// Languages corresponding to each fullname
74    FullNameLang(String, "fullnamelang"),
75
76    /// Italic, oblique or roman
77    Slant(Int, "slant"),
78    /// Light, medium, demibold, bold or black
79    Weight(Int, "weight"),
80    /// Point size
81    Size(Double, "size"),
82    /// Condensed, normal or expanded
83    Width(Int, "width"),
84    /// Stretches glyphs horizontally before hinting
85    Aspect(Double, "aspect"),
86    /// Pixel size
87    PixelSize(Double, "pixelsize"),
88    /// Proportional, dual-width, monospace or charcell
89    Spacing(Int, "spacing"),
90    /// Font foundry name
91    Foundry(String, "foundry"),
92    /// Whether glyphs can be antialiased
93    Antialias(Bool, "antialias"),
94    /// Whether the rasterizer should use hinting
95    Hinting(Bool, "hinting"),
96    /// Automatic hinting style
97    HintStyle(Int, "hintstyle"),
98    /// Automatic hinting style
99    VerticalLayout(Bool, "verticallayout"),
100    /// Use autohinter instead of normal hinter
101    AutoHint(Bool, "autohint"),
102    /// Use font global advance data (deprecated)
103    GlobalAdvance(Bool, "globaladvance"),
104
105    /// The filename holding the font
106    File(String, "file"),
107    /// The index of the font within the file
108    Index(Int, "index"),
109    // TODO:
110    // /// Use the specified FreeType face object
111    // Ftface(FT_Face),
112    /// Which rasterizer is in use (deprecated)
113    Rasterizer(String, "rasterizer"),
114    /// Whether the glyphs are outlines
115    Outline(Bool, "outline"),
116    /// Whether glyphs can be scaled
117    Scalable(Bool, "scalable"),
118    /// Whether any glyphs have color
119    Color(Bool, "color"),
120    /// Scale factor for point->pixel conversions (deprecated)
121    Scale(Double, "scale"),
122    /// Target dots per inch
123    Dpi(Double, "dpi"),
124    /// unknown, rgb, bgr, vrgb, vbgr, none - subpixel geometry
125    Rgba(Int, "rgba"),
126    /// Type of LCD filter
127    Lcdfilter(Int, "lcdfilter"),
128    /// Eliminate leading from line spacing
129    Minspace(Bool, "minspace"),
130    /// Unicode chars encoded by the font
131    Charset(CharSet, "charset"),
132    /// List of RFC-3066-style languages this font supports
133    Lang(String, "lang"),
134    /// Version number of the font
135    Fontversion(Int, "fontversion"),
136    /// List of layout capabilities in the font
137    Capability(String, "capability"),
138    /// String name of the font format
139    Fontformat(String, "fontformat"),
140    /// Rasterizer should synthetically embolden the font
141    Embolden(Bool, "embolden"),
142    /// Use the embedded bitmap instead of the outline
143    Embeddedbitmap(Bool, "embeddedbitmap"),
144    /// Whether the style is a decorative variant
145    Decorative(Bool, "decorative"),
146    /// List of the feature tags in OpenType to be enabled
147    Fontfeatures(String, "fontfeatures"),
148    /// Language name to be used for the default value of familylang, stylelang, and fullnamelang
149    Namelang(String, "namelang"),
150    /// String  Name of the running program
151    Prgname(String, "prgname"),
152    /// Font family name in PostScript
153    Postscriptname(String, "postscriptname"),
154    /// Whether the font has hinting
155    Fonthashint(Bool, "fonthashint"),
156    /// Order number of the font
157    Order(Int, "order"),
158
159    // custom
160
161    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}