diff options
-rw-r--r-- | sw/qa/extras/htmlexport/htmlexport.cxx | 33 | ||||
-rw-r--r-- | sw/source/filter/html/wrthtml.cxx | 13 |
2 files changed, 45 insertions, 1 deletions
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) |