Skip to content

Commit

Permalink
Add From conversions between usvg and fontdb enums
Browse files Browse the repository at this point in the history
Closes #808
  • Loading branch information
dhardy authored Sep 2, 2024
1 parent e49afab commit e3f42ba
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions crates/usvg/src/tree/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,40 @@ impl Default for FontStretch {
}
}

#[cfg(feature = "text")]
impl From<fontdb::Stretch> for FontStretch {
fn from(stretch: fontdb::Stretch) -> Self {
match stretch {
fontdb::Stretch::UltraCondensed => FontStretch::UltraCondensed,
fontdb::Stretch::ExtraCondensed => FontStretch::ExtraCondensed,
fontdb::Stretch::Condensed => FontStretch::Condensed,
fontdb::Stretch::SemiCondensed => FontStretch::SemiCondensed,
fontdb::Stretch::Normal => FontStretch::Normal,
fontdb::Stretch::SemiExpanded => FontStretch::SemiExpanded,
fontdb::Stretch::Expanded => FontStretch::Expanded,
fontdb::Stretch::ExtraExpanded => FontStretch::ExtraExpanded,
fontdb::Stretch::UltraExpanded => FontStretch::UltraExpanded,
}
}
}

#[cfg(feature = "text")]
impl From<FontStretch> for fontdb::Stretch {
fn from(stretch: FontStretch) -> Self {
match stretch {
FontStretch::UltraCondensed => fontdb::Stretch::UltraCondensed,
FontStretch::ExtraCondensed => fontdb::Stretch::ExtraCondensed,
FontStretch::Condensed => fontdb::Stretch::Condensed,
FontStretch::SemiCondensed => fontdb::Stretch::SemiCondensed,
FontStretch::Normal => fontdb::Stretch::Normal,
FontStretch::SemiExpanded => fontdb::Stretch::SemiExpanded,
FontStretch::Expanded => fontdb::Stretch::Expanded,
FontStretch::ExtraExpanded => fontdb::Stretch::ExtraExpanded,
FontStretch::UltraExpanded => fontdb::Stretch::UltraExpanded,
}
}
}

/// A font style property.
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
pub enum FontStyle {
Expand All @@ -51,6 +85,28 @@ impl Default for FontStyle {
}
}

#[cfg(feature = "text")]
impl From<fontdb::Style> for FontStyle {
fn from(style: fontdb::Style) -> Self {
match style {
fontdb::Style::Normal => FontStyle::Normal,
fontdb::Style::Italic => FontStyle::Italic,
fontdb::Style::Oblique => FontStyle::Oblique,
}
}
}

#[cfg(feature = "text")]
impl From<FontStyle> for fontdb::Style {
fn from(style: FontStyle) -> Self {
match style {
FontStyle::Normal => fontdb::Style::Normal,
FontStyle::Italic => fontdb::Style::Italic,
FontStyle::Oblique => fontdb::Style::Oblique,
}
}
}

/// Text font properties.
#[derive(Clone, Eq, PartialEq, Hash, Debug)]
pub struct Font {
Expand Down

0 comments on commit e3f42ba

Please sign in to comment.