tdf#99197 ww8import: all root-level para-styles default to LTR

It is not just the "Normal" paragraph style that should
default to LTR. Any new style that does not inherit from
anything should be set to LTR, regardless of page/section
settings.

Change-Id: Ibe1241b813b82afa9b218eae50d6c78042131893
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92468
Tested-by: Jenkins
Reviewed-by: Justin Luth <justin_luth@sil.org>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
diff --git a/sw/qa/extras/ww8export/data/tdf99197_defaultLTR.doc b/sw/qa/extras/ww8export/data/tdf99197_defaultLTR.doc
new file mode 100644
index 0000000..721b688
--- /dev/null
+++ b/sw/qa/extras/ww8export/data/tdf99197_defaultLTR.doc
Binary files differ
diff --git a/sw/qa/extras/ww8export/ww8export2.cxx b/sw/qa/extras/ww8export/ww8export2.cxx
index 42cc823..fbc4e0d 100644
--- a/sw/qa/extras/ww8export/ww8export2.cxx
+++ b/sw/qa/extras/ww8export/ww8export2.cxx
@@ -294,6 +294,15 @@ DECLARE_WW8EXPORT_TEST(testTdf80635_pageLeft, "tdf80635_pageLeft.doc")
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Table Indent", long(-2750), getProperty<long>(xTable, "LeftMargin"), 100);
}

DECLARE_WW8EXPORT_TEST(testTdf99197_defaultLTR, "tdf99197_defaultLTR.doc")
{
    CPPUNIT_ASSERT_EQUAL_MESSAGE( "Default Paragraph style, LTR",
        text::WritingMode2::LR_TB, getProperty<sal_Int16>(getParagraph(1), "WritingMode") );

    CPPUNIT_ASSERT_EQUAL_MESSAGE( "myDefaultStyle - no base style, LTR",
        text::WritingMode2::LR_TB, getProperty<sal_Int16>(getParagraph(2), "WritingMode") );
}

DECLARE_WW8EXPORT_TEST(testTdf107773, "tdf107773.doc")
{
    uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
diff --git a/sw/source/filter/ww8/ww8par2.cxx b/sw/source/filter/ww8/ww8par2.cxx
index a18dd51..d11d9fb 100644
--- a/sw/source/filter/ww8/ww8par2.cxx
+++ b/sw/source/filter/ww8/ww8par2.cxx
@@ -3751,6 +3751,7 @@ WW8RStyle::WW8RStyle(WW8Fib& _rFib, SwWW8ImplReader* pI)
    , mbFSizeChanged(false)
    , mbFCTLSizeChanged(false)
    , mbWidowsChanged(false)
    , mbBidiChanged(false)
{
    mpIo->m_vColl.resize(m_cstd);
}
@@ -3796,6 +3797,14 @@ void WW8RStyle::Set1StyleDefaults()
            mpIo->m_pCurrentColl->SetFormatAttr( SvxWidowsItem( 2, RES_PARATR_WIDOWS ) );
            mpIo->m_pCurrentColl->SetFormatAttr( SvxOrphansItem( 2, RES_PARATR_ORPHANS ) );
        }

        // Word defaults to ltr, not inheriting from the environment like Writer. Regardless of
        // the page/sections rtl setting, the standard/no-inherit styles lack of rtl still means ltr
        if( !mbBidiChanged )  // likely, since no UI to change LTR except in default style
        {
            mpIo->m_pCurrentColl->SetFormatAttr(
                SvxFrameDirectionItem(SvxFrameDirection::Horizontal_LR_TB, RES_FRAMEDIR));
        }
    }
}

@@ -4550,18 +4559,6 @@ void WW8RStyle::Import()

            mpIo->m_pStandardFormatColl->SetFormatAttr( aAttr );
        }

        /*
        Word defaults to ltr not from environment like writer. Regardless of
        the page/sections rtl setting the standard style lack of rtl still
        means ltr
        */
        if (SfxItemState::SET != mpIo->m_pStandardFormatColl->GetItemState(RES_FRAMEDIR,
            false))
        {
           mpIo->m_pStandardFormatColl->SetFormatAttr(
                SvxFrameDirectionItem(SvxFrameDirection::Horizontal_LR_TB, RES_FRAMEDIR));
        }
    }

    // we do not read styles anymore:
diff --git a/sw/source/filter/ww8/ww8par2.hxx b/sw/source/filter/ww8/ww8par2.hxx
index 86f8436..22ca540 100644
--- a/sw/source/filter/ww8/ww8par2.hxx
+++ b/sw/source/filter/ww8/ww8par2.hxx
@@ -105,6 +105,7 @@ friend class SwWW8ImplReader;
    bool mbFSizeChanged;     // For Simulating Default-FontSize
    bool mbFCTLSizeChanged;  // For Simulating Default-CTL FontSize
    bool mbWidowsChanged;    // For Simulating Default-Widows / Orphans
    bool mbBidiChanged;      // For Simulating Default-LTR

    void ImportSprms(std::size_t nPosFc, short nLen, bool bPap);
    void ImportSprms(sal_uInt8 *pSprms, short nLen, bool bPap);
diff --git a/sw/source/filter/ww8/ww8par6.cxx b/sw/source/filter/ww8/ww8par6.cxx
index 47545c6..dd260b4 100644
--- a/sw/source/filter/ww8/ww8par6.cxx
+++ b/sw/source/filter/ww8/ww8par6.cxx
@@ -3071,6 +3071,9 @@ void SwWW8ImplReader::Read_Bidi(sal_uInt16, const sal_uInt8* pData, short nLen)
        m_bBidi = true;
        sal_uInt8 nBidi = *pData;
        NewAttr( SfxInt16Item( RES_CHRATR_BIDIRTL, (nBidi!=0)? 1 : 0 ) );

        if( m_pCurrentColl && m_xStyles )    // in style definition
            m_xStyles->mbBidiChanged = true;
    }
}