[evince/wip/chpe/issue-1711: 2/3] libdocument: Make EvDocumentInfo extensible
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince/wip/chpe/issue-1711: 2/3] libdocument: Make EvDocumentInfo extensible
- Date: Thu, 2 Dec 2021 17:35:29 +0000 (UTC)
commit 8cd939fa58fcc82dae4453c75364382d4d0c4102
Author: Christian Persch <chpe src gnome org>
Date: Thu Dec 2 18:35:18 2021 +0100
libdocument: Make EvDocumentInfo extensible
Add a EvDocumentInfoExtended, and add ev_document_info_new() for use by
backends.
backend/pdf/ev-poppler.c | 42 +++++++++----------
backend/ps/ev-spectre.c | 12 +++---
backend/xps/xps-document.c | 4 +-
.../libdocument/libevdocument-sections.txt | 1 +
libdocument/ev-document-info.c | 47 ++++++++++++++++++----
libdocument/ev-document-info.h | 6 ++-
libdocument/ev-document.c | 2 +-
7 files changed, 74 insertions(+), 40 deletions(-)
---
diff --git a/backend/pdf/ev-poppler.c b/backend/pdf/ev-poppler.c
index 428656d00..b019fe3b7 100644
--- a/backend/pdf/ev-poppler.c
+++ b/backend/pdf/ev-poppler.c
@@ -1023,27 +1023,27 @@ pdf_document_get_info (EvDocument *document)
char *metadata;
gboolean linearized;
- info = g_new0 (EvDocumentInfo, 1);
-
- info->fields_mask = EV_DOCUMENT_INFO_TITLE |
- EV_DOCUMENT_INFO_FORMAT |
- EV_DOCUMENT_INFO_AUTHOR |
- EV_DOCUMENT_INFO_SUBJECT |
- EV_DOCUMENT_INFO_KEYWORDS |
- EV_DOCUMENT_INFO_LAYOUT |
- EV_DOCUMENT_INFO_START_MODE |
- EV_DOCUMENT_INFO_PERMISSIONS |
- EV_DOCUMENT_INFO_UI_HINTS |
- EV_DOCUMENT_INFO_CREATOR |
- EV_DOCUMENT_INFO_PRODUCER |
- EV_DOCUMENT_INFO_CREATION_DATE |
- EV_DOCUMENT_INFO_MOD_DATE |
- EV_DOCUMENT_INFO_LINEARIZED |
- EV_DOCUMENT_INFO_N_PAGES |
- EV_DOCUMENT_INFO_SECURITY |
- EV_DOCUMENT_INFO_PAPER_SIZE |
- EV_DOCUMENT_INFO_CONTAINS_JS |
- EV_DOCUMENT_INFO_LICENSE;
+ info = ev_document_info_new ();
+
+ info->fields_mask |= EV_DOCUMENT_INFO_TITLE |
+ EV_DOCUMENT_INFO_FORMAT |
+ EV_DOCUMENT_INFO_AUTHOR |
+ EV_DOCUMENT_INFO_SUBJECT |
+ EV_DOCUMENT_INFO_KEYWORDS |
+ EV_DOCUMENT_INFO_LAYOUT |
+ EV_DOCUMENT_INFO_START_MODE |
+ EV_DOCUMENT_INFO_PERMISSIONS |
+ EV_DOCUMENT_INFO_UI_HINTS |
+ EV_DOCUMENT_INFO_CREATOR |
+ EV_DOCUMENT_INFO_PRODUCER |
+ EV_DOCUMENT_INFO_CREATION_DATE |
+ EV_DOCUMENT_INFO_MOD_DATE |
+ EV_DOCUMENT_INFO_LINEARIZED |
+ EV_DOCUMENT_INFO_N_PAGES |
+ EV_DOCUMENT_INFO_SECURITY |
+ EV_DOCUMENT_INFO_PAPER_SIZE |
+ EV_DOCUMENT_INFO_CONTAINS_JS |
+ EV_DOCUMENT_INFO_LICENSE;
g_object_get (PDF_DOCUMENT (document)->document,
"title", &(info->title),
diff --git a/backend/ps/ev-spectre.c b/backend/ps/ev-spectre.c
index 8657e318a..e602d5b13 100644
--- a/backend/ps/ev-spectre.c
+++ b/backend/ps/ev-spectre.c
@@ -246,12 +246,12 @@ ps_document_get_info (EvDocument *document)
SpectrePage *ps_page;
gint width, height;
- info = g_new0 (EvDocumentInfo, 1);
- info->fields_mask = EV_DOCUMENT_INFO_TITLE |
- EV_DOCUMENT_INFO_FORMAT |
- EV_DOCUMENT_INFO_CREATOR |
- EV_DOCUMENT_INFO_N_PAGES |
- EV_DOCUMENT_INFO_PAPER_SIZE;
+ info = ev_document_info_new ();
+ info->fields_mask |= EV_DOCUMENT_INFO_TITLE |
+ EV_DOCUMENT_INFO_FORMAT |
+ EV_DOCUMENT_INFO_CREATOR |
+ EV_DOCUMENT_INFO_N_PAGES |
+ EV_DOCUMENT_INFO_PAPER_SIZE;
creator = spectre_document_get_creator (ps->doc);
diff --git a/backend/xps/xps-document.c b/backend/xps/xps-document.c
index 149705a4a..93635086a 100644
--- a/backend/xps/xps-document.c
+++ b/backend/xps/xps-document.c
@@ -165,8 +165,8 @@ xps_document_get_info (EvDocument *document)
XPSDocument *xps = XPS_DOCUMENT (document);
EvDocumentInfo *info;
- info = g_new0 (EvDocumentInfo, 1);
- info->fields_mask =
+ info = ev_document_info_new ();
+ info->fields_mask |=
EV_DOCUMENT_INFO_N_PAGES |
EV_DOCUMENT_INFO_PAPER_SIZE;
diff --git a/help/reference/libdocument/libevdocument-sections.txt
b/help/reference/libdocument/libevdocument-sections.txt
index 54095eda7..1a9907432 100644
--- a/help/reference/libdocument/libevdocument-sections.txt
+++ b/help/reference/libdocument/libevdocument-sections.txt
@@ -878,6 +878,7 @@ EvDocumentMode
EvDocumentUIHints
EvDocumentPermissions
EvDocumentInfoFields
+ev_document_info_new
ev_document_info_copy
ev_document_info_free
ev_document_license_new
diff --git a/libdocument/ev-document-info.c b/libdocument/ev-document-info.c
index 24e765f56..1215c049c 100644
--- a/libdocument/ev-document-info.c
+++ b/libdocument/ev-document-info.c
@@ -25,8 +25,30 @@
#include "ev-document-info.h"
+typedef struct _EvDocumentInfoExtended EvDocumentInfoExtended;
+struct _EvDocumentInfoExtended {
+ EvDocumentInfo info;
+};
+
G_DEFINE_BOXED_TYPE (EvDocumentInfo, ev_document_info, ev_document_info_copy, ev_document_info_free)
+/**
+ * ev_document_info_new:
+ * @info: a #EvDocumentInfo
+ *
+ * Returns: (transfer full): a new, empty #EvDocumentInfo
+ */
+EvDocumentInfo *
+ev_document_info_new (void)
+{
+ EvDocumentInfoExtended *info_ex;
+
+ info_ex = g_new0 (EvDocumentInfoExtended, 1);
+ info_ex->info.fields_mask |= _EV_DOCUMENT_INFO_EXTENDED;
+
+ return &info_ex->info;
+}
+
/**
* ev_document_info_copy:
* @info: a #EvDocumentInfo
@@ -36,11 +58,16 @@ G_DEFINE_BOXED_TYPE (EvDocumentInfo, ev_document_info, ev_document_info_copy, ev
EvDocumentInfo *
ev_document_info_copy (EvDocumentInfo *info)
{
- EvDocumentInfo *copy;
+ EvDocumentInfoExtended *info_ex = (EvDocumentInfoExtended*)info;
+ EvDocumentInfo *copy;
+ EvDocumentInfoExtended *copy_ex;
+
+ g_return_val_if_fail (info_ex != NULL, NULL);
+ g_return_val_if_fail (info_ex->info.fields_mask & _EV_DOCUMENT_INFO_EXTENDED, NULL);
- g_return_val_if_fail (info != NULL, NULL);
+ copy = ev_document_info_new ();
+ copy_ex = (EvDocumentInfoExtended*)copy;
- copy = g_new0 (EvDocumentInfo, 1);
copy->title = g_strdup (info->title);
copy->format = g_strdup (info->format);
copy->author = g_strdup (info->author);
@@ -60,9 +87,9 @@ ev_document_info_copy (EvDocumentInfo *info)
copy->n_pages = info->n_pages;
copy->license = ev_document_license_copy (info->license);
- copy->fields_mask = info->fields_mask;
+ copy->fields_mask |= info->fields_mask;
- return copy;
+ return ©_ex->info;
}
/**
@@ -74,8 +101,12 @@ ev_document_info_copy (EvDocumentInfo *info)
void
ev_document_info_free (EvDocumentInfo *info)
{
- if (info == NULL)
- return;
+ EvDocumentInfoExtended *info_ex = (EvDocumentInfoExtended*)info;
+
+ if (info_ex == NULL)
+ return;
+
+ g_return_if_fail (info_ex->info.fields_mask & _EV_DOCUMENT_INFO_EXTENDED);
g_free (info->title);
g_free (info->format);
@@ -90,7 +121,7 @@ ev_document_info_free (EvDocumentInfo *info)
g_clear_pointer (&(info->modified_date), g_date_time_unref);
ev_document_license_free (info->license);
- g_free (info);
+ g_free (info_ex);
}
/* EvDocumentLicense */
diff --git a/libdocument/ev-document-info.h b/libdocument/ev-document-info.h
index b75a970d3..1068325a2 100644
--- a/libdocument/ev-document-info.h
+++ b/libdocument/ev-document-info.h
@@ -110,8 +110,8 @@ typedef enum
EV_DOCUMENT_INFO_SECURITY = 1 << 15,
EV_DOCUMENT_INFO_PAPER_SIZE = 1 << 16,
EV_DOCUMENT_INFO_LICENSE = 1 << 17,
- EV_DOCUMENT_INFO_CONTAINS_JS = 1 << 18
-
+ EV_DOCUMENT_INFO_CONTAINS_JS = 1 << 18,
+ _EV_DOCUMENT_INFO_EXTENDED = 1 << 30 /*< skip >*/
} EvDocumentInfoFields;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
@@ -146,6 +146,8 @@ G_GNUC_END_IGNORE_DEPRECATIONS
EV_PUBLIC
GType ev_document_info_get_type (void) G_GNUC_CONST;
EV_PUBLIC
+EvDocumentInfo* ev_document_info_new (void);
+EV_PUBLIC
EvDocumentInfo *ev_document_info_copy (EvDocumentInfo *info);
EV_PUBLIC
void ev_document_info_free (EvDocumentInfo *info);
diff --git a/libdocument/ev-document.c b/libdocument/ev-document.c
index dc7eca3f6..1be739c9b 100644
--- a/libdocument/ev-document.c
+++ b/libdocument/ev-document.c
@@ -102,7 +102,7 @@ ev_document_impl_get_page (EvDocument *document,
static EvDocumentInfo *
ev_document_impl_get_info (EvDocument *document)
{
- return g_new0 (EvDocumentInfo, 1);
+ return ev_document_info_new ();
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]