[poppler] poppler/PDFDoc.cc
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon Dec 12 22:58:25 UTC 2022
poppler/PDFDoc.cc | 25 ++++++++++++++++++++-----
1 file changed, 20 insertions(+), 5 deletions(-)
New commits:
commit a563801e1a6be5e70645472d82f4ba8534b454d1
Author: Albert Astals Cid <aacid at kde.org>
Date: Mon Dec 12 23:40:24 2022 +0100
PDFDoc::sign: Find Arial to sign if Helvetica isn't found
At least on my Windows install Helvetica isn't found and signing thus
fails
diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc
index c46ed0c4..e5b6ed55 100644
--- a/poppler/PDFDoc.cc
+++ b/poppler/PDFDoc.cc
@@ -63,6 +63,7 @@
#include <config.h>
#include <poppler-config.h>
+#include <array>
#include <cctype>
#include <clocale>
#include <cstdio>
@@ -2152,6 +2153,24 @@ 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 char *saveFilename, const char *certNickname, const char *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)
@@ -2169,11 +2188,7 @@ bool PDFDoc::sign(const char *saveFilename, const char *certNickname, const char
}
Form *form = catalog->getCreateForm();
- std::string pdfFontName = form->findFontInDefaultResources("Helvetica", "");
- if (pdfFontName.empty()) {
- pdfFontName = form->addFontToDefaultResources("Helvetica", "").fontName;
- }
-
+ const std::string pdfFontName = findPdfFontNameToUseForSigning(form);
if (pdfFontName.empty()) {
return false;
}
More information about the poppler
mailing list