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/clrschemecontext.hxx>
21 #include <oox/core/xmlfilterbase.hxx>
22 #include <oox/helper/attributelist.hxx>
23 #include <oox/token/namespaces.hxx>
24 #include <oox/token/tokens.hxx>
25
26 using namespace ::oox::core;
27 using namespace ::com::sun::star::uno;
28 using namespace ::com::sun::star::xml::sax;
29
30 namespace oox { namespace drawingml {
31
setClrMap(const::oox::AttributeList & rAttributes,ClrMap & rClrMap,sal_Int32 nToken)32 static void setClrMap( const ::oox::AttributeList& rAttributes,
33 ClrMap& rClrMap, sal_Int32 nToken )
34 {
35 if ( rAttributes.hasAttribute( nToken ) )
36 {
37 sal_Int32 nMappedToken = rAttributes.getToken( nToken, 0 );
38 rClrMap.setColorMap( nToken, nMappedToken );
39 }
40 }
41
clrMapContext(ContextHandler2Helper const & rParent,const::oox::AttributeList & rAttributes,ClrMap & rClrMap)42 clrMapContext::clrMapContext( ContextHandler2Helper const & rParent,
43 const ::oox::AttributeList& rAttributes, ClrMap& rClrMap )
44 : ContextHandler2( rParent )
45 {
46 setClrMap( rAttributes, rClrMap, XML_bg1 );
47 setClrMap( rAttributes, rClrMap, XML_tx1 );
48 setClrMap( rAttributes, rClrMap, XML_bg2 );
49 setClrMap( rAttributes, rClrMap, XML_tx2 );
50 setClrMap( rAttributes, rClrMap, XML_accent1 );
51 setClrMap( rAttributes, rClrMap, XML_accent2 );
52 setClrMap( rAttributes, rClrMap, XML_accent3 );
53 setClrMap( rAttributes, rClrMap, XML_accent4 );
54 setClrMap( rAttributes, rClrMap, XML_accent5 );
55 setClrMap( rAttributes, rClrMap, XML_accent6 );
56 setClrMap( rAttributes, rClrMap, XML_hlink );
57 setClrMap( rAttributes, rClrMap, XML_folHlink );
58 }
59
clrSchemeColorContext(ContextHandler2Helper const & rParent,ClrScheme & rClrScheme,sal_Int32 nColorToken)60 clrSchemeColorContext::clrSchemeColorContext( ContextHandler2Helper const & rParent, ClrScheme& rClrScheme, sal_Int32 nColorToken ) :
61 ColorContext( rParent, *this ),
62 mrClrScheme( rClrScheme ),
63 mnColorToken( nColorToken )
64 {
65 }
66
~clrSchemeColorContext()67 clrSchemeColorContext::~clrSchemeColorContext()
68 {
69 mrClrScheme.setColor( mnColorToken, getColor( getFilter().getGraphicHelper() ) );
70 }
71
clrSchemeContext(ContextHandler2Helper const & rParent,ClrScheme & rClrScheme)72 clrSchemeContext::clrSchemeContext( ContextHandler2Helper const & rParent, ClrScheme& rClrScheme ) :
73 ContextHandler2( rParent ),
74 mrClrScheme( rClrScheme )
75 {
76 }
77
onCreateContext(sal_Int32 nElement,const AttributeList &)78 ContextHandlerRef clrSchemeContext::onCreateContext(
79 sal_Int32 nElement, const AttributeList& )
80 {
81 switch( nElement )
82 {
83 case A_TOKEN( dk1 ):
84 case A_TOKEN( lt1 ):
85 case A_TOKEN( dk2 ):
86 case A_TOKEN( lt2 ):
87 case A_TOKEN( accent1 ):
88 case A_TOKEN( accent2 ):
89 case A_TOKEN( accent3 ):
90 case A_TOKEN( accent4 ):
91 case A_TOKEN( accent5 ):
92 case A_TOKEN( accent6 ):
93 case A_TOKEN( hlink ):
94 case A_TOKEN( folHlink ):
95 return new clrSchemeColorContext( *this, mrClrScheme, getBaseToken( nElement ) );
96 }
97 return nullptr;
98 }
99
100 } }
101
102 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
103