From 52e3e03ed91c5dedbf6a691f709e50dea20f7e1b Mon Sep 17 00:00:00 2001 From: Nikolaus Waxweiler Date: Thu, 28 Jan 2021 16:27:32 +0000 Subject: [PATCH] An off-curve should stay off even with flags --- Lib/fontTools/ttLib/woff2.py | 4 +- NEWS.rst | 3 + .../ttLib/data/woff2_overlap_offcurve_in.ttx | 306 ++++++++++++++++++ Tests/ttLib/woff2_test.py | 15 + 4 files changed, 326 insertions(+), 2 deletions(-) create mode 100644 Tests/ttLib/data/woff2_overlap_offcurve_in.ttx diff --git a/Lib/fontTools/ttLib/woff2.py b/Lib/fontTools/ttLib/woff2.py index 75b55527c..d088b70f6 100644 --- a/Lib/fontTools/ttLib/woff2.py +++ b/Lib/fontTools/ttLib/woff2.py @@ -11,7 +11,7 @@ from fontTools.ttLib import (TTFont, TTLibError, getTableModule, getTableClass, from fontTools.ttLib.sfnt import (SFNTReader, SFNTWriter, DirectoryEntry, WOFFFlavorData, sfntDirectoryFormat, sfntDirectorySize, SFNTDirectoryEntry, sfntDirectoryEntrySize, calcChecksum) -from fontTools.ttLib.tables import ttProgram +from fontTools.ttLib.tables import ttProgram, _g_l_y_f import logging @@ -934,7 +934,7 @@ class WOFF2GlyfTable(getTableClass('glyf')): flags = array.array('B') triplets = array.array('B') for i in range(len(coordinates)): - onCurve = glyph.flags[i] + onCurve = glyph.flags[i] & _g_l_y_f.flagOnCurve x, y = coordinates[i] absX = abs(x) absY = abs(y) diff --git a/NEWS.rst b/NEWS.rst index e22a0f62d..8ab64cd04 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -1,3 +1,6 @@ +- [woff2] An initial off-curve point with an overlap flag now stays an off-curve + point after compression. + 4.19.0 (released 2021-01-25) ---------------------------- diff --git a/Tests/ttLib/data/woff2_overlap_offcurve_in.ttx b/Tests/ttLib/data/woff2_overlap_offcurve_in.ttx new file mode 100644 index 000000000..a36dbf50d --- /dev/null +++ b/Tests/ttLib/data/woff2_overlap_offcurve_in.ttx @@ -0,0 +1,306 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Weight + + + Unnamed + + + Regular + + + 1.000;NONE;Unnamed-Regular + + + Unnamed Regular + + + Version 1.000 + + + Unnamed-Regular + + + Weight + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + wght + 0x0 + 400.0 + 400.0 + 700.0 + 256 + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/ttLib/woff2_test.py b/Tests/ttLib/woff2_test.py index 5923b7f23..16276c039 100644 --- a/Tests/ttLib/woff2_test.py +++ b/Tests/ttLib/woff2_test.py @@ -1,6 +1,7 @@ from fontTools.misc.py23 import * from fontTools import ttLib from fontTools.ttLib import woff2 +from fontTools.ttLib.tables import _g_l_y_f from fontTools.ttLib.woff2 import ( WOFF2Reader, woff2DirectorySize, woff2DirectoryFormat, woff2FlagsSize, woff2UnknownTagSize, woff2Base128MaxSize, WOFF2DirectoryEntry, @@ -1220,6 +1221,20 @@ class WOFF2RoundtripTest(object): assert tmp.getvalue() == tmp2.getvalue() assert ttFont.flavor == "woff2" + def test_roundtrip_overlap_bit(self): + ttx = os.path.join(data_dir, "woff2_overlap_offcurve_in.ttx") + ttFont = ttLib.TTFont() + ttFont.importXML(ttx) + + assert ttFont["glyf"]["A"].flags[0] == _g_l_y_f.flagOverlapSimple + + ttFont.flavor = "woff2" + tmp = BytesIO() + ttFont.save(tmp) + + _, ttFont2 = self.roundtrip(tmp) + assert ttFont2.flavor == "woff2" + assert ttFont2["glyf"]["A"].flags[0] == 0 class MainTest(object):