oox/source/shape/WpsContext.cxx                  |   64 ++++++++++++++++++-----
 sw/qa/extras/ooxmlexport/data/tdf135923-min.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport17.cxx       |   11 +++
 3 files changed, 63 insertions(+), 12 deletions(-)

New commits:
commit 49a40e3ed200e7c6d728f36d0b4be22dd85c51be
Author:     Tünde Tóth <toth.tu...@nisz.hu>
AuthorDate: Thu Mar 3 11:25:31 2022 +0100
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Tue Mar 29 13:01:18 2022 +0200

    tdf#135923 DOCX shape import: set text color
    
    to the character color of the shape if it is not comes
    from direct formatting.
    
    Change-Id: I3f0a3e952b5449a6d92c5bb273d353a561f3e3dc
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130922
    Tested-by: László Németh <nem...@numbertext.org>
    Reviewed-by: László Németh <nem...@numbertext.org>

diff --git a/oox/source/shape/WpsContext.cxx b/oox/source/shape/WpsContext.cxx
index d39f93fc8402..604065be9aad 100644
--- a/oox/source/shape/WpsContext.cxx
+++ b/oox/source/shape/WpsContext.cxx
@@ -15,6 +15,7 @@
 #include <drawingml/customshapeproperties.hxx>
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/beans/XPropertyState.hpp>
+#include <com/sun/star/container/XEnumerationAccess.hpp>
 #include <com/sun/star/drawing/HomogenMatrix3.hpp>
 #include <com/sun/star/lang/XServiceInfo.hpp>
 #include <com/sun/star/text/XText.hpp>
@@ -155,20 +156,59 @@ oox::core::ContextHandlerRef 
WpsContext::onCreateContext(sal_Int32 nElementToken
                 uno::Reference<text::XTextCursor> xTextCursor = 
xText->createTextCursor();
                 xTextCursor->gotoStart(false);
                 xTextCursor->gotoEnd(true);
-                const uno::Reference<beans::XPropertyState> 
xPropertyState(xTextCursor,
-                                                                           
uno::UNO_QUERY);
-                const beans::PropertyState ePropertyState
-                    = xPropertyState->getPropertyState("CharColor");
-                if (ePropertyState == beans::PropertyState_DEFAULT_VALUE)
+                uno::Reference<beans::XPropertySet> 
xTextBoxPropertySet(xTextCursor,
+                                                                        
uno::UNO_QUERY);
+                uno::Any xCharColor = 
xPropertySet->getPropertyValue("CharColor");
+                Color aColor = COL_AUTO;
+                if ((xCharColor >>= aColor) && aColor != COL_AUTO)
                 {
-                    uno::Reference<beans::XPropertySet> 
xTextBoxPropertySet(xTextCursor,
-                                                                            
uno::UNO_QUERY);
-                    uno::Any xCharColor = 
xPropertySet->getPropertyValue("CharColor");
-                    Color aColor = COL_AUTO;
-                    if (xCharColor >>= aColor)
+                    const uno::Reference<beans::XPropertyState> 
xPropertyState(xTextCursor,
+                                                                               
uno::UNO_QUERY);
+                    const beans::PropertyState ePropertyState
+                        = xPropertyState->getPropertyState("CharColor");
+                    if (ePropertyState == beans::PropertyState_DEFAULT_VALUE)
+                    {
+                        xTextBoxPropertySet->setPropertyValue("CharColor", 
xCharColor);
+                    }
+                    else
                     {
-                        if (aColor != COL_AUTO)
-                            xTextBoxPropertySet->setPropertyValue("CharColor", 
xCharColor);
+                        // tdf#135923 Apply character color of the shape to 
the textrun
+                        //            when the character color of the textrun 
is default.
+                        uno::Reference<container::XEnumerationAccess> 
paraEnumAccess(
+                            xText, uno::UNO_QUERY);
+                        if (paraEnumAccess.is())
+                        {
+                            uno::Reference<container::XEnumeration> paraEnum(
+                                paraEnumAccess->createEnumeration());
+
+                            while (paraEnum->hasMoreElements())
+                            {
+                                uno::Reference<text::XTextRange> 
xParagraph(paraEnum->nextElement(),
+                                                                            
uno::UNO_QUERY);
+                                uno::Reference<container::XEnumerationAccess> 
runEnumAccess(
+                                    xParagraph, uno::UNO_QUERY);
+                                if (!runEnumAccess.is())
+                                    continue;
+
+                                uno::Reference<container::XEnumeration> runEnum
+                                    = runEnumAccess->createEnumeration();
+
+                                while (runEnum->hasMoreElements())
+                                {
+                                    uno::Reference<text::XTextRange> 
xRun(runEnum->nextElement(),
+                                                                          
uno::UNO_QUERY);
+                                    const 
uno::Reference<beans::XPropertyState> xRunState(
+                                        xRun, uno::UNO_QUERY);
+                                    if 
(xRunState->getPropertyState("CharColor")
+                                        == beans::PropertyState_DEFAULT_VALUE)
+                                    {
+                                        uno::Reference<beans::XPropertySet> 
xRunPropSet(
+                                            xRun, uno::UNO_QUERY);
+                                        
xRunPropSet->setPropertyValue("CharColor", xCharColor);
+                                    }
+                                }
+                            }
+                        }
                     }
                 }
 
diff --git a/sw/qa/extras/ooxmlexport/data/tdf135923-min.docx 
b/sw/qa/extras/ooxmlexport/data/tdf135923-min.docx
new file mode 100644
index 000000000000..34bc96421499
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf135923-min.docx 
differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
index 6fc7c4e59ac1..444d4f0bb5f8 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
@@ -419,6 +419,17 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf147978enhancedPathABVW)
     }
 }
 
+DECLARE_OOXMLEXPORT_TEST(testTdf135923, "tdf135923-min.docx")
+{
+    uno::Reference<text::XText> xShape(getShape(1), uno::UNO_QUERY);
+    uno::Reference<text::XTextRange> xParagraph = getParagraphOfText(1, 
xShape);
+
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(COL_WHITE),
+                         getProperty<sal_Int32>(getRun(xParagraph, 1), 
"CharColor"));
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(COL_BLACK),
+                         getProperty<sal_Int32>(getRun(xParagraph, 2), 
"CharColor"));
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to