diff options
-rw-r--r-- | include/svx/xoutbmp.hxx | 3 | ||||
-rw-r--r-- | svx/source/xoutdev/_xoutbmp.cxx | 12 | ||||
-rw-r--r-- | sw/qa/extras/htmlexport/data/reqif-transparent-tif-img.odt | bin | 0 -> 13339 bytes | |||
-rw-r--r-- | sw/qa/extras/htmlexport/htmlexport.cxx | 23 | ||||
-rw-r--r-- | sw/source/filter/html/htmlflywriter.cxx | 31 |
5 files changed, 55 insertions, 14 deletions
diff --git a/include/svx/xoutbmp.hxx b/include/svx/xoutbmp.hxx index 43a666d06277..d2137f670c8a 100644 --- a/include/svx/xoutbmp.hxx +++ b/include/svx/xoutbmp.hxx @@ -59,7 +59,8 @@ public: static ErrCode WriteGraphic( const Graphic& rGraphic, OUString& rFileName, const OUString& rFilterName, const XOutFlags nFlags, const Size* pMtfSize_100TH_MM = nullptr, - const css::uno::Sequence< css::beans::PropertyValue >* pFilterData = nullptr); + const css::uno::Sequence< css::beans::PropertyValue >* pFilterData = nullptr, + OUString* pMediaType = nullptr ); static bool GraphicToBase64(const Graphic& rGraphic, OUString& rOUString, bool bAddPrefix = true, ConvertDataFormat aTargetFormat = ConvertDataFormat::Unknown); diff --git a/svx/source/xoutdev/_xoutbmp.cxx b/svx/source/xoutdev/_xoutbmp.cxx index df57f48ce555..149295d22b09 100644 --- a/svx/source/xoutdev/_xoutbmp.cxx +++ b/svx/source/xoutdev/_xoutbmp.cxx @@ -30,10 +30,13 @@ #include <vcl/cvtgrf.hxx> #include <memory> +#include <com/sun/star/beans/XPropertySet.hpp> + constexpr OUStringLiteral FORMAT_BMP = u"bmp"; constexpr OUStringLiteral FORMAT_GIF = u"gif"; constexpr OUStringLiteral FORMAT_JPG = u"jpg"; constexpr OUStringLiteral FORMAT_PNG = u"png"; +constexpr OUStringLiteral FORMAT_TIF = u"tif"; constexpr OUStringLiteral FORMAT_WEBP = u"webp"; using namespace com::sun::star; @@ -104,7 +107,8 @@ Graphic XOutBitmap::MirrorGraphic( const Graphic& rGraphic, const BmpMirrorFlags ErrCode XOutBitmap::WriteGraphic( const Graphic& rGraphic, OUString& rFileName, const OUString& rFilterName, const XOutFlags nFlags, const Size* pMtfSize_100TH_MM, - const css::uno::Sequence< css::beans::PropertyValue >* pFilterData ) + const css::uno::Sequence< css::beans::PropertyValue >* pFilterData, + OUString* pMediaType ) { if( rGraphic.GetType() == GraphicType::NONE ) return ERRCODE_NONE; @@ -182,6 +186,7 @@ ErrCode XOutBitmap::WriteGraphic( const Graphic& rGraphic, OUString& rFileName, case GfxLinkType::NativeJpg: aExt = FORMAT_JPG; break; case GfxLinkType::NativePng: aExt = FORMAT_PNG; break; + case GfxLinkType::NativeTif: aExt = FORMAT_TIF; break; case GfxLinkType::NativeWebp: aExt = FORMAT_WEBP; break; default: @@ -196,6 +201,9 @@ ErrCode XOutBitmap::WriteGraphic( const Graphic& rGraphic, OUString& rFileName, if( !(nFlags & XOutFlags::DontAddExtension) ) aURL.setExtension( aExt ); rFileName = aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ); + if (pMediaType) + if (uno::Reference<beans::XPropertySet> xGraphic{ rGraphic.GetXGraphic(), uno::UNO_QUERY }) + xGraphic->getPropertyValue("MimeType") >>= *pMediaType; SfxMedium aMedium(aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::WRITE | StreamMode::SHARE_DENYNONE | StreamMode::TRUNC); SvStream* pOStm = aMedium.GetOutStream(); @@ -307,6 +315,8 @@ ErrCode XOutBitmap::WriteGraphic( const Graphic& rGraphic, OUString& rFileName, if( !(nFlags & XOutFlags::DontAddExtension) ) aURL.setExtension( aExt ); rFileName = aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ); + if (pMediaType) + *pMediaType = rFilter.GetExportFormatMediaType(nFilter); nErr = ExportGraphic( aGraphic, aURL, rFilter, nFilter, pFilterData ); } } diff --git a/sw/qa/extras/htmlexport/data/reqif-transparent-tif-img.odt b/sw/qa/extras/htmlexport/data/reqif-transparent-tif-img.odt Binary files differnew file mode 100644 index 000000000000..278cf9ebc832 --- /dev/null +++ b/sw/qa/extras/htmlexport/data/reqif-transparent-tif-img.odt diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx index 689e0aa48ea0..f5482ec34b5f 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -2464,6 +2464,29 @@ CPPUNIT_TEST_FIXTURE(HtmlExportTest, testTdf153923) assertXPath(pDoc, "/html/body//dd"); } +CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqIfTransparentTifImg) +{ + // reqIf export must keep the TIF encoding of the image + createSwDoc("reqif-transparent-tif-img.odt"); + ExportToReqif(); + + SvMemoryStream aStream; + WrapReqifFromTempFile(aStream); + xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream); + assertXPath(pXmlDoc, "//reqif-xhtml:p/reqif-xhtml:object[1]", "type", "image/tiff"); + OUString imageName = getXPath(pXmlDoc, "//reqif-xhtml:p/reqif-xhtml:object[1]", "data"); + // Without the accompanying fix in place, this test would have failed, + // ending with .gif, because XOutFlags::UseGifIfSensible flag combined + // with the transparent image would result in GIF export + CPPUNIT_ASSERT(imageName.endsWith(".tif")); + + INetURLObject aURL(maTempFile.GetURL()); + aURL.setName(imageName); + GraphicDescriptor aDescriptor(aURL); + aDescriptor.Detect(); + CPPUNIT_ASSERT_EQUAL(GraphicFileFormat::TIF, aDescriptor.GetFileFormat()); +} + 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 2cf3c6894ec1..d00fd94e33ee 100644 --- a/sw/source/filter/html/htmlflywriter.cxx +++ b/sw/source/filter/html/htmlflywriter.cxx @@ -1967,18 +1967,21 @@ static Writer& OutHTML_FrameFormatGrfNode( Writer& rWrt, const SwFrameFormat& rF Size aMM100Size = o3tl::convert( rSize.GetSize(), o3tl::Length::twip, o3tl::Length::mm100 ); - OUString aFilterName(""); + OUString aFilterName; - if (rHTMLWrt.mbReqIF && !bWritePNGFallback) + if (rHTMLWrt.mbReqIF) { - // Writing image without fallback PNG in ReqIF mode: force PNG - // output. - // But don't force it when writing the original format and we'll write PNG inside - // that. - aFilterName = "PNG"; - nFlags &= ~XOutFlags::UseNativeIfPossible; + // In ReqIF mode, do not try to write GIF for other image types nFlags &= ~XOutFlags::UseGifIfSensible; - aMimeType = "image/png"; + if (!bWritePNGFallback) + { + // Writing image without fallback PNG in ReqIF mode: force PNG + // output. + // But don't force it when writing the original format and we'll write PNG inside + // that. + aFilterName = "PNG"; + nFlags &= ~XOutFlags::UseNativeIfPossible; + } } const Graphic& rGraphic = pGrfNd->GetGrf(); @@ -1987,6 +1990,8 @@ static Writer& OutHTML_FrameFormatGrfNode( Writer& rWrt, const SwFrameFormat& rF if (!rGraphic.isAvailable()) const_cast<Graphic&>(rGraphic).makeAvailable(); + OUString aMimeTypeOverride; + if (rHTMLWrt.mbReqIF && bWritePNGFallback) { // ReqIF: force native data if possible. @@ -1998,7 +2003,7 @@ static Writer& OutHTML_FrameFormatGrfNode( Writer& rWrt, const SwFrameFormat& rF else if (rGraphic.GetGfxLink().IsEMF()) { aFilterName = "emf"; - aMimeType = "image/x-emf"; // avoid image/x-wmf + aMimeTypeOverride = "image/x-emf"; // avoid image/x-wmf } else if (pVectorGraphicData && pVectorGraphicData->getType() == VectorGraphicDataType::Wmf) { @@ -2007,12 +2012,12 @@ static Writer& OutHTML_FrameFormatGrfNode( Writer& rWrt, const SwFrameFormat& rF else if (rGraphic.GetGfxLink().GetType() == GfxLinkType::NativeTif) { aFilterName = "tif"; - aMimeType = "image/tiff"; // avoid image/x-vclgraphic + aMimeTypeOverride = "image/tiff"; // avoid image/x-vclgraphic } } ErrCode nErr = XOutBitmap::WriteGraphic( rGraphic, aGraphicURL, - aFilterName, nFlags, &aMM100Size ); + aFilterName, nFlags, &aMM100Size, nullptr, &aMimeType ); if( nErr ) { rHTMLWrt.m_nWarn = WARN_SWG_POOR_LOAD; @@ -2021,6 +2026,8 @@ static Writer& OutHTML_FrameFormatGrfNode( Writer& rWrt, const SwFrameFormat& rF aGraphicURL = URIHelper::SmartRel2Abs( INetURLObject(rWrt.GetBaseURL()), aGraphicURL, URIHelper::GetMaybeFileHdl() ); + if (!aMimeTypeOverride.isEmpty()) + aMimeType = aMimeTypeOverride; } else { |