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 "rtfattributeoutput.hxx"
10 : #include "rtfstringbuffer.hxx"
11 :
12 883 : RtfStringBufferValue::RtfStringBufferValue()
13 : : m_aBuffer(),
14 : m_pFlyFrmFmt(0),
15 883 : m_pGrfNode(0)
16 : {
17 883 : }
18 :
19 1 : RtfStringBufferValue::RtfStringBufferValue(const SwFlyFrmFmt* pFlyFrmFmt, const SwGrfNode* pGrfNode)
20 : : m_aBuffer(),
21 : m_pFlyFrmFmt(pFlyFrmFmt),
22 1 : m_pGrfNode(pGrfNode)
23 : {
24 1 : }
25 :
26 858 : void RtfStringBufferValue::makeStringAndClear(RtfAttributeOutput* pAttributeOutput)
27 : {
28 858 : if (!isGraphic())
29 857 : pAttributeOutput->m_rExport.Strm().WriteCharPtr( m_aBuffer.makeStringAndClear().getStr() );
30 : else
31 1 : pAttributeOutput->FlyFrameGraphic(m_pFlyFrmFmt, m_pGrfNode);
32 858 : }
33 :
34 31 : OString RtfStringBufferValue::makeStringAndClear()
35 : {
36 31 : return m_aBuffer.makeStringAndClear();
37 : }
38 :
39 5664 : bool RtfStringBufferValue::isGraphic() const
40 : {
41 5664 : return m_pFlyFrmFmt != 0 && m_pGrfNode != 0;
42 : }
43 :
44 633 : RtfStringBuffer::RtfStringBuffer()
45 633 : : m_aValues()
46 : {
47 633 : }
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 512 : void RtfStringBuffer::makeStringAndClear(RtfAttributeOutput* pAttributeOutput)
59 : {
60 1370 : for (RtfStringBuffer::Values_t::iterator i = m_aValues.begin(); i != m_aValues.end(); ++i)
61 858 : i->makeStringAndClear(pAttributeOutput);
62 512 : }
63 :
64 31 : OString RtfStringBuffer::makeStringAndClear()
65 : {
66 31 : OStringBuffer aBuf;
67 62 : for (RtfStringBuffer::Values_t::iterator i = m_aValues.begin(); i != m_aValues.end(); ++i)
68 31 : if (!i->isGraphic())
69 31 : aBuf.append(i->makeStringAndClear());
70 31 : return aBuf.makeStringAndClear();
71 : }
72 :
73 5657 : OStringBuffer& RtfStringBuffer::getLastBuffer()
74 : {
75 5657 : if (m_aValues.empty() || m_aValues.back().isGraphic())
76 883 : m_aValues.push_back(RtfStringBufferValue());
77 5657 : return m_aValues.back().m_aBuffer;
78 : }
79 :
80 4486 : OStringBuffer* RtfStringBuffer::operator->()
81 : {
82 4486 : return &getLastBuffer();
83 : }
84 :
85 1138 : void RtfStringBuffer::clear()
86 : {
87 1138 : m_aValues.clear();
88 1138 : }
89 :
90 1 : void RtfStringBuffer::append(const SwFlyFrmFmt* pFlyFrmFmt, const SwGrfNode* pGrfNode)
91 : {
92 1 : m_aValues.push_back(RtfStringBufferValue(pFlyFrmFmt, pGrfNode));
93 1 : }
94 :
95 1118 : void RtfStringBuffer::appendAndClear(RtfStringBuffer& rBuf)
96 : {
97 2363 : for (RtfStringBuffer::Values_t::iterator i = rBuf.m_aValues.begin(); i != rBuf.m_aValues.end(); ++i)
98 1245 : m_aValues.push_back(*i);
99 1118 : rBuf.clear();
100 1118 : }
101 :
102 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|