fix(ticker/pdf): ralentissement ticker à 18 car/s et correction troncature table PDF via truncateToWidth

This commit is contained in:
2026-08-21 22:35:46 +01:00
parent dd0279ad09
commit 7599b98959
2 changed files with 10 additions and 3 deletions
+9 -2
View File
@@ -91,6 +91,13 @@ function kpiBox(doc, x, y, w, h, label, value, color) {
// ─── Table ────────────────────────────────────────────────────────────────────
function truncateToWidth(doc, text, maxWidth) {
if (doc.widthOfString(text) <= maxWidth) return text;
let t = text;
while (t.length > 1 && doc.widthOfString(t + '…') > maxWidth) t = t.slice(0, -1);
return t + '…';
}
function table(doc, { title, headers, rows, colWidths }) {
const pageW = doc.page.width - 80;
const totalW = colWidths.reduce((a, b) => a + b, 0);
@@ -111,7 +118,7 @@ function table(doc, { title, headers, rows, colWidths }) {
doc.fontSize(7.5).font('Helvetica-Bold');
let x = 40;
for (let i = 0; i < headers.length; i++) {
doc.text(headers[i], x + 3, y + 4, { width: widths[i] - 6, height: 11, ellipsis: true });
doc.text(truncateToWidth(doc, headers[i], widths[i] - 6), x + 3, y + 4, { width: widths[i] - 6, lineBreak: false });
x += widths[i];
}
y += 17;
@@ -134,7 +141,7 @@ function table(doc, { title, headers, rows, colWidths }) {
doc.fontSize(7).font('Helvetica');
let x = 40;
for (let i = 0; i < row.length; i++) {
doc.text(String(row[i] ?? '—'), x + 3, y + 4, { width: widths[i] - 6, height: rowH - 4, ellipsis: true });
doc.text(truncateToWidth(doc, String(row[i] ?? '—'), widths[i] - 6), x + 3, y + 4, { width: widths[i] - 6, lineBreak: false });
x += widths[i];
}
stroke(doc, C.border);