Blob Blame History Raw
From 5192c15c3382caea037991cdbeca55c596fe042f Mon Sep 17 00:00:00 2001
From: Miklos Vajna <vmiklos@collabora.co.uk>
Date: Wed, 18 Nov 2015 15:57:36 +0100
Subject: [PATCH 345/398] gtktiledviewer: allow passing
 initializeForRendering() arguments

Change-Id: Ic7b52764cf2fedbf73d4dcaaf36d1055b8ee22f2
(cherry picked from commit 0ea68eecddf0211f842645c4d257899531692770)
---
 include/LibreOfficeKit/LibreOfficeKitGtk.h         |  2 ++
 .../qa/gtktiledviewer/gtktiledviewer.cxx           | 25 ++++++++++++++++++----
 libreofficekit/source/gtk/lokdocview.cxx           |  5 ++++-
 3 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/include/LibreOfficeKit/LibreOfficeKitGtk.h b/include/LibreOfficeKit/LibreOfficeKitGtk.h
index 32cb66963220..c947ce3f8369 100644
--- a/include/LibreOfficeKit/LibreOfficeKitGtk.h
+++ b/include/LibreOfficeKit/LibreOfficeKitGtk.h
@@ -65,6 +65,7 @@ GtkWidget*                     lok_doc_view_new_from_widget        (LOKDocView*
  * lok_doc_view_open_document:
  * @pDocView: The #LOKDocView instance
  * @pPath: (transfer full): The path of the document that #LOKDocView widget should try to open
+ * @pRenderingArguments: lok::Document::initializeForRendering() arguments.
  * @cancellable:
  * @callback:
  * @userdata:
@@ -73,6 +74,7 @@ GtkWidget*                     lok_doc_view_new_from_widget        (LOKDocView*
  */
 void                           lok_doc_view_open_document          (LOKDocView* pDocView,
                                                                     const gchar* pPath,
+                                                                    const gchar* pRenderingArguments,
                                                                     GCancellable* cancellable,
                                                                     GAsyncReadyCallback callback,
                                                                     gpointer userdata);
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index 7dcd52446344..f9034298e65c 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -29,7 +29,9 @@
 
 static int help()
 {
-    fprintf( stderr, "Usage: gtktiledviewer <absolute-path-to-libreoffice-install's-program-directory> <path-to-document>\n" );
+    fprintf(stderr, "Usage: gtktiledviewer <absolute-path-to-libreoffice-install's-program-directory> <path-to-document> [<options> ... ]\n\n");
+    fprintf(stderr, "Options:\n\n");
+    fprintf(stderr, "--hide-whitespace: Hide whitespace between pages in text documents.\n");
     return 1;
 }
 
@@ -475,13 +477,25 @@ static void createView(GtkWidget* pButton, gpointer /*pItem*/)
 }
 
 /// Creates a new model, i.e. LOK init and document load, one view implicitly.
-static void createModelAndView(const char* pLOPath, const char* pDocPath)
+static void createModelAndView(const char* pLOPath, const char* pDocPath, const std::vector<std::string>& rArguments)
 {
     GtkWidget* pDocView = lok_doc_view_new(pLOPath, nullptr, nullptr);
 
     setupWidgetAndCreateWindow(pDocView);
 
-    lok_doc_view_open_document(LOK_DOC_VIEW(pDocView), pDocPath, nullptr, openDocumentCallback, pDocView);
+    boost::property_tree::ptree aTree;
+    for (const std::string& rArgument : rArguments)
+    {
+        if (rArgument == "--hide-whitespace")
+        {
+            aTree.put(boost::property_tree::ptree::path_type(".uno:HideWhitespace/type", '/'), "boolean");
+            aTree.put(boost::property_tree::ptree::path_type(".uno:HideWhitespace/value", '/'), true);
+        }
+    }
+    std::stringstream aStream;
+    boost::property_tree::write_json(aStream, aTree);
+    std::string aArguments = aStream.str();
+    lok_doc_view_open_document(LOK_DOC_VIEW(pDocView), pDocPath, aArguments.c_str(), nullptr, openDocumentCallback, pDocView);
 }
 
 /// Our GtkClipboardGetFunc implementation for HTML.
@@ -1262,7 +1276,10 @@ int main( int argc, char* argv[] )
 
     gtk_init( &argc, &argv );
 
-    createModelAndView(argv[1], argv[2]);
+    std::vector<std::string> aArguments;
+    for (int i = 3; i < argc; ++i)
+        aArguments.push_back(argv[i]);
+    createModelAndView(argv[1], argv[2], aArguments);
 
     gtk_main();
 
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 802d85dea553..464348d95f1c 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -44,6 +44,7 @@ struct LOKDocViewPrivateImpl
 {
     const gchar* m_aLOPath;
     const gchar* m_aDocPath;
+    std::string m_aRenderingArguments;
     gdouble m_nLoadProgress;
     gboolean m_bIsLoading;
     gboolean m_bCanZoomIn;
@@ -530,7 +531,7 @@ static gboolean postDocumentLoad(gpointer pData)
     LOKDocViewPrivate& priv = getPrivate(pLOKDocView);
 
     priv->m_pDocument->pClass->setView(priv->m_pDocument, priv->m_nViewId);
-    priv->m_pDocument->pClass->initializeForRendering(priv->m_pDocument, nullptr);
+    priv->m_pDocument->pClass->initializeForRendering(priv->m_pDocument, priv->m_aRenderingArguments.c_str());
     priv->m_pDocument->pClass->registerCallback(priv->m_pDocument, callbackWorker, pLOKDocView);
     priv->m_pDocument->pClass->getDocumentSize(priv->m_pDocument, &priv->m_nDocumentWidthTwips, &priv->m_nDocumentHeightTwips);
     g_timeout_add(600, handleTimeout, pLOKDocView);
@@ -2312,6 +2313,7 @@ lok_doc_view_open_document_finish (LOKDocView* pDocView, GAsyncResult* res, GErr
 SAL_DLLPUBLIC_EXPORT void
 lok_doc_view_open_document (LOKDocView* pDocView,
                             const gchar* pPath,
+                            const gchar* pRenderingArguments,
                             GCancellable* cancellable,
                             GAsyncReadyCallback callback,
                             gpointer userdata)
@@ -2324,6 +2326,7 @@ lok_doc_view_open_document (LOKDocView* pDocView,
     pLOEvent->m_pPath = pPath;
 
     priv->m_aDocPath = pPath;
+    priv->m_aRenderingArguments = pRenderingArguments;
     g_task_set_task_data(task, pLOEvent, LOEvent::destroy);
 
     g_thread_pool_push(priv->lokThreadPool, g_object_ref(task), &error);
-- 
2.12.0