tdf#159158 writerfilter: headers always behind text (!opaque)

If the body-anchored thing is in the background,
then if any header stuff was NOT in the background,
then it would show up above the body thing,
and that should not happen in a DOCX world.

This test was not easy to produce.
ODT kind of knows that headers are special,
and so it tries really hard to put stuff in the background
without any wrap - at least after a round-trip.

So I had to hand-craft from my example DOCX
that exhibited a behindDoc which actually
had some wrapping component to it.

make CppunitTest_sw_ooxmlexport18 \
    CPPUNIT_TEST_NAME=testTdf159158_zOrder_headerBehind2

Change-Id: I31617cd7bf2d38add2233a7a06ffe9a8ec00ec0a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164130
Tested-by: Jenkins
Reviewed-by: Justin Luth <jluth@mail.com>
diff --git a/sw/qa/extras/ooxmlexport/data/tdf159158_zOrder_headerBehind2.docx b/sw/qa/extras/ooxmlexport/data/tdf159158_zOrder_headerBehind2.docx
new file mode 100644
index 0000000..e787b9c
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/tdf159158_zOrder_headerBehind2.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
index 91fa26e..cb41f03 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
@@ -1047,6 +1047,23 @@ DECLARE_OOXMLEXPORT_TEST(testTdf159158_zOrder_headerBehind, "tdf159158_zOrder_he
    CPPUNIT_ASSERT_EQUAL(OUString("RectangleInBody"), getProperty<OUString>(zOrder1,"Name"));
}

DECLARE_OOXMLEXPORT_TEST(testTdf159158_zOrder_headerBehind2, "tdf159158_zOrder_headerBehind2.docx")
{
    // given a logo (marked as behind text) anchored in the header
    // and an overlapping blue rectangle anchored in the body text.
    uno::Reference<beans::XPropertySet> zOrder0(getShape(1), uno::UNO_QUERY);
    uno::Reference<beans::XPropertySet> zOrder1(getShape(2), uno::UNO_QUERY);
    CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(zOrder0, "ZOrder")); // lower
    CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getProperty<sal_Int32>(zOrder1, "ZOrder")); // higher
    CPPUNIT_ASSERT_EQUAL(OUString("HeaderImage"),
                         getProperty<OUString>(zOrder0, "LinkDisplayName"));
    CPPUNIT_ASSERT_EQUAL(OUString("BodyBlueRectangle"),
                         getProperty<OUString>(zOrder1,"LinkDisplayName"));
    // The logo should not be opaque since it is in the header.
    CPPUNIT_ASSERT(!getProperty<bool>(zOrder0, "Opaque")); // logo should be invisible
    CPPUNIT_ASSERT(!getProperty<bool>(zOrder1, "Opaque"));
}

DECLARE_OOXMLEXPORT_TEST(testTdf155903, "tdf155903.odt")
{
    // Without the accompanying fix in place, this test would have crashed,
diff --git a/writerfilter/source/dmapper/GraphicImport.cxx b/writerfilter/source/dmapper/GraphicImport.cxx
index 386ac69..f64bef0 100644
--- a/writerfilter/source/dmapper/GraphicImport.cxx
+++ b/writerfilter/source/dmapper/GraphicImport.cxx
@@ -1602,7 +1602,7 @@ void GraphicImport::lcl_sprm(Sprm& rSprm)
                {
                    // tdf#137850: Word >= 2013 seems to ignore bBehindDoc except for wrapNone, but older versions honour it.
                    if (m_pImpl->m_bBehindDoc && m_pImpl->m_rDomainMapper.GetSettingsTable()->GetWordCompatibilityMode() > 14)
                        m_pImpl->m_bOpaque = true;
                        m_pImpl->m_bOpaque = !m_pImpl->m_rDomainMapper.IsInHeaderFooter();
                }
                break;
            }
@@ -1720,7 +1720,7 @@ void GraphicImport::lcl_sprm(Sprm& rSprm)
        case NS_ooxml::LN_EG_WrapType_wrapTopAndBottom:
            // tdf#137850: Word >= 2013 seems to ignore bBehindDoc except for wrapNone, but older versions honour it.
            if (m_pImpl->m_bBehindDoc && m_pImpl->m_rDomainMapper.GetSettingsTable()->GetWordCompatibilityMode() > 14)
                 m_pImpl->m_bOpaque = true;
                 m_pImpl->m_bOpaque = !m_pImpl->m_rDomainMapper.IsInHeaderFooter();
            m_pImpl->m_nWrap = text::WrapTextMode_NONE;
        break;
        case NS_ooxml::LN_CT_GraphicalObject_graphicData: