chore(pdf): extract shared render constants module

This commit is contained in:
Bastien Chanot committed 2026-07-12 17:02:45 +02:00
1 parent a5849113e5
commit 0ec1b27d1f
5 files changed
+52 -33

No files matched your search

+12 -11
View File
@@ -1,4 +1,4 @@
import { rgb, PageSizes, type PDFDocument } from 'pdf-lib'
import { PageSizes, type PDFDocument } from 'pdf-lib'
import type { EmbeddedFonts } from '@/pdf/fonts'
import type { Report } from '@/domain/schema/report'
import type { Locale } from '@/i18n/types'
@@ -6,21 +6,22 @@ import { getDict } from '@/i18n'
import { drawHeader, type HeaderAssets } from './header'
import { wrapLines } from './text'
import { formatDate } from '@/lib/dates'
import {
MARGIN_X,
EYEBROW_Y_OFFSET,
TITLE_Y_OFFSET,
TITLE_RULE_OFFSET,
TITLE_RULE_WIDTH,
SECTION_LABEL_GAP,
COLOR_INK,
COLOR_MUTED,
COLOR_ACCENT,
} from './constants'
const MARGIN_X = 36
const EYEBROW_Y_OFFSET = 95
const TITLE_Y_OFFSET = 122
const TITLE_RULE_OFFSET = 12
const TITLE_RULE_WIDTH = 48
const SECTION_TOP_GAP = 28
const SECTION_LABEL_GAP = 4
const SECTION_BLOCK_GAP = 18
const TEXT_LINE_HEIGHT = 14
const COLOR_INK = rgb(0.12, 0.11, 0.09)
const COLOR_MUTED = rgb(0.42, 0.39, 0.35)
const COLOR_ACCENT = rgb(0.72, 0.35, 0.25)
export async function addConclusionPage(
pdfDoc: PDFDocument,
report: Report,
+19
View File
@@ -0,0 +1,19 @@
import { rgb } from 'pdf-lib'
/**
* Layout and color constants shared across PDF page renderers (header,
* footer, observation page, conclusion page). Only values that are
* byte-identical across all callers live here — a same-named constant
* with a different value per file stays local to that file.
*/
export const MARGIN_X = 36
export const EYEBROW_Y_OFFSET = 95
export const TITLE_Y_OFFSET = 122
export const TITLE_RULE_OFFSET = 12
export const TITLE_RULE_WIDTH = 48
export const SECTION_LABEL_GAP = 4
export const COLOR_INK = rgb(0.12, 0.11, 0.09)
export const COLOR_MUTED = rgb(0.42, 0.39, 0.35)
export const COLOR_ACCENT = rgb(0.72, 0.35, 0.25)
+5 -6
View File
@@ -3,8 +3,8 @@ 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 MARGIN_X = 36
const FOOTER_BASE_Y = 20
const FONT_SIZE = 8
@@ -24,7 +24,6 @@ export function drawFooter(
): void {
const dict = getDict(locale)
const { width } = page.getSize()
const muted = rgb(0.42, 0.39, 0.35)
const accent = rgb(0.28, 0.56, 0.42)
const logoW = 80
@@ -72,7 +71,7 @@ export function drawFooter(
y: textBaseY,
size: FONT_SIZE,
font: fonts.bodyRegular,
color: muted,
color: COLOR_MUTED,
})
const zqX = poweredX + poweredLabelW
if (assets.zqLogoPng) {
@@ -119,7 +118,7 @@ export function drawFooter(
y: textBaseY,
size: FONT_SIZE,
font: fonts.bodyRegular,
color: muted,
color: COLOR_MUTED,
})
const pawsX = partnerX + partnerLabelW
page.drawImage(assets.pawsLogoPng, {
@@ -144,7 +143,7 @@ export function drawFooter(
y: textBaseY,
size: FONT_SIZE,
font: fonts.bodyRegular,
color: muted,
color: COLOR_MUTED,
})
page.drawText(handle, {
x: partnerX + partnerLabelW,
@@ -169,6 +168,6 @@ export function drawFooter(
y: FOOTER_BASE_Y + 2,
size: FONT_SIZE,
font: fonts.bodyRegular,
color: muted,
color: COLOR_MUTED,
})
}
+5 -7
View File
@@ -1,12 +1,12 @@
import { rgb, type PDFPage, type PDFImage } from 'pdf-lib'
import type { PDFPage, PDFImage } from 'pdf-lib'
import type { EmbeddedFonts } from '@/pdf/fonts'
import type { Report } from '@/domain/schema/report'
import type { Locale } from '@/i18n/types'
import { getDict } from '@/i18n'
import { formatDate } from '@/lib/dates'
import { addLinkAnnotation } from './linkAnnotation'
import { MARGIN_X, COLOR_INK, COLOR_MUTED } from './constants'
const MARGIN_X = 36
const TOP_Y = 800
const LOGO_WIDTH = 100
const LOGO_HEIGHT = 38
@@ -24,8 +24,6 @@ export function drawHeader(
): void {
const dict = getDict(locale)
const { width } = page.getSize()
const ink = rgb(0.12, 0.11, 0.09)
const muted = rgb(0.42, 0.39, 0.35)
const y = TOP_Y
@@ -44,7 +42,7 @@ export function drawHeader(
y: y - i * 12,
size: i === 0 ? 11 : 9,
font: i === 0 ? fonts.bodyBold : fonts.bodyRegular,
color: i === 0 ? ink : muted,
color: i === 0 ? COLOR_INK : COLOR_MUTED,
})
})
@@ -88,7 +86,7 @@ export function drawHeader(
y: y - i * 12,
size,
font,
color: i === 0 ? ink : muted,
color: i === 0 ? COLOR_INK : COLOR_MUTED,
})
})
@@ -97,6 +95,6 @@ export function drawHeader(
start: { x: MARGIN_X, y: separatorY },
end: { x: width - MARGIN_X, y: separatorY },
thickness: 0.5,
color: muted,
color: COLOR_MUTED,
})
}
+11 -9
View File
@@ -13,13 +13,19 @@ import { wrapLines } from './text'
import { loadSvg } from '@/anatomy/svgLoader'
import { parseSvgBones } from '@/anatomy/svgConvention'
import { getSpecies } from '@/domain/species/registry'
import {
MARGIN_X,
EYEBROW_Y_OFFSET,
TITLE_Y_OFFSET,
TITLE_RULE_OFFSET,
TITLE_RULE_WIDTH,
SECTION_LABEL_GAP,
COLOR_INK,
COLOR_MUTED,
COLOR_ACCENT,
} from './constants'
const MARGIN_X = 36
const MARGIN_BOTTOM = 48
const EYEBROW_Y_OFFSET = 95
const TITLE_Y_OFFSET = 122
const TITLE_RULE_OFFSET = 12
const TITLE_RULE_WIDTH = 48
const IMAGE_TOP_GAP = 32
const IMAGE_LABEL_GAP = 14
const IMAGE_BOTTOM_GAP = 14
@@ -28,12 +34,8 @@ const IMAGE_ROW_GAP = 12
const IMAGE_MIN_CELL_H = 60
const TEXT_TOP_GAP = 10
const TEXT_LINE_HEIGHT = 13
const SECTION_LABEL_GAP = 4
const SECTION_BLOCK_GAP = 10
const COLOR_INK = rgb(0.12, 0.11, 0.09)
const COLOR_MUTED = rgb(0.42, 0.39, 0.35)
const COLOR_ACCENT = rgb(0.72, 0.35, 0.25)
const COLOR_WHITE = rgb(1, 1, 1)
const SEVERITY_BG: Record<string, ReturnType<typeof rgb>> = {