From 3529bffbbb6627d2e983d9d58ad5e4f043590958 Mon Sep 17 00:00:00 2001 From: Rodrigo Martins Date: Tue, 22 Apr 2025 12:04:19 -0300 Subject: [PATCH] tenta fix pdfservice.js --- src/server/services/PdfService.ts | 54 ++++++++++++++++--------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/src/server/services/PdfService.ts b/src/server/services/PdfService.ts index 8fd63a2..885e65d 100644 --- a/src/server/services/PdfService.ts +++ b/src/server/services/PdfService.ts @@ -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('')) { - // 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) === '') { boldActive = true; - remainingText = remainingText.substring(3); currentFont = italicActive ? boldItalicFont : boldFont; - } else if (remainingText.startsWith('')) { - // Termina negrito + i += 3; + } + else if (text.substring(i, i+4) === '') { boldActive = false; - remainingText = remainingText.substring(4); currentFont = italicActive ? italicFont : normalFont; - } else if (remainingText.startsWith('')) { - // Começa itálico + i += 4; + } + else if (text.substring(i, i+3) === '') { italicActive = true; - remainingText = remainingText.substring(3); currentFont = boldActive ? boldItalicFont : italicFont; - } else if (remainingText.startsWith('')) { - // Termina itálico + i += 3; + } + else if (text.substring(i, i+4) === '') { 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; } } }