nss: upgrade to release 3.73
[LibreOffice.git] / oox / source / drawingml / colorchoicecontext.cxx
blobfc93b460a8de104036bb111cb17c97e249e4b1e6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <oox/drawingml/drawingmltypes.hxx>
21 #include <drawingml/colorchoicecontext.hxx>
22 #include <oox/helper/attributelist.hxx>
23 #include <oox/drawingml/color.hxx>
24 #include <oox/token/namespaces.hxx>
25 #include <oox/token/tokens.hxx>
27 namespace oox::drawingml {
29 ColorValueContext::ColorValueContext( ContextHandler2Helper const & rParent, Color& rColor ) :
30 ContextHandler2( rParent ),
31 mrColor( rColor )
35 void ColorValueContext::onStartElement( const AttributeList& rAttribs )
37 switch( getCurrentElement() )
39 case A_TOKEN( scrgbClr ):
40 mrColor.setScrgbClr(
41 rAttribs.getInteger( XML_r, 0 ),
42 rAttribs.getInteger( XML_g, 0 ),
43 rAttribs.getInteger( XML_b, 0 ) );
44 break;
46 case A_TOKEN( srgbClr ):
47 mrColor.setSrgbClr( rAttribs.getIntegerHex( XML_val, 0 ) );
48 break;
50 case A_TOKEN( hslClr ):
51 mrColor.setHslClr(
52 rAttribs.getInteger( XML_hue, 0 ),
53 rAttribs.getInteger( XML_sat, 0 ),
54 rAttribs.getInteger( XML_lum, 0 ) );
55 break;
57 case A_TOKEN( sysClr ):
58 mrColor.setSysClr(
59 rAttribs.getToken( XML_val, XML_TOKEN_INVALID ),
60 rAttribs.getIntegerHex( XML_lastClr, -1 ) );
61 break;
63 case A_TOKEN( schemeClr ):
65 mrColor.setSchemeClr( rAttribs.getToken( XML_val, XML_TOKEN_INVALID ) );
66 oox::OptValue<OUString> sSchemeName = rAttribs.getString( XML_val );
67 if( sSchemeName.has() )
68 mrColor.setSchemeName( sSchemeName.use() );
70 break;
72 case A_TOKEN( prstClr ):
73 mrColor.setPrstClr( rAttribs.getToken( XML_val, XML_TOKEN_INVALID ) );
74 break;
78 ::oox::core::ContextHandlerRef ColorValueContext::onCreateContext(
79 sal_Int32 nElement, const AttributeList& rAttribs )
81 switch( nElement )
83 case A_TOKEN( alpha ):
84 case A_TOKEN( alphaMod ):
85 case A_TOKEN( alphaOff ):
86 case A_TOKEN( blue ):
87 case A_TOKEN( blueMod ):
88 case A_TOKEN( blueOff ):
89 case A_TOKEN( hue ):
90 case A_TOKEN( hueMod ):
91 case A_TOKEN( hueOff ):
92 case A_TOKEN( lum ):
93 case A_TOKEN( lumMod ):
94 case A_TOKEN( lumOff ):
95 case A_TOKEN( green ):
96 case A_TOKEN( greenMod ):
97 case A_TOKEN( greenOff ):
98 case A_TOKEN( red ):
99 case A_TOKEN( redMod ):
100 case A_TOKEN( redOff ):
101 case A_TOKEN( sat ):
102 case A_TOKEN( satMod ):
103 case A_TOKEN( satOff ):
104 case A_TOKEN( shade ):
105 case A_TOKEN( tint ):
107 OUString aValue = rAttribs.getString( XML_val, OUString() );
108 sal_Int32 nVal = 0;
109 if (aValue.endsWith("%"))
111 nVal = aValue.toDouble() * PER_PERCENT;
113 else
114 nVal = rAttribs.getInteger(XML_val, 0);
115 mrColor.addTransformation( nElement, nVal );
117 break;
118 case A_TOKEN( comp ):
119 case A_TOKEN( gamma ):
120 case A_TOKEN( gray ):
121 case A_TOKEN( inv ):
122 case A_TOKEN( invGamma ):
123 mrColor.addTransformation( nElement );
124 break;
126 return nullptr;
129 ColorContext::ColorContext( ContextHandler2Helper const & rParent, Color& rColor ) :
130 ContextHandler2( rParent ),
131 mrColor( rColor )
135 ::oox::core::ContextHandlerRef ColorContext::onCreateContext(
136 sal_Int32 nElement, const AttributeList& )
138 switch( nElement )
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 );
148 return nullptr;
151 ColorsContext::ColorsContext(ContextHandler2Helper const& rParent, std::vector<Color>& rColors)
152 : ContextHandler2(rParent)
153 , mrColors(rColors)
157 ::oox::core::ContextHandlerRef ColorsContext::onCreateContext(sal_Int32 nElement,
158 const AttributeList&)
160 switch (nElement)
162 case A_TOKEN(scrgbClr):
163 case A_TOKEN(srgbClr):
164 case A_TOKEN(hslClr):
165 case A_TOKEN(sysClr):
166 case A_TOKEN(schemeClr):
167 case A_TOKEN(prstClr):
169 mrColors.emplace_back();
170 return new ColorValueContext(*this, mrColors.back());
173 return nullptr;
176 } // namespace oox::drawingml
178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */