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