Skip to content

Commit

Permalink
[read-fonts] Only inspect reachable lookups for closure
Browse files Browse the repository at this point in the history
Previously we just looked at every lookup in the lookup list when
computing the closure. This sounds okay at first glance, but it
overlooks the fact that the lookup list can include lookups that are
only reachable via other contextual lookups.

This introduces a much more rigorous approach, where on each run we
recalculate the set of reachable lookups, by checking to see if the
current set of glyphs matches any (chain) contextual rules, and then
adding the appropriate lookups from those rules.
  • Loading branch information
cmyr committed Feb 9, 2024
1 parent c06a28b commit aa290fc
Show file tree
Hide file tree
Showing 8 changed files with 379 additions and 5 deletions.
7 changes: 7 additions & 0 deletions font-test-data/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ pub mod closure {
pub static RECURSIVE: &[u8] = include_bytes!("../test_data/ttf/recursive_closure.ttf");
pub static RECURSIVE_GLYPHS: &str =
include_str!("../test_data/fea/recursive_closure_glyphs.txt");
pub static CONTEXTUAL: &[u8] = include_bytes!("../test_data/ttf/context_closure.ttf");
pub static CONTEXTUAL_GLYPHS: &str =
include_str!("../test_data/fea/context_closure_glyphs.txt");
pub static RECURSIVE_CONTEXTUAL: &[u8] =
include_bytes!("../test_data/ttf/recursive_context_closure.ttf");
pub static RECURSIVE_CONTEXTUAL_GLYPHS: &str =
include_str!("../test_data/fea/recursive_context_closure_glyphs.txt");
}

pub mod post {
Expand Down
28 changes: 28 additions & 0 deletions font-test-data/test_data/fea/context_closure.fea
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
feature SUB6 {
lookup GSUB6f1 {
sub one two three' four' five six seven by X;
sub two one three' four' six five seven by Y;
} GSUB6f1;

# format 2 is generally less efficient than format 3 and hard to generate
# (as in, I'm not aware of any input that will compile to format 2)
lookup GSUB6f3 {
sub [space comma semicolon] e' by e.2;
} GSUB6f3;
} SUB6;

# can't declare in a feature or it gets added to the feature
lookup MY_RULES {
sub f by f.2;
} MY_RULES;

feature SUB5 {
lookup GSUB5f1 {
sub a' b' by a_b;
sub c' d' by c_d;
} GSUB5f1;

lookup GSUB5f3 {
sub f' lookup MY_RULES g';
} GSUB5f3;
} SUB5;
24 changes: 24 additions & 0 deletions font-test-data/test_data/fea/context_closure_glyphs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.notdef
space
comma
semicolon
one
two
three
four
five
six
seven
X
Y
a
b
c
d
e
f
g
e.2
f.2
a_b
c_d
12 changes: 12 additions & 0 deletions font-test-data/test_data/fea/recursive_context_closure.fea
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
feature test {

lookup first {
sub a b' c by B;
sub a B.2' by B.3;
} first;

lookup second {
sub a B' c by B.2;
} second;

} test;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
a
b
c
B
B.2
B.3
Binary file added font-test-data/test_data/ttf/context_closure.ttf
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit aa290fc

Please sign in to comment.