Merge pull request #3129 from fonttools/privData_bytes
privData needs to padded with bytes not str
This commit is contained in:
commit
0bf84f9c7b
@ -345,7 +345,7 @@ class SFNTWriter(object):
|
|||||||
self.file.seek(0, 2)
|
self.file.seek(0, 2)
|
||||||
off = self.file.tell()
|
off = self.file.tell()
|
||||||
paddedOff = (off + 3) & ~3
|
paddedOff = (off + 3) & ~3
|
||||||
self.file.write("\0" * (paddedOff - off))
|
self.file.write(b"\0" * (paddedOff - off))
|
||||||
self.privOffset = self.file.tell()
|
self.privOffset = self.file.tell()
|
||||||
self.privLength = len(data.privData)
|
self.privLength = len(data.privData)
|
||||||
self.file.write(data.privData)
|
self.file.write(data.privData)
|
||||||
|
@ -1,9 +1,25 @@
|
|||||||
import io
|
import io
|
||||||
import copy
|
import copy
|
||||||
import pickle
|
import pickle
|
||||||
from fontTools.ttLib.sfnt import calcChecksum, SFNTReader
|
import tempfile
|
||||||
|
from fontTools.ttLib import TTFont
|
||||||
|
from fontTools.ttLib.sfnt import calcChecksum, SFNTReader, WOFFFlavorData
|
||||||
|
from pathlib import Path
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
TEST_DATA = Path(__file__).parent / "data"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def ttfont_path():
|
||||||
|
font = TTFont()
|
||||||
|
font.importXML(TEST_DATA / "TestTTF-Regular.ttx")
|
||||||
|
with tempfile.NamedTemporaryFile(suffix=".ttf", delete=False) as fp:
|
||||||
|
font_path = Path(fp.name)
|
||||||
|
font.save(font_path)
|
||||||
|
yield font_path
|
||||||
|
font_path.unlink()
|
||||||
|
|
||||||
|
|
||||||
def test_calcChecksum():
|
def test_calcChecksum():
|
||||||
assert calcChecksum(b"abcd") == 1633837924
|
assert calcChecksum(b"abcd") == 1633837924
|
||||||
@ -57,3 +73,24 @@ class SFNTReaderTest:
|
|||||||
if k == "file":
|
if k == "file":
|
||||||
continue
|
continue
|
||||||
assert getattr(reader2, k) == v
|
assert getattr(reader2, k) == v
|
||||||
|
|
||||||
|
|
||||||
|
def test_ttLib_sfnt_write_privData(tmp_path, ttfont_path):
|
||||||
|
output_path = tmp_path / "TestTTF-Regular.woff"
|
||||||
|
font = TTFont(ttfont_path)
|
||||||
|
|
||||||
|
privData = "Private Eyes".encode()
|
||||||
|
|
||||||
|
data = WOFFFlavorData()
|
||||||
|
head = font["head"]
|
||||||
|
data.majorVersion, data.minorVersion = map(
|
||||||
|
int, format(head.fontRevision, ".3f").split(".")
|
||||||
|
)
|
||||||
|
|
||||||
|
data.privData = privData
|
||||||
|
font.flavor = "woff"
|
||||||
|
font.flavorData = data
|
||||||
|
font.save(output_path)
|
||||||
|
|
||||||
|
assert output_path.exists()
|
||||||
|
assert TTFont(output_path).flavorData.privData == privData
|
||||||
|
Loading…
x
Reference in New Issue
Block a user