oox/source/export/drawingml.cxx            |   17 +++++++++++
 sd/qa/unit/data/odp/tdf94122_autocolor.odp |binary
 sd/qa/unit/export-tests-ooxml3.cxx         |   42 +++++++++++++++++++++++++++++
 3 files changed, 59 insertions(+)

New commits:
commit 79ea27ec4418b82af5ba2187ae59cd9c0874060b
Author:     Sarper Akdemir <sarper.akde...@collabora.com>
AuthorDate: Fri Sep 16 03:46:45 2022 +0300
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue Sep 20 08:23:01 2022 +0200

    tdf#94122 pptx export: fix automatic text color export
    
    MS Powerpoint doesn't have automatic colors unlike Word or Excel.
    
    Therefore on export the automatic text color should be first resolved
    and then exported.
    
    Change-Id: Ied2c3a4235da403350d8518a3414ff6a372b57a8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140059
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx
index 85e73eb35c85..387bbf5c8d6d 100644
--- a/oox/source/export/drawingml.cxx
+++ b/oox/source/export/drawingml.cxx
@@ -2299,6 +2299,23 @@ void DrawingML::WriteRunProperties( const Reference< 
XPropertySet >& rRun, bool
                     WriteSolidFill(color, nTransparency);
                 }
             }
+            else if (GetDocumentType() == DOCUMENT_PPTX)
+            {
+                // Resolve COL_AUTO for PPTX since MS Powerpoint doesn't have 
automatic colors.
+                bool bIsTextBackgroundDark = mbIsBackgroundDark;
+                if (rXShapePropSet.is() && GetProperty(rXShapePropSet, 
"FillStyle")
+                    && mAny.get<FillStyle>() != FillStyle_NONE
+                    && GetProperty(rXShapePropSet, "FillColor"))
+                {
+                    ::Color aShapeFillColor(ColorTransparency, 
mAny.get<sal_uInt32>());
+                    bIsTextBackgroundDark = aShapeFillColor.IsDark();
+                }
+
+                if (bIsTextBackgroundDark)
+                    WriteSolidFill(COL_WHITE);
+                else
+                    WriteSolidFill(COL_BLACK);
+            }
         }
     }
 
diff --git a/sd/qa/unit/data/odp/tdf94122_autocolor.odp 
b/sd/qa/unit/data/odp/tdf94122_autocolor.odp
new file mode 100644
index 000000000000..921533cbead6
Binary files /dev/null and b/sd/qa/unit/data/odp/tdf94122_autocolor.odp differ
diff --git a/sd/qa/unit/export-tests-ooxml3.cxx 
b/sd/qa/unit/export-tests-ooxml3.cxx
index dd79bb47f6a7..c12a1f0ec4bd 100644
--- a/sd/qa/unit/export-tests-ooxml3.cxx
+++ b/sd/qa/unit/export-tests-ooxml3.cxx
@@ -121,6 +121,7 @@ public:
     void testTdf144092_emptyShapeTextProps();
     void testTdf149551_tbrl90();
     void testTdf149551_btlr();
+    void testTdf94122_autoColor();
 
     CPPUNIT_TEST_SUITE(SdOOXMLExportTest3);
 
@@ -207,6 +208,7 @@ public:
     CPPUNIT_TEST(testTdf144092_emptyShapeTextProps);
     CPPUNIT_TEST(testTdf149551_tbrl90);
     CPPUNIT_TEST(testTdf149551_btlr);
+    CPPUNIT_TEST(testTdf94122_autoColor);
     CPPUNIT_TEST_SUITE_END();
 
     virtual void registerNamespaces(xmlXPathContextPtr& pXmlXPathCtx) override
@@ -2218,6 +2220,46 @@ void SdOOXMLExportTest3::testTdf149551_btlr()
     xDocShRef->DoClose();
 }
 
+void SdOOXMLExportTest3::testTdf94122_autoColor()
+{
+    // Document contains three pages, with different scenarios for automatic
+    // color export to pptx.
+    // - First page: Page background light, automatic colored text on a 
FillType_NONE shape
+    // - Second page: Page background dark, automatic colored text on a 
FillType_NONE shape
+    // - Third page: Page background light, automatic colored text on a dark 
colored fill
+    //   and another automatic colored text on a light colored fill
+    ::sd::DrawDocShellRef xDocShRef
+        = 
loadURL(m_directories.getURLFromSrc(u"sd/qa/unit/data/odp/tdf94122_autocolor.odp"),
 ODP);
+
+    utl::TempFile tempFile;
+    xDocShRef = saveAndReload(xDocShRef.get(), PPTX, &tempFile);
+    xDocShRef->DoClose();
+
+    // Without the accompanying fix in place, these tests would have failed 
with:
+    // - Expected: 1
+    // - Actual  : 0
+    // - In ..., XPath 
'/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:p/a:r/a:rPr/a:solidFill/a:srgbClr' 
number of nodes is incorrect
+    // i.e. automatic color wasn't resolved & exported
+
+    xmlDocUniquePtr pXmlDocContent1 = parseExport(tempFile, 
"ppt/slides/slide1.xml");
+    assertXPath(pXmlDocContent1,
+                
"/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:p/a:r/a:rPr/a:solidFill/a:srgbClr", 
"val",
+                "000000");
+
+    xmlDocUniquePtr pXmlDocContent2 = parseExport(tempFile, 
"ppt/slides/slide2.xml");
+    assertXPath(pXmlDocContent2,
+                
"/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:p/a:r/a:rPr/a:solidFill/a:srgbClr", 
"val",
+                "ffffff");
+
+    xmlDocUniquePtr pXmlDocContent3 = parseExport(tempFile, 
"ppt/slides/slide3.xml");
+    assertXPath(pXmlDocContent3,
+                
"/p:sld/p:cSld/p:spTree/p:sp[1]/p:txBody/a:p/a:r/a:rPr/a:solidFill/a:srgbClr",
+                "val", "ffffff");
+    assertXPath(pXmlDocContent3,
+                
"/p:sld/p:cSld/p:spTree/p:sp[2]/p:txBody/a:p/a:r/a:rPr/a:solidFill/a:srgbClr",
+                "val", "000000");
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SdOOXMLExportTest3);
 
 CPPUNIT_PLUGIN_IMPLEMENT();

Reply via email to