[removeOverlaps] Add test for handling CFF.Private.nominalWidthX

The test currently fails because we don’t take CFF.Private.nominalWidthX
into account when creating new CharString after overlap removal.
This commit is contained in:
Khaled Hosny 2024-10-12 01:14:48 +03:00
parent e8146a6d07
commit f7ecc6fe65
2 changed files with 23 additions and 1 deletions

Binary file not shown.

View File

@ -1,9 +1,13 @@
import logging import logging
import pytest import pytest
from pathlib import Path
pathops = pytest.importorskip("pathops") pathops = pytest.importorskip("pathops")
from fontTools.ttLib.removeOverlaps import _simplify, _round_path from fontTools.ttLib import TTFont
from fontTools.ttLib.removeOverlaps import removeOverlaps, _simplify, _round_path
DATA_DIR = Path(__file__).parent / "data"
def test_pathops_simplify_bug_workaround(caplog): def test_pathops_simplify_bug_workaround(caplog):
@ -49,3 +53,21 @@ def test_pathops_simplify_bug_workaround(caplog):
expected.close() expected.close()
assert expected == _round_path(result, round=lambda v: round(v, 3)) assert expected == _round_path(result, round=lambda v: round(v, 3))
def test_CFF_CharString_width_nominalWidthX():
font_path = DATA_DIR / "IBMPlexSans-Bold.subset.otf"
font = TTFont(str(font_path))
assert font["hmtx"]["OE"][0] == 998
# calcBounds() has the side effect of setting the width attribute
font["CFF "].cff[0].CharStrings["OE"].calcBounds({})
assert font["CFF "].cff[0].CharStrings["OE"].width == font["hmtx"]["OE"][0]
removeOverlaps(font)
assert font["hmtx"]["OE"][0] == 998
font["CFF "].cff[0].CharStrings["OE"].calcBounds({})
assert font["CFF "].cff[0].CharStrings["OE"].width == font["hmtx"]["OE"][0]