cui/source/tabpages/chardlg.cxx | 9 +-- docmodel/Library_docmodel.mk | 1 docmodel/source/theme/ColorSet.cxx | 12 ++++ docmodel/source/uno/UnoComplexColor.cxx | 37 ++++++++++++ editeng/source/items/textitem.cxx | 58 +++++++++++-------- editeng/source/uno/unotext.cxx | 8 +- include/docmodel/color/ComplexColor.hxx | 87 ++++++++++++++++++++++++++++- include/docmodel/theme/ColorSet.hxx | 3 + include/docmodel/theme/ThemeColor.hxx | 5 + include/docmodel/uno/UnoComplexColor.hxx | 50 ++++++++++++++++ include/editeng/colritem.hxx | 16 +---- include/oox/export/ThemeExport.hxx | 2 offapi/UnoApi_offapi.mk | 1 offapi/com/sun/star/util/XComplexColor.idl | 26 ++++++++ sd/source/ui/view/drtxtob1.cxx | 9 +-- sw/source/core/model/ThemeColorChanger.cxx | 16 +++-- sw/source/uibase/shells/textsh1.cxx | 2 17 files changed, 284 insertions(+), 58 deletions(-)
New commits: commit 900c3a2a854436fdbacd488ef1da12ea99fbceb0 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Mon May 1 10:19:06 2023 +0900 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Mon May 8 07:23:17 2023 +0200 svx: use ComplexColor in SvxColorItem instead of the ThemeColor ComplexColor includes everything a ThemeColor has and in addition also can have various other representations that are supported by OOXML. This is important for compatibility reasons to preserve the color information. Change-Id: I677775a96511dc1742c75b1949e002eaa8c622e2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151226 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/cui/source/tabpages/chardlg.cxx b/cui/source/tabpages/chardlg.cxx index 0c600f83ab24..601dae8dce0e 100644 --- a/cui/source/tabpages/chardlg.cxx +++ b/cui/source/tabpages/chardlg.cxx @@ -1600,10 +1600,11 @@ bool SvxCharEffectsPage::FillItemSetColor_Impl( SfxItemSet& rSet ) model::ThemeColorType eType = model::convertToThemeColorType(aSelectedColor.m_nThemeIndex); if (eType != model::ThemeColorType::Unknown) { - aItem.GetThemeColor().setType(eType); - aItem.GetThemeColor().clearTransformations(); - aItem.GetThemeColor().addTransformation({model::TransformationType::LumMod, aSelectedColor.m_nLumMod}); - aItem.GetThemeColor().addTransformation({model::TransformationType::LumOff, aSelectedColor.m_nLumOff}); + model::ComplexColor aComplexColor; + aComplexColor.setSchemeColor(eType); + aComplexColor.addTransformation({model::TransformationType::LumMod, aSelectedColor.m_nLumMod}); + aComplexColor.addTransformation({model::TransformationType::LumOff, aSelectedColor.m_nLumOff}); + aItem.setComplexColor(aComplexColor); } rSet.Put(aItem); diff --git a/docmodel/source/theme/ColorSet.cxx b/docmodel/source/theme/ColorSet.cxx index 55c03dadba8c..44cd5bdc6c4f 100644 --- a/docmodel/source/theme/ColorSet.cxx +++ b/docmodel/source/theme/ColorSet.cxx @@ -50,6 +50,18 @@ Color ColorSet::resolveColor(model::ThemeColor const& rThemeColor) const return rThemeColor.applyTransformations(aColor); } +Color ColorSet::resolveColor(model::ComplexColor const& rComplexColor) const +{ + auto eSchemeType = rComplexColor.meSchemeType; + if (eSchemeType == model::ThemeColorType::Unknown) + { + SAL_WARN("svx", "ColorSet::resolveColor with ThemeColorType::Unknown"); + return COL_AUTO; + } + Color aColor = getColor(eSchemeType); + return rComplexColor.applyTransformations(aColor); +} + void ColorSet::dumpAsXml(xmlTextWriterPtr pWriter) const { (void)xmlTextWriterStartElement(pWriter, BAD_CAST("ColorSet")); diff --git a/editeng/source/items/textitem.cxx b/editeng/source/items/textitem.cxx index ece9a4a35237..153319ae8e75 100644 --- a/editeng/source/items/textitem.cxx +++ b/editeng/source/items/textitem.cxx @@ -1368,10 +1368,10 @@ SvxColorItem::SvxColorItem( const Color& rCol, const sal_uInt16 nId ) : { } -SvxColorItem::SvxColorItem(Color const& rColor, model::ThemeColor const& rThemeColor, const sal_uInt16 nId) +SvxColorItem::SvxColorItem(Color const& rColor, model::ComplexColor const& rComplexColor, const sal_uInt16 nId) : SfxPoolItem(nId) , mColor(rColor) - , maThemeColor(rThemeColor) + , maComplexColor(rComplexColor) { } @@ -1385,7 +1385,7 @@ bool SvxColorItem::operator==( const SfxPoolItem& rAttr ) const const SvxColorItem& rColorItem = static_cast<const SvxColorItem&>(rAttr); return mColor == rColorItem.mColor && - maThemeColor == rColorItem.maThemeColor; + maComplexColor == rColorItem.maComplexColor; } bool SvxColorItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const @@ -1406,13 +1406,13 @@ bool SvxColorItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const } case MID_COLOR_THEME_INDEX: { - rVal <<= sal_Int16(maThemeColor.getType()); + rVal <<= sal_Int16(maComplexColor.meSchemeType); break; } case MID_COLOR_TINT_OR_SHADE: { sal_Int16 nValue = 0; - for (auto const& rTransform : maThemeColor.getTransformations()) + for (auto const& rTransform : maComplexColor.getTransformations()) { if (rTransform.meType == model::TransformationType::Tint) nValue = rTransform.mnValue; @@ -1425,7 +1425,7 @@ bool SvxColorItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const case MID_COLOR_LUM_MOD: { sal_Int16 nValue = 10000; - for (auto const& rTransform : maThemeColor.getTransformations()) + for (auto const& rTransform : maComplexColor.getTransformations()) { if (rTransform.meType == model::TransformationType::LumMod) nValue = rTransform.mnValue; @@ -1436,7 +1436,7 @@ bool SvxColorItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const case MID_COLOR_LUM_OFF: { sal_Int16 nValue = 0; - for (auto const& rTransform : maThemeColor.getTransformations()) + for (auto const& rTransform : maComplexColor.getTransformations()) { if (rTransform.meType == model::TransformationType::LumOff) nValue = rTransform.mnValue; @@ -1446,13 +1446,15 @@ bool SvxColorItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const } case MID_COLOR_THEME_REFERENCE: { - auto xThemeColor = model::theme::createXThemeColor(maThemeColor); + model::ThemeColor aThemeColor = maComplexColor.createThemeColor(); + auto xThemeColor = model::theme::createXThemeColor(aThemeColor); rVal <<= xThemeColor; break; } case MID_COLOR_THEME_REFERENCE_JSON: { - rVal <<= OStringToOUString(model::theme::convertToJSON(maThemeColor), RTL_TEXTENCODING_UTF8); + model::ThemeColor aThemeColor = maComplexColor.createThemeColor(); + rVal <<= OStringToOUString(model::theme::convertToJSON(aThemeColor), RTL_TEXTENCODING_UTF8); break; } case MID_COLOR_RGB: @@ -1491,7 +1493,7 @@ bool SvxColorItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) sal_Int16 nIndex = -1; if (!(rVal >>= nIndex)) return false; - maThemeColor.setType(model::convertToThemeColorType(nIndex)); + maComplexColor.setSchemeColor(model::convertToThemeColorType(nIndex)); } break; case MID_COLOR_TINT_OR_SHADE: @@ -1500,15 +1502,15 @@ bool SvxColorItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) if (!(rVal >>= nTintShade)) return false; - maThemeColor.removeTransformations(model::TransformationType::Tint); - maThemeColor.removeTransformations(model::TransformationType::Shade); + maComplexColor.removeTransformations(model::TransformationType::Tint); + maComplexColor.removeTransformations(model::TransformationType::Shade); if (nTintShade > 0) - maThemeColor.addTransformation({model::TransformationType::Tint, nTintShade}); + maComplexColor.addTransformation({model::TransformationType::Tint, nTintShade}); else if (nTintShade < 0) { sal_Int16 nShade = o3tl::narrowing<sal_Int16>(-nTintShade); - maThemeColor.addTransformation({model::TransformationType::Shade, nShade}); + maComplexColor.addTransformation({model::TransformationType::Shade, nShade}); } } break; @@ -1517,8 +1519,8 @@ bool SvxColorItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) sal_Int16 nLumMod = 10000; if (!(rVal >>= nLumMod)) return false; - maThemeColor.removeTransformations(model::TransformationType::LumMod); - maThemeColor.addTransformation({model::TransformationType::LumMod, nLumMod}); + maComplexColor.removeTransformations(model::TransformationType::LumMod); + maComplexColor.addTransformation({model::TransformationType::LumMod, nLumMod}); } break; case MID_COLOR_LUM_OFF: @@ -1526,8 +1528,8 @@ bool SvxColorItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) sal_Int16 nLumOff = 0; if (!(rVal >>= nLumOff)) return false; - maThemeColor.removeTransformations(model::TransformationType::LumOff); - maThemeColor.addTransformation({model::TransformationType::LumOff, nLumOff}); + maComplexColor.removeTransformations(model::TransformationType::LumOff); + maComplexColor.addTransformation({model::TransformationType::LumOff, nLumOff}); } break; case MID_COLOR_THEME_REFERENCE: @@ -1538,7 +1540,11 @@ bool SvxColorItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) if (xThemeColor.is()) { - model::theme::setFromXThemeColor(maThemeColor, xThemeColor); + model::ThemeColor aThemeColor; + model::theme::setFromXThemeColor(aThemeColor, xThemeColor); + maComplexColor = model::ComplexColor(); + maComplexColor.setSchemeColor(aThemeColor.getType()); + maComplexColor.setTransformations(aThemeColor.getTransformations()); } } break; @@ -1554,7 +1560,11 @@ bool SvxColorItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) return false; } OString aJSON = OUStringToOString(sThemeJson, RTL_TEXTENCODING_ASCII_US); - model::theme::convertFromJSON(aJSON, maThemeColor); + model::ThemeColor aThemeColor; + model::theme::convertFromJSON(aJSON, aThemeColor); + maComplexColor = model::ComplexColor(); + maComplexColor.setSchemeColor(aThemeColor.getType()); + maComplexColor.setTransformations(aThemeColor.getTransformations()); } break; @@ -1599,12 +1609,12 @@ void SvxColorItem::dumpAsXml(xmlTextWriterPtr pWriter) const GetPresentation( SfxItemPresentation::Complete, MapUnit::Map100thMM, MapUnit::Map100thMM, aStr, aIntlWrapper); (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("presentation"), BAD_CAST(OUStringToOString(aStr, RTL_TEXTENCODING_UTF8).getStr())); - (void)xmlTextWriterStartElement(pWriter, BAD_CAST("theme-color")); + (void)xmlTextWriterStartElement(pWriter, BAD_CAST("complex-color")); - (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("theme-index"), - BAD_CAST(OString::number(sal_Int16(maThemeColor.getType())).getStr())); + (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("type"), + BAD_CAST(OString::number(sal_Int16(maComplexColor.meType)).getStr())); - for (auto const& rTransform : maThemeColor.getTransformations()) + for (auto const& rTransform : maComplexColor.getTransformations()) { (void)xmlTextWriterStartElement(pWriter, BAD_CAST("transformation")); (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("type"), diff --git a/editeng/source/uno/unotext.cxx b/editeng/source/uno/unotext.cxx index 54fd7126dbd4..c6a6732ba414 100644 --- a/editeng/source/uno/unotext.cxx +++ b/editeng/source/uno/unotext.cxx @@ -1143,7 +1143,7 @@ bool SvxUnoTextRangeBase::_getOnePropertyStates(const SfxItemSet* pSet, const Sf switch (pMap->nMemberId) { case MID_COLOR_THEME_INDEX: - if (pColor->GetThemeColor().getType() == model::ThemeColorType::Unknown) + if (pColor->getComplexColor().meSchemeType == model::ThemeColorType::Unknown) { eItemState = SfxItemState::DEFAULT; } @@ -1151,7 +1151,7 @@ bool SvxUnoTextRangeBase::_getOnePropertyStates(const SfxItemSet* pSet, const Sf case MID_COLOR_LUM_MOD: { sal_Int16 nLumMod = 10000; - for (auto const& rTransform : pColor->GetThemeColor().getTransformations()) + for (auto const& rTransform : pColor->getComplexColor().getTransformations()) { if (rTransform.meType == model::TransformationType::LumMod) nLumMod = rTransform.mnValue; @@ -1165,7 +1165,7 @@ bool SvxUnoTextRangeBase::_getOnePropertyStates(const SfxItemSet* pSet, const Sf case MID_COLOR_LUM_OFF: { sal_Int16 nLumOff = 0; - for (auto const& rTransform : pColor->GetThemeColor().getTransformations()) + for (auto const& rTransform : pColor->getComplexColor().getTransformations()) { if (rTransform.meType == model::TransformationType::LumOff) nLumOff = rTransform.mnValue; @@ -1177,7 +1177,7 @@ bool SvxUnoTextRangeBase::_getOnePropertyStates(const SfxItemSet* pSet, const Sf break; } case MID_COLOR_THEME_REFERENCE: - if (pColor->GetThemeColor().getType() == model::ThemeColorType::Unknown) + if (pColor->getComplexColor().meType == model::ColorType::Unused) { eItemState = SfxItemState::DEFAULT; } diff --git a/include/docmodel/color/ComplexColor.hxx b/include/docmodel/color/ComplexColor.hxx index 228b32b16932..f5dd37c2e901 100644 --- a/include/docmodel/color/ComplexColor.hxx +++ b/include/docmodel/color/ComplexColor.hxx @@ -64,14 +64,24 @@ enum class SystemColorType WindowText }; -struct DOCMODEL_DLLPUBLIC ComplexColor +/** Definition of a color with multiple representations + * + * A color that can be expresses as a RGB, CRGB or HSL representation or + * a more abstract representation as for example system color, palette, + * scheme (theme) color or a placeholder. In these representations the + * color needs to be additionally + * + * The color can also have transformations defined, which in addition + * manipulates the resulting color (i.e. tints, shades, alpha,...). + */ +class DOCMODEL_DLLPUBLIC ComplexColor { +public: ColorType meType = ColorType::Unused; sal_Int32 mnComponent1 = 0; // Red, Hue sal_Int32 mnComponent2 = 0; // Green, Saturation sal_Int32 mnComponent3 = 0; // Blue, Luminance - sal_Int32 mnAlpha = 0; // Percentage SystemColorType meSystemColorType = SystemColorType::Unused; ::Color maLastColor; @@ -81,6 +91,27 @@ struct DOCMODEL_DLLPUBLIC ComplexColor Color getRGBColor() const { return Color(mnComponent1, mnComponent2, mnComponent3); } + std::vector<Transformation> const& getTransformations() const { return maTransformations; } + + void setTransformations(std::vector<Transformation> const& rTransformations) + { + maTransformations = rTransformations; + } + + void addTransformation(Transformation const& rTransform) + { + maTransformations.push_back(rTransform); + } + + void removeTransformations(TransformationType eType) + { + maTransformations.erase(std::remove_if(maTransformations.begin(), maTransformations.end(), + [eType](Transformation const& rTransform) { + return rTransform.meType == eType; + }), + maTransformations.end()); + } + void setCRGB(sal_Int32 nR, sal_Int32 nG, sal_Int32 nB) { mnComponent1 = nR; @@ -120,6 +151,58 @@ struct DOCMODEL_DLLPUBLIC ComplexColor meSchemeType = eType; meType = ColorType::Scheme; } + + model::ThemeColor createThemeColor() const + { + model::ThemeColor aThemeColor; + if (meType == ColorType::Scheme) + { + aThemeColor.setType(meSchemeType); + aThemeColor.setTransformations(maTransformations); + } + return aThemeColor; + } + + bool operator==(const ComplexColor& rComplexColor) const + { + return meType == rComplexColor.meType && mnComponent1 == rComplexColor.mnComponent1 + && mnComponent2 == rComplexColor.mnComponent2 + && mnComponent3 == rComplexColor.mnComponent3 + && meSystemColorType == rComplexColor.meSystemColorType + && maLastColor == rComplexColor.maLastColor + && meSchemeType == rComplexColor.meSchemeType + && maTransformations.size() == rComplexColor.maTransformations.size() + && std::equal(maTransformations.begin(), maTransformations.end(), + rComplexColor.maTransformations.begin()); + } + + /** Applies the defined transformations to the input color */ + Color applyTransformations(Color const& rColor) const + { + Color aColor(rColor); + + for (auto const& rTransform : maTransformations) + { + switch (rTransform.meType) + { + case TransformationType::Tint: + aColor.ApplyTintOrShade(rTransform.mnValue); + break; + case TransformationType::Shade: + aColor.ApplyTintOrShade(-rTransform.mnValue); + break; + case TransformationType::LumMod: + aColor.ApplyLumModOff(rTransform.mnValue, 0); + break; + case TransformationType::LumOff: + aColor.ApplyLumModOff(10000, rTransform.mnValue); + break; + default: + break; + } + } + return aColor; + } }; } // end of namespace svx diff --git a/include/docmodel/theme/ColorSet.hxx b/include/docmodel/theme/ColorSet.hxx index d803fbc3e668..0b7a8a6efdd6 100644 --- a/include/docmodel/theme/ColorSet.hxx +++ b/include/docmodel/theme/ColorSet.hxx @@ -15,6 +15,7 @@ #include <rtl/ustring.hxx> #include <docmodel/theme/ThemeColorType.hxx> #include <docmodel/theme/ThemeColor.hxx> +#include <docmodel/color/ComplexColor.hxx> #include <tools/color.hxx> typedef struct _xmlTextWriter* xmlTextWriterPtr; @@ -37,6 +38,8 @@ public: Color resolveColor(model::ThemeColor const& rThemeColor) const; + Color resolveColor(model::ComplexColor const& rComplexColor) const; + Color getColor(model::ThemeColorType eType) const; void dumpAsXml(xmlTextWriterPtr pWriter) const; diff --git a/include/docmodel/theme/ThemeColor.hxx b/include/docmodel/theme/ThemeColor.hxx index 33d841155815..b21ef527dc57 100644 --- a/include/docmodel/theme/ThemeColor.hxx +++ b/include/docmodel/theme/ThemeColor.hxx @@ -38,6 +38,11 @@ public: void clearTransformations() { maTransformations.clear(); } + void setTransformations(std::vector<Transformation> const& rTransformations) + { + maTransformations = rTransformations; + } + void addTransformation(Transformation const& rTransform) { maTransformations.push_back(rTransform); diff --git a/include/editeng/colritem.hxx b/include/editeng/colritem.hxx index fc55b6e04553..dca36a5b9fda 100644 --- a/include/editeng/colritem.hxx +++ b/include/editeng/colritem.hxx @@ -22,7 +22,7 @@ #include <svl/poolitem.hxx> #include <tools/color.hxx> #include <editeng/editengdllapi.h> -#include <docmodel/theme/ThemeColor.hxx> +#include <docmodel/color/ComplexColor.hxx> #define VERSION_USEAUTOCOLOR 1 @@ -32,14 +32,14 @@ class EDITENG_DLLPUBLIC SvxColorItem final : public SfxPoolItem { private: Color mColor; - model::ThemeColor maThemeColor; + model::ComplexColor maComplexColor; public: static SfxPoolItem* CreateDefault(); explicit SvxColorItem(const sal_uInt16 nId); SvxColorItem(const Color& aColor, const sal_uInt16 nId); - SvxColorItem(const Color& aColor, model::ThemeColor const& rThemeColor, const sal_uInt16 nId); + SvxColorItem(const Color& aColor, model::ComplexColor const& rComplexColor, const sal_uInt16 nId); virtual ~SvxColorItem() override; // "pure virtual Methods" from SfxPoolItem @@ -60,14 +60,8 @@ public: } void SetValue(const Color& rNewColor); - model::ThemeColor& GetThemeColor() { return maThemeColor; } - - const model::ThemeColor& GetThemeColor() const { return maThemeColor; } - - void setThemeColor(model::ThemeColor const& rThemeColor) - { - maThemeColor = rThemeColor; - } + model::ComplexColor const& getComplexColor() const { return maComplexColor; } + void setComplexColor(model::ComplexColor const& rComplexColor) { maComplexColor = rComplexColor; } void dumpAsXml(xmlTextWriterPtr pWriter) const override; }; diff --git a/include/oox/export/ThemeExport.hxx b/include/oox/export/ThemeExport.hxx index d51311d147e3..e1162279ec84 100644 --- a/include/oox/export/ThemeExport.hxx +++ b/include/oox/export/ThemeExport.hxx @@ -26,7 +26,7 @@ class BlipFill; class PatternFill; class GradientFill; class SolidFill; -struct ComplexColor; +class ComplexColor; struct Transformation; } diff --git a/sd/source/ui/view/drtxtob1.cxx b/sd/source/ui/view/drtxtob1.cxx index 7fba8728d991..f6301ba1b592 100644 --- a/sd/source/ui/view/drtxtob1.cxx +++ b/sd/source/ui/view/drtxtob1.cxx @@ -780,20 +780,21 @@ void TextObjectBar::Execute( SfxRequest &rReq ) if (nSlot == SID_ATTR_CHAR_COLOR) { pColorItem = std::make_unique<SvxColorItem>(pNewArgs->Get(EE_CHAR_COLOR)); - pColorItem->GetThemeColor().clearTransformations(); + model::ComplexColor aComplexColor; if (const SfxInt16Item* pIntItem = pArgs->GetItemIfSet(SID_ATTR_COLOR_THEME_INDEX, false)) { - pColorItem->GetThemeColor().setType(model::convertToThemeColorType(pIntItem->GetValue())); + aComplexColor.setSchemeColor(model::convertToThemeColorType(pIntItem->GetValue())); } if (const SfxInt16Item* pIntItem = pArgs->GetItemIfSet(SID_ATTR_COLOR_LUM_MOD, false)) { - pColorItem->GetThemeColor().addTransformation({model::TransformationType::LumMod, pIntItem->GetValue()}); + aComplexColor.addTransformation({model::TransformationType::LumMod, pIntItem->GetValue()}); } if (const SfxInt16Item* pIntItem = pArgs->GetItemIfSet(SID_ATTR_COLOR_LUM_OFF, false)) { - pColorItem->GetThemeColor().addTransformation({model::TransformationType::LumOff, pIntItem->GetValue()}); + aComplexColor.addTransformation({model::TransformationType::LumOff, pIntItem->GetValue()}); } + pColorItem->setComplexColor(aComplexColor); pNewArgs->Put(std::move(pColorItem)); } diff --git a/sw/source/core/model/ThemeColorChanger.cxx b/sw/source/core/model/ThemeColorChanger.cxx index dd198c14723e..6e230969b692 100644 --- a/sw/source/core/model/ThemeColorChanger.cxx +++ b/sw/source/core/model/ThemeColorChanger.cxx @@ -72,11 +72,11 @@ public: std::shared_ptr<SfxItemSet> pStyleHandle(rAutoFormatPool.GetStyleHandle()); if (const SvxColorItem* pItem = pStyleHandle->GetItemIfSet(RES_CHRATR_COLOR)) { - model::ThemeColor const& rThemeColor = pItem->GetThemeColor(); - auto eThemeType = rThemeColor.getType(); - if (eThemeType != model::ThemeColorType::Unknown) + model::ComplexColor const& rComplexColor = pItem->getComplexColor(); + auto eSchemeType = rComplexColor.meSchemeType; + if (eSchemeType != model::ThemeColorType::Unknown) { - Color aNewColor = mrColorSet.resolveColor(rThemeColor); + Color aNewColor = mrColorSet.resolveColor(rComplexColor); auto pNew = pItem->Clone(); pNew->SetValue(aNewColor); @@ -122,12 +122,14 @@ void changeColor(SwFormat* pFormat, model::ColorSet const& rColorSet, SwDoc* pDo std::unique_ptr<SfxItemSet> pNewSet = rAttrSet.Clone(); SvxColorItem aColorItem(rAttrSet.GetColor()); - model::ThemeColor const& rThemeColor = aColorItem.GetThemeColor(); - auto eThemeType = rThemeColor.getType(); + model::ComplexColor const& rComplexColor = aColorItem.getComplexColor(); + if (rComplexColor.meType != model::ColorType::Scheme) + return; + auto eThemeType = rComplexColor.meSchemeType; if (eThemeType != model::ThemeColorType::Unknown) { Color aColor = rColorSet.getColor(eThemeType); - aColor = rThemeColor.applyTransformations(aColor); + aColor = rComplexColor.applyTransformations(aColor); aColorItem.SetValue(aColor); pNewSet->Put(aColorItem); pDocument->ChgFormat(*pFormat, *pNewSet); diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx index fd0d4454492a..3e4de13cbc8b 100644 --- a/sw/source/uibase/shells/textsh1.cxx +++ b/sw/source/uibase/shells/textsh1.cxx @@ -1692,7 +1692,7 @@ void SwTextShell::Execute(SfxRequest &rReq) // otherwise, it'll be the color for the next text to be typed if (!pApply || pApply->nColor != SID_ATTR_CHAR_COLOR_EXT) { - rWrtSh.SetAttrItem(SvxColorItem(pColorItem->GetValue(), pColorItem->GetThemeColor(), RES_CHRATR_COLOR)); + rWrtSh.SetAttrItem(SvxColorItem(pColorItem->GetValue(), pColorItem->getComplexColor(), RES_CHRATR_COLOR)); } rReq.Done(); commit 7a10187042c1a2b402a9872f66108cfcd8080117 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Sun Apr 30 20:58:14 2023 +0900 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Mon May 8 07:23:09 2023 +0200 XComplexColor and UnoComplexColor - a wrapper for model:ComplexColor Change-Id: I40107fc38a4d080d969fee862595660d2f585e51 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151225 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/docmodel/Library_docmodel.mk b/docmodel/Library_docmodel.mk index 8a07e6532dad..7f0623bcbeda 100644 --- a/docmodel/Library_docmodel.mk +++ b/docmodel/Library_docmodel.mk @@ -10,6 +10,7 @@ $(eval $(call gb_Library_Library,docmodel)) $(eval $(call gb_Library_add_exception_objects,docmodel,\ + docmodel/source/uno/UnoComplexColor \ docmodel/source/uno/UnoThemeColor \ docmodel/source/uno/UnoTheme \ docmodel/source/theme/ColorSet \ diff --git a/docmodel/source/uno/UnoComplexColor.cxx b/docmodel/source/uno/UnoComplexColor.cxx new file mode 100644 index 000000000000..bffa81329f70 --- /dev/null +++ b/docmodel/source/uno/UnoComplexColor.cxx @@ -0,0 +1,37 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#include <docmodel/uno/UnoComplexColor.hxx> +#include <cppuhelper/queryinterface.hxx> + +using namespace css; + +css::util::Color UnoComplexColor::getColor() { return css::util::Color(maColor.getRGBColor()); } + +namespace model::color +{ +uno::Reference<util::XComplexColor> createXComplexColor(model::ComplexColor const& rColor) +{ + return new UnoComplexColor(rColor); +} + +model::ComplexColor +getFromXComplexColor(css::uno::Reference<css::util::XComplexColor> const& rxColor) +{ + model::ComplexColor aComplexColor; + UnoComplexColor const* pUnoComplexColor = static_cast<UnoComplexColor const*>(rxColor.get()); + if (pUnoComplexColor) + aComplexColor = pUnoComplexColor->getComplexColor(); + return aComplexColor; +} + +} // end model::color + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/docmodel/uno/UnoComplexColor.hxx b/include/docmodel/uno/UnoComplexColor.hxx new file mode 100644 index 000000000000..69a0fe4e35b9 --- /dev/null +++ b/include/docmodel/uno/UnoComplexColor.hxx @@ -0,0 +1,50 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include <cppuhelper/implbase.hxx> +#include <cppuhelper/supportsservice.hxx> +#include <comphelper/servicehelper.hxx> + +#include <com/sun/star/util/Color.hpp> +#include <com/sun/star/util/XComplexColor.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> + +#include <utility> +#include <docmodel/dllapi.h> +#include <docmodel/color/ComplexColor.hxx> + +class DOCMODEL_DLLPUBLIC UnoComplexColor final + : public cppu::WeakImplHelper<css::util::XComplexColor> +{ +private: + model::ComplexColor maColor; + +public: + UnoComplexColor(model::ComplexColor const& rColor) + : maColor(rColor) + { + } + + model::ComplexColor const& getComplexColor() const { return maColor; } + + // XComplexColor + css::util::Color SAL_CALL getColor() override; +}; + +namespace model::color +{ +DOCMODEL_DLLPUBLIC css::uno::Reference<css::util::XComplexColor> +createXComplexColor(model::ComplexColor const& rColor); +DOCMODEL_DLLPUBLIC model::ComplexColor +getFromXComplexColor(css::uno::Reference<css::util::XComplexColor> const& rxColor); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/offapi/UnoApi_offapi.mk b/offapi/UnoApi_offapi.mk index 96ed8e6e943a..51eed6e3e4cd 100644 --- a/offapi/UnoApi_offapi.mk +++ b/offapi/UnoApi_offapi.mk @@ -4174,6 +4174,7 @@ $(eval $(call gb_UnoApi_add_idlfiles,offapi,com/sun/star/util,\ XCloseBroadcaster \ XCloseListener \ XCloseable \ + XComplexColor \ XTheme \ XThemeColor \ XDataEditor \ diff --git a/offapi/com/sun/star/util/XComplexColor.idl b/offapi/com/sun/star/util/XComplexColor.idl new file mode 100644 index 000000000000..864e4b1516de --- /dev/null +++ b/offapi/com/sun/star/util/XComplexColor.idl @@ -0,0 +1,26 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + + +module com { module sun { module star { module util { + + +/** Complex color interface + + @since LibreOffice 7.6 +*/ +interface XComplexColor +{ + /** */ + Color getColor(); +}; + +}; }; }; }; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */