Files
accounted/lib/invoices/font-files.ts
T
Mattsson e11f70b347 Bug/gh issues fiz (#1103)
* refactor: optimize page loading and data fetching

* fix: resolve recurring production runtime errors

* feat: add MCP company and customer updates

* fix: handle year-end tax adjustments

* feat: harden annual report compliance

* fix: expand invoice logo and font support

* fix: sanitize API route error responses

* fix: sanitize user-facing error messages

* feat: persist onboarding and tax assessment notices

* fix: reduce cloud backup audit churn

* feat: refine invoice editor layout

* fix: show saved tax adjustments in INK2

* fix: complete annual report API mappings

* docs: record operational safeguards and decisions

* fix: harden annual report review findings

* fix: adjust column span for description based on VAT registration

* New css class name
2026-07-21 23:00:15 +02:00

33 lines
851 B
TypeScript

export type InvoiceFontFileFormat = 'ttf' | 'woff'
export function detectInvoiceFontFileFormat(
bytes: Uint8Array,
): InvoiceFontFileFormat | null {
if (bytes.byteLength < 4) return null
if (
bytes[0] === 0x00 &&
bytes[1] === 0x01 &&
bytes[2] === 0x00 &&
bytes[3] === 0x00
) {
return 'ttf'
}
const signature = String.fromCharCode(bytes[0], bytes[1], bytes[2], bytes[3])
if (signature === 'true') return 'ttf'
if (signature === 'wOFF') return 'woff'
return null
}
export function getInvoiceFontContentType(format: InvoiceFontFileFormat): string {
return format === 'ttf' ? 'font/ttf' : 'font/woff'
}
export function toInvoiceFontDataUrl(
bytes: Uint8Array,
format: InvoiceFontFileFormat,
): string {
return `data:${getInvoiceFontContentType(format)};base64,${Buffer.from(bytes).toString('base64')}`
}