diff options
author | Regina Henschel <rb.henschel@t-online.de> | 2022-10-28 15:39:38 +0200 |
---|---|---|
committer | Regina Henschel <rb.henschel@t-online.de> | 2022-10-28 19:49:00 +0200 |
commit | 2406ba67c8c03b0d6a4adb81f1efc1609c8dfe8c (patch) | |
tree | b701c1d4260602b8f731bb901cc1194ae602477c | |
parent | f546f7573158e52359bbeae6194a83a1ff8ac52c (diff) |
tdf#54095 docx SmartArt import, apply theme text color
PPTShapeGroupContext uses method applyFontRefColor in importExtDrawings
to bring the theme text color to the shape text. The patch copies this
way to ShapeContextHandler, which is used for SmartArt in docx.
Change-Id: Ie0c0453d6a1fd73fbd4b65246aed9570646dc6f0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141992
Tested-by: Jenkins
Reviewed-by: Regina Henschel <rb.henschel@t-online.de>
-rw-r--r-- | include/oox/shape/ShapeContextHandler.hxx | 5 | ||||
-rw-r--r-- | oox/qa/unit/data/tdf54095_SmartArtThemeTextColor.docx | bin | 0 -> 21161 bytes | |||
-rw-r--r-- | oox/qa/unit/shape.cxx | 54 | ||||
-rw-r--r-- | oox/source/shape/ShapeContextHandler.cxx | 13 |
4 files changed, 71 insertions, 1 deletions
diff --git a/include/oox/shape/ShapeContextHandler.hxx b/include/oox/shape/ShapeContextHandler.hxx index 239ff8ec63b8..42e884f27daa 100644 --- a/include/oox/shape/ShapeContextHandler.hxx +++ b/include/oox/shape/ShapeContextHandler.hxx @@ -21,6 +21,7 @@ #include <memory> #include <stack> #include <cppuhelper/implbase.hxx> +#include <oox/drawingml/color.hxx> #include <oox/drawingml/graphicshapecontext.hxx> #include <oox/core/fragmenthandler2.hxx> #include <oox/core/xmlfilterbase.hxx> @@ -151,8 +152,10 @@ private: css::uno::Reference<XFastContextHandler> const & getWpsContext(sal_Int32 nStartElement, sal_Int32 nElement); css::uno::Reference<XFastContextHandler> const & getWpgContext(sal_Int32 nElement); css::uno::Reference<XFastContextHandler> getContextHandler(sal_Int32 nElement = 0); -}; + void applyFontRefColor(const oox::drawingml::ShapePtr& pShape, + const oox::drawingml::Color& rFontRefColor); +}; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/qa/unit/data/tdf54095_SmartArtThemeTextColor.docx b/oox/qa/unit/data/tdf54095_SmartArtThemeTextColor.docx Binary files differnew file mode 100644 index 000000000000..8aff8469bb41 --- /dev/null +++ b/oox/qa/unit/data/tdf54095_SmartArtThemeTextColor.docx diff --git a/oox/qa/unit/shape.cxx b/oox/qa/unit/shape.cxx index 06d7eba9dffd..9a85db9f3894 100644 --- a/oox/qa/unit/shape.cxx +++ b/oox/qa/unit/shape.cxx @@ -19,6 +19,7 @@ #include <com/sun/star/drawing/XDrawPagesSupplier.hpp> #include <com/sun/star/frame/Desktop.hpp> #include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/text/XTextRange.hpp> #include <officecfg/Office/Common.hxx> #include <rtl/math.hxx> @@ -260,6 +261,59 @@ CPPUNIT_TEST_FIXTURE(OoxShapeTest, testTdf151518VertAnchor) } } +CPPUNIT_TEST_FIXTURE(OoxShapeTest, testTdf54095_SmartArtThemeTextColor) +{ + // The document contains a SmartArt where the color for the texts in the shapes is given by + // the theme. + // Error was, that the theme was not considered and therefore the text was white. + + // Make sure it is not loaded as metafile but with single shapes. + bool bUseGroup = officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::get(); + if (!bUseGroup) + { + std::shared_ptr<comphelper::ConfigurationChanges> pChange( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::set(true, pChange); + pChange->commit(); + } + + // get SmartArt + loadFromURL(u"tdf54095_SmartArtThemeTextColor.docx"); + uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), + uno::UNO_QUERY); + uno::Reference<drawing::XShapes> xSmartArt(xDrawPage->getByIndex(0), uno::UNO_QUERY); + // shape 0 is the background shape without text + uno::Reference<text::XTextRange> xShape(xSmartArt->getByIndex(1), uno::UNO_QUERY); + + // text color + uno::Reference<container::XEnumerationAccess> xText(xShape->getText(), uno::UNO_QUERY); + uno::Reference<container::XEnumerationAccess> xPara(xText->createEnumeration()->nextElement(), + uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xPortion(xPara->createEnumeration()->nextElement(), + uno::UNO_QUERY); + sal_Int32 nActualColor{ 0 }; + xPortion->getPropertyValue("CharColor") >>= nActualColor; + // Without fix the test would have failed with: + // - Expected: 2050429 (0x1F497D) + // - Actual : 16777215 (0xFFFFFF), that is text was white + CPPUNIT_ASSERT_EQUAL(sal_Int32(0x1F497D), nActualColor); + + // clrScheme. For map between name in docx and index from CharColorTheme see + // oox::drawingml::Color::getSchemeColorIndex() + // Without fix the color scheme was "lt1" (1) but should be "dk2" (2). + CPPUNIT_ASSERT_EQUAL(sal_Int16(2), + xPortion->getPropertyValue("CharColorTheme").get<sal_Int16>()); + + if (!bUseGroup) + { + std::shared_ptr<comphelper::ConfigurationChanges> pChange( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::set(false, pChange); + pChange->commit(); + } +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/shape/ShapeContextHandler.cxx b/oox/source/shape/ShapeContextHandler.cxx index 4e8329c1417d..91201fea45f4 100644 --- a/oox/source/shape/ShapeContextHandler.cxx +++ b/oox/source/shape/ShapeContextHandler.cxx @@ -429,6 +429,9 @@ ShapeContextHandler::getShape() pShapePtr->setDiagramDoms(mpShape->getDiagramDoms()); pShapePtr->keepDiagramDrawing(*mxShapeFilterBase, aFragmentPath); + if (mpShape->getFontRefColorForNodes().isUsed()) + applyFontRefColor(pShapePtr, mpShape->getFontRefColorForNodes()); + // migrate IDiagramHelper to new oox::Shape (from mpShape which was loaded // to pShapePtr where the geometry is now constructed) mpShape->migrateDiagramHelperToNewShape(pShapePtr); @@ -586,6 +589,16 @@ void ShapeContextHandler::setGraphicMapper(css::uno::Reference<css::graphic::XGr mxShapeFilterBase->setGraphicMapper(rxGraphicMapper); } +void ShapeContextHandler::applyFontRefColor(const oox::drawingml::ShapePtr& pShape, + const oox::drawingml::Color& rFontRefColor) +{ + pShape->getShapeStyleRefs()[XML_fontRef].maPhClr = rFontRefColor; + std::vector<oox::drawingml::ShapePtr>& vChildren = pShape->getChildren(); + for (auto const& child : vChildren) + { + applyFontRefColor(child, rFontRefColor); + } +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |