181 lines
4.4 KiB
TypeScript
181 lines
4.4 KiB
TypeScript
import { rgb, type PDFPage, type PDFImage } from 'pdf-lib'
|
|
import type { EmbeddedFonts } from '@/pdf/fonts'
|
|
import type { Locale } from '@/i18n/types'
|
|
import { getDict } from '@/i18n'
|
|
import { addLinkAnnotation } from './linkAnnotation'
|
|
import { MARGIN_X, COLOR_MUTED } from './constants'
|
|
|
|
const FOOTER_BASE_Y = 20
|
|
const FONT_SIZE = 8
|
|
|
|
export interface FooterAssets {
|
|
logoPng: PDFImage | null
|
|
zqLogoPng: PDFImage | null
|
|
pawsLogoPng: PDFImage | null
|
|
}
|
|
|
|
export function drawFooter(
|
|
page: PDFPage,
|
|
fonts: EmbeddedFonts,
|
|
pageNumber: number,
|
|
totalPages: number,
|
|
locale: Locale,
|
|
assets: FooterAssets,
|
|
): void {
|
|
const dict = getDict(locale)
|
|
const { width } = page.getSize()
|
|
const accent = rgb(0.28, 0.56, 0.42)
|
|
|
|
const logoW = 80
|
|
const logoH = 30
|
|
const rowY = FOOTER_BASE_Y + 14
|
|
const separatorY = rowY + logoH + 6
|
|
|
|
page.drawLine({
|
|
start: { x: MARGIN_X, y: separatorY },
|
|
end: { x: width - MARGIN_X, y: separatorY },
|
|
thickness: 0.5,
|
|
color: rgb(0.85, 0.83, 0.8),
|
|
})
|
|
|
|
if (assets.logoPng) {
|
|
page.drawImage(assets.logoPng, {
|
|
x: MARGIN_X,
|
|
y: rowY,
|
|
width: logoW,
|
|
height: logoH,
|
|
})
|
|
addLinkAnnotation(page, {
|
|
x: MARGIN_X,
|
|
y: rowY,
|
|
width: logoW,
|
|
height: logoH,
|
|
url: 'https://faunosteo.com',
|
|
})
|
|
}
|
|
|
|
const poweredLabel = `${dict['footer.powered_by']} `
|
|
const poweredLabelW = fonts.bodyRegular.widthOfTextAtSize(
|
|
poweredLabel,
|
|
FONT_SIZE,
|
|
)
|
|
const zqLogoW = 70
|
|
const zqLogoH = 16
|
|
const zqFallback = 'zenquality.fr'
|
|
const zqFallbackW = fonts.bodyRegular.widthOfTextAtSize(zqFallback, FONT_SIZE)
|
|
const poweredBlockW = assets.zqLogoPng
|
|
? poweredLabelW + zqLogoW
|
|
: poweredLabelW + zqFallbackW
|
|
const poweredX = (width - poweredBlockW) / 2
|
|
const textBaseY = rowY + 6
|
|
|
|
page.drawText(poweredLabel, {
|
|
x: poweredX,
|
|
y: textBaseY,
|
|
size: FONT_SIZE,
|
|
font: fonts.bodyRegular,
|
|
color: COLOR_MUTED,
|
|
})
|
|
const zqX = poweredX + poweredLabelW
|
|
if (assets.zqLogoPng) {
|
|
page.drawImage(assets.zqLogoPng, {
|
|
x: zqX,
|
|
y: rowY + 2,
|
|
width: zqLogoW,
|
|
height: zqLogoH,
|
|
})
|
|
addLinkAnnotation(page, {
|
|
x: zqX,
|
|
y: rowY + 2,
|
|
width: zqLogoW,
|
|
height: zqLogoH,
|
|
url: 'https://zenquality.fr',
|
|
})
|
|
} else {
|
|
page.drawText(zqFallback, {
|
|
x: zqX,
|
|
y: textBaseY,
|
|
size: FONT_SIZE,
|
|
font: fonts.bodyRegular,
|
|
color: accent,
|
|
})
|
|
addLinkAnnotation(page, {
|
|
x: zqX,
|
|
y: textBaseY - 2,
|
|
width: zqFallbackW,
|
|
height: FONT_SIZE + 4,
|
|
url: 'https://zenquality.fr',
|
|
})
|
|
}
|
|
|
|
const partnerLabel = `${dict['footer.in_partnership']} `
|
|
const partnerLabelW = fonts.bodyRegular.widthOfTextAtSize(
|
|
partnerLabel,
|
|
FONT_SIZE,
|
|
)
|
|
const partnerUrl = 'https://www.instagram.com/paws.iin.harmony'
|
|
|
|
if (assets.pawsLogoPng) {
|
|
const pawsLogoH = 16
|
|
const pawsLogoW =
|
|
pawsLogoH * (assets.pawsLogoPng.width / assets.pawsLogoPng.height)
|
|
const partnerX = width - MARGIN_X - partnerLabelW - pawsLogoW
|
|
page.drawText(partnerLabel, {
|
|
x: partnerX,
|
|
y: textBaseY,
|
|
size: FONT_SIZE,
|
|
font: fonts.bodyRegular,
|
|
color: COLOR_MUTED,
|
|
})
|
|
const pawsX = partnerX + partnerLabelW
|
|
page.drawImage(assets.pawsLogoPng, {
|
|
x: pawsX,
|
|
y: rowY + 2,
|
|
width: pawsLogoW,
|
|
height: pawsLogoH,
|
|
})
|
|
addLinkAnnotation(page, {
|
|
x: pawsX,
|
|
y: rowY + 2,
|
|
width: pawsLogoW,
|
|
height: pawsLogoH,
|
|
url: partnerUrl,
|
|
})
|
|
} else {
|
|
const handle = '@paws.iin.harmony'
|
|
const handleW = fonts.bodyRegular.widthOfTextAtSize(handle, FONT_SIZE)
|
|
const partnerX = width - MARGIN_X - partnerLabelW - handleW
|
|
page.drawText(partnerLabel, {
|
|
x: partnerX,
|
|
y: textBaseY,
|
|
size: FONT_SIZE,
|
|
font: fonts.bodyRegular,
|
|
color: COLOR_MUTED,
|
|
})
|
|
page.drawText(handle, {
|
|
x: partnerX + partnerLabelW,
|
|
y: textBaseY,
|
|
size: FONT_SIZE,
|
|
font: fonts.bodyRegular,
|
|
color: accent,
|
|
})
|
|
addLinkAnnotation(page, {
|
|
x: partnerX + partnerLabelW,
|
|
y: textBaseY - 2,
|
|
width: handleW,
|
|
height: FONT_SIZE + 4,
|
|
url: partnerUrl,
|
|
})
|
|
}
|
|
|
|
const pageText = `${pageNumber} / ${totalPages}`
|
|
const pageW = fonts.bodyRegular.widthOfTextAtSize(pageText, FONT_SIZE)
|
|
page.drawText(pageText, {
|
|
x: (width - pageW) / 2,
|
|
y: FOOTER_BASE_Y + 2,
|
|
size: FONT_SIZE,
|
|
font: fonts.bodyRegular,
|
|
color: COLOR_MUTED,
|
|
})
|
|
}
|