tdf#128304 export TB_RL writing mode as eaVirt

and import eaVirt to TextWritingMode instead of TextPreRotateAngle
(-90) degree of CustomShapeGeometry. CJK text in TB_RL writing mode
are upright in Writer. It corresponds to eaVirt by its defintion.

Change-Id: I2a8bc6676ad6af06b06e023adaa2f201a028d426
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86637
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx
index 087c51d..8c9f641 100644
--- a/oox/source/export/drawingml.cxx
+++ b/oox/source/export/drawingml.cxx
@@ -2692,7 +2692,7 @@

        if( ( mAny >>= eMode ) && eMode == WritingMode_TB_RL )
        {
            sWritingMode = "vert";
            sWritingMode = "eaVert";
            bVertical = true;
        }
    }
diff --git a/oox/source/shape/WpsContext.cxx b/oox/source/shape/WpsContext.cxx
index cf637ea..863621b 100644
--- a/oox/source/shape/WpsContext.cxx
+++ b/oox/source/shape/WpsContext.cxx
@@ -18,6 +18,7 @@
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/text/XText.hpp>
#include <com/sun/star/text/XTextCursor.hpp>
#include <com/sun/star/text/WritingMode.hpp>
#include <svx/svdtrans.hxx>
#include <oox/helper/attributelist.hxx>
#include <oox/token/namespaces.hxx>
@@ -57,7 +58,12 @@
                uno::Reference<lang::XServiceInfo> xServiceInfo(mxShape, uno::UNO_QUERY);
                uno::Reference<beans::XPropertySet> xPropertySet(mxShape, uno::UNO_QUERY);
                sal_Int32 nVert = rAttribs.getToken(XML_vert, XML_horz);
                if (nVert != XML_horz)
                if (nVert == XML_eaVert)
                {
                    xPropertySet->setPropertyValue("TextWritingMode",
                                                   uno::makeAny(text::WritingMode_TB_RL));
                }
                else if (nVert != XML_horz)
                {
                    // Get the existing rotation of the shape.
                    drawing::HomogenMatrix3 aMatrix;
diff --git a/sw/qa/extras/ooxmlexport/data/tdf128304.odt b/sw/qa/extras/ooxmlexport/data/tdf128304.odt
new file mode 100644
index 0000000..6c5cbd1
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/tdf128304.odt
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
index 18e957b..8168768 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
@@ -11,6 +11,7 @@

#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/style/LineSpacing.hpp>
#include <com/sun/star/text/WritingMode.hpp>
#include <com/sun/star/text/WritingMode2.hpp>
#include <com/sun/star/text/XTextFrame.hpp>
#include <com/sun/star/drawing/XControlShape.hpp>
@@ -639,12 +640,10 @@

    if (mbExported)
    {
        // DML import: creates a TextBox.
        // DML import: creates a TextBox, eaVert read back as TB_RL in TextWritingMode

        comphelper::SequenceAsHashMap aGeometry(xTextFrame->getPropertyValue("CustomShapeGeometry"));
        // Without the accompanying fix in place, this test would have failed with 'Expected: -90;
        // Actual: 0', i.e. the tblr writing mode was lost during DML export of a TextFrame.
        CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(-90), aGeometry["TextPreRotateAngle"].get<sal_Int32>());
        auto eMode = getProperty<text::WritingMode>(xTextFrame, "TextWritingMode");
        CPPUNIT_ASSERT_EQUAL(text::WritingMode::WritingMode_TB_RL, eMode);
    }
    else
    {
@@ -993,6 +992,26 @@
    assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:hyperlink/w:r/w:rPr/w:rStyle", "val", "InternetLink");
}

DECLARE_OOXMLEXPORT_TEST(testTdf128304, "tdf128304.odt")
{
    css::text::WritingMode eMode;
    uno::Reference<beans::XPropertySet> xProps1(getShape(1), uno::UNO_QUERY);
    CPPUNIT_ASSERT(xProps1->getPropertyValue("TextWritingMode") >>= eMode);
    CPPUNIT_ASSERT_EQUAL(css::text::WritingMode::WritingMode_TB_RL, eMode);

    uno::Reference<beans::XPropertySet> xProps2(getShape(2), uno::UNO_QUERY);
    CPPUNIT_ASSERT(xProps1->getPropertyValue("TextWritingMode") >>= eMode);
    CPPUNIT_ASSERT_EQUAL(css::text::WritingMode::WritingMode_TB_RL, eMode);

    uno::Reference<beans::XPropertySet> xProps3(getShape(3), uno::UNO_QUERY);
    CPPUNIT_ASSERT(xProps1->getPropertyValue("TextWritingMode") >>= eMode);
    CPPUNIT_ASSERT_EQUAL(css::text::WritingMode::WritingMode_TB_RL, eMode);

    uno::Reference<beans::XPropertySet> xProps4(getShape(4), uno::UNO_QUERY);
    CPPUNIT_ASSERT(xProps1->getPropertyValue("TextWritingMode") >>= eMode);
    CPPUNIT_ASSERT_EQUAL(css::text::WritingMode::WritingMode_TB_RL, eMode);
}

CPPUNIT_PLUGIN_IMPLEMENT();

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ww8/docxsdrexport.cxx b/sw/source/filter/ww8/docxsdrexport.cxx
index 005e50b..8ab399a4 100644
--- a/sw/source/filter/ww8/docxsdrexport.cxx
+++ b/sw/source/filter/ww8/docxsdrexport.cxx
@@ -1359,7 +1359,7 @@

        const SvxFrameDirectionItem& rDirection = rFrameFormat.GetFrameDir();
        if (rDirection.GetValue() == SvxFrameDirection::Vertical_RL_TB)
            m_pImpl->getBodyPrAttrList()->add(XML_vert, "vert");
            m_pImpl->getBodyPrAttrList()->add(XML_vert, "eaVert");
        else if (rDirection.GetValue() == SvxFrameDirection::Vertical_LR_BT)
            m_pImpl->getBodyPrAttrList()->add(XML_vert, "vert270");