summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2021-06-02 08:48:56 +0200
committerMiklos Vajna <vmiklos@collabora.com>2021-06-02 10:31:45 +0200
commit4da0de52bbd9a2f53ce0e838f7b22c228e510f97 (patch)
tree79ca8fa5082e3e0c7c1cb52aff7571eef308b0ee /sw
parentedfd864ab45c029bb590ab34c711cd269e140f09 (diff)
sw XHTML / reqif export: export PNG shapes directly
The old markup was: <object data="draw-png_xhtml_89305eb5d44b6428.gif"> The new markup is: <object data="draw-png_xhtml_89305eb5d44b6428.png" type="image/png"> Which now passes the validator. Change-Id: Ibcdac7aeef0e39c926176bf8852cffe17a137fa2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116565 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/htmlexport/htmlexport.cxx33
-rw-r--r--sw/source/filter/html/htmlflywriter.cxx22
2 files changed, 51 insertions, 4 deletions
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index 275896ed7ccb..74af62a0a3e9 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -1590,6 +1590,39 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifEmbedJPGDirectly)
"image/png");
}
+CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifEmbedPNGShapeDirectly)
+{
+ // Given a document with an image shape:
+ loadURL("private:factory/swriter", nullptr);
+ OUString aImageURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "ole2.png";
+ uno::Reference<css::lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY);
+ uno::Reference<drawing::XShape> xShape(
+ xFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"), uno::UNO_QUERY);
+ xShape->setSize(awt::Size(10000, 10000));
+ uno::Reference<beans::XPropertySet> xShapeProps(xShape, uno::UNO_QUERY);
+ xShapeProps->setPropertyValue("GraphicURL", uno::makeAny(aImageURL));
+ uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
+ xDrawPageSupplier->getDrawPage()->add(xShape);
+
+ // When exporting to XHTML:
+ uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
+ uno::Sequence<beans::PropertyValue> aStoreProperties = {
+ comphelper::makePropertyValue("FilterName", OUString("HTML (StarWriter)")),
+ comphelper::makePropertyValue("FilterOptions", OUString("xhtmlns=reqif-xhtml")),
+ };
+ xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties);
+
+ // Then make sure the PNG is embedded directly, without an RTF wrapper:
+ SvMemoryStream aStream;
+ HtmlExportTest::wrapFragment(maTempFile, aStream);
+ xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream);
+ CPPUNIT_ASSERT(pXmlDoc);
+ // Without the accompanying fix in place, this test would have failed with:
+ // - no attribute 'type' exist
+ // i.e. the PNG was exported as GIF, without an explicit type.
+ assertXPath(pXmlDoc, "//reqif-xhtml:p/reqif-xhtml:object", "type", "image/png");
+}
+
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 a050c9c2056b..f4ff89c0b2b9 100644
--- a/sw/source/filter/html/htmlflywriter.cxx
+++ b/sw/source/filter/html/htmlflywriter.cxx
@@ -41,6 +41,7 @@
#include <editeng/brushitem.hxx>
#include <sal/log.hxx>
#include <osl/diagnose.h>
+#include <svx/svdograf.hxx>
#include <fmtanchr.hxx>
#include <fmtornt.hxx>
@@ -1747,15 +1748,27 @@ static Writer & OutHTML_FrameFormatAsImage( Writer& rWrt, const SwFrameFormat& r
Graphic aGraphic( const_cast<SwFrameFormat &>(rFrameFormat).MakeGraphic( &aIMap ) );
Size aSz( 0, 0 );
OUString GraphicURL;
+ OUString aMimeType("image/jpeg");
if(!rHTMLWrt.mbEmbedImages)
{
if( rHTMLWrt.GetOrigFileName() )
GraphicURL = *rHTMLWrt.GetOrigFileName();
+
+ OUString aFilterName("JPG");
+ XOutFlags nFlags = XOutFlags::UseGifIfPossible | XOutFlags::UseNativeIfPossible;
+
+ if (rHTMLWrt.mbReqIF)
+ {
+ // Writing image without fallback PNG in ReqIF mode: force PNG output.
+ aFilterName = "PNG";
+ nFlags = XOutFlags::NONE;
+ aMimeType = "image/png";
+ }
+
if( aGraphic.GetType() == GraphicType::NONE ||
XOutBitmap::WriteGraphic( aGraphic, GraphicURL,
- "JPG",
- (XOutFlags::UseGifIfPossible|
- XOutFlags::UseNativeIfPossible) ) != ERRCODE_NONE )
+ aFilterName,
+ nFlags ) != ERRCODE_NONE )
{
// empty or incorrect, because there is nothing to output
rHTMLWrt.m_nWarn = WARN_SWG_POOR_LOAD;
@@ -1767,10 +1780,11 @@ static Writer & OutHTML_FrameFormatAsImage( Writer& rWrt, const SwFrameFormat& r
URIHelper::GetMaybeFileHdl() );
}
+
HtmlWriter aHtml(rWrt.Strm(), rHTMLWrt.maNamespace);
OutHTML_ImageStart( aHtml, rWrt, rFrameFormat, GraphicURL, aGraphic, rFrameFormat.GetName(), aSz,
HtmlFrmOpts::GenImgMask, "frame",
- aIMap.GetIMapObjectCount() ? &aIMap : nullptr );
+ aIMap.GetIMapObjectCount() ? &aIMap : nullptr, aMimeType );
OutHTML_ImageEnd(aHtml, rWrt);
return rWrt;