diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2023-02-24 15:27:07 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2023-02-24 15:00:08 +0000 |
commit | c15412eb96bda1037c12811f5818ed8ce1e603bd (patch) | |
tree | 03d62485593856d1d22fa0939c063ac3dad30609 /oox/source | |
parent | 78ae57d02c2a7e39c452b44855874bb8ad1dbc35 (diff) |
tdf#153791: paragraph's/character's shd overrides shape style's fontRef
I couldn't find any references to this in documentation (ECMA-376, MS-OE376)
regarding this, but Word ignores the font properties (including color) defined
in the shape style's fontRef for txbxContent's paragraphs / runs that have shd
elements with non-auto fill color.
Change-Id: Ice634a5eed7b51379649462303300f55358a566f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147630
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'oox/source')
-rw-r--r-- | oox/source/shape/WpsContext.cxx | 86 |
1 files changed, 40 insertions, 46 deletions
diff --git a/oox/source/shape/WpsContext.cxx b/oox/source/shape/WpsContext.cxx index 9fb3812923b2..ca87085165d8 100644 --- a/oox/source/shape/WpsContext.cxx +++ b/oox/source/shape/WpsContext.cxx @@ -677,62 +677,56 @@ oox::core::ContextHandlerRef WpsContext::onCreateContext(sal_Int32 nElementToken // Apply character color of the shape to the shape's textbox. uno::Reference<text::XText> xText(mxShape, uno::UNO_QUERY); - uno::Reference<text::XTextCursor> xTextCursor = xText->createTextCursor(); - xTextCursor->gotoStart(false); - xTextCursor->gotoEnd(true); - 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) { - 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 + // tdf#135923 Apply character color of the shape to the textrun + // when the character color of the textrun is default. + // tdf#153791 But only if the run has no background color (shd element in OOXML) + if (uno::Reference<container::XEnumerationAccess> paraEnumAccess{ + xText, uno::UNO_QUERY }) { - // 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()); + 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()) + 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; + if (uno::Reference<beans::XPropertySet> xParaPropSet{ xParagraph, + uno::UNO_QUERY }) + if ((xParaPropSet->getPropertyValue("ParaBackColor") >>= aColor) + && aColor != COL_AUTO) continue; - uno::Reference<container::XEnumeration> runEnum - = runEnumAccess->createEnumeration(); + uno::Reference<container::XEnumeration> runEnum + = runEnumAccess->createEnumeration(); - while (runEnum->hasMoreElements()) + 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 + || xRunState->getPropertyState("CharColor") + == beans::PropertyState_DEFAULT_VALUE) { - 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); - Color aRunColor = COL_AUTO; - xRunPropSet->getPropertyValue("CharColor") >>= aRunColor; - if (aRunColor == COL_AUTO) - xRunPropSet->setPropertyValue("CharColor", xCharColor); - } + uno::Reference<beans::XPropertySet> xRunPropSet(xRun, + uno::UNO_QUERY); + if (!xRunPropSet) + continue; + if ((xRunPropSet->getPropertyValue("CharBackColor") >>= aColor) + && aColor != COL_AUTO) + continue; + if (!(xRunPropSet->getPropertyValue("CharColor") >>= aColor) + || aColor == COL_AUTO) + xRunPropSet->setPropertyValue("CharColor", xCharColor); } } } |