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, model::FormatScheme& rFormatScheme);
46 virtual ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override;
47
48protected:
51 virtual model::FillStyle* createAndAddFillStyle()
52 {
54 }
55};
56
57}
58
59FillStyleListContext::FillStyleListContext(ContextHandler2Helper const & rParent, FillStyleList& rFillStyleList, model::FormatScheme& rFormatScheme)
60 : ContextHandler2(rParent)
61 , mrFillStyleList(rFillStyleList)
62 , mrFormatScheme(rFormatScheme)
63{
64}
65
66ContextHandlerRef FillStyleListContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
67{
68 switch (nElement)
69 {
70 case A_TOKEN( noFill ):
71 case A_TOKEN( solidFill ):
72 case A_TOKEN( gradFill ):
73 case A_TOKEN( blipFill ):
74 case A_TOKEN( pattFill ):
75 case A_TOKEN( grpFill ):
76 {
77 mrFillStyleList.push_back(std::make_shared<FillProperties>());
78 model::FillStyle* pFillStyle = createAndAddFillStyle();
79 return FillPropertiesContext::createFillContext(*this, nElement, rAttribs, *mrFillStyleList.back(), pFillStyle);
80 }
81 }
82 return nullptr;
83}
84
85namespace
86{
87
88class BackgroundFillStyleListContext : public FillStyleListContext
89{
90public:
91 BackgroundFillStyleListContext(ContextHandler2Helper const & rParent, FillStyleList& rFillStyleList, model::FormatScheme& rFormatScheme)
92 : FillStyleListContext(rParent, rFillStyleList, rFormatScheme)
93 {}
94
95protected:
96 model::FillStyle* createAndAddFillStyle() override
97 {
99 }
100};
101
102} // end anonymous ns
103
104namespace {
105
106class LineStyleListContext : public ContextHandler2
107{
108public:
109 LineStyleListContext(ContextHandler2Helper const & rParent, LineStyleList& rLineStyleList, model::FormatScheme& rFormatScheme);
110 virtual ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override;
111
112private:
115};
116
117}
118
119LineStyleListContext::LineStyleListContext( ContextHandler2Helper const & rParent, LineStyleList& rLineStyleList, model::FormatScheme& rFormatScheme)
120 : ContextHandler2(rParent)
121 , mrFormatScheme(rFormatScheme)
122 , mrLineStyleList(rLineStyleList)
123{
124}
125
126ContextHandlerRef LineStyleListContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
127{
128 switch (nElement)
129 {
130 case A_TOKEN(ln):
131 {
132 mrLineStyleList.push_back( std::make_shared<LineProperties>( ) );
134 return new LinePropertiesContext(*this, rAttribs, *mrLineStyleList.back(), pLineStyle);
135 }
136 }
137 return nullptr;
138}
139
140namespace {
141
142class EffectStyleListContext : public ContextHandler2
143{
144public:
145 EffectStyleListContext(ContextHandler2Helper const & rParent, EffectStyleList& rEffectStyleList, model::FormatScheme& rFormatScheme);
146 virtual ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override;
147
148private:
152};
153
154}
155
156EffectStyleListContext::EffectStyleListContext( ContextHandler2Helper const & rParent, EffectStyleList& rEffectStyleList, model::FormatScheme& rFormatScheme)
157 : ContextHandler2(rParent)
158 , mrFormatScheme(rFormatScheme)
159 , mpEffectStyle(nullptr)
160 , mrEffectStyleList(rEffectStyleList)
161{
162}
163
164ContextHandlerRef EffectStyleListContext::onCreateContext( sal_Int32 nElement, const AttributeList& /*rAttribs*/ )
165{
166 switch( nElement )
167 {
168 case A_TOKEN( effectStyle ):
169 {
171 mrEffectStyleList.push_back( std::make_shared<EffectProperties>( ) );
172 return this;
173 }
174 case A_TOKEN( effectLst ): // CT_EffectList
175 {
176 if( mrEffectStyleList.back() )
177 return new EffectPropertiesContext(*this, *mrEffectStyleList.back(), mpEffectStyle);
178 }
179 break;
180 }
181 return nullptr;
182}
183
184namespace
185{
186
187class FontSchemeContext : public ContextHandler2
188{
189public:
190 FontSchemeContext(ContextHandler2Helper const & rParent, const AttributeList& rAttribs, FontScheme& rFontScheme,
191 std::map<sal_Int32, std::vector<std::pair<OUString, OUString>>>& rSupplementalFontMap,
192 model::Theme& rTheme);
193 ~FontSchemeContext();
194 virtual ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override;
195 virtual void onEndElement() override;
196
197private:
200 std::map<sal_Int32, std::vector<std::pair<OUString, OUString>>>& mrSupplementalFontMap;
201 sal_Int32 maCurrentFont = 0;
204};
205
206} // end anonymous ns
207
208FontSchemeContext::FontSchemeContext(ContextHandler2Helper const & rParent, const AttributeList& rAttribs, FontScheme& rFontScheme,
209 std::map<sal_Int32, std::vector<std::pair<OUString, OUString>>>& rSupplementalFontMap,
210 model::Theme& rTheme)
211 : ContextHandler2(rParent)
212 , mrFontScheme(rFontScheme)
213 , mrSupplementalFontMap(rSupplementalFontMap)
214 , mrTheme(rTheme)
215 , maFontScheme(rAttribs.getStringDefaulted(XML_name))
216{
217}
218
219FontSchemeContext::~FontSchemeContext()
220{
222}
223
224namespace
225{
226
227void fillThemeFont(model::ThemeFont& rThemeFont, const AttributeList& rAttribs)
228{
229 rThemeFont.maTypeface = rAttribs.getStringDefaulted(XML_typeface);
230 rThemeFont.maPanose = rAttribs.getStringDefaulted(XML_panose);
231 rThemeFont.maCharset = rAttribs.getInteger(XML_charset, WINDOWS_CHARSET_DEFAULT);
232 sal_Int32 nPitchFamily = rAttribs.getInteger(XML_pitchFamily, 0);
233 TextFont::resolvePitch(nPitchFamily, rThemeFont.maPitch, rThemeFont.maFamily);
234}
235
236} // end anonymous ns
237
238ContextHandlerRef FontSchemeContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
239{
240 switch( nElement )
241 {
242 case A_TOKEN( majorFont ):
243 mxCharProps = std::make_shared<TextCharacterProperties>();
244 mrFontScheme[ XML_major ] = mxCharProps;
245 maCurrentFont = XML_major;
246 return this;
247 case A_TOKEN( minorFont ):
248 mxCharProps = std::make_shared<TextCharacterProperties>();
249 mrFontScheme[ XML_minor ] = mxCharProps;
250 maCurrentFont = XML_minor;
251 return this;
252 case A_TOKEN( latin ):
253 {
254 if (mxCharProps)
255 mxCharProps->maLatinFont.setAttributes(rAttribs);
256
257 model::ThemeFont aThemeFont;
258 fillThemeFont(aThemeFont, rAttribs);
259 if (maCurrentFont == XML_major)
260 maFontScheme.setMajorLatin(aThemeFont);
261 else if (maCurrentFont == XML_minor)
262 maFontScheme.setMinorLatin(aThemeFont);
263 }
264 break;
265 case A_TOKEN( ea ):
266 {
267 if( mxCharProps )
268 mxCharProps->maAsianFont.setAttributes( rAttribs );
269 model::ThemeFont aThemeFont;
270 fillThemeFont(aThemeFont, rAttribs);
271 if (maCurrentFont == XML_major)
272 maFontScheme.setMajorAsian(aThemeFont);
273 else if (maCurrentFont == XML_minor)
274 maFontScheme.setMinorAsian(aThemeFont);
275 }
276 break;
277 case A_TOKEN( cs ):
278 {
279 if( mxCharProps )
280 mxCharProps->maComplexFont.setAttributes( rAttribs );
281 model::ThemeFont aThemeFont;
282 fillThemeFont(aThemeFont, rAttribs);
283 if (maCurrentFont == XML_major)
284 maFontScheme.setMajorComplex(aThemeFont);
285 else if (maCurrentFont == XML_minor)
286 maFontScheme.setMinorComplex(aThemeFont);
287 }
288 break;
289 case A_TOKEN(font):
290 {
291 OUString aScript = rAttribs.getStringDefaulted(XML_script);
292 OUString aTypeface = rAttribs.getStringDefaulted(XML_typeface);
293 mrSupplementalFontMap[maCurrentFont].emplace_back(std::pair<OUString, OUString>{aScript, aTypeface});
294 if (maCurrentFont == XML_major)
295 maFontScheme.addMajorSupplementalFont({aScript, aTypeface});
296 else if (maCurrentFont == XML_minor)
297 maFontScheme.addMinorSupplementalFont({aScript, aTypeface});
298 }
299 break;
300 }
301 return nullptr;
302}
303
304void FontSchemeContext::onEndElement()
305{
306 switch( getCurrentElement() )
307 {
308 case A_TOKEN( majorFont ):
309 case A_TOKEN( minorFont ):
310 mxCharProps.reset();
311 break;
312 }
313}
314
315ThemeElementsContext::ThemeElementsContext(ContextHandler2Helper const & rParent, Theme& rOoxTheme, model::Theme& rTheme)
316 : ContextHandler2(rParent)
317 , mrOoxTheme(rOoxTheme)
318 , mrTheme(rTheme)
319{
320}
321
323{
324 // CT_BaseStyles
325 switch (nElement)
326 {
327 case A_TOKEN( clrScheme ): // CT_ColorScheme
328 {
329 OUString aColorSchemeName = rAttribs.getStringDefaulted(XML_name);
330 mrTheme.setColorSet(std::make_shared<model::ColorSet>(aColorSchemeName));
331 if (rAttribs.hasAttribute(XML_name))
334 }
335 case A_TOKEN( fontScheme ): // CT_FontScheme
336 {
337 if (rAttribs.hasAttribute(XML_name))
339
340 return new FontSchemeContext(*this, rAttribs, mrOoxTheme.getFontScheme(), mrOoxTheme.getSupplementalFontMap(), mrTheme);
341 }
342
343 case A_TOKEN( fmtScheme ): // CT_StyleMatrix
344 {
345 if (rAttribs.hasAttribute(XML_name))
347 return this;
348 }
349
350 case A_TOKEN( fillStyleLst ): // CT_FillStyleList
351 return new FillStyleListContext(*this, mrOoxTheme.getFillStyleList(), mrTheme.getFormatScheme());
352 case A_TOKEN( lnStyleLst ): // CT_LineStyleList
353 return new LineStyleListContext(*this, mrOoxTheme.getLineStyleList(), mrTheme.getFormatScheme());
354 case A_TOKEN( effectStyleLst ): // CT_EffectStyleList
355 return new EffectStyleListContext(*this, mrOoxTheme.getEffectStyleList(), mrTheme.getFormatScheme());
356 case A_TOKEN( bgFillStyleLst ): // CT_BackgroundFillStyleList
357 return new BackgroundFillStyleListContext( *this, mrOoxTheme.getBgFillStyleList(), mrTheme.getFormatScheme());
358 }
359 return nullptr;
360}
361
362} // namespace oox::drawingml
363
364/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void setMajorAsian(ThemeFont const &aMajor)
void setMinorComplex(ThemeFont const &aMinor)
void setMajorLatin(ThemeFont const &aMajor)
void setMinorAsian(ThemeFont const &aMinor)
void setMinorLatin(ThemeFont const &aMinor)
void addMinorSupplementalFont(ThemeSupplementalFont const &rfont)
void addMajorSupplementalFont(ThemeSupplementalFont const &rfont)
void setMajorComplex(ThemeFont const &aMajor)
EffectStyle * addEffectStyle()
LineStyle * addLineStyle()
FillStyle * addBackgroundFillStyle()
FillStyle * addFillStyle()
std::shared_ptr< model::ColorSet > const & getColorSet() const
void setFontScheme(FontScheme const &rFontScheme)
void setColorSet(std::shared_ptr< model::ColorSet > const &pColorSet)
FormatScheme const & getFormatScheme() const
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:79
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const ::oox::AttributeList &rAttribs) override
void setFormatSchemeName(OUString const &rName)
Definition: theme.hxx:66
std::map< sal_Int32, std::vector< std::pair< OUString, OUString > > > & getSupplementalFontMap()
Definition: theme.hxx:91
FillStyleList & getFillStyleList()
Definition: theme.hxx:72
LineStyleList & getLineStyleList()
Definition: theme.hxx:79
EffectStyleList & getEffectStyleList()
Definition: theme.hxx:84
ClrScheme & getClrScheme()
Definition: theme.hxx:69
FillStyleList & getBgFillStyleList()
Definition: theme.hxx:74
FontScheme & getFontScheme()
Definition: theme.hxx:88
void setFontSchemeName(OUString const &rName)
Definition: theme.hxx:67
std::shared_ptr< T > make_shared(Args &&... args)
::rtl::Reference< ContextHandler > ContextHandlerRef
RefVector< LineProperties > LineStyleList
Definition: theme.hxx:56
RefVector< FillProperties > FillStyleList
Definition: theme.hxx:55
std::shared_ptr< TextCharacterProperties > TextCharacterPropertiesPtr
RefMap< sal_Int32, TextCharacterProperties > FontScheme
Definition: theme.hxx:58
RefVector< EffectProperties > EffectStyleList
Definition: theme.hxx:57
const sal_uInt8 WINDOWS_CHARSET_DEFAULT
Definition: helper.hxx:63
sal_Int16 maFamily
sal_Int16 maPitch
sal_Int32 maCharset
OUString maTypeface
std::map< sal_Int32, std::vector< std::pair< OUString, OUString > > > & mrSupplementalFontMap
model::FontScheme maFontScheme
model::Theme & mrTheme
sal_Int32 maCurrentFont
FillStyleList & mrFillStyleList
model::EffectStyle * mpEffectStyle
EffectStyleList & mrEffectStyleList
model::FormatScheme & mrFormatScheme
LineStyleList & mrLineStyleList
FontScheme & mrFontScheme
TextCharacterPropertiesPtr mxCharProps