tenta fix pdfservice.js
This commit is contained in:
1 parent
00a9e698c6
commit
4726ce1dfa
1 file changed
+14
-59
@@ -398,7 +398,17 @@ export class PdfService {
|
||||
for (const [i, word] of words.entries()) {
|
||||
// Aplica recuo de parágrafo na primeira linha (apenas se alinhamento for justify ou left)
|
||||
let recuo = 0;
|
||||
if (indent && lines.length === 0 && currentTokens.length === 0 && (align === 'justify' || align === 'left')) {
|
||||
// Detecta se é uma linha de lista (ex: "1. ", "a) ", "1) ") e NÃO aplica recuo
|
||||
const isLista = /^\s*((\d+\.|[a-zA-Z]\)|\d+\)))\s+/.test(
|
||||
lines.length === 0 && currentTokens.length === 0 ? word.text : ''
|
||||
);
|
||||
if (
|
||||
indent &&
|
||||
lines.length === 0 &&
|
||||
currentTokens.length === 0 &&
|
||||
(align === 'justify' || align === 'left') &&
|
||||
!isLista
|
||||
) {
|
||||
recuo = fontSize * 2;
|
||||
}
|
||||
const wordWidth = word.font.widthOfTextAtSize(word.text, fontSize);
|
||||
@@ -436,68 +446,13 @@ export class PdfService {
|
||||
|
||||
// Aplica recuo de parágrafo na primeira linha (apenas se alinhamento for justify ou left)
|
||||
let recuo = 0;
|
||||
if (indent && i === 0 && (align === 'justify' || align === 'left')) {
|
||||
// Detecta se é uma linha de lista (ex: "1. ", "a) ", "1) ") e NÃO aplica recuo
|
||||
const isListaLinha = i === 0 && line.tokens.length > 0 && /^\s*((\d+\.|[a-zA-Z]\)|\d+\)))\s+/.test(line.tokens[0].text);
|
||||
if (indent && i === 0 && (align === 'justify' || align === 'left') && !isListaLinha) {
|
||||
recuo = fontSize * 2;
|
||||
drawX += recuo;
|
||||
}
|
||||
|
||||
// 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, {
|
||||
x: drawX,
|
||||
y,
|
||||
size: fontSize,
|
||||
font: t.font,
|
||||
color
|
||||
});
|
||||
if (t.underline && t.text.trim() !== '') {
|
||||
const underlineY = y - 1.5;
|
||||
page.drawLine({
|
||||
start: { x: drawX, y: underlineY },
|
||||
end: { x: drawX + t.font.widthOfTextAtSize(t.text, fontSize), y: underlineY },
|
||||
thickness: 0.75,
|
||||
color
|
||||
});
|
||||
}
|
||||
drawX += t.font.widthOfTextAtSize(t.text, fontSize);
|
||||
}
|
||||
y -= fontSize * 1.5;
|
||||
continue;
|
||||
}
|
||||
// Justificado (exceto última linha)
|
||||
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) {
|
||||
page.drawText(t.text, {
|
||||
x: drawX,
|
||||
y,
|
||||
size: fontSize,
|
||||
font: t.font,
|
||||
color
|
||||
});
|
||||
if (t.underline && t.text.trim() !== '') {
|
||||
const underlineY = y - 1.5;
|
||||
page.drawLine({
|
||||
start: { x: drawX, y: underlineY },
|
||||
end: { x: drawX + t.font.widthOfTextAtSize(t.text, fontSize), y: underlineY },
|
||||
thickness: 0.75,
|
||||
color
|
||||
});
|
||||
}
|
||||
drawX += t.font.widthOfTextAtSize(t.text, fontSize);
|
||||
if (/^\s+$/.test(t.text)) {
|
||||
drawX += extraSpace;
|
||||
}
|
||||
}
|
||||
y -= fontSize * 1.5;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Alinhamento à esquerda (ou última linha justificada)
|
||||
for (const t of line.tokens) {
|
||||
page.drawText(t.text, {
|
||||
|
||||
Reference in new issue
Block a user