Skip to content
11 changes: 10 additions & 1 deletion fontique/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use core_maths::CoreFloat;

use core::fmt;

pub(crate) const DEFAULT_OBLIQUE_ANGLE: f32 = 14.0;

/// Primary attributes for font matching: [`FontWidth`], [`FontStyle`] and [`FontWeight`].
///
/// These are used to [configure] a [`Query`].
Expand Down Expand Up @@ -492,6 +494,13 @@ impl FontStyle {
_ => Self::Normal,
}
}

pub(crate) fn oblique_angle(&self) -> Option<f32> {
match self {
Self::Oblique(angle) => Some(angle.unwrap_or(DEFAULT_OBLIQUE_ANGLE)),
_ => None,
}
}
}

impl fmt::Display for FontStyle {
Expand All @@ -500,7 +509,7 @@ impl fmt::Display for FontStyle {
Self::Normal => "normal",
Self::Italic => "italic",
Self::Oblique(None) => "oblique",
Self::Oblique(Some(degrees)) if *degrees == 14.0 => "oblique",
Self::Oblique(Some(degrees)) if *degrees == DEFAULT_OBLIQUE_ANGLE => "oblique",
Self::Oblique(Some(degrees)) => {
return write!(f, "oblique({degrees}deg)");
}
Expand Down
13 changes: 13 additions & 0 deletions fontique/src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//! Model for a font.

use crate::CharmapIndex;
use crate::matching::FontMatchingInfo;

use super::attributes::{FontStyle, FontWeight, FontWidth};
use super::source::{SourceInfo, SourceKind};
Expand All @@ -27,6 +28,18 @@ pub struct FontInfo {
charmap_index: CharmapIndex,
}

#[allow(clippy::from_over_into)] // In future From won't be possible
impl Into<FontMatchingInfo> for &FontInfo {
fn into(self) -> FontMatchingInfo {
FontMatchingInfo {
width: (self.width().ratio() * 100.0) as i32,
style: self.style(),
weight: self.weight().value(),
has_slnt: self.has_slant_axis(),
}
}
}

impl FontInfo {
/// Creates a new font object from the given source and index.
pub fn from_source(source: SourceInfo, index: u32) -> Option<Self> {
Expand Down
Loading
Loading