diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 05:54:39 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 05:54:39 +0000 |
commit | 267c6f2ac71f92999e969232431ba04678e7437e (patch) | |
tree | 358c9467650e1d0a1d7227a21dac2e3d08b622b2 /sw/source/filter/ww8/rtfstringbuffer.cxx | |
parent | Initial commit. (diff) | |
download | libreoffice-267c6f2ac71f92999e969232431ba04678e7437e.tar.xz libreoffice-267c6f2ac71f92999e969232431ba04678e7437e.zip |
Adding upstream version 4:24.2.0.upstream/4%24.2.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sw/source/filter/ww8/rtfstringbuffer.cxx')
-rw-r--r-- | sw/source/filter/ww8/rtfstringbuffer.cxx | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/sw/source/filter/ww8/rtfstringbuffer.cxx b/sw/source/filter/ww8/rtfstringbuffer.cxx new file mode 100644 index 0000000000..ae491e45b4 --- /dev/null +++ b/sw/source/filter/ww8/rtfstringbuffer.cxx @@ -0,0 +1,88 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "rtfstringbuffer.hxx" +#include "rtfattributeoutput.hxx" +#include "rtfexport.hxx" + +RtfStringBufferValue::RtfStringBufferValue() = default; + +RtfStringBufferValue::RtfStringBufferValue(const SwFlyFrameFormat* pFlyFrameFormat, + const SwGrfNode* pGrfNode) + : m_pFlyFrameFormat(pFlyFrameFormat) + , m_pGrfNode(pGrfNode) +{ +} + +void RtfStringBufferValue::makeStringAndClear(RtfAttributeOutput* pAttributeOutput) +{ + if (!isGraphic()) + { + pAttributeOutput->m_rExport.Strm().WriteOString(m_aBuffer); + m_aBuffer.setLength(0); + } + else + pAttributeOutput->FlyFrameGraphic(m_pFlyFrameFormat, m_pGrfNode); +} + +OString RtfStringBufferValue::makeStringAndClear() { return m_aBuffer.makeStringAndClear(); } + +bool RtfStringBufferValue::isGraphic() const +{ + return m_pFlyFrameFormat != nullptr && m_pGrfNode != nullptr; +} + +RtfStringBuffer::RtfStringBuffer() = default; + +sal_Int32 RtfStringBuffer::getLength() const +{ + sal_Int32 nRet = 0; + for (const auto& rValue : m_aValues) + if (!rValue.isGraphic()) + nRet += rValue.getBuffer().getLength(); + return nRet; +} + +void RtfStringBuffer::makeStringAndClear(RtfAttributeOutput* pAttributeOutput) +{ + for (auto& rValue : m_aValues) + rValue.makeStringAndClear(pAttributeOutput); +} + +OString RtfStringBuffer::makeStringAndClear() +{ + OStringBuffer aBuf; + for (auto& rValue : m_aValues) + if (!rValue.isGraphic()) + aBuf.append(rValue.makeStringAndClear()); + return aBuf.makeStringAndClear(); +} + +OStringBuffer& RtfStringBuffer::getLastBuffer() +{ + if (m_aValues.empty() || m_aValues.back().isGraphic()) + m_aValues.emplace_back(); + return m_aValues.back().getBuffer(); +} + +OStringBuffer* RtfStringBuffer::operator->() { return &getLastBuffer(); } + +void RtfStringBuffer::clear() { m_aValues.clear(); } + +void RtfStringBuffer::append(const SwFlyFrameFormat* pFlyFrameFormat, const SwGrfNode* pGrfNode) +{ + m_aValues.emplace_back(pFlyFrameFormat, pGrfNode); +} + +void RtfStringBuffer::appendAndClear(RtfStringBuffer& rBuf) +{ + m_aValues.insert(m_aValues.end(), rBuf.m_aValues.begin(), rBuf.m_aValues.end()); + rBuf.clear(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |