Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor refactor: use built-in option methods instead of try_for_opt! macro #140

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,6 @@ Font parsing starts with a [`Face`].
#[macro_use]
extern crate std;

macro_rules! try_opt_or {
($value:expr, $ret:expr) => {
match $value {
Some(v) => v,
None => return $ret,
}
};
}

#[cfg(feature = "apple-layout")]
mod aat;
#[cfg(feature = "opentype-layout")]
Expand Down Expand Up @@ -1342,7 +1333,7 @@ impl<'a> Face<'a> {
/// Returns `false` when OS/2 table is not present.
#[inline]
pub fn is_bold(&self) -> bool {
try_opt_or!(self.tables.os2, false).is_bold()
self.tables.os2.map(|os2| os2.is_bold()).unwrap_or(false)
}

/// Checks that face is marked as *Oblique*.
Expand All @@ -1359,15 +1350,18 @@ impl<'a> Face<'a> {
/// Returns face style.
#[inline]
pub fn style(&self) -> Style {
try_opt_or!(self.tables.os2, Style::Normal).style()
self.tables.os2.map(|os2| os2.style()).unwrap_or_default()
}

/// Checks that face is marked as *Monospaced*.
///
/// Returns `false` when `post` table is not present.
#[inline]
pub fn is_monospaced(&self) -> bool {
try_opt_or!(self.tables.post, false).is_monospaced
self.tables
.post
.map(|post| post.is_monospaced)
.unwrap_or(false)
}

/// Checks that face is variable.
Expand All @@ -1392,15 +1386,15 @@ impl<'a> Face<'a> {
/// Returns `Weight::Normal` when OS/2 table is not present.
#[inline]
pub fn weight(&self) -> Weight {
try_opt_or!(self.tables.os2, Weight::default()).weight()
self.tables.os2.map(|os2| os2.weight()).unwrap_or_default()
}

/// Returns face's width.
///
/// Returns `Width::Normal` when OS/2 table is not present or when value is invalid.
#[inline]
pub fn width(&self) -> Width {
try_opt_or!(self.tables.os2, Width::default()).width()
self.tables.os2.map(|os2| os2.width()).unwrap_or_default()
}

/// Returns face's italic angle.
Expand Down
9 changes: 7 additions & 2 deletions src/tables/gvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1626,8 +1626,13 @@ fn infer_delta(
//
// 'Target point delta is derived from the adjacent point deltas
// using linear interpolation.'
let d = f32::from(try_opt_or!(target_point.checked_sub(prev_point), 0.0))
/ f32::from(try_opt_or!(next_point.checked_sub(prev_point), 0.0));
let target_sub = target_point.checked_sub(prev_point);
let next_sub = next_point.checked_sub(prev_point);
let d = if let (Some(target_sub), Some(next_sub)) = (target_sub, next_sub) {
f32::from(target_sub) / f32::from(next_sub)
} else {
return 0.0;
};
(1.0 - d) * prev_delta + d * next_delta
}
}
Expand Down
Loading