include/docmodel/color/ComplexColor.hxx | 127 ++++++++++++++++++++ include/docmodel/color/Transformation.hxx | 72 +++++++++++ include/docmodel/theme/FormatScheme.hxx | 142 +++-------------------- include/docmodel/theme/ThemeColor.hxx | 52 -------- include/oox/export/ThemeExport.hxx | 16 +- oox/inc/drawingml/colorchoicecontext.hxx | 8 - oox/source/drawingml/colorchoicecontext.cxx | 46 +++---- oox/source/drawingml/effectpropertiescontext.cxx | 10 - oox/source/drawingml/misccontexts.cxx | 28 ++-- oox/source/export/ThemeExport.cxx | 64 +++++----- sw/qa/core/theme/ThemeTest.cxx | 16 +- 11 files changed, 313 insertions(+), 268 deletions(-)
New commits: commit 113c6d11afbfc97e17fe90d90dd55d149a33a191 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Sun Apr 30 15:52:32 2023 +0900 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Mon May 1 06:05:19 2023 +0200 docmodel: extract ColorDefinition into own file and rename ColorDefinition is renamed into ComplexColor. Change-Id: I81c2d97e6b7bf9de4ce703c02b6db40636b04961 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151224 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/include/docmodel/color/ComplexColor.hxx b/include/docmodel/color/ComplexColor.hxx new file mode 100644 index 000000000000..228b32b16932 --- /dev/null +++ b/include/docmodel/color/ComplexColor.hxx @@ -0,0 +1,127 @@ +/* -*- 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 <docmodel/dllapi.h> +#include <tools/color.hxx> +#include <docmodel/theme/ThemeColor.hxx> +#include <com/sun/star/graphic/XGraphic.hpp> + +namespace model +{ +enum class ColorType +{ + Unused, + RGB, + CRGB, + HSL, + Scheme, + Palette, + System, + Placeholder +}; + +enum class SystemColorType +{ + Unused, + DarkShadow3D, + Light3D, + ActiveBorder, + ActiveCaption, + AppWorkspace, + Background, + ButtonFace, + ButtonHighlight, + ButtonShadow, + ButtonText, + CaptionText, + GradientActiveCaption, + GradientInactiveCaption, + GrayText, + Highlight, + HighlightText, + HotLight, + InactiveBorder, + InactiveCaption, + InactiveCaptionText, + InfoBack, + InfoText, + Menu, + MenuBar, + MenuHighlight, + MenuText, + ScrollBar, + Window, + WindowFrame, + WindowText +}; + +struct DOCMODEL_DLLPUBLIC ComplexColor +{ + 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; + + ThemeColorType meSchemeType = ThemeColorType::Unknown; + std::vector<Transformation> maTransformations; + + Color getRGBColor() const { return Color(mnComponent1, mnComponent2, mnComponent3); } + + void setCRGB(sal_Int32 nR, sal_Int32 nG, sal_Int32 nB) + { + mnComponent1 = nR; + mnComponent2 = nG; + mnComponent3 = nB; + meType = ColorType::CRGB; + } + + void setRGB(sal_Int32 nRGB) + { + ::Color aColor(ColorTransparency, nRGB); + mnComponent1 = aColor.GetRed(); + mnComponent2 = aColor.GetGreen(); + mnComponent3 = aColor.GetBlue(); + meType = ColorType::RGB; + } + + void setHSL(sal_Int32 nH, sal_Int32 nS, sal_Int32 nL) + { + mnComponent1 = nH; + mnComponent2 = nS; + mnComponent3 = nL; + meType = ColorType::HSL; + } + + void setSystemColor(SystemColorType eSystemColorType, sal_Int32 nRGB) + { + maLastColor = ::Color(ColorTransparency, nRGB); + meSystemColorType = eSystemColorType; + meType = ColorType::System; + } + + void setSchemePlaceholder() { meType = ColorType::Placeholder; } + + void setSchemeColor(ThemeColorType eType) + { + meSchemeType = eType; + meType = ColorType::Scheme; + } +}; + +} // end of namespace svx + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/docmodel/theme/FormatScheme.hxx b/include/docmodel/theme/FormatScheme.hxx index fb65d24d2ba8..6e20d88b51ca 100644 --- a/include/docmodel/theme/FormatScheme.hxx +++ b/include/docmodel/theme/FormatScheme.hxx @@ -13,115 +13,11 @@ #include <docmodel/dllapi.h> #include <tools/color.hxx> #include <docmodel/theme/ThemeColor.hxx> +#include <docmodel/color/ComplexColor.hxx> #include <com/sun/star/graphic/XGraphic.hpp> namespace model { -enum class ColorType -{ - Unused, - RGB, - CRGB, - HSL, - Scheme, - Palette, - System, - Placeholder -}; - -enum class SystemColorType -{ - Unused, - DarkShadow3D, - Light3D, - ActiveBorder, - ActiveCaption, - AppWorkspace, - Background, - ButtonFace, - ButtonHighlight, - ButtonShadow, - ButtonText, - CaptionText, - GradientActiveCaption, - GradientInactiveCaption, - GrayText, - Highlight, - HighlightText, - HotLight, - InactiveBorder, - InactiveCaption, - InactiveCaptionText, - InfoBack, - InfoText, - Menu, - MenuBar, - MenuHighlight, - MenuText, - ScrollBar, - Window, - WindowFrame, - WindowText -}; - -struct DOCMODEL_DLLPUBLIC ColorDefinition -{ - 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; - - ThemeColorType meSchemeType = ThemeColorType::Unknown; - std::vector<Transformation> maTransformations; - - Color getRGBColor() const { return Color(mnComponent1, mnComponent2, mnComponent3); } - - void setCRGB(sal_Int32 nR, sal_Int32 nG, sal_Int32 nB) - { - mnComponent1 = nR; - mnComponent2 = nG; - mnComponent3 = nB; - meType = ColorType::CRGB; - } - - void setRGB(sal_Int32 nRGB) - { - ::Color aColor(ColorTransparency, nRGB); - mnComponent1 = aColor.GetRed(); - mnComponent2 = aColor.GetGreen(); - mnComponent3 = aColor.GetBlue(); - meType = ColorType::RGB; - } - - void setHSL(sal_Int32 nH, sal_Int32 nS, sal_Int32 nL) - { - mnComponent1 = nH; - mnComponent2 = nS; - mnComponent3 = nL; - meType = ColorType::HSL; - } - - void setSystemColor(SystemColorType eSystemColorType, sal_Int32 nRGB) - { - maLastColor = ::Color(ColorTransparency, nRGB); - meSystemColorType = eSystemColorType; - meType = ColorType::System; - } - - void setSchemePlaceholder() { meType = ColorType::Placeholder; } - - void setSchemeColor(ThemeColorType eType) - { - meSchemeType = eType; - meType = ColorType::Scheme; - } -}; - enum class FillType { None, @@ -154,7 +50,7 @@ public: class DOCMODEL_DLLPUBLIC SolidFill : public Fill { public: - ColorDefinition maColorDefinition; + ComplexColor maColor; SolidFill() : Fill(FillType::Solid) @@ -166,7 +62,7 @@ class DOCMODEL_DLLPUBLIC GradientStop { public: double mfPosition = 0.0; // 0.0 - 1.0 - ColorDefinition maColor; + ComplexColor maColor; }; enum class GradientType @@ -271,8 +167,8 @@ class DOCMODEL_DLLPUBLIC PatternFill : public Fill { public: PatternPreset mePatternPreset = PatternPreset::Unused; - ColorDefinition maForegroundColor; - ColorDefinition maBackgroundColor; + ComplexColor maForegroundColor; + ComplexColor maBackgroundColor; PatternFill() : Fill(FillType::Pattern) @@ -339,8 +235,8 @@ public: BlipEffectType meType = BlipEffectType::None; sal_Int32 mnThreshold = 0; // AlphaBiLevel, BiLevel - ColorDefinition maColor1; // AlphaInverse, ColorReplace, DuoTone, ColorChange (from) - ColorDefinition maColor2; // DuoTone, ColorChange (to) + ComplexColor maColor1; // AlphaInverse, ColorReplace, DuoTone, ColorChange (from) + ComplexColor maColor2; // DuoTone, ColorChange (to) sal_Int32 mnAmount = 0; // AlphaModulateFixed, Tint sal_Int32 mnRadius = 0; // Blur bool mbGrow = false; // Blur @@ -352,8 +248,8 @@ public: sal_Int32 mnBrightness = 0; // Luminance sal_Int32 mnContrast = 0; // Luminance - ColorDefinition& getColorFrom() { return maColor1; } - ColorDefinition& getColorTo() { return maColor2; } + ComplexColor& getColorFrom() { return maColor1; } + ComplexColor& getColorTo() { return maColor2; } }; class DOCMODEL_DLLPUBLIC BlipFill : public Fill @@ -526,7 +422,7 @@ public: sal_Int32 mnScewY = 0; RectangleAlignment meAlignment = RectangleAlignment::Bottom; bool mbRotateWithShape = true; - ColorDefinition maColor; + ComplexColor maColor; double mnEndAlpha = 100.0; double mnEndPosition = 0.0; double mnStartAlpha = 0.0; @@ -579,19 +475,19 @@ public: { FillStyle* pFillStyle = pThis->addFillStyle(); auto pFill = std::make_shared<SolidFill>(); - pFill->maColorDefinition.meType = model::ColorType::Placeholder; + pFill->maColor.meType = model::ColorType::Placeholder; pFillStyle->mpFill = pFill; } { FillStyle* pFillStyle = pThis->addFillStyle(); auto pFill = std::make_shared<SolidFill>(); - pFill->maColorDefinition.meType = model::ColorType::Placeholder; + pFill->maColor.meType = model::ColorType::Placeholder; pFillStyle->mpFill = pFill; } { FillStyle* pFillStyle = pThis->addFillStyle(); auto pFill = std::make_shared<SolidFill>(); - pFill->maColorDefinition.meType = model::ColorType::Placeholder; + pFill->maColor.meType = model::ColorType::Placeholder; pFillStyle->mpFill = pFill; } } @@ -622,7 +518,7 @@ public: pLineStyle->maLineDash.mePresetType = PresetDashType::Solid; pLineStyle->maLineJoin.meType = LineJoinType::Miter; auto pFill = std::make_shared<SolidFill>(); - pFill->maColorDefinition.meType = model::ColorType::Placeholder; + pFill->maColor.meType = model::ColorType::Placeholder; pLineStyle->maLineFillStyle.mpFill = pFill; } { @@ -634,7 +530,7 @@ public: pLineStyle->maLineDash.mePresetType = PresetDashType::Solid; pLineStyle->maLineJoin.meType = LineJoinType::Miter; auto pFill = std::make_shared<SolidFill>(); - pFill->maColorDefinition.meType = model::ColorType::Placeholder; + pFill->maColor.meType = model::ColorType::Placeholder; pLineStyle->maLineFillStyle.mpFill = pFill; } { @@ -646,7 +542,7 @@ public: pLineStyle->maLineDash.mePresetType = PresetDashType::Solid; pLineStyle->maLineJoin.meType = LineJoinType::Miter; auto pFill = std::make_shared<SolidFill>(); - pFill->maColorDefinition.meType = model::ColorType::Placeholder; + pFill->maColor.meType = model::ColorType::Placeholder; pLineStyle->maLineFillStyle.mpFill = pFill; } } @@ -696,19 +592,19 @@ public: { FillStyle* pFillStyle = pThis->addBackgroundFillStyle(); auto pFill = std::make_shared<SolidFill>(); - pFill->maColorDefinition.meType = model::ColorType::Placeholder; + pFill->maColor.meType = model::ColorType::Placeholder; pFillStyle->mpFill = pFill; } { FillStyle* pFillStyle = pThis->addBackgroundFillStyle(); auto pFill = std::make_shared<SolidFill>(); - pFill->maColorDefinition.meType = model::ColorType::Placeholder; + pFill->maColor.meType = model::ColorType::Placeholder; pFillStyle->mpFill = pFill; } { FillStyle* pFillStyle = pThis->addBackgroundFillStyle(); auto pFill = std::make_shared<SolidFill>(); - pFill->maColorDefinition.meType = model::ColorType::Placeholder; + pFill->maColor.meType = model::ColorType::Placeholder; pFillStyle->mpFill = pFill; } } diff --git a/include/oox/export/ThemeExport.hxx b/include/oox/export/ThemeExport.hxx index 766d6dfd8a0c..d51311d147e3 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 ColorDefinition; +struct ComplexColor; struct Transformation; } @@ -58,13 +58,13 @@ private: void writePatternFill(model::PatternFill const& rPatternFill); void writeGradientFill(model::GradientFill const& rGradientFill); void writeSolidFill(model::SolidFill const& rSolidFill); - void writeColorDefinition(model::ColorDefinition const& rColorDefinition); - void writeColorPlaceholder(model::ColorDefinition const& rColorDefinition); - void writeColorSystem(model::ColorDefinition const& rColorDefinition); - void writeColorScheme(model::ColorDefinition const& rColorDefinition); - void writeColorHSL(model::ColorDefinition const& rColorDefinition); - void writeColorCRGB(model::ColorDefinition const& rColorDefinition); - void writeColorRGB(model::ColorDefinition const& rColorDefinition); + void writeComplexColor(model::ComplexColor const& rComplexColor); + void writeColorPlaceholder(model::ComplexColor const& rComplexColor); + void writeColorSystem(model::ComplexColor const& rComplexColor); + void writeColorScheme(model::ComplexColor const& rComplexColor); + void writeColorHSL(model::ComplexColor const& rComplexColor); + void writeColorCRGB(model::ComplexColor const& rComplexColor); + void writeColorRGB(model::ComplexColor const& rComplexColor); void writeColorTransformations(std::vector<model::Transformation> const& rTransformations); }; diff --git a/oox/inc/drawingml/colorchoicecontext.hxx b/oox/inc/drawingml/colorchoicecontext.hxx index 73159688ff20..ddd720e3c53d 100644 --- a/oox/inc/drawingml/colorchoicecontext.hxx +++ b/oox/inc/drawingml/colorchoicecontext.hxx @@ -34,7 +34,7 @@ class Color; class ColorValueContext final : public ::oox::core::ContextHandler2 { public: - explicit ColorValueContext(::oox::core::ContextHandler2Helper const & rParent, Color& rColor, model::ColorDefinition* pColorDefinition = nullptr); + explicit ColorValueContext(::oox::core::ContextHandler2Helper const & rParent, Color& rColor, model::ComplexColor* pComplexColor = nullptr); virtual void onStartElement(const ::oox::AttributeList& rAttribs) override; @@ -43,7 +43,7 @@ public: private: Color& mrColor; - model::ColorDefinition* mpColorDefinition; + model::ComplexColor* mpComplexColor; }; @@ -52,7 +52,7 @@ private: class ColorContext : public ::oox::core::ContextHandler2 { public: - explicit ColorContext(::oox::core::ContextHandler2Helper const & rParent, Color& rColor, model::ColorDefinition* pColorDefinition = nullptr); + explicit ColorContext(::oox::core::ContextHandler2Helper const & rParent, Color& rColor, model::ComplexColor* pComplexColor = nullptr); virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const ::oox::AttributeList& rAttribs) override; @@ -61,7 +61,7 @@ private: Color& mrColor; protected: - model::ColorDefinition* mpColorDefinition; + model::ComplexColor* mpComplexColor; }; /// Same as ColorContext, but handles multiple colors. diff --git a/oox/source/drawingml/colorchoicecontext.cxx b/oox/source/drawingml/colorchoicecontext.cxx index d3fff573a711..b0977c5e003c 100644 --- a/oox/source/drawingml/colorchoicecontext.cxx +++ b/oox/source/drawingml/colorchoicecontext.cxx @@ -98,10 +98,10 @@ const std::unordered_map<sal_Int32, model::TransformationType> constTransformTyp } -ColorValueContext::ColorValueContext(ContextHandler2Helper const & rParent, Color& rColor, model::ColorDefinition* pColorDefinition) +ColorValueContext::ColorValueContext(ContextHandler2Helper const & rParent, Color& rColor, model::ComplexColor* pComplexColor) : ContextHandler2(rParent) , mrColor(rColor) - , mpColorDefinition(pColorDefinition) + , mpComplexColor(pComplexColor) { } @@ -115,9 +115,9 @@ void ColorValueContext::onStartElement( const AttributeList& rAttribs ) rAttribs.getInteger( XML_r, 0 ), rAttribs.getInteger( XML_g, 0 ), rAttribs.getInteger( XML_b, 0 ) ); - if (mpColorDefinition) + if (mpComplexColor) { - mpColorDefinition->setCRGB( + mpComplexColor->setCRGB( rAttribs.getInteger(XML_r, 0), rAttribs.getInteger(XML_g, 0), rAttribs.getInteger(XML_b, 0)); @@ -128,9 +128,9 @@ void ColorValueContext::onStartElement( const AttributeList& rAttribs ) case A_TOKEN(srgbClr): { mrColor.setSrgbClr(rAttribs.getIntegerHex(XML_val, 0)); - if (mpColorDefinition) + if (mpComplexColor) { - mpColorDefinition->setRGB(rAttribs.getIntegerHex(XML_val, 0)); + mpComplexColor->setRGB(rAttribs.getIntegerHex(XML_val, 0)); } } break; @@ -142,9 +142,9 @@ void ColorValueContext::onStartElement( const AttributeList& rAttribs ) rAttribs.getInteger( XML_sat, 0 ), rAttribs.getInteger( XML_lum, 0 ) ); - if (mpColorDefinition) + if (mpComplexColor) { - mpColorDefinition->setHSL( + mpComplexColor->setHSL( rAttribs.getInteger(XML_hue, 0), rAttribs.getInteger(XML_sat, 0), rAttribs.getInteger(XML_lum, 0)); @@ -159,14 +159,14 @@ void ColorValueContext::onStartElement( const AttributeList& rAttribs ) mrColor.setSysClr(nToken, nLastColor); - if (mpColorDefinition) + if (mpComplexColor) { auto aIterator = constSystemColorMap.find(nToken); if (aIterator != constSystemColorMap.end()) { auto const& aPair = *aIterator; model::SystemColorType eType = aPair.second; - mpColorDefinition->setSystemColor(eType, nLastColor); + mpComplexColor->setSystemColor(eType, nLastColor); } } } @@ -181,16 +181,16 @@ void ColorValueContext::onStartElement( const AttributeList& rAttribs ) { mrColor.setSchemeName(*sSchemeName); - if (mpColorDefinition) + if (mpComplexColor) { if (nToken == XML_phClr) { - mpColorDefinition->setSchemePlaceholder(); + mpComplexColor->setSchemePlaceholder(); } else { model::ThemeColorType eType = schemeNameToThemeColorType(*sSchemeName); - mpColorDefinition->setSchemeColor(eType); + mpComplexColor->setSchemeColor(eType); } } } @@ -201,14 +201,14 @@ void ColorValueContext::onStartElement( const AttributeList& rAttribs ) { sal_Int32 nToken = rAttribs.getToken(XML_val, XML_TOKEN_INVALID); mrColor.setPrstClr(nToken); - if (mpColorDefinition) + if (mpComplexColor) { // TODO - just converted to RGB for now ::Color nRgbValue = Color::getDmlPresetColor(nToken, API_RGB_TRANSPARENT); - mpColorDefinition->mnComponent1 = nRgbValue.GetRed(); - mpColorDefinition->mnComponent2 = nRgbValue.GetGreen(); - mpColorDefinition->mnComponent3 = nRgbValue.GetBlue(); - mpColorDefinition->meType = model::ColorType::RGB; + mpComplexColor->mnComponent1 = nRgbValue.GetRed(); + mpComplexColor->mnComponent2 = nRgbValue.GetGreen(); + mpComplexColor->mnComponent3 = nRgbValue.GetBlue(); + mpComplexColor->meType = model::ColorType::RGB; } } break; @@ -264,7 +264,7 @@ void ColorValueContext::onStartElement( const AttributeList& rAttribs ) break; } - if (mpColorDefinition) + if (mpComplexColor) { auto aIterator = constTransformTypeMap.find(getBaseToken(nElement)); if (aIterator != constTransformTypeMap.end()) @@ -279,17 +279,17 @@ void ColorValueContext::onStartElement( const AttributeList& rAttribs ) else nValue = rAttribs.getInteger(XML_val, 0); - mpColorDefinition->maTransformations.push_back({eType, sal_Int16(nValue / 10)}); + mpComplexColor->maTransformations.push_back({eType, sal_Int16(nValue / 10)}); } } return nullptr; } -ColorContext::ColorContext(ContextHandler2Helper const & rParent, Color& rColor, model::ColorDefinition* pColorDefinition) +ColorContext::ColorContext(ContextHandler2Helper const & rParent, Color& rColor, model::ComplexColor* pComplexColor) : ContextHandler2(rParent) , mrColor(rColor) - , mpColorDefinition(pColorDefinition) + , mpComplexColor(pComplexColor) { } @@ -304,7 +304,7 @@ ColorContext::ColorContext(ContextHandler2Helper const & rParent, Color& rColor, case A_TOKEN( sysClr ): case A_TOKEN( schemeClr ): case A_TOKEN( prstClr ): - return new ColorValueContext(*this, mrColor, mpColorDefinition); + return new ColorValueContext(*this, mrColor, mpComplexColor); } return nullptr; } diff --git a/oox/source/drawingml/effectpropertiescontext.cxx b/oox/source/drawingml/effectpropertiescontext.cxx index 017d45e4d5ee..ff5a046927dd 100644 --- a/oox/source/drawingml/effectpropertiescontext.cxx +++ b/oox/source/drawingml/effectpropertiescontext.cxx @@ -89,7 +89,7 @@ ContextHandlerRef EffectPropertiesContext::onCreateContext( sal_Int32 nElement, mrEffectProperties.maShadow.moShadowBlur = rAttribs.getInteger( XML_blurRad, 0 ); mrEffectProperties.maShadow.moShadowAlignment = convertToRectangleAlignment( rAttribs.getToken(XML_algn, XML_b) ); - model::ColorDefinition* pColor = nullptr; + model::ComplexColor* pColor = nullptr; if (mpEffectStyle) { auto& rEffect = mpEffectStyle->maEffectList.emplace_back(); @@ -117,7 +117,7 @@ ContextHandlerRef EffectPropertiesContext::onCreateContext( sal_Int32 nElement, mrEffectProperties.maShadow.moShadowDist = rAttribs.getInteger( XML_dist, 0 ); mrEffectProperties.maShadow.moShadowDir = rAttribs.getInteger( XML_dir, 0 ); - model::ColorDefinition* pColor = nullptr; + model::ComplexColor* pColor = nullptr; if (mpEffectStyle) { auto& rEffect = mpEffectStyle->maEffectList.emplace_back(); @@ -136,7 +136,7 @@ ContextHandlerRef EffectPropertiesContext::onCreateContext( sal_Int32 nElement, // undo push_back to effects mrEffectProperties.m_Effects.pop_back(); - model::ColorDefinition* pColor = nullptr; + model::ComplexColor* pColor = nullptr; if (mpEffectStyle) { auto& rEffect = mpEffectStyle->maEffectList.emplace_back(); @@ -163,7 +163,7 @@ ContextHandlerRef EffectPropertiesContext::onCreateContext( sal_Int32 nElement, mrEffectProperties.m_Effects[nPos]->msName = "reflection"; saveUnsupportedAttribs(*mrEffectProperties.m_Effects[nPos], rAttribs); - model::ColorDefinition* pColor = nullptr; + model::ComplexColor* pColor = nullptr; if (mpEffectStyle) { auto& rEffect = mpEffectStyle->maEffectList.emplace_back(); @@ -194,7 +194,7 @@ ContextHandlerRef EffectPropertiesContext::onCreateContext( sal_Int32 nElement, mrEffectProperties.m_Effects[nPos]->msName = "blur"; saveUnsupportedAttribs(*mrEffectProperties.m_Effects[nPos], rAttribs); - model::ColorDefinition* pColor = nullptr; + model::ComplexColor* pColor = nullptr; if (mpEffectStyle) { auto& rEffect = mpEffectStyle->maEffectList.emplace_back(); diff --git a/oox/source/drawingml/misccontexts.cxx b/oox/source/drawingml/misccontexts.cxx index 26df16a17553..25058d392600 100644 --- a/oox/source/drawingml/misccontexts.cxx +++ b/oox/source/drawingml/misccontexts.cxx @@ -38,7 +38,7 @@ using ::oox::core::ContextHandlerRef; namespace oox::drawingml { SolidFillContext::SolidFillContext(ContextHandler2Helper const & rParent, FillProperties& rFillProps, model::SolidFill* pSolidFill) - : ColorContext(rParent, rFillProps.maFillColor, pSolidFill ? &pSolidFill->maColorDefinition : nullptr) + : ColorContext(rParent, rFillProps.maFillColor, pSolidFill ? &pSolidFill->maColor : nullptr) { } @@ -72,15 +72,15 @@ ContextHandlerRef GradientFillContext::onCreateContext( double fPosition = getLimitedValue<double>(rAttribs.getDouble(XML_pos, 0.0) / 100000.0, 0.0, 1.0); auto aElement = mrGradientProps.maGradientStops.emplace(fPosition, Color()); - model::ColorDefinition* pColorDefinition = nullptr; + model::ComplexColor* pComplexColor = nullptr; if (mpGradientFill) { model::GradientStop& rStop = mpGradientFill->maGradientStops.emplace_back(); rStop.mfPosition = fPosition; - pColorDefinition = &rStop.maColor; + pComplexColor = &rStop.maColor; } - return new ColorContext(*this, aElement->second, pColorDefinition); + return new ColorContext(*this, aElement->second, pComplexColor); } break; @@ -227,17 +227,17 @@ PatternFillContext::PatternFillContext(ContextHandler2Helper const & rParent, ContextHandlerRef PatternFillContext::onCreateContext( sal_Int32 nElement, const AttributeList& ) { - model::ColorDefinition* pColorDefinition = nullptr; + model::ComplexColor* pComplexColor = nullptr; switch( nElement ) { case A_TOKEN( bgClr ): if (mpPatternFill) - pColorDefinition = &mpPatternFill->maBackgroundColor; - return new ColorContext(*this, mrPatternProps.maPattBgColor, pColorDefinition); + pComplexColor = &mpPatternFill->maBackgroundColor; + return new ColorContext(*this, mrPatternProps.maPattBgColor, pComplexColor); case A_TOKEN( fgClr ): if (mpPatternFill) - pColorDefinition = &mpPatternFill->maForegroundColor; - return new ColorContext(*this, mrPatternProps.maPattFgColor, pColorDefinition); + pComplexColor = &mpPatternFill->maForegroundColor; + return new ColorContext(*this, mrPatternProps.maPattFgColor, pComplexColor); } return nullptr; } @@ -268,23 +268,23 @@ ColorChangeContext::~ColorChangeContext() ContextHandlerRef ColorChangeContext::onCreateContext( sal_Int32 nElement, const AttributeList& ) { - model::ColorDefinition* pColorDefinition = nullptr; + model::ComplexColor* pComplexColor = nullptr; switch (nElement) { case A_TOKEN(clrFrom): if (mpBlipFill) { auto& rEffect = mpBlipFill->maBlipEffects.back(); - pColorDefinition = &rEffect.getColorFrom(); + pComplexColor = &rEffect.getColorFrom(); } - return new ColorContext(*this, mrBlipProps.maColorChangeFrom, pColorDefinition); + return new ColorContext(*this, mrBlipProps.maColorChangeFrom, pComplexColor); case A_TOKEN(clrTo): if (mpBlipFill) { auto& rEffect = mpBlipFill->maBlipEffects.back(); - pColorDefinition = &rEffect.getColorTo(); + pComplexColor = &rEffect.getColorTo(); } - return new ColorContext(*this, mrBlipProps.maColorChangeTo, pColorDefinition); + return new ColorContext(*this, mrBlipProps.maColorChangeTo, pComplexColor); } return nullptr; } diff --git a/oox/source/export/ThemeExport.cxx b/oox/source/export/ThemeExport.cxx index 88ff2d6364fc..cd944ed1a7ea 100644 --- a/oox/source/export/ThemeExport.cxx +++ b/oox/source/export/ThemeExport.cxx @@ -161,32 +161,32 @@ void ThemeExport::writeColorTransformations( } } -void ThemeExport::writeColorRGB(model::ColorDefinition const& rColorDefinition) +void ThemeExport::writeColorRGB(model::ComplexColor const& rComplexColor) { - auto aColor = rColorDefinition.getRGBColor(); + auto aColor = rComplexColor.getRGBColor(); mpFS->startElementNS(XML_a, XML_srgbClr, XML_val, I32SHEX(sal_Int32(aColor))); mpFS->endElementNS(XML_a, XML_srgbClr); } -void ThemeExport::writeColorCRGB(model::ColorDefinition const& rColorDefinition) +void ThemeExport::writeColorCRGB(model::ComplexColor const& rComplexColor) { - mpFS->startElementNS(XML_a, XML_scrgbClr, XML_r, OString::number(rColorDefinition.mnComponent1), - XML_g, OString::number(rColorDefinition.mnComponent2), XML_b, - OString::number(rColorDefinition.mnComponent3)); - writeColorTransformations(rColorDefinition.maTransformations); + mpFS->startElementNS(XML_a, XML_scrgbClr, XML_r, OString::number(rComplexColor.mnComponent1), + XML_g, OString::number(rComplexColor.mnComponent2), XML_b, + OString::number(rComplexColor.mnComponent3)); + writeColorTransformations(rComplexColor.maTransformations); mpFS->endElementNS(XML_a, XML_scrgbClr); } -void ThemeExport::writeColorHSL(model::ColorDefinition const& rColorDefinition) +void ThemeExport::writeColorHSL(model::ComplexColor const& rComplexColor) { - mpFS->startElementNS(XML_a, XML_hslClr, XML_hue, OString::number(rColorDefinition.mnComponent1), - XML_sat, OString::number(rColorDefinition.mnComponent2), XML_lum, - OString::number(rColorDefinition.mnComponent3)); - writeColorTransformations(rColorDefinition.maTransformations); + mpFS->startElementNS(XML_a, XML_hslClr, XML_hue, OString::number(rComplexColor.mnComponent1), + XML_sat, OString::number(rComplexColor.mnComponent2), XML_lum, + OString::number(rComplexColor.mnComponent3)); + writeColorTransformations(rComplexColor.maTransformations); mpFS->endElementNS(XML_a, XML_hslClr); } -void ThemeExport::writeColorScheme(model::ColorDefinition const& rColorDefinition) +void ThemeExport::writeColorScheme(model::ComplexColor const& rComplexColor) { static std::unordered_map<model::ThemeColorType, const char*> constThemeColorTypeTokenMap = { { model::ThemeColorType::Dark1, "dk1" }, @@ -201,17 +201,17 @@ void ThemeExport::writeColorScheme(model::ColorDefinition const& rColorDefinitio { model::ThemeColorType::Accent6, "accent6" }, { model::ThemeColorType::Hyperlink, "hlink" }, { model::ThemeColorType::FollowedHyperlink, "folHlink" } }; - auto iterator = constThemeColorTypeTokenMap.find(rColorDefinition.meSchemeType); + auto iterator = constThemeColorTypeTokenMap.find(rComplexColor.meSchemeType); if (iterator != constThemeColorTypeTokenMap.end()) { const char* sValue = iterator->second; mpFS->startElementNS(XML_a, XML_schemeClr, XML_val, sValue); - writeColorTransformations(rColorDefinition.maTransformations); + writeColorTransformations(rComplexColor.maTransformations); mpFS->endElementNS(XML_a, XML_schemeClr); } } -void ThemeExport::writeColorSystem(model::ColorDefinition const& rColorDefinition) +void ThemeExport::writeColorSystem(model::ComplexColor const& rComplexColor) { static std::unordered_map<model::SystemColorType, const char*> constThemeColorTypeTokenMap = { { model::SystemColorType::DarkShadow3D, "3dDkShadow" }, @@ -245,49 +245,49 @@ void ThemeExport::writeColorSystem(model::ColorDefinition const& rColorDefinitio { model::SystemColorType::WindowFrame, "windowFrame" }, { model::SystemColorType::WindowText, "windowText" }, }; - auto iterator = constThemeColorTypeTokenMap.find(rColorDefinition.meSystemColorType); + auto iterator = constThemeColorTypeTokenMap.find(rComplexColor.meSystemColorType); if (iterator != constThemeColorTypeTokenMap.end()) { const char* sValue = iterator->second; mpFS->startElementNS(XML_a, XML_sysClr, XML_val, sValue); //XML_lastClr - writeColorTransformations(rColorDefinition.maTransformations); + writeColorTransformations(rComplexColor.maTransformations); mpFS->endElementNS(XML_a, XML_schemeClr); } } -void ThemeExport::writeColorPlaceholder(model::ColorDefinition const& rColorDefinition) +void ThemeExport::writeColorPlaceholder(model::ComplexColor const& rComplexColor) { mpFS->startElementNS(XML_a, XML_schemeClr, XML_val, "phClr"); - writeColorTransformations(rColorDefinition.maTransformations); + writeColorTransformations(rComplexColor.maTransformations); mpFS->endElementNS(XML_a, XML_schemeClr); } -void ThemeExport::writeColorDefinition(model::ColorDefinition const& rColorDefinition) +void ThemeExport::writeComplexColor(model::ComplexColor const& rComplexColor) { - switch (rColorDefinition.meType) + switch (rComplexColor.meType) { case model::ColorType::Unused: break; case model::ColorType::RGB: - writeColorRGB(rColorDefinition); + writeColorRGB(rComplexColor); break; case model::ColorType::CRGB: - writeColorCRGB(rColorDefinition); + writeColorCRGB(rComplexColor); break; case model::ColorType::HSL: - writeColorHSL(rColorDefinition); + writeColorHSL(rComplexColor); break; case model::ColorType::Scheme: - writeColorScheme(rColorDefinition); + writeColorScheme(rComplexColor); break; case model::ColorType::Palette: break; case model::ColorType::System: - writeColorSystem(rColorDefinition); + writeColorSystem(rComplexColor); break; case model::ColorType::Placeholder: - writeColorPlaceholder(rColorDefinition); + writeColorPlaceholder(rComplexColor); break; } } @@ -295,7 +295,7 @@ void ThemeExport::writeColorDefinition(model::ColorDefinition const& rColorDefin void ThemeExport::writeSolidFill(model::SolidFill const& rSolidFill) { mpFS->startElementNS(XML_a, XML_solidFill); - writeColorDefinition(rSolidFill.maColorDefinition); + writeComplexColor(rSolidFill.maColor); mpFS->endElementNS(XML_a, XML_solidFill); } @@ -307,7 +307,7 @@ void ThemeExport::writeGradientFill(model::GradientFill const& rGradientFill) { mpFS->startElementNS(XML_a, XML_gs, XML_pos, OString::number(sal_Int32(rStop.mfPosition * 100000.0))); - writeColorDefinition(rStop.maColor); + writeComplexColor(rStop.maColor); mpFS->endElementNS(XML_a, XML_gs); } mpFS->endElementNS(XML_a, XML_gsLst); @@ -523,11 +523,11 @@ void ThemeExport::writePatternFill(model::PatternFill const& rPatternFill) mpFS->startElementNS(XML_a, XML_pattFill, XML_prst, sPresetType); mpFS->startElementNS(XML_a, XML_fgClr); - writeColorDefinition(rPatternFill.maForegroundColor); + writeComplexColor(rPatternFill.maForegroundColor); mpFS->endElementNS(XML_a, XML_fgClr); mpFS->startElementNS(XML_a, XML_bgClr); - writeColorDefinition(rPatternFill.maBackgroundColor); + writeComplexColor(rPatternFill.maBackgroundColor); mpFS->endElementNS(XML_a, XML_bgClr); mpFS->endElementNS(XML_a, XML_pattFill); diff --git a/sw/qa/core/theme/ThemeTest.cxx b/sw/qa/core/theme/ThemeTest.cxx index 802185494991..169854ec3535 100644 --- a/sw/qa/core/theme/ThemeTest.cxx +++ b/sw/qa/core/theme/ThemeTest.cxx @@ -54,8 +54,8 @@ void checkFillStyles(std::vector<model::FillStyle> const& rStyleList) CPPUNIT_ASSERT(rFillStyle.mpFill); CPPUNIT_ASSERT_EQUAL(model::FillType::Solid, rFillStyle.mpFill->meType); auto* pSolidFill = static_cast<model::SolidFill*>(rFillStyle.mpFill.get()); - CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder, pSolidFill->maColorDefinition.meType); - CPPUNIT_ASSERT_EQUAL(size_t(0), pSolidFill->maColorDefinition.maTransformations.size()); + CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder, pSolidFill->maColor.meType); + CPPUNIT_ASSERT_EQUAL(size_t(0), pSolidFill->maColor.maTransformations.size()); } // Fill style 2 @@ -238,8 +238,8 @@ void checkLineStyles(std::vector<model::LineStyle> const& rStyleList) CPPUNIT_ASSERT(rFillStyle.mpFill); CPPUNIT_ASSERT_EQUAL(model::FillType::Solid, rFillStyle.mpFill->meType); auto* pSolidFill = static_cast<model::SolidFill*>(rFillStyle.mpFill.get()); - CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder, pSolidFill->maColorDefinition.meType); - CPPUNIT_ASSERT_EQUAL(size_t(0), pSolidFill->maColorDefinition.maTransformations.size()); + CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder, pSolidFill->maColor.meType); + CPPUNIT_ASSERT_EQUAL(size_t(0), pSolidFill->maColor.maTransformations.size()); } // Line style 2 @@ -257,8 +257,8 @@ void checkLineStyles(std::vector<model::LineStyle> const& rStyleList) CPPUNIT_ASSERT(rFillStyle.mpFill); CPPUNIT_ASSERT_EQUAL(model::FillType::Solid, rFillStyle.mpFill->meType); auto* pSolidFill = static_cast<model::SolidFill*>(rFillStyle.mpFill.get()); - CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder, pSolidFill->maColorDefinition.meType); - CPPUNIT_ASSERT_EQUAL(size_t(0), pSolidFill->maColorDefinition.maTransformations.size()); + CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder, pSolidFill->maColor.meType); + CPPUNIT_ASSERT_EQUAL(size_t(0), pSolidFill->maColor.maTransformations.size()); } // Line style 3 @@ -276,8 +276,8 @@ void checkLineStyles(std::vector<model::LineStyle> const& rStyleList) CPPUNIT_ASSERT(rFillStyle.mpFill); CPPUNIT_ASSERT_EQUAL(model::FillType::Solid, rFillStyle.mpFill->meType); auto* pSolidFill = static_cast<model::SolidFill*>(rFillStyle.mpFill.get()); - CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder, pSolidFill->maColorDefinition.meType); - CPPUNIT_ASSERT_EQUAL(size_t(0), pSolidFill->maColorDefinition.maTransformations.size()); + CPPUNIT_ASSERT_EQUAL(model::ColorType::Placeholder, pSolidFill->maColor.meType); + CPPUNIT_ASSERT_EQUAL(size_t(0), pSolidFill->maColor.maTransformations.size()); } } commit a0a61ffc29cde98d32dcd3b8d71cc8c21cb6e493 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Sun Apr 30 15:24:39 2023 +0900 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Mon May 1 06:05:13 2023 +0200 docmodel: extract Transformation from ThemeColor into own file Change-Id: I45316e377cf895773037f500c521111f7e4d1ed7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151223 Tested-by: Tomaž Vajngerl <qui...@gmail.com> Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/include/docmodel/color/Transformation.hxx b/include/docmodel/color/Transformation.hxx new file mode 100644 index 000000000000..26f618dee289 --- /dev/null +++ b/include/docmodel/color/Transformation.hxx @@ -0,0 +1,72 @@ +/* -*- 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 <docmodel/dllapi.h> +#include <vector> + +namespace model +{ +/** Color transformation type */ +enum class TransformationType +{ + Undefined, + Red, + RedMod, + RedOff, + Green, + GreenMod, + GreenOff, + Blue, + BlueMod, + BlueOff, + Alpha, + AlphaMod, + AlphaOff, + Hue, + HueMod, + HueOff, + Sat, + SatMod, + SatOff, + Lum, + LumMod, + LumOff, + Shade, + Tint, + Gray, + Comp, + Inv, + Gamma, + InvGamma +}; + +/** Definition of a color transformation. + * + * This just defines how a color should be transformed (changed). The + * type defines what kind of transformation should occur and the value + * defines by how much. + */ +struct DOCMODEL_DLLPUBLIC Transformation +{ + TransformationType meType = TransformationType::Undefined; + + sal_Int16 mnValue = 0; /// percentage value -10000 to +10000 + + bool operator==(const Transformation& rTransformation) const + { + return meType == rTransformation.meType && mnValue == rTransformation.mnValue; + } +}; + +} // end of namespace model + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/docmodel/theme/ThemeColor.hxx b/include/docmodel/theme/ThemeColor.hxx index 4d10cce2579d..33d841155815 100644 --- a/include/docmodel/theme/ThemeColor.hxx +++ b/include/docmodel/theme/ThemeColor.hxx @@ -13,61 +13,11 @@ #include <docmodel/dllapi.h> #include <vector> #include <docmodel/theme/ThemeColorType.hxx> +#include <docmodel/color/Transformation.hxx> #include <tools/color.hxx> namespace model { -/** Color transformation type */ -enum class TransformationType -{ - Undefined, - Red, - RedMod, - RedOff, - Green, - GreenMod, - GreenOff, - Blue, - BlueMod, - BlueOff, - Alpha, - AlphaMod, - AlphaOff, - Hue, - HueMod, - HueOff, - Sat, - SatMod, - SatOff, - Lum, - LumMod, - LumOff, - Shade, - Tint, - Gray, - Comp, - Inv, - Gamma, - InvGamma -}; - -/** Definition of a color transformation. - * - * This just defines how a color should be transformed (changed). The - * type defines what kind of transformation should occur and the value - * defines by how much. - */ -struct DOCMODEL_DLLPUBLIC Transformation -{ - TransformationType meType = TransformationType::Undefined; - sal_Int16 mnValue = 0; /// percentage value -10000 to +10000 - - bool operator==(const Transformation& rTransformation) const - { - return meType == rTransformation.meType && mnValue == rTransformation.mnValue; - } -}; - /** Definition of a theme color * * A theme color is defined by the type of theme color and a set of