summaryrefslogtreecommitdiff
path: root/xmloff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-03-11 12:29:30 +0100
committerMiklos Vajna <vmiklos@collabora.com>2022-03-11 14:04:50 +0100
commit07c2b73d16425fb6d3ea8ab9ec15c87e9548acda (patch)
treeb4aa74338754fa6ce7f855b1cfe09e7e24d78908 /xmloff
parent1f5f94d153fbade9cd96f841f1084fe16815f4f3 (diff)
sw clearing breaks: add ODF export
Write the clearing break as: <text:line-break loext:clear="..."/> Change-Id: Ieb517b825f2ee162bb70a453a3756ec870fa8aac Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131346 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'xmloff')
-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
4 files changed, 76 insertions, 0 deletions
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