related tdf#157572 writerfilter framePr: no vAlign if vAnchor=text

See bug 157572 for the documentation.

This can be seen in MS Word's UI.
Have the vertical position be centered, and then change to "para":
-> the vertical position changes to a numbered distance.

make CppunitTest_sw_ooxmlexport5 \
    CPPUNIT_TEST_NAME=testTdf157572_noVAlignAsText

make CppunitTest_sw_ooxmlexport5 \
    CPPUNIT_TEST_NAME=testTdf157572_insidiousCombination

Change-Id: I6c00a34f14633e16178c1504a37e644a30cf4cd7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157529
Tested-by: Jenkins
Reviewed-by: Justin Luth <jluth@mail.com>
diff --git a/sw/qa/extras/ooxmlexport/data/tdf157572_insidiousCombination.docx b/sw/qa/extras/ooxmlexport/data/tdf157572_insidiousCombination.docx
new file mode 100644
index 0000000..d7437ae
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/tdf157572_insidiousCombination.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/data/tdf157572_noVAlignAsText.docx b/sw/qa/extras/ooxmlexport/data/tdf157572_noVAlignAsText.docx
new file mode 100644
index 0000000..98f1bb1
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/tdf157572_noVAlignAsText.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
index 2ee3e1e..d97fd7c 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
@@ -1440,6 +1440,34 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf157572_defaultVAnchor)
    assertXPathNoAttribute(pXmlDocument, "/w:document/w:body/w:p[1]/w:pPr/w:framePr", "yAlign");
}

CPPUNIT_TEST_FIXTURE(Test, testTdf157572_insidiousCombination)
{
    loadAndSave("tdf157572_insidiousCombination.docx");
    xmlDocUniquePtr pXmlDocument = parseExport("word/document.xml");

    // This is a NASTY example. In MS Word, it IMPORTS yAlign=bottom, but positions it as y=0.
    // although the UI shows "bottom" instead of position 0cm. Clicking -ok- MOVES the textbox.
    // Seems best to throw away "bottom" in LO, since a round-trip in MS Word keeps the 0cm
    // position and the vAlign ONLY affects the UI.

    // vAnchor was defined as text.
    assertXPath(pXmlDocument, "/w:document/w:body/w:p[1]/w:pPr/w:framePr","vAnchor","text");
    // yAlign=something is not compatible with "text" - don't write anything out
    assertXPathNoAttribute(pXmlDocument, "/w:document/w:body/w:p[1]/w:pPr/w:framePr", "yAlign");
    // y is zero - no need to write out the default value
    assertXPathNoAttribute(pXmlDocument, "/w:document/w:body/w:p[1]/w:pPr/w:framePr", "y");
}

CPPUNIT_TEST_FIXTURE(Test, testTdf157572_noVAlignAsText)
{
    loadAndSave("tdf157572_noVAlignAsText.docx");
    xmlDocUniquePtr pXmlDocument = parseExport("word/document.xml");

    assertXPath(pXmlDocument, "/w:document/w:body/w:p[1]/w:pPr/w:framePr","vAnchor","text");
    // yAlign=something is not compatible with vAnchor="text" - don't write anything out
    assertXPathNoAttribute(pXmlDocument, "/w:document/w:body/w:p[1]/w:pPr/w:framePr", "yAlign");
}

CPPUNIT_TEST_FIXTURE(Test, testTdf112287B)
{
    loadAndSave("tdf112287B.docx");
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 1b209d2..1444698 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -1051,13 +1051,15 @@ void DocxAttributeOutput::PopulateFrameProperties(const SwFrameFormat* pFrameFor

    attrList->add( FSNS( XML_w, XML_x), OString::number(aPos.X));

    const OString relativeFromH = convertToOOXMLHoriOrientRel(rHoriOrient.GetRelationOrient());
    const OString relativeFromV = convertToOOXMLVertOrientRel(rVertOrient.GetRelationOrient());
    OString aXAlign = convertToOOXMLHoriOrient(rHoriOrient.GetHoriOrient(), /*bIsPosToggle=*/false);
    OString aYAlign = convertToOOXMLVertOrient(rVertOrient.GetVertOrient());
    if (!aXAlign.isEmpty())
        attrList->add(FSNS(XML_w, XML_xAlign), aXAlign);
    if (!aYAlign.isEmpty())
    if (!aYAlign.isEmpty() && relativeFromV != "text")
        attrList->add(FSNS(XML_w, XML_yAlign), aYAlign);
    else
    else if (aPos.Y)
        attrList->add( FSNS( XML_w, XML_y), OString::number(aPos.Y));

    sal_Int16 nLeft = pFrameFormat->GetLRSpace().GetLeft();
@@ -1075,9 +1077,6 @@ void DocxAttributeOutput::PopulateFrameProperties(const SwFrameFormat* pFrameFor
    attrList->add(FSNS(XML_w, XML_hSpace), OString::number((nLeft + nRight) / 2));
    attrList->add(FSNS(XML_w, XML_vSpace), OString::number((nUpper + nLower) / 2));

    OString relativeFromH = convertToOOXMLHoriOrientRel(rHoriOrient.GetRelationOrient());
    OString relativeFromV = convertToOOXMLVertOrientRel(rVertOrient.GetRelationOrient());

    switch (pFrameFormat->GetSurround().GetValue())
    {
    case css::text::WrapTextMode_NONE:
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 77528bc..36a0f6c 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -1874,8 +1874,6 @@ DomainMapper_Impl::MakeFrameProperties(const ParagraphProperties& rProps)
                break;
            }
        }
        aFrameProperties.push_back(
            comphelper::makePropertyValue(getPropertyName(PROP_VERT_ORIENT), nVertOrient));

        // Default the anchor in case FramePr_vAnchor is missing.
        // ECMA 17.3.1.11 says "page",
@@ -1892,10 +1890,15 @@ DomainMapper_Impl::MakeFrameProperties(const ParagraphProperties& rProps)
            if (pProp->GetvAnchor() < 0)
                continue;
            nVAnchor = pProp->GetvAnchor();
            // vAlign is ignored if vAnchor is set to 'text'
            if (nVAnchor == text::RelOrientation::FRAME)
                nVertOrient = text::VertOrientation::NONE;
            break;
        }
        aFrameProperties.push_back(
            comphelper::makePropertyValue(getPropertyName(PROP_VERT_ORIENT_RELATION), nVAnchor));
        aFrameProperties.push_back(
            comphelper::makePropertyValue(getPropertyName(PROP_VERT_ORIENT), nVertOrient));

        text::WrapTextMode nWrap = text::WrapTextMode_NONE;
        for (const auto pProp : vProps)