From 2da16ff9f018fae68c53a801e5a234dafc2ebcec Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Thu, 23 Feb 2023 08:21:46 +0100 Subject: sw floattable: teach the ODT filter about SwFormatFlySplit Map the IsSplitAllowed text frame property to . This is meant to be always a direct formatting, so doesn't go to the style / autostyle. Change-Id: I439fe372271e4b7db511b5e2150e2a3c2e0acf25 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147499 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- xmloff/qa/unit/data/floattable.fodt | 31 ++++++++++++++++++ xmloff/qa/unit/text.cxx | 51 ++++++++++++++++++++++++++++++ xmloff/source/core/xmltoken.cxx | 2 ++ xmloff/source/text/XMLTextFrameContext.cxx | 10 ++++++ xmloff/source/text/txtparae.cxx | 6 ++++ xmloff/source/token/tokens.txt | 1 + 6 files changed, 101 insertions(+) create mode 100644 xmloff/qa/unit/data/floattable.fodt (limited to 'xmloff') diff --git a/xmloff/qa/unit/data/floattable.fodt b/xmloff/qa/unit/data/floattable.fodt new file mode 100644 index 000000000000..927d14b757e9 --- /dev/null +++ b/xmloff/qa/unit/data/floattable.fodt @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + A1A2anchor text + + + diff --git a/xmloff/qa/unit/text.cxx b/xmloff/qa/unit/text.cxx index 5dfd52010a09..ded7196be09b 100644 --- a/xmloff/qa/unit/text.cxx +++ b/xmloff/qa/unit/text.cxx @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -956,6 +957,56 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testThemeExport) "#c0c0c0"); } +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testFloatingTableExport) +{ + // Given a document with a floating table: + mxComponent = loadFromDesktop("private:factory/swriter"); + // Insert a table: + uno::Sequence aArgs = { + comphelper::makePropertyValue("Rows", static_cast(1)), + comphelper::makePropertyValue("Columns", static_cast(1)), + }; + dispatchCommand(mxComponent, ".uno:InsertTable", aArgs); + // Select it: + dispatchCommand(mxComponent, ".uno:SelectAll", {}); + // Wrap in a fly: + aArgs = { + comphelper::makePropertyValue("AnchorType", static_cast(0)), + }; + dispatchCommand(mxComponent, ".uno:InsertFrame", aArgs); + // Mark it as a floating table: + uno::Reference xTextFramesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xFrame( + xTextFramesSupplier->getTextFrames()->getByName("Frame1"), uno::UNO_QUERY); + xFrame->setPropertyValue("IsSplitAllowed", uno::Any(true)); + + // When saving to ODT: + save("writer8"); + + // Then make sure we write a floating table, not a textframe containing a table: + xmlDocUniquePtr pXmlDoc = parseExport("content.xml"); + // Without the accompanying fix in place, this test would have failed with: + // - XPath '//draw:frame' no attribute 'may-break-between-pages' exist + // i.e. no floating table was exported. + assertXPath(pXmlDoc, "//draw:frame", "may-break-between-pages", "true"); +} + +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testFloatingTableImport) +{ + // Given a document with a floating table (loext:may-break-between-pages="true"), when importing + // that document: + loadFromURL(u"floattable.fodt"); + + // Then make sure that the matching text frame property is set: + uno::Reference xTextFramesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xFrame( + xTextFramesSupplier->getTextFrames()->getByName("Frame1"), uno::UNO_QUERY); + bool bIsSplitAllowed = false; + // Without the accompanying fix in place, this test would have failed, the property was false. + xFrame->getPropertyValue("IsSplitAllowed") >>= bIsSplitAllowed; + CPPUNIT_ASSERT(bIsSplitAllowed); +} + 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 78ef34951013..7eb6f14eee54 100644 --- a/xmloff/source/core/xmltoken.cxx +++ b/xmloff/source/core/xmltoken.cxx @@ -3514,6 +3514,8 @@ namespace xmloff::token { TOKEN("fill-use-slide-background", XML_FILL_USE_SLIDE_BACKGROUND), + TOKEN("may-break-between-pages", XML_MAY_BREAK_BETWEEN_PAGES), + #if OSL_DEBUG_LEVEL > 0 { 0, nullptr, std::nullopt, XML_TOKEN_END } #else diff --git a/xmloff/source/text/XMLTextFrameContext.cxx b/xmloff/source/text/XMLTextFrameContext.cxx index ad0754acfca2..bd145b5213cd 100644 --- a/xmloff/source/text/XMLTextFrameContext.cxx +++ b/xmloff/source/text/XMLTextFrameContext.cxx @@ -370,6 +370,7 @@ class XMLTextFrameContext_Impl : public SvXMLImportContext bool bOwnBase64Stream : 1; bool mbMultipleContent : 1; // This context is created based on a multiple content (image) bool m_isDecorative = false; + bool m_isSplitAllowed = false; void Create(); @@ -687,6 +688,11 @@ void XMLTextFrameContext_Impl::Create() xPropSet->setPropertyValue("Decorative", uno::Any(true)); } + if (m_isSplitAllowed && xPropSetInfo->hasPropertyByName("IsSplitAllowed")) + { + xPropSet->setPropertyValue("IsSplitAllowed", uno::Any(true)); + } + if( XML_TEXT_FRAME_OBJECT != nType && XML_TEXT_FRAME_OBJECT_OLE != nType && XML_TEXT_FRAME_APPLET != nType && @@ -1073,6 +1079,10 @@ XMLTextFrameContext_Impl::XMLTextFrameContext_Impl( case XML_ELEMENT(DRAW, XML_DECORATIVE): ::sax::Converter::convertBool(m_isDecorative, aIter.toString()); break; + case XML_ELEMENT(LO_EXT, XML_MAY_BREAK_BETWEEN_PAGES): + case XML_ELEMENT(DRAW, XML_MAY_BREAK_BETWEEN_PAGES): + sax::Converter::convertBool(m_isSplitAllowed, aIter.toString()); + break; default: SAL_INFO("xmloff", "unknown attribute " << SvXMLImport::getPrefixAndNameFromToken(aIter.getToken()) << " value=" << aIter.toString()); } diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx index 4775fbad9152..4b930e73a0b6 100644 --- a/xmloff/source/text/txtparae.cxx +++ b/xmloff/source/text/txtparae.cxx @@ -3015,6 +3015,12 @@ XMLShapeExportFlags XMLTextParagraphExport::addTextFrameAttributes( GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_DECORATIVE, XML_TRUE); } + if (xPropSetInfo->hasPropertyByName("IsSplitAllowed") + && rPropSet->getPropertyValue("IsSplitAllowed").get()) + { + GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_MAY_BREAK_BETWEEN_PAGES, XML_TRUE); + } + return nShapeFeatures; } diff --git a/xmloff/source/token/tokens.txt b/xmloff/source/token/tokens.txt index 74a725d91b30..576efe9b8bd5 100644 --- a/xmloff/source/token/tokens.txt +++ b/xmloff/source/token/tokens.txt @@ -3255,4 +3255,5 @@ plain-text alias tag fill-use-slide-background +may-break-between-pages TOKEN_END_DUMMY -- cgit