[Libreoffice-commits] core.git: include/xmloff xmloff/qa xmloff/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Thu Sep 2 17:24:51 UTC 2021


 include/xmloff/txtstyli.hxx                    |    6 ++++++
 xmloff/qa/unit/data/para-style-list-level.fodt |   14 ++++++++++++++
 xmloff/qa/unit/text.cxx                        |   22 ++++++++++++++++++++++
 xmloff/source/text/txtstyli.cxx                |   14 ++++++++++++++
 4 files changed, 56 insertions(+)

New commits:
commit 6d9b61c22a5b4372bf5592556d21c8417ed22bfa
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Thu Sep 2 16:39:26 2021 +0200
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Thu Sep 2 19:24:16 2021 +0200

    Related: tdf#137363 ODT import: handle style:list-level="..." for para styles
    
    This is just the import side, the export side still needs doing.
    
    The used attribute was already part of ODF, and NumberingLevel for para
    styles where already imported/exported for DOCX.
    
    Change-Id: I8385ed23dc799c99e81318387236341b404d01a7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121515
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
    Tested-by: Jenkins

diff --git a/include/xmloff/txtstyli.hxx b/include/xmloff/txtstyli.hxx
index 27e9f6dd5b15..aa5627c0e608 100644
--- a/include/xmloff/txtstyli.hxx
+++ b/include/xmloff/txtstyli.hxx
@@ -20,6 +20,9 @@
 #define INCLUDED_XMLOFF_TXTSTYLI_HXX
 
 #include <sal/config.h>
+
+#include <optional>
+
 #include <xmloff/dllapi.h>
 #include <xmloff/prstylei.hxx>
 
@@ -45,6 +48,9 @@ class XMLOFF_DLLPUBLIC XMLTextStyleContext : public XMLPropStyleContext
 
     rtl::Reference<XMLEventsImportContext> m_xEventContext;
 
+    /// Reads <style:style style:list-level="...">.
+    std::optional<sal_Int16> m_aListLevel;
+
 protected:
 
     virtual void SetAttribute( sal_Int32 nElement,
diff --git a/xmloff/qa/unit/data/para-style-list-level.fodt b/xmloff/qa/unit/data/para-style-list-level.fodt
new file mode 100644
index 000000000000..88f96e349ee2
--- /dev/null
+++ b/xmloff/qa/unit/data/para-style-list-level.fodt
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<office:document xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
+  <office:styles>
+    <style:style style:name="mystyle" style:family="paragraph" style:list-style-name="WWNum1" style:list-level="2"/>
+    <text:list-style style:name="mylist">
+    </text:list-style>
+  </office:styles>
+  <office:master-styles/>
+  <office:body>
+    <office:text>
+      <text:p/>
+    </office:text>
+  </office:body>
+</office:document>
diff --git a/xmloff/qa/unit/text.cxx b/xmloff/qa/unit/text.cxx
index 9a177099b8a3..79acb8cb08bf 100644
--- a/xmloff/qa/unit/text.cxx
+++ b/xmloff/qa/unit/text.cxx
@@ -15,6 +15,7 @@
 #include <com/sun/star/frame/XStorable.hpp>
 #include <com/sun/star/text/XTextDocument.hpp>
 #include <com/sun/star/text/BibliographyDataType.hpp>
+#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
 
 #include <comphelper/propertysequence.hxx>
 #include <comphelper/propertyvalue.hxx>
@@ -161,6 +162,27 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testCommentTableBorder)
     getComponent() = loadFromDesktop(aURL);
 }
 
+CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testParaStyleListLevel)
+{
+    // Given a document with style:list-level="...":
+    OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "para-style-list-level.fodt";
+
+    // When loading that document:
+    getComponent() = loadFromDesktop(aURL);
+
+    // Then make sure we map that to the paragraph style's numbering level:
+    uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(getComponent(),
+                                                                         uno::UNO_QUERY);
+    uno::Reference<container::XNameAccess> xStyleFamilies
+        = xStyleFamiliesSupplier->getStyleFamilies();
+    uno::Reference<container::XNameAccess> xStyleFamily(
+        xStyleFamilies->getByName("ParagraphStyles"), uno::UNO_QUERY);
+    uno::Reference<beans::XPropertySet> xStyle(xStyleFamily->getByName("mystyle"), uno::UNO_QUERY);
+    sal_Int16 nNumberingLevel{};
+    CPPUNIT_ASSERT(xStyle->getPropertyValue("NumberingLevel") >>= nNumberingLevel);
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(2), nNumberingLevel);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/text/txtstyli.cxx b/xmloff/source/text/txtstyli.cxx
index 5aa600c25c00..bcd55b140868 100644
--- a/xmloff/source/text/txtstyli.cxx
+++ b/xmloff/source/text/txtstyli.cxx
@@ -115,6 +115,15 @@ void XMLTextStyleContext::SetAttribute( sal_Int32 nElement,
             }
             break;
         }
+        case XML_ELEMENT(STYLE, XML_LIST_LEVEL):
+        {
+            sal_Int32 nTmp;
+            if (sax::Converter::convertNumber(nTmp, rValue) && nTmp >= 0 && nTmp <= 10)
+            {
+                m_aListLevel.emplace(nTmp);
+            }
+            break;
+        }
         default:
             XMLPropStyleContext::SetAttribute( nElement, rValue );
     }
@@ -318,6 +327,11 @@ void XMLTextStyleContext::Finish( bool bOverwrite )
                     xPropSet->setPropertyValue( sNumberingStyleName, Any(sDisplayListStyleName) );
                 }
             }
+
+            if (m_aListLevel.has_value())
+            {
+                xPropSet->setPropertyValue("NumberingLevel", uno::Any(*m_aListLevel));
+            }
         }
     }
 


More information about the Libreoffice-commits mailing list