sw XHTML export: fix writing of section direction

The XHTML export behavior was the same as the HTML one for section text
direction, the <div dir="..."> markup was used.

This shares code with the HTML filter, but it's not valid in
reqif-xhtml, while the CSS markup would be fine: <div style="dir: ...">.

Fix the problem by keeping the behavior unchanged for HTML, but switch
to inline CSS for XHTML.

The other similar attribute was "id", but that's fine even in XHTML.

Change-Id: I5797c90f9cf957dec7fc4074dd6e79dce11fada7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137305
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index 44654bd..5e5af5e 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -2369,6 +2369,29 @@ CPPUNIT_TEST_FIXTURE(HtmlExportTest, testImageKeepRatio)
    assertXPath(pDoc, "/html/body/p/img", "height", "auto");
}

CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testSectionDir)
{
    // Given a document with a section:
    SwDoc* pDoc = createSwDoc();
    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
    pWrtShell->Insert("test");
    pWrtShell->SelAll();
    SwSectionData aSectionData(SectionType::Content, "mysect");
    pWrtShell->InsertSection(aSectionData);

    // When exporting to (reqif-)xhtml:
    ExportToReqif();

    // Then make sure CSS is used to export the text direction of the section:
    SvMemoryStream aStream;
    HtmlExportTest::wrapFragment(maTempFile, aStream);
    xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream);
    // Without the accompanying fix in place, this test would have failed with:
    // - XPath '//reqif-xhtml:div[@id='mysect']' no attribute 'style' exist
    // i.e. the dir="ltr" HTML attribute was used instead.
    assertXPath(pXmlDoc, "//reqif-xhtml:div[@id='mysect']", "style", "dir: ltr");
}

CPPUNIT_PLUGIN_IMPLEMENT();

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/html/css1atr.cxx b/sw/source/filter/html/css1atr.cxx
index bc2449b..1520a4e 100644
--- a/sw/source/filter/html/css1atr.cxx
+++ b/sw/source/filter/html/css1atr.cxx
@@ -2088,6 +2088,17 @@ void SwHTMLWriter::OutCSS1_SectionFormatOptions( const SwFrameFormat& rFrameForm
    if( SfxItemState::SET==rItemSet.GetItemState( RES_BACKGROUND, false, &pItem ) )
        OutCSS1_SvxBrush( *this, *pItem, sw::Css1Background::Section, nullptr );

    if (mbXHTML)
    {
        SvxFrameDirection nDir = GetHTMLDirection(rFrameFormat.GetAttrSet());
        OString sConvertedDirection = convertDirection(nDir);
        if (!sConvertedDirection.isEmpty())
        {
            OutCSS1_Property(sCSS1_P_dir, sConvertedDirection, nullptr,
                             sw::Css1Background::Section);
        }
    }

    if (pCol)
    {
        OString sColumnCount(OString::number(static_cast<sal_Int32>(pCol->GetNumCols())));
diff --git a/sw/source/filter/html/css1kywd.cxx b/sw/source/filter/html/css1kywd.cxx
index af8c539..12d7090 100644
--- a/sw/source/filter/html/css1kywd.cxx
+++ b/sw/source/filter/html/css1kywd.cxx
@@ -171,6 +171,7 @@ const char* const sCSS1_P_height = "height";
const char* const sCSS1_P_float = "float";

const char* const sCSS1_P_column_count = "column-count";
const char* const sCSS1_P_dir = "dir";

// Strings for positioning

diff --git a/sw/source/filter/html/css1kywd.hxx b/sw/source/filter/html/css1kywd.hxx
index 443af7e..67d2c9e 100644
--- a/sw/source/filter/html/css1kywd.hxx
+++ b/sw/source/filter/html/css1kywd.hxx
@@ -172,6 +172,7 @@ extern const char* const sCSS1_P_height;
extern const char* const sCSS1_P_float;

extern const char* const sCSS1_P_column_count;
extern const char* const sCSS1_P_dir;

// Strings for positioning

diff --git a/sw/source/filter/html/wrthtml.cxx b/sw/source/filter/html/wrthtml.cxx
index d216e0d..0cede88 100644
--- a/sw/source/filter/html/wrthtml.cxx
+++ b/sw/source/filter/html/wrthtml.cxx
@@ -711,9 +711,12 @@ static void lcl_html_OutSectionStartTag( SwHTMLWriter& rHTMLWrt,
        sOut.append('\"');
    }

    SvxFrameDirection nDir = rHTMLWrt.GetHTMLDirection( rFormat.GetAttrSet() );
    rHTMLWrt.Strm().WriteOString( sOut.makeStringAndClear() );
    rHTMLWrt.OutDirection( nDir );
    if (!rHTMLWrt.mbXHTML)
    {
        SvxFrameDirection nDir = rHTMLWrt.GetHTMLDirection(rFormat.GetAttrSet());
        rHTMLWrt.OutDirection(nDir);
    }

    if( SectionType::FileLink == rSection.GetType() )
    {