diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-03-07 09:34:38 +0100 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2017-03-10 16:22:42 +0100 |
commit | 13cb8f2b18652e23694609ce5929b1613e2c81ec (patch) | |
tree | 3eab16938a6441557d227b6d3b59fca6de54f578 /writerfilter | |
parent | b6da47459bfb909001d5cf7a97e8a15f653ce796 (diff) |
tdf#104287 RTF import: handle bitmap shapes inside tables
Regression from commit 015fd55c94b7b650ed8e572cafaf3b0f903b01b9
(tdf#96275 RTF import: fix anchor of shapes inside tables, 2016-05-10),
the problem was that since shapes inside tables are now buffered, some
previously hidden problems in the buffering became visible.
For one, there was no code to make sure that a bitmap shape is not
appended at the end of the buffer again when it gets re-played. For
another, only the bitmap shape itself was buffered, not its size.
(cherry picked from commit 8240be9170cc473506531dad2fda82469ae84443)
Conflicts:
sw/qa/extras/rtfimport/rtfimport.cxx
writerfilter/source/rtftok/rtfvalue.cxx
writerfilter/source/rtftok/rtfvalue.hxx
Change-Id: I04d65eb794ff6b160ef77af85479ba25ea5f8aa7
Reviewed-on: https://gerrit.libreoffice.org/34953
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
(cherry picked from commit 9a899023db876630b74493da588b4a5490f90894)
Diffstat (limited to 'writerfilter')
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.cxx | 13 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.hxx | 4 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfvalue.cxx | 52 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfvalue.hxx | 6 |
4 files changed, 60 insertions, 15 deletions
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index 19bc1599e668..07ecb5fd5c2c 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -1530,7 +1530,14 @@ void RTFDocumentImpl::replayBuffer(RTFBuffer_t& rBuffer, else if (std::get<0>(aTuple) == BUFFER_STARTSHAPE) m_pSdrImport->resolve(std::get<1>(aTuple)->getShape(), false, RTFSdrImport::SHAPE); else if (std::get<0>(aTuple) == BUFFER_RESOLVESHAPE) + { + // Make sure there is no current buffer while replaying the shape, + // otherwise it gets re-buffered. + RTFBuffer_t* pCurrentBuffer = m_aStates.top().pCurrentBuffer; + m_aStates.top().pCurrentBuffer = nullptr; m_pSdrImport->resolve(std::get<1>(aTuple)->getShape(), true, RTFSdrImport::SHAPE); + m_aStates.top().pCurrentBuffer = pCurrentBuffer; + } else if (std::get<0>(aTuple) == BUFFER_ENDSHAPE) m_pSdrImport->close(); else if (std::get<0>(aTuple) == BUFFER_RESOLVESUBSTREAM) @@ -1541,6 +1548,8 @@ void RTFDocumentImpl::replayBuffer(RTFBuffer_t& rBuffer, OUString aCustomMark = rAttributes.find(2)->getString(); resolveSubstream(nPos, nId, aCustomMark); } + else if (std::get<0>(aTuple) == BUFFER_PICTURE) + m_aStates.top().aPicture = std::get<1>(aTuple)->getPicture(); else assert(false); } @@ -2085,6 +2094,10 @@ RTFError RTFDocumentImpl::popState() else { // Shape inside table: buffer the import to have correct anchor position. + // Also buffer the RTFPicture of the state stack as it contains + // the shape size. + auto pPictureValue = std::make_shared<RTFValue>(m_aStates.top().aPicture); + m_aStates.top().pCurrentBuffer->push_back(Buf_t(BUFFER_PICTURE, pPictureValue, nullptr)); auto pValue = std::make_shared<RTFValue>(m_aStates.top().aShape); m_aStates.top().pCurrentBuffer->push_back(Buf_t(BUFFER_RESOLVESHAPE, pValue, nullptr)); } diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx index 09905dcd50f6..bb79a6ed53df 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx @@ -59,7 +59,9 @@ enum RTFBufferTypes /// Imports a shape. BUFFER_RESOLVESHAPE, BUFFER_ENDSHAPE, - BUFFER_RESOLVESUBSTREAM + BUFFER_RESOLVESUBSTREAM, + /// Restores RTFParserState::aPicture. + BUFFER_PICTURE }; /// Form field types diff --git a/writerfilter/source/rtftok/rtfvalue.cxx b/writerfilter/source/rtftok/rtfvalue.cxx index dbfe14cfceaa..4814e883a3b4 100644 --- a/writerfilter/source/rtftok/rtfvalue.cxx +++ b/writerfilter/source/rtftok/rtfvalue.cxx @@ -24,7 +24,8 @@ RTFValue::RTFValue(int nValue, const OUString& sValue, uno::Reference<io::XInputStream> const& xStream, uno::Reference<embed::XEmbeddedObject> const& xObject, bool bForceString, - const RTFShape& aShape) + const RTFShape& aShape, + const RTFPicture& rPicture) : m_nValue(nValue), m_sValue(sValue), m_pAttributes(std::make_shared<RTFSprms>(rAttributes)), @@ -33,7 +34,8 @@ RTFValue::RTFValue(int nValue, const OUString& sValue, m_xStream(xStream), m_xObject(xObject), m_bForceString(bForceString), - m_pShape(std::make_shared<RTFShape>(aShape)) + m_pShape(std::make_shared<RTFShape>(aShape)), + m_pPicture(std::make_shared<RTFPicture>(rPicture)) { } @@ -46,7 +48,8 @@ RTFValue::RTFValue() m_xStream(), m_xObject(), m_bForceString(false), - m_pShape(std::make_shared<RTFShape>()) + m_pShape(std::make_shared<RTFShape>()), + m_pPicture(std::make_shared<RTFPicture>()) { } @@ -58,7 +61,8 @@ RTFValue::RTFValue(int nValue) m_xShape(), m_xStream(), m_xObject(), - m_bForceString(false) + m_bForceString(false), + m_pPicture(std::make_shared<RTFPicture>()) { m_pShape.reset(new RTFShape()); } @@ -72,7 +76,8 @@ RTFValue::RTFValue(const OUString& sValue, bool bForce) m_xStream(), m_xObject(), m_bForceString(bForce), - m_pShape(std::make_shared<RTFShape>()) + m_pShape(std::make_shared<RTFShape>()), + m_pPicture(std::make_shared<RTFPicture>()) { } @@ -85,7 +90,8 @@ RTFValue::RTFValue(RTFSprms rAttributes) m_xStream(), m_xObject(), m_bForceString(false), - m_pShape(std::make_shared<RTFShape>()) + m_pShape(std::make_shared<RTFShape>()), + m_pPicture(std::make_shared<RTFPicture>()) { } @@ -98,7 +104,8 @@ RTFValue::RTFValue(RTFSprms rAttributes, RTFSprms rSprms) m_xStream(), m_xObject(), m_bForceString(false), - m_pShape(std::make_shared<RTFShape>()) + m_pShape(std::make_shared<RTFShape>()), + m_pPicture(std::make_shared<RTFPicture>()) { } @@ -111,7 +118,8 @@ RTFValue::RTFValue(uno::Reference<drawing::XShape> const& xShape) m_xStream(), m_xObject(), m_bForceString(false), - m_pShape(std::make_shared<RTFShape>()) + m_pShape(std::make_shared<RTFShape>()), + m_pPicture(std::make_shared<RTFPicture>()) { } @@ -124,7 +132,8 @@ RTFValue::RTFValue(uno::Reference<io::XInputStream> const& xStream) m_xStream(xStream), m_xObject(), m_bForceString(false), - m_pShape(std::make_shared<RTFShape>()) + m_pShape(std::make_shared<RTFShape>()), + m_pPicture(std::make_shared<RTFPicture>()) { } @@ -137,7 +146,8 @@ RTFValue::RTFValue(uno::Reference<embed::XEmbeddedObject> const& xObject) m_xStream(), m_xObject(xObject), m_bForceString(false), - m_pShape(std::make_shared<RTFShape>()) + m_pShape(std::make_shared<RTFShape>()), + m_pPicture(std::make_shared<RTFPicture>()) { } @@ -150,7 +160,18 @@ RTFValue::RTFValue(const RTFShape& aShape) m_xStream(), m_xObject(), m_bForceString(false), - m_pShape(std::make_shared<RTFShape>(aShape)) + m_pShape(std::make_shared<RTFShape>(aShape)), + m_pPicture(std::make_shared<RTFPicture>()) +{ +} + +RTFValue::RTFValue(const RTFPicture& rPicture) + : m_nValue(), + m_pAttributes(std::make_shared<RTFSprms>()), + m_pSprms(std::make_shared<RTFSprms>()), + m_bForceString(false), + m_pShape(std::make_shared<RTFShape>()), + m_pPicture(std::make_shared<RTFPicture>(rPicture)) { } @@ -195,6 +216,11 @@ RTFShape& RTFValue::getShape() const return *m_pShape; } +RTFPicture& RTFValue::getPicture() const +{ + return *m_pPicture; +} + writerfilter::Reference<Properties>::Pointer_t RTFValue::getProperties() { return std::make_shared<RTFReferenceProperties>(*m_pAttributes, *m_pSprms); @@ -217,12 +243,12 @@ std::string RTFValue::toString() const RTFValue* RTFValue::Clone() { - return new RTFValue(m_nValue, m_sValue, *m_pAttributes, *m_pSprms, m_xShape, m_xStream, m_xObject, m_bForceString, *m_pShape); + return new RTFValue(m_nValue, m_sValue, *m_pAttributes, *m_pSprms, m_xShape, m_xStream, m_xObject, m_bForceString, *m_pShape, *m_pPicture); } RTFValue* RTFValue::CloneWithSprms(RTFSprms const& rAttributes, RTFSprms const& rSprms) { - return new RTFValue(m_nValue, m_sValue, rAttributes, rSprms, m_xShape, m_xStream, m_xObject, m_bForceString, *m_pShape); + return new RTFValue(m_nValue, m_sValue, rAttributes, rSprms, m_xShape, m_xStream, m_xObject, m_bForceString, *m_pShape, *m_pPicture); } bool RTFValue::equals(RTFValue& rOther) diff --git a/writerfilter/source/rtftok/rtfvalue.hxx b/writerfilter/source/rtftok/rtfvalue.hxx index eeb973094021..689258175507 100644 --- a/writerfilter/source/rtftok/rtfvalue.hxx +++ b/writerfilter/source/rtftok/rtfvalue.hxx @@ -20,6 +20,7 @@ namespace rtftok { class RTFSprms; class RTFShape; +class RTFPicture; /// Value of an RTF keyword class RTFValue : public Value @@ -30,7 +31,7 @@ public: css::uno::Reference<css::drawing::XShape> const& xShape, css::uno::Reference<css::io::XInputStream> const& xStream, css::uno::Reference<css::embed::XEmbeddedObject> const& xObject, - bool bForceString, const RTFShape& aShape); + bool bForceString, const RTFShape& aShape, const RTFPicture& rPicture); RTFValue(); RTFValue(int nValue); RTFValue(const OUString& sValue, bool bForce = false); @@ -40,6 +41,7 @@ public: RTFValue(css::uno::Reference<css::io::XInputStream> const& xStream); RTFValue(css::uno::Reference<css::embed::XEmbeddedObject> const& xObject); RTFValue(const RTFShape& aShape); + RTFValue(const RTFPicture& rPicture); virtual ~RTFValue() override; void setString(const OUString& sValue); virtual int getInt() const override; @@ -55,6 +57,7 @@ public: RTFSprms& getAttributes(); RTFSprms& getSprms(); RTFShape& getShape() const; + RTFPicture& getPicture() const; bool equals(RTFValue& rOther); private: RTFValue& operator=(RTFValue const& rOther) = delete; @@ -67,6 +70,7 @@ private: css::uno::Reference<css::embed::XEmbeddedObject> m_xObject; bool m_bForceString; std::shared_ptr<RTFShape> m_pShape; + std::shared_ptr<RTFPicture> m_pPicture; }; } // namespace rtftok } // namespace writerfilter |