1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
),
35 void ColorValueContext::onStartElement( const AttributeList
& rAttribs
)
37 switch( getCurrentElement() )
39 case A_TOKEN( scrgbClr
):
41 rAttribs
.getInteger( XML_r
, 0 ),
42 rAttribs
.getInteger( XML_g
, 0 ),
43 rAttribs
.getInteger( XML_b
, 0 ) );
46 case A_TOKEN( srgbClr
):
47 mrColor
.setSrgbClr( rAttribs
.getIntegerHex( XML_val
, 0 ) );
50 case A_TOKEN( hslClr
):
52 rAttribs
.getInteger( XML_hue
, 0 ),
53 rAttribs
.getInteger( XML_sat
, 0 ),
54 rAttribs
.getInteger( XML_lum
, 0 ) );
57 case A_TOKEN( sysClr
):
59 rAttribs
.getToken( XML_val
, XML_TOKEN_INVALID
),
60 rAttribs
.getIntegerHex( XML_lastClr
, -1 ) );
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() );
72 case A_TOKEN( prstClr
):
73 mrColor
.setPrstClr( rAttribs
.getToken( XML_val
, XML_TOKEN_INVALID
) );
78 ::oox::core::ContextHandlerRef
ColorValueContext::onCreateContext(
79 sal_Int32 nElement
, const AttributeList
& rAttribs
)
83 case A_TOKEN( alpha
):
84 case A_TOKEN( alphaMod
):
85 case A_TOKEN( alphaOff
):
87 case A_TOKEN( blueMod
):
88 case A_TOKEN( blueOff
):
90 case A_TOKEN( hueMod
):
91 case A_TOKEN( hueOff
):
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
):
99 case A_TOKEN( redMod
):
100 case A_TOKEN( redOff
):
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() );
109 if (aValue
.endsWith("%"))
111 nVal
= aValue
.toDouble() * PER_PERCENT
;
114 nVal
= rAttribs
.getInteger(XML_val
, 0);
115 mrColor
.addTransformation( nElement
, nVal
);
118 case A_TOKEN( comp
):
119 case A_TOKEN( gamma
):
120 case A_TOKEN( gray
):
122 case A_TOKEN( invGamma
):
123 mrColor
.addTransformation( nElement
);
129 ColorContext::ColorContext( ContextHandler2Helper
const & rParent
, Color
& rColor
) :
130 ContextHandler2( rParent
),
135 ::oox::core::ContextHandlerRef
ColorContext::onCreateContext(
136 sal_Int32 nElement
, const AttributeList
& )
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
);
151 ColorsContext::ColorsContext(ContextHandler2Helper
const& rParent
, std::vector
<Color
>& rColors
)
152 : ContextHandler2(rParent
)
157 ::oox::core::ContextHandlerRef
ColorsContext::onCreateContext(sal_Int32 nElement
,
158 const AttributeList
&)
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());
176 } // namespace oox::drawingml
178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */