Skip to content

Commit

Permalink
Check for italic angle in Face::is_italic.
Browse files Browse the repository at this point in the history
  • Loading branch information
RazrFalcon committed Sep 3, 2024
1 parent 9a5549c commit 1eba570
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Changed
- `Face::is_italic` checks for italic angle as well.
- `Face::italic_angle` returns just a `f32` and not `Option<f32>` now.

## [0.24.1] - 2024-08-05
### Added
Expand Down
27 changes: 10 additions & 17 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1402,21 +1402,14 @@ impl<'a> Face<'a> {
/// Returns `false` when OS/2 table is not present.
#[inline]
pub fn is_regular(&self) -> bool {
self.tables
.os2
.map(|s| s.style() == Style::Normal)
.unwrap_or(false)
self.style() == Style::Normal
}

/// Checks that face is marked as *Italic*.
///
/// Returns `false` when OS/2 table is not present.
#[inline]
pub fn is_italic(&self) -> bool {
self.tables
.os2
.map(|s| s.style() == Style::Italic)
.unwrap_or(false)
// A face can have a Normal style and a non-zero italic angle, which also makes it italic.
self.style() == Style::Italic || self.italic_angle() != 0.0
}

/// Checks that face is marked as *Bold*.
Expand All @@ -1432,10 +1425,7 @@ impl<'a> Face<'a> {
/// Returns `false` when OS/2 table is not present or when its version is < 4.
#[inline]
pub fn is_oblique(&self) -> bool {
self.tables
.os2
.map(|s| s.style() == Style::Oblique)
.unwrap_or(false)
self.style() == Style::Oblique
}

/// Returns face style.
Expand Down Expand Up @@ -1490,10 +1480,13 @@ impl<'a> Face<'a> {

/// Returns face's italic angle.
///
/// Returns `None` when `post` table is not present.
/// Returns `0.0` when `post` table is not present.
#[inline]
pub fn italic_angle(&self) -> Option<f32> {
self.tables.post.map(|table| table.italic_angle)
pub fn italic_angle(&self) -> f32 {
self.tables
.post
.map(|table| table.italic_angle)
.unwrap_or(0.0)
}

// Read https://github.com/freetype/freetype/blob/49270c17011491227ec7bd3fb73ede4f674aa065/src/sfnt/sfobjs.c#L1279
Expand Down

0 comments on commit 1eba570

Please sign in to comment.