summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/xmloff/txtparae.hxx2
-rw-r--r--include/xmloff/xmltoken.hxx1
-rw-r--r--schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng17
-rw-r--r--xmloff/qa/unit/text.cxx35
-rw-r--r--xmloff/source/core/xmltoken.cxx1
-rw-r--r--xmloff/source/text/txtparae.cxx39
-rw-r--r--xmloff/source/token/tokens.txt1
7 files changed, 96 insertions, 0 deletions
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 4f7cd7e148a4..26b46bf890d6 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 9698c0448bdf..7b3eff94de1c 100644
--- a/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng
+++ b/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng
@@ -2634,6 +2634,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 71772edb3585..e0289183d2c4 100644
--- a/xmloff/qa/unit/text.cxx
+++ b/xmloff/qa/unit/text.cxx
@@ -269,6 +269,41 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testListId)
assertXPathNoAttribute(pXmlDoc, "//text:list", "id");
}
+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 c7db64b00174..d1827fcd2915 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 f8e46fb71844..bfd7d2f2f6fa 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 ec591c072789..a5c981a7ce6c 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