XFA: bugfixing rich text and paging

This commit is contained in:
Jakub Melka 2021-12-13 11:57:10 +01:00
parent ecd04a8668
commit f355fe545b

@ -10052,7 +10052,6 @@ private:
/// Performs layout (so, using current layout parameters /// Performs layout (so, using current layout parameters
/// and given layouts, it layouts them to the current layout node) /// and given layouts, it layouts them to the current layout node)
/// \param layoutParameters Parameters, which will be lay out /// \param layoutParameters Parameters, which will be lay out
/// \param isTop Are we layouting top item?
void layout(LayoutParameters layoutParameters); void layout(LayoutParameters layoutParameters);
/// Perform flow layout. Does nothing, if layout has positional /// Perform flow layout. Does nothing, if layout has positional
@ -10165,7 +10164,7 @@ void PDFXFALayoutEngine::layout(LayoutParameters layoutParameters)
LayoutParameters& currentLayoutParameters = getLayoutParameters(); LayoutParameters& currentLayoutParameters = getLayoutParameters();
layoutFlow(layoutParameters); layoutFlow(layoutParameters);
std::vector<Layout>& layout = currentLayoutParameters.layout; std::vector<Layout>& layouts = currentLayoutParameters.layout;
if (layoutParameters.nodeArea) if (layoutParameters.nodeArea)
{ {
// Case 2) // Case 2)
@ -10173,21 +10172,42 @@ void PDFXFALayoutEngine::layout(LayoutParameters layoutParameters)
const PDFReal y = layoutParameters.yOffset; const PDFReal y = layoutParameters.yOffset;
// Just translate the layout by area offset // Just translate the layout by area offset
for (Layout& layout : layoutParameters.layout) for (Layout& areaLayout : layoutParameters.layout)
{ {
layout.translate(x, y); areaLayout.translate(x, y);
if (currentLayoutParameters.layoutType == xfa::XFA_BaseNode::LAYOUT::Position)
{
auto it = std::find_if(layouts.begin(), layouts.end(), [&](const auto& layout) { return layout.pageIndex == areaLayout.pageIndex; });
if (it == layouts.end())
{
layouts.emplace_back(std::move(areaLayout));
} }
layout.insert(layout.end(), else
{
// Merge layouts
Layout& layout = *it;
layout.items.insert(layout.items.end(),
std::make_move_iterator(areaLayout.items.begin()),
std::make_move_iterator(areaLayout.items.end()));
}
}
}
if (currentLayoutParameters.layoutType != xfa::XFA_BaseNode::LAYOUT::Position)
{
layouts.insert(layouts.end(),
std::make_move_iterator(layoutParameters.layout.begin()), std::make_move_iterator(layoutParameters.layout.begin()),
std::make_move_iterator(layoutParameters.layout.end())); std::make_move_iterator(layoutParameters.layout.end()));
} }
}
else else
{ {
// Case 3) // Case 3)
if (!layoutPositional(layoutParameters, currentLayoutParameters)) if (!layoutPositional(layoutParameters, currentLayoutParameters))
{ {
// Not a positional layout // Not a positional layout
layout.insert(layout.end(), layouts.insert(layouts.end(),
std::make_move_iterator(layoutParameters.layout.begin()), std::make_move_iterator(layoutParameters.layout.begin()),
std::make_move_iterator(layoutParameters.layout.end())); std::make_move_iterator(layoutParameters.layout.end()));
} }
@ -11876,16 +11896,16 @@ void PDFXFAEngineImpl::drawUiTextEdit(const xfa::XFA_textEdit* textEdit,
QRectF textRect = nominalContentArea; QRectF textRect = nominalContentArea;
textRect = textRect.marginsRemoved(settings.getMargins()); textRect = textRect.marginsRemoved(settings.getMargins());
if (!isRichTextAllowed)
{
int textFlag = int(settings.getAlignment()) | Qt::TextDontClip;
// Do we have space for at least one line? // Do we have space for at least one line?
if (isMultiline && textRect.height() < 1.8 * painter->fontMetrics().lineSpacing()) if (isMultiline && textRect.height() < 1.8 * painter->fontMetrics().lineSpacing())
{ {
isMultiline = false; isMultiline = false;
} }
if (!isRichTextAllowed)
{
int textFlag = int(settings.getAlignment()) | Qt::TextDontClip;
if (isMultiline) if (isMultiline)
{ {
textFlag = textFlag | Qt::TextWordWrap; textFlag = textFlag | Qt::TextWordWrap;
@ -11911,7 +11931,7 @@ void PDFXFAEngineImpl::drawUiTextEdit(const xfa::XFA_textEdit* textEdit,
QTextOption textOption = document.defaultTextOption(); QTextOption textOption = document.defaultTextOption();
textOption.setAlignment(settings.getAlignment()); textOption.setAlignment(settings.getAlignment());
textOption.setWrapMode(QTextOption::ManualWrap); textOption.setWrapMode(isMultiline ? QTextOption::WrapAtWordBoundaryOrAnywhere : QTextOption::ManualWrap);
document.setDefaultTextOption(textOption); document.setDefaultTextOption(textOption);
document.setHtml(html); document.setHtml(html);
@ -11959,7 +11979,7 @@ void PDFXFAEngineImpl::drawUiTextEdit(const xfa::XFA_textEdit* textEdit,
document.setPageSize(size); document.setPageSize(size);
} }
document.drawContents(painter, textRect.translated(-textRect.topLeft())); document.drawContents(painter);
} }
} }
else else