From 75f3d31daa050ca822d2ab501cdeca748ddf9d54 Mon Sep 17 00:00:00 2001
From: Marek Kasik <mkasik@redhat.com>
Date: Wed, 2 Jan 2019 14:55:41 +0100
Subject: 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
diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc
index d97d1448..ed37da4c 100644
--- a/glib/poppler-document.cc
+++ b/glib/poppler-document.cc
@@ -36,6 +37,7 @@
#include <FontInfo.h>
#include <PDFDocEncoding.h>
#include <OptionalContent.h>
+#include <ViewerPreferences.h>
#endif
#include "poppler.h"
@@ -78,7 +80,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);
@@ -1516,6 +1519,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.26.5
+ **/
+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::printScalingAppDefault:
+ print_scaling = POPPLER_PRINT_SCALING_APP_DEFAULT;
+ break;
+ case ViewerPreferences::printScalingNone:
+ print_scaling = POPPLER_PRINT_SCALING_NONE;
+ break;
+ }
+ }
+ }
+
+ return print_scaling;
+}
+
/**
* poppler_document_get_permissions:
* @document: A #PopplerDocument
@@ -1746,6 +1787,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;
@@ -2013,6 +2057,20 @@ poppler_document_class_init (PopplerDocumentClass *klass)
POPPLER_VIEWER_PREFERENCES_UNSET,
G_PARAM_READABLE));
+ /**
+ * PopplerDocument:print-scaling:
+ *
+ * Since: 0.26.5
+ */
+ 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,
+ (GParamFlags) (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));
+
/**
* PopplerDocument:permissions:
*
diff --git a/glib/poppler-document.h b/glib/poppler-document.h
index ebf3a9e1..e9eeebfd 100644
--- a/glib/poppler-document.h
+++ b/glib/poppler-document.h
@@ -135,6 +136,21 @@ typedef enum /*< flags >*/
POPPLER_VIEWER_PREFERENCES_DIRECTION_RTL = 1 << 6
} PopplerViewerPreferences;
+/**
+ * PopplerPrintScaling:
+ * @POPPLER_PRINT_SCALING_APP_DEFAULT: application's default page scaling
+ * @POPPLER_PRINT_SCALING_NONE: no page scaling
+ *
+ * PrintScaling viewer preference
+ *
+ * Since: 0.26.5
+ */
+typedef enum
+{
+ POPPLER_PRINT_SCALING_APP_DEFAULT,
+ POPPLER_PRINT_SCALING_NONE
+} PopplerPrintScaling;
+
/**
* PopplerPermissions:
* @POPPLER_PERMISSIONS_OK_TO_PRINT: document can be printer
@@ -356,6 +372,7 @@ POPPLER_PUBLIC
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 39985553..c71c2776 100644
--- a/glib/reference/poppler-sections.txt
+++ b/glib/reference/poppler-sections.txt
@@ -174,6 +174,7 @@ poppler_document_get_pdf_subtype_string
poppler_document_get_page_layout
poppler_document_get_page_mode
poppler_document_get_permissions
+poppler_document_get_print_scaling
poppler_document_get_metadata
poppler_document_is_linearized
poppler_document_get_n_pages
@@ -246,6 +247,7 @@ POPPLER_TYPE_PDF_CONFORMANCE
POPPLER_TYPE_PAGE_LAYOUT
POPPLER_TYPE_PAGE_MODE
POPPLER_TYPE_PERMISSIONS
+POPPLER_TYPE_PRINT_SCALING
POPPLER_TYPE_VIEWER_PREFERENCES
<SUBSECTION Private>
@@ -260,6 +262,7 @@ poppler_pdf_conformance_get_type
poppler_page_layout_get_type
poppler_page_mode_get_type
poppler_permissions_get_type
+poppler_print_scaling_get_type
poppler_viewer_preferences_get_type
</SECTION>
diff --git a/glib/reference/poppler.types b/glib/reference/poppler.types
index 354fdd3a..2f7a3991 100644
--- a/glib/reference/poppler.types
+++ b/glib/reference/poppler.types
@@ -60,5 +60,6 @@ poppler_pdf_subtype_get_type
poppler_layer_get_type
poppler_media_get_type
poppler_movie_get_type
+poppler_print_scaling_get_type
poppler_structure_element_get_type
poppler_structure_element_iter_get_type