summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2021-04-16 10:14:05 +0200
committerMiklos Vajna <vmiklos@collabora.com>2021-04-16 10:58:49 +0200
commit21cd910d144b14ead358bccd1146650806346eb5 (patch)
tree2b949bdd9ae68b5f44b596e7073e47e31577e822 /sw
parent0255a3f1704e50c478bd9a9e3e389a5e1f23ae81 (diff)
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). Change-Id: I7e240c1e115846c17b0945376b0de02d19769100 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114197 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/htmlexport/data/reqif-aschar-objsize.odtbin0 -> 70411 bytes
-rw-r--r--sw/qa/extras/htmlexport/htmlexport.cxx38
-rw-r--r--sw/source/filter/html/htmlplug.cxx4
-rw-r--r--sw/source/filter/html/htmlreqifreader.cxx7
-rw-r--r--sw/source/filter/html/htmlreqifreader.hxx4
5 files changed, 48 insertions, 5 deletions
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
--- /dev/null
+++ b/sw/qa/extras/htmlexport/data/reqif-aschar-objsize.odt
Binary files differ
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index 52eb25978a10..a6795abc253f 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -58,10 +58,14 @@ public:
TestReqIfRtfReader(SvStream& rStream);
void NextToken(int nToken) override;
bool WriteObjectData(SvStream& rOLE);
+ tools::Long GetObjw() const { return m_nObjw; }
+ tools::Long GetObjh() const { return m_nObjh; }
private:
bool m_bInObjData = false;
OStringBuffer m_aHex;
+ tools::Long m_nObjw = 0;
+ tools::Long m_nObjh = 0;
};
TestReqIfRtfReader::TestReqIfRtfReader(SvStream& rStream)
@@ -83,6 +87,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;
}
}
@@ -1373,6 +1383,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<tools::Long>(7344), xReader->GetObjw());
+ CPPUNIT_ASSERT_EQUAL(static_cast<tools::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 65e0419f4ed9..a744e6cb64ff 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 c0a3196bb018..6c9155fbc556 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.