LibreOffice Module sw (master)  1
rtfstringbuffer.cxx
Go to the documentation of this file.
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 #include "rtfexport.hxx"
12 
14 
16  const SwGrfNode* pGrfNode)
17  : m_pFlyFrameFormat(pFlyFrameFormat)
18  , m_pGrfNode(pGrfNode)
19 {
20 }
21 
23 {
24  if (!isGraphic())
25  pAttributeOutput->m_rExport.Strm().WriteCharPtr(m_aBuffer.makeStringAndClear().getStr());
26  else
27  pAttributeOutput->FlyFrameGraphic(m_pFlyFrameFormat, m_pGrfNode);
28 }
29 
30 OString RtfStringBufferValue::makeStringAndClear() { return m_aBuffer.makeStringAndClear(); }
31 
33 {
34  return m_pFlyFrameFormat != nullptr && m_pGrfNode != nullptr;
35 }
36 
38 
39 sal_Int32 RtfStringBuffer::getLength() const
40 {
41  sal_Int32 nRet = 0;
42  for (const auto& rValue : m_aValues)
43  if (!rValue.isGraphic())
44  nRet += rValue.getBuffer().getLength();
45  return nRet;
46 }
47 
49 {
50  for (auto& rValue : m_aValues)
51  rValue.makeStringAndClear(pAttributeOutput);
52 }
53 
55 {
56  OStringBuffer aBuf;
57  for (auto& rValue : m_aValues)
58  if (!rValue.isGraphic())
59  aBuf.append(rValue.makeStringAndClear());
60  return aBuf.makeStringAndClear();
61 }
62 
64 {
65  if (m_aValues.empty() || m_aValues.back().isGraphic())
66  m_aValues.emplace_back(RtfStringBufferValue());
67  return m_aValues.back().getBuffer();
68 }
69 
70 OStringBuffer* RtfStringBuffer::operator->() { return &getLastBuffer(); }
71 
72 void RtfStringBuffer::clear() { m_aValues.clear(); }
73 
74 void RtfStringBuffer::append(const SwFlyFrameFormat* pFlyFrameFormat, const SwGrfNode* pGrfNode)
75 {
76  m_aValues.emplace_back(RtfStringBufferValue(pFlyFrameFormat, pGrfNode));
77 }
78 
80 {
81  for (const auto& rValue : rBuf.m_aValues)
82  m_aValues.push_back(rValue);
83  rBuf.clear();
84 }
85 
86 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 getLength() const
Length of all the contained buffers.
Wrapper around OStringBuffers, so less hexdump of graphics have to be kept in memory during RTF expor...
Contains a buffered string or graphic during RTF export.
const SwFlyFrameFormat * m_pFlyFrameFormat
SvStream & Strm()
Definition: rtfexport.cxx:1069
aBuf
void FlyFrameGraphic(const SwFlyFrameFormat *pFlyFrameFormat, const SwGrfNode *pGrfNode)
Output graphic fly frames.
void clear()
Similar to ->setLength(0), but for all buffers.
SvStream & WriteCharPtr(const char *pBuf)
The class that has handlers for various resource types when exporting as RTF.
RtfExport & m_rExport
Reference to the export, where to get the data from.
void appendAndClear(RtfStringBuffer &rBuf)
Append all contained buffers and clear the argument.
const SwGrfNode * m_pGrfNode
OStringBuffer & getLastBuffer()
Access to the last buffer.
OString makeStringAndClear()
This one doesn't.
void append(const SwFlyFrameFormat *pFlyFrameFormat, const SwGrfNode *pGrfNode)
Same as ->append(), but for graphics and without expanding contents to save memory.
OString makeStringAndClear()
Returns the buffered strings as a string (ignores graphic elements!)
RtfStringBufferValue()
Constructor for a string buffering.
OStringBuffer * operator->()