LibreOffice Module oox (master)  1
themeelementscontext.cxx
Go to the documentation of this file.
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 
27 #include <oox/drawingml/theme.hxx>
29 #include "effectproperties.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::drawingml {
39 
40 namespace {
41 
42 class FillStyleListContext : public ContextHandler2
43 {
44 public:
45  FillStyleListContext( ContextHandler2Helper const & rParent, FillStyleList& rFillStyleList );
46  virtual ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override;
47 
48 private:
50 };
51 
52 }
53 
54 FillStyleListContext::FillStyleListContext( ContextHandler2Helper const & rParent, FillStyleList& rFillStyleList ) :
55  ContextHandler2( rParent ),
56  mrFillStyleList( rFillStyleList )
57 {
58 }
59 
60 ContextHandlerRef FillStyleListContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
61 {
62  switch( nElement )
63  {
64  case A_TOKEN( noFill ):
65  case A_TOKEN( solidFill ):
66  case A_TOKEN( gradFill ):
67  case A_TOKEN( blipFill ):
68  case A_TOKEN( pattFill ):
69  case A_TOKEN( grpFill ):
70  mrFillStyleList.push_back( std::make_shared<FillProperties>( ) );
71  return FillPropertiesContext::createFillContext( *this, nElement, rAttribs, *mrFillStyleList.back() );
72  }
73  return nullptr;
74 }
75 
76 namespace {
77 
78 class LineStyleListContext : public ContextHandler2
79 {
80 public:
81  LineStyleListContext( ContextHandler2Helper const & rParent, LineStyleList& rLineStyleList );
82  virtual ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override;
83 
84 private:
86 };
87 
88 }
89 
90 LineStyleListContext::LineStyleListContext( ContextHandler2Helper const & rParent, LineStyleList& rLineStyleList ) :
91  ContextHandler2( rParent ),
92  mrLineStyleList( rLineStyleList )
93 {
94 }
95 
96 ContextHandlerRef LineStyleListContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
97 {
98  switch( nElement )
99  {
100  case A_TOKEN( ln ):
101  mrLineStyleList.push_back( std::make_shared<LineProperties>( ) );
102  return new LinePropertiesContext( *this, rAttribs, *mrLineStyleList.back() );
103  }
104  return nullptr;
105 }
106 
107 namespace {
108 
109 class EffectStyleListContext : public ContextHandler2
110 {
111 public:
112  EffectStyleListContext( ContextHandler2Helper const & rParent, EffectStyleList& rEffectStyleList );
113  virtual ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override;
114 
115 private:
117 };
118 
119 }
120 
121 EffectStyleListContext::EffectStyleListContext( ContextHandler2Helper const & rParent, EffectStyleList& rEffectStyleList ) :
122  ContextHandler2( rParent ),
123  mrEffectStyleList( rEffectStyleList )
124 {
125 }
126 
127 ContextHandlerRef EffectStyleListContext::onCreateContext( sal_Int32 nElement, const AttributeList& /*rAttribs*/ )
128 {
129  switch( nElement )
130  {
131  case A_TOKEN( effectStyle ):
132  mrEffectStyleList.push_back( std::make_shared<EffectProperties>( ) );
133  return this;
134 
135  case A_TOKEN( effectLst ): // CT_EffectList
136  if( mrEffectStyleList.back() )
137  return new EffectPropertiesContext( *this, *mrEffectStyleList.back() );
138  break;
139  }
140  return nullptr;
141 }
142 
143 namespace {
144 
145 class FontSchemeContext : public ContextHandler2
146 {
147 public:
148  FontSchemeContext( ContextHandler2Helper const & rParent, FontScheme& rFontScheme );
149  virtual ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override;
150  virtual void onEndElement() override;
151 
152 private:
155 };
156 
157 }
158 
159 FontSchemeContext::FontSchemeContext( ContextHandler2Helper const & rParent, FontScheme& rFontScheme ) :
160  ContextHandler2( rParent ),
161  mrFontScheme( rFontScheme )
162 {
163 }
164 
165 ContextHandlerRef FontSchemeContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
166 {
167  switch( nElement )
168  {
169  case A_TOKEN( majorFont ):
170  mxCharProps = std::make_shared<TextCharacterProperties>();
171  mrFontScheme[ XML_major ] = mxCharProps;
172  return this;
173  case A_TOKEN( minorFont ):
174  mxCharProps = std::make_shared<TextCharacterProperties>();
175  mrFontScheme[ XML_minor ] = mxCharProps;
176  return this;
177 
178  case A_TOKEN( latin ):
179  if( mxCharProps )
180  mxCharProps->maLatinFont.setAttributes( rAttribs );
181  break;
182  case A_TOKEN( ea ):
183  if( mxCharProps )
184  mxCharProps->maAsianFont.setAttributes( rAttribs );
185  break;
186  case A_TOKEN( cs ):
187  if( mxCharProps )
188  mxCharProps->maComplexFont.setAttributes( rAttribs );
189  break;
190  }
191  return nullptr;
192 }
193 
194 void FontSchemeContext::onEndElement()
195 {
196  switch( getCurrentElement() )
197  {
198  case A_TOKEN( majorFont ):
199  case A_TOKEN( minorFont ):
200  mxCharProps.reset();
201  break;
202  }
203 }
204 
205 ThemeElementsContext::ThemeElementsContext( ContextHandler2Helper const & rParent, Theme& rTheme ) :
206  ContextHandler2( rParent ),
207  mrTheme( rTheme )
208 {
209 }
210 
212 {
213  // CT_BaseStyles
214  switch( nElement )
215  {
216  case A_TOKEN( clrScheme ): // CT_ColorScheme
217  return new clrSchemeContext( *this, mrTheme.getClrScheme() );
218  case A_TOKEN( fontScheme ): // CT_FontScheme
219  return new FontSchemeContext( *this, mrTheme.getFontScheme() );
220 
221  case A_TOKEN( fmtScheme ): // CT_StyleMatrix
222  mrTheme.setStyleName( rAttribs.getString( XML_name ).get() );
223  return this;
224 
225  case A_TOKEN( fillStyleLst ): // CT_FillStyleList
226  return new FillStyleListContext( *this, mrTheme.getFillStyleList() );
227  case A_TOKEN( lnStyleLst ): // CT_LineStyleList
228  return new LineStyleListContext( *this, mrTheme.getLineStyleList() );
229  case A_TOKEN( effectStyleLst ): // CT_EffectStyleList
230  return new EffectStyleListContext( *this, mrTheme.getEffectStyleList() );
231  case A_TOKEN( bgFillStyleLst ): // CT_BackgroundFillStyleList
232  return new FillStyleListContext( *this, mrTheme.getBgFillStyleList() );
233  }
234  return nullptr;
235 }
236 
237 } // namespace oox::drawingml
238 
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
RefMap< sal_Int32, TextCharacterProperties > FontScheme
Definition: theme.hxx:52
FillStyleList & getBgFillStyleList()
Definition: theme.hxx:69
FillStyleList & mrFillStyleList
LineStyleList & mrLineStyleList
OptValue< OUString > getString(sal_Int32 nAttrToken) const
Returns the string value of the specified attribute.
std::shared_ptr< T > make_shared(Args &&...args)
std::shared_ptr< TextCharacterProperties > TextCharacterPropertiesPtr
ClrScheme & getClrScheme()
Definition: theme.hxx:64
const Type & get() const
Definition: helper.hxx:185
TextCharacterPropertiesPtr mxCharProps
RefVector< EffectProperties > EffectStyleList
Definition: theme.hxx:51
LineStyleList & getLineStyleList()
Definition: theme.hxx:74
FontScheme & getFontScheme()
Definition: theme.hxx:83
EffectStyleList & getEffectStyleList()
Definition: theme.hxx:79
RefVector< LineProperties > LineStyleList
Definition: theme.hxx:50
FontScheme & mrFontScheme
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const ::oox::AttributeList &rAttribs) override
Provides access to attribute values of an element.
RefVector< FillProperties > FillStyleList
Definition: theme.hxx:49
if(aStr!=aBuf) UpdateName_Impl(m_xFollowLb.get()
::rtl::Reference< ContextHandler > ContextHandlerRef
FillStyleList & getFillStyleList()
Definition: theme.hxx:67
Helper class that provides a context stack.
EffectStyleList & mrEffectStyleList
void setStyleName(const OUString &rStyleName)
Definition: theme.hxx:62