Skip to content

Commit

Permalink
A test
Browse files Browse the repository at this point in the history
  • Loading branch information
rsheeter committed Oct 30, 2023
1 parent e364c40 commit e722100
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 7 deletions.
6 changes: 2 additions & 4 deletions fontbe/src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,6 @@ impl<'a> FeatureWriter<'a> {
let mut mark_base_lookups = Vec::new();
let mut mark_mark_lookups = Vec::new();

eprintln!("{mark_groups:#?}");

for (group_name, group) in mark_groups.iter() {
let mark_class_name: SmolStr = format!("MC_{group_name}").into();

Expand All @@ -357,7 +355,7 @@ impl<'a> FeatureWriter<'a> {
for (base_name, base_anchor) in group.bases.iter() {
let Some(base_gid) = self.glyph_id(base_name) else {
return Err(Error::MissingGlyphId(base_name.clone()));
};
};
let mark_class: SmolStr = format!("MC_{}", base_anchor.name).into();

let mut mark_base = MarkToBaseBuilder::default();
Expand Down Expand Up @@ -458,7 +456,7 @@ impl<'a> FeatureWriter<'a> {
let (y, y_deltas) = self.resolve_variable_metric(&y_values)?;
let x_var_idx = (!x_deltas.is_empty()).then(|| builder.add_deltas(x_deltas));
let y_var_idx = (!y_deltas.is_empty()).then(|| builder.add_deltas(y_deltas));
eprintln!("x,y {x},{y} for {anchor:?}");

if x_var_idx.is_some() || y_var_idx.is_some() {
Ok(AnchorTable::format_3(
x,
Expand Down
80 changes: 77 additions & 3 deletions fontc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,11 @@ mod tests {
use pretty_assertions::assert_eq;

use read_fonts::{
tables::{name::Name, os2::SelectionFlags},
tables::{
gpos::{AnchorTable, PositionLookup},
name::Name,
os2::SelectionFlags,
},
types::NameId,
};
use skrifa::{
Expand Down Expand Up @@ -2029,18 +2033,88 @@ mod tests {
);
}

fn anchor_coords(at: AnchorTable) -> (i32, i32) {
match at {
AnchorTable::Format1(at) => (at.x_coordinate() as i32, at.y_coordinate() as i32),
AnchorTable::Format2(at) => (at.x_coordinate() as i32, at.y_coordinate() as i32),
AnchorTable::Format3(at) => (at.x_coordinate() as i32, at.y_coordinate() as i32),
}
}

#[test]
fn compile_basic_gpos_mark_base() {
let temp_dir = tempdir().unwrap();
let build_dir = temp_dir.path();
compile(Args::for_test(build_dir, "glyphs3/WghtVar_Anchors.glyphs"));
let result = compile(Args::for_test(build_dir, "glyphs3/WghtVar_Anchors.glyphs"));

let font_file = build_dir.join("font.ttf");
assert!(font_file.exists());
let buf = fs::read(font_file).unwrap();
let font = FontRef::new(&buf).unwrap();

let gpos = font.gpos().unwrap();


let base_gid = GlyphId::new(result.get_glyph_index("A") as u16);
let macroncomb_gid = GlyphId::new(result.get_glyph_index("macroncomb") as u16);
let brevecomb_gid = GlyphId::new(result.get_glyph_index("brevecomb") as u16);

// If only we had more indirections
let mark_base_lookups: Vec<_> = gpos
.lookup_list()
.iter()
.flat_map(|l| l.lookups().iter().map(|l| l.unwrap()))
.filter_map(|l| match l {
PositionLookup::MarkToBase(mark_base) => Some(mark_base),
_ => None,
})
.flat_map(|mb| mb.subtables().iter().map(|s| s.unwrap()))
.collect();

let bases = mark_base_lookups
.iter()
.flat_map(|mb| mb.base_coverage().unwrap().iter().collect::<Vec<_>>())
.zip(
mark_base_lookups
.iter()
.flat_map(|mb| {
let base_array = mb.base_array().unwrap();
let data = base_array.offset_data();
base_array
.base_records()
.iter()
.map(move |r| (data, r.unwrap()))
})
.flat_map(|(data, b)| b.base_anchors(data).iter().map(|b| b.unwrap().unwrap()))
.map(anchor_coords),
)
.collect::<Vec<_>>();

let marks = mark_base_lookups
.iter()
.flat_map(|mb| mb.mark_coverage().unwrap().iter().collect::<Vec<_>>())
.zip(
mark_base_lookups
.iter()
.flat_map(|mb| {
let mark_array = mb.mark_array().unwrap();
let data = mark_array.offset_data();
mb.mark_array()
.unwrap()
.mark_records()
.iter()
.map(move |mr| (data, mr))
})
.map(|(data, mr)| mr.mark_anchor(data).unwrap())
.map(anchor_coords),
)
.collect::<Vec<_>>();

assert_eq!(
(
vec![(base_gid, (300, 700))],
vec![(macroncomb_gid, (300, 600)), (brevecomb_gid, (200, 500))]
),
(bases, marks)
);
}
}

0 comments on commit e722100

Please sign in to comment.