tdf#103961 writerfilter: parentless styles need pPrDefault(s)

It is possible for paragraph styles to be based on -none-.
In those cases, the DocDefaults must be applied.

Change-Id: I5b3458384c6473f3aaf64e5f274372d291ff824d
Reviewed-on: https://gerrit.libreoffice.org/57371
Tested-by: Jenkins
Reviewed-by: Justin Luth <justin_luth@sil.org>
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
diff --git a/sw/qa/extras/ooxmlexport/data/tdf117504_numberingIndent.docx b/sw/qa/extras/ooxmlexport/data/tdf117504_numberingIndent.docx
index 0917189..d86b0b4 100644
--- a/sw/qa/extras/ooxmlexport/data/tdf117504_numberingIndent.docx
+++ b/sw/qa/extras/ooxmlexport/data/tdf117504_numberingIndent.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx
index 852e631..d45284d 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx
@@ -727,6 +727,12 @@ DECLARE_OOXMLEXPORT_TEST(testTdf117504_numberingIndent, "tdf117504_numberingInde
{
    OUString sName = getProperty<OUString>(getParagraph(1), "NumberingStyleName");
    CPPUNIT_ASSERT_MESSAGE("Paragraph has numbering style", !sName.isEmpty());

    uno::Reference<beans::XPropertySet> xPropertySet(
        getStyles("ParagraphStyles")->getByName("Revision"), uno::UNO_QUERY);
    CPPUNIT_ASSERT_EQUAL(sal_Int32(353), getProperty<sal_Int32>(xPropertySet, "ParaBottomMargin"));
    xPropertySet.set(getStyles("ParagraphStyles")->getByName("Body Note"), uno::UNO_QUERY);
    CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xPropertySet, "ParaBottomMargin"));
}

DECLARE_OOXMLEXPORT_TEST(testWatermark, "watermark.docx")
diff --git a/writerfilter/source/dmapper/PropertyMap.cxx b/writerfilter/source/dmapper/PropertyMap.cxx
index a24ae3d..46b8462 100644
--- a/writerfilter/source/dmapper/PropertyMap.cxx
+++ b/writerfilter/source/dmapper/PropertyMap.cxx
@@ -317,20 +317,23 @@ void PropertyMap::dumpXml() const
}
#endif

void PropertyMap::InsertProps( const PropertyMapPtr& rMap )
void PropertyMap::InsertProps( const PropertyMapPtr& rMap, const bool bOverwrite )
{
    if ( rMap )
    {
        for ( const auto& rPropPair : rMap->m_vMap )
            m_vMap[rPropPair.first] = rPropPair.second;
        {
            if ( bOverwrite || !m_vMap.count(rPropPair.first) )
                m_vMap[rPropPair.first] = rPropPair.second;
        }

        insertTableProperties( rMap.get() );
        insertTableProperties( rMap.get(), bOverwrite );

        Invalidate();
    }
}

void PropertyMap::insertTableProperties( const PropertyMap* )
void PropertyMap::insertTableProperties( const PropertyMap*, const bool )
{
#ifdef DEBUG_WRITERFILTER
    TagLogger::getInstance().element( "PropertyMap.insertTableProperties" );
@@ -1825,7 +1828,7 @@ void TablePropertyMap::setValue( TablePropertyMapTarget eWhich, sal_Int32 nSet )
        OSL_FAIL( "invalid TablePropertyMapTarget" );
}

void TablePropertyMap::insertTableProperties( const PropertyMap* pMap )
void TablePropertyMap::insertTableProperties( const PropertyMap* pMap, const bool bOverwrite )
{
#ifdef DEBUG_WRITERFILTER
    TagLogger::getInstance().startElement( "TablePropertyMap.insertTableProperties" );
@@ -1838,7 +1841,7 @@ void TablePropertyMap::insertTableProperties( const PropertyMap* pMap )
        for ( sal_Int32 eTarget = TablePropertyMapTarget_START;
            eTarget < TablePropertyMapTarget_MAX; ++eTarget )
        {
            if ( pSource->m_aValidValues[eTarget].bValid )
            if ( pSource->m_aValidValues[eTarget].bValid && (bOverwrite || !m_aValidValues[eTarget].bValid) )
            {
                m_aValidValues[eTarget].bValid = true;
                m_aValidValues[eTarget].nValue = pSource->m_aValidValues[eTarget].nValue;
diff --git a/writerfilter/source/dmapper/PropertyMap.hxx b/writerfilter/source/dmapper/PropertyMap.hxx
index c20951c..91e182d 100644
--- a/writerfilter/source/dmapper/PropertyMap.hxx
+++ b/writerfilter/source/dmapper/PropertyMap.hxx
@@ -141,8 +141,8 @@ public:
    // Remove a named property from *this, does nothing if the property id has not been set
    void Erase( PropertyIds eId);

    // Imports properties from pMap, overwriting those with the same PropertyIds as the current map
    void InsertProps( const tools::SvRef< PropertyMap >& rMap );
    // Imports properties from pMap
    void InsertProps( const tools::SvRef< PropertyMap >& rMap, const bool bOverwrite = true );

    // Returns a copy of the property if it exists, .first is its PropertyIds and .second is its Value (type css::uno::Any)
    boost::optional< Property > getProperty( PropertyIds eId ) const;
@@ -154,7 +154,7 @@ public:

    void SetFootnote( const css::uno::Reference< css::text::XFootnote >& xF ) { m_xFootnote = xF; }

    virtual void insertTableProperties( const PropertyMap* );
    virtual void insertTableProperties( const PropertyMap*, const bool bOverwrite = true );

    const std::vector< RedlineParamsPtr >& Redlines() const { return m_aRedlines; }

@@ -557,7 +557,7 @@ public:
    bool getValue( TablePropertyMapTarget eWhich, sal_Int32& nFill );
    void setValue( TablePropertyMapTarget eWhich, sal_Int32 nSet );

    virtual void insertTableProperties( const PropertyMap* ) override;
    virtual void insertTableProperties( const PropertyMap*, const bool bOverwrite = true ) override;
};

typedef tools::SvRef< TablePropertyMap > TablePropertyMapPtr;
diff --git a/writerfilter/source/dmapper/StyleSheetTable.cxx b/writerfilter/source/dmapper/StyleSheetTable.cxx
index ad1aa6e..4780cee 100644
--- a/writerfilter/source/dmapper/StyleSheetTable.cxx
+++ b/writerfilter/source/dmapper/StyleSheetTable.cxx
@@ -994,6 +994,10 @@ void StyleSheetTable::ApplyStyleSheets( const FontTablePtr& rFontTable )
                    }
                    else if( bParaStyle )
                    {
                        // Paragraph styles that don't inherit from some parent need to apply the DocDefaults
                        if ( sConvertedStyleName != "Standard" )
                            pEntry->pProperties->InsertProps( m_pImpl->m_pDefaultParaProps, /*bAllowOverwrite=*/false );

                        //now it's time to set the default parameters - for paragraph styles
                        //Fonts: Western first entry in font table
                        //CJK: second entry