[poppler] glib/poppler-document.cc poppler/PDFDoc.cc poppler/PDFDoc.h
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Tue Feb 1 23:36:17 UTC 2022
glib/poppler-document.cc | 2 -
poppler/PDFDoc.cc | 49 ++++++++++++++++++-----------------------------
poppler/PDFDoc.h | 1
3 files changed, 20 insertions(+), 32 deletions(-)
New commits:
commit b8dab63b747b61de6678d6e8cd852daebd44c27e
Author: Albert Astals Cid <aacid at kde.org>
Date: Mon Jan 24 00:50:30 2022 +0100
Improve PDFDoc::getSignatureFields
diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc
index 787d05d8..c64eb58c 100644
--- a/glib/poppler-document.cc
+++ b/glib/poppler-document.cc
@@ -1783,7 +1783,7 @@ gint poppler_document_get_n_signatures(const PopplerDocument *document)
{
g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), 0);
- return document->doc->getNumSignatureFields();
+ return document->doc->getSignatureFields().size();
}
/**
diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc
index 2f526a5c..6acde17b 100644
--- a/poppler/PDFDoc.cc
+++ b/poppler/PDFDoc.cc
@@ -620,8 +620,11 @@ static void addSignatureFieldsToVector(FormField *ff, std::vector<FormFieldSigna
std::vector<FormFieldSignature *> PDFDoc::getSignatureFields()
{
+ // Unfortunately there's files with signatures in Forms but not in Annots
+ // and files with signatures in Annots but no in forms so we need to search both
std::vector<FormFieldSignature *> res;
+ // First search
const Form *f = catalog->getForm();
if (!f)
return res;
@@ -631,40 +634,26 @@ std::vector<FormFieldSignature *> PDFDoc::getSignatureFields()
FormField *ff = f->getRootField(i);
addSignatureFieldsToVector(ff, res);
}
- return res;
-}
-
-static int sumSignatureFields(FormField *ff)
-{
- int sum = 0;
- if (ff->getNumChildren() == 0) {
- if (ff->getType() == formSignature) {
- sum = 1;
- }
- } else {
- for (int i = 0; i < ff->getNumChildren(); ++i) {
- FormField *children = ff->getChildren(i);
- sum += sumSignatureFields(children);
+ // Second search
+ for (int page = 1; page <= getNumPages(); ++page) {
+ Page *p = getPage(page);
+ if (p) {
+ const std::unique_ptr<FormPageWidgets> pw = p->getFormWidgets();
+ for (int i = 0; i < pw->getNumWidgets(); ++i) {
+ FormWidget *fw = pw->getWidget(i);
+ if (fw->getType() == formSignature) {
+ assert(fw->getField()->getType() == formSignature);
+ FormFieldSignature *ffs = static_cast<FormFieldSignature *>(fw->getField());
+ if (std::find(res.begin(), res.end(), ffs) == res.end()) {
+ res.push_back(ffs);
+ }
+ }
+ }
}
}
- return sum;
-}
-
-int PDFDoc::getNumSignatureFields()
-{
- const Form *f = catalog->getForm();
-
- if (!f)
- return 0;
- const int nRootFields = f->getNumFields();
- int sum = 0;
- for (int i = 0; i < nRootFields; ++i) {
- FormField *ff = f->getRootField(i);
- sum += sumSignatureFields(ff);
- }
- return sum;
+ return res;
}
void PDFDoc::displayPage(OutputDev *out, int page, double hDPI, double vDPI, int rotate, bool useMediaBox, bool crop, bool printing, bool (*abortCheckCbk)(void *data), void *abortCheckCbkData,
diff --git a/poppler/PDFDoc.h b/poppler/PDFDoc.h
index 0c60ed15..61bd74a2 100644
--- a/poppler/PDFDoc.h
+++ b/poppler/PDFDoc.h
@@ -228,7 +228,6 @@ public:
bool isEncrypted() { return xref->isEncrypted(); }
std::vector<FormFieldSignature *> getSignatureFields();
- int getNumSignatureFields();
// Check various permissions.
bool okToPrint(bool ignoreOwnerPW = false) { return xref->okToPrint(ignoreOwnerPW); }
More information about the poppler
mailing list