[Libreoffice-commits] .: 3 commits - starmath/source sw/CppunitTest_sw_subsequent_ooxmlexport.mk sw/qa writerfilter/source

Miklos Vajna vmiklos at kemper.freedesktop.org
Fri Jul 27 08:28:15 PDT 2012


 starmath/source/ooxmlimport.cxx                |    2 -
 sw/CppunitTest_sw_subsequent_ooxmlexport.mk    |    2 +
 sw/qa/extras/ooxmlexport/data/math-escape.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport.cxx       |   11 ++++++
 sw/qa/extras/rtfexport/data/math-runs.rtf      |   12 +++++++
 sw/qa/extras/rtfexport/rtfexport.cxx           |    9 +++++
 writerfilter/source/rtftok/rtfdocumentimpl.cxx |   40 +++++++++++--------------
 7 files changed, 54 insertions(+), 22 deletions(-)

New commits:
commit 55d72ab8ec4e4445e62f8224b5f54e97c464c4a5
Author: Miklos Vajna <vmiklos at suse.cz>
Date:   Fri Jul 27 17:26:12 2012 +0200

    RTFDocumentImpl::text: don't try to read beyond the end of string
    
    Change-Id: If8dc4686f28870f1ce6b22458e29d3a9043f9783

diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 6729b88..b63bc3c 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -984,7 +984,7 @@ void RTFDocumentImpl::text(OUString& rString)
             m_aStates.top().aDestinationText.append(rString);
             break;
         case DESTINATION_EQINSTRUCTION:
-            if ( rString.copy(0, 2) == "do" && rString.copy(2).toInt32() > 0 )
+            if ( rString.getLength() > 3 && rString.copy(0, 2) == "do" && rString.copy(2).toInt32() > 0 )
                 dispatchFlag(RTF_SUB);
             break;
         default: bRet = false; break;
commit 2d422d868a717adf735ef45a6bf5e4af0efb1a0c
Author: Miklos Vajna <vmiklos at suse.cz>
Date:   Fri Jul 27 16:47:07 2012 +0200

    SmOoxmlImport::handleR: escape brackets in math runs
    
    Also remove the previous escaping that took care of RTF only.
    
    Change-Id: Ie9a019912f83a3f56ef52429855cd72cf2c8f463

diff --git a/starmath/source/ooxmlimport.cxx b/starmath/source/ooxmlimport.cxx
index 0ca2d05..12e20a6 100644
--- a/starmath/source/ooxmlimport.cxx
+++ b/starmath/source/ooxmlimport.cxx
@@ -597,7 +597,7 @@ OUString SmOoxmlImport::handleR()
         }
     }
     stream.ensureClosingTag( M_TOKEN( r ));
-    return text;
+    return text.replaceAll("{", "\\{").replaceAll("}", "\\}");
 }
 
 OUString SmOoxmlImport::handleRad()
diff --git a/sw/CppunitTest_sw_subsequent_ooxmlexport.mk b/sw/CppunitTest_sw_subsequent_ooxmlexport.mk
index 531e0b5..4e63fb4 100644
--- a/sw/CppunitTest_sw_subsequent_ooxmlexport.mk
+++ b/sw/CppunitTest_sw_subsequent_ooxmlexport.mk
@@ -66,6 +66,7 @@ $(eval $(call gb_CppunitTest_use_ure,sw_subsequent_ooxmlexport))
 $(eval $(call gb_CppunitTest_use_components,sw_subsequent_ooxmlexport,\
     comphelper/util/comphelp \
     configmgr/source/configmgr \
+    embeddedobj/util/embobj \
     fileaccess/source/fileacc \
     filter/source/config/cache/filterconfig1 \
     framework/util/fwk \
@@ -79,6 +80,7 @@ $(eval $(call gb_CppunitTest_use_components,sw_subsequent_ooxmlexport,\
     sw/util/swd \
     sw/util/msword \
     sfx2/util/sfx \
+    starmath/util/sm \
     svl/source/fsstor/fsstorage \
     svtools/util/svt \
     toolkit/util/tk \
diff --git a/sw/qa/extras/ooxmlexport/data/math-escape.docx b/sw/qa/extras/ooxmlexport/data/math-escape.docx
new file mode 100644
index 0000000..e935a83
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/math-escape.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index c426c37..02f66a2 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -41,12 +41,17 @@ public:
     void testZoom();
     void defaultTabStopNotInStyles();
     void testFdo38244();
+    void testMathEscape();
 
     CPPUNIT_TEST_SUITE(Test);
 #if !defined(MACOSX) && !defined(WNT)
     CPPUNIT_TEST(testZoom);
     CPPUNIT_TEST(defaultTabStopNotInStyles);
     CPPUNIT_TEST(testFdo38244);
+    // See rtfexport test on why this is blacklisted.
+#if !(__GNUC__ == 4 && __GNUC_MINOR__ == 4)
+    CPPUNIT_TEST(testMathEscape);
+#endif
 #endif
     CPPUNIT_TEST_SUITE_END();
 
@@ -159,6 +164,12 @@ void Test::testFdo38244()
     CPPUNIT_ASSERT_EQUAL(true, bCaught);
 }
 
+void Test::testMathEscape()
+{
+    roundtrip("math-escape.docx");
+    CPPUNIT_ASSERT_EQUAL(OUString("\\{ left [ right ] left ( right ) \\}"), getFormula(getRun(getParagraph(1), 1)));
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 2c590c0..6729b88 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -1535,13 +1535,6 @@ int RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword)
     if (cCh > 0)
     {
         OUString aStr(OStringToOUString(OString(cCh), RTL_TEXTENCODING_MS_1252));
-        if ((nKeyword == RTF_LBRACE || nKeyword == RTF_RBRACE) && m_aStates.top().nDestinationState == DESTINATION_MR)
-        {
-            if (nKeyword == RTF_LBRACE)
-                aStr = "\\{";
-            else
-                aStr = "\\}";
-        }
         text(aStr);
         return 0;
     }
commit dba6b5151e26ea0bc88f8d30a70859fcbbd2e81f
Author: Miklos Vajna <vmiklos at suse.cz>
Date:   Fri Jul 27 16:32:13 2012 +0200

    fix import of nested RTF_MF groups
    
    Change-Id: Ibd4f93663d27d997c44f73e201c355a34d6452d3

diff --git a/sw/qa/extras/rtfexport/data/math-runs.rtf b/sw/qa/extras/rtfexport/data/math-runs.rtf
new file mode 100644
index 0000000..7a4ae2d
--- /dev/null
+++ b/sw/qa/extras/rtfexport/data/math-runs.rtf
@@ -0,0 +1,12 @@
+{\rtf1
+{\mmath
+{\*\moMath 
+{\rtlch\fcs1 \af31507 \ltrch\fcs0 \i\loch\af34\hich\af34\dbch\af31505\insrsid7024409 \{\hich\af34\dbch\af31505\loch\f34 
+{\mr\mscr0\msty2 
+[]()}
+}
+{\rtlch\fcs1 \af31507 \ltrch\fcs0 \i\f34\insrsid7024409 \}}
+}
+}
+\par
+}
diff --git a/sw/qa/extras/rtfexport/rtfexport.cxx b/sw/qa/extras/rtfexport/rtfexport.cxx
index 7cf93df..ca72d9b 100644
--- a/sw/qa/extras/rtfexport/rtfexport.cxx
+++ b/sw/qa/extras/rtfexport/rtfexport.cxx
@@ -67,6 +67,7 @@ public:
     void testMathSepchr();
     void testMathSubscripts();
     void testMathVerticalstacks();
+    void testMathRuns();
 
     CPPUNIT_TEST_SUITE(Test);
 #if !defined(MACOSX) && !defined(WNT)
@@ -96,6 +97,7 @@ public:
     CPPUNIT_TEST(testMathSepchr);
     CPPUNIT_TEST(testMathSubscripts);
     CPPUNIT_TEST(testMathVerticalstacks);
+    CPPUNIT_TEST(testMathRuns);
 #endif
 #endif
     CPPUNIT_TEST_SUITE_END();
@@ -397,6 +399,13 @@ void Test::testMathVerticalstacks()
     CPPUNIT_ASSERT_EQUAL(OUString("stack { a # stack { b # c } }"), getFormula(getRun(getParagraph(4), 1)));
 }
 
+void Test::testMathRuns()
+{
+    roundtrip("math-runs.rtf");
+    // was [](){}, i.e. first curly bracket had an incorrect position
+    CPPUNIT_ASSERT_EQUAL(OUString("\\{ left [ right ] left ( right ) \\}"), getFormula(getRun(getParagraph(1), 1)));
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index bece052..2c590c0 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -202,6 +202,19 @@ static util::DateTime lcl_getDateTime(std::stack<RTFParserState>& aStates)
             aStates.top().nDay, aStates.top().nMonth, aStates.top().nYear);
 }
 
+static void lcl_DestinationToMath(OUStringBuffer& rDestinationText, oox::formulaimport::XmlStreamBuilder& rMathBuffer)
+{
+    OUString aStr = rDestinationText.makeStringAndClear();
+    if (!aStr.isEmpty())
+    {
+        rMathBuffer.appendOpeningTag(M_TOKEN(r));
+        rMathBuffer.appendOpeningTag(M_TOKEN(t));
+        rMathBuffer.appendCharacters(aStr);
+        rMathBuffer.appendClosingTag(M_TOKEN(t));
+        rMathBuffer.appendClosingTag(M_TOKEN(r));
+    }
+}
+
 RTFDocumentImpl::RTFDocumentImpl(uno::Reference<uno::XComponentContext> const& xContext,
         uno::Reference<io::XInputStream> const& xInputStream,
         uno::Reference<lang::XComponent> const& xDstDoc,
@@ -3131,7 +3144,11 @@ int RTFDocumentImpl::pushState()
     if (m_aStates.empty())
         aState = m_aDefaultState;
     else
+    {
+        if (m_aStates.top().nDestinationState == DESTINATION_MR)
+            lcl_DestinationToMath(m_aStates.top().aDestinationText, m_aMathBuffer);
         aState = m_aStates.top();
+    }
     m_aStates.push(aState);
     m_aStates.top().aDestinationText.setLength(0);
 
@@ -3616,19 +3633,7 @@ int RTFDocumentImpl::popState()
         m_aMathBuffer = oox::formulaimport::XmlStreamBuilder();
     }
     break;
-    case DESTINATION_MR:
-    {
-        OUString aStr = m_aStates.top().aDestinationText.makeStringAndClear();
-        if (!aStr.isEmpty())
-        {
-            m_aMathBuffer.appendOpeningTag(M_TOKEN(r));
-            m_aMathBuffer.appendOpeningTag(M_TOKEN(t));
-            m_aMathBuffer.appendCharacters(aStr);
-            m_aMathBuffer.appendClosingTag(M_TOKEN(t));
-            m_aMathBuffer.appendClosingTag(M_TOKEN(r));
-        }
-    }
-    break;
+    case DESTINATION_MR: lcl_DestinationToMath(m_aStates.top().aDestinationText, m_aMathBuffer); break;
     case DESTINATION_MF: m_aMathBuffer.appendClosingTag(M_TOKEN(f)); break;
     case DESTINATION_MFPR: m_aMathBuffer.appendClosingTag(M_TOKEN(fPr)); break;
     case DESTINATION_MCTRLPR: m_aMathBuffer.appendClosingTag(M_TOKEN(ctrlPr)); break;


More information about the Libreoffice-commits mailing list