1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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>
33
34 using namespace ::oox::core;
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::xml::sax;
37
38 namespace oox {
39 namespace drawingml {
40
41 class FillStyleListContext : public ContextHandler2
42 {
43 public:
44 FillStyleListContext( ContextHandler2Helper const & rParent, FillStyleList& rFillStyleList );
45 virtual ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override;
46
47 private:
48 FillStyleList& mrFillStyleList;
49 };
50
FillStyleListContext(ContextHandler2Helper const & rParent,FillStyleList & rFillStyleList)51 FillStyleListContext::FillStyleListContext( ContextHandler2Helper const & rParent, FillStyleList& rFillStyleList ) :
52 ContextHandler2( rParent ),
53 mrFillStyleList( rFillStyleList )
54 {
55 }
56
onCreateContext(sal_Int32 nElement,const AttributeList & rAttribs)57 ContextHandlerRef FillStyleListContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
58 {
59 switch( nElement )
60 {
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() );
69 }
70 return nullptr;
71 }
72
73 class LineStyleListContext : public ContextHandler2
74 {
75 public:
76 LineStyleListContext( ContextHandler2Helper const & rParent, LineStyleList& rLineStyleList );
77 virtual ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override;
78
79 private:
80 LineStyleList& mrLineStyleList;
81 };
82
LineStyleListContext(ContextHandler2Helper const & rParent,LineStyleList & rLineStyleList)83 LineStyleListContext::LineStyleListContext( ContextHandler2Helper const & rParent, LineStyleList& rLineStyleList ) :
84 ContextHandler2( rParent ),
85 mrLineStyleList( rLineStyleList )
86 {
87 }
88
onCreateContext(sal_Int32 nElement,const AttributeList & rAttribs)89 ContextHandlerRef LineStyleListContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
90 {
91 switch( nElement )
92 {
93 case A_TOKEN( ln ):
94 mrLineStyleList.push_back( std::make_shared<LineProperties>( ) );
95 return new LinePropertiesContext( *this, rAttribs, *mrLineStyleList.back() );
96 }
97 return nullptr;
98 }
99
100 class EffectStyleListContext : public ContextHandler2
101 {
102 public:
103 EffectStyleListContext( ContextHandler2Helper const & rParent, EffectStyleList& rEffectStyleList );
104 virtual ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override;
105
106 private:
107 EffectStyleList& mrEffectStyleList;
108 };
109
EffectStyleListContext(ContextHandler2Helper const & rParent,EffectStyleList & rEffectStyleList)110 EffectStyleListContext::EffectStyleListContext( ContextHandler2Helper const & rParent, EffectStyleList& rEffectStyleList ) :
111 ContextHandler2( rParent ),
112 mrEffectStyleList( rEffectStyleList )
113 {
114 }
115
onCreateContext(sal_Int32 nElement,const AttributeList &)116 ContextHandlerRef EffectStyleListContext::onCreateContext( sal_Int32 nElement, const AttributeList& /*rAttribs*/ )
117 {
118 switch( nElement )
119 {
120 case A_TOKEN( effectStyle ):
121 mrEffectStyleList.push_back( std::make_shared<EffectProperties>( ) );
122 return this;
123
124 case A_TOKEN( effectLst ): // CT_EffectList
125 if( mrEffectStyleList.back() )
126 return new EffectPropertiesContext( *this, *mrEffectStyleList.back() );
127 break;
128 }
129 return nullptr;
130 }
131
132 class FontSchemeContext : public ContextHandler2
133 {
134 public:
135 FontSchemeContext( ContextHandler2Helper const & rParent, FontScheme& rFontScheme );
136 virtual ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override;
137 virtual void onEndElement() override;
138
139 private:
140 FontScheme& mrFontScheme;
141 TextCharacterPropertiesPtr mxCharProps;
142 };
143
FontSchemeContext(ContextHandler2Helper const & rParent,FontScheme & rFontScheme)144 FontSchemeContext::FontSchemeContext( ContextHandler2Helper const & rParent, FontScheme& rFontScheme ) :
145 ContextHandler2( rParent ),
146 mrFontScheme( rFontScheme )
147 {
148 }
149
onCreateContext(sal_Int32 nElement,const AttributeList & rAttribs)150 ContextHandlerRef FontSchemeContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
151 {
152 switch( nElement )
153 {
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;
162
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;
175 }
176 return nullptr;
177 }
178
onEndElement()179 void FontSchemeContext::onEndElement()
180 {
181 switch( getCurrentElement() )
182 {
183 case A_TOKEN( majorFont ):
184 case A_TOKEN( minorFont ):
185 mxCharProps.reset();
186 break;
187 }
188 }
189
ThemeElementsContext(ContextHandler2Helper const & rParent,Theme & rTheme)190 ThemeElementsContext::ThemeElementsContext( ContextHandler2Helper const & rParent, Theme& rTheme ) :
191 ContextHandler2( rParent ),
192 mrTheme( rTheme )
193 {
194 }
195
onCreateContext(sal_Int32 nElement,const AttributeList & rAttribs)196 ContextHandlerRef ThemeElementsContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
197 {
198 // CT_BaseStyles
199 switch( nElement )
200 {
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() );
205
206 case A_TOKEN( fmtScheme ): // CT_StyleMatrix
207 mrTheme.setStyleName( rAttribs.getString( XML_name ).get() );
208 return this;
209
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() );
218 }
219 return nullptr;
220 }
221
222 } // namespace drawingml
223 } // namespace oox
224
225 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
226