Skip to content

Commit

Permalink
Make use of jump_take!
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanUkhov committed Aug 18, 2023
1 parent bf9a955 commit 712a4ad
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 21 deletions.
15 changes: 5 additions & 10 deletions src/compact1/font_set/character_id_keyed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,10 @@ impl<'l> Walue<'l> for Record {
_ => raise!("found a malformed character-ID-keyed record"),
};
let offset = get!(@single top_operations, FDSelect);
tape.jump(position + offset as u64)?;
let encoding = tape.take_given(character_strings)?;
let encoding = jump_take_given!(@unwrap tape, position, offset, character_strings);
let offset = get!(@single top_operations, FDArray);
tape.jump(position + offset as u64)?;
let operations: Vec<_> = (&tape.take::<Dictionaries>()?).try_into()?;
let operations: Dictionaries = jump_take!(@unwrap tape, position, offset);
let operations: Vec<_> = (&operations).try_into()?;
let mut records = vec![];
for top_operations in operations.iter() {
records.push(tape.take_given((position, top_operations))?);
Expand All @@ -100,14 +99,10 @@ impl<'l> Walue<'l> for RecordInner {

fn read<T: Tape>(tape: &mut T, (position, top_operations): Self::Parameter) -> Result<Self> {
let (size, offset) = get!(@double top_operations, Private);
tape.jump(position + offset as u64)?;
let chunk = tape.take_given::<Vec<u8>>(size as usize)?;
let chunk: Vec<u8> = jump_take_given!(@unwrap tape, position, offset, size as usize);
let operations = Cursor::new(chunk).take::<Operations>()?;
let subroutines = match get!(@try @single operations, Subrs) {
Some(another_offset) => {
tape.jump(position + offset as u64 + another_offset as u64)?;
tape.take()?
}
Some(another_offset) => jump_take!(@unwrap tape, position, offset + another_offset),
_ => Default::default(),
};
Ok(Self {
Expand Down
13 changes: 3 additions & 10 deletions src/compact1/font_set/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ impl Value for FontSet {
fn read<T: Tape>(tape: &mut T) -> Result<Self> {
let position = tape.position()?;
let header = tape.take::<Header>()?;
tape.jump(position + header.header_size as u64)?;
let names = tape.take::<Names>()?;
let names: Names = jump_take!(@unwrap tape, position, header.header_size);
let operations: Vec<_> = (&tape.take::<Dictionaries>()?).try_into()?;
let strings = tape.take::<Strings>()?;
let subroutines = tape.take::<Subroutines>()?;
Expand All @@ -74,18 +73,12 @@ impl Value for FontSet {
0 => CharacterSet::ISOAdobe,
1 => CharacterSet::Expert,
2 => CharacterSet::ExpertSubset,
offset => {
tape.jump(position + offset as u64)?;
tape.take_given(character_strings[i].count as usize)?
}
offset => jump_take_given!(@unwrap tape, position, offset, character_strings[i].count as usize),
});
encodings.push(match get!(@single operations, Encoding) {
0 => Encoding::Standard,
1 => Encoding::Expert,
offset => {
tape.jump(position + offset as u64)?;
tape.take()?
}
offset => jump_take!(@unwrap tape, position, offset),
});
records.push(tape.take_given((position, operations, &character_strings[i]))?);
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Parser for PostScript fonts.

#[macro_use(dereference, raise, table)]
#[macro_use(dereference, jump_take, jump_take_given, raise, table)]
extern crate typeface;

pub mod compact1;
Expand Down

0 comments on commit 712a4ad

Please sign in to comment.