Skip to content

Commit

Permalink
Add FontSet::count
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanUkhov committed Feb 2, 2024
1 parent 08f3739 commit 42b4add
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/compact1/font_set/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ pub enum Record {
CharacterNameKeyed(character_name_keyed::Record),
}

impl FontSet {
/// Count the number of records.
pub fn count<T: crate::tape::Read>(tape: &mut T) -> Result<usize> {
let position = tape.position()?;
let header = tape.take::<Header>()?;
let count: u16 = jump_take!(@unwrap tape, position, header.header_size);
Ok(count as usize)
}
}

impl crate::value::Read for FontSet {
fn read<T: crate::tape::Read>(tape: &mut T) -> Result<Self> {
let position = tape.position()?;
Expand Down
12 changes: 9 additions & 3 deletions tests/support/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(dead_code)]

use std::fs::File;
use std::io::{Seek, SeekFrom};
use std::path::PathBuf;
Expand All @@ -7,7 +9,6 @@ use postscript::value::Read;

macro_rules! ok(($result:expr) => ($result.unwrap()));

#[allow(dead_code)]
pub enum Fixture {
NotoSansJP,
SourceSerifPro,
Expand Down Expand Up @@ -37,6 +38,11 @@ pub fn setup(fixture: Fixture) -> File {
}

pub fn setup_font_set(fixture: Fixture) -> FontSet {
let mut file = setup(fixture);
ok!(FontSet::read(&mut file))
let mut file = ok!(File::open(fixture.path()));
ok!(file.seek(SeekFrom::Start(fixture.offset())));
let count = ok!(FontSet::count(&mut file));
ok!(file.seek(SeekFrom::Start(fixture.offset())));
let table = ok!(FontSet::read(&mut file));
assert_eq!(table.operations.len(), count);
table
}

0 comments on commit 42b4add

Please sign in to comment.