c2e870
From 75f3d31daa050ca822d2ab501cdeca748ddf9d54 Mon Sep 17 00:00:00 2001
c2e870
From: Marek Kasik <mkasik@redhat.com>
c2e870
Date: Wed, 2 Jan 2019 14:55:41 +0100
c2e870
Subject: glib: Make PrintScaling preference available in API
c2e870
c2e870
Add poppler_document_get_print_scaling() function and
c2e870
PopplerPrintScaling enum so that applications which
c2e870
use poppler's glib frontend can access this preference.
c2e870
c2e870
https://bugs.freedesktop.org/show_bug.cgi?id=92779
c2e870
c2e870
diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc
c2e870
index d97d1448..ed37da4c 100644
c2e870
--- a/glib/poppler-document.cc
c2e870
+++ b/glib/poppler-document.cc
c2e870
@@ -36,6 +37,7 @@
c2e870
 #include <FontInfo.h>
c2e870
 #include <PDFDocEncoding.h>
c2e870
 #include <OptionalContent.h>
c2e870
+#include <ViewerPreferences.h>
c2e870
 #endif
c2e870
 
c2e870
 #include "poppler.h"
c2e870
@@ -78,7 +80,8 @@ enum {
c2e870
 	PROP_PAGE_MODE,
c2e870
 	PROP_VIEWER_PREFERENCES,
c2e870
 	PROP_PERMISSIONS,
c2e870
-	PROP_METADATA
c2e870
+	PROP_METADATA,
c2e870
+	PROP_PRINT_SCALING
c2e870
 };
c2e870
 
c2e870
 static void poppler_document_layers_free (PopplerDocument *document);
c2e870
@@ -1516,6 +1519,44 @@ poppler_document_get_page_mode (PopplerDocument *document)
c2e870
   return POPPLER_PAGE_MODE_UNSET;
c2e870
 }
c2e870
 
c2e870
+/**
c2e870
+ * poppler_document_get_print_scaling:
c2e870
+ * @document: A #PopplerDocument
c2e870
+ *
c2e870
+ * Returns the print scaling value suggested by author of the document.
c2e870
+ *
c2e870
+ * Return value: a #PopplerPrintScaling that should be used when document is printed
c2e870
+ *
c2e870
+ * Since: 0.26.5
c2e870
+ **/
c2e870
+PopplerPrintScaling
c2e870
+poppler_document_get_print_scaling (PopplerDocument *document)
c2e870
+{
c2e870
+  Catalog *catalog;
c2e870
+  ViewerPreferences *preferences;
c2e870
+  PopplerPrintScaling print_scaling = POPPLER_PRINT_SCALING_APP_DEFAULT;
c2e870
+
c2e870
+  g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), POPPLER_PRINT_SCALING_APP_DEFAULT);
c2e870
+
c2e870
+  catalog = document->doc->getCatalog ();
c2e870
+  if (catalog && catalog->isOk ()) {
c2e870
+    preferences = catalog->getViewerPreferences();
c2e870
+    if (preferences) {
c2e870
+      switch (preferences->getPrintScaling()) {
c2e870
+        default:
c2e870
+        case ViewerPreferences::printScalingAppDefault:
c2e870
+          print_scaling = POPPLER_PRINT_SCALING_APP_DEFAULT;
c2e870
+          break;
c2e870
+        case ViewerPreferences::printScalingNone:
c2e870
+          print_scaling = POPPLER_PRINT_SCALING_NONE;
c2e870
+          break;
c2e870
+      }
c2e870
+    }
c2e870
+  }
c2e870
+
c2e870
+  return print_scaling;
c2e870
+}
c2e870
+
c2e870
 /**
c2e870
  * poppler_document_get_permissions:
c2e870
  * @document: A #PopplerDocument
c2e870
@@ -1746,6 +1787,9 @@ poppler_document_get_property (GObject    *object,
c2e870
       /* FIXME: write... */
c2e870
       g_value_set_flags (value, POPPLER_VIEWER_PREFERENCES_UNSET);
c2e870
       break;
c2e870
+    case PROP_PRINT_SCALING:
c2e870
+      g_value_set_enum (value, poppler_document_get_print_scaling (document));
c2e870
+      break;
c2e870
     case PROP_PERMISSIONS:
c2e870
       g_value_set_flags (value, poppler_document_get_permissions (document));
c2e870
       break;
c2e870
@@ -2013,6 +2057,20 @@ poppler_document_class_init (PopplerDocumentClass *klass)
c2e870
 						       POPPLER_VIEWER_PREFERENCES_UNSET,
c2e870
 						       G_PARAM_READABLE));
c2e870
 
c2e870
+  /**
c2e870
+   * PopplerDocument:print-scaling:
c2e870
+   *
c2e870
+   * Since: 0.26.5
c2e870
+   */
c2e870
+  g_object_class_install_property (G_OBJECT_CLASS (klass),
c2e870
+				   PROP_PRINT_SCALING,
c2e870
+				   g_param_spec_enum ("print-scaling",
c2e870
+						      "Print Scaling",
c2e870
+						      "Print Scaling Viewer Preference",
c2e870
+						      POPPLER_TYPE_PRINT_SCALING,
c2e870
+						      POPPLER_PRINT_SCALING_APP_DEFAULT,
c2e870
+						      (GParamFlags) (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));
c2e870
+
c2e870
   /**
c2e870
    * PopplerDocument:permissions:
c2e870
    *
c2e870
diff --git a/glib/poppler-document.h b/glib/poppler-document.h
c2e870
index ebf3a9e1..e9eeebfd 100644
c2e870
--- a/glib/poppler-document.h
c2e870
+++ b/glib/poppler-document.h
c2e870
@@ -135,6 +136,21 @@ typedef enum /*< flags >*/
c2e870
   POPPLER_VIEWER_PREFERENCES_DIRECTION_RTL = 1 << 6
c2e870
 } PopplerViewerPreferences;
c2e870
 
c2e870
+/**
c2e870
+ * PopplerPrintScaling:
c2e870
+ * @POPPLER_PRINT_SCALING_APP_DEFAULT: application's default page scaling
c2e870
+ * @POPPLER_PRINT_SCALING_NONE: no page scaling
c2e870
+ *
c2e870
+ * PrintScaling viewer preference
c2e870
+ *
c2e870
+ * Since: 0.26.5
c2e870
+ */
c2e870
+typedef enum
c2e870
+{
c2e870
+  POPPLER_PRINT_SCALING_APP_DEFAULT,
c2e870
+  POPPLER_PRINT_SCALING_NONE
c2e870
+} PopplerPrintScaling;
c2e870
+
c2e870
 /**
c2e870
  * PopplerPermissions:
c2e870
  * @POPPLER_PERMISSIONS_OK_TO_PRINT: document can be printer
c2e870
@@ -356,6 +372,7 @@ POPPLER_PUBLIC
c2e870
 PopplerPageMode    poppler_document_get_page_mode          (PopplerDocument *document);
c2e870
 PopplerPermissions poppler_document_get_permissions        (PopplerDocument *document);
c2e870
 gchar             *poppler_document_get_metadata           (PopplerDocument *document);
c2e870
+PopplerPrintScaling poppler_document_get_print_scaling     (PopplerDocument *document);
c2e870
 
c2e870
 /* Attachments */
c2e870
 guint              poppler_document_get_n_attachments      (PopplerDocument  *document);
c2e870
diff --git a/glib/reference/poppler-sections.txt b/glib/reference/poppler-sections.txt
c2e870
index 39985553..c71c2776 100644
c2e870
--- a/glib/reference/poppler-sections.txt
c2e870
+++ b/glib/reference/poppler-sections.txt
c2e870
@@ -174,6 +174,7 @@ poppler_document_get_pdf_subtype_string
c2e870
 poppler_document_get_page_layout
c2e870
 poppler_document_get_page_mode
c2e870
 poppler_document_get_permissions
c2e870
+poppler_document_get_print_scaling
c2e870
 poppler_document_get_metadata
c2e870
 poppler_document_is_linearized
c2e870
 poppler_document_get_n_pages
c2e870
@@ -246,6 +247,7 @@ POPPLER_TYPE_PDF_CONFORMANCE
c2e870
 POPPLER_TYPE_PAGE_LAYOUT
c2e870
 POPPLER_TYPE_PAGE_MODE
c2e870
 POPPLER_TYPE_PERMISSIONS
c2e870
+POPPLER_TYPE_PRINT_SCALING
c2e870
 POPPLER_TYPE_VIEWER_PREFERENCES
c2e870
 
c2e870
 <SUBSECTION Private>
c2e870
@@ -260,6 +262,7 @@ poppler_pdf_conformance_get_type
c2e870
 poppler_page_layout_get_type
c2e870
 poppler_page_mode_get_type
c2e870
 poppler_permissions_get_type
c2e870
+poppler_print_scaling_get_type
c2e870
 poppler_viewer_preferences_get_type
c2e870
 </SECTION>
c2e870
 
c2e870
diff --git a/glib/reference/poppler.types b/glib/reference/poppler.types
c2e870
index 354fdd3a..2f7a3991 100644
c2e870
--- a/glib/reference/poppler.types
c2e870
+++ b/glib/reference/poppler.types
c2e870
@@ -60,5 +60,6 @@ poppler_pdf_subtype_get_type
c2e870
 poppler_layer_get_type
c2e870
 poppler_media_get_type
c2e870
 poppler_movie_get_type
c2e870
+poppler_print_scaling_get_type
c2e870
 poppler_structure_element_get_type
c2e870
 poppler_structure_element_iter_get_type