XFA: Rendering rich text (bugfixes)

This commit is contained in:
Jakub Melka 2021-12-03 20:06:53 +01:00
parent cc387916fe
commit ee459c77d7
1 changed files with 21 additions and 2 deletions

View File

@ -11623,7 +11623,6 @@ void PDFXFAEngineImpl::drawUiTextEdit(const xfa::XFA_textEdit* textEdit,
painter->translate(textRect.topLeft()); painter->translate(textRect.topLeft());
QString html = value.value.toString(); QString html = value.value.toString();
html.replace("pt", "px");
QTextDocument document; QTextDocument document;
document.setDocumentMargin(0); document.setDocumentMargin(0);
@ -11634,7 +11633,6 @@ void PDFXFAEngineImpl::drawUiTextEdit(const xfa::XFA_textEdit* textEdit,
textOption.setAlignment(settings.getAlignment()); textOption.setAlignment(settings.getAlignment());
textOption.setWrapMode(QTextOption::ManualWrap); textOption.setWrapMode(QTextOption::ManualWrap);
document.setDefaultTextOption(textOption); document.setDefaultTextOption(textOption);
document.setHtml(html); document.setHtml(html);
QTextBlock block = document.firstBlock(); QTextBlock block = document.firstBlock();
@ -11648,6 +11646,27 @@ void PDFXFAEngineImpl::drawUiTextEdit(const xfa::XFA_textEdit* textEdit,
cursor.select(QTextCursor::BlockUnderCursor); cursor.select(QTextCursor::BlockUnderCursor);
cursor.mergeBlockFormat(format); cursor.mergeBlockFormat(format);
QVector<QTextLayout::FormatRange> 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(); block = block.next();
} }