Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / oox / source / drawingml / colorchoicecontext.cxx
blobd1e5df65fded2a79ed204ce585ed317fd22c0ca7
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 {
28 namespace drawingml {
30 ColorValueContext::ColorValueContext( ContextHandler2Helper& rParent, Color& rColor ) :
31 ContextHandler2( rParent ),
32 mrColor( rColor )
36 void ColorValueContext::onStartElement( const AttributeList& rAttribs )
38 switch( getCurrentElement() )
40 case A_TOKEN( scrgbClr ):
41 mrColor.setScrgbClr(
42 rAttribs.getInteger( XML_r, 0 ),
43 rAttribs.getInteger( XML_g, 0 ),
44 rAttribs.getInteger( XML_b, 0 ) );
45 break;
47 case A_TOKEN( srgbClr ):
48 mrColor.setSrgbClr( rAttribs.getIntegerHex( XML_val, 0 ) );
49 break;
51 case A_TOKEN( hslClr ):
52 mrColor.setHslClr(
53 rAttribs.getInteger( XML_hue, 0 ),
54 rAttribs.getInteger( XML_sat, 0 ),
55 rAttribs.getInteger( XML_lum, 0 ) );
56 break;
58 case A_TOKEN( sysClr ):
59 mrColor.setSysClr(
60 rAttribs.getToken( XML_val, XML_TOKEN_INVALID ),
61 rAttribs.getIntegerHex( XML_lastClr, -1 ) );
62 break;
64 case A_TOKEN( schemeClr ):
66 mrColor.setSchemeClr( rAttribs.getToken( XML_val, XML_TOKEN_INVALID ) );
67 oox::OptValue<rtl::OUString> sSchemeName = rAttribs.getString( XML_val );
68 if( sSchemeName.has() )
69 mrColor.setSchemeName( sSchemeName.use() );
71 break;
73 case A_TOKEN( prstClr ):
74 mrColor.setPrstClr( rAttribs.getToken( XML_val, XML_TOKEN_INVALID ) );
75 break;
79 ::oox::core::ContextHandlerRef ColorValueContext::onCreateContext(
80 sal_Int32 nElement, const AttributeList& rAttribs )
82 switch( nElement )
84 case A_TOKEN( alpha ):
85 case A_TOKEN( alphaMod ):
86 case A_TOKEN( alphaOff ):
87 case A_TOKEN( blue ):
88 case A_TOKEN( blueMod ):
89 case A_TOKEN( blueOff ):
90 case A_TOKEN( hue ):
91 case A_TOKEN( hueMod ):
92 case A_TOKEN( hueOff ):
93 case A_TOKEN( lum ):
94 case A_TOKEN( lumMod ):
95 case A_TOKEN( lumOff ):
96 case A_TOKEN( green ):
97 case A_TOKEN( greenMod ):
98 case A_TOKEN( greenOff ):
99 case A_TOKEN( red ):
100 case A_TOKEN( redMod ):
101 case A_TOKEN( redOff ):
102 case A_TOKEN( sat ):
103 case A_TOKEN( satMod ):
104 case A_TOKEN( satOff ):
105 case A_TOKEN( shade ):
106 case A_TOKEN( tint ):
108 OUString aValue = rAttribs.getString( XML_val, OUString() );
109 sal_Int32 nVal = 0;
110 if (aValue.endsWith("%"))
112 nVal = aValue.toDouble() * PER_PERCENT;
114 else
115 nVal = rAttribs.getInteger(XML_val, 0);
116 mrColor.addTransformation( nElement, nVal );
118 break;
119 case A_TOKEN( comp ):
120 case A_TOKEN( gamma ):
121 case A_TOKEN( gray ):
122 case A_TOKEN( inv ):
123 case A_TOKEN( invGamma ):
124 mrColor.addTransformation( nElement );
125 break;
127 return nullptr;
130 ColorContext::ColorContext( ContextHandler2Helper& rParent, Color& rColor ) :
131 ContextHandler2( rParent ),
132 mrColor( rColor )
136 ::oox::core::ContextHandlerRef ColorContext::onCreateContext(
137 sal_Int32 nElement, const AttributeList& )
139 switch( nElement )
141 case A_TOKEN( scrgbClr ):
142 case A_TOKEN( srgbClr ):
143 case A_TOKEN( hslClr ):
144 case A_TOKEN( sysClr ):
145 case A_TOKEN( schemeClr ):
146 case A_TOKEN( prstClr ):
147 return new ColorValueContext( *this, mrColor );
149 return nullptr;
152 } // namespace drawingml
153 } // namespace oox
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */