From 25b4c26acd2c4d73d52af6a9ffb0937cc6160ebf Mon Sep 17 00:00:00 2001 From: Tim Davies Date: Thu, 16 May 2024 17:15:40 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=88=20Reset=20the=20file=20pointer=20w?= =?UTF-8?q?hen=20returning=20font=20from=20`get=5Fwebfont`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/converter/font.py | 3 +++ tests/integration/test_structure.py | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/converter/font.py b/src/converter/font.py index d6b1bf7..bc0d503 100644 --- a/src/converter/font.py +++ b/src/converter/font.py @@ -49,7 +49,10 @@ def convert( name: Tuple[str, str], font_file: IO[bytes], postscript: str, output_zip: ZipFile ) -> FontReference: family, subfamily = name + + font_file.seek(0) data = font_file.read() + sha = utils.generate_file_ref(data) path = f"fonts/{sha}" output_zip.open(path, "w").write(data) diff --git a/tests/integration/test_structure.py b/tests/integration/test_structure.py index 3c4c49c..645e9f7 100644 --- a/tests/integration/test_structure.py +++ b/tests/integration/test_structure.py @@ -91,11 +91,11 @@ def test_document(sketch_doc): assert doc["fontReferences"] == [ { "_class": "fontReference", - "do_objectID": "4B16DCBA-BB70-4392-9B48-95FE92292C38", + "do_objectID": "46BF164E-CB00-4E1A-A5DE-9E6EB74A4F1F", "fontData": { "_class": "MSJSONFileReference", "_ref_class": "MSFontData", - "_ref": "fonts/be1bdec0aa74b4dcb079943e70528096cca985f8", + "_ref": "fonts/be10cc8996f037af7331dc965bae42ef33478700", }, "fontFamilyName": "Inter", "fontFileName": "Inter-Regular.ttf", @@ -116,7 +116,7 @@ def test_document(sketch_doc): [ "images/616d10a80971e08c6b43a164746afac1972c7ccc.png", "images/92e4d5e0c24ffd632c3db3264e62cc907c2f5e29", - "fonts/be1bdec0aa74b4dcb079943e70528096cca985f8", + "fonts/be10cc8996f037af7331dc965bae42ef33478700", ], ) def test_file_hashes(sketch_doc, img): @@ -223,7 +223,7 @@ def test_files(sketch_doc): "images/92e4d5e0c24ffd632c3db3264e62cc907c2f5e29", "pages/8F292FCA-49C0-4E31-957E-93FB2D1A7231.json", "pages/A4E5259A-9CE6-49D9-B4A1-A8062C205347.json", - "fonts/be1bdec0aa74b4dcb079943e70528096cca985f8", + "fonts/be10cc8996f037af7331dc965bae42ef33478700", "document.json", "user.json", "meta.json",