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
29#include "effectproperties.hxx"
31#include <oox/token/namespaces.hxx>
32#include <oox/token/tokens.hxx>
33
34using namespace ::oox::core;
35using namespace ::com::sun::star::uno;
36using namespace ::com::sun::star::xml::sax;
37
38namespace oox::drawingml {
39
40namespace {
41
42class FillStyleListContext : public ContextHandler2
43{
44public:
45 FillStyleListContext( ContextHandler2Helper const & rParent, FillStyleList& rFillStyleList );
46 virtual ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override;
47
48private:
50};
51
52}
53
54FillStyleListContext::FillStyleListContext( ContextHandler2Helper const & rParent, FillStyleList& rFillStyleList ) :
55 ContextHandler2( rParent ),
56 mrFillStyleList( rFillStyleList )
57{
58}
59
60ContextHandlerRef 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
76namespace {
77
78class LineStyleListContext : public ContextHandler2
79{
80public:
81 LineStyleListContext( ContextHandler2Helper const & rParent, LineStyleList& rLineStyleList );
82 virtual ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override;
83
84private:
86};
87
88}
89
90LineStyleListContext::LineStyleListContext( ContextHandler2Helper const & rParent, LineStyleList& rLineStyleList ) :
91 ContextHandler2( rParent ),
92 mrLineStyleList( rLineStyleList )
93{
94}
95
96ContextHandlerRef LineStyleListContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
97{
98 switch( nElement )
99 {
100 case A_TOKEN( ln ):
102 return new LinePropertiesContext( *this, rAttribs, *mrLineStyleList.back() );
103 }
104 return nullptr;
105}
106
107namespace {
108
109class EffectStyleListContext : public ContextHandler2
110{
111public:
112 EffectStyleListContext( ContextHandler2Helper const & rParent, EffectStyleList& rEffectStyleList );
113 virtual ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override;
114
115private:
117};
118
119}
120
121EffectStyleListContext::EffectStyleListContext( ContextHandler2Helper const & rParent, EffectStyleList& rEffectStyleList ) :
122 ContextHandler2( rParent ),
123 mrEffectStyleList( rEffectStyleList )
124{
125}
126
127ContextHandlerRef 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
143namespace {
144
145class FontSchemeContext : public ContextHandler2
146{
147public:
148 FontSchemeContext(ContextHandler2Helper const & rParent, FontScheme& rFontScheme,
149 std::map<sal_Int32, std::vector<std::pair<OUString, OUString>>>& rSupplementalFontMap);
150 virtual ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override;
151 virtual void onEndElement() override;
152
153private:
156 std::map<sal_Int32, std::vector<std::pair<OUString, OUString>>>& mrSupplementalFontMap;
157 sal_Int32 maCurrentFont = 0;
158};
159
160}
161
162FontSchemeContext::FontSchemeContext(ContextHandler2Helper const & rParent, FontScheme& rFontScheme,
163 std::map<sal_Int32, std::vector<std::pair<OUString, OUString>>>& rSupplementalFontMap)
164 : ContextHandler2(rParent)
165 , mrFontScheme(rFontScheme)
166 , mrSupplementalFontMap(rSupplementalFontMap)
167{
168}
169
170ContextHandlerRef FontSchemeContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
171{
172 switch( nElement )
173 {
174 case A_TOKEN( majorFont ):
175 mxCharProps = std::make_shared<TextCharacterProperties>();
176 mrFontScheme[ XML_major ] = mxCharProps;
177 maCurrentFont = XML_major;
178 return this;
179 case A_TOKEN( minorFont ):
180 mxCharProps = std::make_shared<TextCharacterProperties>();
181 mrFontScheme[ XML_minor ] = mxCharProps;
182 maCurrentFont = XML_minor;
183 return this;
184 case A_TOKEN( latin ):
185 if( mxCharProps )
186 mxCharProps->maLatinFont.setAttributes( rAttribs );
187 break;
188 case A_TOKEN( ea ):
189 if( mxCharProps )
190 mxCharProps->maAsianFont.setAttributes( rAttribs );
191 break;
192 case A_TOKEN( cs ):
193 if( mxCharProps )
194 mxCharProps->maComplexFont.setAttributes( rAttribs );
195 break;
196 case A_TOKEN(font):
197 OUString aScript = rAttribs.getStringDefaulted(XML_script);
198 OUString aTypeface = rAttribs.getStringDefaulted(XML_typeface);
199 mrSupplementalFontMap[maCurrentFont].emplace_back(std::pair<OUString, OUString>{aScript, aTypeface});
200 break;
201 }
202 return nullptr;
203}
204
205void FontSchemeContext::onEndElement()
206{
207 switch( getCurrentElement() )
208 {
209 case A_TOKEN( majorFont ):
210 case A_TOKEN( minorFont ):
211 mxCharProps.reset();
212 break;
213 }
214}
215
216ThemeElementsContext::ThemeElementsContext( ContextHandler2Helper const & rParent, Theme& rTheme ) :
217 ContextHandler2( rParent ),
218 mrTheme( rTheme )
219{
220}
221
223{
224 // CT_BaseStyles
225 switch( nElement )
226 {
227 case A_TOKEN( clrScheme ): // CT_ColorScheme
228 {
229 if (rAttribs.hasAttribute(XML_name))
230 mrTheme.getClrScheme().SetName(rAttribs.getStringDefaulted(XML_name));
231 return new clrSchemeContext(*this, mrTheme.getClrScheme());
232 }
233 case A_TOKEN( fontScheme ): // CT_FontScheme
234 {
235 if (rAttribs.hasAttribute(XML_name))
236 mrTheme.setFontSchemeName(rAttribs.getStringDefaulted(XML_name));
237 return new FontSchemeContext(*this, mrTheme.getFontScheme(), mrTheme.getSupplementalFontMap());
238 }
239
240 case A_TOKEN( fmtScheme ): // CT_StyleMatrix
241 {
242 if (rAttribs.hasAttribute(XML_name))
244 return this;
245 }
246
247 case A_TOKEN( fillStyleLst ): // CT_FillStyleList
248 return new FillStyleListContext( *this, mrTheme.getFillStyleList() );
249 case A_TOKEN( lnStyleLst ): // CT_LineStyleList
250 return new LineStyleListContext( *this, mrTheme.getLineStyleList() );
251 case A_TOKEN( effectStyleLst ): // CT_EffectStyleList
252 return new EffectStyleListContext( *this, mrTheme.getEffectStyleList() );
253 case A_TOKEN( bgFillStyleLst ): // CT_BackgroundFillStyleList
254 return new FillStyleListContext( *this, mrTheme.getBgFillStyleList() );
255 }
256 return nullptr;
257}
258
259} // namespace oox::drawingml
260
261/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Provides access to attribute values of an element.
OUString getStringDefaulted(sal_Int32 nAttrToken) const
Returns the string value of the specified attribute, returns an empty string if attribute not present...
bool hasAttribute(sal_Int32 nAttrToken) const
Returns true, if the specified attribute is present.
void SetName(const OUString &rName)
Definition: clrscheme.hxx:94
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const ::oox::AttributeList &rAttribs) override
void setFormatSchemeName(OUString const &rName)
Definition: theme.hxx:65
std::map< sal_Int32, std::vector< std::pair< OUString, OUString > > > & getSupplementalFontMap()
Definition: theme.hxx:90
FillStyleList & getFillStyleList()
Definition: theme.hxx:71
LineStyleList & getLineStyleList()
Definition: theme.hxx:78
EffectStyleList & getEffectStyleList()
Definition: theme.hxx:83
ClrScheme & getClrScheme()
Definition: theme.hxx:68
FillStyleList & getBgFillStyleList()
Definition: theme.hxx:73
FontScheme & getFontScheme()
Definition: theme.hxx:87
void setFontSchemeName(OUString const &rName)
Definition: theme.hxx:66
if(aStr !=aBuf) UpdateName_Impl(m_xFollowLb.get()
std::shared_ptr< T > make_shared(Args &&... args)
::rtl::Reference< ContextHandler > ContextHandlerRef
RefVector< LineProperties > LineStyleList
Definition: theme.hxx:55
RefVector< FillProperties > FillStyleList
Definition: theme.hxx:54
std::shared_ptr< TextCharacterProperties > TextCharacterPropertiesPtr
RefMap< sal_Int32, TextCharacterProperties > FontScheme
Definition: theme.hxx:57
RefVector< EffectProperties > EffectStyleList
Definition: theme.hxx:56
std::map< sal_Int32, std::vector< std::pair< OUString, OUString > > > & mrSupplementalFontMap
sal_Int32 maCurrentFont
FillStyleList & mrFillStyleList
EffectStyleList & mrEffectStyleList
LineStyleList & mrLineStyleList
FontScheme & mrFontScheme
TextCharacterPropertiesPtr mxCharProps