fonttools/Tests/otlLib/optimize_test.py
2021-07-05 17:28:44 +01:00

55 lines
1.4 KiB
Python

from pathlib import Path
from subprocess import run
from fontTools.feaLib.builder import addOpenTypeFeaturesFromString
from fontTools.fontBuilder import FontBuilder
def test_main(tmpdir: Path):
"""Check that calling the main function on an input TTF works."""
glyphs = ".notdef space A Aacute B D".split()
features = """
@A = [A Aacute];
@B = [B D];
feature kern {
pos @A @B -50;
} kern;
"""
fb = FontBuilder(1000)
fb.setupGlyphOrder(glyphs)
addOpenTypeFeaturesFromString(fb.font, features)
input = tmpdir / "in.ttf"
fb.save(str(input))
output = tmpdir / "out.ttf"
run(
[
"fonttools",
"otlLib.optimize",
"--gpos-compact-mode",
"5",
str(input),
"-o",
str(output),
],
check=True,
)
assert output.exists()
def test_off_by_default(tmpdir: Path):
"""Check that calling the main function on an input TTF works."""
glyphs = ".notdef space A B".split()
features = """
feature kern {
pos A B -50;
} kern;
"""
fb = FontBuilder(1000)
fb.setupGlyphOrder(glyphs)
addOpenTypeFeaturesFromString(fb.font, features)
input = tmpdir / "in.ttf"
fb.save(str(input))
output = tmpdir / "out.ttf"
run(["fonttools", "otlLib.optimize", str(input), "-o", str(output)], check=True)
assert output.exists()