Skip to content

Commit

Permalink
Merge pull request #164 from LaurenzV/fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
RazrFalcon committed Jul 13, 2024
2 parents 13ab167 + 949d179 commit 85c1ff2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
19 changes: 19 additions & 0 deletions src/tables/glyf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,25 @@ impl<'a> Table<'a> {
outline_impl(self.loca_table, self.data, glyph_data, 0, &mut b)?
}

/// The bounding box of the glyph. Unlike the `outline` method, this method does not
/// calculate the bounding box manually by outlining the glyph, but instead uses the
/// bounding box in the `glyf` program. As a result, this method will be much faster,
/// but the bounding box could be more inaccurate.
#[inline]
pub fn bbox(&self, glyph_id: GlyphId) -> Option<Rect> {
let glyph_data = self.get(glyph_id)?;

let mut s = Stream::new(glyph_data);
// number of contours
let _ = s.read::<i16>()?;
Some(Rect {
x_min: s.read::<i16>()?,
y_min: s.read::<i16>()?,
x_max: s.read::<i16>()?,
y_max: s.read::<i16>()?,
})
}

#[inline]
pub(crate) fn get(&self, glyph_id: GlyphId) -> Option<&'a [u8]> {
let range = self.loca_table.glyph_range(glyph_id)?;
Expand Down
4 changes: 2 additions & 2 deletions src/tables/gpos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ pub struct AnchorMatrix<'a> {
pub rows: u16,
/// Number of columns in the matrix.
pub cols: u16,
matrix: LazyArray32<'a, Offset16>,
matrix: LazyArray32<'a, Option<Offset16>>,
}

impl<'a> AnchorMatrix<'a> {
Expand All @@ -909,7 +909,7 @@ impl<'a> AnchorMatrix<'a> {
/// Returns an [`Anchor`] at position.
pub fn get(&self, row: u16, col: u16) -> Option<Anchor> {
let idx = u32::from(row) * u32::from(self.cols) + u32::from(col);
let offset = self.matrix.get(idx)?.to_usize();
let offset = self.matrix.get(idx)??.to_usize();
Anchor::parse(self.data.get(offset..)?)
}
}
Expand Down

0 comments on commit 85c1ff2

Please sign in to comment.