tenta fix pdfservice.js

This commit is contained in:
rodrigo committed 2025-04-22 12:04:19 -03:00
1 parent db0c011b8b
commit 3529bffbbb
1 file changed
+28 -26
+28 -26
View File
@@ -378,51 +378,53 @@ export class PdfService {
let currentLineWidth = 0;
let textParts = [];
// Detectar formatação inline
let remainingText = text;
// Processa texto com formatação - remover tags HTML e aplicar estilos
let processedText = '';
let currentFont = normalFont;
let boldActive = false;
let italicActive = false;
// Processa texto com formatação
while (remainingText.length > 0) {
if (remainingText.startsWith('<b>')) {
// Começa negrito
// Primeiro, extrair partes do texto com suas formatações
let i = 0;
while (i < text.length) {
if (text.substring(i, i+3) === '<b>') {
boldActive = true;
remainingText = remainingText.substring(3);
currentFont = italicActive ? boldItalicFont : boldFont;
} else if (remainingText.startsWith('</b>')) {
// Termina negrito
i += 3;
}
else if (text.substring(i, i+4) === '</b>') {
boldActive = false;
remainingText = remainingText.substring(4);
currentFont = italicActive ? italicFont : normalFont;
} else if (remainingText.startsWith('<i>')) {
// Começa itálico
i += 4;
}
else if (text.substring(i, i+3) === '<i>') {
italicActive = true;
remainingText = remainingText.substring(3);
currentFont = boldActive ? boldItalicFont : italicFont;
} else if (remainingText.startsWith('</i>')) {
// Termina itálico
i += 3;
}
else if (text.substring(i, i+4) === '</i>') {
italicActive = false;
remainingText = remainingText.substring(4);
currentFont = boldActive ? boldFont : normalFont;
} else {
// Texto normal - procura pela próxima tag de formatação
let nextTag = remainingText.search(/<\/?[bi]>/);
if (nextTag === -1) {
// Não há mais tags, adiciona todo o texto restante
i += 4;
}
else {
// Encontrar o próximo início de tag
let nextTagPos = text.indexOf('<', i);
if (nextTagPos === -1) {
// Não há mais tags, pegar o restante do texto
textParts.push({
text: remainingText,
text: text.substring(i),
font: currentFont
});
remainingText = '';
break;
} else {
// Adiciona texto até a próxima tag
// Pegar texto até a próxima tag
textParts.push({
text: remainingText.substring(0, nextTag),
text: text.substring(i, nextTagPos),
font: currentFont
});
remainingText = remainingText.substring(nextTag);
i = nextTagPos;
}
}
}