Conversation
Introduces a new font caching mechanism to handle custom printer fonts. This allows users to upload TTF/OTF font files that will be registered with the browser and used for text rendering. The font cache persists fonts in localStorage and provides a hook for components to subscribe to cache changes.
There was a problem hiding this comment.
Code Review
This pull request implements support for custom TrueType fonts via the ZPL ^A@ command, including a font cache system using localStorage and a new font upload UI. Key feedback includes the accidental removal of barcode offset logic which will cause rendering misalignments, potential failures of crypto.randomUUID() in non-secure contexts, and the limitations of localStorage for storing large font files compared to IndexedDB.
| const dataUrl = reader.result as string; | ||
| const name = printerName.toUpperCase(); | ||
| const fontFamily = printerNameToFamily(name); | ||
| const entry: CachedFont = { id: crypto.randomUUID(), name, dataUrl, fontFamily }; |
There was a problem hiding this comment.
crypto.randomUUID() is only available in secure contexts (HTTPS or localhost). If the application is accessed over a standard HTTP connection, this call will throw an error and prevent font uploads. Consider providing a fallback for non-secure contexts or using a different method for generating unique IDs if HTTP support is required.
| const entry: CachedFont = { id: crypto.randomUUID(), name, dataUrl, fontFamily }; | ||
| cache.set(name, entry); | ||
| try { | ||
| localStorage.setItem(LS_PREFIX + name, JSON.stringify(entry)); |
There was a problem hiding this comment.
Storing font files as data URLs in localStorage is problematic because localStorage has a strict size limit (typically 5MB). A single TrueType font can be several hundred kilobytes or even megabytes, meaning the cache will fill up very quickly. Consider using IndexedDB for persisting large binary data like fonts, as it offers much higher storage limits and better performance for binary blobs.
| } catch { | ||
| // localStorage full — font stays in memory only | ||
| } |
There was a problem hiding this comment.
When localStorage.setItem fails (e.g., due to quota exceeded), the error is caught silently. This results in an inconsistent state where the font is available in the current session's memory but will disappear upon page reload. It would be better to notify the user that the font could not be persisted permanently.
feat: add bwip-js for barcode rendering and implement LabelPreviewMod…
No description provided.