Skip to content

Commit 29a304b

Browse files
committed
Fix the number encoding in Type 2
1 parent e2ed35e commit 29a304b

4 files changed

Lines changed: 39 additions & 4 deletions

File tree

src/type2/number.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::Result;
22

3-
const FIXED_SCALING: f32 = 1f32 / (1 << 16) as f32;
3+
const SCALE: f32 = (1 << 16) as f32;
44

55
pub fn read<T: crate::tape::Read>(tape: &mut T) -> Result<f32> {
66
let first = tape.take::<u8>()?;
@@ -9,7 +9,7 @@ pub fn read<T: crate::tape::Read>(tape: &mut T) -> Result<f32> {
99
0xf7..=0xfa => ((first as i32 - 247) * 256 + tape.take::<u8>()? as i32 + 108) as f32,
1010
0xfb..=0xfe => (-(first as i32 - 251) * 256 - tape.take::<u8>()? as i32 - 108) as f32,
1111
0x1c => tape.take::<u16>()? as i16 as i32 as f32,
12-
0xff => FIXED_SCALING * (tape.take::<u32>()? as f32),
12+
0xff => (tape.take::<i32>()? as f32) / SCALE,
1313
_ => raise!("found a malformed number"),
1414
})
1515
}
133 KB
Binary file not shown.

tests/support/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ use postscript::value::Read;
1010
macro_rules! ok(($result:expr) => ($result.unwrap()));
1111

1212
pub enum Fixture {
13+
Hirakatana,
1314
NotoSansJP,
1415
SourceSerifPro,
1516
}
1617

1718
impl Fixture {
1819
pub fn path(&self) -> PathBuf {
1920
let file_name = match *self {
21+
Fixture::Hirakatana => "Hirakatana-Regular.otf",
2022
Fixture::NotoSansJP => "NotoSansJP-Regular.otf",
2123
Fixture::SourceSerifPro => "SourceSerifPro-Regular.otf",
2224
};
@@ -25,6 +27,7 @@ impl Fixture {
2527

2628
pub fn offset(&self) -> u64 {
2729
match *self {
30+
Fixture::Hirakatana => 1524,
2831
Fixture::NotoSansJP => 337316,
2932
Fixture::SourceSerifPro => 17732,
3033
}

tests/type2.rs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,46 @@ macro_rules! operations(
1010
});
1111
);
1212

13+
mod hirakatana {
14+
use postscript::compact1::font_set::Record;
15+
use postscript::type2::Program;
16+
17+
use crate::support::{setup_font_set, Fixture};
18+
19+
#[test]
20+
fn one() {
21+
let set = setup_font_set(Fixture::Hirakatana);
22+
let code = &set.character_strings[0][10];
23+
let global = &set.subroutines;
24+
let local = match &set.records[0] {
25+
Record::CharacterNameKeyed(ref record) => &*record.subroutines,
26+
_ => unreachable!(),
27+
};
28+
let mut program = Program::new(code, global, local);
29+
let mut operations = vec![];
30+
while let Some(operation) = ok!(program.next()) {
31+
operations.push(operation);
32+
}
33+
assert_eq!(
34+
operations,
35+
operations!(
36+
HStem: [372.0, 57.933594],
37+
RMoveTo: [42.0, 401.05176],
38+
VLineTo: [-29.051758, 186.59766],
39+
RLineTo: [186.59668, 0.0, -0.18261719, 28.88086, -0.18261719, 28.88086, -186.41504, 0.171875, -186.41406, 0.17089844],
40+
)
41+
);
42+
}
43+
}
44+
1345
mod source_serif {
1446
use postscript::compact1::font_set::Record;
1547
use postscript::type2::Program;
1648

1749
use crate::support::{setup_font_set, Fixture};
1850

1951
#[test]
20-
fn program_all() {
52+
fn all() {
2153
let set = setup_font_set(Fixture::SourceSerifPro);
2254
let global = &set.subroutines;
2355
let local = match &set.records[0] {
@@ -31,7 +63,7 @@ mod source_serif {
3163
}
3264

3365
#[test]
34-
fn program_one() {
66+
fn one() {
3567
let set = setup_font_set(Fixture::SourceSerifPro);
3668
let code = &set.character_strings[0][134];
3769
let global = &set.subroutines;

0 commit comments

Comments
 (0)