Skip to content

Commit

Permalink
Enable old gpos spec tests
Browse files Browse the repository at this point in the history
These had been disabled way back when because we didn't support device
tables. We do now, so we might as well make these work again.
  • Loading branch information
cmyr authored and dfrg committed Nov 9, 2023
1 parent 1d49b0d commit d04b9bb
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 72 deletions.
4 changes: 2 additions & 2 deletions read-fonts/src/tables/gpos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ pub use super::layout::{
pub use value_record::ValueRecord;

#[cfg(test)]
#[path = "../tests/gpos.rs"]
mod tests;
#[path = "../tests/test_gpos.rs"]
mod spec_tests;

include!("../../generated/generated_gpos.rs");

Expand Down
86 changes: 51 additions & 35 deletions read-fonts/src/tests/gpos.rs → read-fonts/src/tests/test_gpos.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::tables::layout::DeltaFormat;

use super::*;
use font_test_data::gpos as test_data;

Expand Down Expand Up @@ -194,25 +196,32 @@ fn sequencelookuprecord() {
assert_eq!(record.lookup_list_index(), 1);
}

//FIXME: turn this back on when we support device records
//#[test]
//fn valueformattable() {
// // https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#example-14-valueformat-table-and-valuerecord

//#[rustfmt::skip]
//let bytes = [
//0x00, 0x01, 0x00, 0x0E, 0x00, 0x99, 0x00, 0x50, 0x00, 0xD2,
//0x00, 0x18, 0x00, 0x20, 0x00, 0x02, 0x00, 0x01, 0x00, 0xC8,
//0x00, 0xD1, 0x00, 0x00, 0x00, 0x0B, 0x00, 0x0F, 0x00, 0x01,
//0x55, 0x40, 0x00, 0x0B, 0x00, 0x0F, 0x00, 0x01, 0x55, 0x40,
//];

//let table = SinglePosFormat1::read(&bytes).unwrap();
//let owned = table.to_owned_table().unwrap();
//let dumped = crate::write::dump_table(&owned);
#[test]
fn valueformattable() {
// https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#example-14-valueformat-table-and-valuerecord

//assert_hex_eq!(&bytes, &dumped);
//}
let table = SinglePosFormat1::read(test_data::VALUEFORMATTABLE.into()).unwrap();
assert_eq!(
table.value_format(),
ValueFormat::X_PLACEMENT
| ValueFormat::Y_ADVANCE
| ValueFormat::X_PLACEMENT_DEVICE
| ValueFormat::Y_ADVANCE_DEVICE
);
let record = table.value_record();
assert_eq!(record.y_advance(), Some(210));
let DeviceOrVariationIndex::Device(device) = record
.y_advance_device(table.offset_data())
.unwrap()
.unwrap()
else {
panic!("not a device");
};

assert_eq!((device.start_size(), device.end_size()), (11, 15));
assert_eq!(device.delta_format(), DeltaFormat::Local2BitDeltas);
assert_eq!(device.delta_value(), [0x5540]);
}

#[test]
fn anchorformat1() {
Expand All @@ -232,24 +241,31 @@ fn anchorformat2() {
assert_eq!(table.anchor_point(), 13);
}

//FIXME: enable when we have device tables working
//#[test]
//fn anchorformat3() {
// // https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#example-17-anchorformat3-table

//let bytes = [
//0x00, 0x03, 0x01, 0x17, 0x05, 0x15, 0x00, 0x0A, 0x00, 0x14,
//0x00, 0x0C, 0x00, 0x11, 0x00, 0x02, 0x11, 0x11, 0x22, 0x00,
//0x00, 0x0C, 0x00, 0x11, 0x00, 0x02, 0x11, 0x11, 0x22, 0x00,
//];
//let table = AnchorFormat3::read(&bytes).unwrap();
//let owned = table.to_owned_obj(&[]).unwrap();
//let dumped = crate::write::dump_table(&owned);
#[test]
fn anchorformat3() {
// https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#example-17-anchorformat3-table

//assert_hex_eq!(&bytes, &dumped);
//}
let table = AnchorFormat3::read(test_data::ANCHORFORMAT3.into()).unwrap();
assert_eq!(table.x_coordinate(), 279);
assert_eq!(table.y_coordinate(), 1301);

let x_dev = table.x_device().unwrap().unwrap();
let y_dev = table.y_device().unwrap().unwrap();

let (DeviceOrVariationIndex::Device(x_dev), DeviceOrVariationIndex::Device(y_dev)) =
(x_dev, y_dev)
else {
panic!("missing device tables");
};

assert_eq!(x_dev.delta_format(), DeltaFormat::Local4BitDeltas);
assert_eq!(x_dev.delta_value(), [0x1111, 0x2200]);

assert_eq!(y_dev.delta_format(), DeltaFormat::Local4BitDeltas);
assert_eq!(y_dev.delta_value(), [0x1111, 0x2200]);
}

//NOTE: I think the sample bites are missing the actual anchor tables??
//NOTE: I think the sample bytes are missing the actual anchor tables??
// and so we can't really round-trip this...
//#[test]
//fn markarraytable() {
Expand All @@ -261,4 +277,4 @@ fn anchorformat2() {
//let dumped = crate::write::dump_table(&owned);

//assert_hex_eq!(&bytes, &dumped);
//}
//}[1, 1, 1, 1, 1]
53 changes: 18 additions & 35 deletions write-fonts/src/tests/test_gpos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,25 +131,15 @@ fn contextualposformat3() {
assert_hex_eq!(test_data::CONTEXTUALPOSFORMAT3, &dumped);
}

//FIXME: turn this back on when we support device records
//#[test]
//fn valueformattable() {
// // https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#example-14-valueformat-table-and-valuerecord

//#[rustfmt::skip]
//let bytes = [
//0x00, 0x01, 0x00, 0x0E, 0x00, 0x99, 0x00, 0x50, 0x00, 0xD2,
//0x00, 0x18, 0x00, 0x20, 0x00, 0x02, 0x00, 0x01, 0x00, 0xC8,
//0x00, 0xD1, 0x00, 0x00, 0x00, 0x0B, 0x00, 0x0F, 0x00, 0x01,
//0x55, 0x40, 0x00, 0x0B, 0x00, 0x0F, 0x00, 0x01, 0x55, 0x40,
//];

//let table = SinglePosFormat1::read(&bytes).unwrap();
//let table = table.to_owned_table().unwrap();
//let dumped = crate::write::dump_table(&table).unwrap();

//assert_hex_eq!(&bytes, &dumped);
//}
#[test]
fn valueformattable() {
// https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#example-14-valueformat-table-and-valuerecord
let table = SinglePosFormat1::read(test_data::VALUEFORMATTABLE.into()).unwrap();
let dumped = crate::write::dump_table(&table).unwrap();
let read_back = SinglePosFormat1::read(dumped.as_slice().into()).unwrap();
// we can't compare bytes because we deduplicate the device tables
assert_eq!(table, read_back);
}

#[test]
fn anchorformat1() {
Expand All @@ -174,22 +164,15 @@ fn anchorformat2() {
assert_hex_eq!(test_data::ANCHORFORMAT2, &dumped);
}

//FIXME: enable when we have device tables working
//#[test]
//fn anchorformat3() {
// // https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#example-17-anchorformat3-table

//let bytes = [
//0x00, 0x03, 0x01, 0x17, 0x05, 0x15, 0x00, 0x0A, 0x00, 0x14,
//0x00, 0x0C, 0x00, 0x11, 0x00, 0x02, 0x11, 0x11, 0x22, 0x00,
//0x00, 0x0C, 0x00, 0x11, 0x00, 0x02, 0x11, 0x11, 0x22, 0x00,
//];
//let table = AnchorFormat3::read(&bytes).unwrap();
//let table = table.to_owned_obj(&[]).unwrap();
//let dumped = crate::write::dump_table(&table).unwrap();

//assert_hex_eq!(&bytes, &dumped);
//}
#[test]
fn anchorformat3() {
// https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#example-17-anchorformat3-table
let table = AnchorFormat3::read(test_data::ANCHORFORMAT3.into()).unwrap();
let dumped = crate::write::dump_table(&table).unwrap();
let read_back = AnchorFormat3::read(dumped.as_slice().into()).unwrap();
// we can't compare bytes since we deduplicate the device tables on write
assert_eq!(table, read_back)
}

// not from the spec; this is a general test that we don't write out versioned
// fields inappropriately.
Expand Down

0 comments on commit d04b9bb

Please sign in to comment.