tdf#155470 DOCX export: fix RTL numbers changed to LTR

When using numerals in "context" mode in "Tools > Options", in
"Language Settings > Complext Text Layout > General Options > Numerals",
the actual display of the numbers is dependant on the direction and
the language of those numbers.

Previously, when exporting the DOCX in LO the RTL direction was lost,
and because of that, the numerals were shown incorrectly after saving
in LibreOffice, and loading again.

This patch adds <w:rtl/> where <w:lang> contains an RTL language.
For example, before <w:lang w:bidi="fa-IR"/> inside <w:rPr>, it always
adds <w:rtl/>.

It is worth noting that this is not always the case, as there are
situations that <w:rtl/> is not present in <w:rPr> with an RTL language
like <w:lang w:bidi="fa-IR"/> and <w:rtl/> should not be in the output.
This patch does not handle that case, because currently loading such a
text is not done correctly in LO, and the LTR numbers inside RTL
environment are shown just like RTL numbers. To fix it, first loading
and displaying of that should be fixed.

A test is added to check the export of the sample file, which can be
invoked with:

 make CppunitTest_sw_ooxmlexport CPPUNIT_TEST_NAME=testTdf155470

Change-Id: I8fc54916fcd3295010c5c81ccb632bc6082ffaa2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155721
Tested-by: Jenkins
Reviewed-by: Hossein <hossein@libreoffice.org>
This commit is contained in:
Hossein 2023-08-15 14:56:53 +02:00
parent 8ec43f37a7
commit 40ed8dd3a5
4 changed files with 13 additions and 1 deletions

Binary file not shown.

View file

@ -1106,6 +1106,15 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf115094v3)
assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tblPr/w:tblpPr", "tblpY", "1064");
}
CPPUNIT_TEST_FIXTURE(Test, testTdf155470)
{
loadAndSave("numbers-rtl.docx");
xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
// Make sure that <w:rtl/> is preserved
assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r/w:rPr/w:rtl");
}
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View file

@ -174,7 +174,7 @@ CPPUNIT_TEST_FIXTURE(Test, testStyleInheritance)
// We output exactly 2 properties in rPrDefault, nothing else was
// introduced as an additional default
assertXPath(pXmlStyles, "/w:styles/w:docDefaults/w:rPrDefault/w:rPr/*", 2);
assertXPath(pXmlStyles, "/w:styles/w:docDefaults/w:rPrDefault/w:rPr/*", 3);
// Check that we output real content of rPrDefault
assertXPath(pXmlStyles, "/w:styles/w:docDefaults/w:rPrDefault/w:rPr/w:rFonts", "ascii", "Times New Roman");
assertXPath(pXmlStyles, "/w:styles/w:docDefaults/w:rPrDefault/w:rPr/w:lang", "bidi", "ar-SA");

View file

@ -160,6 +160,7 @@
#include <frozen/bits/defines.h>
#include <frozen/bits/elsa_std.h>
#include <frozen/unordered_map.h>
#include <i18nlangtag/mslangid.hxx>
using ::editeng::SvxBorderLine;
@ -7916,6 +7917,8 @@ void DocxAttributeOutput::CharLanguage( const SvxLanguageItem& rLanguage )
AddToAttrList( m_pCharLangAttrList, FSNS( XML_w, XML_eastAsia ), aLanguageCode );
break;
case RES_CHRATR_CTL_LANGUAGE:
if (MsLangId::isRightToLeft(rLanguage.GetLanguage()))
m_pSerializer->singleElementNS(XML_w, XML_rtl);
AddToAttrList( m_pCharLangAttrList, FSNS( XML_w, XML_bidi ), aLanguageCode );
break;
}