[Libreoffice-commits] .: 5 commits - filter/inc filter/Library_msfilter.mk filter/Package_inc.mk filter/source starmath/source sw/source

Miklos Vajna vmiklos at kemper.freedesktop.org
Wed Jul 25 08:07:40 PDT 2012


 filter/Library_msfilter.mk                  |    1 
 filter/Package_inc.mk                       |    1 
 filter/inc/filter/msfilter/rtfutil.hxx      |   54 +++++++
 filter/source/msfilter/rtfutil.cxx          |  151 ++++++++++++++++++++
 starmath/source/rtfexport.cxx               |  210 ++++++++++++++++++++++++++--
 sw/source/filter/ww8/rtfattributeoutput.cxx |   31 ++--
 sw/source/filter/ww8/rtfexport.cxx          |  129 +----------------
 sw/source/filter/ww8/rtfexport.hxx          |    3 
 sw/source/filter/ww8/rtfsdrexport.cxx       |    7 
 9 files changed, 437 insertions(+), 150 deletions(-)

New commits:
commit 1ec55802d90334d2b6112cfc0df43c4cedcd3d1b
Author: Miklos Vajna <vmiklos at suse.cz>
Date:   Wed Jul 25 17:00:45 2012 +0200

    export RTF_MLIM and related keywords
    
    Change-Id: I533807168fea34216bfd2a7cf64d13bca4815d25

diff --git a/starmath/source/rtfexport.cxx b/starmath/source/rtfexport.cxx
index dbce7ed..493a483 100644
--- a/starmath/source/rtfexport.cxx
+++ b/starmath/source/rtfexport.cxx
@@ -41,7 +41,7 @@ SmRtfExport::SmRtfExport(const SmNode* pIn)
 
 bool SmRtfExport::ConvertFromStarMath(OStringBuffer& rBuffer)
 {
-    if (m_pTree == NULL)
+    if (!m_pTree)
         return false;
     m_pBuffer = &rBuffer;
     m_pBuffer->append("{" OOO_STRING_SVTOOLS_RTF_IGNORE "\\moMath");
@@ -68,6 +68,9 @@ void SmRtfExport::HandleNode(const SmNode* pNode, int nLevel)
         case NBRACE:
             HandleBrace( static_cast< const SmBraceNode* >( pNode ), nLevel );
             break;
+        case NOPER:
+            HandleOperator(static_cast<const SmOperNode*>(pNode), nLevel);
+            break;
         case NBINHOR:
             HandleBinaryOperation(static_cast<const SmBinHorNode*>(pNode), nLevel);
             break;
@@ -275,9 +278,78 @@ OString mathSymbolToString(const SmNode* node)
 }
 }
 
-void SmRtfExport::HandleOperator(const SmOperNode* /*pNode*/, int /*nLevel*/)
+void SmRtfExport::HandleOperator(const SmOperNode* pNode, int nLevel)
 {
-    SAL_INFO("starmath.rtf", "TODO: " << OSL_THIS_FUNC);
+    SAL_INFO("starmath.rtf", "Operator: " << int(pNode->GetToken().eType));
+    switch (pNode->GetToken().eType)
+    {
+        case TINT:
+        case TIINT:
+        case TIIINT:
+        case TLINT:
+        case TLLINT:
+        case TLLLINT:
+        case TPROD:
+        case TCOPROD:
+        case TSUM:
+        {
+            const SmSubSupNode* subsup = pNode->GetSubNode(0)->GetType() == NSUBSUP ? static_cast<const SmSubSupNode*>(pNode->GetSubNode(0)) : 0;
+            const SmNode* operation = subsup ? subsup->GetBody() : pNode->GetSubNode(0);
+            m_pBuffer->append("{\\mnary ");
+            m_pBuffer->append("{\\mnaryPr ");
+            m_pBuffer->append("{\\mchr ");
+            m_pBuffer->append(mathSymbolToString(operation));
+            m_pBuffer->append("}"); // mchr
+            if (!subsup || !subsup->GetSubSup(CSUB))
+                m_pBuffer->append("{\\msubHide 1}");
+            if (!subsup || !subsup->GetSubSup(CSUP))
+                m_pBuffer->append("{\\msupHide 1}");
+            m_pBuffer->append("}"); // mnaryPr
+            if (!subsup || !subsup->GetSubSup(CSUB))
+                m_pBuffer->append("{\\msub }");
+            else
+            {
+                m_pBuffer->append("{\\msub ");
+                HandleNode(subsup->GetSubSup(CSUB), nLevel + 1);
+                m_pBuffer->append("}"); // msub
+            }
+            if (!subsup || !subsup->GetSubSup( CSUP ))
+                m_pBuffer->append("{\\msup }");
+            else
+            {
+                m_pBuffer->append("{\\msup ");
+                HandleNode(subsup->GetSubSup(CSUP), nLevel + 1);
+                m_pBuffer->append("}"); // msup
+            }
+            m_pBuffer->append("{\\me ");
+            HandleNode(pNode->GetSubNode(1), nLevel + 1); // body
+            m_pBuffer->append("}"); // me
+            m_pBuffer->append("}"); // mnary
+            break;
+        }
+        case TLIM:
+            m_pBuffer->append("{\\mfunc ");
+            m_pBuffer->append("{\\mfName ");
+            m_pBuffer->append("{\\mlimLow ");
+            m_pBuffer->append("{\\me ");
+            HandleNode(pNode->GetSymbol(), nLevel + 1);
+            m_pBuffer->append("}"); // me
+            m_pBuffer->append("{\\mlim ");
+            if (const SmSubSupNode* subsup = pNode->GetSubNode(0)->GetType() == NSUBSUP ? static_cast<const SmSubSupNode*>( pNode->GetSubNode(0)) : 0)
+                if (subsup->GetSubSup(CSUB))
+                    HandleNode(subsup->GetSubSup(CSUB), nLevel + 1);
+            m_pBuffer->append("}"); // mlim
+            m_pBuffer->append("}"); // mlimLow
+            m_pBuffer->append("}"); // mfName
+            m_pBuffer->append("{\\me ");
+            HandleNode(pNode->GetSubNode(1), nLevel + 1); // body
+            m_pBuffer->append("}"); // me
+            m_pBuffer->append("}"); // mfunc
+            break;
+        default:
+            SAL_INFO("starmath.rtf", "TODO: " << OSL_THIS_FUNC << " unhandled oper type");
+            break;
+    }
 }
 
 void SmRtfExport::HandleSubSupScript(const SmSubSupNode* /*pNode*/, int /*nLevel*/)
commit 69df3928f374f4c331b5208a7cdb282f05cba87d
Author: Miklos Vajna <vmiklos at suse.cz>
Date:   Wed Jul 25 16:25:55 2012 +0200

    escape output properly inside RTF_MR
    
    Change-Id: I93ea57e6bd5f93c9a5d256a11f91ec260f96c223

diff --git a/starmath/source/rtfexport.cxx b/starmath/source/rtfexport.cxx
index 32c1cc5..dbce7ed 100644
--- a/starmath/source/rtfexport.cxx
+++ b/starmath/source/rtfexport.cxx
@@ -130,8 +130,8 @@ void SmRtfExport::HandleText(const SmNode* pNode, int /*nLevel*/)
     for (xub_StrLen i = 0; i < pTemp->GetText().Len(); i++)
     {
         sal_uInt16 nChar = pTemp->GetText().GetChar(i);
-        // TODO special/non-ascii chars?
-        m_pBuffer->append(OUStringToOString(OUString(SmTextNode::ConvertSymbolToUnicode(nChar)), RTL_TEXTENCODING_UTF8));
+        OUString aValue(SmTextNode::ConvertSymbolToUnicode(nChar));
+        m_pBuffer->append(msfilter::rtfutil::OutString(aValue, RTL_TEXTENCODING_MS_1252));
     }
 
     m_pBuffer->append("}");
commit 8556a1cdebe7de52e0d88755f24c00f5a83da314
Author: Miklos Vajna <vmiklos at suse.cz>
Date:   Wed Jul 25 16:20:33 2012 +0200

    export RTF_MD and related keywords
    
    Change-Id: Ib97ce01e738714d2df9b30f0c7c0069c6957335b

diff --git a/starmath/source/rtfexport.cxx b/starmath/source/rtfexport.cxx
index fa8b816..32c1cc5 100644
--- a/starmath/source/rtfexport.cxx
+++ b/starmath/source/rtfexport.cxx
@@ -65,6 +65,9 @@ void SmRtfExport::HandleNode(const SmNode* pNode, int nLevel)
         case NTEXT:
             HandleText(pNode,nLevel);
             break;
+        case NBRACE:
+            HandleBrace( static_cast< const SmBraceNode* >( pNode ), nLevel );
+            break;
         case NBINHOR:
             HandleBinaryOperation(static_cast<const SmBinHorNode*>(pNode), nLevel);
             break;
@@ -260,6 +263,18 @@ void SmRtfExport::HandleRoot(const SmRootNode* /*pNode*/, int /*nLevel*/)
     SAL_INFO("starmath.rtf", "TODO: " << OSL_THIS_FUNC);
 }
 
+namespace {
+OString mathSymbolToString(const SmNode* node)
+{
+    assert(node->GetType() == NMATH);
+    const SmTextNode* txtnode = static_cast<const SmTextNode*>(node);
+    assert(txtnode->GetText().Len() == 1);
+    sal_Unicode chr = SmTextNode::ConvertSymbolToUnicode(txtnode->GetText().GetChar(0));
+    OUString aValue(chr);
+    return msfilter::rtfutil::OutString(aValue, RTL_TEXTENCODING_MS_1252);
+}
+}
+
 void SmRtfExport::HandleOperator(const SmOperNode* /*pNode*/, int /*nLevel*/)
 {
     SAL_INFO("starmath.rtf", "TODO: " << OSL_THIS_FUNC);
@@ -280,9 +295,49 @@ void SmRtfExport::HandleMatrix(const SmMatrixNode* /*pNode*/, int /*nLevel*/)
     SAL_INFO("starmath.rtf", "TODO: " << OSL_THIS_FUNC);
 }
 
-void SmRtfExport::HandleBrace(const SmBraceNode* /*pNode*/, int /*nLevel*/)
+void SmRtfExport::HandleBrace(const SmBraceNode* pNode, int nLevel)
 {
-    SAL_INFO("starmath.rtf", "TODO: " << OSL_THIS_FUNC);
+    m_pBuffer->append("{\\md ");
+    m_pBuffer->append("{\\mdPr ");
+    m_pBuffer->append("{\\mbegChr ");
+    m_pBuffer->append(mathSymbolToString(pNode->OpeningBrace()));
+    m_pBuffer->append("}"); // mbegChr
+    std::vector< const SmNode* > subnodes;
+    if (pNode->Body()->GetType() == NBRACEBODY)
+    {
+        const SmBracebodyNode* body = static_cast<const SmBracebodyNode*>( pNode->Body());
+        bool separatorWritten = false; // assume all separators are the same
+        for (int i = 0; i < body->GetNumSubNodes(); ++i)
+        {
+            const SmNode* subnode = body->GetSubNode(i);
+            if (subnode->GetType() == NMATH)
+            { // do not write, but write what separator it is
+                const SmMathSymbolNode* math = static_cast<const SmMathSymbolNode*>(subnode);
+                if(!separatorWritten)
+                {
+                    m_pBuffer->append("{\\msepChr ");
+                    m_pBuffer->append(mathSymbolToString(math));
+                    m_pBuffer->append("}"); // msepChr
+                    separatorWritten = true;
+                }
+            }
+            else
+                subnodes.push_back(subnode);
+        }
+    }
+    else
+        subnodes.push_back(pNode->Body());
+    m_pBuffer->append("{\\mendChr ");
+    m_pBuffer->append(mathSymbolToString(pNode->ClosingBrace()));
+    m_pBuffer->append("}"); // mendChr
+    m_pBuffer->append("}"); // mdPr
+    for (unsigned int i = 0; i < subnodes.size(); ++i)
+    {
+        m_pBuffer->append("{\\me ");
+        HandleNode(subnodes[ i ], nLevel + 1);
+        m_pBuffer->append("}"); // me
+    }
+    m_pBuffer->append("}"); // md
 }
 
 void SmRtfExport::HandleVerticalBrace(const SmVerticalBraceNode* /*pNode*/, int /*nLevel*/)
commit 0e15567d5100df21b541cb908138cb10aa57a501
Author: Miklos Vajna <vmiklos at suse.cz>
Date:   Wed Jul 25 14:51:39 2012 +0200

    export RTF_MACC and related keywords
    
    Change-Id: I862f008f2a8b4972be1b33ec45128bbfeeb9fb99

diff --git a/starmath/source/rtfexport.cxx b/starmath/source/rtfexport.cxx
index f4e560f..fa8b816 100644
--- a/starmath/source/rtfexport.cxx
+++ b/starmath/source/rtfexport.cxx
@@ -31,6 +31,7 @@
 
 #include <rtl/oustringostreaminserter.hxx>
 #include <svtools/rtfkeywd.hxx>
+#include <filter/msfilter/rtfutil.hxx>
 
 SmRtfExport::SmRtfExport(const SmNode* pIn)
     : m_pTree(pIn)
@@ -58,6 +59,9 @@ void SmRtfExport::HandleNode(const SmNode* pNode, int nLevel)
 
     switch(pNode->GetType())
     {
+        case NATTRIBUT:
+            HandleAttribute( static_cast< const SmAttributNode* >( pNode ), nLevel );
+            break;
         case NTEXT:
             HandleText(pNode,nLevel);
             break;
@@ -170,9 +174,70 @@ void SmRtfExport::HandleBinaryOperation(const SmBinHorNode* pNode, int nLevel)
     }
 }
 
-void SmRtfExport::HandleAttribute(const SmAttributNode* /*pNode*/, int /*nLevel*/)
+void SmRtfExport::HandleAttribute(const SmAttributNode* pNode, int nLevel)
 {
-    SAL_INFO("starmath.rtf", "TODO: " << OSL_THIS_FUNC);
+    switch (pNode->Attribute()->GetToken().eType)
+    {
+        case TCHECK:
+        case TACUTE:
+        case TGRAVE:
+        case TBREVE:
+        case TCIRCLE:
+        case TVEC:
+        case TTILDE:
+        case THAT:
+        case TDOT:
+        case TDDOT:
+        case TDDDOT:
+        case TWIDETILDE:
+        case TWIDEHAT:
+        case TWIDEVEC:
+        case TBAR:
+        {
+            m_pBuffer->append("{\\macc ");
+            m_pBuffer->append("{\\maccPr ");
+            m_pBuffer->append("{\\mchr ");
+            OUString aValue(pNode->Attribute()->GetToken().cMathChar);
+            m_pBuffer->append(msfilter::rtfutil::OutString(aValue, RTL_TEXTENCODING_MS_1252));
+            m_pBuffer->append("}"); // mchr
+            m_pBuffer->append("}"); // maccPr
+            m_pBuffer->append("{\\me ");
+            HandleNode( pNode->Body(), nLevel + 1 );
+            m_pBuffer->append("}"); // me
+            m_pBuffer->append("}"); // macc
+            break;
+        }
+        case TOVERLINE:
+        case TUNDERLINE:
+            m_pBuffer->append("{\\mbar ");
+            m_pBuffer->append("{\\mbarPr ");
+            m_pBuffer->append("{\\mpos ");
+            m_pBuffer->append((pNode->Attribute()->GetToken().eType == TUNDERLINE ) ? "bot" : "top");
+            m_pBuffer->append("}"); // mpos
+            m_pBuffer->append("}"); // mbarPr
+            m_pBuffer->append("{\\me ");
+            HandleNode( pNode->Body(), nLevel + 1 );
+            m_pBuffer->append("}"); // me
+            m_pBuffer->append("}"); // mbar
+            break;
+        case TOVERSTRIKE:
+            m_pBuffer->append("{\\mborderBox ");
+            m_pBuffer->append("{\\mborderBoxPr ");
+            m_pBuffer->append("{\\mhideTop 1}");
+            m_pBuffer->append("{\\mhideBot 1}");
+            m_pBuffer->append("{\\mhideLeft 1}");
+            m_pBuffer->append("{\\mhideRight 1}");
+            m_pBuffer->append("{\\mstrikeH 1}");
+            m_pBuffer->append("}"); // mborderBoxPr
+            m_pBuffer->append("{\\me ");
+            HandleNode( pNode->Body(), nLevel + 1 );
+            m_pBuffer->append("}"); // me
+            m_pBuffer->append("}"); // mborderBox
+            break;
+        default:
+            HandleAllSubNodes( pNode, nLevel );
+            break;
+    }
 }
 
 void SmRtfExport::HandleMath(const SmNode* pNode, int nLevel)
commit 041961e18b16c64d1395b1ed6fcb460d82b9939a
Author: Miklos Vajna <vmiklos at suse.cz>
Date:   Wed Jul 25 15:43:54 2012 +0200

    move rtf escaping functions to msfilter, so starmath can use them as well
    
    Change-Id: Ib847f5207f3f36585427313c1454b0fba730c503

diff --git a/filter/Library_msfilter.mk b/filter/Library_msfilter.mk
index a592fbf..c7eebae 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 141cc29..578fe96 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 0000000..6f5d82c
--- /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 at 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 0000000..ebb72bd
--- /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 at 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 3328ff0..c804ee8 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 b09345a..2876a52 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 75feb92..8c0f02e 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 5970fb6..c8040e5 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('}');


More information about the Libreoffice-commits mailing list