diff options
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/tdf95377.docx | bin | 0 -> 11982 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport10.cxx | 16 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper.cxx | 61 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.cxx | 42 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.hxx | 1 |
5 files changed, 74 insertions, 46 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/tdf95377.docx b/sw/qa/extras/ooxmlexport/data/tdf95377.docx Binary files differnew file mode 100644 index 000000000000..be5551dca282 --- /dev/null +++ b/sw/qa/extras/ooxmlexport/data/tdf95377.docx diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx index e5af806f373b..9128303db319 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx @@ -907,6 +907,22 @@ DECLARE_OOXMLEXPORT_TEST(testTdf92454, "tdf92454.docx") CPPUNIT_ASSERT_EQUAL(beans::PropertyState_DIRECT_VALUE, xParagraph->getPropertyState("ParaFirstLineIndent")); } +DECLARE_OOXMLEXPORT_TEST(testTdf95377, "tdf95377.docx") +{ + uno::Reference<beans::XPropertyState> xParagraph(getParagraph(1), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1000), getProperty<sal_Int32>(xParagraph, "ParaRightMargin")); + + xParagraph.set(getParagraph(2), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(-501), getProperty<sal_Int32>(xParagraph, "ParaFirstLineIndent")); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2501), getProperty<sal_Int32>(xParagraph, "ParaLeftMargin")); + CPPUNIT_ASSERT_EQUAL(beans::PropertyState_DIRECT_VALUE, xParagraph->getPropertyState("ParaFirstLineIndent")); + + xParagraph.set(getParagraph(3), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(-250), getProperty<sal_Int32>(xParagraph, "ParaFirstLineIndent")); + CPPUNIT_ASSERT_EQUAL(sal_Int32(250), getProperty<sal_Int32>(xParagraph, "ParaLeftMargin")); + CPPUNIT_ASSERT_EQUAL(beans::PropertyState_DIRECT_VALUE, xParagraph->getPropertyState("ParaFirstLineIndent")); +} + DECLARE_OOXMLEXPORT_TEST(testTdf95376, "tdf95376.docx") { uno::Reference<beans::XPropertyState> xParagraph(getParagraph(2), uno::UNO_QUERY); diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx index 35693db196ec..9acb00fb86ae 100644 --- a/writerfilter/source/dmapper/DomainMapper.cxx +++ b/writerfilter/source/dmapper/DomainMapper.cxx @@ -1165,40 +1165,6 @@ void DomainMapper::lcl_sprm(Sprm & rSprm) sprmWithProps(rSprm, m_pImpl->GetTopContext()); } -sal_Int32 lcl_getCurrentNumberingProperty( - uno::Reference<container::XIndexAccess> const& xNumberingRules, - sal_Int32 nNumberingLevel, const OUString& aProp) -{ - sal_Int32 nRet = 0; - - try - { - if (nNumberingLevel < 0) // It seems it's valid to omit numbering level, and in that case it means zero. - nNumberingLevel = 0; - if (xNumberingRules.is()) - { - uno::Sequence<beans::PropertyValue> aProps; - xNumberingRules->getByIndex(nNumberingLevel) >>= aProps; - for (int i = 0; i < aProps.getLength(); ++i) - { - const beans::PropertyValue& rProp = aProps[i]; - - if (rProp.Name == aProp) - { - rProp.Value >>= nRet; - break; - } - } - } - } - catch( const uno::Exception& ) - { - // This can happen when the doc contains some hand-crafted invalid list level. - } - - return nRet; -} - // In rtl-paragraphs the meaning of left/right are to be exchanged static bool ExchangeLeftRight(const PropertyMapPtr& rContext, DomainMapper_Impl& rImpl) { @@ -2169,6 +2135,16 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, const PropertyMapPtr& rContext ) if ( !pEntry->bIsChapterNumbering ) rContext->Insert( PROP_NUMBERING_STYLE_NAME, uno::makeAny( ListDef::GetStyleName( nListId ) ), false); + // Indent properties from the paragraph style have priority + // over the ones from the numbering styles in Word + // but in Writer numbering styles have priority, + // so insert directly into the paragraph properties to compensate. + boost::optional<PropertyMap::Property> oProperty; + if ( (oProperty = pStyleSheetProperties->getProperty(PROP_PARA_FIRST_LINE_INDENT)) ) + rContext->Insert(PROP_PARA_FIRST_LINE_INDENT, oProperty->second, /*bOverwrite=*/false); + if ( (oProperty = pStyleSheetProperties->getProperty(PROP_PARA_LEFT_MARGIN)) ) + rContext->Insert(PROP_PARA_LEFT_MARGIN, oProperty->second, /*bOverwrite=*/false); + // We're inheriting properties from a numbering style. Make sure a possible right margin is inherited from the base style. sal_Int32 nParaRightMargin = 0; if (!pEntry->sBaseStyleIdentifier.isEmpty()) @@ -2182,22 +2158,15 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, const PropertyMapPtr& rContext ) if (nParaRightMargin != 0) { // If we're setting the right margin, we should set the first / left margin as well from the numbering style. - sal_Int32 nFirstLineIndent = lcl_getCurrentNumberingProperty(m_pImpl->GetCurrentNumberingRules(), pStyleSheetProperties->GetListLevel(), "FirstLineIndent"); - sal_Int32 nParaLeftMargin = lcl_getCurrentNumberingProperty(m_pImpl->GetCurrentNumberingRules(), pStyleSheetProperties->GetListLevel(), "IndentAt"); + const sal_Int32 nFirstLineIndent = m_pImpl->getNumberingProperty(nListId, pStyleSheetProperties->GetListLevel(), "FirstLineIndent"); + const sal_Int32 nParaLeftMargin = m_pImpl->getNumberingProperty(nListId, pStyleSheetProperties->GetListLevel(), "IndentAt"); if (nFirstLineIndent != 0) - rContext->Insert(PROP_PARA_FIRST_LINE_INDENT, uno::makeAny(nFirstLineIndent)); + rContext->Insert(PROP_PARA_FIRST_LINE_INDENT, uno::makeAny(nFirstLineIndent), /*bOverwrite=*/false); if (nParaLeftMargin != 0) - rContext->Insert(PROP_PARA_LEFT_MARGIN, uno::makeAny(nParaLeftMargin)); + rContext->Insert(PROP_PARA_LEFT_MARGIN, uno::makeAny(nParaLeftMargin), /*bOverwrite=*/false); - rContext->Insert(PROP_PARA_RIGHT_MARGIN, uno::makeAny(nParaRightMargin)); + rContext->Insert(PROP_PARA_RIGHT_MARGIN, uno::makeAny(nParaRightMargin), /*bOverwrite=*/false); } - - // Indent properties from the paragraph style have priority - // over the ones from the numbering styles in Word, not in - // Writer. - boost::optional<PropertyMap::Property> oProperty; - if (pStyleSheetProperties && (oProperty = pStyleSheetProperties->getProperty(PROP_PARA_FIRST_LINE_INDENT))) - rContext->Insert(PROP_PARA_FIRST_LINE_INDENT, oProperty->second); } if( pStyleSheetProperties && pStyleSheetProperties->GetListLevel() >= 0 ) diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index c66b087eca67..823fc605cddb 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -5533,6 +5533,48 @@ void DomainMapper_Impl::processDeferredCharacterProperties() } } +sal_Int32 DomainMapper_Impl::getNumberingProperty(const sal_Int32 nListId, sal_Int32 nNumberingLevel, const OUString& aProp) +{ + sal_Int32 nRet = 0; + if ( nListId < 0 ) + return nRet; + + try + { + if (nNumberingLevel < 0) // It seems it's valid to omit numbering level, and in that case it means zero. + nNumberingLevel = 0; + + const OUString aListName = ListDef::GetStyleName(nListId); + const uno::Reference< style::XStyleFamiliesSupplier > xStylesSupplier(GetTextDocument(), uno::UNO_QUERY_THROW); + const uno::Reference< container::XNameAccess > xStyleFamilies = xStylesSupplier->getStyleFamilies(); + uno::Reference<container::XNameAccess> xNumberingStyles; + xStyleFamilies->getByName("NumberingStyles") >>= xNumberingStyles; + const uno::Reference<beans::XPropertySet> xStyle(xNumberingStyles->getByName(aListName), uno::UNO_QUERY); + const uno::Reference<container::XIndexAccess> xNumberingRules(xStyle->getPropertyValue("NumberingRules"), uno::UNO_QUERY); + if (xNumberingRules.is()) + { + uno::Sequence<beans::PropertyValue> aProps; + xNumberingRules->getByIndex(nNumberingLevel) >>= aProps; + for (int i = 0; i < aProps.getLength(); ++i) + { + const beans::PropertyValue& rProp = aProps[i]; + + if (rProp.Name == aProp) + { + rProp.Value >>= nRet; + break; + } + } + } + } + catch( const uno::Exception& ) + { + // This can happen when the doc contains some hand-crafted invalid list level. + } + + return nRet; +} + sal_Int32 DomainMapper_Impl::getCurrentNumberingProperty(const OUString& aProp) { sal_Int32 nRet = 0; diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx index db2ec50de9b5..0d7a693e83f8 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx @@ -873,6 +873,7 @@ public: */ void processDeferredCharacterProperties(); + sal_Int32 getNumberingProperty(const sal_Int32 nListId, sal_Int32 nListLevel, const OUString& aProp); /// Get a property of the current numbering style's current level. sal_Int32 getCurrentNumberingProperty(const OUString& aProp); |