Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impl From for FontStretch, FontStyle #813

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading