[poppler] glib/demo glib/poppler-action.cc glib/poppler-action.h glib/poppler-document.cc glib/poppler-document.h glib/reference
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Thu Jun 11 15:56:11 UTC 2020
glib/demo/utils.c | 3 ++
glib/poppler-action.cc | 34 ++++++++++++++++++++++++++++++++
glib/poppler-action.h | 15 +++++++++++++-
glib/poppler-document.cc | 38 ++++++++++++++++++++++++++++++++++++
glib/poppler-document.h | 5 ++++
glib/reference/poppler-sections.txt | 1
6 files changed, 95 insertions(+), 1 deletion(-)
New commits:
commit 9c9c3df8f22a12569d5f7a8d8add7abf92e30446
Author: Marek Kasik <mkasik at redhat.com>
Date: Mon Jun 8 17:27:28 2020 +0200
glib: Add ability to reset forms
Add new PopplerActionType POPPLER_ACTION_RESET_FORM and
its handling to PopplerAction.
Add poppler_document_reset_form() to PopplerDocument.
diff --git a/glib/demo/utils.c b/glib/demo/utils.c
index 2d754b09..24e5ebaf 100644
--- a/glib/demo/utils.c
+++ b/glib/demo/utils.c
@@ -475,6 +475,9 @@ pgd_action_view_set_action (GtkWidget *action_view,
gtk_widget_show (swindow);
}
break;
+ case POPPLER_ACTION_RESET_FORM:
+ pgd_table_add_property (GTK_GRID (table), "<b>Type:</b>", "ResetForm", &row);
+ break;
default:
g_assert_not_reached ();
}
diff --git a/glib/poppler-action.cc b/glib/poppler-action.cc
index f9228897..442b05b7 100644
--- a/glib/poppler-action.cc
+++ b/glib/poppler-action.cc
@@ -143,6 +143,10 @@ poppler_action_free (PopplerAction *action)
if (action->javascript.script)
g_free (action->javascript.script);
break;
+ case POPPLER_ACTION_RESET_FORM:
+ if (action->reset_form.fields)
+ g_list_free_full (action->reset_form.fields, g_free);
+ break;
default:
break;
}
@@ -221,6 +225,16 @@ poppler_action_copy (PopplerAction *action)
if (action->javascript.script)
new_action->javascript.script = g_strdup (action->javascript.script);
break;
+ case POPPLER_ACTION_RESET_FORM:
+ if (action->reset_form.fields) {
+ GList *iter;
+
+ new_action->reset_form.fields = nullptr;
+ for (iter = action->reset_form.fields; iter != nullptr; iter = iter->next)
+ new_action->reset_form.fields = g_list_append (new_action->reset_form.fields,
+ g_strdup ((char *) iter->data));
+ }
+ break;
default:
break;
}
@@ -520,7 +534,23 @@ build_javascript (PopplerAction *action,
const GooString script(link->getScript());
action->javascript.script = _poppler_goo_string_to_utf8 (&script);
}
+}
+
+static void
+build_reset_form (PopplerAction *action,
+ const LinkResetForm *link)
+{
+ const std::vector<std::string>& fields = link->getFields ();
+
+ if (action->reset_form.fields != nullptr)
+ g_list_free_full (action->reset_form.fields, g_free);
+ action->reset_form.fields = nullptr;
+ for (const auto & field : fields) {
+ action->reset_form.fields = g_list_append (action->reset_form.fields, g_strdup (field.c_str ()));
+ }
+
+ action->reset_form.exclude = link->getExclude ();
}
static void
@@ -661,6 +691,10 @@ _poppler_action_new (PopplerDocument *document,
action->type = POPPLER_ACTION_JAVASCRIPT;
build_javascript (action, static_cast<const LinkJavaScript*> (link));
break;
+ case actionResetForm:
+ action->type = POPPLER_ACTION_RESET_FORM;
+ build_reset_form (action, dynamic_cast<const LinkResetForm*> (link));
+ break;
case actionUnknown:
default:
action->type = POPPLER_ACTION_UNKNOWN;
diff --git a/glib/poppler-action.h b/glib/poppler-action.h
index 93a026be..7e60e0b4 100644
--- a/glib/poppler-action.h
+++ b/glib/poppler-action.h
@@ -37,6 +37,7 @@ G_BEGIN_DECLS
* @POPPLER_ACTION_RENDITION: play multimedia content. Since 0.14
* @POPPLER_ACTION_OCG_STATE: state of layer. Since 0.14
* @POPPLER_ACTION_JAVASCRIPT: Javascript. Since 0.18
+ * @POPPLER_ACTION_RESET_FORM: resets form. Since 0.90
*
* Action types
*/
@@ -52,7 +53,8 @@ typedef enum
POPPLER_ACTION_MOVIE, /* movie action */
POPPLER_ACTION_RENDITION, /* rendition action */
POPPLER_ACTION_OCG_STATE, /* Set-OCG-State action */
- POPPLER_ACTION_JAVASCRIPT /* Javascript action */
+ POPPLER_ACTION_JAVASCRIPT, /* Javascript action */
+ POPPLER_ACTION_RESET_FORM /* ResetForm action */
} PopplerActionType;
/**
@@ -148,6 +150,7 @@ typedef struct _PopplerActionMovie PopplerActionMovie;
typedef struct _PopplerActionRendition PopplerActionRendition;
typedef struct _PopplerActionOCGState PopplerActionOCGState;
typedef struct _PopplerActionJavascript PopplerActionJavascript;
+typedef struct _PopplerActionResetForm PopplerActionResetForm;
/**
* PopplerDest:
@@ -284,6 +287,15 @@ struct _PopplerActionJavascript
gchar *script;
};
+struct _PopplerActionResetForm
+{
+ PopplerActionType type;
+ gchar *title;
+
+ GList *fields;
+ gboolean exclude;
+};
+
/**
* PopplerAction:
*
@@ -302,6 +314,7 @@ union _PopplerAction
PopplerActionRendition rendition;
PopplerActionOCGState ocg_state;
PopplerActionJavascript javascript;
+ PopplerActionResetForm reset_form;
};
#define POPPLER_TYPE_ACTION (poppler_action_get_type ())
diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc
index 9a767df1..95400d89 100644
--- a/glib/poppler-document.cc
+++ b/glib/poppler-document.cc
@@ -2002,6 +2002,44 @@ poppler_document_get_metadata (PopplerDocument *document)
return retval;
}
+/**
+ * poppler_document_reset_form:
+ * @document: A #PopplerDocument
+ * @fields: list of fields to reset
+ * @exclude_fields: whether to reset all fields except those in @fields
+ *
+ * Resets the form fields specified by fields if exclude_fields is FALSE.
+ * Resets all others if exclude_fields is TRUE.
+ * All form fields are reset regardless of the exclude_fields flag
+ * if fields is empty.
+ *
+ * Since: 0.90
+ **/
+void
+poppler_document_reset_form (PopplerDocument *document,
+ GList *fields,
+ gboolean exclude_fields)
+{
+ std::vector<std::string> list;
+ Catalog *catalog;
+ GList *iter;
+ Form *form;
+
+ g_return_if_fail (POPPLER_IS_DOCUMENT (document));
+
+ catalog = document->doc->getCatalog ();
+ if (catalog && catalog->isOk ()) {
+ form = catalog->getForm ();
+
+ if (form) {
+ for (iter = fields; iter != nullptr; iter = iter->next)
+ list.emplace_back (std::string ((char *) iter->data));
+
+ form->reset (list, exclude_fields);
+ }
+ }
+}
+
static void
poppler_document_get_property (GObject *object,
guint prop_id,
diff --git a/glib/poppler-document.h b/glib/poppler-document.h
index 98dae9a3..570504f2 100644
--- a/glib/poppler-document.h
+++ b/glib/poppler-document.h
@@ -426,6 +426,11 @@ POPPLER_PUBLIC
PopplerFormField *poppler_document_get_form_field (PopplerDocument *document,
gint id);
+POPPLER_PUBLIC
+void poppler_document_reset_form (PopplerDocument *document,
+ GList *fields,
+ gboolean exclude_fields);
+
/* Interface for getting the Index of a poppler_document */
#define POPPLER_TYPE_INDEX_ITER (poppler_index_iter_get_type ())
POPPLER_PUBLIC
diff --git a/glib/reference/poppler-sections.txt b/glib/reference/poppler-sections.txt
index 65e4ad99..f04a2c62 100644
--- a/glib/reference/poppler-sections.txt
+++ b/glib/reference/poppler-sections.txt
@@ -190,6 +190,7 @@ poppler_document_new_from_data
poppler_document_new_from_file
poppler_document_new_from_gfile
poppler_document_new_from_stream
+poppler_document_reset_form
poppler_document_save
poppler_document_save_a_copy
poppler_document_set_author
More information about the poppler
mailing list