sc/qa/unit/data/xlsx/tdf151818_SmartartThemeFontColor.xlsx |binary
 sc/qa/unit/subsequent_filters_test2.cxx                    |   58 +++++++++++++
 sc/source/filter/inc/drawingfragment.hxx                   |    5 +
 sc/source/filter/oox/drawingfragment.cxx                   |   14 +++
 4 files changed, 77 insertions(+)

New commits:
commit 4d15adebcc492112ca88e36aa7e8799b62d86466
Author:     Regina Henschel <rb.hensc...@t-online.de>
AuthorDate: Sun Oct 30 00:35:31 2022 +0200
Commit:     Regina Henschel <rb.hensc...@t-online.de>
CommitDate: Sun Oct 30 13:30:21 2022 +0100

    tdf#151818 xlsx SmartArt import, apply theme text color
    
    Similar as patch 2406ba67 for tdf#54095 but now for import of
    SmartArt objects in xlsx files.
    
    Change-Id: I12ca8c476fb9d141cef991e8e98ad13b53c70613
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142027
    Tested-by: Jenkins
    Reviewed-by: Regina Henschel <rb.hensc...@t-online.de>

diff --git a/sc/qa/unit/data/xlsx/tdf151818_SmartartThemeFontColor.xlsx 
b/sc/qa/unit/data/xlsx/tdf151818_SmartartThemeFontColor.xlsx
new file mode 100644
index 000000000000..c1851ca3791d
Binary files /dev/null and 
b/sc/qa/unit/data/xlsx/tdf151818_SmartartThemeFontColor.xlsx differ
diff --git a/sc/qa/unit/subsequent_filters_test2.cxx 
b/sc/qa/unit/subsequent_filters_test2.cxx
index 8ae23af8048c..293c7300d7fb 100644
--- a/sc/qa/unit/subsequent_filters_test2.cxx
+++ b/sc/qa/unit/subsequent_filters_test2.cxx
@@ -55,6 +55,7 @@
 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
 #include <com/sun/star/container/XIndexAccess.hpp>
 #include <com/sun/star/text/WritingMode2.hpp>
+#include <com/sun/star/text/XTextRange.hpp>
 
 #include <comphelper/scopeguard.hxx>
 #include <tools/UnitConversion.hxx>
@@ -188,6 +189,7 @@ public:
     void testTooManyColsRows();
     void testTdf83671_SmartArt_import();
     void testTdf83671_SmartArt_import2();
+    void testTdf151818_SmartArtFontColor();
 
     CPPUNIT_TEST_SUITE(ScFiltersTest2);
 
@@ -306,6 +308,7 @@ public:
     CPPUNIT_TEST(testTooManyColsRows);
     CPPUNIT_TEST(testTdf83671_SmartArt_import);
     CPPUNIT_TEST(testTdf83671_SmartArt_import2);
+    CPPUNIT_TEST(testTdf151818_SmartArtFontColor);
 
     CPPUNIT_TEST_SUITE_END();
 };
@@ -3137,6 +3140,61 @@ void ScFiltersTest2::testTdf83671_SmartArt_import2()
     xDocSh->DoClose();
 }
 
+void ScFiltersTest2::testTdf151818_SmartArtFontColor()
+{
+    // 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 document and shape in SmartArt object
+    ScDocShellRef xDocSh = loadDoc(u"tdf151818_SmartartThemeFontColor.", 
FORMAT_XLSX);
+    uno::Reference<drawing::XDrawPagesSupplier> xDoc(xDocSh->GetModel(), 
uno::UNO_QUERY_THROW);
+    uno::Reference<drawing::XDrawPage> 
xPage(xDoc->getDrawPages()->getByIndex(0),
+                                             uno::UNO_QUERY_THROW);
+    uno::Reference<drawing::XShapes> xSmartArt(xPage->getByIndex(0), 
uno::UNO_QUERY_THROW);
+    // 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:  4478058 (0x44546A)
+    // - Actual  : 16777215 (0xFFFFFF), that is text was white
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(0x44546A), nActualColor);
+
+    // clrScheme. For map between name in xlsx 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();
+    }
+
+    xDocSh->DoClose();
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(ScFiltersTest2);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sc/source/filter/inc/drawingfragment.hxx 
b/sc/source/filter/inc/drawingfragment.hxx
index b9fda07553f5..0ba281db09a6 100644
--- a/sc/source/filter/inc/drawingfragment.hxx
+++ b/sc/source/filter/inc/drawingfragment.hxx
@@ -21,6 +21,7 @@
 
 #include <memory>
 #include <oox/drawingml/shapegroupcontext.hxx>
+#include <oox/drawingml/color.hxx>
 #include <oox/ole/axcontrol.hxx>
 #include <oox/drawingml/shape.hxx>
 #include <oox/ole/vbaproject.hxx>
@@ -112,6 +113,10 @@ private:
                         mxDrawPage;             /// Drawing page of this sheet.
     ::oox::drawingml::ShapePtr mxShape;         /// Current top-level shape.
     ShapeAnchorRef      mxAnchor;               /// Current anchor of 
top-level shape.
+    // for SmartArt. Apply the colors in rFontRefColor (from clrScheme) to all 
shapes in pShape,
+    // the group object which represents the SmartArt.
+    void applyFontRefColor(const oox::drawingml::ShapePtr& pShape,
+                           const oox::drawingml::Color& rFontRefColor);
 };
 
 // VML
diff --git a/sc/source/filter/oox/drawingfragment.cxx 
b/sc/source/filter/oox/drawingfragment.cxx
index d61e17331428..5fb1cd029972 100644
--- a/sc/source/filter/oox/drawingfragment.cxx
+++ b/sc/source/filter/oox/drawingfragment.cxx
@@ -325,6 +325,9 @@ void DrawingFragment::onEndElement()
                         mxShape->setId(sBackupId);
                     }
 
+                    if (mxShape->getFontRefColorForNodes().isUsed())
+                          applyFontRefColor(mxShape, 
mxShape->getFontRefColorForNodes());
+
                     basegfx::B2DHomMatrix aTransformation;
                     if ( !bIsShapeVisible)
                         mxShape->setHidden(true);
@@ -355,6 +358,17 @@ void DrawingFragment::onEndElement()
     }
 }
 
+void DrawingFragment::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);
+    }
+}
+
 // VML
 
 namespace {

Reply via email to