summaryrefslogtreecommitdiff
path: root/oox
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2019-11-21 17:53:35 +0100
committerMiklos Vajna <vmiklos@collabora.com>2020-05-11 09:32:18 +0200
commit8c9d925e2030ee58f4fb2afd7f6e4737de1b2d9c (patch)
tree4a9f71d69ce391b40308711f68860a608bc10889 /oox
parentd91a2c8691f50806ec68d163edb38ccb4b011bd9 (diff)
oox: add PPTX import/export for semi-transparent shape text
And start a drawingml test suite in oox, so the test and the tested code is close to each other (just like how it's done in chart2/ already). (cherry picked from commit 1e64d9ebaa231caef5fb062009b8f76465e415f4) Conflicts: oox/Module_oox.mk Change-Id: I9a2810691f12604d240e4394e6a5ff4e7f52f1c1
Diffstat (limited to 'oox')
-rw-r--r--oox/CppunitTest_oox_drawingml.mk45
-rw-r--r--oox/Module_oox.mk1
-rw-r--r--oox/qa/unit/data/transparent-text.pptxbin0 -> 32797 bytes
-rw-r--r--oox/qa/unit/drawingml.cxx100
-rw-r--r--oox/source/drawingml/textcharacterproperties.cxx10
-rw-r--r--oox/source/export/drawingml.cxx12
-rw-r--r--oox/source/token/properties.txt1
7 files changed, 167 insertions, 2 deletions
diff --git a/oox/CppunitTest_oox_drawingml.mk b/oox/CppunitTest_oox_drawingml.mk
new file mode 100644
index 000000000000..dd0288074e32
--- /dev/null
+++ b/oox/CppunitTest_oox_drawingml.mk
@@ -0,0 +1,45 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#*************************************************************************
+#
+# 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/.
+#
+#*************************************************************************
+
+$(eval $(call gb_CppunitTest_CppunitTest,oox_drawingml))
+
+$(eval $(call gb_CppunitTest_use_externals,oox_drawingml,\
+ boost_headers \
+))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,oox_drawingml, \
+ oox/qa/unit/drawingml \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,oox_drawingml, \
+ comphelper \
+ cppu \
+ oox \
+ sal \
+ test \
+ unotest \
+ utl \
+))
+
+$(eval $(call gb_CppunitTest_use_sdk_api,oox_drawingml))
+
+$(eval $(call gb_CppunitTest_use_ure,oox_drawingml))
+$(eval $(call gb_CppunitTest_use_vcl,oox_drawingml))
+
+$(eval $(call gb_CppunitTest_use_rdb,oox_drawingml,services))
+
+$(eval $(call gb_CppunitTest_use_custom_headers,oox_drawingml,\
+ officecfg/registry \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,oox_drawingml))
+
+# vim: set noet sw=4 ts=4:
diff --git a/oox/Module_oox.mk b/oox/Module_oox.mk
index 540b9a8d2ba0..fe22e7344dd5 100644
--- a/oox/Module_oox.mk
+++ b/oox/Module_oox.mk
@@ -28,6 +28,7 @@ $(eval $(call gb_Module_add_check_targets,oox,\
CppunitTest_oox_mathml \
CppunitTest_oox_vml \
CppunitTest_oox_shape \
+ CppunitTest_oox_drawingml \
))
# vim: set noet sw=4 ts=4:
diff --git a/oox/qa/unit/data/transparent-text.pptx b/oox/qa/unit/data/transparent-text.pptx
new file mode 100644
index 000000000000..b7b3ede4dc3d
--- /dev/null
+++ b/oox/qa/unit/data/transparent-text.pptx
Binary files differ
diff --git a/oox/qa/unit/drawingml.cxx b/oox/qa/unit/drawingml.cxx
new file mode 100644
index 000000000000..e3c455c04867
--- /dev/null
+++ b/oox/qa/unit/drawingml.cxx
@@ -0,0 +1,100 @@
+/* -*- 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 <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
+#include <com/sun/star/embed/XStorage.hpp>
+#include <com/sun/star/frame/Desktop.hpp>
+#include <com/sun/star/frame/XStorable.hpp>
+
+#include <comphelper/embeddedobjectcontainer.hxx>
+#include <comphelper/processfactory.hxx>
+#include <comphelper/propertyvalue.hxx>
+#include <comphelper/scopeguard.hxx>
+#include <comphelper/storagehelper.hxx>
+#include <unotools/mediadescriptor.hxx>
+#include <unotools/tempfile.hxx>
+
+using namespace ::com::sun::star;
+
+/// oox drawingml tests.
+class OoxDrawingmlTest : public test::BootstrapFixture, public unotest::MacrosTest
+{
+private:
+ uno::Reference<uno::XComponentContext> mxComponentContext;
+ uno::Reference<lang::XComponent> mxComponent;
+
+public:
+ void setUp() override;
+ void tearDown() override;
+ uno::Reference<lang::XComponent>& getComponent() { return mxComponent; }
+ void loadAndReload(const OUString& rURL, const OUString& rFilterName);
+};
+
+void OoxDrawingmlTest::setUp()
+{
+ test::BootstrapFixture::setUp();
+
+ mxComponentContext.set(comphelper::getComponentContext(getMultiServiceFactory()));
+ mxDesktop.set(frame::Desktop::create(mxComponentContext));
+}
+
+void OoxDrawingmlTest::tearDown()
+{
+ if (mxComponent.is())
+ mxComponent->dispose();
+
+ test::BootstrapFixture::tearDown();
+}
+
+void OoxDrawingmlTest::loadAndReload(const OUString& rURL, const OUString& rFilterName)
+{
+ mxComponent = loadFromDesktop(rURL);
+ uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
+ utl::MediaDescriptor aMediaDescriptor;
+ aMediaDescriptor["FilterName"] <<= rFilterName;
+ utl::TempFile aTempFile;
+ xStorable->storeToURL(aTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
+ mxComponent->dispose();
+ validate(aTempFile.GetFileName(), test::OOXML);
+ mxComponent = loadFromDesktop(aTempFile.GetURL());
+}
+
+char const DATA_DIRECTORY[] = "/oox/qa/unit/data/";
+
+CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testTransparentText)
+{
+ OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "transparent-text.pptx";
+ loadAndReload(aURL, "Impress Office Open XML");
+
+ uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(getComponent(), uno::UNO_QUERY);
+ uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
+ uno::UNO_QUERY);
+ uno::Reference<container::XEnumerationAccess> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
+ uno::Reference<container::XEnumerationAccess> xParagraph(
+ xShape->createEnumeration()->nextElement(), uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xPortion(xParagraph->createEnumeration()->nextElement(),
+ uno::UNO_QUERY);
+
+ sal_Int16 nTransparency = 0;
+ xPortion->getPropertyValue("CharTransparence") >>= nTransparency;
+
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 75
+ // - Actual : 0
+ // i.e. the transparency of the character color was lost on import/export.
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(75), nTransparency);
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oox/source/drawingml/textcharacterproperties.cxx b/oox/source/drawingml/textcharacterproperties.cxx
index e2f5cc63c0a2..de47058e60ca 100644
--- a/oox/source/drawingml/textcharacterproperties.cxx
+++ b/oox/source/drawingml/textcharacterproperties.cxx
@@ -109,7 +109,15 @@ void TextCharacterProperties::pushToPropMap( PropertyMap& rPropMap, const XmlFil
}
if ( maFillProperties.moFillType.has() )
- rPropMap.setProperty( PROP_CharColor, maFillProperties.getBestSolidColor().getColor( rFilter.getGraphicHelper() ));
+ {
+ Color aColor = maFillProperties.getBestSolidColor();
+ rPropMap.setProperty(PROP_CharColor, aColor.getColor(rFilter.getGraphicHelper()));
+
+ if (aColor.hasTransparency())
+ {
+ rPropMap.setProperty(PROP_CharTransparence, aColor.getTransparency());
+ }
+ }
if( moLang.has() && !moLang.get().isEmpty() )
{
diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx
index 4259feb2ae81..8ca75aaa9522 100644
--- a/oox/source/export/drawingml.cxx
+++ b/oox/source/export/drawingml.cxx
@@ -1883,13 +1883,23 @@ void DrawingML::WriteRunProperties( const Reference< XPropertySet >& rRun, bool
::Color color( *o3tl::doAccess<sal_uInt32>(mAny) );
SAL_INFO("oox.shape", "run color: " << sal_uInt32(color) << " auto: " << sal_uInt32(COL_AUTO));
+ // WriteSolidFill() handles MAX_PERCENT as "no transparency".
+ sal_Int32 nTransparency = MAX_PERCENT;
+ if (rXPropSet->getPropertySetInfo()->hasPropertyByName("CharTransparence"))
+ {
+ rXPropSet->getPropertyValue("CharTransparence") >>= nTransparency;
+ // UNO scale is 0..100, OOXML scale is 0..100000; also UNO tracks transparency, OOXML
+ // tracks opacity.
+ nTransparency = MAX_PERCENT - (nTransparency * PER_PERCENT);
+ }
+
// tdf#104219 In LibreOffice and MS Office, there are two types of colors:
// Automatic and Fixed. OOXML is setting automatic color, by not providing color.
if( color != COL_AUTO )
{
color.SetTransparency(0);
// TODO: special handle embossed/engraved
- WriteSolidFill( color );
+ WriteSolidFill(color, nTransparency);
}
}
diff --git a/oox/source/token/properties.txt b/oox/source/token/properties.txt
index f53b73f8b79e..2a9295367c11 100644
--- a/oox/source/token/properties.txt
+++ b/oox/source/token/properties.txt
@@ -82,6 +82,7 @@ CharPostureComplex
CharShadowed
CharStrikeout
CharStyleName
+CharTransparence
CharUnderline
CharUnderlineColor
CharUnderlineHasColor