Skip to content

Commit

Permalink
Flip misnamed is_bitmap_embedding_allowed function.
Browse files Browse the repository at this point in the history
Increase lenience of embed permissions for older OS/2 versions.
  • Loading branch information
Fuzzyzilla committed Jan 1, 2024
1 parent 8140832 commit f892c83
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 17 deletions.
11 changes: 7 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1709,7 +1709,7 @@ impl<'a> Face<'a> {
self.tables.os2?.permissions()
}

/// Checks if the face subsetting is allowed.
/// Checks if the face allows embedding a subset, further restricted by [`Self::permissions`].
#[inline]
pub fn is_subsetting_allowed(&self) -> bool {
self.tables
Expand All @@ -1718,12 +1718,15 @@ impl<'a> Face<'a> {
.unwrap_or(false)
}

/// Checks if the face bitmaps embedding is allowed.
/// Checks if the face allows outline data to be embedded.
/// If false, only bitmaps may be embedded in accordance with [`Self::permissions`].
///
/// If the font contains no bitmaps and this flag is not set, it implies no embedding is allowed.
#[inline]
pub fn is_bitmap_embedding_allowed(&self) -> bool {
pub fn is_outline_embedding_allowed(&self) -> bool {
self.tables
.os2
.map(|t| t.is_bitmap_embedding_allowed())
.map(|t| t.is_outline_embedding_allowed())
.unwrap_or(false)
}

Expand Down
56 changes: 43 additions & 13 deletions src/tables/os2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,27 +424,57 @@ impl<'a> Table<'a> {
#[inline]
pub fn permissions(&self) -> Option<Permissions> {
let n = Stream::read_at::<u16>(self.data, TYPE_OFFSET).unwrap_or(0);
match n & 0xF {
0 => Some(Permissions::Installable),
2 => Some(Permissions::Restricted),
4 => Some(Permissions::PreviewAndPrint),
8 => Some(Permissions::Editable),
_ => None,
if self.version <= 2 {
// Version 2 and prior, applications are allowed to take
// the most permissive of provided flags
let permission = if n & 0xF == 0 {
Permissions::Installable
} else if n & 8 != 0 {
Permissions::Editable
} else if n & 4 != 0 {
Permissions::PreviewAndPrint
} else {
Permissions::Restricted
};

Some(permission)
} else {
// Version 3 onwards, flags must be mutually exclusive.
match n & 0xF {
0 => Some(Permissions::Installable),
2 => Some(Permissions::Restricted),
4 => Some(Permissions::PreviewAndPrint),
8 => Some(Permissions::Editable),
_ => None,
}
}
}

/// Checks if the face subsetting is allowed.
/// Checks if the face allows embedding a subset, further restricted by [`Self::permissions`].
#[inline]
pub fn is_subsetting_allowed(&self) -> bool {
let n = Stream::read_at::<u16>(self.data, TYPE_OFFSET).unwrap_or(0);
n & 0x0100 == 0
if self.version <= 1 {
// Flag introduced in version 2
true
} else {
let n = Stream::read_at::<u16>(self.data, TYPE_OFFSET).unwrap_or(0);
n & 0x0100 == 0
}
}

/// Checks if the face bitmaps embedding is allowed.
/// Checks if the face allows outline data to be embedded.
/// If false, only bitmaps may be embedded in accordance with [`Self::permissions`].
///
/// If the font contains no bitmaps and this flag is not set, it implies no embedding is allowed.
#[inline]
pub fn is_bitmap_embedding_allowed(&self) -> bool {
let n = Stream::read_at::<u16>(self.data, TYPE_OFFSET).unwrap_or(0);
n & 0x0200 == 0
pub fn is_outline_embedding_allowed(&self) -> bool {
if self.version <= 1 {
// Flag introduced in version 2
true
} else {
let n = Stream::read_at::<u16>(self.data, TYPE_OFFSET).unwrap_or(0);
n & 0x0200 == 0
}
}

/// Returns subscript metrics.
Expand Down

0 comments on commit f892c83

Please sign in to comment.