Kaydet (Commit) 4ed3acc1 authored tarafından Miklos Vajna's avatar Miklos Vajna

introduce RtfStringBuffer

It's a wrapper around OStringBuffer to handle export of graphics more
efficiently.
üst 85887d55
...@@ -90,6 +90,7 @@ $(eval $(call gb_Library_add_exception_objects,msword,\ ...@@ -90,6 +90,7 @@ $(eval $(call gb_Library_add_exception_objects,msword,\
sw/source/filter/ww8/rtfexportfilter \ sw/source/filter/ww8/rtfexportfilter \
sw/source/filter/ww8/rtfimportfilter \ sw/source/filter/ww8/rtfimportfilter \
sw/source/filter/ww8/rtfsdrexport \ sw/source/filter/ww8/rtfsdrexport \
sw/source/filter/ww8/rtfstringbuffer \
sw/source/filter/ww8/WW8FFData \ sw/source/filter/ww8/WW8FFData \
sw/source/filter/ww8/WW8FibData \ sw/source/filter/ww8/WW8FibData \
sw/source/filter/ww8/WW8Sttbf \ sw/source/filter/ww8/WW8Sttbf \
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "attributeoutputbase.hxx" #include "attributeoutputbase.hxx"
#include "rtfexport.hxx" #include "rtfexport.hxx"
#include "rtfstringbuffer.hxx"
#include <rtl/strbuf.hxx> #include <rtl/strbuf.hxx>
...@@ -43,6 +44,7 @@ class SwFlyFrmFmt; ...@@ -43,6 +44,7 @@ class SwFlyFrmFmt;
/// The class that has handlers for various resource types when exporting as RTF /// The class that has handlers for various resource types when exporting as RTF
class RtfAttributeOutput : public AttributeOutputBase class RtfAttributeOutput : public AttributeOutputBase
{ {
friend class RtfStringBufferValue;
public: public:
/// Export the state of RTL/CJK. /// Export the state of RTL/CJK.
virtual void RTLAndCJKState( bool bIsRTL, sal_uInt16 nScript ); virtual void RTLAndCJKState( bool bIsRTL, sal_uInt16 nScript );
...@@ -446,8 +448,8 @@ private: ...@@ -446,8 +448,8 @@ private:
* This is needed because the call order is: run text, run properties, paragraph properties. * This is needed because the call order is: run text, run properties, paragraph properties.
* What we need is the opposite. * What we need is the opposite.
*/ */
rtl::OStringBuffer m_aRun; RtfStringBuffer m_aRun;
rtl::OStringBuffer m_aRunText; RtfStringBuffer m_aRunText;
/* /*
* This is written after runs. * This is written after runs.
*/ */
......
...@@ -447,12 +447,12 @@ void RtfSdrExport::impl_writeGraphic() ...@@ -447,12 +447,12 @@ void RtfSdrExport::impl_writeGraphic()
Size aMapped(aGraphic.GetPrefSize()); Size aMapped(aGraphic.GetPrefSize());
// Add it to the properties. // Add it to the properties.
OStringBuffer aBuf; RtfStringBuffer aBuf;
aBuf.append('{').append(OOO_STRING_SVTOOLS_RTF_PICT).append(OOO_STRING_SVTOOLS_RTF_PNGBLIP); aBuf->append('{').append(OOO_STRING_SVTOOLS_RTF_PICT).append(OOO_STRING_SVTOOLS_RTF_PNGBLIP);
aBuf.append(OOO_STRING_SVTOOLS_RTF_PICW).append(sal_Int32(aMapped.Width())); aBuf->append(OOO_STRING_SVTOOLS_RTF_PICW).append(sal_Int32(aMapped.Width()));
aBuf.append(OOO_STRING_SVTOOLS_RTF_PICH).append(sal_Int32(aMapped.Height())).append(RtfExport::sNewLine); aBuf->append(OOO_STRING_SVTOOLS_RTF_PICH).append(sal_Int32(aMapped.Height())).append(RtfExport::sNewLine);
aBuf.append(RtfAttributeOutput::WriteHex(pGraphicAry, nSize)); aBuf->append(RtfAttributeOutput::WriteHex(pGraphicAry, nSize));
aBuf.append('}'); aBuf->append('}');
m_aShapeProps.insert(std::pair<OString,OString>(OString("pib"), aBuf.makeStringAndClear())); m_aShapeProps.insert(std::pair<OString,OString>(OString("pib"), aBuf.makeStringAndClear()));
} }
......
/*
* 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: */
/*
* 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.
*/
#ifndef _RTFSTRINGBUFFER_HXX_
#define _RTFSTRINGBUFFER_HXX_
#include <rtl/strbuf.hxx>
#include <vector>
class SwGrfNode;
class SwFlyFrmFmt;
class RtfAttributeOutput;
/// Contains a buffered string or graphic during RTF export.
class RtfStringBufferValue
{
public:
/// Constructor for a string buffering.
RtfStringBufferValue();
/// Constructor for graphic buffering.
RtfStringBufferValue(const SwFlyFrmFmt* pFlyFrmFmt, const SwGrfNode* pGrfNode);
/// This version handles graphics.
void makeStringAndClear(RtfAttributeOutput* pAttributeOutput);
/// This one doesn't.
rtl::OString makeStringAndClear();
bool isGraphic() const;
rtl::OStringBuffer m_aBuffer;
const SwFlyFrmFmt* m_pFlyFrmFmt;
const SwGrfNode* m_pGrfNode;
};
/// Wrapper around OStringBuffers, so less hexdump of graphics have to be kept in memory during RTF export.
class RtfStringBuffer
{
public:
RtfStringBuffer();
/// Length of all the contained buffers.
sal_Int32 getLength() const;
/// Writes the contents of the buffer directly to the supplied stream.
void makeStringAndClear(RtfAttributeOutput* pAttributeOutput);
/// Returns the bufferent strings as a string (ignores graphic elements!)
rtl::OString makeStringAndClear();
/// Access to the last buffer.
rtl::OStringBuffer& getLastBuffer();
rtl::OStringBuffer* operator->();
/// Similar to ->setLength(0), but for all buffers.
void clear();
/// Same as ->append(), but for graphics and without expanding contents to save memory.
void append(const SwFlyFrmFmt* pFlyFrmFmt, const SwGrfNode* pGrfNode);
/// Append all contained buffers and clear the argument.
void appendAndClear(RtfStringBuffer& rBuf);
private:
typedef std::vector<RtfStringBufferValue> Values_t;
Values_t m_aValues;
};
#endif // _RTFSTRINGBUFFER_HXX_
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment