-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[test-data] Add FEA-based test file generation
This adds support in the font-test-data crate for compiling fonts using FEA (instead of TTX) as the 'source of truth'. This is motivated by wanting to test glyph closure, where FEA is a much more manageable and intelligible source than TTX.
- Loading branch information
Showing
6 changed files
with
97 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import sys | ||
import os | ||
|
||
from fontTools.ttLib import TTFont | ||
|
||
from fontTools.feaLib.builder import addOpenTypeFeatures | ||
|
||
def makeTTFont(glyph_list_path): | ||
glyphs = get_glyph_list(glyph_list_path) | ||
font = TTFont() | ||
font.setGlyphOrder(glyphs) | ||
return font | ||
|
||
def get_glyph_list(path): | ||
with open(path) as f: | ||
lines = f.read().splitlines() | ||
return [l for l in lines if not l.startswith("#")] | ||
|
||
def main(): | ||
try: | ||
fea_path = sys.argv[1] | ||
out_path = sys.argv[2] | ||
except IndexError: | ||
print("Usage: compile_fea.py <fea_file> <out_file>") | ||
sys.exit(1) | ||
|
||
|
||
if not os.path.exists(fea_path): | ||
print("Feature file not found: " + fea_path) | ||
sys.exit(1) | ||
glyph_list_path = os.path.splitext(fea_path)[0] + "_glyphs.txt" | ||
if not os.path.exists(glyph_list_path): | ||
print("Glyph list file not found: " + glyph_list_path) | ||
sys.exit(1) | ||
|
||
font = makeTTFont((glyph_list_path)) | ||
addOpenTypeFeatures(font, fea_path) | ||
# if you want to manually inspect you can dump as TTX: | ||
# font.saveXML(out_path, tables=[ 'GDEF', 'GSUB', 'GPOS']) | ||
font.save(out_path) | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
feature test { | ||
lookup single_sub_f1 { | ||
sub a by A; | ||
} single_sub_f1; | ||
|
||
lookup single_sub_f2 { | ||
sub a by b; | ||
# just to force format 2 | ||
sub X by Y; | ||
} single_sub_f2; | ||
|
||
lookup multiple_sub { | ||
sub a by c d; | ||
} multiple_sub; | ||
|
||
lookup lig_sub { | ||
sub a a by a_a; | ||
} lig_sub; | ||
|
||
lookup alt_sub { | ||
sub a from [a.1 a.2]; | ||
} alt_sub; | ||
} test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
a | ||
b | ||
c | ||
d | ||
A | ||
a_a | ||
a.1 | ||
a.2 | ||
X | ||
Y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.