Commit 12eeb475 authored by Albert Astals Cid's avatar Albert Astals Cid Committed by Albert Astals Cid

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
parent ba311960
......@@ -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;
......
......@@ -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;
......
......@@ -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 );
......
......@@ -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.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment