1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
;
41 class FillStyleListContext
: public ContextHandler2
44 FillStyleListContext( ContextHandler2Helper
& rParent
, FillStyleList
& rFillStyleList
);
45 virtual ContextHandlerRef
onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
) override
;
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
)
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() );
73 class LineStyleListContext
: public ContextHandler2
76 LineStyleListContext( ContextHandler2Helper
& rParent
, LineStyleList
& rLineStyleList
);
77 virtual ContextHandlerRef
onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
) override
;
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
)
94 mrLineStyleList
.push_back( std::make_shared
<LineProperties
>( ) );
95 return new LinePropertiesContext( *this, rAttribs
, *mrLineStyleList
.back() );
100 class EffectStyleListContext
: public ContextHandler2
103 EffectStyleListContext( ContextHandler2Helper
& rParent
, EffectStyleList
& rEffectStyleList
);
104 virtual ContextHandlerRef
onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
) override
;
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*/ )
120 case A_TOKEN( effectStyle
):
121 mrEffectStyleList
.push_back( std::make_shared
<EffectProperties
>( ) );
124 case A_TOKEN( effectLst
): // CT_EffectList
125 if( mrEffectStyleList
.back() )
126 return new EffectPropertiesContext( *this, *mrEffectStyleList
.back() );
132 class FontSchemeContext
: public ContextHandler2
135 FontSchemeContext( ContextHandler2Helper
& rParent
, FontScheme
& rFontScheme
);
136 virtual ContextHandlerRef
onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
) override
;
137 virtual void onEndElement() override
;
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
)
154 case A_TOKEN( majorFont
):
155 mxCharProps
.reset( new TextCharacterProperties
);
156 mrFontScheme
[ XML_major
] = mxCharProps
;
158 case A_TOKEN( minorFont
):
159 mxCharProps
.reset( new TextCharacterProperties
);
160 mrFontScheme
[ XML_minor
] = mxCharProps
;
163 case A_TOKEN( latin
):
164 if( mxCharProps
.get() )
165 mxCharProps
->maLatinFont
.setAttributes( rAttribs
);
168 if( mxCharProps
.get() )
169 mxCharProps
->maAsianFont
.setAttributes( rAttribs
);
172 if( mxCharProps
.get() )
173 mxCharProps
->maComplexFont
.setAttributes( rAttribs
);
179 void FontSchemeContext::onEndElement()
181 switch( getCurrentElement() )
183 case A_TOKEN( majorFont
):
184 case A_TOKEN( minorFont
):
190 ThemeElementsContext::ThemeElementsContext( ContextHandler2Helper
& rParent
, Theme
& rTheme
) :
191 ContextHandler2( rParent
),
196 ContextHandlerRef
ThemeElementsContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
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() );
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() );
222 } // namespace drawingml
225 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */