summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@suse.cz>2012-07-25 15:43:54 +0200
committerMiklos Vajna <vmiklos@suse.cz>2012-07-25 17:07:35 +0200
commit041961e18b16c64d1395b1ed6fcb460d82b9939a (patch)
tree9356ca1ab07a8979852a5efada9257616146c59a
parent05035c894644f700fdc972b51dbd918f7530b2d5 (diff)
move rtf escaping functions to msfilter, so starmath can use them as well
Change-Id: Ib847f5207f3f36585427313c1454b0fba730c503
-rw-r--r--filter/Library_msfilter.mk1
-rw-r--r--filter/Package_inc.mk1
-rw-r--r--filter/inc/filter/msfilter/rtfutil.hxx54
-rw-r--r--filter/source/msfilter/rtfutil.cxx151
-rw-r--r--sw/source/filter/ww8/rtfattributeoutput.cxx31
-rw-r--r--sw/source/filter/ww8/rtfexport.cxx129
-rw-r--r--sw/source/filter/ww8/rtfexport.hxx3
-rw-r--r--sw/source/filter/ww8/rtfsdrexport.cxx7
8 files changed, 236 insertions, 141 deletions
diff --git a/filter/Library_msfilter.mk b/filter/Library_msfilter.mk
index a592fbf9ffeb..c7eebae6df41 100644
--- a/filter/Library_msfilter.mk
+++ b/filter/Library_msfilter.mk
@@ -67,6 +67,7 @@ $(eval $(call gb_Library_add_exception_objects,msfilter,\
filter/source/msfilter/services \
filter/source/msfilter/svdfppt \
filter/source/msfilter/svxmsbas2 \
+ filter/source/msfilter/rtfutil \
filter/source/msfilter/util \
))
diff --git a/filter/Package_inc.mk b/filter/Package_inc.mk
index 141cc29dabfa..578fe96207df 100644
--- a/filter/Package_inc.mk
+++ b/filter/Package_inc.mk
@@ -29,6 +29,7 @@ $(eval $(call gb_Package_add_file,filter_inc,inc/filter/msfilter/mstoolbar.hxx,f
$(eval $(call gb_Package_add_file,filter_inc,inc/filter/msfilter/msvbahelper.hxx,filter/msfilter/msvbahelper.hxx))
$(eval $(call gb_Package_add_file,filter_inc,inc/filter/msfilter/svdfppt.hxx,filter/msfilter/svdfppt.hxx))
$(eval $(call gb_Package_add_file,filter_inc,inc/filter/msfilter/svxmsbas.hxx,filter/msfilter/svxmsbas.hxx))
+$(eval $(call gb_Package_add_file,filter_inc,inc/filter/msfilter/rtfutil.hxx,filter/msfilter/rtfutil.hxx))
$(eval $(call gb_Package_add_file,filter_inc,inc/filter/msfilter/util.hxx,filter/msfilter/util.hxx))
# vim: set noet sw=4 ts=4:
diff --git a/filter/inc/filter/msfilter/rtfutil.hxx b/filter/inc/filter/msfilter/rtfutil.hxx
new file mode 100644
index 000000000000..6f5d82c37283
--- /dev/null
+++ b/filter/inc/filter/msfilter/rtfutil.hxx
@@ -0,0 +1,54 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * 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 INCLUDED_MSFILTER_RTFUTIL_HXX
+#define INCLUDED_MSFILTER_RTFUTIL_HXX
+
+#include "filter/msfilter/msfilterdllapi.h"
+#include <rtl/string.hxx>
+#include <rtl/textenc.h>
+#include <tools/string.hxx>
+
+namespace msfilter {
+namespace rtfutil {
+
+/// Outputs a single character in hex form.
+MSFILTER_DLLPUBLIC OString OutHex(sal_uLong nHex, sal_uInt8 nLen);
+
+/// Handles correct unicode and legacy export of a single character.
+MSFILTER_DLLPUBLIC OString OutChar(sal_Unicode c, int *pUCMode, rtl_TextEncoding eDestEnc);
+
+/// Handles correct unicode and legacy export of a string.
+MSFILTER_DLLPUBLIC OString OutString(const String &rStr, rtl_TextEncoding eDestEnc);
+
+}
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/filter/source/msfilter/rtfutil.cxx b/filter/source/msfilter/rtfutil.cxx
new file mode 100644
index 000000000000..ebb72bdeda94
--- /dev/null
+++ b/filter/source/msfilter/rtfutil.cxx
@@ -0,0 +1,151 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * 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 <filter/msfilter/rtfutil.hxx>
+#include <rtl/strbuf.hxx>
+#include <svtools/rtfkeywd.hxx>
+
+namespace msfilter {
+namespace rtfutil {
+
+OString OutHex(sal_uLong nHex, sal_uInt8 nLen)
+{
+ sal_Char aNToABuf[] = "0000000000000000";
+
+ OSL_ENSURE( nLen < sizeof(aNToABuf), "nLen is too big" );
+ if( nLen >= sizeof(aNToABuf) )
+ nLen = (sizeof(aNToABuf)-1);
+
+ // Set pointer to the buffer end
+ sal_Char* pStr = aNToABuf + (sizeof(aNToABuf)-1);
+ for( sal_uInt8 n = 0; n < nLen; ++n )
+ {
+ *(--pStr) = (sal_Char)(nHex & 0xf ) + 48;
+ if( *pStr > '9' )
+ *pStr += 39;
+ nHex >>= 4;
+ }
+ return OString(pStr);
+}
+
+OString OutChar(sal_Unicode c, int *pUCMode, rtl_TextEncoding eDestEnc)
+{
+ OStringBuffer aBuf;
+ const sal_Char* pStr = 0;
+ // 0x0b instead of \n, etc because of the replacements in SwWW8AttrIter::GetSnippet()
+ switch (c)
+ {
+ case 0x0b:
+ // hard line break
+ pStr = OOO_STRING_SVTOOLS_RTF_LINE;
+ break;
+ case '\t':
+ pStr = OOO_STRING_SVTOOLS_RTF_TAB;
+ break;
+ case '\\':
+ case '}':
+ case '{':
+ aBuf.append('\\');
+ aBuf.append((sal_Char)c);
+ break;
+ case 0xa0:
+ // non-breaking space
+ pStr = "\\~";
+ break;
+ case 0x1e:
+ // non-breaking hyphen
+ pStr = "\\_";
+ break;
+ case 0x1f:
+ // optional hyphen
+ pStr = "\\-";
+ break;
+ default:
+ if (c >= ' ' && c <= '~')
+ aBuf.append((sal_Char)c);
+ else {
+ OUString sBuf(&c, 1);
+ OString sConverted;
+ sBuf.convertToString(&sConverted, eDestEnc, OUSTRING_TO_OSTRING_CVTFLAGS);
+ const sal_Int32 nLen = sConverted.getLength();
+
+ if (pUCMode)
+ {
+ if (*pUCMode != nLen)
+ {
+ aBuf.append("\\uc");
+ aBuf.append((sal_Int32)nLen);
+ // #i47831# add an additional whitespace, so that "document whitespaces" are not ignored.
+ aBuf.append(' ');
+ *pUCMode = nLen;
+ }
+ aBuf.append("\\u");
+ aBuf.append((sal_Int32)c);
+ }
+
+ for (sal_Int32 nI = 0; nI < nLen; ++nI)
+ {
+ aBuf.append("\\'");
+ aBuf.append(OutHex(sConverted.getStr()[nI], 2));
+ }
+ }
+ }
+ if (pStr) {
+ aBuf.append(pStr);
+ switch (c)
+ {
+ case 0xa0:
+ case 0x1e:
+ case 0x1f:
+ break;
+ default:
+ aBuf.append(' ');
+ }
+ }
+ return aBuf.makeStringAndClear();
+}
+
+OString OutString(const String &rStr, rtl_TextEncoding eDestEnc)
+{
+ SAL_INFO("filter.ms", OSL_THIS_FUNC << ", rStr = '" << OUString(rStr) << "'");
+ OStringBuffer aBuf;
+ int nUCMode = 1;
+ for (xub_StrLen n = 0; n < rStr.Len(); ++n)
+ aBuf.append(OutChar(rStr.GetChar(n), &nUCMode, eDestEnc));
+ if (nUCMode != 1) {
+ aBuf.append(OOO_STRING_SVTOOLS_RTF_UC);
+ aBuf.append((sal_Int32)1);
+ aBuf.append(" "); // #i47831# add an additional whitespace, so that "document whitespaces" are not ignored.;
+ }
+ return aBuf.makeStringAndClear();
+}
+
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx b/sw/source/filter/ww8/rtfattributeoutput.cxx
index 3328ff0770ff..c804ee8ecdd4 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.cxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.cxx
@@ -78,6 +78,7 @@
#include <svx/fmglob.hxx>
#include <svx/svdouno.hxx>
#include <filter/msfilter/msoleexp.hxx>
+#include <filter/msfilter/rtfutil.hxx>
#include <svtools/miscopt.hxx>
#include <docufld.hxx>
@@ -439,7 +440,7 @@ OStringBuffer& RtfAttributeOutput::Styles()
void RtfAttributeOutput::RawText( const String& rText, bool /*bForceUnicode*/, rtl_TextEncoding eCharSet )
{
SAL_INFO("sw.rtf", OSL_THIS_FUNC);
- m_aRunText->append(m_rExport.OutString(rText, eCharSet));
+ m_aRunText->append(msfilter::rtfutil::OutString(rText, eCharSet));
}
void RtfAttributeOutput::StartRuby( const SwTxtNode& /*rNode*/, xub_StrLen /*nPos*/, const SwFmtRuby& /*rRuby*/ )
@@ -467,14 +468,14 @@ bool RtfAttributeOutput::StartURL( const String& rUrl, const String& rTarget )
if( sURL.Len() )
{
m_aStyles.append("\"");
- m_aStyles.append(m_rExport.OutString( sURL, m_rExport.eCurrentEncoding));
+ m_aStyles.append(msfilter::rtfutil::OutString( sURL, m_rExport.eCurrentEncoding));
m_aStyles.append("\" ");
}
if( rTarget.Len() )
{
m_aStyles.append("\\\\t \"");
- m_aStyles.append(m_rExport.OutString( rTarget, m_rExport.eCurrentEncoding));
+ m_aStyles.append(msfilter::rtfutil::OutString( rTarget, m_rExport.eCurrentEncoding));
m_aStyles.append("\" ");
}
@@ -1106,7 +1107,7 @@ void RtfAttributeOutput::EndStyle()
m_rExport.InsStyle(m_nStyleId, aStyles);
m_aStylesheet.append(aStyles);
m_aStylesheet.append(' ');
- m_aStylesheet.append(m_rExport.OutString(m_rStyleName, m_rExport.eCurrentEncoding));
+ m_aStylesheet.append(msfilter::rtfutil::OutString(m_rStyleName, m_rExport.eCurrentEncoding));
m_aStylesheet.append(";}");
m_aStylesheet.append(m_rExport.sNewLine);
}
@@ -1389,8 +1390,8 @@ void RtfAttributeOutput::NumberingLevel( sal_uInt8 nLevel,
}
else
{
- m_rExport.Strm() << "\\'" << m_rExport.OutHex( rNumberingString.Len(), 2 ).getStr();
- m_rExport.Strm() << m_rExport.OutString( rNumberingString, m_rExport.eDefaultEncoding ).getStr();
+ m_rExport.Strm() << "\\'" << msfilter::rtfutil::OutHex( rNumberingString.Len(), 2 ).getStr();
+ m_rExport.Strm() << msfilter::rtfutil::OutString( rNumberingString, m_rExport.eDefaultEncoding ).getStr();
}
m_rExport.Strm() << ";}";
@@ -1399,7 +1400,7 @@ void RtfAttributeOutput::NumberingLevel( sal_uInt8 nLevel,
m_rExport.Strm() << "{" << OOO_STRING_SVTOOLS_RTF_LEVELNUMBERS;
for( sal_uInt8 i = 0; i <= nLevel && pNumLvlPos[ i ]; ++i )
{
- m_rExport.Strm() << "\\'" << m_rExport.OutHex(pNumLvlPos[ i ], 2).getStr();
+ m_rExport.Strm() << "\\'" << msfilter::rtfutil::OutHex(pNumLvlPos[ i ], 2).getStr();
}
m_rExport.Strm() << ";}";
@@ -1433,11 +1434,11 @@ void RtfAttributeOutput::WriteField_Impl( const SwField* pFld, ww::eField /*eTyp
{
m_aRunText->append("{" OOO_STRING_SVTOOLS_RTF_FIELD);
m_aRunText->append("{" OOO_STRING_SVTOOLS_RTF_IGNORE OOO_STRING_SVTOOLS_RTF_FLDINST " ");
- m_aRunText->append(m_rExport.OutString(rFldCmd, m_rExport.eCurrentEncoding));
+ m_aRunText->append(msfilter::rtfutil::OutString(rFldCmd, m_rExport.eCurrentEncoding));
m_aRunText->append("}{" OOO_STRING_SVTOOLS_RTF_FLDRSLT " ");
}
if (pFld)
- m_aRunText->append(m_rExport.OutString(pFld->ExpandField(true), m_rExport.eDefaultEncoding));
+ m_aRunText->append(msfilter::rtfutil::OutString(pFld->ExpandField(true), m_rExport.eDefaultEncoding));
if (bHasInstructions)
m_aRunText->append("}}");
}
@@ -1447,7 +1448,7 @@ void RtfAttributeOutput::WriteBookmarks_Impl( std::vector< rtl::OUString >& rSta
for ( std::vector< OUString >::const_iterator it = rStarts.begin(), end = rStarts.end(); it != end; ++it )
{
m_aRun->append("{" OOO_STRING_SVTOOLS_RTF_IGNORE OOO_STRING_SVTOOLS_RTF_BKMKSTART " ");
- m_aRun->append(m_rExport.OutString(*it, m_rExport.eCurrentEncoding));
+ m_aRun->append(msfilter::rtfutil::OutString(*it, m_rExport.eCurrentEncoding));
m_aRun->append('}');
}
rStarts.clear();
@@ -1455,7 +1456,7 @@ void RtfAttributeOutput::WriteBookmarks_Impl( std::vector< rtl::OUString >& rSta
for ( std::vector< OUString >::const_iterator it = rEnds.begin(), end = rEnds.end(); it != end; ++it )
{
m_aRun->append("{" OOO_STRING_SVTOOLS_RTF_IGNORE OOO_STRING_SVTOOLS_RTF_BKMKEND " ");
- m_aRun->append(m_rExport.OutString(*it, m_rExport.eCurrentEncoding));
+ m_aRun->append(msfilter::rtfutil::OutString(*it, m_rExport.eCurrentEncoding));
m_aRun->append('}');
}
rEnds.clear();
@@ -1676,7 +1677,7 @@ void RtfAttributeOutput::OutputFlyFrame_Impl( const sw::Frame& rFrame, const Poi
aStr = aBuf.makeStringAndClear();
pStr = aStr.getStr();
for (int i = 0; i < aStr.getLength(); i++, pStr++)
- m_aRun->append(m_rExport.OutHex(*pStr, 2));
+ m_aRun->append(msfilter::rtfutil::OutHex(*pStr, 2));
m_aRun->append('}');
m_aRun->append("}{" OOO_STRING_SVTOOLS_RTF_FLDRSLT " ");
xPropSet->getPropertyValue("Text") >>= aTmp;
@@ -2312,7 +2313,7 @@ void RtfAttributeOutput::WriteTextFootnoteNumStr(const SwFmtFtn& rFootnote)
if (!rFootnote.GetNumStr().Len())
m_aRun->append(OOO_STRING_SVTOOLS_RTF_CHFTN);
else
- m_aRun->append(m_rExport.OutString(rFootnote.GetNumStr(), m_rExport.eCurrentEncoding));
+ m_aRun->append(msfilter::rtfutil::OutString(rFootnote.GetNumStr(), m_rExport.eCurrentEncoding));
}
void RtfAttributeOutput::TextFootnote_Impl( const SwFmtFtn& rFootnote )
@@ -2524,7 +2525,7 @@ void RtfAttributeOutput::ParaNumRule_Impl( const SwTxtNode* pTxtNd, sal_Int32 nL
if (sTxt.Len())
{
m_aStyles.append(' ');
- m_aStyles.append(m_rExport.OutString(sTxt, m_rExport.eDefaultEncoding));
+ m_aStyles.append(msfilter::rtfutil::OutString(sTxt, m_rExport.eDefaultEncoding));
}
if( bExportNumRule )
@@ -3249,7 +3250,7 @@ void lcl_AppendSP( OStringBuffer& rBuffer,
rBuffer.append( cName ); //"PropName"
rBuffer.append( "}{" OOO_STRING_SVTOOLS_RTF_SV " " );
// "}{ \sv "
- rBuffer.append( rExport.OutString( rValue, rExport.eCurrentEncoding ) );
+ rBuffer.append( msfilter::rtfutil::OutString( rValue, rExport.eCurrentEncoding ) );
rBuffer.append( "}}" );
}
diff --git a/sw/source/filter/ww8/rtfexport.cxx b/sw/source/filter/ww8/rtfexport.cxx
index b09345aae542..2876a5281f54 100644
--- a/sw/source/filter/ww8/rtfexport.cxx
+++ b/sw/source/filter/ww8/rtfexport.cxx
@@ -64,6 +64,7 @@
#include <comphelper/string.hxx>
#include <rtl/oustringostreaminserter.hxx>
#include <svtools/rtfkeywd.hxx>
+#include <filter/msfilter/rtfutil.hxx>
#include <unotools/configmgr.hxx>
#if OSL_DEBUG_LEVEL > 1
@@ -271,7 +272,7 @@ void RtfExport::WriteRevTab()
const String* pAuthor = GetRedline(i);
Strm() << '{';
if (pAuthor)
- Strm() << OutString(*pAuthor, eDefaultEncoding).getStr();
+ Strm() << msfilter::rtfutil::OutString(*pAuthor, eDefaultEncoding).getStr();
Strm() << ";}";
}
Strm() << '}' << sNewLine;
@@ -348,14 +349,14 @@ void RtfExport::DoFormText(const SwInputField* pFld )
m_pAttrOutput->RunText().append( OOO_STRING_SVTOOLS_RTF_FFTYPETXT "0" );
if( !sName.isEmpty() )
- m_pAttrOutput->RunText().append( "{" OOO_STRING_SVTOOLS_RTF_IGNORE OOO_STRING_SVTOOLS_RTF_FFNAME " ").append( OutString( sName, eDefaultEncoding )).append( "}" );
+ m_pAttrOutput->RunText().append( "{" OOO_STRING_SVTOOLS_RTF_IGNORE OOO_STRING_SVTOOLS_RTF_FFNAME " ").append( msfilter::rtfutil::OutString( sName, eDefaultEncoding )).append( "}" );
if( !sHelp.isEmpty() )
- m_pAttrOutput->RunText().append( "{" OOO_STRING_SVTOOLS_RTF_IGNORE OOO_STRING_SVTOOLS_RTF_FFHELPTEXT " ").append( OutString( sHelp, eDefaultEncoding )).append( "}" );
- m_pAttrOutput->RunText().append( "{" OOO_STRING_SVTOOLS_RTF_IGNORE OOO_STRING_SVTOOLS_RTF_FFDEFTEXT " ").append( OutString( sResult, eDefaultEncoding )).append( "}" );
+ m_pAttrOutput->RunText().append( "{" OOO_STRING_SVTOOLS_RTF_IGNORE OOO_STRING_SVTOOLS_RTF_FFHELPTEXT " ").append( msfilter::rtfutil::OutString( sHelp, eDefaultEncoding )).append( "}" );
+ m_pAttrOutput->RunText().append( "{" OOO_STRING_SVTOOLS_RTF_IGNORE OOO_STRING_SVTOOLS_RTF_FFDEFTEXT " ").append( msfilter::rtfutil::OutString( sResult, eDefaultEncoding )).append( "}" );
if( !sStatus.isEmpty() )
- m_pAttrOutput->RunText().append( "{" OOO_STRING_SVTOOLS_RTF_IGNORE OOO_STRING_SVTOOLS_RTF_FFSTATTEXT " ").append( OutString( sStatus, eDefaultEncoding )).append( "}");
+ m_pAttrOutput->RunText().append( "{" OOO_STRING_SVTOOLS_RTF_IGNORE OOO_STRING_SVTOOLS_RTF_FFSTATTEXT " ").append( msfilter::rtfutil::OutString( sStatus, eDefaultEncoding )).append( "}");
m_pAttrOutput->RunText().append( "}}}{" OOO_STRING_SVTOOLS_RTF_FLDRSLT " " );
- m_pAttrOutput->RunText().append( OutString( sResult, eDefaultEncoding )).append( "}}" );
+ m_pAttrOutput->RunText().append( msfilter::rtfutil::OutString( sResult, eDefaultEncoding )).append( "}}" );
}
sal_uLong RtfExport::ReplaceCr( sal_uInt8 )
@@ -455,7 +456,7 @@ void RtfExport::WritePageDescTable()
break;
Strm() << OOO_STRING_SVTOOLS_RTF_PGDSCNXT;
OutULong( i ) << ' ';
- Strm() << OutString( rPageDesc.GetName(), eDefaultEncoding).getStr() << ";}";
+ Strm() << msfilter::rtfutil::OutString( rPageDesc.GetName(), eDefaultEncoding).getStr() << ";}";
}
Strm() << '}' << sNewLine;
bOutPageDescs = sal_False;
@@ -816,123 +817,11 @@ void RtfExport::OutUnicode(const sal_Char *pToken, const String &rContent)
if (rContent.Len())
{
Strm() << '{' << pToken << ' ';
- Strm() << OutString( rContent, eCurrentEncoding ).getStr();
+ Strm() << msfilter::rtfutil::OutString( rContent, eCurrentEncoding ).getStr();
Strm() << '}';
}
}
-OString RtfExport::OutHex(sal_uLong nHex, sal_uInt8 nLen)
-{
- sal_Char aNToABuf[] = "0000000000000000";
-
- OSL_ENSURE( nLen < sizeof(aNToABuf), "nLen is too big" );
- if( nLen >= sizeof(aNToABuf) )
- nLen = (sizeof(aNToABuf)-1);
-
- // Set pointer to the buffer end
- sal_Char* pStr = aNToABuf + (sizeof(aNToABuf)-1);
- for( sal_uInt8 n = 0; n < nLen; ++n )
- {
- *(--pStr) = (sal_Char)(nHex & 0xf ) + 48;
- if( *pStr > '9' )
- *pStr += 39;
- nHex >>= 4;
- }
- return OString(pStr);
-}
-
-OString RtfExport::OutChar(sal_Unicode c, int *pUCMode, rtl_TextEncoding eDestEnc)
-{
- OStringBuffer aBuf;
- const sal_Char* pStr = 0;
- // 0x0b instead of \n, etc because of the replacements in SwWW8AttrIter::GetSnippet()
- switch (c)
- {
- case 0x0b:
- // hard line break
- pStr = OOO_STRING_SVTOOLS_RTF_LINE;
- break;
- case '\t':
- pStr = OOO_STRING_SVTOOLS_RTF_TAB;
- break;
- case '\\':
- case '}':
- case '{':
- aBuf.append('\\');
- aBuf.append((sal_Char)c);
- break;
- case 0xa0:
- // non-breaking space
- pStr = "\\~";
- break;
- case 0x1e:
- // non-breaking hyphen
- pStr = "\\_";
- break;
- case 0x1f:
- // optional hyphen
- pStr = "\\-";
- break;
- default:
- if (c >= ' ' && c <= '~')
- aBuf.append((sal_Char)c);
- else {
- OUString sBuf(&c, 1);
- OString sConverted;
- sBuf.convertToString(&sConverted, eDestEnc, OUSTRING_TO_OSTRING_CVTFLAGS);
- const sal_Int32 nLen = sConverted.getLength();
-
- if (pUCMode)
- {
- if (*pUCMode != nLen)
- {
- aBuf.append("\\uc");
- aBuf.append((sal_Int32)nLen);
- // #i47831# add an additional whitespace, so that "document whitespaces" are not ignored.
- aBuf.append(' ');
- *pUCMode = nLen;
- }
- aBuf.append("\\u");
- aBuf.append((sal_Int32)c);
- }
-
- for (sal_Int32 nI = 0; nI < nLen; ++nI)
- {
- aBuf.append("\\'");
- aBuf.append(OutHex(sConverted.getStr()[nI], 2));
- }
- }
- }
- if (pStr) {
- aBuf.append(pStr);
- switch (c)
- {
- case 0xa0:
- case 0x1e:
- case 0x1f:
- break;
- default:
- aBuf.append(' ');
- }
- }
- return aBuf.makeStringAndClear();
-}
-
-OString RtfExport::OutString(const String &rStr, rtl_TextEncoding eDestEnc)
-{
- SAL_INFO("sw.rtf", OSL_THIS_FUNC << ", rStr = '" << OUString(rStr) << "'");
- OStringBuffer aBuf;
- int nUCMode = 1;
- for (xub_StrLen n = 0; n < rStr.Len(); ++n)
- aBuf.append(OutChar(rStr.GetChar(n), &nUCMode, eDestEnc));
- if (nUCMode != 1) {
- aBuf.append(OOO_STRING_SVTOOLS_RTF_UC);
- aBuf.append((sal_Int32)1);
- aBuf.append(" "); // #i47831# add an additional whitespace, so that "document whitespaces" are not ignored.;
- }
- return aBuf.makeStringAndClear();
-}
-
void RtfExport::OutDateTime(const sal_Char* pStr, const util::DateTime& rDT )
{
Strm() << '{' << pStr << OOO_STRING_SVTOOLS_RTF_YR;
diff --git a/sw/source/filter/ww8/rtfexport.hxx b/sw/source/filter/ww8/rtfexport.hxx
index 75feb92444cb..8c0f02ee13b1 100644
--- a/sw/source/filter/ww8/rtfexport.hxx
+++ b/sw/source/filter/ww8/rtfexport.hxx
@@ -168,9 +168,6 @@ public:
SvStream& OutLong( long nVal );
void OutUnicode(const sal_Char *pToken, const String &rContent);
void OutDateTime(const sal_Char* pStr, const util::DateTime& rDT );
- static rtl::OString OutChar(sal_Unicode c, int *pUCMode, rtl_TextEncoding eDestEnc);
- static rtl::OString OutString(const String &rStr, rtl_TextEncoding eDestEnc);
- static rtl::OString OutHex(sal_uLong nHex, sal_uInt8 nLen);
void OutPageDescription( const SwPageDesc& rPgDsc, sal_Bool bWriteReset, sal_Bool bCheckForFirstPage );
sal_uInt16 GetColor( const Color& rColor ) const;
diff --git a/sw/source/filter/ww8/rtfsdrexport.cxx b/sw/source/filter/ww8/rtfsdrexport.cxx
index 5970fb6aa30c..c8040e5a2358 100644
--- a/sw/source/filter/ww8/rtfsdrexport.cxx
+++ b/sw/source/filter/ww8/rtfsdrexport.cxx
@@ -32,6 +32,7 @@
#include "rtfexportfilter.hxx"
#include <svtools/rtfkeywd.hxx>
+#include <filter/msfilter/rtfutil.hxx>
#include <editeng/editobj.hxx>
#include <svx/svdotext.hxx>
#include <svx/unoapi.hxx>
@@ -475,8 +476,8 @@ sal_Int32 RtfSdrExport::StartShape()
for(std::map<OString,OString>::reverse_iterator i = m_aShapeProps.rbegin(); i != m_aShapeProps.rend(); ++i)
lcl_AppendSP(m_rAttrOutput.RunText(), (*i).first.getStr(), (*i).second );
- lcl_AppendSP(m_rAttrOutput.RunText(), "wzDescription", RtfExport::OutString( m_pSdrObject->GetDescription(), m_rExport.eCurrentEncoding));
- lcl_AppendSP(m_rAttrOutput.RunText(), "wzName", RtfExport::OutString( m_pSdrObject->GetTitle(), m_rExport.eCurrentEncoding));
+ lcl_AppendSP(m_rAttrOutput.RunText(), "wzDescription", msfilter::rtfutil::OutString( m_pSdrObject->GetDescription(), m_rExport.eCurrentEncoding));
+ lcl_AppendSP(m_rAttrOutput.RunText(), "wzName", msfilter::rtfutil::OutString( m_pSdrObject->GetTitle(), m_rExport.eCurrentEncoding));
// now check if we have some text
const SdrTextObj* pTxtObj = PTR_CAST(SdrTextObj, m_pSdrObject);
@@ -549,7 +550,7 @@ void RtfSdrExport::WriteOutliner(const OutlinerParaObject& rParaObj)
if( !bTxtAtr )
{
String aOut( aStr.Copy( nAktPos, nNextAttr - nAktPos ) );
- m_rAttrOutput.RunText().append( m_rExport.OutString( aOut, eChrSet ) );
+ m_rAttrOutput.RunText().append( msfilter::rtfutil::OutString( aOut, eChrSet ) );
}
m_rAttrOutput.RunText().append('}');