From ab845b6db29705da9a16c3ae4bef456c8d836825 Mon Sep 17 00:00:00 2001 From: Marek Kasik Date: Wed, 11 Apr 2018 18:34:02 +0200 Subject: [PATCH] glib: Make PrintScaling preference available in API Add poppler_document_get_print_scaling() function and PopplerPrintScaling enum so that applications which use poppler's glib frontend can access this preference. https://bugs.freedesktop.org/show_bug.cgi?id=92779 --- glib/poppler-document.cc | 57 ++++++++++++++++++++++++++++- glib/poppler-document.h | 14 +++++++ glib/reference/poppler-sections.txt | 3 ++ 3 files changed, 73 insertions(+), 1 deletion(-) diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc index e845bc12..87cfbf56 100644 --- a/glib/poppler-document.cc +++ b/glib/poppler-document.cc @@ -36,6 +36,7 @@ #include #include #include +#include #endif #include "poppler.h" @@ -70,7 +71,8 @@ enum { PROP_PAGE_MODE, PROP_VIEWER_PREFERENCES, PROP_PERMISSIONS, - PROP_METADATA + PROP_METADATA, + PROP_PRINT_SCALING }; static void poppler_document_layers_free (PopplerDocument *document); @@ -1315,6 +1317,44 @@ poppler_document_get_page_mode (PopplerDocument *document) return POPPLER_PAGE_MODE_UNSET; } +/** + * poppler_document_get_print_scaling: + * @document: A #PopplerDocument + * + * Returns the print scaling value suggested by author of the document. + * + * Return value: a #PopplerPrintScaling that should be used when document is printed + * + * Since: 0.63 + **/ +PopplerPrintScaling +poppler_document_get_print_scaling (PopplerDocument *document) +{ + Catalog *catalog; + ViewerPreferences *preferences; + PopplerPrintScaling print_scaling = POPPLER_PRINT_SCALING_APP_DEFAULT; + + g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), POPPLER_PRINT_SCALING_APP_DEFAULT); + + catalog = document->doc->getCatalog (); + if (catalog && catalog->isOk ()) { + preferences = catalog->getViewerPreferences(); + if (preferences) { + switch (preferences->getPrintScaling()) { + default: + case ViewerPreferences::PrintScaling::printScalingAppDefault: + print_scaling = POPPLER_PRINT_SCALING_APP_DEFAULT; + break; + case ViewerPreferences::PrintScaling::printScalingNone: + print_scaling = POPPLER_PRINT_SCALING_NONE; + break; + } + } + } + + return print_scaling; +} + /** * poppler_document_get_permissions: * @document: A #PopplerDocument @@ -1443,6 +1483,9 @@ poppler_document_get_property (GObject *object, /* FIXME: write... */ g_value_set_flags (value, POPPLER_VIEWER_PREFERENCES_UNSET); break; + case PROP_PRINT_SCALING: + g_value_set_enum (value, poppler_document_get_print_scaling (document)); + break; case PROP_PERMISSIONS: g_value_set_flags (value, poppler_document_get_permissions (document)); break; @@ -1698,6 +1741,18 @@ poppler_document_class_init (PopplerDocumentClass *klass) POPPLER_VIEWER_PREFERENCES_UNSET, G_PARAM_READABLE)); + /** + * PopplerDocument:print-scaling: + */ + g_object_class_install_property (G_OBJECT_CLASS (klass), + PROP_PRINT_SCALING, + g_param_spec_enum ("print-scaling", + "Print Scaling", + "Print Scaling Viewer Preference", + POPPLER_TYPE_PRINT_SCALING, + POPPLER_PRINT_SCALING_APP_DEFAULT, + G_PARAM_READABLE)); + /** * PopplerDocument:permissions: * diff --git a/glib/poppler-document.h b/glib/poppler-document.h index a7fcea1d..337ab85e 100644 --- a/glib/poppler-document.h +++ b/glib/poppler-document.h @@ -135,6 +135,19 @@ typedef enum /*< flags >*/ POPPLER_VIEWER_PREFERENCES_DIRECTION_RTL = 1 << 6 } PopplerViewerPreferences; +/** + * PopplerPrintScaling: + * @POPPLER_PRINT_SCALING_APP_DEFAULT: current page scaling + * @POPPLER_PRINT_SCALING_NONE: no page scaling + * + * PrintScaling viewer preference + */ +typedef enum +{ + POPPLER_PRINT_SCALING_APP_DEFAULT, + POPPLER_PRINT_SCALING_NONE +} PopplerPrintScaling; + /** * PopplerPermissions: * @POPPLER_PERMISSIONS_OK_TO_PRINT: document can be printer @@ -231,6 +244,7 @@ PopplerPageLayout poppler_document_get_page_layout (PopplerDocument *doc PopplerPageMode poppler_document_get_page_mode (PopplerDocument *document); PopplerPermissions poppler_document_get_permissions (PopplerDocument *document); gchar *poppler_document_get_metadata (PopplerDocument *document); +PopplerPrintScaling poppler_document_get_print_scaling (PopplerDocument *document); /* Attachments */ guint poppler_document_get_n_attachments (PopplerDocument *document); diff --git a/glib/reference/poppler-sections.txt b/glib/reference/poppler-sections.txt index af1bbba9..d5f918fc 100644 --- a/glib/reference/poppler-sections.txt +++ b/glib/reference/poppler-sections.txt @@ -153,6 +153,7 @@ poppler_document_get_page_layout poppler_document_get_page_mode poppler_document_get_permissions poppler_document_get_metadata +poppler_document_get_print_scaling poppler_document_is_linearized poppler_document_get_n_pages poppler_document_get_page @@ -214,6 +215,7 @@ POPPLER_TYPE_PAGE_LAYOUT POPPLER_TYPE_PAGE_MODE POPPLER_TYPE_PERMISSIONS POPPLER_TYPE_VIEWER_PREFERENCES +POPPLER_TYPE_PRINT_SCALING poppler_document_get_type @@ -227,6 +229,7 @@ poppler_page_layout_get_type poppler_page_mode_get_type poppler_permissions_get_type poppler_viewer_preferences_get_type +poppler_print_scaling_get_type
-- 2.17.0