include/xmloff/txtparae.hxx                                 |    2 
 include/xmloff/xmltoken.hxx                                 |    1 
 schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng |   17 +++++
 xmloff/qa/unit/text.cxx                                     |   35 ++++++++++
 xmloff/source/core/xmltoken.cxx                             |    1 
 xmloff/source/text/txtparae.cxx                             |   39 ++++++++++++
 xmloff/source/token/tokens.txt                              |    1 
 7 files changed, 96 insertions(+)

New commits:
commit 9ac75ca18463203b0f0b70bf9dd35985636ebaf0
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Fri Mar 11 12:29:30 2022 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue Mar 29 14:22:45 2022 +0200

    sw clearing breaks: add ODF export
    
    Write the clearing break as:
    
            <text:line-break loext:clear="..."/>
    
    (cherry picked from commit 07c2b73d16425fb6d3ea8ab9ec15c87e9548acda)
    
    Conflicts:
            xmloff/qa/unit/text.cxx
    
    Change-Id: Ieb517b825f2ee162bb70a453a3756ec870fa8aac
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132259
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/include/xmloff/txtparae.hxx b/include/xmloff/txtparae.hxx
index eaf23409bd7a..70716c1f77a2 100644
--- a/include/xmloff/txtparae.hxx
+++ b/include/xmloff/txtparae.hxx
@@ -321,6 +321,8 @@ protected:
 
     void exportSoftPageBreak();
 
+    void exportTextLineBreak(const 
css::uno::Reference<css::beans::XPropertySet>& xPropSet);
+
     void exportTextRange(
         const css::uno::Reference< css::text::XTextRange > & rTextRange,
         bool bAutoStyles,
diff --git a/include/xmloff/xmltoken.hxx b/include/xmloff/xmltoken.hxx
index c510b8cab00d..8e7583694f47 100644
--- a/include/xmloff/xmltoken.hxx
+++ b/include/xmloff/xmltoken.hxx
@@ -1173,6 +1173,7 @@ namespace xmloff::token {
         XML_LIMIT,
         XML_LINE,
         XML_LINE_BREAK,
+        XML_CLEAR,
         XML_LINE_DISTANCE,
         XML_LINE_HEIGHT,
         XML_LINE_HEIGHT_AT_LEAST,
diff --git a/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng 
b/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng
index 3919ba47f04f..0d64385a7e67 100644
--- a/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng
+++ b/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng
@@ -2581,6 +2581,23 @@ 
xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.
     </rng:element>
   </rng:define>
 
+  <!-- TODO no proposal for clearing breaks -->
+  <rng:define name="paragraph-content" combine="choice">
+    <rng:element name="text:line-break">
+      <rng:optional>
+        <!-- default value: none -->
+        <rng:attribute name="loext:clear">
+          <rng:choice>
+            <rng:value>none</rng:value>
+            <rng:value>left</rng:value>
+            <rng:value>right</rng:value>
+            <rng:value>all</rng:value>
+          </rng:choice>
+        </rng:attribute>
+      </rng:optional>
+    </rng:element>
+  </rng:define>
+
   <!-- TODO no proposal -->
   <rng:define name="animation-element" combine="choice">
     <rng:choice>
diff --git a/xmloff/qa/unit/text.cxx b/xmloff/qa/unit/text.cxx
index 1d239e2e0c09..3b64f73fdc0a 100644
--- a/xmloff/qa/unit/text.cxx
+++ b/xmloff/qa/unit/text.cxx
@@ -245,6 +245,41 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, 
testContinueNumberingWord)
     CPPUNIT_ASSERT_EQUAL(OUString("2."), aActual);
 }
 
+CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testClearingBreakExport)
+{
+    // Given a document with a clearing break:
+    getComponent() = loadFromDesktop("private:factory/swriter");
+    uno::Reference<lang::XMultiServiceFactory> xMSF(getComponent(), 
uno::UNO_QUERY);
+    uno::Reference<text::XTextDocument> xTextDocument(getComponent(), 
uno::UNO_QUERY);
+    uno::Reference<text::XTextContent> xLineBreak(
+        xMSF->createInstance("com.sun.star.text.LineBreak"), uno::UNO_QUERY);
+    uno::Reference<beans::XPropertySet> xLineBreakProps(xLineBreak, 
uno::UNO_QUERY);
+    // SwLineBreakClear::ALL;
+    sal_Int16 eClear = 3;
+    xLineBreakProps->setPropertyValue("Clear", uno::makeAny(eClear));
+    uno::Reference<text::XText> xText = xTextDocument->getText();
+    uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor();
+    xText->insertTextContent(xCursor, xLineBreak, /*bAbsorb=*/false);
+
+    // When exporting to ODT:
+    uno::Reference<frame::XStorable> xStorable(getComponent(), uno::UNO_QUERY);
+    uno::Sequence<beans::PropertyValue> aStoreProps = 
comphelper::InitPropertySequence({
+        { "FilterName", uno::makeAny(OUString("writer8")) },
+    });
+    utl::TempFile aTempFile;
+    aTempFile.EnableKillingFile();
+    xStorable->storeToURL(aTempFile.GetURL(), aStoreProps);
+    validate(aTempFile.GetFileName(), test::ODF);
+
+    // Then make sure the expected markup is used:
+    std::unique_ptr<SvStream> pStream = parseExportStream(aTempFile, 
"content.xml");
+    xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get());
+    // Without the accompanying fix in place, this failed with:
+    // - XPath '//text:line-break' number of nodes is incorrect
+    // i.e. the clearing break was lost on export.
+    assertXPath(pXmlDoc, "//text:line-break", "clear", "all");
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx
index 704f374a5026..80cd4b6d6f3f 100644
--- a/xmloff/source/core/xmltoken.cxx
+++ b/xmloff/source/core/xmltoken.cxx
@@ -1186,6 +1186,7 @@ namespace xmloff::token {
         TOKEN( "limit",                           XML_LIMIT ),
         TOKEN( "line",                            XML_LINE ),
         TOKEN( "line-break",                      XML_LINE_BREAK ),
+        TOKEN( "clear",                           XML_CLEAR ),
         TOKEN( "line-distance",                   XML_LINE_DISTANCE ),
         TOKEN( "line-height",                     XML_LINE_HEIGHT ),
         TOKEN( "line-height-at-least",            XML_LINE_HEIGHT_AT_LEAST ),
diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx
index 732c119cdb58..5f0247bc32c7 100644
--- a/xmloff/source/text/txtparae.cxx
+++ b/xmloff/source/text/txtparae.cxx
@@ -109,6 +109,7 @@
 #include <algorithm>
 #include <iterator>
 #include <officecfg/Office/Common.hxx>
+#include <o3tl/safeint.hxx>
 
 using namespace ::std;
 using namespace ::com::sun::star;
@@ -2356,6 +2357,10 @@ void XMLTextParagraphExport::exportTextRangeEnumeration(
             {
                 exportSoftPageBreak();
             }
+            else if (sType == "LineBreak")
+            {
+                exportTextLineBreak(xPropSet);
+            }
             else {
                 OSL_FAIL("unknown text portion type");
             }
@@ -2431,6 +2436,40 @@ void XMLTextParagraphExport::exportSoftPageBreak()
                               false );
 }
 
+void XMLTextParagraphExport::exportTextLineBreak(
+    const uno::Reference<beans::XPropertySet>& xPropSet)
+{
+    static const XMLTokenEnum aLineBreakClears[] = {
+        XML_NONE,
+        XML_LEFT,
+        XML_RIGHT,
+        XML_ALL,
+    };
+
+    uno::Reference<text::XTextContent> xLineBreak;
+    xPropSet->getPropertyValue("LineBreak") >>= xLineBreak;
+    if (!xLineBreak.is())
+    {
+        return;
+    }
+
+    uno::Reference<beans::XPropertySet> xLineBreakProps(xLineBreak, 
uno::UNO_QUERY);
+    if (!xLineBreakProps.is())
+    {
+        return;
+    }
+
+    sal_Int16 eClear{};
+    xLineBreakProps->getPropertyValue("Clear") >>= eClear;
+    if (eClear >= 0 && o3tl::make_unsigned(eClear) < 
SAL_N_ELEMENTS(aLineBreakClears))
+    {
+        GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_CLEAR,
+                                 GetXMLToken(aLineBreakClears[eClear]));
+    }
+    SvXMLElementExport aElem(GetExport(), XML_NAMESPACE_TEXT, XML_LINE_BREAK,
+                             /*bIgnWSOutside=*/false, /*bIgnWSInside=*/false);
+}
+
 void XMLTextParagraphExport::exportTextMark(
     const Reference<XPropertySet> & rPropSet,
     const OUString& rProperty,
diff --git a/xmloff/source/token/tokens.txt b/xmloff/source/token/tokens.txt
index 6e34ec554fab..072777981400 100644
--- a/xmloff/source/token/tokens.txt
+++ b/xmloff/source/token/tokens.txt
@@ -1086,6 +1086,7 @@ lime
 limit
 line
 line-break
+clear
 line-distance
 line-height
 line-height-at-least

Reply via email to