summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Astals Cid <aacid@kde.org>2022-12-12 23:40:24 +0100
committerAlbert Astals Cid <aacid@kde.org>2022-12-12 23:54:05 +0100
commita563801e1a6be5e70645472d82f4ba8534b454d1 (patch)
tree5e30cb610462e966dc9b091bc716e9612540d9dc
parent09fdfecea3a13d30b5c52e1258d17549739d9ea8 (diff)
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
-rw-r--r--poppler/PDFDoc.cc25
1 files changed, 20 insertions, 5 deletions
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;
}