[poppler] poppler/Form.cc poppler/Form.h poppler/PDFDoc.cc
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Fri May 12 12:02:46 UTC 2023
poppler/Form.cc | 25 +++++++++++++++++++++++--
poppler/Form.h | 4 ++++
poppler/PDFDoc.cc | 21 +--------------------
3 files changed, 28 insertions(+), 22 deletions(-)
New commits:
commit beb63c33457ed41033fb071eb25bb61e393280f6
Author: Andre Heinecke <aheinecke at gnupg.org>
Date: Fri May 5 15:09:00 2023 +0200
Fix crash when signing existing signature
On windows, helvetica is not available and that makes poppler crash, so
fix crash and add fallback to arial.
This has already been implemented for "new" signatures, both the
fallback and the crash in
09fdfecea3a13d30b5c52e1258d17549739d9ea8 and
a563801e1a6be5e70645472d82f4ba8534b454d1
Refactor the fallback code to be reusable and use the same crash guard.
diff --git a/poppler/Form.cc b/poppler/Form.cc
index 9e86abc2..958ff3e1 100644
--- a/poppler/Form.cc
+++ b/poppler/Form.cc
@@ -41,6 +41,7 @@
#include <config.h>
+#include <array>
#include <set>
#include <limits>
#include <cstddef>
@@ -702,9 +703,9 @@ bool FormWidgetSignature::signDocumentWithAppearance(const std::string &saveFile
std::string originalDefaultAppearance = aux ? aux->toStr() : std::string();
Form *form = doc->getCatalog()->getCreateForm();
- std::string pdfFontName = form->findFontInDefaultResources("Helvetica", "");
+ const std::string pdfFontName = form->findPdfFontNameToUseForSigning();
if (pdfFontName.empty()) {
- pdfFontName = form->addFontToDefaultResources("Helvetica", "").fontName;
+ return false;
}
const DefaultAppearance da { { objName, pdfFontName.c_str() }, fontSize, std::move(fontColor) };
@@ -3113,6 +3114,26 @@ void Form::reset(const std::vector<std::string> &fields, bool excludeFields)
}
}
+std::string Form::findPdfFontNameToUseForSigning()
+{
+ static constexpr std::array<const char *, 2> fontsToUseToSign = { "Helvetica", "Arial" };
+ for (const char *fontToUseToSign : fontsToUseToSign) {
+ std::string pdfFontName = findFontInDefaultResources(fontToUseToSign, "");
+ if (!pdfFontName.empty()) {
+ return pdfFontName;
+ }
+
+ pdfFontName = addFontToDefaultResources(fontToUseToSign, "").fontName;
+ if (!pdfFontName.empty()) {
+ return pdfFontName;
+ }
+ }
+
+ error(errInternal, -1, "Form::findPdfFontNameToUseForSigning: No suitable font found'\n");
+
+ return {};
+}
+
//------------------------------------------------------------------------
// FormPageWidgets
//------------------------------------------------------------------------
diff --git a/poppler/Form.h b/poppler/Form.h
index 23c40701..0ead4ea6 100644
--- a/poppler/Form.h
+++ b/poppler/Form.h
@@ -685,6 +685,10 @@ public:
// has the given fontFamily and fontStyle. This makes us relatively sure that we added that font ourselves
std::string findFontInDefaultResources(const std::string &fontFamily, const std::string &fontStyle) const;
+ // Finds in the default resources a font that is suitable to create a signature annotation.
+ // If none is found then it is added to the default resources.
+ std::string findPdfFontNameToUseForSigning();
+
struct AddFontResult
{
std::string fontName;
diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc
index f1b9bfcb..fc2f1c37 100644
--- a/poppler/PDFDoc.cc
+++ b/poppler/PDFDoc.cc
@@ -64,7 +64,6 @@
#include <config.h>
#include <poppler-config.h>
-#include <array>
#include <cctype>
#include <clocale>
#include <cstdio>
@@ -2154,24 +2153,6 @@ bool PDFDoc::hasJavascript()
return jsInfo.containsJS();
}
-static std::string findPdfFontNameToUseForSigning(Form *form)
-{
- static constexpr std::array<const char *, 2> fontsToUseToSign = { "Helvetica", "Arial" };
- for (const char *fontToUseToSign : fontsToUseToSign) {
- std::string pdfFontName = form->findFontInDefaultResources(fontToUseToSign, "");
- if (!pdfFontName.empty()) {
- return pdfFontName;
- }
-
- pdfFontName = form->addFontToDefaultResources(fontToUseToSign, "").fontName;
- if (!pdfFontName.empty()) {
- return pdfFontName;
- }
- }
-
- return {};
-}
-
bool PDFDoc::sign(const std::string &saveFilename, const std::string &certNickname, const std::string &password, GooString *partialFieldName, int page, const PDFRectangle &rect, const GooString &signatureText,
const GooString &signatureTextLeft, double fontSize, double leftFontSize, std::unique_ptr<AnnotColor> &&fontColor, double borderWidth, std::unique_ptr<AnnotColor> &&borderColor,
std::unique_ptr<AnnotColor> &&backgroundColor, const GooString *reason, const GooString *location, const std::string &imagePath, const std::optional<GooString> &ownerPassword, const std::optional<GooString> &userPassword)
@@ -2189,7 +2170,7 @@ bool PDFDoc::sign(const std::string &saveFilename, const std::string &certNickna
}
Form *form = catalog->getCreateForm();
- const std::string pdfFontName = findPdfFontNameToUseForSigning(form);
+ const std::string pdfFontName = form->findPdfFontNameToUseForSigning();
if (pdfFontName.empty()) {
return false;
}
More information about the poppler
mailing list