Merge pull request #3659 from fonttools/issue-3658

[removeOverlaps] Fix CFF CharString width
This commit is contained in:
خالد حسني (Khaled Hosny) 2024-10-12 10:57:02 +03:00 committed by GitHub
commit e2c22371d5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 2 deletions

View File

@ -87,7 +87,11 @@ def ttfGlyphFromSkPath(path: pathops.Path) -> _g_l_y_f.Glyph:
def _charString_from_SkPath(
path: pathops.Path, charString: T2CharString
) -> T2CharString:
t2Pen = T2CharStringPen(width=charString.width, glyphSet=None)
if charString.width == charString.private.defaultWidthX:
width = None
else:
width = charString.width - charString.private.nominalWidthX
t2Pen = T2CharStringPen(width=width, glyphSet=None)
path.draw(t2Pen)
return t2Pen.getCharString(charString.private, charString.globalSubrs)

Binary file not shown.

View File

@ -1,9 +1,13 @@
import logging
import pytest
from pathlib import Path
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):
@ -49,3 +53,21 @@ def test_pathops_simplify_bug_workaround(caplog):
expected.close()
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]