[poppler] 3 commits - poppler/Annot.cc poppler/Annot.h poppler/Form.cc poppler/Form.h poppler/Link.cc poppler/Link.h
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Fri Jun 21 18:31:37 UTC 2019
poppler/Annot.cc | 58 ++++++++++++++++++++++++++++++++++++++-----------------
poppler/Annot.h | 2 +
poppler/Form.cc | 7 ++++++
poppler/Form.h | 3 +-
poppler/Link.cc | 9 ++++++++
poppler/Link.h | 2 +
6 files changed, 63 insertions(+), 18 deletions(-)
New commits:
commit a4d3db87c3bae5e2a364c828479a6cbb0277069e
Author: Albert Astals Cid <aacid at kde.org>
Date: Sun Jun 9 20:18:54 2019 +0200
Add AnnotWidget::setFormAdditionalAction
And the corresponding Form helper
refactor the code that gets the char * from
Annot::FormAdditionalActionsType to a function
diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index eb902591..8a0c261d 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -232,6 +232,14 @@ static LinkAction* getAdditionalAction(Annot::AdditionalActionsType type, Object
return linkAction;
}
+static const char *getFormAdditionalActionKey(Annot::FormAdditionalActionsType type)
+{
+ return (type == Annot::actionFieldModified ? "K" :
+ type == Annot::actionFormatField ? "F" :
+ type == Annot::actionValidateField ? "V" :
+ type == Annot::actionCalculateField ? "C" : nullptr);
+}
+
//------------------------------------------------------------------------
// AnnotBorderEffect
//------------------------------------------------------------------------
@@ -3777,10 +3785,7 @@ LinkAction* AnnotWidget::getFormAdditionalAction(FormAdditionalActionsType formA
Object additionalActionsObject = additionalActions.fetch(doc->getXRef());
if (additionalActionsObject.isDict()) {
- const char *key = (formAdditionalActionType == Annot::actionFieldModified ? "K" :
- formAdditionalActionType == Annot::actionFormatField ? "F" :
- formAdditionalActionType == Annot::actionValidateField ? "V" :
- formAdditionalActionType == Annot::actionCalculateField ? "C" : nullptr);
+ const char *key = getFormAdditionalActionKey(formAdditionalActionType);
Object actionObject = additionalActionsObject.dictLookup(key);
if (actionObject.isDict())
@@ -3790,6 +3795,29 @@ LinkAction* AnnotWidget::getFormAdditionalAction(FormAdditionalActionsType formA
return linkAction;
}
+bool AnnotWidget::setFormAdditionalAction(FormAdditionalActionsType formAdditionalActionType, const GooString &js)
+{
+ Object additionalActionsObject = additionalActions.fetch(doc->getXRef());
+
+ if (!additionalActionsObject.isDict()) {
+ additionalActionsObject = Object(new Dict(doc->getXRef()));
+ annotObj.dictSet("AA", additionalActionsObject.copy());
+ }
+
+ additionalActionsObject.dictSet(getFormAdditionalActionKey(formAdditionalActionType),
+ LinkJavaScript::createObject(doc->getXRef(), js));
+
+ if (additionalActions.isRef()) {
+ doc->getXRef()->setModifiedObject(&additionalActionsObject, additionalActions.getRef());
+ } else if (hasRef) {
+ doc->getXRef()->setModifiedObject(&annotObj, ref);
+ } else {
+ error(errInternal, -1, "AnnotWidget::setFormAdditionalAction, where neither additionalActions is ref nor annotobj itself is ref");
+ return false;
+ }
+ return true;
+}
+
// Grand unified handler for preparing text strings to be drawn into form
// fields. Takes as input a text string (in PDFDocEncoding or UTF-16).
// Converts some or all of this string to the appropriate encoding for the
diff --git a/poppler/Annot.h b/poppler/Annot.h
index 96a46c7f..88c165f2 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -1410,6 +1410,8 @@ public:
LinkAction *getFormAdditionalAction(FormAdditionalActionsType type); // The caller should delete the result
Dict *getParent() { return parent; }
+ bool setFormAdditionalAction(FormAdditionalActionsType type, const GooString &js);
+
private:
void initialize(PDFDoc *docA, Dict *dict);
diff --git a/poppler/Form.cc b/poppler/Form.cc
index 3efa6b4f..258d235e 100644
--- a/poppler/Form.cc
+++ b/poppler/Form.cc
@@ -177,6 +177,13 @@ LinkAction *FormWidget::getAdditionalAction(Annot::FormAdditionalActionsType t)
return widget ? widget->getFormAdditionalAction(t) : nullptr;
}
+bool FormWidget::setAdditionalAction(Annot::FormAdditionalActionsType t, const GooString &js) {
+ if (!widget)
+ return false;
+
+ return widget->setFormAdditionalAction(t, js);
+}
+
FormWidgetButton::FormWidgetButton (PDFDoc *docA, Object *aobj, unsigned num, Ref refA, FormField *p) :
FormWidget(docA, aobj, num, refA, p)
{
diff --git a/poppler/Form.h b/poppler/Form.h
index 9cc82fc8..923b6c8f 100644
--- a/poppler/Form.h
+++ b/poppler/Form.h
@@ -6,7 +6,7 @@
//
// Copyright 2006 Julien Rebetez <julienr at svn.gnome.org>
// Copyright 2007, 2008, 2011 Carlos Garcia Campos <carlosgc at gnome.org>
-// Copyright 2007-2010, 2012, 2015-2018 Albert Astals Cid <aacid at kde.org>
+// Copyright 2007-2010, 2012, 2015-2019 Albert Astals Cid <aacid at kde.org>
// Copyright 2010 Mark Riedesel <mark at klowner.com>
// Copyright 2011 Pino Toscano <pino at kde.org>
// Copyright 2012 Fabio D'Urso <fabiodurso at hotmail.it>
@@ -119,6 +119,7 @@ public:
LinkAction *getActivationAction(); // The caller should not delete the result
LinkAction *getAdditionalAction(Annot::FormAdditionalActionsType type); // The caller should delete the result
+ bool setAdditionalAction(Annot::FormAdditionalActionsType t, const GooString &js);
// return the unique ID corresponding to pageNum/fieldNum
static int encodeID (unsigned pageNum, unsigned fieldNum);
commit f5e49ed4c604e735ee26427eb1a46536938ed80c
Author: Albert Astals Cid <aacid at kde.org>
Date: Sun Jun 9 20:15:47 2019 +0200
Add LinkJavaScript::createObject
Creates an Object that represents a a LinkJavaScript with the given text
diff --git a/poppler/Link.cc b/poppler/Link.cc
index 5a5e8682..bbba89c9 100644
--- a/poppler/Link.cc
+++ b/poppler/Link.cc
@@ -823,6 +823,15 @@ LinkJavaScript::~LinkJavaScript() {
}
}
+Object LinkJavaScript::createObject(XRef *xref, const GooString &js)
+{
+ Dict *linkDict = new Dict(xref);
+ linkDict->add("S", Object(objName, "JavaScript"));
+ linkDict->add("JS", Object(js.copy()));
+
+ return Object(linkDict);
+}
+
//------------------------------------------------------------------------
// LinkOCGState
//------------------------------------------------------------------------
diff --git a/poppler/Link.h b/poppler/Link.h
index c1079bd5..d610fad0 100644
--- a/poppler/Link.h
+++ b/poppler/Link.h
@@ -427,6 +427,8 @@ public:
LinkActionKind getKind() const override { return actionJavaScript; }
const GooString *getScript() const { return js; }
+ static Object createObject(XRef *xref, const GooString &js);
+
private:
GooString *js;
commit 4867583bf4a26566fd20345c45280ea21254c89c
Author: Albert Astals Cid <aacid at kde.org>
Date: Sun Jun 9 18:43:24 2019 +0200
Annot: Move implementation of getFormAdditionalAction
No idea why it was implemented as a static, it's not reused or anything
diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 5993d30e..eb902591 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -232,24 +232,6 @@ static LinkAction* getAdditionalAction(Annot::AdditionalActionsType type, Object
return linkAction;
}
-static LinkAction* getFormAdditionalAction(Annot::FormAdditionalActionsType type, Object *additionalActions, PDFDoc *doc) {
- LinkAction *linkAction = nullptr;
- Object additionalActionsObject = additionalActions->fetch(doc->getXRef());
-
- if (additionalActionsObject.isDict()) {
- const char *key = (type == Annot::actionFieldModified ? "K" :
- type == Annot::actionFormatField ? "F" :
- type == Annot::actionValidateField ? "V" :
- type == Annot::actionCalculateField ? "C" : nullptr);
-
- Object actionObject = additionalActionsObject.dictLookup(key);
- if (actionObject.isDict())
- linkAction = LinkAction::parseAction(&actionObject, doc->getCatalog()->getBaseURI());
- }
-
- return linkAction;
-}
-
//------------------------------------------------------------------------
// AnnotBorderEffect
//------------------------------------------------------------------------
@@ -3791,7 +3773,21 @@ LinkAction* AnnotWidget::getAdditionalAction(AdditionalActionsType additionalAct
LinkAction* AnnotWidget::getFormAdditionalAction(FormAdditionalActionsType formAdditionalActionType)
{
- return ::getFormAdditionalAction(formAdditionalActionType, &additionalActions, doc);
+ LinkAction *linkAction = nullptr;
+ Object additionalActionsObject = additionalActions.fetch(doc->getXRef());
+
+ if (additionalActionsObject.isDict()) {
+ const char *key = (formAdditionalActionType == Annot::actionFieldModified ? "K" :
+ formAdditionalActionType == Annot::actionFormatField ? "F" :
+ formAdditionalActionType == Annot::actionValidateField ? "V" :
+ formAdditionalActionType == Annot::actionCalculateField ? "C" : nullptr);
+
+ Object actionObject = additionalActionsObject.dictLookup(key);
+ if (actionObject.isDict())
+ linkAction = LinkAction::parseAction(&actionObject, doc->getCatalog()->getBaseURI());
+ }
+
+ return linkAction;
}
// Grand unified handler for preparing text strings to be drawn into form
More information about the poppler
mailing list