tenta fix pdfservice.js

This commit is contained in:
rodrigo committed 2025-04-21 22:50:08 -03:00
1 parent a946f86cae
commit bb5c9e25e2
1 file changed
+21 -9
+21 -9
View File
@@ -385,11 +385,11 @@ export class PdfService {
if (token.bold && token.italic) usedFont = fontBoldItalic;
else if (token.bold) usedFont = fontBold;
else if (token.italic) usedFont = fontItalic;
// Corrige: split por espaço, mas preserva espaços como tokens separados
const split = token.text.split(/(\s+)/);
for (const part of split) {
if (part.length > 0) {
words.push({ text: part, font: usedFont, underline: token.underline, bold: token.bold, italic: token.italic });
}
// Adiciona todos os tokens, inclusive espaços, para manter alinhamento correto
words.push({ text: part, font: usedFont, underline: token.underline, bold: token.bold, italic: token.italic });
}
}
@@ -403,13 +403,25 @@ export class PdfService {
recuo = fontSize * 2;
}
const wordWidth = word.font.widthOfTextAtSize(word.text, fontSize);
if (currentWidth + wordWidth + recuo > maxWidth && currentTokens.length > 0) {
lines.push({ tokens: currentTokens });
currentTokens = [word];
currentWidth = wordWidth;
// Se for a primeira palavra da linha, soma o recuo
if (currentTokens.length === 0) {
if (currentWidth + wordWidth + recuo > maxWidth && currentTokens.length > 0) {
lines.push({ tokens: currentTokens });
currentTokens = [word];
currentWidth = wordWidth;
} else {
currentTokens.push(word);
currentWidth += wordWidth + recuo;
}
} else {
currentTokens.push(word);
currentWidth += wordWidth;
if (currentWidth + wordWidth > maxWidth && currentTokens.length > 0) {
lines.push({ tokens: currentTokens });
currentTokens = [word];
currentWidth = wordWidth;
} else {
currentTokens.push(word);
currentWidth += wordWidth;
}
}
}
if (currentTokens.length > 0) {