svx/source/xoutdev/_xoutbmp.cxx | 6 +++++- sw/qa/extras/htmlimport/data/ole-img-svg.xhtml | 7 +++++++ sw/qa/extras/htmlimport/data/ole2.svg | 3 +++ sw/qa/extras/htmlimport/htmlimport.cxx | 24 ++++++++++++++++++++++++ sw/source/filter/html/htmlflywriter.cxx | 24 ++++++++++++++++++++++++ sw/source/filter/html/htmlplug.cxx | 6 ++++++ 6 files changed, 69 insertions(+), 1 deletion(-)
New commits: commit f3b2fc2276ee8a7f64e73d9975d0143d1696362c Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Tue Jul 20 17:13:36 2021 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Tue Jul 20 19:06:20 2021 +0200 sw XHTML import, improved <object> handling for images: support more formats This was working for only png and gif in the past, handle more formats: - bmp - jpg - emf - svg - wmf - tif Change-Id: I2af42157428550977f0abab88f2ed728636d2a02 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119287 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins diff --git a/svx/source/xoutdev/_xoutbmp.cxx b/svx/source/xoutdev/_xoutbmp.cxx index ef2b31716a2f..a3505202310e 100644 --- a/svx/source/xoutdev/_xoutbmp.cxx +++ b/svx/source/xoutdev/_xoutbmp.cxx @@ -134,7 +134,11 @@ ErrCode XOutBitmap::WriteGraphic( const Graphic& rGraphic, OUString& rFileName, { const bool bIsSvg(rFilterName.equalsIgnoreAsciiCase("svg") && VectorGraphicDataType::Svg == rVectorGraphicDataPtr->getType()); const bool bIsWmf(rFilterName.equalsIgnoreAsciiCase("wmf") && VectorGraphicDataType::Wmf == rVectorGraphicDataPtr->getType()); - const bool bIsEmf(rFilterName.equalsIgnoreAsciiCase("emf") && VectorGraphicDataType::Emf == rVectorGraphicDataPtr->getType()); + bool bIsEmf(rFilterName.equalsIgnoreAsciiCase("emf") && VectorGraphicDataType::Emf == rVectorGraphicDataPtr->getType()); + if (!bIsEmf) + { + bIsEmf = rGraphic.GetGfxLink().IsEMF(); + } const bool bIsPdf(rFilterName.equalsIgnoreAsciiCase("pdf") && VectorGraphicDataType::Pdf == rVectorGraphicDataPtr->getType()); if (bIsSvg || bIsWmf || bIsEmf || bIsPdf) diff --git a/sw/qa/extras/htmlimport/data/ole-img-svg.xhtml b/sw/qa/extras/htmlimport/data/ole-img-svg.xhtml new file mode 100644 index 000000000000..2e063937ff20 --- /dev/null +++ b/sw/qa/extras/htmlimport/data/ole-img-svg.xhtml @@ -0,0 +1,7 @@ +<reqif-xhtml:div> +<reqif-xhtml:p> +<reqif-xhtml:object data="ole2.svg" type="image/svg+xml"> + <reqif-xhtml:object data="ole2.png" type="image/png"></reqif-xhtml:object> +</reqif-xhtml:object> +</reqif-xhtml:p> +</reqif-xhtml:div> diff --git a/sw/qa/extras/htmlimport/data/ole2.svg b/sw/qa/extras/htmlimport/data/ole2.svg new file mode 100644 index 000000000000..552a1cf5afaf --- /dev/null +++ b/sw/qa/extras/htmlimport/data/ole2.svg @@ -0,0 +1,3 @@ +<svg width="400" height="110"> + <rect width="300" height="100" style="fill:none;stroke-width:3;stroke:rgb(0,0,0)" /> +</svg> diff --git a/sw/qa/extras/htmlimport/htmlimport.cxx b/sw/qa/extras/htmlimport/htmlimport.cxx index 033d53e8629b..5490f5178319 100644 --- a/sw/qa/extras/htmlimport/htmlimport.cxx +++ b/sw/qa/extras/htmlimport/htmlimport.cxx @@ -485,6 +485,30 @@ CPPUNIT_TEST_FIXTURE(SwModelTestBase, testOleImg) CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xObjects->getCount()); } +CPPUNIT_TEST_FIXTURE(SwModelTestBase, testOleImgSvg) +{ + // Given an XHTML with an <object> (containing SVG) and an inner <object> (containing PNG, to be + // ignored): + uno::Sequence<beans::PropertyValue> aLoadProperties = { + comphelper::makePropertyValue("FilterName", OUString("HTML (StarWriter)")), + comphelper::makePropertyValue("FilterOptions", OUString("xhtmlns=reqif-xhtml")), + }; + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "ole-img-svg.xhtml"; + + // When loading the document: + mxComponent = loadFromDesktop(aURL, "com.sun.star.text.TextDocument", aLoadProperties); + + // Then make sure the result is a single Writer image: + uno::Reference<text::XTextGraphicObjectsSupplier> xSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xObjects(xSupplier->getGraphicObjects(), + uno::UNO_QUERY); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 0 + // - Actual : 1 + // i.e. the image was not imported as a Writer image (but as an OLE object). + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xObjects->getCount()); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/filter/html/htmlflywriter.cxx b/sw/source/filter/html/htmlflywriter.cxx index 593a8689a83a..f528c061c9a6 100644 --- a/sw/source/filter/html/htmlflywriter.cxx +++ b/sw/source/filter/html/htmlflywriter.cxx @@ -1962,6 +1962,30 @@ static Writer& OutHTML_FrameFormatGrfNode( Writer& rWrt, const SwFrameFormat& rF if (!rGraphic.isAvailable()) const_cast<Graphic&>(rGraphic).makeAvailable(); + if (rHTMLWrt.mbReqIF && bWritePNGFallback) + { + // ReqIF: force native data if possible. + const std::shared_ptr<VectorGraphicData>& pVectorGraphicData = rGraphic.getVectorGraphicData(); + if (pVectorGraphicData && pVectorGraphicData->getType() == VectorGraphicDataType::Svg) + { + aFilterName = "svg"; + } + else if (rGraphic.GetGfxLink().IsEMF()) + { + aFilterName = "emf"; + aMimeType = "image/x-emf"; // avoid image/x-wmf + } + else if (pVectorGraphicData && pVectorGraphicData->getType() == VectorGraphicDataType::Wmf) + { + aFilterName = "wmf"; + } + else if (rGraphic.GetGfxLink().GetType() == GfxLinkType::NativeTif) + { + aFilterName = "tif"; + aMimeType = "image/tiff"; // avoid image/x-vclgraphic + } + } + ErrCode nErr = XOutBitmap::WriteGraphic( rGraphic, aGraphicURL, aFilterName, nFlags, &aMM100Size ); if( nErr ) diff --git a/sw/source/filter/html/htmlplug.cxx b/sw/source/filter/html/htmlplug.cxx index e09de84671e6..2c06177f539c 100644 --- a/sw/source/filter/html/htmlplug.cxx +++ b/sw/source/filter/html/htmlplug.cxx @@ -437,6 +437,12 @@ bool SwHTMLParser::InsertEmbed() static const std::set<std::u16string_view> vAllowlist = { u"image/png", u"image/gif", + u"image/x-MS-bmp", + u"image/jpeg", + u"image/x-wmf", + u"image/svg+xml", + u"image/tiff", + u"image/x-emf", }; if (vAllowlist.find(aType) != vAllowlist.end() && m_aEmbeds.empty()) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits