summaryrefslogtreecommitdiff
path: root/sw/source/filter/ww8/rtfstringbuffer.cxx
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@suse.cz>2012-03-05 09:43:25 +0100
committerMiklos Vajna <vmiklos@suse.cz>2012-03-05 10:09:25 +0100
commit4ed3acc18e70a6c867e827c19f8ccf7fa925b9c5 (patch)
tree16fc6d3dee110629e9cefaa15bfae87091947de2 /sw/source/filter/ww8/rtfstringbuffer.cxx
parent85887d554141c33d4a9803ab2fd7765dadf7e64d (diff)
introduce RtfStringBuffer
It's a wrapper around OStringBuffer to handle export of graphics more efficiently.
Diffstat (limited to 'sw/source/filter/ww8/rtfstringbuffer.cxx')
-rw-r--r--sw/source/filter/ww8/rtfstringbuffer.cxx121
1 files changed, 121 insertions, 0 deletions
diff --git a/sw/source/filter/ww8/rtfstringbuffer.cxx b/sw/source/filter/ww8/rtfstringbuffer.cxx
new file mode 100644
index 000000000000..554adb1f48cb
--- /dev/null
+++ b/sw/source/filter/ww8/rtfstringbuffer.cxx
@@ -0,0 +1,121 @@
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Initial Developer of the Original Code is
+ * Miklos Vajna <vmiklos@suse.cz> (SUSE, Inc.)
+ * Portions created by the Initial Developer are Copyright (C) 2012 the
+ * Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+#include "rtfattributeoutput.hxx"
+#include "rtfstringbuffer.hxx"
+
+RtfStringBufferValue::RtfStringBufferValue()
+ : m_aBuffer(),
+ m_pFlyFrmFmt(0),
+ m_pGrfNode(0)
+{
+}
+
+RtfStringBufferValue::RtfStringBufferValue(const SwFlyFrmFmt* pFlyFrmFmt, const SwGrfNode* pGrfNode)
+ : m_aBuffer(),
+ m_pFlyFrmFmt(pFlyFrmFmt),
+ m_pGrfNode(pGrfNode)
+{
+}
+
+void RtfStringBufferValue::makeStringAndClear(RtfAttributeOutput* pAttributeOutput)
+{
+ if (!isGraphic())
+ pAttributeOutput->m_rExport.Strm() << m_aBuffer.makeStringAndClear().getStr();
+ else
+ pAttributeOutput->FlyFrameGraphic(m_pFlyFrmFmt, m_pGrfNode);
+}
+
+rtl::OString RtfStringBufferValue::makeStringAndClear()
+{
+ return m_aBuffer.makeStringAndClear();
+}
+
+bool RtfStringBufferValue::isGraphic() const
+{
+ return m_pFlyFrmFmt != 0 && m_pGrfNode != 0;
+}
+
+RtfStringBuffer::RtfStringBuffer()
+ : m_aValues()
+{
+}
+
+sal_Int32 RtfStringBuffer::getLength() const
+{
+ sal_Int32 nRet = 0;
+ for (RtfStringBuffer::Values_t::const_iterator i = m_aValues.begin(); i != m_aValues.end(); ++i)
+ if (!i->isGraphic())
+ nRet += i->m_aBuffer.getLength();
+ return nRet;
+}
+
+void RtfStringBuffer::makeStringAndClear(RtfAttributeOutput* pAttributeOutput)
+{
+ for (RtfStringBuffer::Values_t::iterator i = m_aValues.begin(); i != m_aValues.end(); ++i)
+ i->makeStringAndClear(pAttributeOutput);
+}
+
+rtl::OString RtfStringBuffer::makeStringAndClear()
+{
+ rtl::OStringBuffer aBuf;
+ for (RtfStringBuffer::Values_t::iterator i = m_aValues.begin(); i != m_aValues.end(); ++i)
+ if (!i->isGraphic())
+ aBuf.append(i->makeStringAndClear());
+ return aBuf.makeStringAndClear();
+}
+
+rtl::OStringBuffer& RtfStringBuffer::getLastBuffer()
+{
+ if (!m_aValues.size() || m_aValues.back().isGraphic())
+ m_aValues.push_back(RtfStringBufferValue());
+ return m_aValues.back().m_aBuffer;
+}
+
+rtl::OStringBuffer* RtfStringBuffer::operator->()
+{
+ return &getLastBuffer();
+}
+
+void RtfStringBuffer::clear()
+{
+ m_aValues.clear();
+}
+
+void RtfStringBuffer::append(const SwFlyFrmFmt* pFlyFrmFmt, const SwGrfNode* pGrfNode)
+{
+ m_aValues.push_back(RtfStringBufferValue(pFlyFrmFmt, pGrfNode));
+}
+
+void RtfStringBuffer::appendAndClear(RtfStringBuffer& rBuf)
+{
+ for (RtfStringBuffer::Values_t::iterator i = rBuf.m_aValues.begin(); i != rBuf.m_aValues.end(); ++i)
+ m_aValues.push_back(*i);
+ rBuf.clear();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */