feat(pdf): generate PNG assets from SVG logos, use -com variant in footer
- Generated 24 PNGs (128/256/512/1024) from 6 SVG logos into public/assets/ - PDF footer now uses faunosteo-horizontal-com (with .com branding) - Simplified logo.ts: both logos are pre-rasterized PNGs, removed SVG rasterization code Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
No files matched your search
|
After Width: | Height: | Size: 49 KiB |
|
After Width: | Height: | Size: 4.4 KiB |
|
After Width: | Height: | Size: 9.8 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 83 KiB |
|
After Width: | Height: | Size: 7.5 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 37 KiB |
|
After Width: | Height: | Size: 58 KiB |
|
After Width: | Height: | Size: 5.5 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 26 KiB |
|
After Width: | Height: | Size: 67 KiB |
|
After Width: | Height: | Size: 6.2 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 31 KiB |
|
After Width: | Height: | Size: 54 KiB |
|
After Width: | Height: | Size: 4.9 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 81 KiB |
|
After Width: | Height: | Size: 7.4 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 36 KiB |
@@ -106,7 +106,7 @@ export async function exportReportToPdf(
|
|||||||
let logoPdfImage = null
|
let logoPdfImage = null
|
||||||
let zqLogoPdfImage = null
|
let zqLogoPdfImage = null
|
||||||
try {
|
try {
|
||||||
const logoPngBytes = await loadFaunosteoLogo(400)
|
const logoPngBytes = await loadFaunosteoLogo()
|
||||||
logoPdfImage = await pdfDoc.embedPng(logoPngBytes)
|
logoPdfImage = await pdfDoc.embedPng(logoPngBytes)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn('Faunosteo logo embed failed:', err)
|
console.warn('Faunosteo logo embed failed:', err)
|
||||||
|
|||||||
@@ -1,82 +1,16 @@
|
|||||||
const FAUNOSTEO_LOGO = '/logo-horizontal.svg'
|
const FAUNOSTEO_LOGO = '/assets/faunosteo-horizontal-com-512.png'
|
||||||
const ZENQUALITY_LOGO = '/brand/zenquality-logo-fr.png'
|
const ZENQUALITY_LOGO = '/brand/zenquality-logo-fr.png'
|
||||||
|
|
||||||
async function rasterizeSvgToCanvas(
|
async function fetchPngBytes(path: string): Promise<Uint8Array> {
|
||||||
svgString: string,
|
|
||||||
width: number,
|
|
||||||
height: number,
|
|
||||||
): Promise<HTMLCanvasElement> {
|
|
||||||
const doc = new DOMParser().parseFromString(svgString, 'image/svg+xml')
|
|
||||||
const root = doc.documentElement
|
|
||||||
if (!root.getAttribute('xmlns')) {
|
|
||||||
root.setAttribute('xmlns', 'http://www.w3.org/2000/svg')
|
|
||||||
}
|
|
||||||
if (!root.getAttribute('width')) root.setAttribute('width', String(width))
|
|
||||||
if (!root.getAttribute('height')) root.setAttribute('height', String(height))
|
|
||||||
|
|
||||||
const normalized = new XMLSerializer().serializeToString(root)
|
|
||||||
const blob = new Blob([normalized], { type: 'image/svg+xml;charset=utf-8' })
|
|
||||||
const url = URL.createObjectURL(blob)
|
|
||||||
const img = new Image()
|
|
||||||
img.decoding = 'sync'
|
|
||||||
img.crossOrigin = 'anonymous'
|
|
||||||
|
|
||||||
try {
|
|
||||||
await new Promise<void>((resolve, reject) => {
|
|
||||||
img.onload = () => resolve()
|
|
||||||
img.onerror = () => reject(new Error('Failed to rasterize logo SVG'))
|
|
||||||
img.src = url
|
|
||||||
})
|
|
||||||
} finally {
|
|
||||||
URL.revokeObjectURL(url)
|
|
||||||
}
|
|
||||||
|
|
||||||
const canvas = document.createElement('canvas')
|
|
||||||
canvas.width = width
|
|
||||||
canvas.height = height
|
|
||||||
const ctx = canvas.getContext('2d')
|
|
||||||
if (!ctx) throw new Error('Canvas 2D context unavailable')
|
|
||||||
ctx.drawImage(img, 0, 0, width, height)
|
|
||||||
return canvas
|
|
||||||
}
|
|
||||||
|
|
||||||
async function canvasToPng(canvas: HTMLCanvasElement): Promise<Uint8Array> {
|
|
||||||
const blob = await new Promise<Blob | null>((resolve) => {
|
|
||||||
canvas.toBlob((b) => resolve(b), 'image/png')
|
|
||||||
})
|
|
||||||
if (blob) return new Uint8Array(await blob.arrayBuffer())
|
|
||||||
const dataUrl = canvas.toDataURL('image/png')
|
|
||||||
const comma = dataUrl.indexOf(',')
|
|
||||||
const binary = atob(dataUrl.slice(comma + 1))
|
|
||||||
const bytes = new Uint8Array(binary.length)
|
|
||||||
for (let i = 0; i < binary.length; i += 1) bytes[i] = binary.charCodeAt(i)
|
|
||||||
return bytes
|
|
||||||
}
|
|
||||||
|
|
||||||
async function loadSvgLogoPng(
|
|
||||||
path: string,
|
|
||||||
widthPx: number,
|
|
||||||
fallbackViewBox: string,
|
|
||||||
): Promise<Uint8Array> {
|
|
||||||
const resp = await fetch(path)
|
const resp = await fetch(path)
|
||||||
if (!resp.ok) throw new Error(`Logo fetch failed: HTTP ${resp.status}`)
|
if (!resp.ok) throw new Error(`Logo fetch failed: HTTP ${resp.status}`)
|
||||||
const svgText = await resp.text()
|
return new Uint8Array(await resp.arrayBuffer())
|
||||||
|
|
||||||
const vb = svgText.match(/viewBox="([^"]*)"/)
|
|
||||||
const parts = (vb?.[1] ?? fallbackViewBox).split(/\s+/).map(Number)
|
|
||||||
const ratio = parts[3] / parts[2]
|
|
||||||
const heightPx = Math.round(widthPx * ratio)
|
|
||||||
|
|
||||||
const canvas = await rasterizeSvgToCanvas(svgText, widthPx, heightPx)
|
|
||||||
return canvasToPng(canvas)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function loadFaunosteoLogo(widthPx: number): Promise<Uint8Array> {
|
export async function loadFaunosteoLogo(): Promise<Uint8Array> {
|
||||||
return loadSvgLogoPng(FAUNOSTEO_LOGO, widthPx, '0 0 1070 410')
|
return fetchPngBytes(FAUNOSTEO_LOGO)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function loadZenqualityLogo(): Promise<Uint8Array> {
|
export async function loadZenqualityLogo(): Promise<Uint8Array> {
|
||||||
const resp = await fetch(ZENQUALITY_LOGO)
|
return fetchPngBytes(ZENQUALITY_LOGO)
|
||||||
if (!resp.ok) throw new Error(`ZQ logo fetch failed: HTTP ${resp.status}`)
|
|
||||||
return new Uint8Array(await resp.arrayBuffer())
|
|
||||||
}
|
}
|
||||||