From 1eba570e0802892855ebc41a0ea04279103e5987 Mon Sep 17 00:00:00 2001 From: Yevhenii Reizner Date: Tue, 3 Sep 2024 10:57:25 +0300 Subject: [PATCH] Check for italic angle in `Face::is_italic`. --- CHANGELOG.md | 3 +++ src/lib.rs | 27 ++++++++++----------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b27b56..bd21235 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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` now. ## [0.24.1] - 2024-08-05 ### Added diff --git a/src/lib.rs b/src/lib.rs index f0d5f36..fc80ba3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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*. @@ -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. @@ -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 { - 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