2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 #include "rtfstringbuffer.hxx"
10 #include "rtfattributeoutput.hxx"
11 #include "rtfexport.hxx"
13 RtfStringBufferValue::RtfStringBufferValue() = default;
15 RtfStringBufferValue::RtfStringBufferValue(const SwFlyFrameFormat
* pFlyFrameFormat
,
16 const SwGrfNode
* pGrfNode
)
17 : m_pFlyFrameFormat(pFlyFrameFormat
)
18 , m_pGrfNode(pGrfNode
)
22 void RtfStringBufferValue::makeStringAndClear(RtfAttributeOutput
* pAttributeOutput
)
25 pAttributeOutput
->m_rExport
.Strm().WriteOString(m_aBuffer
.makeStringAndClear());
27 pAttributeOutput
->FlyFrameGraphic(m_pFlyFrameFormat
, m_pGrfNode
);
30 OString
RtfStringBufferValue::makeStringAndClear() { return m_aBuffer
.makeStringAndClear(); }
32 bool RtfStringBufferValue::isGraphic() const
34 return m_pFlyFrameFormat
!= nullptr && m_pGrfNode
!= nullptr;
37 RtfStringBuffer::RtfStringBuffer() = default;
39 sal_Int32
RtfStringBuffer::getLength() const
42 for (const auto& rValue
: m_aValues
)
43 if (!rValue
.isGraphic())
44 nRet
+= rValue
.getBuffer().getLength();
48 void RtfStringBuffer::makeStringAndClear(RtfAttributeOutput
* pAttributeOutput
)
50 for (auto& rValue
: m_aValues
)
51 rValue
.makeStringAndClear(pAttributeOutput
);
54 OString
RtfStringBuffer::makeStringAndClear()
57 for (auto& rValue
: m_aValues
)
58 if (!rValue
.isGraphic())
59 aBuf
.append(rValue
.makeStringAndClear());
60 return aBuf
.makeStringAndClear();
63 OStringBuffer
& RtfStringBuffer::getLastBuffer()
65 if (m_aValues
.empty() || m_aValues
.back().isGraphic())
66 m_aValues
.emplace_back(RtfStringBufferValue());
67 return m_aValues
.back().getBuffer();
70 OStringBuffer
* RtfStringBuffer::operator->() { return &getLastBuffer(); }
72 void RtfStringBuffer::clear() { m_aValues
.clear(); }
74 void RtfStringBuffer::append(const SwFlyFrameFormat
* pFlyFrameFormat
, const SwGrfNode
* pGrfNode
)
76 m_aValues
.emplace_back(RtfStringBufferValue(pFlyFrameFormat
, pGrfNode
));
79 void RtfStringBuffer::appendAndClear(RtfStringBuffer
& rBuf
)
81 for (const auto& rValue
: rBuf
.m_aValues
)
82 m_aValues
.push_back(rValue
);
86 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */