starmath/source/ooxmlimport.cxx | 4 ++-- sw/qa/extras/ooxmlexport/data/tdf158023_export.docx |binary sw/qa/extras/ooxmlexport/ooxmlexport2.cxx | 9 ++++++++- sw/qa/extras/ooxmlimport/data/tdf158023_import.docx |binary sw/qa/extras/ooxmlimport/ooxmlimport2.cxx | 20 ++++++++++++++++++++ sw/qa/extras/rtfexport/data/tdf158023.rtf | 8 ++++++++ sw/qa/extras/rtfexport/rtfexport.cxx | 10 +++++++++- 7 files changed, 47 insertions(+), 4 deletions(-)
New commits: commit 57946f4262b5d548d3429723faf380eaba5ce9f8 Author: Irgaliev Amin <irgalie...@mail.ru> AuthorDate: Mon Dec 25 20:13:34 2023 +0400 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Tue Jun 18 14:06:35 2024 +0200 tdf#158023 Add \ before parentheses if they are in the <t> tag. MSO allows you to write unpair opening or closing parentheses in the t tag. The patch adds a backslash before parentheses, which allows you to correctly recognize and correctly save such formulas when exporting. Also add a test to check whether the parentheses are wrapped correctly. Change-Id: Ib1a941858f0843742b56b8089f3c14983ba1222c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158794 Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> Tested-by: Jenkins (cherry picked from commit 8148dd6ed3c61eaf5f9fe3a060ecda9d11611f39) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169103 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/starmath/source/ooxmlimport.cxx b/starmath/source/ooxmlimport.cxx index 4023a5e652ac..b0932c43919c 100644 --- a/starmath/source/ooxmlimport.cxx +++ b/starmath/source/ooxmlimport.cxx @@ -602,9 +602,9 @@ OUString SmOoxmlImport::handleR() { XmlStream::Tag rtag = m_rStream.ensureOpeningTag( M_TOKEN( t )); if( rtag.attribute( OOX_TOKEN( xml, space )) != "preserve" ) - text.append(o3tl::trim(rtag.text)); + text.append(o3tl::trim(rtag.text.replaceAll("(", "\(").replaceAll(")", "\)"))); else - text.append(rtag.text); + text.append(rtag.text.replaceAll("(", "\(").replaceAll(")", "\)")); m_rStream.ensureClosingTag( M_TOKEN( t )); break; } diff --git a/sw/qa/extras/ooxmlexport/data/tdf158023_export.docx b/sw/qa/extras/ooxmlexport/data/tdf158023_export.docx new file mode 100644 index 000000000000..289619a7e4b6 Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf158023_export.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx index 6e27f9a6a1ab..e18c1eebca5e 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx @@ -261,7 +261,14 @@ 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("\{ left [ right ] \( \) \}"), getFormula(getRun(getParagraph(1), 1))); +} + +// Saving left and right for parentheses when importing not from the m:t tag (docx) +CPPUNIT_TEST_FIXTURE(Test, testTdf158023Export) +{ + loadAndReload("tdf158023_export.docx"); + CPPUNIT_ASSERT_EQUAL(OUString("left [ right ] left ( right ) left lbrace right rbrace"), getFormula(getRun(getParagraph(1), 1))); } CPPUNIT_TEST_FIXTURE(Test, testFdo51034) diff --git a/sw/qa/extras/ooxmlimport/data/tdf158023_import.docx b/sw/qa/extras/ooxmlimport/data/tdf158023_import.docx new file mode 100644 index 000000000000..1095499e2ebf Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/tdf158023_import.docx differ diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx index 0c29484d765e..642c05b14aa8 100644 --- a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx +++ b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx @@ -697,6 +697,26 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf119200) CPPUNIT_ASSERT_EQUAL(u" size 12{ func \u2287 } {}"_ustr, getFormula(getRun(xPara, 7))); } +// Checking a formula where the closing brackets +// come first, and then the opening ones +CPPUNIT_TEST_FIXTURE(Test, testTdf158023Import) +{ + auto verify = [this]() { + auto xPara = getParagraph(1); + CPPUNIT_ASSERT_EQUAL(u"\) sqrt {\)2\(} \("_ustr, getFormula(getRun(xPara, 1))); + }; + auto verifyReload = [this]() { + auto xPara = getParagraph(1); + CPPUNIT_ASSERT_EQUAL(u"\) sqrt {\) 2 \(} \("_ustr, getFormula(getRun(xPara, 1))); + }; + + createSwDoc("tdf158023_import.docx"); + verify(); + + saveAndReload("Office Open XML Text"); + verifyReload(); +} + CPPUNIT_TEST_FIXTURE(Test, testTdf115094) { createSwDoc("tdf115094.docx"); diff --git a/sw/qa/extras/rtfexport/data/tdf158023.rtf b/sw/qa/extras/rtfexport/data/tdf158023.rtf new file mode 100644 index 000000000000..cdcddc4532fc --- /dev/null +++ b/sw/qa/extras/rtfexport/data/tdf158023.rtf @@ -0,0 +1,8 @@ +{ tf1 +{\mmath {\*\moMath +{\md {\mdPr {\mbegChr [}{\mendChr ]}}{\me {\mr a}}} +{\md {\mdPr {\mbegChr (}{\mendChr )}}{\me {\mr b}}} +{\md {\mdPr {\mbegChr \{}{\mendChr \}}}{\me {\mr c}}} +}} +\par +} diff --git a/sw/qa/extras/rtfexport/rtfexport.cxx b/sw/qa/extras/rtfexport/rtfexport.cxx index bbb09090500e..193d0c6e54fb 100644 --- a/sw/qa/extras/rtfexport/rtfexport.cxx +++ b/sw/qa/extras/rtfexport/rtfexport.cxx @@ -371,7 +371,15 @@ 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("\{ left [ right ] \( \) \}"), + getFormula(getRun(getParagraph(1), 1))); +} + +// Saving left and right for parentheses when importing not from the m:t tag (rtf) +CPPUNIT_TEST_FIXTURE(Test, testTdf158023_rtf) +{ + loadAndReload("tdf158023.rtf"); + CPPUNIT_ASSERT_EQUAL(OUString("left [a right ] left (b right ) left lbrace c right rbrace"), getFormula(getRun(getParagraph(1), 1))); }