qt5/src/poppler-document.cc | 16 +++++++++++++++ qt5/src/poppler-form.cc | 46 ++++++++++++++++++++++---------------------- qt5/src/poppler-private.h | 2 - qt5/src/poppler-qt5.h | 11 ++++++++++ 4 files changed, 52 insertions(+), 23 deletions(-)
New commits: commit 12eeb475fbf3ee0bb43b96ea79d46a426ba809e7 Author: Albert Astals Cid <aa...@kde.org> Date: Fri Apr 10 00:31:40 2020 +0200 qt5: Add Document::signatures Returns all the signatures of a given document, this is better than iterating over all the pages getting the form fields that are of signature type since there's documents with signatures not associated to a given page Fixes part of #895 diff --git a/qt5/src/poppler-document.cc b/qt5/src/poppler-document.cc index e1b8d05b..cba9da39 100644 --- a/qt5/src/poppler-document.cc +++ b/qt5/src/poppler-document.cc @@ -48,6 +48,7 @@ #include <QtCore/QFile> #include <QtCore/QByteArray> +#include "poppler-form.h" #include "poppler-private.h" #include "poppler-page-private.h" #include "poppler-outline-private.h" @@ -829,6 +830,21 @@ namespace Poppler { return result; } + QVector<FormFieldSignature*> Document::signatures() const + { + QVector<FormFieldSignature*> result; + + const std::vector<::FormFieldSignature*> pSignatures = m_doc->doc->getSignatureFields(); + + for (::FormFieldSignature *pSignature : pSignatures) { + ::FormWidget *fw = pSignature->getWidget(0); + ::Page *p = m_doc->doc->getPage(fw->getWidgetAnnotation()->getPageNum()); + result.append(new FormFieldSignature(m_doc, p, static_cast<FormWidgetSignature*>(fw))); + } + + return result; + } + QDateTime convertDate( const char *dateString ) { int year, mon, day, hour, min, sec, tzHours, tzMins; diff --git a/qt5/src/poppler-form.cc b/qt5/src/poppler-form.cc index 1ed419c8..19adbd7b 100644 --- a/qt5/src/poppler-form.cc +++ b/qt5/src/poppler-form.cc @@ -105,29 +105,31 @@ FormFieldIcon::~FormFieldIcon() FormField::FormField(std::unique_ptr<FormFieldData> dd) : m_formData(std::move(dd)) { - const int rotation = m_formData->page->getRotate(); - // reading the coords - double left, top, right, bottom; - m_formData->fm->getRect(&left, &bottom, &right, &top); - // build a normalized transform matrix for this page at 100% scale - GfxState gfxState( 72.0, 72.0, m_formData->page->getCropBox(), rotation, true ); - const double * gfxCTM = gfxState.getCTM(); - double MTX[6]; - double pageWidth = m_formData->page->getCropWidth(); - double pageHeight = m_formData->page->getCropHeight(); - // landscape and seascape page rotation: be sure to use the correct (== rotated) page size - if (((rotation / 90) % 2) == 1) - qSwap(pageWidth, pageHeight); - for ( int i = 0; i < 6; i+=2 ) - { - MTX[i] = gfxCTM[i] / pageWidth; - MTX[i+1] = gfxCTM[i+1] / pageHeight; + if (m_formData->page) { + const int rotation = m_formData->page->getRotate(); + // reading the coords + double left, top, right, bottom; + m_formData->fm->getRect(&left, &bottom, &right, &top); + // build a normalized transform matrix for this page at 100% scale + GfxState gfxState( 72.0, 72.0, m_formData->page->getCropBox(), rotation, true ); + const double * gfxCTM = gfxState.getCTM(); + double MTX[6]; + double pageWidth = m_formData->page->getCropWidth(); + double pageHeight = m_formData->page->getCropHeight(); + // landscape and seascape page rotation: be sure to use the correct (== rotated) page size + if (((rotation / 90) % 2) == 1) + qSwap(pageWidth, pageHeight); + for ( int i = 0; i < 6; i+=2 ) + { + MTX[i] = gfxCTM[i] / pageWidth; + MTX[i+1] = gfxCTM[i+1] / pageHeight; + } + QPointF topLeft; + XPDFReader::transform( MTX, qMin( left, right ), qMax( top, bottom ), topLeft ); + QPointF bottomRight; + XPDFReader::transform( MTX, qMax( left, right ), qMin( top, bottom ), bottomRight ); + m_formData->box = QRectF(topLeft, QSizeF(bottomRight.x() - topLeft.x(), bottomRight.y() - topLeft.y())); } - QPointF topLeft; - XPDFReader::transform( MTX, qMin( left, right ), qMax( top, bottom ), topLeft ); - QPointF bottomRight; - XPDFReader::transform( MTX, qMax( left, right ), qMin( top, bottom ), bottomRight ); - m_formData->box = QRectF(topLeft, QSizeF(bottomRight.x() - topLeft.x(), bottomRight.y() - topLeft.y())); } FormField::~FormField() = default; diff --git a/qt5/src/poppler-private.h b/qt5/src/poppler-private.h index 03312daa..7e612ba1 100644 --- a/qt5/src/poppler-private.h +++ b/qt5/src/poppler-private.h @@ -256,7 +256,7 @@ namespace Poppler { } DocumentData *doc; - ::Page *page; + ::Page *page; // Note for some signatures it can be null since there's signatures that don't belong to a given page ::FormWidget *fm; QRectF box; static POPPLER_QT5_EXPORT ::FormWidget *getFormWidget( const FormField *f ); diff --git a/qt5/src/poppler-qt5.h b/qt5/src/poppler-qt5.h index d32ffa3b..fc2fcc3b 100644 --- a/qt5/src/poppler-qt5.h +++ b/qt5/src/poppler-qt5.h @@ -66,6 +66,7 @@ namespace Poppler { class PageData; class FormField; + class FormFieldSignature; class TextBoxData; @@ -1846,6 +1847,16 @@ QString subject = m_doc->info("Subject"); */ QVector<int> formCalculateOrder() const; + /** + Returns the signatures of this document. + + Prefer to use this over getting the signatures for all the pages of the document + since there are documents with signatures that don't belong to a given page + + \since 0.88 + */ + QVector<FormFieldSignature*> signatures() const; + /** Destructor. */ _______________________________________________ poppler mailing list poppler@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/poppler