From 9ebf7034c9cd3a0601542397254ebc97647a862e Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Fri, 3 Dec 2021 08:38:18 +0100 Subject: svx: consider color effects when updating objects for theme changes This builds on top of commit 48f0c5f73f99c919ec24deadc96c3cf5483c9314 (svx: update objects of pages of a master page when the theme changes, 2021-11-30), but now not only plain colors with colors with effects are also considered. The luminance modulation / offset is what PowerPoint uses the generate lighter / darker variants, tinting / shading is what Word uses. Change-Id: Ibfafb9be9986645117015bf3b05491daec8914be Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126270 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- svx/source/styles/ColorSets.cxx | 42 ++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) (limited to 'svx/source/styles') diff --git a/svx/source/styles/ColorSets.cxx b/svx/source/styles/ColorSets.cxx index a5f8c6e7c548..30a9dd423d78 100644 --- a/svx/source/styles/ColorSets.cxx +++ b/svx/source/styles/ColorSets.cxx @@ -33,6 +33,38 @@ using namespace com::sun::star; namespace { +/// Updates a text portion to match a new color set, in case it already uses theme colors. +void UpdateTextPortionColorSet(const uno::Reference& xPortion, + svx::ColorSet& rColorSet) +{ + sal_Int16 nCharColorTheme = -1; + xPortion->getPropertyValue(UNO_NAME_EDIT_CHAR_COLOR_THEME) >>= nCharColorTheme; + if (nCharColorTheme < 0 || nCharColorTheme > 11) + { + return; + } + + Color aColor = rColorSet.getColor(nCharColorTheme); + sal_Int32 nCharColorLumMod{}; + xPortion->getPropertyValue(UNO_NAME_EDIT_CHAR_COLOR_LUM_MOD) >>= nCharColorLumMod; + sal_Int32 nCharColorLumOff{}; + xPortion->getPropertyValue(UNO_NAME_EDIT_CHAR_COLOR_LUM_OFF) >>= nCharColorLumOff; + if (nCharColorLumMod != 10000 || nCharColorLumOff != 0) + { + aColor.ApplyLumModOff(nCharColorLumMod, nCharColorLumOff); + } + + sal_Int32 nCharColorTintOrShade{}; + xPortion->getPropertyValue(UNO_NAME_EDIT_CHAR_COLOR_TINT_OR_SHADE) >>= nCharColorTintOrShade; + if (nCharColorTintOrShade != 0) + { + aColor.ApplyTintOrShade(nCharColorTintOrShade); + } + + xPortion->setPropertyValue(UNO_NAME_EDIT_CHAR_COLOR, + uno::makeAny(static_cast(aColor))); +} + void UpdateSdrObject(svx::Theme* pTheme, SdrObject* pObject) { svx::ColorSet* pColorSet = pTheme->GetColorSet(); @@ -51,15 +83,7 @@ void UpdateSdrObject(svx::Theme* pTheme, SdrObject* pObject) while (xPortions->hasMoreElements()) { uno::Reference xPortion(xPortions->nextElement(), uno::UNO_QUERY); - sal_Int16 nCharColorTheme = -1; - xPortion->getPropertyValue(UNO_NAME_EDIT_CHAR_COLOR_THEME) >>= nCharColorTheme; - if (nCharColorTheme < 0 || nCharColorTheme > 11) - { - continue; - } - - Color aColor = pColorSet->getColor(nCharColorTheme); - xPortion->setPropertyValue(UNO_NAME_EDIT_CHAR_COLOR, uno::makeAny(static_cast(aColor))); + UpdateTextPortionColorSet(xPortion, *pColorSet); } } } -- cgit