sw/qa/extras/htmlexport/htmlexport.cxx |   33 +++++++++++++++++++++++++++++++++
 sw/source/filter/html/wrthtml.cxx      |   13 ++++++++++++-
 2 files changed, 45 insertions(+), 1 deletion(-)

New commits:
commit c2cf1b01d5bed68c572ca73b32c6f92d6723562c
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Thu Feb 24 20:35:46 2022 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Fri Feb 25 08:25:00 2022 +0100

    sw HTML export: allow setting filter data keys from the cmdline
    
    For example to produce bitmaps for shape that look better with hidpi:
    
    soffice --convert-to 'html:HTML 
(StarWriter):{"ShapeDPI":{"type":"long","value":"192"}}' test.odt
    
    Change-Id: I2654f894d0c20b2cab381e8c6688ec7b13c6e11f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130509
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx 
b/sw/qa/extras/htmlexport/htmlexport.cxx
index 793e404e2dab..ccf5276c1f39 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -1841,6 +1841,39 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, 
testShapeAsImageHtml)
     CPPUNIT_ASSERT_EQUAL(OUString(" "), getParagraph(1)->getString());
 }
 
+CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testJson)
+{
+    // Given a document with a shape:
+    loadURL("private:factory/swriter", nullptr);
+    uno::Reference<css::lang::XMultiServiceFactory> xFactory(mxComponent, 
uno::UNO_QUERY);
+    uno::Reference<drawing::XShape> xShape(
+        xFactory->createInstance("com.sun.star.drawing.RectangleShape"), 
uno::UNO_QUERY);
+    xShape->setSize(awt::Size(2540, 2540));
+    uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, 
uno::UNO_QUERY);
+    xDrawPageSupplier->getDrawPage()->add(xShape);
+
+    // When exporting to HTML, and specifying options as JSON:
+    uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
+    OUString aJson("{\"XhtmlNs\":{\"type\":\"string\", 
\"value\":\"reqif-xhtml\"},"
+                   "\"ShapeDPI\":{\"type\":\"long\",\"value\":\"192\"}}");
+    uno::Sequence<beans::PropertyValue> aStoreProperties = {
+        comphelper::makePropertyValue("FilterName", OUString("HTML 
(StarWriter)")),
+        comphelper::makePropertyValue("FilterOptions", aJson),
+    };
+    xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties);
+
+    // Then make sure those options are not ignored:
+    // Without the accompanying fix in place, this test would have failed, as 
GetPngPath() expects
+    // XML output, but xhtmlns=reqif-xhtml was ignored.
+    OUString aPngUrl = GetPngPath();
+    SvFileStream aFileStream(aPngUrl, StreamMode::READ);
+    GraphicDescriptor aDescriptor(aFileStream, nullptr);
+    aDescriptor.Detect(/*bExtendedInfo=*/true);
+    // Make sure that the increased DPI is taken into account:
+    tools::Long nExpected = 192;
+    CPPUNIT_ASSERT_EQUAL(nExpected, aDescriptor.GetSizePixel().getWidth());
+}
+
 CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifEmbedShapeAsPNGCustomDPI)
 {
     // Given a document with a shape:
diff --git a/sw/source/filter/html/wrthtml.cxx 
b/sw/source/filter/html/wrthtml.cxx
index 4d1be19b2fe7..39c2e39049de 100644
--- a/sw/source/filter/html/wrthtml.cxx
+++ b/sw/source/filter/html/wrthtml.cxx
@@ -83,6 +83,8 @@
 #include <unotools/tempfile.hxx>
 #include <comphelper/sequenceashashmap.hxx>
 #include <officecfg/Office/Common.hxx>
+#include <comphelper/propertysequence.hxx>
+#include <comphelper/sequence.hxx>
 
 #define MAX_INDENT_LEVEL 20
 
@@ -187,13 +189,22 @@ void SwHTMLWriter::SetupFilterOptions(SfxMedium& rMedium)
         return;
 
     const SfxPoolItem* pItem;
+    uno::Sequence<beans::PropertyValue> aArgs = rMedium.GetArgs();
     if (pSet->GetItemState(SID_FILE_FILTEROPTIONS, true, &pItem) == 
SfxItemState::SET)
     {
         const OUString sFilterOptions = static_cast<const 
SfxStringItem*>(pItem)->GetValue();
+
+        if (sFilterOptions.startsWith("{"))
+        {
+            std::vector<beans::PropertyValue> aArgsVec
+                = comphelper::JsonToPropertyValues(sFilterOptions.toUtf8());
+            aArgs = comphelper::containerToSequence(aArgsVec);
+        }
+
         SetupFilterOptions(sFilterOptions);
     }
 
-    SetupFilterFromPropertyValues(rMedium.GetArgs());
+    SetupFilterFromPropertyValues(aArgs);
 }
 
 void SwHTMLWriter::SetupFilterOptions(const OUString& rFilterOptions)

Reply via email to