diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2021-04-19 20:27:32 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2021-04-20 09:01:27 +0200 |
commit | 4cb71fefc61d9015a0142f3a4fdafc5250913f2c (patch) | |
tree | 48f608e87c63c6dffc941842eb4269c098db8bd0 /oox/qa | |
parent | 028f47cc490374264a6648a7682ff6234195b380 (diff) |
tdf#122962 DOCX drawingML export: fix polygon shape in group shape
Regression from commit cfb5b20cdc230320ff9f864d1cfd81aaea221da0
(DocxAttributeOutput::OutputFlyFrame_Impl: enable DML export by default,
2013-12-18), there were two problems here.
First, <a:chOff> and <a:chExt> was not written for docx group shapes.
This can be done for toplevel shapes just by writing what would be the
shape position and size (but for docx, we don't write the size).
Second, (poly)polygon shapes used the bounding rectangle of their points
as size, which doesn't necessarily match the shape size. Given that the
group shape is meant to simply contain its children in LibreOffice (and
not have an own size), switch to using the UNO API for polygon shapes as
well, that way the two sizes will always match.
Change-Id: I4406ddefe5f6105aa2fc74d805359add452936bb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114305
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'oox/qa')
-rw-r--r-- | oox/qa/unit/data/dml-groupshape-polygon.docx | bin | 0 -> 24492 bytes | |||
-rw-r--r-- | oox/qa/unit/export.cxx | 157 |
2 files changed, 157 insertions, 0 deletions
diff --git a/oox/qa/unit/data/dml-groupshape-polygon.docx b/oox/qa/unit/data/dml-groupshape-polygon.docx Binary files differnew file mode 100644 index 000000000000..6d20b0342f68 --- /dev/null +++ b/oox/qa/unit/data/dml-groupshape-polygon.docx diff --git a/oox/qa/unit/export.cxx b/oox/qa/unit/export.cxx new file mode 100644 index 000000000000..6e6620ab63a4 --- /dev/null +++ b/oox/qa/unit/export.cxx @@ -0,0 +1,157 @@ +/* -*- 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 <test/bootstrapfixture.hxx> +#include <unotest/macros_test.hxx> +#include <test/xmltesttools.hxx> + +#include <com/sun/star/frame/Desktop.hpp> +#include <com/sun/star/frame/XStorable.hpp> +#include <com/sun/star/packages/zip/ZipFileAccess.hpp> + +#include <unotools/mediadescriptor.hxx> +#include <unotools/tempfile.hxx> +#include <unotools/ucbstreamhelper.hxx> + +using namespace ::com::sun::star; + +namespace +{ +/// Covers ooox/source/export/ fixes. +class Test : public test::BootstrapFixture, public unotest::MacrosTest, public XmlTestTools +{ +private: + uno::Reference<lang::XComponent> mxComponent; + utl::TempFile maTempFile; + +public: + void setUp() override; + void tearDown() override; + void registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx) override; + utl::TempFile& getTempFile() { return maTempFile; } + void loadAndSave(const OUString& rURL, const OUString& rFilterName); +}; + +void Test::setUp() +{ + test::BootstrapFixture::setUp(); + + mxDesktop.set(frame::Desktop::create(mxComponentContext)); +} + +void Test::tearDown() +{ + if (mxComponent.is()) + mxComponent->dispose(); + + test::BootstrapFixture::tearDown(); +} + +void Test::registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx) +{ + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("w"), + BAD_CAST("http://schemas.openxmlformats.org/wordprocessingml/2006/main")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("v"), BAD_CAST("urn:schemas-microsoft-com:vml")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("mc"), + BAD_CAST("http://schemas.openxmlformats.org/markup-compatibility/2006")); + xmlXPathRegisterNs( + pXmlXpathCtx, BAD_CAST("wps"), + BAD_CAST("http://schemas.microsoft.com/office/word/2010/wordprocessingShape")); + xmlXPathRegisterNs( + pXmlXpathCtx, BAD_CAST("wpg"), + BAD_CAST("http://schemas.microsoft.com/office/word/2010/wordprocessingGroup")); + xmlXPathRegisterNs( + pXmlXpathCtx, BAD_CAST("wp"), + BAD_CAST("http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing")); + xmlXPathRegisterNs( + pXmlXpathCtx, BAD_CAST("wp14"), + BAD_CAST("http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("a"), + BAD_CAST("http://schemas.openxmlformats.org/drawingml/2006/main")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("pic"), + BAD_CAST("http://schemas.openxmlformats.org/drawingml/2006/picture")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("rels"), + BAD_CAST("http://schemas.openxmlformats.org/package/2006/relationships")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("w14"), + BAD_CAST("http://schemas.microsoft.com/office/word/2010/wordml")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("m"), + BAD_CAST("http://schemas.openxmlformats.org/officeDocument/2006/math")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("ContentType"), + BAD_CAST("http://schemas.openxmlformats.org/package/2006/content-types")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("lc"), + BAD_CAST("http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas")); + xmlXPathRegisterNs( + pXmlXpathCtx, BAD_CAST("cp"), + BAD_CAST("http://schemas.openxmlformats.org/package/2006/metadata/core-properties")); + xmlXPathRegisterNs( + pXmlXpathCtx, BAD_CAST("extended-properties"), + BAD_CAST("http://schemas.openxmlformats.org/officeDocument/2006/extended-properties")); + xmlXPathRegisterNs( + pXmlXpathCtx, BAD_CAST("custom-properties"), + BAD_CAST("http://schemas.openxmlformats.org/officeDocument/2006/custom-properties")); + xmlXPathRegisterNs( + pXmlXpathCtx, BAD_CAST("vt"), + BAD_CAST("http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("dcterms"), BAD_CAST("http://purl.org/dc/terms/")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("a14"), + BAD_CAST("http://schemas.microsoft.com/office/drawing/2010/main")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("c"), + BAD_CAST("http://schemas.openxmlformats.org/drawingml/2006/chart")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("o"), + BAD_CAST("urn:schemas-microsoft-com:office:office")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("w10"), + BAD_CAST("urn:schemas-microsoft-com:office:word")); +} + +void Test::loadAndSave(const OUString& rURL, const OUString& rFilterName) +{ + mxComponent = loadFromDesktop(rURL); + uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); + utl::MediaDescriptor aMediaDescriptor; + aMediaDescriptor["FilterName"] <<= rFilterName; + maTempFile.EnableKillingFile(); + xStorable->storeToURL(maTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); + mxComponent->dispose(); + mxComponent.clear(); + // too many DOCX validation errors right now + if (rFilterName != "Office Open XML Text") + { + validate(maTempFile.GetFileName(), test::OOXML); + } +} + +constexpr OUStringLiteral DATA_DIRECTORY = u"/oox/qa/unit/data/"; + +CPPUNIT_TEST_FIXTURE(Test, testDmlGroupshapePolygon) +{ + // Given a document with a group shape, containing a single polygon child shape: + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "dml-groupshape-polygon.docx"; + + // When saving that to DOCX: + loadAndSave(aURL, "Office Open XML Text"); + + // Then make sure that the group shape, the group shape's child size and the child shape's size + // match: + uno::Reference<packages::zip::XZipFileAccess2> xNameAccess + = packages::zip::ZipFileAccess::createWithURL(mxComponentContext, getTempFile().GetURL()); + uno::Reference<io::XInputStream> xInputStream(xNameAccess->getByName("word/document.xml"), + uno::UNO_QUERY); + std::unique_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true)); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + assertXPath(pXmlDoc, "//wpg:grpSpPr/a:xfrm/a:ext", "cx", "5328360"); + // Without the accompanying fix in place, this test would have failed, the <a:chExt> element was + // not written. + assertXPath(pXmlDoc, "//wpg:grpSpPr/a:xfrm/a:chExt", "cx", "5328360"); + assertXPath(pXmlDoc, "//wps:spPr/a:xfrm/a:ext", "cx", "5328360"); +} +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |