tdf#136617 DOCX import: fix empty table paragraphs with direct formatting

Table paragraph styles applied on paragraphs without runs, i.e.
on empty paragraphs, despite their direct formatting, resulting
e.g. different font size, and after that different paragraph
i.e. cell height, breaking the original table layout.

Regression from commit bf3124cdf61b40c94ba117a76f1b63dabdfd528e
"tdf#135187 DOCX import: fix table style at character formatting".

Also clean-up commit 498d2b82187ec3ff58f076e0d15741e64c0505ba
"tdf#131546 DOCX import: fix performance regression at tables".

Change-Id: I41f8da61d49902c8c1683bd01632cce6d58aebd9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141052
Tested-by: Jenkins
Reviewed-by: László Németh <nemeth@numbertext.org>
diff --git a/sw/qa/extras/ooxmlexport/data/tdf136617.docx b/sw/qa/extras/ooxmlexport/data/tdf136617.docx
new file mode 100644
index 0000000..e7b35aa
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/tdf136617.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx
index 586f36e..7bead3a 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx
@@ -1874,6 +1874,18 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf135187)
                "false");
}

CPPUNIT_TEST_FIXTURE(Test, testTdf136617)
{
    loadAndSave("tdf136617.docx");

    // This was 2
    CPPUNIT_ASSERT_EQUAL(1, getPages());

    xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
    assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[2]/w:p[2]/w:pPr/w:rPr/w:sz", "val",
                "16");
}

CPPUNIT_TEST_FIXTURE(Test, testTdf121597TrackedDeletionOfMultipleParagraphs)
{
    loadAndSave("tdf121597.odt");
diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
index cc9f9ad..2e96226 100644
--- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
+++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
@@ -1112,14 +1112,6 @@ void DomainMapperTableHandler::ApplyParagraphPropertiesFromTableStyle(TableParag

            OUString sPropertyName = getPropertyName(eId);

            if ( bIsParaLevel && ( rParaProp.m_aParaOverrideApplied.find(sPropertyName) != rParaProp.m_aParaOverrideApplied.end() ||
                sPropertyName.startsWith("CharFontName") ) )
            {
                // don't apply table style, if this character property was applied on paragraph level
                // (or in the case of paragraph level font name settings to avoid regressions)
                continue;
            }

            auto pCellProp = std::find_if(rCellProperties.begin(), rCellProperties.end(),
                [&](const beans::PropertyValue& rProp) { return rProp.Name == sPropertyName; });
            // this cell applies the table style property
@@ -1179,6 +1171,10 @@ void DomainMapperTableHandler::ApplyParagraphPropertiesFromTableStyle(TableParag
                    uno::Reference< beans::XPropertyState > xParaProperties( xParagraph, uno::UNO_QUERY_THROW );
                    if ( xParaProperties->getPropertyState(sPropertyName) == css::beans::PropertyState_DEFAULT_VALUE )
                    {
                        // don't overwrite empty paragraph with table style, if it has a direct paragraph formatting
                        if ( bIsParaLevel && xParagraph->getString().getLength() == 0 )
                            continue;

                        if ( eId != PROP_FILL_COLOR )
                        {
                            // apply style setting when the paragraph doesn't modify it
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 191b7fe..dc42f01 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -2462,7 +2462,7 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con
                    xParaCursor->gotoStartOfParagraph(false);
                    if (m_nTableDepth > 0)
                    {
                        TableParagraph aPending{xParaCursor, xCur, pParaContext, xParaProps, std::set<OUString>()};
                        TableParagraph aPending{xParaCursor, xCur, pParaContext, xParaProps};
                        getTableManager().getCurrentParagraphs()->push_back(aPending);
                    }

diff --git a/writerfilter/source/dmapper/PropertyMap.hxx b/writerfilter/source/dmapper/PropertyMap.hxx
index 0678440..701546e 100644
--- a/writerfilter/source/dmapper/PropertyMap.hxx
+++ b/writerfilter/source/dmapper/PropertyMap.hxx
@@ -606,7 +606,6 @@ struct TableParagraph
    css::uno::Reference<css::text::XTextRange> m_rEndParagraph;
    PropertyMapPtr m_pPropertyMap;
    css::uno::Reference<css::beans::XPropertySet> m_rPropertySet;
    std::set<OUString> m_aParaOverrideApplied;
};

typedef std::shared_ptr< std::vector<TableParagraph> > TableParagraphVectorPtr;