[poppler] Form-Reset and Print [patches]

Guillermo Amaral gamaral at kdab.com
Sat Jun 12 19:40:44 PDT 2010


Albert Astals Cid <aacid at kde.org> wrote:
> A Dissabte, 12 de juny de 2010, Guillermo Amaral va escriure:
>> 
>> I wanted to send in these patches, they allow handling of reset-form and
>> print actions respectably.
>> 
>> Please check them out, and if you have any questions please don't hesitate
>> to ask.
> 
> Do you have a document that uses them?

  I do, but I dunno if I can share them ATM, looking into it.
  But I did make a test pdf that uses both features. :-)

> Also what is the point of
> 
> +  } else if (obj2.isName("ResetForm")) {
> +    action = new LinkResetForm(obj2.getName());

  As usual, you are right aacid :) I try a little to hard not to break the
  flow of other programs, I think I went to far lol (fixed)

> And 
> if (obj->dictLookup("AA", &tmp)->isDict())
> seems like an unrelated fix, can you please explain it too?

  Mixed them up, that one should be in the print patch (moved). Sometimes the
  AA dict is used to hold a ref to the named object. I have seen it in two docs so
  far, it seems to happen when people set an action to happen on mouse down
  instead of mouse up. It should not break anything else (as far as I can see).

  Example in attached test.pdf.
  
-- 
Guillermo Amaral | guillermo.amaral at kdab.com | Software Desperado
Klarälvdalens Datakonsult AB, a KDAB Group company
Tel. Sweden (HQ) +46-563-540090, USA +1-866-777-KDAB(5322)
KDAB - Qt Experts - Platform-independent software solutions

-------------- next part --------------
diff --git a/qt4/src/poppler-form.cc b/qt4/src/poppler-form.cc
index 6224b68..4ce4465 100644
--- a/qt4/src/poppler-form.cc
+++ b/qt4/src/poppler-form.cc
@@ -139,14 +139,24 @@ Link* FormField::activationAction() const
   Object tmp;
   Object *obj = m_formData->fm->getObj();
   Link* action = 0;
+  ::LinkAction *act = 0;
+
   if (obj->dictLookup("A", &tmp)->isDict())
   {
-    ::LinkAction *act = ::LinkAction::parseAction(&tmp, m_formData->doc->doc->getCatalog()->getBaseURI());
-    if (act)
-    {
-      action = PageData::convertLinkActionToLink(act, m_formData->doc, QRectF());
-      delete act;
-    }
+    act = ::LinkAction::parseAction(&tmp, m_formData->doc->doc->getCatalog()->getBaseURI());
+  }
+  else if (obj->dictLookup("AA", &tmp)->isDict())
+  {
+    Object tmp1;
+    if (tmp.dictLookup("D", &tmp1)->isDict())
+      act = ::LinkAction::parseAction(&tmp1, m_formData->doc->doc->getCatalog()->getBaseURI());
+    tmp1.free();
+  }
+
+  if (act)
+  {
+    action = PageData::convertLinkActionToLink(act, m_formData->doc, QRectF());
+    delete act;
   }
   tmp.free();
   return action;
diff --git a/qt4/src/poppler-link.h b/qt4/src/poppler-link.h
index 6d42cbe..48b558d 100644
--- a/qt4/src/poppler-link.h
+++ b/qt4/src/poppler-link.h
@@ -357,7 +357,8 @@ class POPPLER_QT4_EXPORT LinkAction : public Link
 		                  EndPresentation = 9,
 		                  Find = 10,
 		                  GoToPage = 11,
-		                  Close = 12 };
+		                  Close = 12,
+		                  Print = 13 };
 
 		/**
 		 * The action of the current LinkAction
diff --git a/qt4/src/poppler-page.cc b/qt4/src/poppler-page.cc
index 6dbf50f..8aea6ce 100644
--- a/qt4/src/poppler-page.cc
+++ b/qt4/src/poppler-page.cc
@@ -129,6 +129,8 @@ Link* PageData::convertLinkActionToLink(::LinkAction * a, DocumentData *parentDo
         popplerLink = new LinkAction( linkArea, LinkAction::Find );
       else if ( !strcmp( name, "FullScreen" ) )
         popplerLink = new LinkAction( linkArea, LinkAction::Presentation );
+      else if ( !strcmp( name, "Print" ) )
+        popplerLink = new LinkAction( linkArea, LinkAction::Print );
       else if ( !strcmp( name, "Close" ) )
       {
         // acroread closes the document always, doesnt care whether 
-------------- next part --------------
diff --git a/poppler/Link.cc b/poppler/Link.cc
index 5d7b779..e3d6ce7 100644
--- a/poppler/Link.cc
+++ b/poppler/Link.cc
@@ -124,6 +124,10 @@ LinkAction *LinkAction::parseAction(Object *obj, GooString *baseURI) {
   } else if (obj2.isName("SetOCGState")) {
     action = new LinkOCGState(obj);
 
+  // ResetForm action
+  } else if (obj2.isName("ResetForm")) {
+    action = new LinkResetForm();
+
   // unknown action
   } else if (obj2.isName()) {
     action = new LinkUnknown(obj2.getName());
@@ -856,6 +860,18 @@ LinkOCGState::StateList::~StateList() {
 }
 
 //------------------------------------------------------------------------
+// LinkFormClear
+//------------------------------------------------------------------------
+
+LinkResetForm::LinkResetForm() {
+  action = new GooString("ResetForm");
+}
+
+LinkResetForm::~LinkResetForm() {
+  delete action;
+}
+
+//------------------------------------------------------------------------
 // LinkUnknown
 //------------------------------------------------------------------------
 
diff --git a/poppler/Link.h b/poppler/Link.h
index ea10375..15a594d 100644
--- a/poppler/Link.h
+++ b/poppler/Link.h
@@ -53,6 +53,7 @@ enum LinkActionKind {
   actionSound,			// sound action
   actionJavaScript,		// JavaScript action
   actionOCGState,               // Set-OCG-State action
+  actionResetForm,              // Reset form action
   actionUnknown			// anything else
 };
 
@@ -429,6 +430,31 @@ private:
 };
 
 //------------------------------------------------------------------------
+// LinkResetForm
+//------------------------------------------------------------------------
+
+class LinkResetForm: public LinkAction {
+public:
+
+  // Build a LinkResetForm with the specified action type.
+  LinkResetForm();
+
+  // Destructor.
+  virtual ~LinkResetForm();
+
+  // Was the LinkResetForm create successfully?
+  virtual GBool isOk() { return action != NULL; }
+
+  // Accessors.
+  virtual LinkActionKind getKind() { return actionResetForm; }
+  GooString *getAction() { return action; }
+
+private:
+
+  GooString *action;		// action subtype
+};
+
+//------------------------------------------------------------------------
 // LinkUnknown
 //------------------------------------------------------------------------
 
diff --git a/qt4/src/poppler-link.cc b/qt4/src/poppler-link.cc
index de06242..17779b5 100644
--- a/qt4/src/poppler-link.cc
+++ b/qt4/src/poppler-link.cc
@@ -179,6 +179,19 @@ class LinkMoviePrivate : public LinkPrivate
 	}
 #endif
 
+class LinkFormActionPrivate : public LinkPrivate
+{
+	public:
+		LinkFormActionPrivate( const QRectF &area, LinkFormAction::ActionType actionType );
+
+		LinkFormAction::ActionType type;
+};
+
+	LinkFormActionPrivate::LinkFormActionPrivate( const QRectF &area, LinkFormAction::ActionType actionType )
+		: LinkPrivate( area ), type( actionType )
+	{
+	}
+
 	static void cvtUserToDev(::Page *page, double xu, double yu, int *xd, int *yd) {
 		double ctm[6];
 		
@@ -581,4 +594,25 @@ class LinkMoviePrivate : public LinkPrivate
 	}
 #endif
 
+	// LinkFormAction
+	LinkFormAction::LinkFormAction( const QRectF &linkArea, ActionType actionType )
+		: Link( *new LinkFormActionPrivate( linkArea, actionType ) )
+	{
+	}
+		
+	LinkFormAction::~LinkFormAction()
+	{
+	}
+	
+	LinkFormAction::ActionType LinkFormAction::actionType() const
+	{
+		Q_D( const LinkFormAction );
+		return d->type;
+	}
+
+	Link::LinkType LinkFormAction::linkType() const
+	{
+		return FormAction;
+	}
+
 }
diff --git a/qt4/src/poppler-link.h b/qt4/src/poppler-link.h
index 6d42cbe..f037642 100644
--- a/qt4/src/poppler-link.h
+++ b/qt4/src/poppler-link.h
@@ -39,6 +39,7 @@ class LinkJavaScriptPrivate;
 class LinkMoviePrivate;
 class LinkDestinationData;
 class LinkDestinationPrivate;
+class LinkFormActionPrivate;
 class SoundObject;
 
 /**
@@ -182,7 +183,8 @@ class POPPLER_QT4_EXPORT Link
 		    Action,   ///< A "standard" action to be executed in the viewer
 		    Sound,    ///< A link representing a sound to be played
 		    Movie,    ///< An action to be executed on a movie
-		    JavaScript    ///< A JavaScript code to be interpreted \since 0.10
+		    JavaScript,   ///< A JavaScript code to be interpreted \since 0.10
+		    FormAction    ///< A "form" action to be executed in the viewer
 		};
 
 		/**
@@ -484,6 +486,46 @@ class POPPLER_QT4_EXPORT LinkMovie : public Link
 };
 #endif
 
+/**
+ * \brief "Form" action request.
+ *
+ * The LinkFormAction class represents a link that request a "form" action
+ * to be performed by the viewer on the displayed document.
+ */
+class POPPLER_QT4_EXPORT LinkFormAction : public Link
+{
+	public:
+		/**
+		 * The possible types of actions
+		 */
+		enum ActionType { Submit = 1,
+		                  Reset = 2,
+		                  ImportData = 3 };
+
+		/**
+		 * The action of the current LinkFormAction
+		 */
+		ActionType actionType() const;
+
+		/**
+		 * Create a new Action link, that executes a specified action
+		 * on the document.
+		 *
+		 * \param linkArea the active area of the link
+		 * \param actionType which action should be executed
+		 */
+		LinkFormAction( const QRectF &linkArea, ActionType actionType );
+		/**
+		 * Destructor.
+		 */
+		~LinkFormAction();
+		LinkType linkType() const;
+
+	private:
+		Q_DECLARE_PRIVATE( LinkFormAction )
+		Q_DISABLE_COPY( LinkFormAction )
+};
+
 }
 
 #endif
diff --git a/qt4/src/poppler-page.cc b/qt4/src/poppler-page.cc
index 6dbf50f..b0b2871 100644
--- a/qt4/src/poppler-page.cc
+++ b/qt4/src/poppler-page.cc
@@ -174,6 +174,10 @@ Link* PageData::convertLinkActionToLink(::LinkAction * a, DocumentData *parentDo
           copyString( m_uri, m->getTitle()->getCString() );
 */  break;
 
+    case actionResetForm:
+        popplerLink = new LinkFormAction( linkArea, LinkFormAction::Reset );
+    break;
+
     case actionUnknown:
     break;
   }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.pdf
Type: application/pdf
Size: 26457 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/poppler/attachments/20100612/bd09d98d/attachment-0001.pdf>


More information about the poppler mailing list