LibreOffice Module oox (master) 1
clrschemecontext.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
23#include <oox/token/namespaces.hxx>
24#include <oox/token/tokens.hxx>
25
26using namespace ::oox::core;
27using namespace ::com::sun::star::uno;
28using namespace ::com::sun::star::xml::sax;
29
30namespace oox::drawingml {
31
32static void setClrMap( const ::oox::AttributeList& rAttributes,
33 ClrMap& rClrMap, sal_Int32 nToken )
34{
35 if ( rAttributes.hasAttribute( nToken ) )
36 {
37 sal_Int32 nMappedToken = rAttributes.getToken( nToken, 0 );
38 rClrMap.setColorMap( nToken, nMappedToken );
39 }
40}
41
42clrMapContext::clrMapContext( ContextHandler2Helper const & rParent,
43 const ::oox::AttributeList& rAttributes, ClrMap& rClrMap )
44: ContextHandler2( rParent )
45{
46 setClrMap( rAttributes, rClrMap, XML_bg1 );
47 setClrMap( rAttributes, rClrMap, XML_tx1 );
48 setClrMap( rAttributes, rClrMap, XML_bg2 );
49 setClrMap( rAttributes, rClrMap, XML_tx2 );
50 setClrMap( rAttributes, rClrMap, XML_accent1 );
51 setClrMap( rAttributes, rClrMap, XML_accent2 );
52 setClrMap( rAttributes, rClrMap, XML_accent3 );
53 setClrMap( rAttributes, rClrMap, XML_accent4 );
54 setClrMap( rAttributes, rClrMap, XML_accent5 );
55 setClrMap( rAttributes, rClrMap, XML_accent6 );
56 setClrMap( rAttributes, rClrMap, XML_hlink );
57 setClrMap( rAttributes, rClrMap, XML_folHlink );
58}
59
60clrSchemeColorContext::clrSchemeColorContext(ContextHandler2Helper const & rParent, ClrScheme& rClrScheme, model::ColorSet& rColorSet, sal_Int32 nColorToken)
61 : ColorContext(rParent, *this, nullptr)
62 , mrClrScheme(rClrScheme)
63 , mrColorSet(rColorSet)
64 , mnColorToken(nColorToken)
65{
66}
67
69{
70 ::Color aColor = getColor(getFilter().getGraphicHelper());
72 switch (mnColorToken)
73 {
74 case XML_tx1:
75 case XML_dk1: mrColorSet.add(model::ThemeColorType::Dark1, aColor); break;
76 case XML_bg1:
77 case XML_lt1: mrColorSet.add(model::ThemeColorType::Light1, aColor); break;
78 case XML_tx2:
79 case XML_dk2: mrColorSet.add(model::ThemeColorType::Dark2, aColor); break;
80 case XML_bg2:
81 case XML_lt2: mrColorSet.add(model::ThemeColorType::Light2, aColor); break;
82 case XML_accent1: mrColorSet.add(model::ThemeColorType::Accent1, aColor); break;
83 case XML_accent2: mrColorSet.add(model::ThemeColorType::Accent2, aColor); break;
84 case XML_accent3: mrColorSet.add(model::ThemeColorType::Accent3, aColor); break;
85 case XML_accent4: mrColorSet.add(model::ThemeColorType::Accent4, aColor); break;
86 case XML_accent5: mrColorSet.add(model::ThemeColorType::Accent5, aColor); break;
87 case XML_accent6: mrColorSet.add(model::ThemeColorType::Accent6, aColor); break;
88 case XML_hlink: mrColorSet.add(model::ThemeColorType::Hyperlink, aColor); break;
89 case XML_folHlink: mrColorSet.add(model::ThemeColorType::FollowedHyperlink, aColor); break;
90 default: break;
91 }
92}
93
94clrSchemeContext::clrSchemeContext(ContextHandler2Helper const & rParent, ClrScheme& rClrScheme, model::ColorSet& rColorSet)
95 : ContextHandler2(rParent)
96 , mrClrScheme(rClrScheme)
97 , mrColorSet(rColorSet)
98{
99}
100
102 sal_Int32 nElement, const AttributeList& )
103{
104 switch( nElement )
105 {
106 case A_TOKEN( dk1 ):
107 case A_TOKEN( tx1 ):
108 case A_TOKEN( lt1 ):
109 case A_TOKEN( bg1 ):
110 case A_TOKEN( dk2 ):
111 case A_TOKEN( tx2 ):
112 case A_TOKEN( lt2 ):
113 case A_TOKEN( bg2 ):
114 case A_TOKEN( accent1 ):
115 case A_TOKEN( accent2 ):
116 case A_TOKEN( accent3 ):
117 case A_TOKEN( accent4 ):
118 case A_TOKEN( accent5 ):
119 case A_TOKEN( accent6 ):
120 case A_TOKEN( hlink ):
121 case A_TOKEN( folHlink ):
122 return new clrSchemeColorContext(*this, mrClrScheme, mrColorSet, getBaseToken(nElement));
123 }
124 return nullptr;
125}
126
127}
128
129/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void add(model::ThemeColorType Type, Color aColorData)
Provides access to attribute values of an element.
XmlFilterBase & getFilter() const
Returns the filter instance.
void setColorMap(sal_Int32 nClrToken, sal_Int32 nMappedClrToken)
Definition: clrscheme.cxx:83
void setColor(sal_Int32 nSchemeClrToken, ::Color nColor)
Definition: clrscheme.cxx:137
Context handler for elements that contain a color value element (a:scrgbClr, a:srgbClr,...
::Color getColor(const GraphicHelper &rGraphicHelper, ::Color nPhClr=API_RGB_TRANSPARENT) const
Returns the final RGB color value.
Definition: color.cxx:644
clrMapContext(::oox::core::ContextHandler2Helper const &rParent, const ::oox::AttributeList &rAttributes, ClrMap &rClrMap)
clrSchemeColorContext(::oox::core::ContextHandler2Helper const &rParent, ClrScheme &rClrScheme, model::ColorSet &mrColorSet, sal_Int32 nColorToken)
virtual ::oox::core::ContextHandlerRef onCreateContext(::sal_Int32 Element, const ::oox::AttributeList &rAttribs) override
clrSchemeContext(::oox::core::ContextHandler2Helper const &rParent, ClrScheme &rClrScheme, model::ColorSet &rColorSet)
static void setClrMap(const ::oox::AttributeList &rAttributes, ClrMap &rClrMap, sal_Int32 nToken)
sal_Int32 mnColorToken
Themed style index.
DefTokenId nToken