diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2020-01-15 21:24:17 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2020-01-16 09:21:02 +0100 |
commit | 3a749d7278bbe65cfc063e64460df8af6bc2af47 (patch) | |
tree | d74c8f37908a61683f9a244f586770f44c5c6686 | |
parent | c99107f6700287fda2be3c7321613cd68b7c404c (diff) |
sw: add DOCX import for semi-transparent text
This is one of the text effects properties, which is already
grab-bagged. That is done in a generic way, so the easiest is to just
read the value from the grab-bag, rather than from the dmapper tokens
directly.
Change-Id: Id74a3eb0abddf745a9e4e59625bf9345f7df9dfe
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86884
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
-rw-r--r-- | writerfilter/CppunitTest_writerfilter_dmapper.mk | 1 | ||||
-rw-r--r-- | writerfilter/qa/cppunittests/dmapper/TextEffectsHandler.cxx | 78 | ||||
-rw-r--r-- | writerfilter/qa/cppunittests/dmapper/data/semi-transparent-text.docx | bin | 0 -> 12738 bytes | |||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper.cxx | 9 | ||||
-rw-r--r-- | writerfilter/source/dmapper/PropertyIds.cxx | 1 | ||||
-rw-r--r-- | writerfilter/source/dmapper/PropertyIds.hxx | 1 | ||||
-rw-r--r-- | writerfilter/source/dmapper/TextEffectsHandler.cxx | 50 | ||||
-rw-r--r-- | writerfilter/source/dmapper/TextEffectsHandler.hxx | 2 |
8 files changed, 141 insertions, 1 deletions
diff --git a/writerfilter/CppunitTest_writerfilter_dmapper.mk b/writerfilter/CppunitTest_writerfilter_dmapper.mk index 41b92e9bdb3e..0beb3e6145a5 100644 --- a/writerfilter/CppunitTest_writerfilter_dmapper.mk +++ b/writerfilter/CppunitTest_writerfilter_dmapper.mk @@ -19,6 +19,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,writerfilter_dmapper, \ writerfilter/qa/cppunittests/dmapper/CellColorHandler \ writerfilter/qa/cppunittests/dmapper/DomainMapperTableHandler \ writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl \ + writerfilter/qa/cppunittests/dmapper/TextEffectsHandler \ )) $(eval $(call gb_CppunitTest_use_libraries,writerfilter_dmapper, \ diff --git a/writerfilter/qa/cppunittests/dmapper/TextEffectsHandler.cxx b/writerfilter/qa/cppunittests/dmapper/TextEffectsHandler.cxx new file mode 100644 index 000000000000..1678aac52773 --- /dev/null +++ b/writerfilter/qa/cppunittests/dmapper/TextEffectsHandler.cxx @@ -0,0 +1,78 @@ +/* -*- 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/frame/Desktop.hpp> +#include <com/sun/star/text/XTextDocument.hpp> + +#include <comphelper/processfactory.hxx> + +using namespace ::com::sun::star; + +namespace +{ +/// Tests for writerfilter/source/dmapper/TextEffectsHandler.cxx. +class Test : 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 Test::setUp() +{ + test::BootstrapFixture::setUp(); + + mxComponentContext.set(comphelper::getComponentContext(getMultiServiceFactory())); + mxDesktop.set(frame::Desktop::create(mxComponentContext)); +} + +void Test::tearDown() +{ + if (mxComponent.is()) + mxComponent->dispose(); + + test::BootstrapFixture::tearDown(); +} + +char const DATA_DIRECTORY[] = "/writerfilter/qa/cppunittests/dmapper/data/"; + +CPPUNIT_TEST_FIXTURE(Test, testSemiTransparentText) +{ + // Load a document with a single paragraph: second text portion has semi-transparent text. + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "semi-transparent-text.docx"; + getComponent() = loadFromDesktop(aURL); + uno::Reference<text::XTextDocument> xTextDocument(getComponent(), uno::UNO_QUERY); + uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(), + uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration(); + uno::Reference<container::XEnumerationAccess> xPara(xParaEnum->nextElement(), uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xPortionEnum = xPara->createEnumeration(); + xPortionEnum->nextElement(); + uno::Reference<beans::XPropertySet> xPortion(xPortionEnum->nextElement(), uno::UNO_QUERY); + sal_Int16 nCharTransparence = 0; + xPortion->getPropertyValue("CharTransparence") >>= nCharTransparence; + + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 74 + // - Actual : 0 + // i.e. text was imported as regular text with solid color only. + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(74), nCharTransparence); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/qa/cppunittests/dmapper/data/semi-transparent-text.docx b/writerfilter/qa/cppunittests/dmapper/data/semi-transparent-text.docx Binary files differnew file mode 100644 index 000000000000..6c0f8a79cbb4 --- /dev/null +++ b/writerfilter/qa/cppunittests/dmapper/data/semi-transparent-text.docx diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx index d02a73016cd1..8a62a2ebda83 100644 --- a/writerfilter/source/dmapper/DomainMapper.cxx +++ b/writerfilter/source/dmapper/DomainMapper.cxx @@ -2658,7 +2658,14 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, const PropertyMapPtr& rContext ) { pProperties->resolve(*pTextEffectsHandlerPtr); - rContext->Insert(*aPropertyId, uno::makeAny(pTextEffectsHandlerPtr->getInteropGrabBag()), true, CHAR_GRAB_BAG); + beans::PropertyValue aGrabBag = pTextEffectsHandlerPtr->getInteropGrabBag(); + rContext->Insert(*aPropertyId, uno::makeAny(aGrabBag), true, CHAR_GRAB_BAG); + + sal_Int16 nTransparency = TextEffectsHandler::GetTextFillSolidFillAlpha(aGrabBag); + if (nTransparency != 0) + { + rContext->Insert(PROP_CHAR_TRANSPARENCE, uno::makeAny(nTransparency)); + } } } } diff --git a/writerfilter/source/dmapper/PropertyIds.cxx b/writerfilter/source/dmapper/PropertyIds.cxx index 0d5740e9fa83..132ec9f63995 100644 --- a/writerfilter/source/dmapper/PropertyIds.cxx +++ b/writerfilter/source/dmapper/PropertyIds.cxx @@ -354,6 +354,7 @@ OUString getPropertyName( PropertyIds eId ) case PROP_COMMAND_TYPE: sName = "DataCommandType"; break; case PROP_DATATABLE_NAME: sName = "DataTableName"; break; case PROP_DATACOLUMN_NAME: sName = "DataColumnName"; break; + case PROP_CHAR_TRANSPARENCE: sName = "CharTransparence"; break; } assert(sName.getLength()>0); return sName; diff --git a/writerfilter/source/dmapper/PropertyIds.hxx b/writerfilter/source/dmapper/PropertyIds.hxx index a1a0c8f851a1..b2e10a13ee46 100644 --- a/writerfilter/source/dmapper/PropertyIds.hxx +++ b/writerfilter/source/dmapper/PropertyIds.hxx @@ -354,6 +354,7 @@ enum PropertyIds ,PROP_COMMAND_TYPE ,PROP_DATATABLE_NAME ,PROP_DATACOLUMN_NAME + ,PROP_CHAR_TRANSPARENCE }; //Returns the UNO string equivalent to eId. diff --git a/writerfilter/source/dmapper/TextEffectsHandler.cxx b/writerfilter/source/dmapper/TextEffectsHandler.cxx index fcefb30295a3..1c0a9da9a26c 100644 --- a/writerfilter/source/dmapper/TextEffectsHandler.cxx +++ b/writerfilter/source/dmapper/TextEffectsHandler.cxx @@ -17,6 +17,8 @@ #include <rtl/ustrbuf.hxx> #include <comphelper/string.hxx> #include <ooxml/resourceids.hxx> +#include <comphelper/sequenceashashmap.hxx> +#include <oox/drawingml/drawingmltypes.hxx> namespace writerfilter { namespace dmapper @@ -749,6 +751,54 @@ beans::PropertyValue TextEffectsHandler::getInteropGrabBag() return aReturn; } +sal_uInt8 TextEffectsHandler::GetTextFillSolidFillAlpha(const css::beans::PropertyValue& rValue) +{ + if (rValue.Name != "textFill") + { + return 0; + } + + uno::Sequence<beans::PropertyValue> aPropertyValues; + rValue.Value >>= aPropertyValues; + comphelper::SequenceAsHashMap aMap(aPropertyValues); + auto it = aMap.find("solidFill"); + if (it == aMap.end()) + { + return 0; + } + + comphelper::SequenceAsHashMap aSolidFillMap(it->second); + it = aSolidFillMap.find("srgbClr"); + if (it == aSolidFillMap.end()) + { + return 0; + } + + comphelper::SequenceAsHashMap aSrgbClrMap(it->second); + it = aSrgbClrMap.find("alpha"); + if (it == aSrgbClrMap.end()) + { + return 0; + } + + comphelper::SequenceAsHashMap aAlphaMap(it->second); + it = aAlphaMap.find("attributes"); + if (it == aAlphaMap.end()) + { + return 0; + } + + comphelper::SequenceAsHashMap aAttributesMap(it->second); + it = aAttributesMap.find("val"); + if (it == aAttributesMap.end()) + { + return 0; + } + sal_Int32 nVal = 0; + it->second >>= nVal; + return nVal / oox::drawingml::PER_PERCENT; +} + }//namespace dmapper } //namespace writerfilter diff --git a/writerfilter/source/dmapper/TextEffectsHandler.hxx b/writerfilter/source/dmapper/TextEffectsHandler.hxx index b4a74715b02c..42718440991a 100644 --- a/writerfilter/source/dmapper/TextEffectsHandler.hxx +++ b/writerfilter/source/dmapper/TextEffectsHandler.hxx @@ -66,6 +66,8 @@ public: static OUString getNumFormString(sal_Int32 nType); static OUString getNumSpacingString(sal_Int32 nType); + static sal_uInt8 GetTextFillSolidFillAlpha(const css::beans::PropertyValue& rValue); + }; }} |