diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2023-02-23 08:21:46 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2023-02-23 09:32:08 +0000 |
commit | 2da16ff9f018fae68c53a801e5a234dafc2ebcec (patch) | |
tree | 60b5bdcdd4ac2bca705705fe8dea101bb1b76a71 /xmloff | |
parent | 988cdcc18610300dd389e0efc25553e6c1bcb19e (diff) |
sw floattable: teach the ODT filter about SwFormatFlySplit
Map the IsSplitAllowed text frame property to <draw:frame
loext:may-break-between-pages="...">. 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 <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'xmloff')
-rw-r--r-- | xmloff/qa/unit/data/floattable.fodt | 31 | ||||
-rw-r--r-- | xmloff/qa/unit/text.cxx | 51 | ||||
-rw-r--r-- | xmloff/source/core/xmltoken.cxx | 2 | ||||
-rw-r--r-- | xmloff/source/text/XMLTextFrameContext.cxx | 10 | ||||
-rw-r--r-- | xmloff/source/text/txtparae.cxx | 6 | ||||
-rw-r--r-- | xmloff/source/token/tokens.txt | 1 |
6 files changed, 101 insertions, 0 deletions
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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text"> + <office:styles> + <style:style style:name="Frame" style:family="graphic"/> + </office:styles> + <office:automatic-styles> + <style:style style:name="Table1" style:family="table"> + <style:table-properties style:width="6.743cm"/> + </style:style> + <style:style style:name="Table1.A" style:family="table-column"> + <style:table-column-properties style:column-width="6.743cm"/> + </style:style> + <style:style style:name="Table1.1" style:family="table-row"> + <style:table-row-properties style:min-row-height="3.196cm"/> + </style:style> + <style:style style:name="fr1" style:family="graphic" style:parent-style-name="Frame"> + <style:graphic-properties fo:margin-left="0.318cm" fo:margin-right="0.318cm" fo:margin-top="0cm" fo:margin-bottom="0cm" style:vertical-pos="from-top" style:vertical-rel="paragraph" style:horizontal-pos="from-left" style:horizontal-rel="paragraph" fo:padding="0cm" fo:border="none"/> + </style:style> + <style:page-layout style:name="pm1"> + <style:page-layout-properties fo:page-width="21.59cm" fo:page-height="10.941cm" fo:margin-top="2.54cm" fo:margin-bottom="2.54cm" fo:margin-left="2.54cm" fo:margin-right="2.54cm"/> + </style:page-layout> + </office:automatic-styles> + <office:master-styles> + <style:master-page style:name="Standard" style:page-layout-name="pm1"/> + </office:master-styles> + <office:body> + <office:text> + <text:p><draw:frame draw:style-name="fr1" draw:name="Frame1" text:anchor-type="paragraph" svg:x="-0.009cm" svg:y="0.002cm" svg:width="6.743cm" draw:z-index="0" loext:may-break-between-pages="true"><draw:text-box fo:min-height="0cm"><table:table table:name="Table1" table:style-name="Table1"><table:table-column table:style-name="Table1.A"/><table:table-row table:style-name="Table1.1"><table:table-cell office:value-type="string"><text:p>A1</text:p></table:table-cell></table:table-row><table:table-row table:style-name="Table1.1"><table:table-cell office:value-type="string"><text:p>A2</text:p></table:table-cell></table:table-row></table:table></draw:text-box></draw:frame>anchor text</text:p> + </office:text> + </office:body> +</office:document> 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 <com/sun/star/text/TextContentAnchorType.hpp> #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> #include <com/sun/star/drawing/XDrawPageSupplier.hpp> +#include <com/sun/star/text/XTextFramesSupplier.hpp> #include <comphelper/propertysequence.hxx> #include <comphelper/propertyvalue.hxx> @@ -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<beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("Rows", static_cast<sal_Int32>(1)), + comphelper::makePropertyValue("Columns", static_cast<sal_Int32>(1)), + }; + dispatchCommand(mxComponent, ".uno:InsertTable", aArgs); + // Select it: + dispatchCommand(mxComponent, ".uno:SelectAll", {}); + // Wrap in a fly: + aArgs = { + comphelper::makePropertyValue("AnchorType", static_cast<sal_uInt16>(0)), + }; + dispatchCommand(mxComponent, ".uno:InsertFrame", aArgs); + // Mark it as a floating table: + uno::Reference<text::XTextFramesSupplier> xTextFramesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> 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<text::XTextFramesSupplier> xTextFramesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> 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<bool>()) + { + 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 |