From a6ec829055ab0b9d223979ae5f90d158d5549db1 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Mon, 8 Jan 2018 22:59:21 +0100 Subject: tdf#114703 DOCX import: apply num defaults only to abstract nums Numbering definitions have two levels: abstract ones and overrides. The full definition is a merge of the two. Make sure that when defaults are added to the numbering level properties, these are only added for abstract ones, otherwise overriding e.g. the start value of a level will also pull in other, unwanted default properties. Change-Id: If0273ebc6b49476df17b09d636489a3bfb717334 Reviewed-on: https://gerrit.libreoffice.org/47619 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- sw/qa/extras/ooxmlexport/data/tdf114703.docx | Bin 0 -> 26969 bytes sw/qa/extras/ooxmlexport/ooxmlexport11.cxx | 12 ++++++++++ writerfilter/source/dmapper/NumberingManager.cxx | 28 +++++++++++++---------- writerfilter/source/dmapper/NumberingManager.hxx | 8 +++---- 4 files changed, 32 insertions(+), 16 deletions(-) create mode 100644 sw/qa/extras/ooxmlexport/data/tdf114703.docx diff --git a/sw/qa/extras/ooxmlexport/data/tdf114703.docx b/sw/qa/extras/ooxmlexport/data/tdf114703.docx new file mode 100644 index 000000000000..116b56a2b42f Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf114703.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx index 46e31f89b6c8..fcb662e93286 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx @@ -202,6 +202,18 @@ DECLARE_OOXMLEXPORT_TEST(testTdf114882, "tdf114882.docx") // fastserializer must not fail assertion because of mismatching elements } +DECLARE_OOXMLEXPORT_TEST(testTdf114703, "tdf114703.docx") +{ + uno::Reference xRules + = getProperty>( + getStyles("NumberingStyles")->getByName("WWNum1"), "NumberingRules"); + // This was 0, level override "default" replaced the non-default value from + // the abstract level. + CPPUNIT_ASSERT_EQUAL( + static_cast(-1000), + comphelper::SequenceAsHashMap(xRules->getByIndex(0))["FirstLineIndent"].get()); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/NumberingManager.cxx b/writerfilter/source/dmapper/NumberingManager.cxx index 809717e62659..273501e6ccc6 100644 --- a/writerfilter/source/dmapper/NumberingManager.cxx +++ b/writerfilter/source/dmapper/NumberingManager.cxx @@ -191,9 +191,9 @@ sal_Int16 ListLevel::GetParentNumbering( const OUString& sText, sal_Int16 nLevel return nParentNumbering; } -uno::Sequence< beans::PropertyValue > ListLevel::GetProperties( ) +uno::Sequence ListLevel::GetProperties(bool bDefaults) { - uno::Sequence< beans::PropertyValue > aLevelProps = GetLevelProperties( ); + uno::Sequence aLevelProps = GetLevelProperties(bDefaults); if ( m_pParaStyle.get( ) ) AddParaProperties( &aLevelProps ); return aLevelProps; @@ -233,7 +233,7 @@ uno::Sequence< beans::PropertyValue > ListLevel::GetCharStyleProperties( ) return comphelper::containerToSequence(rProperties); } -uno::Sequence< beans::PropertyValue > ListLevel::GetLevelProperties( ) +uno::Sequence ListLevel::GetLevelProperties(bool bDefaults) { const sal_Int16 aWWToUnoAdjust[] = { @@ -286,7 +286,8 @@ uno::Sequence< beans::PropertyValue > ListLevel::GetLevelProperties( ) } } - aNumberingProperties.push_back(lcl_makePropVal(PROP_LISTTAB_STOP_POSITION, m_nTabstop)); + if (bDefaults || m_nTabstop != 0) + aNumberingProperties.push_back(lcl_makePropVal(PROP_LISTTAB_STOP_POSITION, m_nTabstop)); //TODO: handling of nFLegal? //TODO: nFNoRestart lower levels do not restart when higher levels are incremented, like: @@ -299,7 +300,8 @@ uno::Sequence< beans::PropertyValue > ListLevel::GetLevelProperties( ) // TODO: sRGBXchNums; array of inherited numbers // nXChFollow; following character 0 - tab, 1 - space, 2 - nothing - aNumberingProperties.push_back(lcl_makePropVal(PROP_LEVEL_FOLLOW, m_nXChFollow)); + if (bDefaults || m_nXChFollow != SvxNumberFormat::LISTTAB) + aNumberingProperties.push_back(lcl_makePropVal(PROP_LEVEL_FOLLOW, m_nXChFollow)); PropertyIds const aReadIds[] = { @@ -310,7 +312,7 @@ uno::Sequence< beans::PropertyValue > ListLevel::GetLevelProperties( ) boost::optional aProp = getProperty(rReadId); if (aProp) aNumberingProperties.emplace_back( getPropertyName(aProp->first), 0, aProp->second, beans::PropertyState_DIRECT_VALUE ); - else if (rReadId == PROP_FIRST_LINE_INDENT) + else if (rReadId == PROP_FIRST_LINE_INDENT && bDefaults) // Writer default is -360 twips, Word default seems to be 0. aNumberingProperties.emplace_back("FirstLineIndent", 0, uno::makeAny(static_cast(0)), beans::PropertyState_DIRECT_VALUE); } @@ -424,7 +426,7 @@ void AbstractListDef::AddLevel( ) m_aLevels.push_back( pLevel ); } -uno::Sequence< uno::Sequence< beans::PropertyValue > > AbstractListDef::GetPropertyValues( ) +uno::Sequence> AbstractListDef::GetPropertyValues(bool bDefaults) { uno::Sequence< uno::Sequence< beans::PropertyValue > > result( sal_Int32( m_aLevels.size( ) ) ); uno::Sequence< beans::PropertyValue >* aResult = result.getArray( ); @@ -432,7 +434,7 @@ uno::Sequence< uno::Sequence< beans::PropertyValue > > AbstractListDef::GetPrope int nLevels = m_aLevels.size( ); for ( int i = 0; i < nLevels; i++ ) { - aResult[i] = m_aLevels[i]->GetProperties( ); + aResult[i] = m_aLevels[i]->GetProperties(bDefaults); } return result; @@ -456,16 +458,18 @@ OUString ListDef::GetStyleName( sal_Int32 nId ) return sStyleName; } -uno::Sequence< uno::Sequence< beans::PropertyValue > > ListDef::GetPropertyValues( ) +uno::Sequence> ListDef::GetMergedPropertyValues() { if (!m_pAbstractDef) return uno::Sequence< uno::Sequence< beans::PropertyValue > >(); // [1] Call the same method on the abstract list - uno::Sequence< uno::Sequence< beans::PropertyValue > > aAbstract = m_pAbstractDef->GetPropertyValues( ); + uno::Sequence> aAbstract + = m_pAbstractDef->GetPropertyValues(/*bDefaults=*/true); // [2] Call the upper class method - uno::Sequence< uno::Sequence< beans::PropertyValue > > aThis = AbstractListDef::GetPropertyValues( ); + uno::Sequence> aThis + = AbstractListDef::GetPropertyValues(/*bDefaults=*/false); // Merge the results of [2] in [1] sal_Int32 nThisCount = aThis.getLength( ); @@ -529,7 +533,7 @@ void ListDef::CreateNumberingRules( DomainMapper& rDMapper, uno::Any aRules = xStyle->getPropertyValue( getPropertyName( PROP_NUMBERING_RULES ) ); aRules >>= m_xNumRules; - uno::Sequence< uno::Sequence< beans::PropertyValue > > aProps = GetPropertyValues( ); + uno::Sequence> aProps = GetMergedPropertyValues(); sal_Int32 nAbstLevels = m_pAbstractDef ? m_pAbstractDef->Size() : 0; sal_Int32 nLevel = 0; diff --git a/writerfilter/source/dmapper/NumberingManager.hxx b/writerfilter/source/dmapper/NumberingManager.hxx index eabf4a0276c6..339e6d491757 100644 --- a/writerfilter/source/dmapper/NumberingManager.hxx +++ b/writerfilter/source/dmapper/NumberingManager.hxx @@ -90,12 +90,12 @@ public: static sal_Int16 GetParentNumbering( const OUString& sText, sal_Int16 nLevel, OUString& rPrefix, OUString& rSuffix ); - css::uno::Sequence GetProperties(); + css::uno::Sequence GetProperties(bool bDefaults); css::uno::Sequence GetCharStyleProperties(); private: - css::uno::Sequence GetLevelProperties(); + css::uno::Sequence GetLevelProperties(bool bDefaults); void AddParaProperties(css::uno::Sequence* pProps); }; @@ -153,7 +153,7 @@ public: const ListLevel::Pointer& GetCurrentLevel( ) { return m_pCurrentLevel; }; - virtual css::uno::Sequence< css::uno::Sequence > GetPropertyValues(); + css::uno::Sequence< css::uno::Sequence > GetPropertyValues(bool bDefaults); void SetNumStyleLink(const OUString& sValue) { m_sNumStyleLink = sValue; }; const OUString& GetNumStyleLink() { return m_sNumStyleLink; }; @@ -181,7 +181,7 @@ public: // Mapping functions static OUString GetStyleName( sal_Int32 nId ); - css::uno::Sequence< css::uno::Sequence > GetPropertyValues() override; + css::uno::Sequence< css::uno::Sequence > GetMergedPropertyValues(); void CreateNumberingRules(DomainMapper& rDMapper, css::uno::Reference const& xFactory); -- cgit v1.2.3