diff options
author | Tünde Tóth <toth.tunde@nisz.hu> | 2022-03-03 11:25:31 +0100 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2022-03-29 13:01:18 +0200 |
commit | 49a40e3ed200e7c6d728f36d0b4be22dd85c51be (patch) | |
tree | 9455cd4a8083093ce7fd37ebe120a258a4152112 | |
parent | bc72514f90d90e1ab3fed8167663e835edf03508 (diff) |
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 <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
-rw-r--r-- | oox/source/shape/WpsContext.cxx | 64 | ||||
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/tdf135923-min.docx | bin | 0 -> 16777 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport17.cxx | 11 |
3 files changed, 63 insertions, 12 deletions
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 Binary files differnew file mode 100644 index 000000000000..34bc96421499 --- /dev/null +++ b/sw/qa/extras/ooxmlexport/data/tdf135923-min.docx 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: */ |