LibreOffice Module oox (master) 1
colorchoicecontext.cxx
Go to the documentation of this file.
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
24#include <oox/token/namespaces.hxx>
25#include <oox/token/tokens.hxx>
26
27namespace oox::drawingml {
28
30 ContextHandler2( rParent ),
31 mrColor( rColor )
32{
33}
34
36{
37 switch( getCurrentElement() )
38 {
39 case A_TOKEN( scrgbClr ):
41 rAttribs.getInteger( XML_r, 0 ),
42 rAttribs.getInteger( XML_g, 0 ),
43 rAttribs.getInteger( XML_b, 0 ) );
44 break;
45
46 case A_TOKEN( srgbClr ):
47 mrColor.setSrgbClr( rAttribs.getIntegerHex( XML_val, 0 ) );
48 break;
49
50 case A_TOKEN( hslClr ):
52 rAttribs.getInteger( XML_hue, 0 ),
53 rAttribs.getInteger( XML_sat, 0 ),
54 rAttribs.getInteger( XML_lum, 0 ) );
55 break;
56
57 case A_TOKEN( sysClr ):
59 rAttribs.getToken( XML_val, XML_TOKEN_INVALID ),
60 rAttribs.getIntegerHex( XML_lastClr, -1 ) );
61 break;
62
63 case A_TOKEN( schemeClr ):
64 {
65 mrColor.setSchemeClr( rAttribs.getToken( XML_val, XML_TOKEN_INVALID ) );
66 std::optional<OUString> sSchemeName = rAttribs.getString( XML_val );
67 if( sSchemeName.has_value() )
68 mrColor.setSchemeName( *sSchemeName );
69 }
70 break;
71
72 case A_TOKEN( prstClr ):
73 mrColor.setPrstClr( rAttribs.getToken( XML_val, XML_TOKEN_INVALID ) );
74 break;
75 }
76}
77
79 sal_Int32 nElement, const AttributeList& rAttribs )
80{
81 switch( nElement )
82 {
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 ):
106 {
107 OUString aValue = rAttribs.getString( XML_val, OUString() );
108 sal_Int32 nVal = 0;
109 if (aValue.endsWith("%"))
110 {
111 nVal = aValue.toDouble() * PER_PERCENT;
112 }
113 else
114 nVal = rAttribs.getInteger(XML_val, 0);
115 mrColor.addTransformation( nElement, nVal );
116 }
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;
125 }
126 return nullptr;
127}
128
130 ContextHandler2( rParent ),
131 mrColor( rColor )
132{
133}
134
136 sal_Int32 nElement, const AttributeList& )
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 nullptr;
149}
150
151ColorsContext::ColorsContext(ContextHandler2Helper const& rParent, std::vector<Color>& rColors)
152 : ContextHandler2(rParent)
153 , mrColors(rColors)
154{
155}
156
158 const AttributeList&)
159{
160 switch (nElement)
161 {
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):
168 {
169 mrColors.emplace_back();
170 return new ColorValueContext(*this, mrColors.back());
171 }
172 }
173 return nullptr;
174}
175
176} // namespace oox::drawingml
177
178/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Provides access to attribute values of an element.
std::optional< sal_Int32 > getIntegerHex(sal_Int32 nAttrToken) const
Returns the 32-bit signed integer value of the specified attribute (hexadecimal).
std::optional< sal_Int32 > getInteger(sal_Int32 nAttrToken) const
Returns the 32-bit signed integer value of the specified attribute (decimal).
std::optional< OUString > getString(sal_Int32 nAttrToken) const
Returns the string value of the specified attribute.
std::optional< sal_Int32 > getToken(sal_Int32 nAttrToken) const
Returns the token identifier of the value of the specified attribute.
Helper class that provides a context stack.
sal_Int32 getCurrentElement() const
Returns the identifier of the currently processed element.
ColorContext(::oox::core::ContextHandler2Helper const &rParent, Color &rColor)
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const ::oox::AttributeList &rAttribs) override
Context handler for the different color value elements (a:scrgbClr, a:srgbClr, a:hslClr,...
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const ::oox::AttributeList &rAttribs) override
virtual void onStartElement(const ::oox::AttributeList &rAttribs) override
ColorValueContext(::oox::core::ContextHandler2Helper const &rParent, Color &rColor)
void addTransformation(sal_Int32 nElement, sal_Int32 nValue=-1)
Inserts the passed color transformation.
Definition: color.cxx:327
void setPrstClr(sal_Int32 nToken)
Sets a predefined color from the a:prstClr element.
Definition: color.cxx:289
void setScrgbClr(sal_Int32 nR, sal_Int32 nG, sal_Int32 nB)
Sets the percentual RGB values from the a:scrgbClr element.
Definition: color.cxx:267
void setSchemeClr(sal_Int32 nToken)
Sets a scheme color from the a:schemeClr element.
Definition: color.cxx:305
void setHslClr(sal_Int32 nHue, sal_Int32 nSat, sal_Int32 nLum)
Sets the HSL values from the a:hslClr element.
Definition: color.cxx:278
void setSysClr(sal_Int32 nToken, sal_Int32 nLastRgb)
Sets a system color from the a:sysClr element.
Definition: color.cxx:319
void setSchemeName(const OUString &sSchemeName)
Sets the scheme name from the a:schemeClr element for interoperability purposes.
Definition: color.hxx:66
void setSrgbClr(sal_Int32 nRgb)
Sets an RGB value (hexadecimal RRGGBB) from the a:srgbClr element.
Definition: color.cxx:260
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const ::oox::AttributeList &rAttribs) override
ColorsContext(::oox::core::ContextHandler2Helper const &rParent, std::vector< Color > &rColors)
std::vector< Color > & mrColors
const sal_Int32 PER_PERCENT
comp
XML_TOKEN_INVALID