Skip to content

Commit

Permalink
👈 Reset the file pointer when returning font from get_webfont (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmdvs committed May 16, 2024
1 parent d8b6bf5 commit 6781109
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/converter/font.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/test_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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):
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 6781109

Please sign in to comment.