include/oox/drawingml/color.hxx         |    2 +-
 oox/qa/unit/data/theme-tint.pptx        |binary
 oox/qa/unit/drawingml.cxx               |   32 ++++++++++++++++++++++++++++++++
 oox/source/drawingml/color.cxx          |    2 +-
 oox/source/drawingml/fillproperties.cxx |    2 +-
 5 files changed, 35 insertions(+), 3 deletions(-)

New commits:
commit f932b00f3a72dd802a6e50af84c3dc55072a22a0
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Thu May 5 20:18:06 2022 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Fri May 6 08:13:08 2022 +0200

    tdf#148929 sd theme: limit PPTX import for shape fill effects to lum mod/off
    
    Regression from 30735bdb5a0a81619000fdd24b2d0fbf45687f01 (sd theme: add PPTX
    import for shape fill color effects, 2022-04-27), the bugdoc's A2 cell
    lost its tinting (its background color is no longer lighter than A1)
    after saving back to PPTX + import again.
    
    The code assumed that in case a fill color has effects, it can only be
    luminance offset or modulation, since that's what the PowerPoint UI
    generates when setting a fill color explicitly. This did not take the
    table style case into account, which uses tinting to make a color
    lighter.
    
    Fix the problem by not importing the theme index / effects if tinting is
    used -- the current doc model is limited to theme index + lum mod/off
    with effects.
    
    This limitation can be removed while text color / fill color effects are
    not limited to lum mod/off, but also support tinting/shading.
    
    Change-Id: I382cc0067518cc262e261a462999170cb7db261b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133908
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/include/oox/drawingml/color.hxx b/include/oox/drawingml/color.hxx
index cc65c1346720..b28c926986ca 100644
--- a/include/oox/drawingml/color.hxx
+++ b/include/oox/drawingml/color.hxx
@@ -99,7 +99,7 @@ public:
     /** Returns the scheme name from the a:schemeClr element for 
interoperability purposes */
     const OUString&     getSchemeColorName() const { return msSchemeName; }
     sal_Int16           getSchemeColorIndex() const;
-    sal_Int16           getTintOrShade();
+    sal_Int16           getTintOrShade() const;
     sal_Int16           getLumMod() const;
     sal_Int16           getLumOff() const;
 
diff --git a/oox/qa/unit/data/theme-tint.pptx b/oox/qa/unit/data/theme-tint.pptx
new file mode 100644
index 000000000000..23ab7589dea0
Binary files /dev/null and b/oox/qa/unit/data/theme-tint.pptx differ
diff --git a/oox/qa/unit/drawingml.cxx b/oox/qa/unit/drawingml.cxx
index 9ae434717fb8..4dc066f98039 100644
--- a/oox/qa/unit/drawingml.cxx
+++ b/oox/qa/unit/drawingml.cxx
@@ -29,6 +29,7 @@
 #include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
 #include <com/sun/star/drawing/XMasterPageTarget.hpp>
 #include <com/sun/star/text/XTextRange.hpp>
+#include <com/sun/star/table/XCellRange.hpp>
 
 #include <unotools/mediadescriptor.hxx>
 #include <unotools/tempfile.hxx>
@@ -509,6 +510,37 @@ CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, 
testTdf132557_footerCustomShapes)
                          xShapeSlideNum->getShapeType());
 }
 
+CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testThemeTint)
+{
+    // Given a document with a table style, using theme color with tinting in 
the A2 cell:
+    OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"theme-tint.pptx";
+
+    // When loading that document:
+    load(aURL);
+
+    // Then make sure that we only import theming info to the doc model if the 
effects are limited
+    // to lum mod / off that we can handle (i.e. no tint/shade):
+    uno::Reference<drawing::XDrawPagesSupplier> 
xDrawPagesSupplier(getComponent(), uno::UNO_QUERY);
+    uno::Reference<drawing::XDrawPage> 
xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
+                                                 uno::UNO_QUERY);
+    uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(0), 
uno::UNO_QUERY);
+    uno::Reference<table::XCellRange> xTable;
+    CPPUNIT_ASSERT(xShape->getPropertyValue("Model") >>= xTable);
+    uno::Reference<beans::XPropertySet> xA1(xTable->getCellByPosition(0, 0), 
uno::UNO_QUERY);
+    sal_Int16 nFillColorTheme{};
+    CPPUNIT_ASSERT(xA1->getPropertyValue("FillColorTheme") >>= 
nFillColorTheme);
+    // This is OK, no problematic effects:
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(4), nFillColorTheme);
+    uno::Reference<beans::XPropertySet> xA2(xTable->getCellByPosition(0, 1), 
uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xA2->getPropertyValue("FillColorTheme") >>= 
nFillColorTheme);
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: -1
+    // - Actual  : 4
+    // i.e. we remembered the theme index, without being able to remember the 
tint effect, leading
+    // to a bad background color.
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(-1), nFillColorTheme);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oox/source/drawingml/color.cxx b/oox/source/drawingml/color.cxx
index 982b77ff4831..f810deecf2bf 100644
--- a/oox/source/drawingml/color.cxx
+++ b/oox/source/drawingml/color.cxx
@@ -479,7 +479,7 @@ void Color::clearTransparence()
     mnAlpha = MAX_PERCENT;
 }
 
-sal_Int16 Color::getTintOrShade()
+sal_Int16 Color::getTintOrShade() const
 {
     for(auto const& aTransform : maTransforms)
     {
diff --git a/oox/source/drawingml/fillproperties.cxx 
b/oox/source/drawingml/fillproperties.cxx
index 2d85bf807e1a..98b9e2f93e73 100644
--- a/oox/source/drawingml/fillproperties.cxx
+++ b/oox/source/drawingml/fillproperties.cxx
@@ -397,7 +397,7 @@ void FillProperties::pushToPropMap( ShapePropertyMap& 
rPropMap,
                 {
                     rPropMap.setProperty(PROP_FillColorTheme, nPhClrTheme);
                 }
-                else
+                else if (maFillColor.getTintOrShade() == 0)
                 {
                     rPropMap.setProperty(PROP_FillColorTheme, 
maFillColor.getSchemeColorIndex());
                     rPropMap.setProperty(PROP_FillColorLumMod, 
maFillColor.getLumMod());

Reply via email to