Skip to content

Commit

Permalink
Expose more font metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
bwoods committed Nov 14, 2024
1 parent 839143c commit 80bc3ec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
12 changes: 9 additions & 3 deletions composable-views/src/text/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,16 @@ impl<'a> Font<'a> {

/// Capital height,
#[inline]
pub fn capital_height(&self) -> f32 {
pub fn capital_height(&self) -> Option<f32> {
self.face
.capital_height()
.unwrap_or_else(|| self.face.ascender()) as f32
.capital_height().map(|x| x as f32)
}

/// x height.
#[inline]
pub fn x_height(&self) -> Option<f32> {
self.face
.x_height().map(|x| x as f32)
}

/// Line gap,
Expand Down
10 changes: 8 additions & 2 deletions composable-views/src/text/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,14 @@ impl Text<'_> {

/// Capital height of the Text’s font.
#[inline]
pub fn capital_height(&self) -> f32 {
self.font.capital_height() * self.scale
pub fn capital_height(&self) -> Option<f32> {
self.font.capital_height().map(|x| x * self.scale)
}

/// x height of the Text’s font.
#[inline]
pub fn x_height(&self) -> Option<f32> {
self.font.capital_height().map(|x| x * self.scale)
}

/// Line gap of the Text’s font.
Expand Down

0 comments on commit 80bc3ec

Please sign in to comment.