Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / oox / source / drawingml / themeelementscontext.cxx
bloba936c36678a9b1f8b753045fdd929d06c581c7ee
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "drawingml/themeelementscontext.hxx"
21 #include "drawingml/clrschemecontext.hxx"
22 #include "drawingml/lineproperties.hxx"
23 #include "drawingml/linepropertiescontext.hxx"
24 #include "drawingml/fillproperties.hxx"
25 #include "drawingml/misccontexts.hxx"
26 #include "drawingml/textcharacterproperties.hxx"
27 #include "oox/drawingml/theme.hxx"
28 #include "oox/helper/attributelist.hxx"
29 #include "effectproperties.hxx"
30 #include "effectpropertiescontext.hxx"
31 #include <oox/token/namespaces.hxx>
32 #include <oox/token/tokens.hxx>
34 using namespace ::oox::core;
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::xml::sax;
38 namespace oox {
39 namespace drawingml {
41 class FillStyleListContext : public ContextHandler2
43 public:
44 FillStyleListContext( ContextHandler2Helper& rParent, FillStyleList& rFillStyleList );
45 virtual ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override;
47 private:
48 FillStyleList& mrFillStyleList;
51 FillStyleListContext::FillStyleListContext( ContextHandler2Helper& rParent, FillStyleList& rFillStyleList ) :
52 ContextHandler2( rParent ),
53 mrFillStyleList( rFillStyleList )
57 ContextHandlerRef FillStyleListContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
59 switch( nElement )
61 case A_TOKEN( noFill ):
62 case A_TOKEN( solidFill ):
63 case A_TOKEN( gradFill ):
64 case A_TOKEN( blipFill ):
65 case A_TOKEN( pattFill ):
66 case A_TOKEN( grpFill ):
67 mrFillStyleList.push_back( std::make_shared<FillProperties>( ) );
68 return FillPropertiesContext::createFillContext( *this, nElement, rAttribs, *mrFillStyleList.back() );
70 return nullptr;
73 class LineStyleListContext : public ContextHandler2
75 public:
76 LineStyleListContext( ContextHandler2Helper& rParent, LineStyleList& rLineStyleList );
77 virtual ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override;
79 private:
80 LineStyleList& mrLineStyleList;
83 LineStyleListContext::LineStyleListContext( ContextHandler2Helper& rParent, LineStyleList& rLineStyleList ) :
84 ContextHandler2( rParent ),
85 mrLineStyleList( rLineStyleList )
89 ContextHandlerRef LineStyleListContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
91 switch( nElement )
93 case A_TOKEN( ln ):
94 mrLineStyleList.push_back( std::make_shared<LineProperties>( ) );
95 return new LinePropertiesContext( *this, rAttribs, *mrLineStyleList.back() );
97 return nullptr;
100 class EffectStyleListContext : public ContextHandler2
102 public:
103 EffectStyleListContext( ContextHandler2Helper& rParent, EffectStyleList& rEffectStyleList );
104 virtual ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override;
106 private:
107 EffectStyleList& mrEffectStyleList;
110 EffectStyleListContext::EffectStyleListContext( ContextHandler2Helper& rParent, EffectStyleList& rEffectStyleList ) :
111 ContextHandler2( rParent ),
112 mrEffectStyleList( rEffectStyleList )
116 ContextHandlerRef EffectStyleListContext::onCreateContext( sal_Int32 nElement, const AttributeList& /*rAttribs*/ )
118 switch( nElement )
120 case A_TOKEN( effectStyle ):
121 mrEffectStyleList.push_back( std::make_shared<EffectProperties>( ) );
122 return this;
124 case A_TOKEN( effectLst ): // CT_EffectList
125 if( mrEffectStyleList.back() )
126 return new EffectPropertiesContext( *this, *mrEffectStyleList.back() );
127 break;
129 return nullptr;
132 class FontSchemeContext : public ContextHandler2
134 public:
135 FontSchemeContext( ContextHandler2Helper& rParent, FontScheme& rFontScheme );
136 virtual ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override;
137 virtual void onEndElement() override;
139 private:
140 FontScheme& mrFontScheme;
141 TextCharacterPropertiesPtr mxCharProps;
144 FontSchemeContext::FontSchemeContext( ContextHandler2Helper& rParent, FontScheme& rFontScheme ) :
145 ContextHandler2( rParent ),
146 mrFontScheme( rFontScheme )
150 ContextHandlerRef FontSchemeContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
152 switch( nElement )
154 case A_TOKEN( majorFont ):
155 mxCharProps.reset( new TextCharacterProperties );
156 mrFontScheme[ XML_major ] = mxCharProps;
157 return this;
158 case A_TOKEN( minorFont ):
159 mxCharProps.reset( new TextCharacterProperties );
160 mrFontScheme[ XML_minor ] = mxCharProps;
161 return this;
163 case A_TOKEN( latin ):
164 if( mxCharProps.get() )
165 mxCharProps->maLatinFont.setAttributes( rAttribs );
166 break;
167 case A_TOKEN( ea ):
168 if( mxCharProps.get() )
169 mxCharProps->maAsianFont.setAttributes( rAttribs );
170 break;
171 case A_TOKEN( cs ):
172 if( mxCharProps.get() )
173 mxCharProps->maComplexFont.setAttributes( rAttribs );
174 break;
176 return nullptr;
179 void FontSchemeContext::onEndElement()
181 switch( getCurrentElement() )
183 case A_TOKEN( majorFont ):
184 case A_TOKEN( minorFont ):
185 mxCharProps.reset();
186 break;
190 ThemeElementsContext::ThemeElementsContext( ContextHandler2Helper& rParent, Theme& rTheme ) :
191 ContextHandler2( rParent ),
192 mrTheme( rTheme )
196 ContextHandlerRef ThemeElementsContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
198 // CT_BaseStyles
199 switch( nElement )
201 case A_TOKEN( clrScheme ): // CT_ColorScheme
202 return new clrSchemeContext( *this, mrTheme.getClrScheme() );
203 case A_TOKEN( fontScheme ): // CT_FontScheme
204 return new FontSchemeContext( *this, mrTheme.getFontScheme() );
206 case A_TOKEN( fmtScheme ): // CT_StyleMatrix
207 mrTheme.setStyleName( rAttribs.getString( XML_name ).get() );
208 return this;
210 case A_TOKEN( fillStyleLst ): // CT_FillStyleList
211 return new FillStyleListContext( *this, mrTheme.getFillStyleList() );
212 case A_TOKEN( lnStyleLst ): // CT_LineStyleList
213 return new LineStyleListContext( *this, mrTheme.getLineStyleList() );
214 case A_TOKEN( effectStyleLst ): // CT_EffectStyleList
215 return new EffectStyleListContext( *this, mrTheme.getEffectStyleList() );
216 case A_TOKEN( bgFillStyleLst ): // CT_BackgroundFillStyleList
217 return new FillStyleListContext( *this, mrTheme.getBgFillStyleList() );
219 return nullptr;
222 } // namespace drawingml
223 } // namespace oox
225 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */