From 7f58b57b47e6642cb9a7aeac48915b30148042d2 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Tue, 28 Nov 2023 08:46:58 +0100 Subject: [PATCH] sw floattable, per-frame wrap-on-all-pages mode: add ODT filter See , map SwFormatWrapTextAtFlyStart to on export, and the opposite on import. Change-Id: I43ee4c014fbcef8e883ff08ea061cfd395399a98 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160010 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- include/xmloff/xmltoken.hxx | 1 + .../OpenDocument-v1.3+libreoffice-schema.rng | 6 ++ xmloff/CppunitTest_xmloff_text.mk | 1 + xmloff/inc/xmlprop.hxx | 1 + .../unit/data/floattable-wrap-all-pages2.fodt | 41 +++++++++ xmloff/qa/unit/text/txtprmap.cxx | 87 +++++++++++++++++++ xmloff/source/core/xmltoken.cxx | 1 + xmloff/source/text/txtprmap.cxx | 1 + xmloff/source/token/tokens.txt | 1 + 9 files changed, 140 insertions(+) create mode 100644 xmloff/qa/unit/data/floattable-wrap-all-pages2.fodt create mode 100644 xmloff/qa/unit/text/txtprmap.cxx diff --git a/include/xmloff/xmltoken.hxx b/include/xmloff/xmltoken.hxx index ba42fae4d035..b6fa0dc2acba 100644 --- a/include/xmloff/xmltoken.hxx +++ b/include/xmloff/xmltoken.hxx @@ -3547,6 +3547,7 @@ namespace xmloff::token { XML_FILL_USE_SLIDE_BACKGROUND, XML_MAY_BREAK_BETWEEN_PAGES, + XML_WRAP_TEXT_AT_FRAME_START, XML_GRADIENT_STOP, // multi-color-gradient XML_OPACITY_STOP, diff --git a/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng b/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng index 828b4b28c9fd..a68033d1954e 100644 --- a/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng +++ b/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng @@ -926,6 +926,12 @@ xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1. + + + + + + diff --git a/xmloff/CppunitTest_xmloff_text.mk b/xmloff/CppunitTest_xmloff_text.mk index 7fc0fa394950..73e5dbb8eaaa 100644 --- a/xmloff/CppunitTest_xmloff_text.mk +++ b/xmloff/CppunitTest_xmloff_text.mk @@ -18,6 +18,7 @@ $(eval $(call gb_CppunitTest_use_externals,xmloff_text,\ $(eval $(call gb_CppunitTest_add_exception_objects,xmloff_text, \ xmloff/qa/unit/text \ + xmloff/qa/unit/text/txtprmap \ )) $(eval $(call gb_CppunitTest_use_libraries,xmloff_text, \ diff --git a/xmloff/inc/xmlprop.hxx b/xmloff/inc/xmlprop.hxx index 31b500335891..d93e0b89fbf5 100644 --- a/xmloff/inc/xmlprop.hxx +++ b/xmloff/inc/xmlprop.hxx @@ -660,6 +660,7 @@ inline constexpr OUString PROP_Weight = u"Weight"_ustr; inline constexpr OUString PROP_Width = u"Width"_ustr; inline constexpr OUString PROP_WidthType = u"WidthType"_ustr; inline constexpr OUString PROP_WrapInfluenceOnPosition = u"WrapInfluenceOnPosition"_ustr; +inline constexpr OUString PROP_WrapTextAtFlyStart = u"WrapTextAtFlyStart"_ustr; inline constexpr OUString PROP_WritingMode = u"WritingMode"_ustr; inline constexpr OUString PROP_XName = u"XName"_ustr; inline constexpr OUString PROP_YName = u"YName"_ustr; diff --git a/xmloff/qa/unit/data/floattable-wrap-all-pages2.fodt b/xmloff/qa/unit/data/floattable-wrap-all-pages2.fodt new file mode 100644 index 000000000000..e8289d66536d --- /dev/null +++ b/xmloff/qa/unit/data/floattable-wrap-all-pages2.fodt @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + First paragraph + A1A2He heard quiet steps behind him. That didn't bode well. Who could be following him this late at night and in this deadbeat part of town? And at this particular moment, just after he pulled off the big time and was making off with the greenbacks. Was there another crook who'd had the same idea, and was now watching him and waiting for a chance to grab the fruit of his labor? Or did the steps behind him mean that one of many law officers in town was on to him and just waiting to pounce and snap those cuffs on his wrists? He nervously looked all around. Suddenly he saw the alley. Like lightning he darted off to the left and disappeared between the two warehouses almost falling over the trash can lying in the middle of the sidewalk. + + + diff --git a/xmloff/qa/unit/text/txtprmap.cxx b/xmloff/qa/unit/text/txtprmap.cxx new file mode 100644 index 000000000000..f40b04b3fdd1 --- /dev/null +++ b/xmloff/qa/unit/text/txtprmap.cxx @@ -0,0 +1,87 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include + +#include +#include + +#include + +using namespace ::com::sun::star; + +namespace +{ +/// Covers xmloff/source/text/txtprmap.cxx fixes. +class Test : public UnoApiXmlTest +{ +public: + Test(); +}; +} + +Test::Test() + : UnoApiXmlTest("/xmloff/qa/unit/data/") +{ +} + +CPPUNIT_TEST_FIXTURE(Test, testFloatingTableWrapTextAtFlyStartExport) +{ + // 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 that wraps on all pages: + uno::Reference xTextFramesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xFrame( + xTextFramesSupplier->getTextFrames()->getByName("Frame1"), uno::UNO_QUERY); + xFrame->setPropertyValue("IsSplitAllowed", uno::Any(true)); + xFrame->setPropertyValue("WrapTextAtFlyStart", uno::Any(true)); + + // When saving to ODT: + save("writer8"); + + // Then make sure we write a floating table, that wraps on all pages: + xmlDocUniquePtr pXmlDoc = parseExport("content.xml"); + // Without the accompanying fix in place, this test would have failed with: + // - XPath '//style:graphic-properties' no attribute 'wrap-text-at-frame-start' exist + // i.e. no floating table was exported. + assertXPath(pXmlDoc, "//style:graphic-properties"_ostr, "wrap-text-at-frame-start"_ostr, + "true"); +} + +CPPUNIT_TEST_FIXTURE(Test, testFloatingTableWrapTextAtFlyStartImport) +{ + // Given a document with a floating table + wrap on all pages + // (loext:may-break-between-pages="true" and loext:wrap-text-at-frame-start="true"), when + // importing that document: + loadFromURL(u"floattable-wrap-all-pages2.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 bWrapTextAtFlyStart = false; + // Without the accompanying fix in place, this test would have failed, the property was false. + xFrame->getPropertyValue("WrapTextAtFlyStart") >>= bWrapTextAtFlyStart; + CPPUNIT_ASSERT(bWrapTextAtFlyStart); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx index e11dc0d16111..78ac1500e07a 100644 --- a/xmloff/source/core/xmltoken.cxx +++ b/xmloff/source/core/xmltoken.cxx @@ -3549,6 +3549,7 @@ namespace xmloff::token { TOKEN("fill-use-slide-background", XML_FILL_USE_SLIDE_BACKGROUND), TOKEN("may-break-between-pages", XML_MAY_BREAK_BETWEEN_PAGES), + TOKEN("wrap-text-at-frame-start", XML_WRAP_TEXT_AT_FRAME_START), TOKEN("gradient-stop", XML_GRADIENT_STOP), TOKEN("opacity-stop", XML_OPACITY_STOP), diff --git a/xmloff/source/text/txtprmap.cxx b/xmloff/source/text/txtprmap.cxx index 418d4e396ff2..cf6adc9a1927 100644 --- a/xmloff/source/text/txtprmap.cxx +++ b/xmloff/source/text/txtprmap.cxx @@ -876,6 +876,7 @@ XMLPropertyMapEntry constexpr aXMLFramePropMap[] = // #i28701# - RES_WRAP_INFLUENCE_ON_OBJPOS MG_E( PROP_WrapInfluenceOnPosition, XML_NAMESPACE_DRAW, XML_WRAP_INFLUENCE_ON_POSITION, XML_TYPE_WRAP_INFLUENCE_ON_POSITION, 0 ), MAP_EXT( PROP_AllowOverlap, XML_NAMESPACE_LO_EXT, XML_ALLOW_OVERLAP, XML_TYPE_BOOL|XML_TYPE_PROP_GRAPHIC, 0 ), + MAP_EXT( PROP_WrapTextAtFlyStart, XML_NAMESPACE_LO_EXT, XML_WRAP_TEXT_AT_FRAME_START, XML_TYPE_BOOL|XML_TYPE_PROP_GRAPHIC, 0 ), // special entries for floating frames MG_E( PROP_, XML_NAMESPACE_DRAW, XML_FRAME_DISPLAY_SCROLLBAR, XML_TYPE_BOOL|MID_FLAG_NO_PROPERTY|MID_FLAG_MULTI_PROPERTY, CTF_FRAME_DISPLAY_SCROLLBAR ), diff --git a/xmloff/source/token/tokens.txt b/xmloff/source/token/tokens.txt index 7eb09f6f2f9f..882ad0e5978d 100644 --- a/xmloff/source/token/tokens.txt +++ b/xmloff/source/token/tokens.txt @@ -3291,6 +3291,7 @@ alias tag fill-use-slide-background may-break-between-pages +wrap-text-at-frame-start gradient-stop opacity-stop color-value