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/colorchoicecontext.hxx"
25 #include "oox/helper/attributelist.hxx"
26 #include "oox/drawingml/color.hxx"
27
28 using ::com::sun::star::uno::Reference;
29 using ::com::sun::star::uno::RuntimeException;
30 using ::com::sun::star::xml::sax::SAXException;
31 using ::com::sun::star::xml::sax::XFastAttributeList;
32 using ::com::sun::star::xml::sax::XFastContextHandler;
33 using ::oox::core::ContextHandler;
34
35 namespace oox {
36 namespace drawingml {
37
38 // ============================================================================
39
ColorValueContext(ContextHandler & rParent,Color & rColor)40 ColorValueContext::ColorValueContext( ContextHandler& rParent, Color& rColor ) :
41 ContextHandler( rParent ),
42 mrColor( rColor )
43 {
44 }
45
startFastElement(sal_Int32 nElement,const Reference<XFastAttributeList> & rxAttribs)46 void ColorValueContext::startFastElement( sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs )
47 {
48 AttributeList aAttribs( rxAttribs );
49 switch( nElement )
50 {
51 case A_TOKEN( scrgbClr ):
52 mrColor.setScrgbClr(
53 aAttribs.getInteger( XML_r, 0 ),
54 aAttribs.getInteger( XML_g, 0 ),
55 aAttribs.getInteger( XML_b, 0 ) );
56 break;
57
58 case A_TOKEN( srgbClr ):
59 mrColor.setSrgbClr( aAttribs.getIntegerHex( XML_val, 0 ) );
60 break;
61
62 case A_TOKEN( hslClr ):
63 mrColor.setHslClr(
64 aAttribs.getInteger( XML_hue, 0 ),
65 aAttribs.getInteger( XML_sat, 0 ),
66 aAttribs.getInteger( XML_lum, 0 ) );
67 break;
68
69 case A_TOKEN( sysClr ):
70 mrColor.setSysClr(
71 aAttribs.getToken( XML_val, XML_TOKEN_INVALID ),
72 aAttribs.getIntegerHex( XML_lastClr, -1 ) );
73 break;
74
75 case A_TOKEN( schemeClr ):
76 mrColor.setSchemeClr( aAttribs.getToken( XML_val, XML_TOKEN_INVALID ) );
77 break;
78
79 case A_TOKEN( prstClr ):
80 mrColor.setPrstClr( aAttribs.getToken( XML_val, XML_TOKEN_INVALID ) );
81 break;
82 }
83 }
84
createFastChildContext(sal_Int32 nElement,const Reference<XFastAttributeList> & rxAttribs)85 Reference< XFastContextHandler > ColorValueContext::createFastChildContext(
86 sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs )
87 {
88 AttributeList aAttribs( rxAttribs );
89 switch( nElement )
90 {
91 case A_TOKEN( alpha ):
92 case A_TOKEN( alphaMod ):
93 case A_TOKEN( alphaOff ):
94 case A_TOKEN( blue ):
95 case A_TOKEN( blueMod ):
96 case A_TOKEN( blueOff ):
97 case A_TOKEN( hue ):
98 case A_TOKEN( hueMod ):
99 case A_TOKEN( hueOff ):
100 case A_TOKEN( lum ):
101 case A_TOKEN( lumMod ):
102 case A_TOKEN( lumOff ):
103 case A_TOKEN( green ):
104 case A_TOKEN( greenMod ):
105 case A_TOKEN( greenOff ):
106 case A_TOKEN( red ):
107 case A_TOKEN( redMod ):
108 case A_TOKEN( redOff ):
109 case A_TOKEN( sat ):
110 case A_TOKEN( satMod ):
111 case A_TOKEN( satOff ):
112 case A_TOKEN( shade ):
113 case A_TOKEN( tint ):
114 mrColor.addTransformation( nElement, aAttribs.getInteger( XML_val, 0 ) );
115 break;
116 case A_TOKEN( comp ):
117 case A_TOKEN( gamma ):
118 case A_TOKEN( gray ):
119 case A_TOKEN( inv ):
120 case A_TOKEN( invGamma ):
121 mrColor.addTransformation( nElement );
122 break;
123 }
124 return 0;
125 }
126
127 // ============================================================================
128
ColorContext(ContextHandler & rParent,Color & rColor)129 ColorContext::ColorContext( ContextHandler& rParent, Color& rColor ) :
130 ContextHandler( rParent ),
131 mrColor( rColor )
132 {
133 }
134
createFastChildContext(sal_Int32 nElement,const Reference<XFastAttributeList> &)135 Reference< XFastContextHandler > ColorContext::createFastChildContext(
136 sal_Int32 nElement, const Reference< XFastAttributeList >& )
137 {
138 switch( nElement )
139 {
140 case A_TOKEN( scrgbClr ):
141 case A_TOKEN( srgbClr ):
142 case A_TOKEN( hslClr ):
143 case A_TOKEN( sysClr ):
144 case A_TOKEN( schemeClr ):
145 case A_TOKEN( prstClr ):
146 return new ColorValueContext( *this, mrColor );
147 }
148 return 0;
149 }
150
151 // ============================================================================
152
153 } // namespace drawingml
154 } // namespace oox
155