diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2022-05-19 09:12:21 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-05-20 14:27:57 +0200 |
commit | 7111b64948bc6eb62397bc8a097b75a20e8a0d33 (patch) | |
tree | 4fbb1489e06346e72a01b5944c42d22f883aecc6 /xmloff/qa/unit | |
parent | 18f8522f6d70315caa3d6626d1c7c96a333ab9a4 (diff) |
sw content controls, picture: add ODT filter
Map Picture UNO property on content controls to:
<loext:content-control loext:picture="...">
And do the opposite on import.
(cherry picked from commit 81ce15c466cda946ae94f38904215f24555021ad)
Change-Id: I47c3d04c505ba94da958d5d6b6b2c883236afc3d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134665
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'xmloff/qa/unit')
-rw-r--r-- | xmloff/qa/unit/data/content-control-picture.fodt | 13 | ||||
-rw-r--r-- | xmloff/qa/unit/text.cxx | 71 |
2 files changed, 84 insertions, 0 deletions
diff --git a/xmloff/qa/unit/data/content-control-picture.fodt b/xmloff/qa/unit/data/content-control-picture.fodt new file mode 100644 index 000000000000..ae47bfa0dfac --- /dev/null +++ b/xmloff/qa/unit/data/content-control-picture.fodt @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8"?> +<office:document xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office: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" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"> + <office:body> + <office:text> + <text:p><loext:content-control loext:showing-place-holder="true" loext:picture="true"><draw:frame text:anchor-type="as-char" svg:width="1cm" svg:height="1cm"><draw:image draw:mime-type="image/png"> + <office:binary-data>iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQAAAAA3bvkkAAAAEElEQVR4nGJgAQAAAP//AwAA + BgAFV7+r1AAAAABJRU5ErkJggg== + </office:binary-data> + </draw:image> + </draw:frame></loext:content-control></text:p> + </office:text> + </office:body> +</office:document> diff --git a/xmloff/qa/unit/text.cxx b/xmloff/qa/unit/text.cxx index d11c58a69ed0..e91f71d64cc7 100644 --- a/xmloff/qa/unit/text.cxx +++ b/xmloff/qa/unit/text.cxx @@ -17,6 +17,7 @@ #include <com/sun/star/frame/XStorable.hpp> #include <com/sun/star/text/XTextDocument.hpp> #include <com/sun/star/text/BibliographyDataType.hpp> +#include <com/sun/star/text/TextContentAnchorType.hpp> #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> #include <com/sun/star/packages/zip/ZipFileAccess.hpp> @@ -577,6 +578,76 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testDropdownContentControlImport) CPPUNIT_ASSERT_EQUAL(OUString("choose a color"), xContent->getString()); } +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testPictureContentControlExport) +{ + // Given a document with a picture content control around an as-char image: + 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::XText> xText = xTextDocument->getText(); + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + uno::Reference<beans::XPropertySet> xTextGraphic( + xMSF->createInstance("com.sun.star.text.TextGraphicObject"), uno::UNO_QUERY); + xTextGraphic->setPropertyValue("AnchorType", + uno::Any(text::TextContentAnchorType_AS_CHARACTER)); + uno::Reference<text::XTextContent> xTextContent(xTextGraphic, uno::UNO_QUERY); + xText->insertTextContent(xCursor, xTextContent, false); + xCursor->gotoStart(/*bExpand=*/false); + xCursor->gotoEnd(/*bExpand=*/true); + uno::Reference<text::XTextContent> xContentControl( + xMSF->createInstance("com.sun.star.text.ContentControl"), uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, uno::UNO_QUERY); + xContentControlProps->setPropertyValue("Picture", uno::Any(true)); + xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true); + + // When exporting to ODT: + uno::Reference<frame::XStorable> xStorable(getComponent(), uno::UNO_QUERY); + uno::Sequence<beans::PropertyValue> aStoreProps = comphelper::InitPropertySequence({ + { "FilterName", uno::Any(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 test would have failed with: + // - XPath '//loext:content-control' no attribute 'picture' exist + assertXPath(pXmlDoc, "//loext:content-control", "picture", "true"); +} + +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testPictureContentControlImport) +{ + // Given an ODF document with a picture content control: + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "content-control-picture.fodt"; + + // When loading that document: + getComponent() = loadFromDesktop(aURL); + + // Then make sure that the content control is not lost on import: + uno::Reference<text::XTextDocument> xTextDocument(getComponent(), uno::UNO_QUERY); + uno::Reference<container::XEnumerationAccess> xParagraphsAccess(xTextDocument->getText(), + uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xParagraphs = xParagraphsAccess->createEnumeration(); + uno::Reference<container::XEnumerationAccess> xParagraph(xParagraphs->nextElement(), + uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xPortions = xParagraph->createEnumeration(); + uno::Reference<beans::XPropertySet> xTextPortion(xPortions->nextElement(), uno::UNO_QUERY); + OUString aPortionType; + xTextPortion->getPropertyValue("TextPortionType") >>= aPortionType; + CPPUNIT_ASSERT_EQUAL(OUString("ContentControl"), aPortionType); + uno::Reference<text::XTextContent> xContentControl; + xTextPortion->getPropertyValue("ContentControl") >>= xContentControl; + uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, uno::UNO_QUERY); + bool bPicture{}; + xContentControlProps->getPropertyValue("Picture") >>= bPicture; + // Without the accompanying fix in place, this failed, as the picture attribute was ignored on + // import. + CPPUNIT_ASSERT(bPicture); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |