Signature plugin: bugfixing

This commit is contained in:
Jakub Melka 2022-04-24 14:47:39 +02:00
parent c6cfb4cdc8
commit f77e761182
4 changed files with 38 additions and 15 deletions

View File

@ -953,7 +953,15 @@ void PDFCreatePCElementTextTool::setAlignment(Qt::Alignment alignment)
void PDFCreatePCElementTextTool::setPen(const QPen& pen) void PDFCreatePCElementTextTool::setPen(const QPen& pen)
{ {
BaseClass::setPen(pen); BaseClass::setPen(pen);
m_textEditWidget->setAppearance(m_element->getFont(), m_element->getAlignment(), m_element->getRectangle(), std::numeric_limits<int>::max(), pen.color());
QFont font = m_element->getFont();
font.setHintingPreference(QFont::PreferNoHinting);
if (font.pointSizeF() > 0.0)
{
font.setPixelSize(qRound(font.pointSizeF()));
}
m_textEditWidget->setAppearance(font, m_element->getAlignment(), m_element->getRectangle(), std::numeric_limits<int>::max(), pen.color());
emit getProxy()->repaintNeeded(); emit getProxy()->repaintNeeded();
} }

View File

@ -638,6 +638,24 @@ int PDFPageContentScene::getInputPriority() const
return ToolPriority + 1; return ToolPriority + 1;
} }
void PDFPageContentScene::drawElements(QPainter* painter,
PDFInteger pageIndex,
PDFTextLayoutGetter& layoutGetter,
const QMatrix& pagePointToDevicePointMatrix,
const PDFPrecompiledPage* compiledPage,
QList<PDFRenderError>& errors) const
{
for (const auto& element : m_elements)
{
if (element->getPageIndex() != pageIndex)
{
continue;
}
element->drawPage(painter, pageIndex, compiledPage, layoutGetter, pagePointToDevicePointMatrix, errors);
}
}
void PDFPageContentScene::drawPage(QPainter* painter, void PDFPageContentScene::drawPage(QPainter* painter,
PDFInteger pageIndex, PDFInteger pageIndex,
const PDFPrecompiledPage* compiledPage, const PDFPrecompiledPage* compiledPage,
@ -650,16 +668,7 @@ void PDFPageContentScene::drawPage(QPainter* painter,
return; return;
} }
for (const auto& element : m_elements) drawElements(painter, pageIndex, layoutGetter, pagePointToDevicePointMatrix, compiledPage, errors);
{
if (element->getPageIndex() != pageIndex)
{
continue;
}
element->drawPage(painter, pageIndex, compiledPage, layoutGetter, pagePointToDevicePointMatrix, errors);
}
m_manipulator.drawPage(painter, pageIndex, compiledPage, layoutGetter, pagePointToDevicePointMatrix, errors); m_manipulator.drawPage(painter, pageIndex, compiledPage, layoutGetter, pagePointToDevicePointMatrix, errors);
} }
@ -2367,7 +2376,7 @@ void PDFPageContentElementTextBox::drawPage(QPainter* painter,
font.setHintingPreference(QFont::PreferNoHinting); font.setHintingPreference(QFont::PreferNoHinting);
if (font.pointSizeF() > 0.0) if (font.pointSizeF() > 0.0)
{ {
font.setPixelSize(qCeil(font.pointSizeF())); font.setPixelSize(qRound(font.pointSizeF()));
} }
PDFPainterStateGuard guard(painter); PDFPainterStateGuard guard(painter);

View File

@ -534,17 +534,23 @@ public:
virtual const std::optional<QCursor>& getCursor() const override; virtual const std::optional<QCursor>& getCursor() const override;
virtual int getInputPriority() const override; virtual int getInputPriority() const override;
// IDocumentDrawInterface interface
public:
virtual void drawPage(QPainter* painter, virtual void drawPage(QPainter* painter,
PDFInteger pageIndex, PDFInteger pageIndex,
const PDFPrecompiledPage* compiledPage, const PDFPrecompiledPage* compiledPage,
PDFTextLayoutGetter& layoutGetter, PDFTextLayoutGetter& layoutGetter,
const QMatrix& pagePointToDevicePointMatrix, const QMatrix& pagePointToDevicePointMatrix,
QList<PDFRenderError>& errors) const override; QList<PDFRenderError>& errors) const override;
PDFWidget* widget() const; PDFWidget* widget() const;
void setWidget(PDFWidget* newWidget); void setWidget(PDFWidget* newWidget);
void drawElements(QPainter* painter,
PDFInteger pageIndex,
PDFTextLayoutGetter& layoutGetter,
const QMatrix& pagePointToDevicePointMatrix,
const PDFPrecompiledPage* compiledPage,
QList<PDFRenderError>& errors) const;
signals: signals:
/// This signal is emitted when scene has changed (including graphics) /// This signal is emitted when scene has changed (including graphics)
void sceneChanged(bool graphicsOnly); void sceneChanged(bool graphicsOnly);

View File

@ -290,7 +290,7 @@ void SignaturePlugin::onSignElectronically()
QPainter* painter = pageContentStreamBuilder.begin(page->getPageReference()); QPainter* painter = pageContentStreamBuilder.begin(page->getPageReference());
QList<pdf::PDFRenderError> errors; QList<pdf::PDFRenderError> errors;
pdf::PDFTextLayoutGetter nullGetter(nullptr, pageIndex); pdf::PDFTextLayoutGetter nullGetter(nullptr, pageIndex);
m_scene.drawPage(painter, pageIndex, nullptr, nullGetter, QMatrix(), errors); m_scene.drawElements(painter, pageIndex, nullGetter, QMatrix(), nullptr, errors);
pageContentStreamBuilder.end(painter); pageContentStreamBuilder.end(painter);
modifier.markPageContentsChanged(); modifier.markPageContentsChanged();
} }