diff options
author | Carlos Garcia Campos <carlosgc@gnome.org> | 2010-09-17 13:04:33 +0200 |
---|---|---|
committer | Carlos Garcia Campos <carlosgc@gnome.org> | 2010-09-17 13:04:33 +0200 |
commit | d4a6c17255821925906c17b79b88eebed9edfee1 (patch) | |
tree | 2a574a728b22f9ad3429f2449f81d36e0cf70243 | |
parent | a5fec843dbb40fdd2007b926405b96789b21496d (diff) |
[glib] Add accessor for all PopplerDocument properties
PopplerDocument:linearized is now a boolean value rather than string,
so this commit breaks the API again.
-rw-r--r-- | glib/demo/info.cc | 8 | ||||
-rw-r--r-- | glib/poppler-document.cc | 532 | ||||
-rw-r--r-- | glib/poppler-document.h | 74 | ||||
-rw-r--r-- | glib/reference/poppler-sections.txt | 16 |
4 files changed, 498 insertions, 132 deletions
diff --git a/glib/demo/info.cc b/glib/demo/info.cc index 8aa6dc83..98c30151 100644 --- a/glib/demo/info.cc +++ b/glib/demo/info.cc @@ -118,3 +118,3 @@ pgd_info_create_widget (PopplerDocument *document) gchar *title, *format, *author, *subject; - gchar *keywords, *creator, *producer, *linearized; + gchar *keywords, *creator, *producer; gchar *metadata; @@ -122,2 +122,3 @@ pgd_info_create_widget (PopplerDocument *document) gchar *up_id; + gboolean linearized; GTime creation_date, mod_date; @@ -198,5 +199,4 @@ pgd_info_create_widget (PopplerDocument *document) - pgd_table_add_property (GTK_TABLE (table), "<b>Linearized:</b>", linearized, &row); - g_free (linearized); - + pgd_table_add_property (GTK_TABLE (table), "<b>Linearized:</b>", linearized ? "Yes" : "No", &row); + str = pgd_format_date (creation_date); diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc index aaa26b37..8eb7e3db 100644 --- a/glib/poppler-document.cc +++ b/glib/poppler-document.cc @@ -617,4 +617,4 @@ char *_poppler_goo_string_to_utf8(GooString *s) -static void -info_dict_get_string (Dict *info_dict, const gchar *key, GValue *value) +static gchar * +info_dict_get_string (Dict *info_dict, const gchar *key) { @@ -626,3 +626,3 @@ info_dict_get_string (Dict *info_dict, const gchar *key, GValue *value) obj.free (); - return; + return NULL; } @@ -630,14 +630,10 @@ info_dict_get_string (Dict *info_dict, const gchar *key, GValue *value) goo_value = obj.getString (); - result = _poppler_goo_string_to_utf8(goo_value); - obj.free (); - g_value_set_string (value, result); - - g_free (result); + return result; } -static void -info_dict_get_date (Dict *info_dict, const gchar *key, GValue *value) +static time_t +info_dict_get_date (Dict *info_dict, const gchar *key) { @@ -648,9 +644,10 @@ info_dict_get_date (Dict *info_dict, const gchar *key, GValue *value) obj.free (); - return; + return (time_t)-1; } - if (_poppler_convert_pdf_date_to_gtime (obj.getString (), &result)) - g_value_set_int (value, result); - + if (!_poppler_convert_pdf_date_to_gtime (obj.getString (), &result)) + result = (time_t)-1; obj.free (); + + return result; } @@ -701,2 +698,398 @@ convert_page_mode (Catalog::PageMode pageMode) +/** + * poppler_document_get_pdf_version_string: + * @document: A #PopplerDocument + * + * Returns the PDF version of @document as a string (e.g. PDF-1.6) + * + * Return value: a new allocated string containing the PDF version + * of @document, or %NULL + * + * Since: 0.16 + **/ +gchar * +poppler_document_get_pdf_version_string (PopplerDocument *document) +{ + gchar *retval; + + g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), NULL); + + retval = g_strndup ("PDF-", 15); /* allocates 16 chars, pads with \0s */ + g_ascii_formatd (retval + 4, 15 + 1 - 4, "%.2g", + document->doc->getPDFMajorVersion () + document->doc->getPDFMinorVersion() / 10.0); + return retval; +} + +/** + * poppler_document_get_pdf_version: + * @document: A #PopplerDocument + * @major_version: (allow-none): return location for the PDF major version number + * @minor_version: (allow-none): return location for the PDF minor version number + * + * Returns the major and minor PDF version numbers. + * + * Since: 0.16 + **/ +void +poppler_document_get_pdf_version (PopplerDocument *document, + guint *major_version, + guint *minor_version) +{ + g_return_if_fail (POPPLER_IS_DOCUMENT (document)); + + if (major_version) + *major_version = document->doc->getPDFMajorVersion (); + if (minor_version) + *minor_version = document->doc->getPDFMinorVersion(); +} + +/** + * poppler_document_get_title: + * @document: A #PopplerDocument + * + * Returns the document's title + * + * Return value: a new allocated string containing the title + * of @document, or %NULL + * + * Since: 0.16 + **/ +gchar * +poppler_document_get_title (PopplerDocument *document) +{ + Object obj; + gchar *retval = NULL; + + g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), NULL); + + document->doc->getDocInfo (&obj); + if (obj.isDict ()) + retval = info_dict_get_string (obj.getDict(), "Title"); + obj.free (); + + return retval; +} + +/** + * poppler_document_get_author: + * @document: A #PopplerDocument + * + * Returns the author of the document + * + * Return value: a new allocated string containing the author + * of @document, or %NULL + * + * Since: 0.16 + **/ +gchar * +poppler_document_get_author (PopplerDocument *document) +{ + Object obj; + gchar *retval = NULL; + + g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), NULL); + + document->doc->getDocInfo (&obj); + if (obj.isDict ()) + retval = info_dict_get_string (obj.getDict(), "Author"); + obj.free (); + + return retval; +} + +/** + * poppler_document_get_subject: + * @document: A #PopplerDocument + * + * Returns the subject of the document + * + * Return value: a new allocated string containing the subject + * of @document, or %NULL + * + * Since: 0.16 + **/ +gchar * +poppler_document_get_subject (PopplerDocument *document) +{ + Object obj; + gchar *retval = NULL; + + g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), NULL); + + document->doc->getDocInfo (&obj); + if (obj.isDict ()) + retval = info_dict_get_string (obj.getDict(), "Subject"); + obj.free (); + + return retval; +} + +/** + * poppler_document_get_keywords: + * @document: A #PopplerDocument + * + * Returns the keywords associated to the document + * + * Return value: a new allocated string containing keywords associated + * to @document, or %NULL + * + * Since: 0.16 + **/ +gchar * +poppler_document_get_keywords (PopplerDocument *document) +{ + Object obj; + gchar *retval = NULL; + + g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), NULL); + + document->doc->getDocInfo (&obj); + if (obj.isDict ()) + retval = info_dict_get_string (obj.getDict(), "Keywords"); + obj.free (); + + return retval; +} + +/** + * poppler_document_get_creator: + * @document: A #PopplerDocument + * + * Returns the creator of the document. If the document was converted + * from another format, the creator is the name of the product + * that created the original document from which it was converted. + * + * Return value: a new allocated string containing the creator + * of @document, or %NULL + * + * Since: 0.16 + **/ +gchar * +poppler_document_get_creator (PopplerDocument *document) +{ + Object obj; + gchar *retval = NULL; + + g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), NULL); + + document->doc->getDocInfo (&obj); + if (obj.isDict ()) + retval = info_dict_get_string (obj.getDict(), "Creator"); + obj.free (); + + return retval; +} + +/** + * poppler_document_get_producer: + * @document: A #PopplerDocument + * + * Returns the producer of the document. If the document was converted + * from another format, the producer is the name of the product + * that converted it to PDF + * + * Return value: a new allocated string containing the producer + * of @document, or %NULL + * + * Since: 0.16 + **/ +gchar * +poppler_document_get_producer (PopplerDocument *document) +{ + Object obj; + gchar *retval = NULL; + + g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), NULL); + + document->doc->getDocInfo (&obj); + if (obj.isDict ()) + retval = info_dict_get_string (obj.getDict(), "Producer"); + obj.free (); + + return retval; +} + +/** + * poppler_document_get_creation_date: + * @document: A #PopplerDocument + * + * Returns the date the document was created as seconds since the Epoch + * + * Return value: the date the document was created, or -1 + * + * Since: 0.16 + **/ +time_t +poppler_document_get_creation_date (PopplerDocument *document) +{ + Object obj; + time_t retval = (time_t)-1; + + g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), (time_t)-1); + + document->doc->getDocInfo (&obj); + if (obj.isDict ()) + retval = info_dict_get_date (obj.getDict(), "CreationDate"); + obj.free (); + + return retval; +} + +/** + * poppler_document_get_modification_date: + * @document: A #PopplerDocument + * + * Returns the date the document was most recently modified as seconds since the Epoch + * + * Return value: the date the document was most recently modified, or -1 + * + * Since: 0.16 + **/ +time_t +poppler_document_get_modification_date (PopplerDocument *document) +{ + Object obj; + time_t retval = (time_t)-1; + + g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), (time_t)-1); + + document->doc->getDocInfo (&obj); + if (obj.isDict ()) + retval = info_dict_get_date (obj.getDict(), "ModDate"); + obj.free (); + + return retval; +} + +/** + * poppler_document_is_linearized: + * @document: A #PopplerDocument + * + * Returns whether @document is linearized or not. Linearization of PDF + * enables efficient incremental access of the PDF file in a network environment. + * + * Return value: %TRUE if @document is linearized, %FALSE otherwhise + * + * Since: 0.16 + **/ +gboolean +poppler_document_is_linearized (PopplerDocument *document) +{ + g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), FALSE); + + return document->doc->isLinearized (); +} + +/** + * poppler_document_get_page_layout: + * @document: A #PopplerDocument + * + * Returns the page layout that should be used when the document is opened + * + * Return value: a #PopplerPageLayout that should be used when the document is opened + * + * Since: 0.16 + **/ +PopplerPageLayout +poppler_document_get_page_layout (PopplerDocument *document) +{ + Catalog *catalog; + + g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), POPPLER_PAGE_LAYOUT_UNSET); + + catalog = document->doc->getCatalog (); + if (catalog && catalog->isOk ()) + return convert_page_layout (catalog->getPageLayout ()); + + return POPPLER_PAGE_LAYOUT_UNSET; +} + +/** + * poppler_document_get_page_mode: + * @document: A #PopplerDocument + * + * Returns a #PopplerPageMode representing how the document should + * be initially displayed when opened. + * + * Return value: a #PopplerPageMode that should be used when document is opened + * + * Since: 0.16 + **/ +PopplerPageMode +poppler_document_get_page_mode (PopplerDocument *document) +{ + Catalog *catalog; + + g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), POPPLER_PAGE_MODE_UNSET); + + catalog = document->doc->getCatalog (); + if (catalog && catalog->isOk ()) + return convert_page_mode (catalog->getPageMode ()); + + return POPPLER_PAGE_MODE_UNSET; +} + +/** + * poppler_document_get_permissions: + * @document: A #PopplerDocument + * + * Returns the flags spcifying which operations are permitted when the document is opened. + * + * Return value: a set of falgs from #PopplerPermissions enumeration + * + * Since: 0.16 + **/ +PopplerPermissions +poppler_document_get_permissions (PopplerDocument *document) +{ + guint flag = 0; + + g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), POPPLER_PERMISSIONS_FULL); + + if (document->doc->okToPrint ()) + flag |= POPPLER_PERMISSIONS_OK_TO_PRINT; + if (document->doc->okToChange ()) + flag |= POPPLER_PERMISSIONS_OK_TO_MODIFY; + if (document->doc->okToCopy ()) + flag |= POPPLER_PERMISSIONS_OK_TO_COPY; + if (document->doc->okToAddNotes ()) + flag |= POPPLER_PERMISSIONS_OK_TO_ADD_NOTES; + if (document->doc->okToFillForm ()) + flag |= POPPLER_PERMISSIONS_OK_TO_FILL_FORM; + + return (PopplerPermissions)flag; +} + +/** + * poppler_document_get_metadata: + * @document: A #PopplerDocument + * + * Returns the XML metadata string of the document + * + * Return value: a new allocated string containing the XML + * metadata, or %NULL + * + * Since: 0.16 + **/ +gchar * +poppler_document_get_metadata (PopplerDocument *document) +{ + Catalog *catalog; + gchar *retval = NULL; + + g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), NULL); + + catalog = document->doc->getCatalog (); + if (catalog && catalog->isOk ()) { + GooString *s = catalog->readMetadata (); + + if (s != NULL) { + retval = g_strdup (s->getCString()); + delete s; + } + } + + return retval; +} + static void @@ -708,6 +1101,3 @@ poppler_document_get_property (GObject *object, PopplerDocument *document = POPPLER_DOCUMENT (object); - Object obj; - Catalog *catalog; - gchar *str; - guint flag; + guint version; @@ -716,83 +1106,44 @@ poppler_document_get_property (GObject *object, case PROP_TITLE: - document->doc->getDocInfo (&obj); - if (obj.isDict ()) - info_dict_get_string (obj.getDict(), "Title", value); - obj.free (); + g_value_take_string (value, poppler_document_get_title (document)); break; case PROP_FORMAT: - str = g_strndup("PDF-", 15); /* allocates 16 chars, pads with \0s */ - g_ascii_formatd (str + 4, 15 + 1 - 4, - "%.2g", document->doc->getPDFMajorVersion () + document->doc->getPDFMinorVersion() / 10.0); - g_value_take_string (value, str); + g_value_take_string (value, poppler_document_get_pdf_version_string (document)); break; case PROP_FORMAT_MAJOR: - g_value_set_uint (value, document->doc->getPDFMajorVersion ()); + poppler_document_get_pdf_version (document, &version, NULL); + g_value_set_uint (value, version); break; case PROP_FORMAT_MINOR: - g_value_set_uint (value, document->doc->getPDFMinorVersion()); + poppler_document_get_pdf_version (document, NULL, &version); + g_value_set_uint (value, version); break; case PROP_AUTHOR: - document->doc->getDocInfo (&obj); - if (obj.isDict ()) - info_dict_get_string (obj.getDict(), "Author", value); - obj.free (); + g_value_take_string (value, poppler_document_get_author (document)); break; case PROP_SUBJECT: - document->doc->getDocInfo (&obj); - if (obj.isDict ()) - info_dict_get_string (obj.getDict(), "Subject", value); - obj.free (); + g_value_take_string (value, poppler_document_get_subject (document)); break; case PROP_KEYWORDS: - document->doc->getDocInfo (&obj); - if (obj.isDict ()) - info_dict_get_string (obj.getDict(), "Keywords", value); - obj.free (); + g_value_take_string (value, poppler_document_get_keywords (document)); break; case PROP_CREATOR: - document->doc->getDocInfo (&obj); - if (obj.isDict ()) - info_dict_get_string (obj.getDict(), "Creator", value); - obj.free (); + g_value_take_string (value, poppler_document_get_creator (document)); break; case PROP_PRODUCER: - document->doc->getDocInfo (&obj); - if (obj.isDict ()) - info_dict_get_string (obj.getDict(), "Producer", value); - obj.free (); + g_value_take_string (value, poppler_document_get_producer (document)); break; case PROP_CREATION_DATE: - document->doc->getDocInfo (&obj); - if (obj.isDict ()) - info_dict_get_date (obj.getDict(), "CreationDate", value); - obj.free (); + g_value_set_int (value, poppler_document_get_creation_date (document)); break; case PROP_MOD_DATE: - document->doc->getDocInfo (&obj); - if (obj.isDict ()) - info_dict_get_date (obj.getDict(), "ModDate", value); - obj.free (); - break; + g_value_set_int (value, poppler_document_get_modification_date (document)); + break; case PROP_LINEARIZED: - if (document->doc->isLinearized ()) { - g_value_set_string (value, "Yes"); - } else { - g_value_set_string (value, "No"); - } + g_value_set_boolean (value, poppler_document_is_linearized (document)); break; case PROP_PAGE_LAYOUT: - catalog = document->doc->getCatalog (); - if (catalog && catalog->isOk ()) - { - PopplerPageLayout page_layout = convert_page_layout (catalog->getPageLayout ()); - g_value_set_enum (value, page_layout); - } + g_value_set_enum (value, poppler_document_get_page_layout (document)); break; case PROP_PAGE_MODE: - catalog = document->doc->getCatalog (); - if (catalog && catalog->isOk ()) - { - PopplerPageMode page_mode = convert_page_mode (catalog->getPageMode ()); - g_value_set_enum (value, page_mode); - } + g_value_set_enum (value, poppler_document_get_page_mode (document)); break; @@ -803,25 +1154,6 @@ poppler_document_get_property (GObject *object, case PROP_PERMISSIONS: - flag = 0; - if (document->doc->okToPrint ()) - flag |= POPPLER_PERMISSIONS_OK_TO_PRINT; - if (document->doc->okToChange ()) - flag |= POPPLER_PERMISSIONS_OK_TO_MODIFY; - if (document->doc->okToCopy ()) - flag |= POPPLER_PERMISSIONS_OK_TO_COPY; - if (document->doc->okToAddNotes ()) - flag |= POPPLER_PERMISSIONS_OK_TO_ADD_NOTES; - if (document->doc->okToFillForm ()) - flag |= POPPLER_PERMISSIONS_OK_TO_FILL_FORM; - g_value_set_flags (value, flag); + g_value_set_flags (value, poppler_document_get_permissions (document)); break; case PROP_METADATA: - catalog = document->doc->getCatalog (); - if (catalog && catalog->isOk ()) - { - GooString *s = catalog->readMetadata (); - if ( s != NULL ) { - g_value_set_string (value, s->getCString()); - delete s; - } - } + g_value_take_string (value, poppler_document_get_metadata (document)); break; @@ -942,7 +1274,7 @@ poppler_document_class_init (PopplerDocumentClass *klass) PROP_LINEARIZED, - g_param_spec_string ("linearized", - "Fast Web View Enabled", - "Is the document optimized for web viewing?", - NULL, - G_PARAM_READABLE)); + g_param_spec_boolean ("linearized", + "Fast Web View Enabled", + "Is the document optimized for web viewing?", + FALSE, + G_PARAM_READABLE)); diff --git a/glib/poppler-document.h b/glib/poppler-document.h index 4dc7c99b..5cec9aea 100644 --- a/glib/poppler-document.h +++ b/glib/poppler-document.h @@ -158,35 +158,53 @@ typedef enum /*< flags >*/ -GType poppler_document_get_type (void) G_GNUC_CONST; -PopplerDocument *poppler_document_new_from_file (const char *uri, - const char *password, - GError **error); -PopplerDocument *poppler_document_new_from_data (char *data, - int length, - const char *password, - GError **error); -gboolean poppler_document_save (PopplerDocument *document, - const char *uri, - GError **error); -gboolean poppler_document_save_a_copy (PopplerDocument *document, - const char *uri, - GError **error); -gboolean poppler_document_get_id (PopplerDocument *document, - gchar **permanent_id, - gchar **update_id); -int poppler_document_get_n_pages (PopplerDocument *document); -PopplerPage *poppler_document_get_page (PopplerDocument *document, - int index); -PopplerPage *poppler_document_get_page_by_label (PopplerDocument *document, - const char *label); +GType poppler_document_get_type (void) G_GNUC_CONST; +PopplerDocument *poppler_document_new_from_file (const char *uri, + const char *password, + GError **error); +PopplerDocument *poppler_document_new_from_data (char *data, + int length, + const char *password, + GError **error); +gboolean poppler_document_save (PopplerDocument *document, + const char *uri, + GError **error); +gboolean poppler_document_save_a_copy (PopplerDocument *document, + const char *uri, + GError **error); +gboolean poppler_document_get_id (PopplerDocument *document, + gchar **permanent_id, + gchar **update_id); +int poppler_document_get_n_pages (PopplerDocument *document); +PopplerPage *poppler_document_get_page (PopplerDocument *document, + int index); +PopplerPage *poppler_document_get_page_by_label (PopplerDocument *document, + const char *label); +gchar *poppler_document_get_pdf_version_string (PopplerDocument *document); +void poppler_document_get_pdf_version (PopplerDocument *document, + guint *major_version, + guint *minor_version); +gchar *poppler_document_get_title (PopplerDocument *document); +gchar *poppler_document_get_author (PopplerDocument *document); +gchar *poppler_document_get_subject (PopplerDocument *document); +gchar *poppler_document_get_keywords (PopplerDocument *document); +gchar *poppler_document_get_creator (PopplerDocument *document); +gchar *poppler_document_get_producer (PopplerDocument *document); +time_t poppler_document_get_creation_date (PopplerDocument *document); +time_t poppler_document_get_modification_date (PopplerDocument *document); +gboolean poppler_document_is_linearized (PopplerDocument *document); +PopplerPageLayout poppler_document_get_page_layout (PopplerDocument *document); +PopplerPageMode poppler_document_get_page_mode (PopplerDocument *document); +PopplerPermissions poppler_document_get_permissions (PopplerDocument *document); +gchar *poppler_document_get_metadata (PopplerDocument *document); + /* Attachments */ -gboolean poppler_document_has_attachments (PopplerDocument *document); -GList *poppler_document_get_attachments (PopplerDocument *document); +gboolean poppler_document_has_attachments (PopplerDocument *document); +GList *poppler_document_get_attachments (PopplerDocument *document); /* Links */ -PopplerDest *poppler_document_find_dest (PopplerDocument *document, - const gchar *link_name); +PopplerDest *poppler_document_find_dest (PopplerDocument *document, + const gchar *link_name); /* Form */ -PopplerFormField *poppler_document_get_form_field (PopplerDocument *document, - gint id); +PopplerFormField *poppler_document_get_form_field (PopplerDocument *document, + gint id); diff --git a/glib/reference/poppler-sections.txt b/glib/reference/poppler-sections.txt index 344c3e2a..96eaf750 100644 --- a/glib/reference/poppler-sections.txt +++ b/glib/reference/poppler-sections.txt @@ -114,2 +114,18 @@ poppler_document_save_a_copy poppler_document_get_id +poppler_document_get_pdf_version_string +poppler_document_get_pdf_version +poppler_document_get_title +poppler_document_get_author +poppler_document_get_subject +poppler_document_get_keywords +poppler_document_get_creator +poppler_document_get_producer +poppler_document_get_creation_date +poppler_document_get_modification_date +poppler_document_get_page_layout +poppler_document_get_page_mode +poppler_document_get_permissions +poppler_document_get_metadata +poppler_document_get_permissions +poppler_document_is_linearized poppler_document_get_n_pages |