From ee459c77d7d06c3903944105c9aeb32a3e723dba Mon Sep 17 00:00:00 2001 From: Jakub Melka Date: Fri, 3 Dec 2021 20:06:53 +0100 Subject: [PATCH] XFA: Rendering rich text (bugfixes) --- Pdf4QtLib/sources/pdfxfaengine.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/Pdf4QtLib/sources/pdfxfaengine.cpp b/Pdf4QtLib/sources/pdfxfaengine.cpp index d6ba971..2a38a77 100644 --- a/Pdf4QtLib/sources/pdfxfaengine.cpp +++ b/Pdf4QtLib/sources/pdfxfaengine.cpp @@ -11623,7 +11623,6 @@ void PDFXFAEngineImpl::drawUiTextEdit(const xfa::XFA_textEdit* textEdit, painter->translate(textRect.topLeft()); QString html = value.value.toString(); - html.replace("pt", "px"); QTextDocument document; document.setDocumentMargin(0); @@ -11634,7 +11633,6 @@ void PDFXFAEngineImpl::drawUiTextEdit(const xfa::XFA_textEdit* textEdit, textOption.setAlignment(settings.getAlignment()); textOption.setWrapMode(QTextOption::ManualWrap); document.setDefaultTextOption(textOption); - document.setHtml(html); QTextBlock block = document.firstBlock(); @@ -11648,6 +11646,27 @@ void PDFXFAEngineImpl::drawUiTextEdit(const xfa::XFA_textEdit* textEdit, cursor.select(QTextCursor::BlockUnderCursor); cursor.mergeBlockFormat(format); + QVector textFormats = block.textFormats(); + for (const QTextLayout::FormatRange& formatRange : textFormats) + { + QTextCharFormat format = formatRange.format; + QFont font = format.font(); + + if (font.pointSizeF() < 0) + { + continue; + } + + font.setPixelSize(qFloor(font.pointSizeF())); + font.setHintingPreference(QFont::PreferNoHinting); + format.setFont(font, QTextCharFormat::FontPropertiesAll); + + QTextCursor cursor(block); + cursor.setPosition(block.position() + formatRange.start, QTextCursor::MoveAnchor); + cursor.setPosition(block.position() + formatRange.start + formatRange.length, QTextCursor::KeepAnchor); + cursor.mergeCharFormat(format); + } + block = block.next(); }