packages = ["whl/ziafont-0.4-py3-none-any.whl"]
Ziafont Glyph Inspection Demo
Type a character...
Load Font
Download SVG
import asyncio from js import document, Object, window, console from pyodide.ffi import to_js, create_proxy import ziafont font = ziafont.Font() async def load_font(): global font try: fileHandles = await window.showOpenFilePicker(); except Exception as e: console.log('Exception: ' + str(e)) return else: file = await fileHandles[0].getFile() buf = file.arrayBuffer() await asyncio.sleep(.5) b = buf.result().to_bytes() with open('myfont.otf', 'wb') as f: f.write(b) font = ziafont.Font('myfont.otf') await drawit() async def drawit(): console.log('DRAWIT') expr = Element("expression").value Element("expression").clear() Element("expression").element.value = expr[-1] if len(expr) == 0: return try: glyph = font.glyph(expr[-1]) textsvg = glyph.test() desc = glyph.describe() except Exception as e: console.log('Exception: ' + str(e.args)) else: Element('description').clear() display(textsvg, target='textout', append=False) display(desc, target='description', append=False) async def file_save(): try: options = {"startIn": "downloads", "suggestedName": "math.svg"} fileHandle = await window.showSaveFilePicker(Object.fromEntries(to_js(options))) except Exception as e: console.log('Exception: ' + str(e.args)) return expr = Element("expression").value textsvg = font.glyph(expr[-1]).test().svg() file = await fileHandle.createWritable() await file.write(textsvg) await file.close() return drawit()