Line data Source code
1 : /*
2 : * This file is part of the LibreOffice project.
3 : *
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/.
7 : */
8 :
9 : #include "rtfstringbuffer.hxx"
10 : #include "rtfattributeoutput.hxx"
11 :
12 1565 : RtfStringBufferValue::RtfStringBufferValue()
13 : : m_aBuffer(),
14 : m_pFlyFrameFormat(0),
15 1565 : m_pGrfNode(0)
16 : {
17 1565 : }
18 :
19 11 : RtfStringBufferValue::RtfStringBufferValue(const SwFlyFrameFormat* pFlyFrameFormat, const SwGrfNode* pGrfNode)
20 : : m_aBuffer(),
21 : m_pFlyFrameFormat(pFlyFrameFormat),
22 11 : m_pGrfNode(pGrfNode)
23 : {
24 11 : }
25 :
26 1548 : void RtfStringBufferValue::makeStringAndClear(RtfAttributeOutput* pAttributeOutput)
27 : {
28 1548 : if (!isGraphic())
29 1537 : pAttributeOutput->m_rExport.Strm().WriteCharPtr(m_aBuffer.makeStringAndClear().getStr());
30 : else
31 11 : pAttributeOutput->FlyFrameGraphic(m_pFlyFrameFormat, m_pGrfNode);
32 1548 : }
33 :
34 32 : OString RtfStringBufferValue::makeStringAndClear()
35 : {
36 32 : return m_aBuffer.makeStringAndClear();
37 : }
38 :
39 10191 : bool RtfStringBufferValue::isGraphic() const
40 : {
41 10191 : return m_pFlyFrameFormat != 0 && m_pGrfNode != 0;
42 : }
43 :
44 1028 : RtfStringBuffer::RtfStringBuffer()
45 1028 : : m_aValues()
46 : {
47 1028 : }
48 :
49 0 : sal_Int32 RtfStringBuffer::getLength() const
50 : {
51 0 : sal_Int32 nRet = 0;
52 0 : for (RtfStringBuffer::Values_t::const_iterator i = m_aValues.begin(); i != m_aValues.end(); ++i)
53 0 : if (!i->isGraphic())
54 0 : nRet += i->m_aBuffer.getLength();
55 0 : return nRet;
56 : }
57 :
58 812 : void RtfStringBuffer::makeStringAndClear(RtfAttributeOutput* pAttributeOutput)
59 : {
60 2360 : for (RtfStringBuffer::Values_t::iterator i = m_aValues.begin(); i != m_aValues.end(); ++i)
61 1548 : i->makeStringAndClear(pAttributeOutput);
62 812 : }
63 :
64 36 : OString RtfStringBuffer::makeStringAndClear()
65 : {
66 36 : OStringBuffer aBuf;
67 68 : for (RtfStringBuffer::Values_t::iterator i = m_aValues.begin(); i != m_aValues.end(); ++i)
68 32 : if (!i->isGraphic())
69 32 : aBuf.append(i->makeStringAndClear());
70 36 : return aBuf.makeStringAndClear();
71 : }
72 :
73 10165 : OStringBuffer& RtfStringBuffer::getLastBuffer()
74 : {
75 10165 : if (m_aValues.empty() || m_aValues.back().isGraphic())
76 1565 : m_aValues.push_back(RtfStringBufferValue());
77 10165 : return m_aValues.back().m_aBuffer;
78 : }
79 :
80 7710 : OStringBuffer* RtfStringBuffer::operator->()
81 : {
82 7710 : return &getLastBuffer();
83 : }
84 :
85 1835 : void RtfStringBuffer::clear()
86 : {
87 1835 : m_aValues.clear();
88 1835 : }
89 :
90 11 : void RtfStringBuffer::append(const SwFlyFrameFormat* pFlyFrameFormat, const SwGrfNode* pGrfNode)
91 : {
92 11 : m_aValues.push_back(RtfStringBufferValue(pFlyFrameFormat, pGrfNode));
93 11 : }
94 :
95 1812 : void RtfStringBuffer::appendAndClear(RtfStringBuffer& rBuf)
96 : {
97 4122 : for (RtfStringBuffer::Values_t::iterator i = rBuf.m_aValues.begin(); i != rBuf.m_aValues.end(); ++i)
98 2310 : m_aValues.push_back(*i);
99 1812 : rBuf.clear();
100 1872 : }
101 :
102 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|