tdf#160952 sw: ignore top margin only at page top, not in fly

See
<https://gerrit.libreoffice.org/c/core/+/167671/2#message-8603b129dd8bd72608259571056ded950182ca96>,
multi-column shape text can't appear in DOCX files, so collapsing upper
spacing in that case is not correct, avoid it.

Change-Id: Icf69c8d84fdd15d6e3289ff614b2f6ba7cee1e0e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167758
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
diff --git a/sw/qa/core/layout/calcmove.cxx b/sw/qa/core/layout/calcmove.cxx
index a44dc12..ad53df9 100644
--- a/sw/qa/core/layout/calcmove.cxx
+++ b/sw/qa/core/layout/calcmove.cxx
@@ -58,6 +58,30 @@ CPPUNIT_TEST_FIXTURE(Test, testIgnoreTopMarginTable)
    // i.e. the top margin in B1's first paragraph was ignored, but not in Word.
    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2000), nParaTopMargin);
}

CPPUNIT_TEST_FIXTURE(Test, testIgnoreTopMarginFly)
{
    // Given a document with compat flags like DOCX (>= Word 2013), 2 pages, multi-col fly frame on
    // page 2:
    createSwDoc("ignore-top-margin-fly.odt");

    // When laying out that document:
    xmlDocUniquePtr pXmlDoc = parseLayoutDump();

    // Then make sure that the top margin is not ignored inside shape text:
    sal_Int32 nParaTopMargin
        = getXPath(
              pXmlDoc,
              "/root/page[2]/body/section/column[2]/body/txt/anchored/fly/column/body/txt/infos/prtBounds"_ostr,
              "top"_ostr)
              .toInt32();
    // Without the accompanying fix in place, this test would have failed with:
    // - Expected: 4000
    // - Actual  : 0
    // i.e. the top margin was ignored inside shape text for Word compat, while multi-col shape text
    // is a Writer feature.
    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(4000), nParaTopMargin);
}
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/core/layout/data/ignore-top-margin-fly.odt b/sw/qa/core/layout/data/ignore-top-margin-fly.odt
new file mode 100644
index 0000000..51bda8f
--- /dev/null
+++ b/sw/qa/core/layout/data/ignore-top-margin-fly.odt
Binary files differ
diff --git a/sw/source/core/layout/calcmove.cxx b/sw/source/core/layout/calcmove.cxx
index ea27716..6e81123 100644
--- a/sw/source/core/layout/calcmove.cxx
+++ b/sw/source/core/layout/calcmove.cxx
@@ -1092,6 +1092,12 @@ bool SwFrame::IsCollapseUpper() const
        return false;
    }

    if (IsInFly())
    {
        // Not in a page's body.
        return false;
    }

    // Word >= 2013 style: when we're at the top of the page's body, but not on the first page, then
    // ignore the upper margin for paragraphs.
    if (GetPrev() || !GetUpper() || !GetUpper()->IsBodyFrame())