starmath/inc/parse5.hxx | 4 + starmath/source/ooxmlimport.cxx | 16 ++-- starmath/source/parse5.cxx | 41 ++++++++++ sw/qa/extras/ooxmlexport/data/tdf162070_export.docx |binary sw/qa/extras/ooxmlexport/ooxmlexport2.cxx | 77 +++++++++++--------- sw/qa/extras/rtfexport/data/math-mso2007.rtf | 12 +-- sw/qa/extras/rtfexport/rtfexport.cxx | 55 +++++++------- 7 files changed, 133 insertions(+), 72 deletions(-)
New commits: commit c1703cc07a960ab394f094f1665f74c42ed8f2c9 Author: Pranam Lashkari <lpra...@collabora.com> AuthorDate: Tue Nov 12 12:50:10 2024 +0530 Commit: Andras Timar <andras.ti...@collabora.com> CommitDate: Mon Dec 9 13:49:55 2024 +0100 tdf#162070: enclose delimiters in in formula inside quotes problem: 1. some characters were not correctly interpreted inside formulas casuing them to appear as inverted question mark. 2. when some special symbols like 'abs' were inserted as normal string were replaced with symbols and sometimes also causing to invalidate formula and add inverted question mark Change-Id: Id1b0cda36727c1749619adc858b27212057b37e3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176421 Reviewed-by: Pranam Lashkari <lpra...@collabora.com> Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178138 Reviewed-by: Andras Timar <andras.ti...@collabora.com> diff --git a/starmath/inc/parse5.hxx b/starmath/inc/parse5.hxx index 92fc2a02917b..83978709985a 100644 --- a/starmath/inc/parse5.hxx +++ b/starmath/inc/parse5.hxx @@ -119,4 +119,8 @@ public: inline bool SmParser5::TokenInGroup(TG nGroup) { return bool(m_aCurToken.nGroup & nGroup); } +const SmTokenTableEntry* GetTokenTableEntry(const OUString& rName); + +OUString encloseOrEscapeLiteral(const OUString& string, bool force); + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/starmath/source/ooxmlimport.cxx b/starmath/source/ooxmlimport.cxx index f040265ad31d..82f1b2a28425 100644 --- a/starmath/source/ooxmlimport.cxx +++ b/starmath/source/ooxmlimport.cxx @@ -20,6 +20,7 @@ #include <rtl/ustrbuf.hxx> #include <sal/log.hxx> #include <o3tl/string_view.hxx> +#include <parse5.hxx> using namespace oox::formulaimport; @@ -595,17 +596,19 @@ OUString SmOoxmlImport::handleR() m_rStream.ensureClosingTag( M_TOKEN( rPr )); } OUStringBuffer text; + bool isTagT = false; while( !m_rStream.atEnd() && m_rStream.currentToken() != CLOSING( m_rStream.currentToken())) { switch( m_rStream.currentToken()) { case OPENING( M_TOKEN( t )): { + isTagT = true; XmlStream::Tag rtag = m_rStream.ensureOpeningTag( M_TOKEN( t )); + OUString sTagText = rtag.text; if( rtag.attribute( OOX_TOKEN( xml, space )) != "preserve" ) - text.append(o3tl::trim(rtag.text)); - else - text.append(rtag.text); + sTagText = o3tl::trim(sTagText); + text.append(sTagText); m_rStream.ensureClosingTag( M_TOKEN( t )); break; } @@ -615,12 +618,11 @@ OUString SmOoxmlImport::handleR() } } m_rStream.ensureClosingTag( M_TOKEN( r )); - if( normal || literal ) + if (normal || literal || isTagT) { - text.insert(0, "\""); - text.append("\""); + return encloseOrEscapeLiteral(text.makeStringAndClear(), normal || literal); } - return text.makeStringAndClear().replaceAll("{", "\{").replaceAll("}", "\}"); + return text.makeStringAndClear(); } OUString SmOoxmlImport::handleRad() diff --git a/starmath/source/parse5.cxx b/starmath/source/parse5.cxx index 13f3701db26a..dc6e88da0a25 100644 --- a/starmath/source/parse5.cxx +++ b/starmath/source/parse5.cxx @@ -33,6 +33,7 @@ #include <starmathdatabase.hxx> #include <stack> +#include <unordered_set> using namespace ::com::sun::star::i18n; @@ -292,7 +293,7 @@ static inline bool findCompare(const SmTokenTableEntry& lhs, const OUString& s) } //Returns the SmTokenTableEntry for a keyword -static const SmTokenTableEntry* GetTokenTableEntry(const OUString& rName) +const SmTokenTableEntry* GetTokenTableEntry(const OUString& rName) { if (rName.isEmpty()) return nullptr; //avoid null pointer exceptions @@ -304,6 +305,42 @@ static const SmTokenTableEntry* GetTokenTableEntry(const OUString& rName) return nullptr; //not found } +OUString encloseOrEscapeLiteral(const OUString& string, bool force) +{ + if (force) + return "\"" + string + "\""; + OUStringBuffer result; + const std::unordered_set<sal_Unicode> DelimiterTable1{ + //keeping " as first entry is important to not get into recursive replacement + ' ', ' ', ' ', ' ', '+', '-', '*', '/', '=', '^', + '_', '#', '%', '>', '<', '&', '|', '~', '`' + }; + const std::unordered_set<sal_Unicode> DelimiterTable2{ + //keeping " as first entry is important to not get into recursive replacement + '{', '}', '(', ')', '[', ']', + }; + for (sal_Int32 i = 0; i < string.getLength(); i++) + { + if (string[i] == '"') + result.append("\"\\"\""); + else if (DelimiterTable1.find(string[i]) != DelimiterTable1.end()) + result.append("\"" + OUStringChar(string[i]) + "\""); + else if (DelimiterTable2.find(string[i]) != DelimiterTable2.end()) + result.append("\" + OUStringChar(string[i])); + else + result.append(string[i]); + } + + OUString resultString = result.makeStringAndClear(); + const SmTokenTableEntry* tkn = GetTokenTableEntry(resultString); + // excluding function and operator as they take arguments and can't treat them as litral or else arguments are not displayed correctly + if (tkn && tkn->nGroup != TG::Function && tkn->nGroup != TG::Oper) + { + resultString = "\"" + resultString + "\""; + } + return resultString; +} + static bool IsDelimiter(const OUString& rTxt, sal_Int32 nPos) { // returns 'true' iff cChar is ' @@ -313,7 +350,7 @@ static bool IsDelimiter(const OUString& rTxt, sal_Int32 nPos) sal_Unicode cChar = rTxt[nPos]; // check if 'cChar' is in the delimiter table - static const sal_Unicode aDelimiterTable[] = { + constexpr sal_Unicode aDelimiterTable[] = { ' ', '{', '}', '(', ')', ' ', ' ', ' ', '+', '-', '*', '/', '=', '[', ']', '^', '_', '#', '%', '>', '<', '&', '|', '\', '"', '~', '`' }; //reordered by usage (by eye) for nanoseconds saving. diff --git a/sw/qa/extras/ooxmlexport/data/tdf162070_export.docx b/sw/qa/extras/ooxmlexport/data/tdf162070_export.docx new file mode 100644 index 000000000000..133edbd2d58f Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf162070_export.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx index 0ff66099b7b2..14bfb259eb6d 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx @@ -271,9 +271,12 @@ CPPUNIT_TEST_FIXTURE(Test, testCommentsNested) CPPUNIT_TEST_FIXTURE(Test, testMathEscape) { loadAndReload("math-escape.docx"); - CPPUNIT_ASSERT_EQUAL(OUString("\{ left [ right ] left ( right ) \}"), getFormula(getRun(getParagraph(1), 1))); + CPPUNIT_ASSERT_EQUAL(OUString("\{ \[ \] \( \) \}"), + getFormula(getRun(getParagraph(1), 1))); } + + CPPUNIT_TEST_FIXTURE(Test, testFdo51034) { loadAndReload("fdo51034.odt"); @@ -313,7 +316,8 @@ DECLARE_OOXMLEXPORT_TEST(testMathD, "math-d.docx") DECLARE_OOXMLEXPORT_TEST(testMathEscaping, "math-escaping.docx") { - CHECK_FORMULA( u"\u2212 \u221E < x < \u221E", getFormula( getRun( getParagraph( 1 ), 1 ))); + CHECK_FORMULA(u"\u2212 \u221E \"<\" x \"<\" \u221E", + getFormula(getRun(getParagraph(1), 1))); } DECLARE_OOXMLEXPORT_TEST(testMathLim, "math-lim.docx") @@ -329,38 +333,42 @@ DECLARE_OOXMLEXPORT_TEST(testMathMatrix, "math-matrix.docx") CPPUNIT_TEST_FIXTURE(Test, testMathMso2k7) { loadAndReload("math-mso2k7.docx"); - CHECK_FORMULA( u"A = \u03C0 {r} ^ {2}", getFormula( getRun( getParagraph( 1 ), 1 ))); -// TODO check the stack/binom difference -// CHECK_FORMULA( "{left (x+a right )} ^ {n} = sum from {k=0} to {n} {left (binom {n} {k} right ) {x} ^ {k} {a} ^ {n-k}}", - CHECK_FORMULA( "{left (x+a right )} ^ {n} = sum from {k=0} to {n} {left (stack {n # k} right ) {x} ^ {k} {a} ^ {n-k}}", - getFormula( getRun( getParagraph( 2 ), 1 ))); - CHECK_FORMULA( u"{left (1+x right )} ^ {n} =1+ {nx} over {1!} + {n left (n-1 right ) {x} ^ {2}} over {2!} +\u2026", - getFormula( getRun( getParagraph( 3 ), 1 ))); -// TODO check (cos/sin miss {}) -// CHECK_FORMULA( "f left (x right ) = {a} rsub {0} + sum from {n=1} to {\xe2\x88\x9e} {left ({a} rsub {n} cos {{n\xcf\x80x} over {L}} + {b} rsub {n} sin {{n\xcf\x80x} over {L}} right )}", - CHECK_FORMULA( u"f left (x right ) = {a} rsub {0} + sum from {n=1} to {\u221E} {left ({a} rsub {n} cos {n\u03C0x} over {L} + {b} rsub {n} sin {n\u03C0x} over {L} right )}", - getFormula( getRun( getParagraph( 4 ), 1 ))); - CHECK_FORMULA( "{a} ^ {2} + {b} ^ {2} = {c} ^ {2}", getFormula( getRun( getParagraph( 5 ), 1 ))); - CHECK_FORMULA( u"x = {- b \u00B1 sqrt {{b} ^ {2} -4 ac}} over {2 a}", - getFormula( getRun( getParagraph( 6 ), 1 ))); + CHECK_FORMULA(u"A \"=\" \u03C0 {r} ^ {2}", getFormula(getRun(getParagraph(1), 1))); + // TODO check the stack/binom difference + // CHECK_FORMULA( "{left (x+a right )} ^ {n} = sum from {k=0} to {n} {left (binom {n} {k} right ) {x} ^ {k} {a} ^ {n-k}}", + CHECK_FORMULA("{left (x\"+\"a right )} ^ {n} \"=\" sum from {k\"=\"0} to {n} {left (stack {n # " + "k} right ) {x} ^ {k} {a} ^ {n\"-\"k}}", + getFormula(getRun(getParagraph(2), 1))); + CHECK_FORMULA( + u"{left (1\"+\"x right )} ^ {n} \"=\"1\"+\" {nx} over {1!} \"+\" {n left (n\"-\"1 right ) {x} ^ {2}} over {2!} \"+\"\u2026", + getFormula(getRun(getParagraph(3), 1))); + // TODO check (cos/sin miss {}) + // CHECK_FORMULA( "f left (x right ) = {a} rsub {0} + sum from {n=1} to {\xe2\x88\x9e} {left ({a} rsub {n} cos {{n\xcf\x80x} over {L}} + {b} rsub {n} sin {{n\xcf\x80x} over {L}} right )}", CHECK_FORMULA( - u"{e} ^ {x} =1+ {x} over {1!} + {{x} ^ {2}} over {2!} + {{x} ^ {3}} over {3!} +\u2026, -\u221E<x<\u221E", - getFormula( getRun( getParagraph( 7 ), 1 ))); + u"f left (x right ) \"=\" {a} rsub {0} \"+\" sum from {n\"=\"1} to {\u221E} {left ({a} rsub {n} cos {n\u03C0x} over {L} \"+\" {b} rsub {n} sin {n\u03C0x} over {L} right )}", + getFormula(getRun(getParagraph(4), 1))); + CHECK_FORMULA("{a} ^ {2} \"+\" {b} ^ {2} \"=\" {c} ^ {2}", + getFormula(getRun(getParagraph(5), 1))); + CHECK_FORMULA(u"x \"=\" {\"-\" b \u00B1 sqrt {{b} ^ {2} \"-\"4 ac}} over {2 a}", + getFormula(getRun(getParagraph(6), 1))); CHECK_FORMULA( -// "sin {\xce\xb1} \xc2\xb1 sin {\xce\xb2} =2 sin {{1} over {2} left (\xce\xb1\xc2\xb1\xce\xb2 right )} cos {{1} over {2} left (\xce\xb1\xe2\x88\x93\xce\xb2 right )}", -// TODO check (cos/in miss {}) - u"sin \u03B1 \u00B1 sin \u03B2 =2 sin {1} over {2} left (\u03B1\u00B1\u03B2 right ) cos {1} over {2} left (\u03B1\u2213\u03B2 right )", - getFormula( getRun( getParagraph( 8 ), 1 ))); + u"{e} ^ {x} \"=\"1\"+\" {x} over {1!} \"+\" {{x} ^ {2}} over {2!} \"+\" {{x} ^ {3}} over {3!} \"+\"\u2026,\" \" \" \" \"-\"\u221E\"<\"x\"<\"\u221E", + getFormula(getRun(getParagraph(7), 1))); CHECK_FORMULA( -// "cos {\xce\xb1} + cos {\xce\xb2} =2 cos {{1} over {2} left (\xce\xb1+\xce\xb2 right )} cos {{1} over {2} left (\xce\xb1-\xce\xb2 right )}", -// TODO check (cos/sin miss {}) - u"cos \u03B1 + cos \u03B2 =2 cos {1} over {2} left (\u03B1+\u03B2 right ) cos {1} over {2} left (\u03B1-\u03B2 right )", - getFormula( getRun( getParagraph( 9 ), 1 ))); + // "sin {\xce\xb1} \xc2\xb1 sin {\xce\xb2} =2 sin {{1} over {2} left (\xce\xb1\xc2\xb1\xce\xb2 right )} cos {{1} over {2} left (\xce\xb1\xe2\x88\x93\xce\xb2 right )}", + // TODO check (cos/in miss {}) + u"sin \u03B1 \u00B1 sin \u03B2 \"=\"2 sin {1} over {2} left (\u03B1\u00B1\u03B2 right ) cos {1} over {2} left (\u03B1\u2213\u03B2 right )", + getFormula(getRun(getParagraph(8), 1))); + CHECK_FORMULA( + // "cos {\xce\xb1} + cos {\xce\xb2} =2 cos {{1} over {2} left (\xce\xb1+\xce\xb2 right )} cos {{1} over {2} left (\xce\xb1-\xce\xb2 right )}", + // TODO check (cos/sin miss {}) + u"cos \u03B1 \"+\" cos \u03B2 \"=\"2 cos {1} over {2} left (\u03B1\"+\"\u03B2 right ) cos {1} over {2} left (\u03B1\"-\"\u03B2 right )", + getFormula(getRun(getParagraph(9), 1))); } DECLARE_OOXMLEXPORT_TEST(testMathNary, "math-nary.docx") { - CHECK_FORMULA( "lllint from {1} to {2} {x + 1}", getFormula( getRun( getParagraph( 1 ), 1 ))); + CHECK_FORMULA("lllint from {1} to {2} {x \"+\" 1}", getFormula(getRun(getParagraph(1), 1))); CHECK_FORMULA( "prod from {a} {b}", getFormula( getRun( getParagraph( 1 ), 2 ))); CHECK_FORMULA( "sum to {2} {x}", getFormula( getRun( getParagraph( 1 ), 3 ))); } @@ -384,12 +392,12 @@ DECLARE_OOXMLEXPORT_TEST(testMathPlaceholders, "math-placeholders.docx") DECLARE_OOXMLEXPORT_TEST(testMathRad, "math-rad.docx") { CHECK_FORMULA( "sqrt {4}", getFormula( getRun( getParagraph( 1 ), 1 ))); - CHECK_FORMULA( "nroot {3} {x + 1}", getFormula( getRun( getParagraph( 1 ), 2 ))); + CHECK_FORMULA("nroot {3} {x \"+\" 1}", getFormula(getRun(getParagraph(1), 2))); } DECLARE_OOXMLEXPORT_TEST(testMathSubscripts, "math-subscripts.docx") { - CHECK_FORMULA( "{x} ^ {y} + {e} ^ {x}", getFormula( getRun( getParagraph( 1 ), 1 ))); + CHECK_FORMULA("{x} ^ {y} \"+\" {e} ^ {x}", getFormula(getRun(getParagraph(1), 1))); CHECK_FORMULA( "{x} ^ {b}", getFormula( getRun( getParagraph( 1 ), 2 ))); CHECK_FORMULA( "{x} rsub {b}", getFormula( getRun( getParagraph( 1 ), 3 ))); CHECK_FORMULA( "{a} rsub {c} rsup {b}", getFormula( getRun( getParagraph( 1 ), 4 ))); @@ -651,8 +659,9 @@ DECLARE_OOXMLEXPORT_TEST(testTableStylerPrSz, "table-style-rPr-sz.docx") DECLARE_OOXMLEXPORT_TEST(testMathLiteral, "math-literal.docx") { - CHECK_FORMULA( u"iiint from {V} to <?> {\"div\" \"F\"} dV= llint from {S} to <?> {\"F\" \u2219 \"n \" dS}", - getFormula( getRun( getParagraph( 1 ), 1 ))); + CHECK_FORMULA( + u"iiint from {V} to <?> {\"div\" \"F\"} dV\"=\" llint from {S} to <?> {\"F\" \u2219 \"n \" dS}", + getFormula(getRun(getParagraph(1), 1))); } CPPUNIT_TEST_FIXTURE(Test, testFdo48557) @@ -1149,6 +1158,12 @@ DECLARE_OOXMLEXPORT_TEST(testBnc837302, "bnc837302.docx") CPPUNIT_ASSERT_EQUAL(false, hasProperty(getRun(xParagraph, 1), "RedlineType")); } +CPPUNIT_TEST_FIXTURE(Test, testTdf162070Export) +{ + loadAndReload("tdf162070_export.docx"); + CPPUNIT_ASSERT_EQUAL(OUString(u"{P} rsub {\"abs\"} \"~\" {B} rsub {0} \u00B2"), getFormula(getRun(getParagraph(1), 1))); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/extras/rtfexport/data/math-mso2007.rtf b/sw/qa/extras/rtfexport/data/math-mso2007.rtf index bc26831bae5a..dd8c9f607521 100644 --- a/sw/qa/extras/rtfexport/data/math-mso2007.rtf +++ b/sw/qa/extras/rtfexport/data/math-mso2007.rtf @@ -186,7 +186,7 @@ Cambria Math;} {\mr\mscr0\msty2 n} } { tlchcs1 f34 \ltrchcs0 \i\lochf34\hichf34\dbchf34\insrsid3104674 \hichf34\dbchf34\loch34 -{\mr\mscr0\msty2 -} +{\mr\mscr0\msty2 \u8722\'3f} } { tlchcs1 f34 \ltrchcs0 \i\lochf34\hichf34\dbchf34\insrsid3104674 \hichf34\dbchf34\loch34 @@ -290,7 +290,7 @@ Cambria Math;} {\mr\mscr0\msty2 n} } { tlchcs1 f31507 \ltrchcs0 \i\lochf34\hichf34\dbchf31505\insrsid3104674 \hichf34\dbchf31505\loch34 -{\mr\mscr0\msty2 -} +{\mr\mscr0\msty2 \u8722\'3f} } { tlchcs1 f31507 \ltrchcs0 \i\lochf34\hichf34\dbchf31505\insrsid3104674 \hichf34\dbchf31505\loch34 @@ -643,7 +643,7 @@ Cambria Math;} {\mnum { tlchcs1 f34 \ltrchcs0 \lochf34\hichf34\dbchf31505\insrsid3104674 \hichf34\dbchf31505\loch34 -{\mr\mscr0\msty0 -} +{\mr\mscr0\msty0 \u8722\'3f} } { tlchcs1 f34 \ltrchcs0 \i\lochf34\hichf34\dbchf31505\insrsid3104674 \hichf34\dbchf31505\loch34 {\mr\mscr0\msty2 b} @@ -685,7 +685,7 @@ Cambria Math;} } } { tlchcs1 f34 \ltrchcs0 \lochf34\hichf34\dbchf31505\insrsid3104674 \hichf34\dbchf31505\loch34 -{\mr\mscr0\msty0 -} +{\mr\mscr0\msty0 \u8722\'3f} } { tlchcs1 f34 \ltrchcs0 \lochf34\hichf34\dbchf31505\insrsid3104674 \hichf34\dbchf31505\loch34 @@ -855,7 +855,7 @@ Cambria Math;} {\mr\mscr0\msty0 } } { tlchcs1 f31507 \ltrchcs0 \i\lochf34\hichf34\dbchf31505\insrsid3104674 \hichf34\dbchf31505\loch34 -{\mr\mscr0\msty2 \hich34 -\u8734\'38} +{\mr\mscr0\msty2 \hich34 \u8722\'3f\u8734\'38} } { tlchcs1 f31507 \ltrchcs0 \i\lochf34\hichf34\dbchf31505\insrsid3104674 \hichf34\dbchf31505\loch34 @@ -1198,7 +1198,7 @@ Cambria Math;} {\mr\mscr0\msty2 \'e1} } { tlchcs1 f34 \ltrchcs0 \i\lochf34\hichf34\dbchf34\insrsid3104674 \hichf34\dbchf34\loch34 -{\mr\mscr0\msty2 -} +{\mr\mscr0\msty2 \u8722\'3f} } { tlchcs1 f635 \ltrchcs0 \i\lochf635\hichf635\dbchf34\insrsid3104674 \lochf635\dbchf34\hich635 diff --git a/sw/qa/extras/rtfexport/rtfexport.cxx b/sw/qa/extras/rtfexport/rtfexport.cxx index 65baf279cfb5..88ab791d0c39 100644 --- a/sw/qa/extras/rtfexport/rtfexport.cxx +++ b/sw/qa/extras/rtfexport/rtfexport.cxx @@ -200,9 +200,9 @@ CPPUNIT_TEST_FIXTURE(Test, testMathEqarray) { loadAndReload("math-eqarray.rtf"); OUString aActual = getFormula(getRun(getParagraph(1), 1)); - CPPUNIT_ASSERT_EQUAL( - OUString("y = left lbrace stack { 0 , x < 0 # 1 , x = 0 # {x} ^ {2} , x > 0 } right none"), - aActual); + CPPUNIT_ASSERT_EQUAL(OUString("y \"=\" left lbrace stack { 0 , x \"<\" 0 # 1 , x \"=\" 0 # {x} " + "^ {2} , x \">\" 0 } right none"), + aActual); } DECLARE_RTFEXPORT_TEST(testMathD, "math-d.rtf") @@ -246,46 +246,50 @@ CPPUNIT_TEST_FIXTURE(Test, testMathMso2007) { loadAndReload("math-mso2007.rtf"); OUString aActual = getFormula(getRun(getParagraph(1), 1)); - OUString aExpected(u"A = \u03C0 {r} ^ {2}"); + OUString aExpected(u"A \"=\" \u03C0 {r} ^ {2}"); CPPUNIT_ASSERT_EQUAL(aExpected, aActual); aActual = getFormula(getRun(getParagraph(2), 1)); - aExpected = OUString(u"{left (x + a right )} ^ {n} = sum from {k = 0} to {n} {left (stack { n " - u"# k } right ) {x} ^ {k} {a} ^ {n \u2212 k}}"); + aExpected + = u"{left (x \"+\" a right )} ^ {n} \"=\" sum from {k \"=\" 0} to {n} {left (stack { n " + u"# k } right ) {x} ^ {k} {a} ^ {n \u2212 k}}"; CPPUNIT_ASSERT_EQUAL(aExpected, aActual); aActual = getFormula(getRun(getParagraph(3), 1)); - aExpected = OUString(u"{left (1 + x right )} ^ {n} = 1 + {nx} over {1 !} + {n left (n \u2212 1 " - u"right ) {x} ^ {2}} over {2 !} + \u2026"); + aExpected = u"{left (1 \"+\" x right )} ^ {n} \"=\" 1 \"+\" {nx} over {1 !} \"+\" {n left (n " + u"\u2212 1 " + u"right ) {x} ^ {2}} over {2 !} \"+\" \u2026"; CPPUNIT_ASSERT_EQUAL(aExpected, aActual); aActual = getFormula(getRun(getParagraph(4), 1)); - aExpected = OUString(u"f left (x right ) = {a} rsub {0} + sum from {n = 1} to {\u221E} {left " - u"({a} rsub {n} cos {n\u03C0x} over {L} + {b} rsub {n} sin {n\u03C0x} " - u"over {L} right )}"); + aExpected + = u"f left (x right ) \"=\" {a} rsub {0} \"+\" sum from {n \"=\" 1} to {\u221E} {left " + u"({a} rsub {n} cos {n\u03C0x} over {L} \"+\" {b} rsub {n} sin {n\u03C0x} " + u"over {L} right )}"; CPPUNIT_ASSERT_EQUAL(aExpected, aActual); aActual = getFormula(getRun(getParagraph(5), 1)); - aExpected = "{a} ^ {2} + {b} ^ {2} = {c} ^ {2}"; + aExpected = "{a} ^ {2} \"+\" {b} ^ {2} \"=\" {c} ^ {2}"; CPPUNIT_ASSERT_EQUAL(aExpected, aActual); aActual = getFormula(getRun(getParagraph(6), 1)); - aExpected = OUString(u"x = {\u2212 b \u00B1 sqrt {{b} ^ {2} \u2212 4 ac}} over {2 a}"); + aExpected = u"x \"=\" {\u2212 b \u00B1 sqrt {{b} ^ {2} \u2212 4 ac}} over {2 a}"; CPPUNIT_ASSERT_EQUAL(aExpected, aActual); aActual = getFormula(getRun(getParagraph(7), 1)); - aExpected = OUString(u"{e} ^ {x} = 1 + {x} over {1 !} + {{x} ^ {2}} over {2 !} + {{x} ^ {3}} " - u"over {3 !} + \u2026 , \u2212 \u221E < x < \u221E"); + aExpected + = u"{e} ^ {x} \"=\" 1 \"+\" {x} over {1 !} \"+\" {{x} ^ {2}} over {2 !} \"+\" {{x} ^ {3}} " + u"over {3 !} \"+\" \u2026 , \u2212 \u221E \"<\" x \"<\" \u221E"; CPPUNIT_ASSERT_EQUAL(aExpected, aActual); aActual = getFormula(getRun(getParagraph(8), 1)); - aExpected = OUString(u"sin \u03B1 \u00B1 sin \u03B2 = 2 sin {1} over {2} left (\u03B1 \u00B1 " - u"\u03B2 right ) cos {1} over {2} left (\u03B1 \u2213 \u03B2 right )"); + aExpected = u"sin \u03B1 \u00B1 sin \u03B2 \"=\" 2 sin {1} over {2} left (\u03B1 \u00B1 " + u"\u03B2 right ) cos {1} over {2} left (\u03B1 \u2213 \u03B2 right )"; CPPUNIT_ASSERT_EQUAL(aExpected, aActual); aActual = getFormula(getRun(getParagraph(9), 1)); - aExpected = OUString(u"cos \u03B1 + cos \u03B2 = 2 cos {1} over {2} left (\u03B1 + \u03B2 " - u"right ) cos {1} over {2} left (\u03B1 \u2212 \u03B2 right )"); + aExpected = u"cos \u03B1 \"+\" cos \u03B2 \"=\" 2 cos {1} over {2} left (\u03B1 \"+\" \u03B2 " + u"right ) cos {1} over {2} left (\u03B1 \u2212 \u03B2 right )"; CPPUNIT_ASSERT_EQUAL(aExpected, aActual); } @@ -294,7 +298,7 @@ CPPUNIT_TEST_FIXTURE(Test, testMathNary) loadAndReload("math-nary.rtf"); OUString aActual = getFormula(getRun(getParagraph(1), 1)); CPPUNIT_ASSERT_EQUAL( - OUString("lllint from {1} to {2} {x + 1} prod from {a} {b} sum to {2} {x}"), aActual); + OUString("lllint from {1} to {2} {x \"+\" 1} prod from {a} {b} sum to {2} {x}"), aActual); } DECLARE_RTFEXPORT_TEST(testMathLimupp, "math-limupp.rtf") @@ -322,7 +326,7 @@ CPPUNIT_TEST_FIXTURE(Test, testMathRad) { loadAndReload("math-rad.rtf"); OUString aActual = getFormula(getRun(getParagraph(1), 1)); - CPPUNIT_ASSERT_EQUAL(OUString("sqrt {4} nroot {3} {x + 1}"), aActual); + CPPUNIT_ASSERT_EQUAL(OUString("sqrt {4} nroot {3} {x \"+\" 1}"), aActual); } DECLARE_RTFEXPORT_TEST(testMathSepchr, "math-sepchr.rtf") @@ -335,7 +339,7 @@ DECLARE_RTFEXPORT_TEST(testMathSubscripts, "math-subscripts.rtf") { OUString aActual = getFormula(getRun(getParagraph(1), 1)); CPPUNIT_ASSERT_EQUAL( - OUString("{x} ^ {y} + {e} ^ {x} {x} ^ {b} {x} rsub {b} {a} rsub {c} rsup {b} " + OUString("{x} ^ {y} \"+\" {e} ^ {x} {x} ^ {b} {x} rsub {b} {a} rsub {c} rsup {b} " "{x} lsub {2} lsup {1} {{x csup {6} csub {3}} lsub {4} lsup {5}} rsub " "{2} rsup {1}"), aActual); @@ -379,7 +383,7 @@ CPPUNIT_TEST_FIXTURE(Test, testMathRuns) { loadAndReload("math-runs.rtf"); // was [](){}, i.e. first curly bracket had an incorrect position - CPPUNIT_ASSERT_EQUAL(OUString("\{ left [ right ] left ( right ) \}"), + CPPUNIT_ASSERT_EQUAL(OUString("\{ \[ \] \( \) \}"), getFormula(getRun(getParagraph(1), 1))); } @@ -522,9 +526,8 @@ DECLARE_RTFEXPORT_TEST(testMnor, "mnor.rtf") { // \mnor wasn't handled, leading to missing quotes around "divF" and so on. OUString aActual = getFormula(getRun(getParagraph(1), 1)); - CPPUNIT_ASSERT_EQUAL( - OUString( - u"iiint from {V} to <?> {\"divF\"} dV = llint from {S} to <?> {\"F\" \u2219 \"n\" dS}"), + CPPUNIT_ASSERT_EQUAL(OUString( + u"iiint from {V} to <?> {\"divF\"} dV \"=\" llint from {S} to <?> {\"F\" \u2219 \"n\" dS}"), aActual); }