[Libreoffice-commits] core.git: oox/CppunitTest_oox_drawingml.mk oox/Module_oox.mk oox/qa oox/source
Miklos Vajna (via logerrit)
logerrit at kemper.freedesktop.org
Thu Nov 21 21:04:42 UTC 2019
oox/CppunitTest_oox_drawingml.mk | 45 ++++++++++
oox/Module_oox.mk | 1
oox/qa/unit/data/transparent-text.pptx |binary
oox/qa/unit/drawingml.cxx | 100 +++++++++++++++++++++++
oox/source/drawingml/textcharacterproperties.cxx | 10 ++
oox/source/export/drawingml.cxx | 12 ++
oox/source/token/properties.txt | 1
7 files changed, 167 insertions(+), 2 deletions(-)
New commits:
commit 1e64d9ebaa231caef5fb062009b8f76465e415f4
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Thu Nov 21 17:53:35 2019 +0100
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Thu Nov 21 22:03:04 2019 +0100
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).
Change-Id: I9a2810691f12604d240e4394e6a5ff4e7f52f1c1
Reviewed-on: https://gerrit.libreoffice.org/83412
Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
Tested-by: Jenkins
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 636f9f6ece99..6078a7e24c0c 100644
--- a/oox/Module_oox.mk
+++ b/oox/Module_oox.mk
@@ -26,6 +26,7 @@ $(eval $(call gb_Module_add_check_targets,oox,\
CppunitTest_oox_vba_encryption \
CppunitTest_oox_crypto \
CppunitTest_oox_mathml \
+ 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
Binary files /dev/null and b/oox/qa/unit/data/transparent-text.pptx 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 2cc160d05b57..5dc696259649 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 db44e176ef33..a319b2bd42a9 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
More information about the Libreoffice-commits
mailing list