Merge pull request #3659 from fonttools/issue-3658
[removeOverlaps] Fix CFF CharString width
This commit is contained in:
commit
e2c22371d5
@ -87,7 +87,11 @@ def ttfGlyphFromSkPath(path: pathops.Path) -> _g_l_y_f.Glyph:
|
|||||||
def _charString_from_SkPath(
|
def _charString_from_SkPath(
|
||||||
path: pathops.Path, charString: T2CharString
|
path: pathops.Path, charString: T2CharString
|
||||||
) -> 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)
|
path.draw(t2Pen)
|
||||||
return t2Pen.getCharString(charString.private, charString.globalSubrs)
|
return t2Pen.getCharString(charString.private, charString.globalSubrs)
|
||||||
|
|
||||||
|
BIN
Tests/ttLib/data/IBMPlexSans-Bold.subset.otf
Normal file
BIN
Tests/ttLib/data/IBMPlexSans-Bold.subset.otf
Normal file
Binary file not shown.
@ -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]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user