1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "oox/drawingml/clrschemecontext.hxx"
25 #include "oox/core/xmlfilterbase.hxx"
26 
27 using namespace ::oox::core;
28 using namespace ::com::sun::star::uno;
29 using namespace ::com::sun::star::xml::sax;
30 
31 namespace oox { namespace drawingml {
32 
setClrMap(const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XFastAttributeList> & xAttributes,ClrMap & rClrMap,sal_Int32 nToken)33 static void setClrMap( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttributes,
34             ClrMap& rClrMap, sal_Int32 nToken )
35 {
36 	if ( xAttributes->hasAttribute( nToken ) )
37 	{
38 		sal_Int32 nMappedToken = xAttributes->getOptionalValueToken( nToken, 0 );
39 		rClrMap.setColorMap( nToken, nMappedToken );
40 	}
41 }
42 
clrMapContext(ContextHandler & rParent,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XFastAttributeList> & xAttributes,ClrMap & rClrMap)43 clrMapContext::clrMapContext( ContextHandler& rParent,
44     const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttributes, ClrMap& rClrMap )
45 : ContextHandler( rParent )
46 {
47 	setClrMap( xAttributes, rClrMap, XML_bg1 );
48 	setClrMap( xAttributes, rClrMap, XML_tx1 );
49 	setClrMap( xAttributes, rClrMap, XML_bg2 );
50 	setClrMap( xAttributes, rClrMap, XML_tx2 );
51 	setClrMap( xAttributes, rClrMap, XML_accent1 );
52 	setClrMap( xAttributes, rClrMap, XML_accent2 );
53 	setClrMap( xAttributes, rClrMap, XML_accent3 );
54 	setClrMap( xAttributes, rClrMap, XML_accent4 );
55 	setClrMap( xAttributes, rClrMap, XML_accent5 );
56 	setClrMap( xAttributes, rClrMap, XML_accent6 );
57 	setClrMap( xAttributes, rClrMap, XML_hlink );
58 	setClrMap( xAttributes, rClrMap, XML_folHlink );
59 }
60 
clrSchemeColorContext(ContextHandler & rParent,ClrScheme & rClrScheme,sal_Int32 nColorToken)61 clrSchemeColorContext::clrSchemeColorContext( ContextHandler& rParent, ClrScheme& rClrScheme, sal_Int32 nColorToken ) :
62     ColorContext( rParent, *this ),
63     mrClrScheme( rClrScheme ),
64     mnColorToken( nColorToken )
65 {
66 }
67 
~clrSchemeColorContext()68 clrSchemeColorContext::~clrSchemeColorContext()
69 {
70     mrClrScheme.setColor( mnColorToken, getColor( getFilter().getGraphicHelper() ) );
71 }
72 
clrSchemeContext(ContextHandler & rParent,ClrScheme & rClrScheme)73 clrSchemeContext::clrSchemeContext( ContextHandler& rParent, ClrScheme& rClrScheme ) :
74     ContextHandler( rParent ),
75     mrClrScheme( rClrScheme )
76 {
77 }
78 
createFastChildContext(sal_Int32 nElement,const Reference<XFastAttributeList> &)79 Reference< XFastContextHandler > clrSchemeContext::createFastChildContext(
80         sal_Int32 nElement, const Reference< XFastAttributeList >& ) throw (SAXException, RuntimeException)
81 {
82     switch( nElement )
83     {
84         case A_TOKEN( dk1 ):
85         case A_TOKEN( lt1 ):
86         case A_TOKEN( dk2 ):
87         case A_TOKEN( lt2 ):
88         case A_TOKEN( accent1 ):
89         case A_TOKEN( accent2 ):
90         case A_TOKEN( accent3 ):
91         case A_TOKEN( accent4 ):
92         case A_TOKEN( accent5 ):
93         case A_TOKEN( accent6 ):
94         case A_TOKEN( hlink ):
95         case A_TOKEN( folHlink ):
96             return new clrSchemeColorContext( *this, mrClrScheme, getBaseToken( nElement ) );
97     }
98     return 0;
99 }
100 
101 } }
102