From a2bff3baeb7edef4893eeb79128e2ba02cd2c0ca Mon Sep 17 00:00:00 2001 From: Rodrigo Martins Date: Tue, 22 Apr 2025 09:46:30 -0300 Subject: [PATCH] tenta fix pdfservice.js --- src/server/services/PdfService.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/server/services/PdfService.ts b/src/server/services/PdfService.ts index 679c58c..2c11b8c 100644 --- a/src/server/services/PdfService.ts +++ b/src/server/services/PdfService.ts @@ -392,15 +392,19 @@ export class PdfService { } } - // NOVA ABORDAGEM: calcula o recuo apenas na PRIMEIRA linha do parágrafo, nunca nas demais + // Reformulação: recuo de parágrafo como citação (blockquote) e recuo consistente só na primeira linha let lines: { tokens: { text: string, font: any, underline: boolean, bold: boolean, italic: boolean }[] }[] = []; let currentTokens: { text: string, font: any, underline: boolean, bold: boolean, italic: boolean }[] = []; let currentWidth = 0; - const recuo = indent ? fontSize * 2 : 0; + // Recuo de citação: se indent, recua todo o parágrafo (blockquote); se não, recua só a primeira linha + const blockRecuo = indent ? fontSize * 2 : 0; + const firstLineRecuo = !indent && fontSize * 2; // só para parágrafo normal com recuo na primeira linha + for (const [i, word] of words.entries()) { const wordWidth = word.font.widthOfTextAtSize(word.text, fontSize); - // Só aplica recuo na primeira linha do parágrafo - if (lines.length === 0 && currentTokens.length === 0 && recuo > 0) { + // Se for a primeira linha, aplica recuo de bloco OU recuo de primeira linha + if (lines.length === 0 && currentTokens.length === 0) { + let recuo = blockRecuo || firstLineRecuo; if (wordWidth + recuo + currentWidth > maxWidth) { lines.push({ tokens: currentTokens }); currentTokens = [word]; @@ -432,8 +436,8 @@ export class PdfService { let drawX = x; let totalWidth = line.tokens.reduce((acc, t) => acc + t.font.widthOfTextAtSize(t.text, fontSize), 0); - // Aplica recuo de parágrafo SOMENTE na primeira linha - let lineRecuo = (indent && i === 0) ? recuo : 0; + // Aplica recuo de bloco (blockquote) em todas as linhas se indent, ou só na primeira linha se não for indent + let lineRecuo = indent ? blockRecuo : (i === 0 ? firstLineRecuo : 0); drawX += lineRecuo; // Alinhamento @@ -443,7 +447,6 @@ export class PdfService { drawX = x + (maxWidth - totalWidth) + lineRecuo; } else if (align === 'justify' && i !== lines.length - 1 && line.tokens.length > 1) { // Justify: distribui espaço entre palavras (menos na última linha) - const wordsOnly = line.tokens.filter(t => t.text.trim() !== ''); const spaces = line.tokens.filter(t => /^\s+$/.test(t.text)); const numSpaces = spaces.length; const lineTextWidth = line.tokens.reduce((acc, t) => acc + t.font.widthOfTextAtSize(t.text, fontSize), 0);