Kaydet (Commit) 8fd13c35 authored tarafından Justin Luth's avatar Justin Luth Kaydeden (comit) Miklos Vajna

ooxmlimport: support inherited listid

This is prep work for tdf#95377. This unit test avoids the unique
chapter-numbering style (from the heading paragraph styles) and just
has a basic, user-created style inheriting from Default.

Also unique about this unit test is that the numbering is
specified by the "Default Style" which takes a rather unique
code path and exposes even more problems.

We already know the listId through a recursive function, and
GetCurrentNumberingRules only looks at the current style which
isn't good enough. Moved that modified function into
DomainMapper_Impl since I will need it there for bug 95377.

Additionally, ensure that directly applied paragraph properties
are not overwritten. That also meant changing the order, so that
paraStyle properties are directly applied to the paragraph before
applying RightMargin and friends.

Change-Id: I5c1fb71d64727be9d9105f287150daf4e0ff413d
Reviewed-on: https://gerrit.libreoffice.org/48457Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarJustin Luth <justin_luth@sil.org>
Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst f82434b5
......@@ -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);
......
......@@ -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 )
......
......@@ -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;
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment