{ "packages": ["whl/ziafont-0.4-py3-none-any.whl"] }

Ziafont String Rendering Demo

Type some text...







import asyncio from js import document, Object, window 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 if len(expr) == 0: return try: text = font.text(expr) textsvg = text.svg() except Exception as e: console.log('Exception: ' + str(e.args)) else: Element('textout').write(textsvg) 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.text(expr).svg() file = await fileHandle.createWritable() await file.write(textsvg) await file.close() return drawit()