fix(pdf): push titles below header rule + style headings and section labels

Layout:
- Title baseline dropped from height-90 to height-115 so the size-22
  ascender clears the header rule at y=760 with a real cushion.
- Image area starts further down to match.

Visual style:
- Eyebrow label (small bold accent) above each title: OBSERVATION /
  SYNTHÈSE. Title uses Times 22; observation page shows the index
  as a zero-padded number (01, 02, …) with severity as a muted
  inline note next to it.
- 2pt accent rule (48pt wide) under each title.
- Section labels (ZONES, PATHOLOGIES, SÉVÉRITÉ, COMMENTAIRE,
  CONCLUSION, RECOMMANDATIONS, PROCHAIN RENDEZ-VOUS) rendered as
  small bold uppercase accent labels with the value on the next
  line in regular body.
- Image area gets a "VUE GÉNÉRALE" / "VUE DÉTAIL — <id>" eyebrow.

Colors are inlined as rgb tokens (ink, muted, accent terracotta).
No new assets, only the three Standard fonts already embedded.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Bastien ChanotandClaude committed 2026-05-19 06:08:12 +02:00
1 parent 3bb229331e
commit ee5b7f0277
2 files changed
+148 -50

No files matched your search

+65 -21
View File
@@ -5,6 +5,17 @@ import { drawHeader } from './header'
import { formatDateFr } from '@/lib/dates'
const MARGIN_X = 36
const TITLE_Y_OFFSET = 115
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)
function wrap(text: string, font: PDFFont, size: number, max: number): string[] {
const words = text.split(/\s+/)
@@ -30,36 +41,69 @@ export async function addConclusionPage(
): Promise<void> {
const page = pdfDoc.addPage(PageSizes.A4)
const { width, height } = page.getSize()
drawHeader(page, report, fonts)
const ink = rgb(0.12, 0.11, 0.09)
const muted = rgb(0.42, 0.39, 0.35)
const max = width - MARGIN_X * 2
let y = height - 90
page.drawText('Conclusion', { x: MARGIN_X, y, size: 16, font: fonts.headingRegular, color: ink })
y -= 20
wrap(report.conclusion || '—', fonts.bodyRegular, 11, max).forEach((line) => {
page.drawText(line, { x: MARGIN_X, y, size: 11, font: fonts.bodyRegular, color: ink })
y -= 14
drawHeader(page, report, fonts)
const titleY = height - TITLE_Y_OFFSET
page.drawText('SYNTHÈSE', {
x: MARGIN_X,
y: titleY + 14,
size: 9,
font: fonts.bodyBold,
color: COLOR_ACCENT,
})
page.drawText('Conclusion', {
x: MARGIN_X,
y: titleY,
size: 22,
font: fonts.headingRegular,
color: COLOR_INK,
})
page.drawLine({
start: { x: MARGIN_X, y: titleY - TITLE_RULE_OFFSET },
end: { x: MARGIN_X + TITLE_RULE_WIDTH, y: titleY - TITLE_RULE_OFFSET },
thickness: 2,
color: COLOR_ACCENT,
})
y -= 12
page.drawText('Recommandations', { x: MARGIN_X, y, size: 14, font: fonts.headingRegular, color: ink })
y -= 18
wrap(report.recommendations || '—', fonts.bodyRegular, 11, max).forEach((line) => {
page.drawText(line, { x: MARGIN_X, y, size: 11, font: fonts.bodyRegular, color: ink })
y -= 14
})
let cursorY = titleY - SECTION_TOP_GAP
const sections: Array<{ label: string; body: string; color?: typeof COLOR_INK }> = [
{ label: 'CONCLUSION', body: report.conclusion || '—' },
{ label: 'RECOMMANDATIONS', body: report.recommendations || '—' },
]
if (report.nextAppointment) {
y -= 12
page.drawText('Prochain rendez-vous', { x: MARGIN_X, y, size: 14, font: fonts.headingRegular, color: ink })
y -= 18
const txt =
report.nextAppointment.kind === 'date'
? formatDateFr(report.nextAppointment.date)
: report.nextAppointment.text
page.drawText(txt || '—', { x: MARGIN_X, y, size: 11, font: fonts.bodyRegular, color: muted })
sections.push({
label: 'PROCHAIN RENDEZ-VOUS',
body: txt || '—',
color: COLOR_MUTED,
})
}
for (const { label, body, color } of sections) {
page.drawText(label, {
x: MARGIN_X,
y: cursorY,
size: 9,
font: fonts.bodyBold,
color: COLOR_ACCENT,
})
cursorY -= SECTION_LABEL_GAP + 10
wrap(body, fonts.bodyRegular, 11, max).forEach((line) => {
page.drawText(line, {
x: MARGIN_X,
y: cursorY,
size: 11,
font: fonts.bodyRegular,
color: color ?? COLOR_INK,
})
cursorY -= TEXT_LINE_HEIGHT
})
cursorY -= SECTION_BLOCK_GAP
}
}
+83 -29
View File
@@ -9,12 +9,20 @@ import { parseSvgBones } from '@/anatomy/svgConvention'
import { getSpecies } from '@/domain/species/registry'
const MARGIN_X = 36
const TITLE_Y_OFFSET = 90
const IMAGE_TOP_GAP = 14
const IMAGE_BOTTOM_GAP = 10
const TEXT_TOP_GAP = 8
const TITLE_Y_OFFSET = 115
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
const TEXT_TOP_GAP = 10
const TEXT_LINE_HEIGHT = 13
const TEXT_BLOCK_GAP = 6
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)
function wrapLines(text: string, font: PDFFont, size: number, max: number): string[] {
const words = text.split(/\s+/)
@@ -33,15 +41,6 @@ function wrapLines(text: string, font: PDFFont, size: number, max: number): stri
return lines
}
/**
* Returns a colorized + cleaned SVG string for rasterization:
* - selected zones (matching `sourceDetailId`) are filled with the accent
* - all other annotated elements are hidden via `display="none"`
* - every `data-anno-*` attribute is stripped from the output
*
* Result: the rendered PNG shows only highlighted zones over the bare
* anatomy artwork, with no leftover overlay tints.
*/
async function colorizedSvgString(
speciesSvgPath: string,
observation: Observation,
@@ -88,14 +87,37 @@ export async function addObservationPage(
const { width, height } = page.getSize()
drawHeader(page, report, fonts)
const ink = rgb(0.12, 0.11, 0.09)
const titleY = height - TITLE_Y_OFFSET
page.drawText(`Observation #${obsIndex + 1}`, {
const obsLabel = String(obsIndex + 1).padStart(2, '0')
page.drawText('OBSERVATION', {
x: MARGIN_X,
y: titleY + 14,
size: 9,
font: fonts.bodyBold,
color: COLOR_ACCENT,
})
page.drawText(obsLabel, {
x: MARGIN_X,
y: titleY,
size: 16,
size: 22,
font: fonts.headingRegular,
color: ink,
color: COLOR_INK,
})
const numW = fonts.headingRegular.widthOfTextAtSize(obsLabel, 22)
if (observation.severity) {
page.drawText(`Sévérité — ${observation.severity}`, {
x: MARGIN_X + numW + 16,
y: titleY + 5,
size: 10,
font: fonts.bodyRegular,
color: COLOR_MUTED,
})
}
page.drawLine({
start: { x: MARGIN_X, y: titleY - TITLE_RULE_OFFSET },
end: { x: MARGIN_X + TITLE_RULE_WIDTH, y: titleY - TITLE_RULE_OFFSET },
thickness: 2,
color: COLOR_ACCENT,
})
const species = getSpecies(report.animal.speciesId)
@@ -105,6 +127,14 @@ export async function addObservationPage(
let cursorY = titleY - IMAGE_TOP_GAP
if (hasMainZones) {
page.drawText('VUE GÉNÉRALE', {
x: MARGIN_X,
y: cursorY,
size: 8,
font: fonts.bodyBold,
color: COLOR_ACCENT,
})
cursorY -= IMAGE_LABEL_GAP
const mainSvgStr = await colorizedSvgString(species.mainSvg, observation, undefined)
const mainPng = await rasterizeSvg(mainSvgStr, 2)
const mainImg = await pdfDoc.embedPng(mainPng)
@@ -125,6 +155,14 @@ export async function addObservationPage(
for (const detailId of detailIds) {
const detailPath = species.details[detailId]
if (!detailPath) continue
page.drawText(`VUE DÉTAIL — ${detailId.toUpperCase()}`, {
x: MARGIN_X,
y: cursorY,
size: 8,
font: fonts.bodyBold,
color: COLOR_ACCENT,
})
cursorY -= IMAGE_LABEL_GAP
const detailSvg = await colorizedSvgString(detailPath, observation, detailId)
const detailPng = await rasterizeSvg(detailSvg, 2)
const dImg = await pdfDoc.embedPng(detailPng)
@@ -146,28 +184,44 @@ export async function addObservationPage(
})
.join(' · ')
const blocks: string[] = [`Zones : ${zonesText}`]
if (observation.pathologyIds.length || observation.freeTextPathologies.length) {
blocks.push(
`Pathologies : ${[...observation.pathologyIds, ...observation.freeTextPathologies].join(' · ')}`,
)
const sections: Array<{ label: string; value: string }> = [
{ label: 'ZONES', value: zonesText || '—' },
]
const pathologies = [
...observation.pathologyIds,
...observation.freeTextPathologies,
]
if (pathologies.length) {
sections.push({ label: 'PATHOLOGIES', value: pathologies.join(' · ') })
}
if (observation.severity) {
sections.push({ label: 'SÉVÉRITÉ', value: observation.severity })
}
if (observation.comment.trim()) {
sections.push({ label: 'COMMENTAIRE', value: observation.comment.trim() })
}
if (observation.severity) blocks.push(`Sévérité : ${observation.severity}`)
if (observation.comment.trim()) blocks.push(`Commentaire : ${observation.comment.trim()}`)
const max = width - MARGIN_X * 2
for (const block of blocks) {
const lines = wrapLines(block, fonts.bodyRegular, 10, max)
for (const { label, value } of sections) {
page.drawText(label, {
x: MARGIN_X,
y: cursorY,
size: 8,
font: fonts.bodyBold,
color: COLOR_ACCENT,
})
cursorY -= SECTION_LABEL_GAP + 9
const lines = wrapLines(value, fonts.bodyRegular, 10, max)
for (const line of lines) {
page.drawText(line, {
x: MARGIN_X,
y: cursorY,
size: 10,
font: fonts.bodyRegular,
color: ink,
color: COLOR_INK,
})
cursorY -= TEXT_LINE_HEIGHT
}
cursorY -= TEXT_BLOCK_GAP
cursorY -= SECTION_BLOCK_GAP
}
}