sw/qa/extras/htmlexport/data/reqif-aschar-objsize.odt |binary sw/qa/extras/htmlexport/htmlexport.cxx | 38 ++++++++++++++++++ sw/source/filter/html/htmlplug.cxx | 4 - sw/source/filter/html/htmlreqifreader.cxx | 7 ++- sw/source/filter/html/htmlreqifreader.hxx | 4 + 5 files changed, 48 insertions(+), 5 deletions(-)
New commits: commit a4b426d4cd246fc9a5faf2a89cad0ebdc0a18847 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Fri Apr 16 10:14:05 2021 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Fri Apr 16 17:16:08 2021 +0200 sw html/reqif export: fix size of embedded object We used to write the size of the underlying OLE object, which may or may not match the user-configured size. The PNG preview was correct, which works with the size from the SwFormatFlyCnt ("as-char formatting"). Do the same when writing the "object size" (i.e. \objw and \objh in the RTF snippet). (cherry picked from commit 21cd910d144b14ead358bccd1146650806346eb5) Change-Id: I7e240c1e115846c17b0945376b0de02d19769100 diff --git a/sw/qa/extras/htmlexport/data/reqif-aschar-objsize.odt b/sw/qa/extras/htmlexport/data/reqif-aschar-objsize.odt new file mode 100644 index 000000000000..6028b54a4190 Binary files /dev/null and b/sw/qa/extras/htmlexport/data/reqif-aschar-objsize.odt differ diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx index 5e1264fcadb4..08a21b6b7dd3 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -48,10 +48,14 @@ public: TestReqIfRtfReader(SvStream& rStream); void NextToken(int nToken) override; bool WriteObjectData(SvStream& rOLE); + long GetObjw() const { return m_nObjw; } + long GetObjh() const { return m_nObjh; } private: bool m_bInObjData = false; OStringBuffer m_aHex; + long m_nObjw = 0; + long m_nObjh = 0; }; TestReqIfRtfReader::TestReqIfRtfReader(SvStream& rStream) @@ -73,6 +77,12 @@ void TestReqIfRtfReader::NextToken(int nToken) case RTF_OBJDATA: m_bInObjData = true; break; + case RTF_OBJW: + m_nObjw = nTokenValue; + break; + case RTF_OBJH: + m_nObjh = nTokenValue; + break; } } @@ -1316,6 +1326,34 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifOle1PresDataWmfOnly) CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(135660), aOle1Reader.m_nPresentationDataSize); } +CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifAscharObjsize) +{ + // Given a document with an as-char anchored embedded object: + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "reqif-aschar-objsize.odt"; + mxComponent = loadFromDesktop(aURL, "com.sun.star.text.TextDocument", {}); + + // When exporting to reqif-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 that the RTF snippet has the correct aspect ratio: + OUString aRtfUrl = GetOlePath(); + SvMemoryStream aRtf; + HtmlExportTest::wrapRtfFragment(aRtfUrl, aRtf); + tools::SvRef<TestReqIfRtfReader> xReader(new TestReqIfRtfReader(aRtf)); + CPPUNIT_ASSERT(xReader->CallParser() != SvParserState::Error); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 7344 + // - Actual : 2836 + // i.e. the aspect ratio was 1:1, while the PNG aspect ratio was correctly not 1:1. + CPPUNIT_ASSERT_EQUAL(static_cast<long>(7344), xReader->GetObjw()); + CPPUNIT_ASSERT_EQUAL(static_cast<long>(4116), xReader->GetObjh()); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/filter/html/htmlplug.cxx b/sw/source/filter/html/htmlplug.cxx index 525b3b0ea175..5fd6b3e54d7b 100644 --- a/sw/source/filter/html/htmlplug.cxx +++ b/sw/source/filter/html/htmlplug.cxx @@ -1549,7 +1549,7 @@ Writer& OutHTML_FrameFormatOLENodeGrf( Writer& rWrt, const SwFrameFormat& rFrame if (xStream.is()) { std::unique_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xStream)); - if (SwReqIfReader::WrapOleInRtf(*pStream, aOutStream, *pOLENd)) + if (SwReqIfReader::WrapOleInRtf(*pStream, aOutStream, *pOLENd, rFrameFormat)) { // Data always wrapped in RTF. aFileType = aRTFType; @@ -1568,7 +1568,7 @@ Writer& OutHTML_FrameFormatOLENodeGrf( Writer& rWrt, const SwFrameFormat& rFrame aOLEExp.ExportOLEObject(rOLEObj.GetObject(), *pStorage); pStorage->Commit(); aMemory.Seek(0); - if (SwReqIfReader::WrapOleInRtf(aMemory, aOutStream, *pOLENd)) + if (SwReqIfReader::WrapOleInRtf(aMemory, aOutStream, *pOLENd, rFrameFormat)) { // Data always wrapped in RTF. aFileType = aRTFType; diff --git a/sw/source/filter/html/htmlreqifreader.cxx b/sw/source/filter/html/htmlreqifreader.cxx index 3aa3de435b11..a59f56ee40ee 100644 --- a/sw/source/filter/html/htmlreqifreader.cxx +++ b/sw/source/filter/html/htmlreqifreader.cxx @@ -24,6 +24,8 @@ #include <vcl/FilterConfigItem.hxx> #include <vcl/wmf.hxx> #include <comphelper/propertyvalue.hxx> +#include <fmtfsize.hxx> +#include <frmfmt.hxx> using namespace com::sun::star; @@ -427,7 +429,8 @@ bool ExtractOleFromRtf(SvStream& rRtf, SvStream& rOle, bool& bOwnFormat) return true; } -bool WrapOleInRtf(SvStream& rOle2, SvStream& rRtf, SwOLENode& rOLENode) +bool WrapOleInRtf(SvStream& rOle2, SvStream& rRtf, SwOLENode& rOLENode, + const SwFrameFormat& rFormat) { sal_uInt64 nPos = rOle2.Tell(); comphelper::ScopeGuard g([&rOle2, nPos] { rOle2.Seek(nPos); }); @@ -436,7 +439,7 @@ bool WrapOleInRtf(SvStream& rOle2, SvStream& rRtf, SwOLENode& rOLENode) SvMemoryStream aOLE1; // Prepare presentation data early, so it's available to both OLE1 and RTF. - Size aSize(rOLENode.GetTwipSize()); + Size aSize = rFormat.GetFrameSize().GetSize(); sal_uInt32 nWidth = aSize.getWidth(); sal_uInt32 nHeight = aSize.getHeight(); const Graphic* pGraphic = rOLENode.GetGraphic(); diff --git a/sw/source/filter/html/htmlreqifreader.hxx b/sw/source/filter/html/htmlreqifreader.hxx index 3d0816739d6a..5f757d0fbf1d 100644 --- a/sw/source/filter/html/htmlreqifreader.hxx +++ b/sw/source/filter/html/htmlreqifreader.hxx @@ -13,6 +13,7 @@ class Graphic; class Size; class SvStream; class SwOLENode; +class SwFrameFormat; namespace SwReqIfReader { @@ -24,7 +25,8 @@ namespace SwReqIfReader bool ExtractOleFromRtf(SvStream& rRtf, SvStream& rOle, bool& bOwnFormat); /// Wraps an OLE2 container binary in an RTF fragment. -bool WrapOleInRtf(SvStream& rOle2, SvStream& rRtf, SwOLENode& rOLENode); +bool WrapOleInRtf(SvStream& rOle2, SvStream& rRtf, SwOLENode& rOLENode, + const SwFrameFormat& rFormat); /** * Wraps an image in an RTF fragment. _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits