tenta fix pdfservice.js

This commit is contained in:
rodrigo committed 2025-04-21 22:57:55 -03:00
1 parent bb5c9e25e2
commit 00a9e698c6
1 file changed
+5 -5
+5 -5
View File
@@ -388,7 +388,6 @@ export class PdfService {
// Corrige: split por espaço, mas preserva espaços como tokens separados
const split = token.text.split(/(\s+)/);
for (const part of split) {
// 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,7 +402,6 @@ export class PdfService {
recuo = fontSize * 2;
}
const wordWidth = word.font.widthOfTextAtSize(word.text, fontSize);
// 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 });
@@ -443,8 +441,10 @@ export class PdfService {
drawX += recuo;
}
// Centralizado
if (align === 'center') {
// CORREÇÃO: Se align não for definido, usar 'left' por padrão, mas se center, centralizar corretamente
let effectiveAlign = align || 'left';
if (effectiveAlign === 'center') {
drawX = x + (maxWidth - totalWidth) / 2;
for (const t of line.tokens) {
page.drawText(t.text, {
@@ -469,7 +469,7 @@ export class PdfService {
continue;
}
// Justificado (exceto última linha)
else if (align === 'justify' && i < lines.length - 1) {
else if (effectiveAlign === 'justify' && i < lines.length - 1) {
const spaceCount = line.tokens.filter(t => /^\s+$/.test(t.text)).length;
const extraSpace = spaceCount > 0 ? (maxWidth - totalWidth) / spaceCount : 0;
for (const t of line.tokens) {