[woff2] Support cubic curves as untransformed glyph table

This commit is contained in:
Behdad Esfahbod 2023-02-21 12:11:25 -07:00
parent 568dd0c5d4
commit 9e40409094
2 changed files with 25 additions and 0 deletions

View File

@ -1041,6 +1041,8 @@ class WOFF2GlyfTable(getTableClass("glyf")):
def _encodeCoordinates(self, glyph):
lastEndPoint = -1
if _g_l_y_f.flagCubic in glyph.flags:
raise NotImplementedError
for endPoint in glyph.endPtsOfContours:
ptsOfContour = endPoint - lastEndPoint
self.nPointsStream += pack255UShort(ptsOfContour)

View File

@ -28,6 +28,7 @@ from fontTools.misc import sstruct
from fontTools.misc.textTools import Tag, bytechr, byteord
from fontTools import fontBuilder
from fontTools.pens.ttGlyphPen import TTGlyphPen
from fontTools.pens.recordingPen import RecordingPen
from io import BytesIO
import struct
import os
@ -1505,6 +1506,28 @@ class VarCompositeTest(unittest.TestCase):
ttf.save(out)
class CubicTest(unittest.TestCase):
def test_cubic(self):
input_path = os.path.join(
data_dir, "..", "tables", "data", "NotoSans-VF-cubic.subset.ttf"
)
ttf = ttLib.TTFont(input_path)
pen1 = RecordingPen()
ttf.getGlyphSet()["a"].draw(pen1)
ttf.flavor = "woff2"
out = BytesIO()
ttf.save(out)
ttf = ttLib.TTFont(out)
ttf.flavor = None
pen2 = RecordingPen()
ttf.getGlyphSet()["a"].draw(pen2)
out = BytesIO()
ttf.save(out)
assert pen1.value == pen2.value
if __name__ == "__main__":
import sys