summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-05-19 09:12:21 +0200
committerMiklos Vajna <vmiklos@collabora.com>2022-05-20 14:27:57 +0200
commit7111b64948bc6eb62397bc8a097b75a20e8a0d33 (patch)
tree4fbb1489e06346e72a01b5944c42d22f883aecc6
parent18f8522f6d70315caa3d6626d1c7c96a333ab9a4 (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>
-rw-r--r--include/xmloff/xmltoken.hxx1
-rw-r--r--schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng6
-rw-r--r--xmloff/qa/unit/data/content-control-picture.fodt13
-rw-r--r--xmloff/qa/unit/text.cxx71
-rw-r--r--xmloff/source/core/xmltoken.cxx1
-rw-r--r--xmloff/source/text/txtparae.cxx10
-rw-r--r--xmloff/source/text/xmlcontentcontrolcontext.cxx13
-rw-r--r--xmloff/source/text/xmlcontentcontrolcontext.hxx1
-rw-r--r--xmloff/source/token/tokens.txt1
9 files changed, 117 insertions, 0 deletions
diff --git a/include/xmloff/xmltoken.hxx b/include/xmloff/xmltoken.hxx
index 1344e5a4b56f..85619ab39550 100644
--- a/include/xmloff/xmltoken.hxx
+++ b/include/xmloff/xmltoken.hxx
@@ -3473,6 +3473,7 @@ namespace xmloff::token {
XML_CHECKED_STATE,
XML_UNCHECKED_STATE,
XML_DISPLAY_TEXT,
+ XML_PICTURE,
XML_TOKEN_END
};
diff --git a/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng b/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng
index cc24f7a386a9..32ab55fb9445 100644
--- a/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng
+++ b/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng
@@ -2794,6 +2794,12 @@ xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.
<rng:ref name="string"/>
</rng:attribute>
</rng:optional>
+ <rng:optional>
+ <!-- default value: false -->
+ <rng:attribute name="loext:picture">
+ <rng:ref name="boolean"/>
+ </rng:attribute>
+ </rng:optional>
<rng:zeroOrMore>
<rng:element name="loext:list-item">
<rng:attribute name="loext:display-text">
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: */
diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx
index ffc2eddaf792..f2a3386a532e 100644
--- a/xmloff/source/core/xmltoken.cxx
+++ b/xmloff/source/core/xmltoken.cxx
@@ -3475,6 +3475,7 @@ namespace xmloff::token {
TOKEN("checked-state", XML_CHECKED_STATE),
TOKEN("unchecked-state", XML_UNCHECKED_STATE),
TOKEN("display-text", XML_DISPLAY_TEXT),
+ TOKEN("picture", XML_PICTURE),
#if OSL_DEBUG_LEVEL > 0
diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx
index 4665df3e2f1f..ef5471c5aeed 100644
--- a/xmloff/source/text/txtparae.cxx
+++ b/xmloff/source/text/txtparae.cxx
@@ -3907,6 +3907,16 @@ void XMLTextParagraphExport::ExportContentControl(
{
GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_UNCHECKED_STATE, aUncheckedState);
}
+
+ bool bPicture = false;
+ xPropertySet->getPropertyValue("Picture") >>= bPicture;
+ if (bPicture)
+ {
+ OUStringBuffer aBuffer;
+ sax::Converter::convertBool(aBuffer, bPicture);
+ GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_PICTURE,
+ aBuffer.makeStringAndClear());
+ }
}
SvXMLElementExport aElem(GetExport(), bExport, XML_NAMESPACE_LO_EXT, XML_CONTENT_CONTROL, false,
diff --git a/xmloff/source/text/xmlcontentcontrolcontext.cxx b/xmloff/source/text/xmlcontentcontrolcontext.cxx
index eb3a384d6b98..c9f4b8a8b2b9 100644
--- a/xmloff/source/text/xmlcontentcontrolcontext.cxx
+++ b/xmloff/source/text/xmlcontentcontrolcontext.cxx
@@ -86,6 +86,14 @@ void XMLContentControlContext::startFastElement(
m_aUncheckedState = rIter.toString();
break;
}
+ case XML_ELEMENT(LO_EXT, XML_PICTURE):
+ {
+ if (sax::Converter::convertBool(bTmp, rIter.toView()))
+ {
+ m_bPicture = bTmp;
+ }
+ break;
+ }
default:
XMLOFF_WARN_UNKNOWN("xmloff", rIter);
}
@@ -149,6 +157,11 @@ void XMLContentControlContext::endFastElement(sal_Int32)
xPropertySet->setPropertyValue("ListItems",
uno::Any(comphelper::containerToSequence(m_aListItems)));
}
+
+ if (m_bPicture)
+ {
+ xPropertySet->setPropertyValue("Picture", uno::Any(m_bPicture));
+ }
}
css::uno::Reference<css::xml::sax::XFastContextHandler>
diff --git a/xmloff/source/text/xmlcontentcontrolcontext.hxx b/xmloff/source/text/xmlcontentcontrolcontext.hxx
index 20c39ad44d2c..d3874d31257e 100644
--- a/xmloff/source/text/xmlcontentcontrolcontext.hxx
+++ b/xmloff/source/text/xmlcontentcontrolcontext.hxx
@@ -43,6 +43,7 @@ class XMLContentControlContext : public SvXMLImportContext
OUString m_aCheckedState;
OUString m_aUncheckedState;
std::vector<css::beans::PropertyValues> m_aListItems;
+ bool m_bPicture = false;
public:
XMLContentControlContext(SvXMLImport& rImport, sal_Int32 nElement, XMLHints_Impl& rHints,
diff --git a/xmloff/source/token/tokens.txt b/xmloff/source/token/tokens.txt
index f0aadbea63f2..ffd10a485dd0 100644
--- a/xmloff/source/token/tokens.txt
+++ b/xmloff/source/token/tokens.txt
@@ -3219,4 +3219,5 @@ showing-place-holder
checked-state
unchecked-state
display-text
+picture
TOKEN_END_DUMMY