Skip to content

Commit

Permalink
Open up Font::position
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanUkhov committed Feb 2, 2024
1 parent 1935f7c commit 5be7bfa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "opentype"
version = "0.34.1"
version = "0.34.2"
edition = "2021"
license = "Apache-2.0/MIT"
authors = [
Expand Down
39 changes: 20 additions & 19 deletions src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,26 @@ impl Font {
self.offsets.records.iter().any(|record| record.tag == tag)
}

/// Jump to the position of the table.
pub fn position<T, U>(&self, tape: &mut T) -> Result<Option<()>>
where
T: crate::tape::Read,
U: Table,
{
let tag = U::tag();
for record in &self.offsets.records {
if record.tag == tag {
#[cfg(not(feature = "ignore-invalid-checksums"))]
if record.checksum != record.checksum(tape)? {
raise!("found a malformed font table with {:?}", record.tag);
}
Read::jump(tape, record.offset as u64)?;
return Ok(Some(()));
}
}
Ok(None)
}

/// Read a table.
#[inline]
pub fn take<T, U>(&self, tape: &mut T) -> Result<Option<U>>
Expand All @@ -48,25 +68,6 @@ impl Font {
.map(|_| tape.take_given::<U>(parameter))
.transpose()
}

fn position<T, U>(&self, tape: &mut T) -> Result<Option<()>>
where
T: crate::tape::Read,
U: Table,
{
let tag = U::tag();
for record in &self.offsets.records {
if record.tag == tag {
#[cfg(not(feature = "ignore-invalid-checksums"))]
if record.checksum != record.checksum(tape)? {
raise!("found a malformed font table with {:?}", record.tag);
}
Read::jump(tape, record.offset as u64)?;
return Ok(Some(()));
}
}
Ok(None)
}
}

impl crate::value::Read for Font {
Expand Down

0 comments on commit 5be7bfa

Please sign in to comment.