Skip to content

Commit e3f42ba

Browse files
authored
Add From conversions between usvg and fontdb enums
Closes #808
1 parent e49afab commit e3f42ba

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

crates/usvg/src/tree/text.rs

+56
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,40 @@ impl Default for FontStretch {
3333
}
3434
}
3535

36+
#[cfg(feature = "text")]
37+
impl From<fontdb::Stretch> for FontStretch {
38+
fn from(stretch: fontdb::Stretch) -> Self {
39+
match stretch {
40+
fontdb::Stretch::UltraCondensed => FontStretch::UltraCondensed,
41+
fontdb::Stretch::ExtraCondensed => FontStretch::ExtraCondensed,
42+
fontdb::Stretch::Condensed => FontStretch::Condensed,
43+
fontdb::Stretch::SemiCondensed => FontStretch::SemiCondensed,
44+
fontdb::Stretch::Normal => FontStretch::Normal,
45+
fontdb::Stretch::SemiExpanded => FontStretch::SemiExpanded,
46+
fontdb::Stretch::Expanded => FontStretch::Expanded,
47+
fontdb::Stretch::ExtraExpanded => FontStretch::ExtraExpanded,
48+
fontdb::Stretch::UltraExpanded => FontStretch::UltraExpanded,
49+
}
50+
}
51+
}
52+
53+
#[cfg(feature = "text")]
54+
impl From<FontStretch> for fontdb::Stretch {
55+
fn from(stretch: FontStretch) -> Self {
56+
match stretch {
57+
FontStretch::UltraCondensed => fontdb::Stretch::UltraCondensed,
58+
FontStretch::ExtraCondensed => fontdb::Stretch::ExtraCondensed,
59+
FontStretch::Condensed => fontdb::Stretch::Condensed,
60+
FontStretch::SemiCondensed => fontdb::Stretch::SemiCondensed,
61+
FontStretch::Normal => fontdb::Stretch::Normal,
62+
FontStretch::SemiExpanded => fontdb::Stretch::SemiExpanded,
63+
FontStretch::Expanded => fontdb::Stretch::Expanded,
64+
FontStretch::ExtraExpanded => fontdb::Stretch::ExtraExpanded,
65+
FontStretch::UltraExpanded => fontdb::Stretch::UltraExpanded,
66+
}
67+
}
68+
}
69+
3670
/// A font style property.
3771
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
3872
pub enum FontStyle {
@@ -51,6 +85,28 @@ impl Default for FontStyle {
5185
}
5286
}
5387

88+
#[cfg(feature = "text")]
89+
impl From<fontdb::Style> for FontStyle {
90+
fn from(style: fontdb::Style) -> Self {
91+
match style {
92+
fontdb::Style::Normal => FontStyle::Normal,
93+
fontdb::Style::Italic => FontStyle::Italic,
94+
fontdb::Style::Oblique => FontStyle::Oblique,
95+
}
96+
}
97+
}
98+
99+
#[cfg(feature = "text")]
100+
impl From<FontStyle> for fontdb::Style {
101+
fn from(style: FontStyle) -> Self {
102+
match style {
103+
FontStyle::Normal => fontdb::Style::Normal,
104+
FontStyle::Italic => fontdb::Style::Italic,
105+
FontStyle::Oblique => fontdb::Style::Oblique,
106+
}
107+
}
108+
}
109+
54110
/// Text font properties.
55111
#[derive(Clone, Eq, PartialEq, Hash, Debug)]
56112
pub struct Font {

0 commit comments

Comments
 (0)