Skip to content

Feat/cutom font#1

Merged
u8array merged 3 commits intomainfrom
feat/cutom-font
Apr 21, 2026
Merged

Feat/cutom font#1
u8array merged 3 commits intomainfrom
feat/cutom-font

Conversation

@u8array
Copy link
Copy Markdown
Owner

@u8array u8array commented Apr 21, 2026

No description provided.

u8array added 2 commits April 21, 2026 18:05
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.
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/components/Canvas/KonvaObject.tsx
Comment thread src/lib/fontCache.ts
const dataUrl = reader.result as string;
const name = printerName.toUpperCase();
const fontFamily = printerNameToFamily(name);
const entry: CachedFont = { id: crypto.randomUUID(), name, dataUrl, fontFamily };
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Comment thread src/lib/fontCache.ts
const entry: CachedFont = { id: crypto.randomUUID(), name, dataUrl, fontFamily };
cache.set(name, entry);
try {
localStorage.setItem(LS_PREFIX + name, JSON.stringify(entry));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Comment thread src/lib/fontCache.ts
Comment on lines +96 to +98
} catch {
// localStorage full — font stays in memory only
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

@u8array u8array merged commit 58aeccf into main Apr 21, 2026
2 checks passed
u8array added a commit that referenced this pull request Apr 25, 2026
feat: add bwip-js for barcode rendering and implement LabelPreviewMod…
u8array added a commit that referenced this pull request Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant