From 7c206a9cb06d70fb95f7f7eae137865bb68f5b1b Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Wed, 18 Nov 2015 14:59:51 +0100 Subject: [PATCH 343/398] lok::Document::initializeForRendering: support init. arguments Change-Id: I8aaf19a50f25f495cb87fba7ff6a4b0f56ed7d80 (cherry picked from commit 4bddfc00d25a42917db79ceaf0547c2e792132c4) --- desktop/qa/desktop_lib/test_desktop_lib.cxx | 4 +- desktop/source/lib/init.cxx | 76 +++++++++++++++-------------- desktop/source/lib/lokandroid.cxx | 2 +- include/LibreOfficeKit/LibreOfficeKit.h | 3 +- include/LibreOfficeKit/LibreOfficeKit.hxx | 16 +++++- libreofficekit/source/gtk/lokdocview.cxx | 2 +- 6 files changed, 60 insertions(+), 43 deletions(-) diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index 1edf8d722d2f..4b08f9448f61 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -283,7 +283,7 @@ void DesktopLOKTest::testSearchCalc() LibLibreOffice_Impl aOffice; comphelper::LibreOfficeKit::setActive(); LibLODocument_Impl* pDocument = loadDoc("search.ods"); - pDocument->pClass->initializeForRendering(pDocument); + pDocument->pClass->initializeForRendering(pDocument, nullptr); pDocument->pClass->registerCallback(pDocument, &DesktopLOKTest::callback, this); uno::Sequence aPropertyValues(comphelper::InitPropertySequence( @@ -406,7 +406,7 @@ void DesktopLOKTest::testRowColumnHeaders() */ LibLODocument_Impl* pDocument = loadDoc("search.ods"); - pDocument->pClass->initializeForRendering(pDocument); + pDocument->pClass->initializeForRendering(pDocument, nullptr); boost::property_tree::ptree aTree; char* pJSON = pDocument->m_pDocumentClass->getCommandValues(pDocument, ".uno:ViewRowColumnHeaders"); diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 4ee862d21cd0..2ff0a9d02853 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -260,6 +260,40 @@ static OUString getAbsoluteURL(const char* pURL) return OUString(); } +static void jsonToPropertyValues(const char* pJSON, uno::Sequence& rPropertyValues) +{ + std::vector aArguments; + if (pJSON) + { + boost::property_tree::ptree aTree; + std::stringstream aStream(pJSON); + boost::property_tree::read_json(aStream, aTree); + + for (const std::pair& rPair : aTree) + { + const std::string& rType = rPair.second.get("type"); + const std::string& rValue = rPair.second.get("value"); + + beans::PropertyValue aValue; + aValue.Name = OUString::fromUtf8(rPair.first.c_str()); + if (rType == "string") + aValue.Value <<= OUString::fromUtf8(rValue.c_str()); + else if (rType == "boolean") + aValue.Value <<= OString(rValue.c_str()).toBoolean(); + else if (rType == "float") + aValue.Value <<= OString(rValue.c_str()).toFloat(); + else if (rType == "long") + aValue.Value <<= OString(rValue.c_str()).toInt32(); + else if (rType == "unsigned short") + aValue.Value <<= static_cast(OString(rValue.c_str()).toUInt32()); + else + SAL_WARN("desktop.lib", "jsonToPropertyValues: unhandled type '"< aPropertyValues; + jsonToPropertyValues(pArguments, aPropertyValues); pDoc->initializeForTiledRendering(); } } @@ -987,40 +1025,6 @@ static void doc_postKeyEvent(LibreOfficeKitDocument* pThis, int nType, int nChar pDoc->postKeyEvent(nType, nCharCode, nKeyCode); } -static void jsonToPropertyValues(const char* pJSON, uno::Sequence& rPropertyValues) -{ - std::vector aArguments; - if (pJSON) - { - boost::property_tree::ptree aTree; - std::stringstream aStream(pJSON); - boost::property_tree::read_json(aStream, aTree); - - for (const std::pair& rPair : aTree) - { - const std::string& rType = rPair.second.get("type"); - const std::string& rValue = rPair.second.get("value"); - - beans::PropertyValue aValue; - aValue.Name = OUString::fromUtf8(rPair.first.c_str()); - if (rType == "string") - aValue.Value <<= OUString::fromUtf8(rValue.c_str()); - else if (rType == "boolean") - aValue.Value <<= OString(rValue.c_str()).toBoolean(); - else if (rType == "float") - aValue.Value <<= OString(rValue.c_str()).toFloat(); - else if (rType == "long") - aValue.Value <<= OString(rValue.c_str()).toInt32(); - else if (rType == "unsigned short") - aValue.Value <<= static_cast(OString(rValue.c_str()).toUInt32()); - else - SAL_WARN("desktop.lib", "jsonToPropertyValues: unhandled type '"<(pEnv, aObject); - pDocument->pClass->initializeForRendering(pDocument); + pDocument->pClass->initializeForRendering(pDocument, NULL); } extern "C" SAL_JNI_EXPORT jint JNICALL Java_org_libreoffice_kit_Office_saveAs diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h index 03210376c61e..93f7dca6d455 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.h +++ b/include/LibreOfficeKit/LibreOfficeKit.h @@ -124,7 +124,8 @@ struct _LibreOfficeKitDocumentClass long* pHeight); /// @see lok::Document::initializeForRendering(). - void (*initializeForRendering) (LibreOfficeKitDocument* pThis); + void (*initializeForRendering) (LibreOfficeKitDocument* pThis, + const char* pArguments); /// @see lok::Document::registerCallback(). void (*registerCallback) (LibreOfficeKitDocument* pThis, diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx index c474195de213..152d0f415f17 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.hxx +++ b/include/LibreOfficeKit/LibreOfficeKit.hxx @@ -156,10 +156,22 @@ public: * needed to render the document correctly using tiled rendering. This * method has to be called right after documentLoad() in case any of the * tiled rendering methods are to be used later. + * + * Example argument string for text documents: + * + * { + * ".uno:HideWhitespace": + * { + * "type": "boolean", + * "value": "true" + * } + * } + * + * @param pArguments arguments of the rendering */ - inline void initializeForRendering() + inline void initializeForRendering(const char* pArguments = NULL) { - mpDoc->pClass->initializeForRendering(mpDoc); + mpDoc->pClass->initializeForRendering(mpDoc, pArguments); } /** diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx index 47ada280dde3..802d85dea553 100644 --- a/libreofficekit/source/gtk/lokdocview.cxx +++ b/libreofficekit/source/gtk/lokdocview.cxx @@ -530,7 +530,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); + priv->m_pDocument->pClass->initializeForRendering(priv->m_pDocument, nullptr); 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); -- 2.12.0