From 7a0cf6797bb53d1fec5101a8f7007d2287ae53b0 Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Fri, 24 Feb 2023 00:29:45 +0900 Subject: oox: introduce FormatScheme - use in Theme import MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduces model::FormatScheme as an member of model::Theme, which is used in the theme import. As an first step it imports FillStyleList, but only SolidFill and NoFill. Change-Id: I14a75782ebabcf7ff69b0872752d411183653a47 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147573 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- include/docmodel/theme/FormatScheme.hxx | 196 +++++++++++++++++++++ include/docmodel/theme/Theme.hxx | 7 +- include/oox/drawingml/color.hxx | 5 +- oox/inc/drawingml/colorchoicecontext.hxx | 30 ++-- oox/inc/drawingml/misccontexts.hxx | 17 +- oox/source/drawingml/clrschemecontext.cxx | 2 +- oox/source/drawingml/color.cxx | 56 ++++-- oox/source/drawingml/colorchoicecontext.cxx | 151 +++++++++++++--- oox/source/drawingml/diagram/datamodelcontext.cxx | 3 +- oox/source/drawingml/linepropertiescontext.cxx | 2 +- oox/source/drawingml/misccontexts.cxx | 60 +++++-- oox/source/drawingml/shapepropertiescontext.cxx | 2 +- oox/source/drawingml/table/tablecellcontext.cxx | 3 +- .../drawingml/textcharacterpropertiescontext.cxx | 2 +- oox/source/drawingml/themeelementscontext.cxx | 35 +++- oox/source/ppt/backgroundproperties.cxx | 2 +- 16 files changed, 481 insertions(+), 92 deletions(-) create mode 100644 include/docmodel/theme/FormatScheme.hxx diff --git a/include/docmodel/theme/FormatScheme.hxx b/include/docmodel/theme/FormatScheme.hxx new file mode 100644 index 000000000000..a256532791d9 --- /dev/null +++ b/include/docmodel/theme/FormatScheme.hxx @@ -0,0 +1,196 @@ +/* -*- 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 +#include +#include + +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 maTransformations; + + 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, + Solid, + Gradient, + Pattern, + Blip +}; + +class DOCMODEL_DLLPUBLIC Fill +{ +public: + Fill(FillType eType) + : meType(eType) + { + } + + FillType meType; +}; + +class DOCMODEL_DLLPUBLIC NoFill : public Fill +{ +public: + NoFill() + : Fill(FillType::None) + { + } +}; + +class DOCMODEL_DLLPUBLIC SolidFill : public Fill +{ +public: + ColorDefinition maColorDefinition; + + SolidFill() + : Fill(FillType::Solid) + { + } +}; + +// Format Scheme + +class DOCMODEL_DLLPUBLIC FillStyle +{ +public: + std::shared_ptr mpFill; +}; + +class DOCMODEL_DLLPUBLIC BackgroundFillStyle +{ +public: + std::shared_ptr mpFill; +}; + +class DOCMODEL_DLLPUBLIC FormatScheme +{ +private: + OUString maName; + std::vector maFillStyleList; + std::vector maBackgroundFillStyleList; + +public: + FormatScheme() = default; + + FormatScheme(OUString const& rName) + : maName(rName) + { + } + + const OUString& getName() const { return maName; } +}; + +} // end of namespace svx + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/docmodel/theme/Theme.hxx b/include/docmodel/theme/Theme.hxx index 5f5e47578db5..70766a8488ae 100644 --- a/include/docmodel/theme/Theme.hxx +++ b/include/docmodel/theme/Theme.hxx @@ -18,6 +18,7 @@ #include #include #include +#include #include typedef struct _xmlTextWriter* xmlTextWriterPtr; @@ -143,6 +144,7 @@ private: std::unique_ptr mpColorSet; FontScheme maFontScheme; + FormatScheme maFormatScheme; public: Theme(); @@ -151,9 +153,12 @@ public: Theme(Theme const& rTheme); void setFontScheme(FontScheme const& rFontScheme) { maFontScheme = rFontScheme; } - FontScheme const& getFontScheme() const { return maFontScheme; } + void setFormatScheme(FormatScheme const& rFormatScheme) { maFormatScheme = rFormatScheme; } + FormatScheme const& getFormatScheme() const { return maFormatScheme; } + FormatScheme& getFormatScheme() { return maFormatScheme; } + void SetColorSet(std::unique_ptr pColorSet); const ColorSet* GetColorSet() const; ColorSet* GetColorSet(); diff --git a/include/oox/drawingml/color.hxx b/include/oox/drawingml/color.hxx index b28c926986ca..75812c200c28 100644 --- a/include/oox/drawingml/color.hxx +++ b/include/oox/drawingml/color.hxx @@ -29,11 +29,14 @@ #include #include #include +#include namespace oox { class GraphicHelper; } -namespace oox::drawingml { +namespace oox::drawingml +{ +model::ThemeColorType schemeNameToThemeColorType(OUString const& rSchemeName); class OOX_DLLPUBLIC Color { diff --git a/oox/inc/drawingml/colorchoicecontext.hxx b/oox/inc/drawingml/colorchoicecontext.hxx index 6e82ee3224b4..73159688ff20 100644 --- a/oox/inc/drawingml/colorchoicecontext.hxx +++ b/oox/inc/drawingml/colorchoicecontext.hxx @@ -21,7 +21,7 @@ #define INCLUDED_OOX_DRAWINGML_COLORCHOICECONTEXT_HXX #include - +#include #include namespace oox::drawingml { @@ -34,19 +34,16 @@ class Color; class ColorValueContext final : public ::oox::core::ContextHandler2 { public: - explicit ColorValueContext( ::oox::core::ContextHandler2Helper const & rParent, Color& rColor ); - + explicit ColorValueContext(::oox::core::ContextHandler2Helper const & rParent, Color& rColor, model::ColorDefinition* pColorDefinition = nullptr); - virtual void onStartElement( - const ::oox::AttributeList& rAttribs ) override; + virtual void onStartElement(const ::oox::AttributeList& rAttribs) override; - virtual ::oox::core::ContextHandlerRef - onCreateContext( - sal_Int32 nElement, - const ::oox::AttributeList& rAttribs ) override; + virtual ::oox::core::ContextHandlerRef onCreateContext( + sal_Int32 nElement, const ::oox::AttributeList& rAttribs) override; private: - Color& mrColor; + Color& mrColor; + model::ColorDefinition* mpColorDefinition; }; @@ -55,15 +52,16 @@ private: class ColorContext : public ::oox::core::ContextHandler2 { public: - explicit ColorContext( ::oox::core::ContextHandler2Helper const & rParent, Color& rColor ); + explicit ColorContext(::oox::core::ContextHandler2Helper const & rParent, Color& rColor, model::ColorDefinition* pColorDefinition = nullptr); - virtual ::oox::core::ContextHandlerRef - onCreateContext( - sal_Int32 nElement, - const ::oox::AttributeList& rAttribs ) override; + virtual ::oox::core::ContextHandlerRef onCreateContext( + sal_Int32 nElement, const ::oox::AttributeList& rAttribs) override; private: - Color& mrColor; + Color& mrColor; + +protected: + model::ColorDefinition* mpColorDefinition; }; /// Same as ColorContext, but handles multiple colors. diff --git a/oox/inc/drawingml/misccontexts.hxx b/oox/inc/drawingml/misccontexts.hxx index 495b3bce906c..e2e255d10b64 100644 --- a/oox/inc/drawingml/misccontexts.hxx +++ b/oox/inc/drawingml/misccontexts.hxx @@ -23,17 +23,18 @@ #include #include +#include -namespace oox::drawingml { - +namespace oox::drawingml +{ /** Context handler that imports the a:solidFill element. */ class SolidFillContext final : public ColorContext { public: - explicit SolidFillContext( - ::oox::core::ContextHandler2Helper const & rParent, - FillProperties& rFillProps ); + explicit SolidFillContext(::oox::core::ContextHandler2Helper const & rParent, + FillProperties& rFillProps, model::SolidFill* pSolidFill); + ~SolidFillContext(); }; @@ -212,10 +213,12 @@ public: ::oox::core::ContextHandler2Helper const & rParent, sal_Int32 nElement, const ::oox::AttributeList& rAttribs, - FillProperties& rFillProps ); + FillProperties& rFillProps, + model::FillStyle* pFillStyle); private: - FillProperties& mrFillProps; + FillProperties& mrFillProps; + model::FillStyle maFillStyle; }; /** Context handler for elements that contain a fill property element diff --git a/oox/source/drawingml/clrschemecontext.cxx b/oox/source/drawingml/clrschemecontext.cxx index 5e423f3a7e8a..6023703dbe77 100644 --- a/oox/source/drawingml/clrschemecontext.cxx +++ b/oox/source/drawingml/clrschemecontext.cxx @@ -58,7 +58,7 @@ clrMapContext::clrMapContext( ContextHandler2Helper const & rParent, } clrSchemeColorContext::clrSchemeColorContext(ContextHandler2Helper const & rParent, ClrScheme& rClrScheme, model::ColorSet& rColorSet, sal_Int32 nColorToken) - : ColorContext(rParent, *this) + : ColorContext(rParent, *this, nullptr) , mrClrScheme(rClrScheme) , mrColorSet(rColorSet) , mnColorToken(nColorToken) diff --git a/oox/source/drawingml/color.cxx b/oox/source/drawingml/color.cxx index 9e9218f285e8..592d0734efc2 100644 --- a/oox/source/drawingml/color.cxx +++ b/oox/source/drawingml/color.cxx @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -211,6 +212,44 @@ void lclOffValue( sal_Int32& ornValue, sal_Int32 nOff, sal_Int32 nMax = MAX_PERC } // namespace +model::ThemeColorType schemeNameToThemeColorType(OUString const& rSchemeName) +{ + static std::unordered_map const aSchemeColorNameToIndex{ + { u"dk1", model::ThemeColorType::Dark1 }, + { u"lt1", model::ThemeColorType::Light1 }, + { u"dk2", model::ThemeColorType::Dark2 }, + { u"lt2", model::ThemeColorType::Light2 }, + { u"accent1", model::ThemeColorType::Accent1 }, + { u"accent2", model::ThemeColorType::Accent2 }, + { u"accent3", model::ThemeColorType::Accent3 }, + { u"accent4", model::ThemeColorType::Accent4 }, + { u"accent5", model::ThemeColorType::Accent5 }, + { u"accent6", model::ThemeColorType::Accent6 }, + { u"hlink", model::ThemeColorType::Hyperlink }, + { u"folHlink", model::ThemeColorType::FollowedHyperlink }, + { u"tx1", model::ThemeColorType::Dark1 }, + { u"bg1", model::ThemeColorType::Light1 }, + { u"tx2", model::ThemeColorType::Dark2 }, + { u"bg2", model::ThemeColorType::Light2 }, + { u"dark1", model::ThemeColorType::Dark1}, + { u"light1", model::ThemeColorType::Light1}, + { u"dark2", model::ThemeColorType::Dark2 }, + { u"light2", model::ThemeColorType::Light2 }, + { u"text1", model::ThemeColorType::Dark1 }, + { u"background1", model::ThemeColorType::Light1 }, + { u"text2", model::ThemeColorType::Dark2 }, + { u"background2", model::ThemeColorType::Light2 }, + { u"hyperlink", model::ThemeColorType::Hyperlink }, + { u"followedHyperlink", model::ThemeColorType::FollowedHyperlink} + }; + + auto aIterator = aSchemeColorNameToIndex.find(rSchemeName); + if (aIterator == aSchemeColorNameToIndex.end()) + return model::ThemeColorType::Unknown; + else + return aIterator->second; +} + Color::Color() : meMode( COLOR_UNUSED ), mnC1( 0 ), @@ -712,21 +751,8 @@ sal_Int16 Color::getTransparency() const sal_Int16 Color::getSchemeColorIndex() const { - static std::map const aSchemeColorNameToIndex{ - { "dk1", 0 }, { "lt1", 1 }, { "dk2", 2 }, { "lt2", 3 }, - { "accent1", 4 }, { "accent2", 5 }, { "accent3", 6 }, { "accent4", 7 }, - { "accent5", 8 }, { "accent6", 9 }, { "hlink", 10 }, { "folHlink", 11 }, - { "tx1", 0 }, { "bg1", 1 }, { "tx2", 2 }, { "bg2", 3 }, - { "dark1", 0}, { "light1", 1}, { "dark2", 2 }, { "light2", 3 }, - { "text1", 0 }, { "background1", 1 }, { "text2", 2 }, { "background2", 3 }, - { "hyperlink", 10 }, { "followedHyperlink", 11} - }; - - auto aIt = aSchemeColorNameToIndex.find(msSchemeName); - if( aIt == aSchemeColorNameToIndex.end() ) - return -1; - else - return aIt->second; + auto eThemeType = schemeNameToThemeColorType(msSchemeName); + return sal_Int16(eThemeType); } // private -------------------------------------------------------------------- diff --git a/oox/source/drawingml/colorchoicecontext.cxx b/oox/source/drawingml/colorchoicecontext.cxx index f63dd88d5f41..3d559299f4c2 100644 --- a/oox/source/drawingml/colorchoicecontext.cxx +++ b/oox/source/drawingml/colorchoicecontext.cxx @@ -23,12 +23,52 @@ #include #include #include +#include namespace oox::drawingml { -ColorValueContext::ColorValueContext( ContextHandler2Helper const & rParent, Color& rColor ) : - ContextHandler2( rParent ), - mrColor( rColor ) +namespace +{ + +std::unordered_map constSystemColorMap = +{ + { XML_scrollBar, model::SystemColorType::ScrollBar }, + { XML_background, model::SystemColorType::Background }, + { XML_activeCaption, model::SystemColorType::ActiveCaption }, + { XML_inactiveCaption, model::SystemColorType::InactiveCaption }, + { XML_menu, model::SystemColorType::Menu }, + { XML_window, model::SystemColorType::Window }, + { XML_windowFrame, model::SystemColorType::WindowFrame }, + { XML_menuText, model::SystemColorType::MenuText }, + { XML_windowText, model::SystemColorType::WindowText }, + { XML_captionText, model::SystemColorType::CaptionText }, + { XML_activeBorder, model::SystemColorType::ActiveBorder }, + { XML_inactiveBorder, model::SystemColorType::InactiveBorder }, + { XML_appWorkspace, model::SystemColorType::AppWorkspace }, + { XML_highlight, model::SystemColorType::Highlight }, + { XML_highlightText, model::SystemColorType::HighlightText }, + { XML_btnFace, model::SystemColorType::ButtonFace }, + { XML_btnShadow, model::SystemColorType::ButtonShadow }, + { XML_grayText, model::SystemColorType::GrayText }, + { XML_btnText, model::SystemColorType::ButtonText }, + { XML_inactiveCaptionText, model::SystemColorType::InactiveCaptionText }, + { XML_btnHighlight, model::SystemColorType::ButtonHighlight }, + { XML_3dDkShadow, model::SystemColorType::DarkShadow3D }, + { XML_3dLight, model::SystemColorType::Light3D }, + { XML_infoText, model::SystemColorType::InfoText }, + { XML_infoBk, model::SystemColorType::InfoBack }, + { XML_hotLight, model::SystemColorType::HotLight }, + { XML_gradientActiveCaption, model::SystemColorType::GradientActiveCaption }, + { XML_gradientInactiveCaption, model::SystemColorType::GradientInactiveCaption }, + { XML_menuHighlight, model::SystemColorType::MenuHighlight }, + { XML_menuBar, model::SystemColorType::MenuBar } +}; +} + +ColorValueContext::ColorValueContext(ContextHandler2Helper const & rParent, Color& rColor, model::ColorDefinition* pColorDefinition) + : ContextHandler2(rParent) + , mrColor(rColor) + , mpColorDefinition(pColorDefinition) { } @@ -36,41 +76,105 @@ void ColorValueContext::onStartElement( const AttributeList& rAttribs ) { switch( getCurrentElement() ) { - case A_TOKEN( scrgbClr ): + case A_TOKEN(scrgbClr): + { mrColor.setScrgbClr( rAttribs.getInteger( XML_r, 0 ), rAttribs.getInteger( XML_g, 0 ), rAttribs.getInteger( XML_b, 0 ) ); + if (mpColorDefinition) + { + mpColorDefinition->setCRGB( + rAttribs.getInteger(XML_r, 0), + rAttribs.getInteger(XML_g, 0), + rAttribs.getInteger(XML_b, 0)); + } + } break; - case A_TOKEN( srgbClr ): - mrColor.setSrgbClr( rAttribs.getIntegerHex( XML_val, 0 ) ); + case A_TOKEN(srgbClr): + { + mrColor.setSrgbClr(rAttribs.getIntegerHex(XML_val, 0)); + if (mpColorDefinition) + { + mpColorDefinition->setRGB(rAttribs.getIntegerHex(XML_val, 0)); + } + } break; - case A_TOKEN( hslClr ): + case A_TOKEN(hslClr): + { mrColor.setHslClr( rAttribs.getInteger( XML_hue, 0 ), rAttribs.getInteger( XML_sat, 0 ), rAttribs.getInteger( XML_lum, 0 ) ); + + if (mpColorDefinition) + { + mpColorDefinition->setHSL( + rAttribs.getInteger(XML_hue, 0), + rAttribs.getInteger(XML_sat, 0), + rAttribs.getInteger(XML_lum, 0)); + } + } break; - case A_TOKEN( sysClr ): - mrColor.setSysClr( - rAttribs.getToken( XML_val, XML_TOKEN_INVALID ), - rAttribs.getIntegerHex( XML_lastClr, -1 ) ); + case A_TOKEN(sysClr): + { + sal_Int32 nToken = rAttribs.getToken(XML_val, XML_TOKEN_INVALID); + sal_Int32 nLastColor = rAttribs.getIntegerHex(XML_lastClr, -1); + + mrColor.setSysClr(nToken, nLastColor); + + auto aIterator = constSystemColorMap.find(nToken); + if (aIterator != constSystemColorMap.end()) + { + auto const& aPair = *aIterator; + model::SystemColorType eType = aPair.second; + if (mpColorDefinition) + mpColorDefinition->setSystemColor(eType, nLastColor); + } + } break; - case A_TOKEN( schemeClr ): + case A_TOKEN(schemeClr): { - mrColor.setSchemeClr( rAttribs.getToken( XML_val, XML_TOKEN_INVALID ) ); - std::optional sSchemeName = rAttribs.getString( XML_val ); - if( sSchemeName.has_value() ) - mrColor.setSchemeName( *sSchemeName ); + auto nToken = rAttribs.getToken(XML_val, XML_TOKEN_INVALID); + mrColor.setSchemeClr(nToken); + std::optional sSchemeName = rAttribs.getString(XML_val); + if (sSchemeName.has_value()) + { + mrColor.setSchemeName(*sSchemeName); + + if (mpColorDefinition) + { + if (nToken == XML_phClr) + { + mpColorDefinition->setSchemePlaceholder(); + } + else + { + model::ThemeColorType eType = schemeNameToThemeColorType(*sSchemeName); + mpColorDefinition->setSchemeColor(eType); + } + } + } } break; - case A_TOKEN( prstClr ): - mrColor.setPrstClr( rAttribs.getToken( XML_val, XML_TOKEN_INVALID ) ); + case A_TOKEN(prstClr): + { + sal_Int32 nToken = rAttribs.getToken(XML_val, XML_TOKEN_INVALID); + mrColor.setPrstClr(nToken); + if (mpColorDefinition) + { + ::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; + } + } break; } } @@ -126,9 +230,10 @@ void ColorValueContext::onStartElement( const AttributeList& rAttribs ) return nullptr; } -ColorContext::ColorContext( ContextHandler2Helper const & rParent, Color& rColor ) : - ContextHandler2( rParent ), - mrColor( rColor ) +ColorContext::ColorContext(ContextHandler2Helper const & rParent, Color& rColor, model::ColorDefinition* pColorDefinition) + : ContextHandler2(rParent) + , mrColor(rColor) + , mpColorDefinition(pColorDefinition) { } @@ -143,7 +248,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 ); + return new ColorValueContext(*this, mrColor, mpColorDefinition); } return nullptr; } @@ -167,7 +272,7 @@ ColorsContext::ColorsContext(ContextHandler2Helper const& rParent, std::vectorgetBackgroundShapeFillProperties() ); + return FillPropertiesContext::createFillContext(*this, aElementToken, rAttribs, *mpDataModel->getBackgroundShapeFillProperties(), nullptr); case A_TOKEN( effectDag ): case A_TOKEN( effectLst ): // TODO diff --git a/oox/source/drawingml/linepropertiescontext.cxx b/oox/source/drawingml/linepropertiescontext.cxx index 0ee0e8727bcb..0a95883ccbf8 100644 --- a/oox/source/drawingml/linepropertiescontext.cxx +++ b/oox/source/drawingml/linepropertiescontext.cxx @@ -55,7 +55,7 @@ ContextHandlerRef LinePropertiesContext::onCreateContext( sal_Int32 nElement, co case A_TOKEN( solidFill ): case A_TOKEN( gradFill ): case A_TOKEN( pattFill ): - return FillPropertiesContext::createFillContext( *this, nElement, rAttribs, mrLineProperties.maLineFill ); + return FillPropertiesContext::createFillContext(*this, nElement, rAttribs, mrLineProperties.maLineFill, nullptr); break; // LineDashPropertiesGroup diff --git a/oox/source/drawingml/misccontexts.cxx b/oox/source/drawingml/misccontexts.cxx index e7ec679ad318..9a5ff0e75572 100644 --- a/oox/source/drawingml/misccontexts.cxx +++ b/oox/source/drawingml/misccontexts.cxx @@ -36,12 +36,14 @@ using ::oox::core::ContextHandlerRef; namespace oox::drawingml { -SolidFillContext::SolidFillContext( ContextHandler2Helper const & rParent, - FillProperties& rFillProps ) : - ColorContext( rParent, rFillProps.maFillColor ) +SolidFillContext::SolidFillContext(ContextHandler2Helper const & rParent, FillProperties& rFillProps, model::SolidFill* pSolidFill) + : ColorContext(rParent, rFillProps.maFillColor, pSolidFill ? &pSolidFill->maColorDefinition : nullptr) { } +SolidFillContext::~SolidFillContext() +{} + GradientFillContext::GradientFillContext( ContextHandler2Helper const & rParent, const AttributeList& rAttribs, GradientFillProperties& rGradientProps ) : ContextHandler2( rParent ), @@ -272,21 +274,57 @@ FillPropertiesContext::FillPropertiesContext( ContextHandler2Helper const & rPar ContextHandlerRef FillPropertiesContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) { - return createFillContext( *this, nElement, rAttribs, mrFillProps ); + return createFillContext(*this, nElement, rAttribs, mrFillProps, &maFillStyle); } ContextHandlerRef FillPropertiesContext::createFillContext( ContextHandler2Helper const & rParent, sal_Int32 nElement, - const AttributeList& rAttribs, FillProperties& rFillProps ) + const AttributeList& rAttribs, FillProperties& rFillProps, + model::FillStyle* pFillStyle) { switch( nElement ) { - case A_TOKEN( noFill ): { rFillProps.moFillType = getBaseToken( nElement ); return nullptr; }; - case A_TOKEN( solidFill ): { rFillProps.moFillType = getBaseToken( nElement ); return new SolidFillContext( rParent, rFillProps ); }; - case A_TOKEN( gradFill ): { rFillProps.moFillType = getBaseToken( nElement ); return new GradientFillContext( rParent, rAttribs, rFillProps.maGradientProps ); }; - case A_TOKEN( pattFill ): { rFillProps.moFillType = getBaseToken( nElement ); return new PatternFillContext( rParent, rAttribs, rFillProps.maPatternProps ); }; - case A_TOKEN( blipFill ): { rFillProps.moFillType = getBaseToken( nElement ); return new BlipFillContext( rParent, rAttribs, rFillProps.maBlipProps ); }; - case A_TOKEN( grpFill ): { rFillProps.moFillType = getBaseToken( nElement ); return nullptr; }; // TODO + case A_TOKEN( noFill ): + { + rFillProps.moFillType = getBaseToken(nElement); + if (pFillStyle) + { + pFillStyle->mpFill = std::make_shared(); + } + return nullptr; + } + case A_TOKEN( solidFill ): + { + rFillProps.moFillType = getBaseToken(nElement); + model::SolidFill* pSolidFill = nullptr; + if (pFillStyle) + { + pFillStyle->mpFill = std::make_shared(); + pSolidFill = static_cast(pFillStyle->mpFill.get()); + } + return new SolidFillContext(rParent, rFillProps, pSolidFill); + } + case A_TOKEN( gradFill ): + { + rFillProps.moFillType = getBaseToken(nElement); + return new GradientFillContext(rParent, rAttribs, rFillProps.maGradientProps); + } + case A_TOKEN( pattFill ): + { + rFillProps.moFillType = getBaseToken( nElement ); + return new PatternFillContext( rParent, rAttribs, rFillProps.maPatternProps ); + } + case A_TOKEN( blipFill ): + { + rFillProps.moFillType = getBaseToken( nElement ); + return new BlipFillContext( rParent, rAttribs, rFillProps.maBlipProps ); + } + case A_TOKEN( grpFill ): + { + // TODO + rFillProps.moFillType = getBaseToken( nElement ); + return nullptr; + }; } return nullptr; } diff --git a/oox/source/drawingml/shapepropertiescontext.cxx b/oox/source/drawingml/shapepropertiescontext.cxx index 935cc4970c7c..a637f011d501 100644 --- a/oox/source/drawingml/shapepropertiescontext.cxx +++ b/oox/source/drawingml/shapepropertiescontext.cxx @@ -95,7 +95,7 @@ ContextHandlerRef ShapePropertiesContext::onCreateContext( sal_Int32 aElementTok return new Shape3DPropertiesContext( *this, rAttribs, mrShape.get3DProperties() ); } - return FillPropertiesContext::createFillContext( *this, aElementToken, rAttribs, mrShape.getFillProperties() ); + return FillPropertiesContext::createFillContext(*this, aElementToken, rAttribs, mrShape.getFillProperties(), nullptr); } } diff --git a/oox/source/drawingml/table/tablecellcontext.cxx b/oox/source/drawingml/table/tablecellcontext.cxx index 8f256b725528..3c4780f34e3c 100644 --- a/oox/source/drawingml/table/tablecellcontext.cxx +++ b/oox/source/drawingml/table/tablecellcontext.cxx @@ -91,8 +91,7 @@ TableCellContext::onCreateContext( ::sal_Int32 aElementToken, const AttributeLis break; default: - return FillPropertiesContext::createFillContext( *this, aElementToken, rAttribs, mrTableCell.maFillProperties ); - + return FillPropertiesContext::createFillContext(*this, aElementToken, rAttribs, mrTableCell.maFillProperties, nullptr); } return this; diff --git a/oox/source/drawingml/textcharacterpropertiescontext.cxx b/oox/source/drawingml/textcharacterpropertiescontext.cxx index 2b87aa7f1cd0..fb4390e4c7a7 100644 --- a/oox/source/drawingml/textcharacterpropertiescontext.cxx +++ b/oox/source/drawingml/textcharacterpropertiescontext.cxx @@ -124,7 +124,7 @@ ContextHandlerRef TextCharacterPropertiesContext::onCreateContext( sal_Int32 aEl case A_TOKEN( gradFill ): case A_TOKEN( pattFill ): case A_TOKEN( blipFill ): // Fontwork uses blibFill. - return FillPropertiesContext::createFillContext( *this, aElementToken, rAttribs, mrTextCharacterProperties.maFillProperties ); + return FillPropertiesContext::createFillContext(*this, aElementToken, rAttribs, mrTextCharacterProperties.maFillProperties, nullptr); // EG_EffectProperties case A_TOKEN( effectDag ): // CT_EffectContainer 5.1.10.25 case A_TOKEN( effectLst ): // CT_EffectList 5.1.10.26 diff --git a/oox/source/drawingml/themeelementscontext.cxx b/oox/source/drawingml/themeelementscontext.cxx index d0f8d577678a..7d37145661cf 100644 --- a/oox/source/drawingml/themeelementscontext.cxx +++ b/oox/source/drawingml/themeelementscontext.cxx @@ -42,24 +42,26 @@ namespace { class FillStyleListContext : public ContextHandler2 { public: - FillStyleListContext( ContextHandler2Helper const & rParent, FillStyleList& rFillStyleList ); + FillStyleListContext(ContextHandler2Helper const & rParent, FillStyleList& rFillStyleList, model::FormatScheme& rFormatScheme); virtual ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override; private: FillStyleList& mrFillStyleList; + //model::FormatScheme& mrFormatScheme; }; } -FillStyleListContext::FillStyleListContext( ContextHandler2Helper const & rParent, FillStyleList& rFillStyleList ) : - ContextHandler2( rParent ), - mrFillStyleList( rFillStyleList ) +FillStyleListContext::FillStyleListContext(ContextHandler2Helper const & rParent, FillStyleList& rFillStyleList, model::FormatScheme& /*rFormatScheme*/) + : ContextHandler2(rParent) + , mrFillStyleList(rFillStyleList) + //, mrFormatScheme(rFormatScheme) { } ContextHandlerRef FillStyleListContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) { - switch( nElement ) + switch (nElement) { case A_TOKEN( noFill ): case A_TOKEN( solidFill ): @@ -67,12 +69,27 @@ ContextHandlerRef FillStyleListContext::onCreateContext( sal_Int32 nElement, con case A_TOKEN( blipFill ): case A_TOKEN( pattFill ): case A_TOKEN( grpFill ): - mrFillStyleList.push_back( std::make_shared( ) ); - return FillPropertiesContext::createFillContext( *this, nElement, rAttribs, *mrFillStyleList.back() ); + { + mrFillStyleList.push_back(std::make_shared()); + return FillPropertiesContext::createFillContext(*this, nElement, rAttribs, *mrFillStyleList.back(), nullptr); + } } return nullptr; } +namespace +{ + +class BackgroundFillStyleListContext : public FillStyleListContext +{ +public: + BackgroundFillStyleListContext(ContextHandler2Helper const & rParent, FillStyleList& rFillStyleList, model::FormatScheme& rFormatScheme) + : FillStyleListContext(rParent, rFillStyleList, rFormatScheme) + {} +}; + +} // end anonymous ns + namespace { class LineStyleListContext : public ContextHandler2 @@ -307,13 +324,13 @@ ContextHandlerRef ThemeElementsContext::onCreateContext(sal_Int32 nElement, cons } case A_TOKEN( fillStyleLst ): // CT_FillStyleList - return new FillStyleListContext( *this, mrOoxTheme.getFillStyleList() ); + return new FillStyleListContext( *this, mrOoxTheme.getFillStyleList(), mrTheme.getFormatScheme()); case A_TOKEN( lnStyleLst ): // CT_LineStyleList return new LineStyleListContext( *this, mrOoxTheme.getLineStyleList() ); case A_TOKEN( effectStyleLst ): // CT_EffectStyleList return new EffectStyleListContext( *this, mrOoxTheme.getEffectStyleList() ); case A_TOKEN( bgFillStyleLst ): // CT_BackgroundFillStyleList - return new FillStyleListContext( *this, mrOoxTheme.getBgFillStyleList() ); + return new BackgroundFillStyleListContext( *this, mrOoxTheme.getBgFillStyleList(), mrTheme.getFormatScheme()); } return nullptr; } diff --git a/oox/source/ppt/backgroundproperties.cxx b/oox/source/ppt/backgroundproperties.cxx index 9fe25661205d..b3c71875e6e7 100644 --- a/oox/source/ppt/backgroundproperties.cxx +++ b/oox/source/ppt/backgroundproperties.cxx @@ -42,7 +42,7 @@ BackgroundPropertiesContext::BackgroundPropertiesContext( FragmentHandler2 const return this; } - return ::oox::drawingml::FillPropertiesContext::createFillContext( *this, aElementToken, rAttribs, mrFillProperties ); + return ::oox::drawingml::FillPropertiesContext::createFillContext(*this, aElementToken, rAttribs, mrFillProperties, nullptr); } } -- cgit