Skip to content

Commit bbcb871

Browse files
committed
Move conversion into font module
Signed-off-by: Nico Burns <[email protected]>
1 parent 47f2445 commit bbcb871

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

fontique/src/font.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//! Model for a font.
55
66
use crate::CharmapIndex;
7+
use crate::matching::FontMatchingInfo;
78

89
use super::attributes::{FontStyle, FontWeight, FontWidth};
910
use super::source::{SourceInfo, SourceKind};
@@ -27,6 +28,17 @@ pub struct FontInfo {
2728
charmap_index: CharmapIndex,
2829
}
2930

31+
impl Into<FontMatchingInfo> for &FontInfo {
32+
fn into(&self) -> FontMatchingInfo {
33+
FontMatchingInfo {
34+
width: (self.width().ratio() * 100.0) as i32,
35+
style: self.style(),
36+
weight: self.weight().value(),
37+
has_slnt: self.has_slant_axis(),
38+
}
39+
}
40+
}
41+
3042
impl FontInfo {
3143
/// Creates a new font object from the given source and index.
3244
pub fn from_source(source: SourceInfo, index: u32) -> Option<Self> {

fontique/src/matching.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@
66
use core::ops::Deref;
77

88
use super::attributes::{DEFAULT_OBLIQUE_ANGLE, FontStyle, FontWeight, FontWidth};
9-
use super::font::FontInfo;
109
use core::cmp::Ordering;
1110
use smallvec::SmallVec;
1211

1312
// Public API
1413

1514
#[derive(Copy, Clone)]
1615
pub struct FontMatchingInfo {
17-
width: i32,
18-
style: FontStyle,
19-
weight: f32,
20-
has_slnt: bool,
16+
pub width: i32,
17+
pub style: FontStyle,
18+
pub weight: f32,
19+
pub has_slnt: bool,
2120
}
2221

2322
pub fn match_font(
@@ -33,17 +32,6 @@ pub fn match_font(
3332

3433
// Private implementation details
3534

36-
impl From<&FontInfo> for FontMatchingInfo {
37-
fn from(info: &FontInfo) -> Self {
38-
Self {
39-
width: (info.width().ratio() * 100.0) as i32,
40-
style: info.style(),
41-
weight: info.weight().value(),
42-
has_slnt: info.has_slant_axis(),
43-
}
44-
}
45-
}
46-
4735
#[derive(Copy, Clone)]
4836
struct CandidateFont {
4937
index: usize,

0 commit comments

Comments
 (0)