From 8f48f91009caa86d896f247059874242ed18bf39 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Thu, 10 Mar 2022 16:29:48 +0100 Subject: ODT export: omit unreferenced This attribute is needed when a numbering is built using multiple, independent elements. In that case the markup to connect these are either: ... In case there is no other list in-between, or: ... In case there are other lists in-between. This means that at least in case all the text nodes of the numbering are after each other, then the random value in xml:id="..." is never referenced, so it can be omitted. This helps deterministic ODF output when the input is HTML, where there are never text:continue-list="..." attributes that would refer to these xml:id="..." attributes. Change-Id: Ice69422a12d4229879f89f3a4a24ed926c6d43af Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131322 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- xmloff/qa/unit/data/list-id.fodt | 23 +++++++++++++++++++++++ xmloff/qa/unit/text.cxx | 24 ++++++++++++++++++++++++ xmloff/source/text/XMLTextNumRuleInfo.cxx | 11 ++++++++++- xmloff/source/text/XMLTextNumRuleInfo.hxx | 4 ++++ xmloff/source/text/txtparae.cxx | 4 ++-- 5 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 xmloff/qa/unit/data/list-id.fodt (limited to 'xmloff') diff --git a/xmloff/qa/unit/data/list-id.fodt b/xmloff/qa/unit/data/list-id.fodt new file mode 100644 index 000000000000..377dbcbd6473 --- /dev/null +++ b/xmloff/qa/unit/data/list-id.fodt @@ -0,0 +1,23 @@ + + + + + + + + + + + + First + + + Second + + + Third + + + + + diff --git a/xmloff/qa/unit/text.cxx b/xmloff/qa/unit/text.cxx index 1d239e2e0c09..71772edb3585 100644 --- a/xmloff/qa/unit/text.cxx +++ b/xmloff/qa/unit/text.cxx @@ -245,6 +245,30 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testContinueNumberingWord) CPPUNIT_ASSERT_EQUAL(OUString("2."), aActual); } +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testListId) +{ + // Given a document with a simple list (no continue-list="..." attribute): + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "list-id.fodt"; + getComponent() = loadFromDesktop(aURL); + + // When storing that document as ODF: + uno::Reference xStorable(getComponent(), uno::UNO_QUERY); + uno::Sequence aStoreProps = comphelper::InitPropertySequence({ + { "FilterName", uno::makeAny(OUString("writer8")) }, + }); + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + xStorable->storeToURL(aTempFile.GetURL(), aStoreProps); + + // Then make sure that unreferenced xml:id="..." attributes are not written: + std::unique_ptr pStream = parseExportStream(aTempFile, "content.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + // Without the accompanying fix in place, this failed with: + // - XPath '//text:list' unexpected 'id' attribute + // i.e. xml:id="..." was written unconditionally, even when no other list needed it. + assertXPathNoAttribute(pXmlDoc, "//text:list", "id"); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/text/XMLTextNumRuleInfo.cxx b/xmloff/source/text/XMLTextNumRuleInfo.cxx index c6889abbbc9e..062b92879ee2 100644 --- a/xmloff/source/text/XMLTextNumRuleInfo.cxx +++ b/xmloff/source/text/XMLTextNumRuleInfo.cxx @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -37,7 +38,8 @@ using namespace ::com::sun::star::style; // Complete refactoring of the class and enhancement of the class for lists. XMLTextNumRuleInfo::XMLTextNumRuleInfo() - : mnListStartValue( -1 ) + : mbListIdIsDefault(false) + , mnListStartValue( -1 ) , mnListLevel( 0 ) , mbIsNumbered( false ) , mbIsRestart( false ) @@ -59,6 +61,7 @@ void XMLTextNumRuleInfo::Set( mbOutlineStyleAsNormalListStyle = bOutlineStyleAsNormalListStyle; Reference< XPropertySet > xPropSet( xTextContent, UNO_QUERY ); + Reference xPropState(xTextContent, UNO_QUERY); Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo(); // check if this paragraph supports a numbering @@ -135,6 +138,12 @@ void XMLTextNumRuleInfo::Set( if( xPropSetInfo->hasPropertyByName( "ListId" ) ) { xPropSet->getPropertyValue( "ListId" ) >>= msListId; + + if (xPropState.is()) + { + mbListIdIsDefault + = xPropState->getPropertyState("ListId") == PropertyState_DEFAULT_VALUE; + } } mbContinueingPreviousSubTree = false; diff --git a/xmloff/source/text/XMLTextNumRuleInfo.hxx b/xmloff/source/text/XMLTextNumRuleInfo.hxx index 53ad8e97f188..adb405411164 100644 --- a/xmloff/source/text/XMLTextNumRuleInfo.hxx +++ b/xmloff/source/text/XMLTextNumRuleInfo.hxx @@ -43,6 +43,8 @@ class XMLTextNumRuleInfo // paragraph's list attributes OUString msListId; + /// msListId won't be referenced by later lists. + bool mbListIdIsDefault; sal_Int16 mnListStartValue; sal_Int16 mnListLevel; bool mbIsNumbered; @@ -83,6 +85,8 @@ public: return msListId; } + bool IsListIdDefault() const { return mbListIdIsDefault; } + sal_Int16 GetLevel() const { return mnListLevel; diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx index 732c119cdb58..f8e46fb71844 100644 --- a/xmloff/source/text/txtparae.cxx +++ b/xmloff/source/text/txtparae.cxx @@ -932,7 +932,7 @@ void XMLTextParagraphExport::exportListChange( { if ( bExportODF && eODFDefaultVersion >= SvtSaveOptions::ODFSVER_012 && - !sListId.isEmpty() ) + !sListId.isEmpty() && !rNextInfo.IsListIdDefault() ) { /* Property text:id at element has to be replaced by property xml:id (#i92221#) @@ -951,7 +951,7 @@ void XMLTextParagraphExport::exportListChange( mpTextListsHelper->GenerateNewListId() ); if ( bExportODF && eODFDefaultVersion >= SvtSaveOptions::ODFSVER_012 && - !sListId.isEmpty() ) + !sListId.isEmpty() && !rNextInfo.IsListIdDefault() ) { /* Property text:id at element has to be replaced by property xml:id (#i92221#) -- cgit