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/.
10 #include <drawingml/effectpropertiescontext.hxx>
11 #include "effectproperties.hxx"
12 #include <drawingml/colorchoicecontext.hxx>
13 #include <oox/helper/attributelist.hxx>
14 #include <oox/token/namespaces.hxx>
15 #include <oox/token/tokens.hxx>
17 using namespace ::oox::core
;
18 using namespace ::com::sun::star::uno
;
19 using namespace ::com::sun::star::xml::sax
;
21 // CT_EffectProperties
23 namespace oox::drawingml
{
25 EffectPropertiesContext::EffectPropertiesContext( ContextHandler2Helper
const& rParent
,
26 EffectProperties
& rEffectProperties
) throw()
27 : ContextHandler2( rParent
)
28 , mrEffectProperties( rEffectProperties
)
32 EffectPropertiesContext::~EffectPropertiesContext()
36 void EffectPropertiesContext::saveUnsupportedAttribs( Effect
& rEffect
, const AttributeList
& rAttribs
)
38 if( rAttribs
.hasAttribute( XML_algn
) )
39 rEffect
.maAttribs
["algn"] <<= rAttribs
.getString( XML_algn
, "" );
40 if( rAttribs
.hasAttribute( XML_blurRad
) )
41 rEffect
.maAttribs
["blurRad"] <<= rAttribs
.getInteger( XML_blurRad
, 0 );
42 if( rAttribs
.hasAttribute( XML_dir
) )
43 rEffect
.maAttribs
["dir"] <<= rAttribs
.getInteger( XML_dir
, 0 );
44 if( rAttribs
.hasAttribute( XML_dist
) )
45 rEffect
.maAttribs
["dist"] <<= rAttribs
.getInteger( XML_dist
, 0 );
46 if( rAttribs
.hasAttribute( XML_kx
) )
47 rEffect
.maAttribs
["kx"] <<= rAttribs
.getInteger( XML_kx
, 0 );
48 if( rAttribs
.hasAttribute( XML_ky
) )
49 rEffect
.maAttribs
["ky"] <<= rAttribs
.getInteger( XML_ky
, 0 );
50 if( rAttribs
.hasAttribute( XML_rotWithShape
) )
51 rEffect
.maAttribs
["rotWithShape"] <<= rAttribs
.getInteger( XML_rotWithShape
, 0 );
52 if( rAttribs
.hasAttribute( XML_sx
) )
53 rEffect
.maAttribs
["sx"] <<= rAttribs
.getInteger( XML_sx
, 0 );
54 if( rAttribs
.hasAttribute( XML_sy
) )
55 rEffect
.maAttribs
["sy"] <<= rAttribs
.getInteger( XML_sy
, 0 );
56 if( rAttribs
.hasAttribute( XML_rad
) )
57 rEffect
.maAttribs
["rad"] <<= rAttribs
.getInteger( XML_rad
, 0 );
58 if( rAttribs
.hasAttribute( XML_endA
) )
59 rEffect
.maAttribs
["endA"] <<= rAttribs
.getInteger( XML_endA
, 0 );
60 if( rAttribs
.hasAttribute( XML_endPos
) )
61 rEffect
.maAttribs
["endPos"] <<= rAttribs
.getInteger( XML_endPos
, 0 );
62 if( rAttribs
.hasAttribute( XML_fadeDir
) )
63 rEffect
.maAttribs
["fadeDir"] <<= rAttribs
.getInteger( XML_fadeDir
, 0 );
64 if( rAttribs
.hasAttribute( XML_stA
) )
65 rEffect
.maAttribs
["stA"] <<= rAttribs
.getInteger( XML_stA
, 0 );
66 if( rAttribs
.hasAttribute( XML_stPos
) )
67 rEffect
.maAttribs
["stPos"] <<= rAttribs
.getInteger( XML_stPos
, 0 );
68 if( rAttribs
.hasAttribute( XML_grow
) )
69 rEffect
.maAttribs
["grow"] <<= rAttribs
.getInteger( XML_grow
, 0 );
72 ContextHandlerRef
EffectPropertiesContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
74 sal_Int32 nPos
= mrEffectProperties
.m_Effects
.size();
75 mrEffectProperties
.m_Effects
.push_back(std::make_unique
<Effect
>());
78 case A_TOKEN( outerShdw
):
80 mrEffectProperties
.m_Effects
[nPos
]->msName
= "outerShdw";
81 saveUnsupportedAttribs(*mrEffectProperties
.m_Effects
[nPos
], rAttribs
);
83 mrEffectProperties
.maShadow
.moShadowDist
= rAttribs
.getInteger( XML_dist
, 0 );
84 mrEffectProperties
.maShadow
.moShadowDir
= rAttribs
.getInteger( XML_dir
, 0 );
85 mrEffectProperties
.maShadow
.moShadowSx
= rAttribs
.getInteger( XML_sx
, 0 );
86 mrEffectProperties
.maShadow
.moShadowSy
= rAttribs
.getInteger( XML_sy
, 0 );
87 mrEffectProperties
.maShadow
.moShadowBlur
= rAttribs
.getInteger( XML_blurRad
, 0 );
88 return new ColorContext(*this, mrEffectProperties
.m_Effects
[nPos
]->moColor
);
91 case A_TOKEN( innerShdw
):
93 mrEffectProperties
.m_Effects
[nPos
]->msName
= "innerShdw";
94 saveUnsupportedAttribs(*mrEffectProperties
.m_Effects
[nPos
], rAttribs
);
96 mrEffectProperties
.maShadow
.moShadowDist
= rAttribs
.getInteger( XML_dist
, 0 );
97 mrEffectProperties
.maShadow
.moShadowDir
= rAttribs
.getInteger( XML_dir
, 0 );
98 return new ColorContext(*this, mrEffectProperties
.m_Effects
[nPos
]->moColor
);
101 case A_TOKEN( glow
):
103 mrEffectProperties
.maGlow
.moGlowRad
= rAttribs
.getInteger( XML_rad
, 0 );
104 // undo push_back to effects
105 mrEffectProperties
.m_Effects
.pop_back();
106 return new ColorContext(*this, mrEffectProperties
.maGlow
.moGlowColor
);
109 case A_TOKEN( softEdge
):
111 mrEffectProperties
.maSoftEdge
.moRad
= rAttribs
.getInteger(XML_rad
, 0);
112 return this; // no inner elements
114 case A_TOKEN( reflection
):
115 case A_TOKEN( blur
):
117 if (nElement
== A_TOKEN(reflection
))
118 mrEffectProperties
.m_Effects
[nPos
]->msName
= "reflection";
119 else if( nElement
== A_TOKEN( blur
) )
120 mrEffectProperties
.m_Effects
[nPos
]->msName
= "blur";
121 saveUnsupportedAttribs(*mrEffectProperties
.m_Effects
[nPos
], rAttribs
);
122 return new ColorContext(*this, mrEffectProperties
.m_Effects
[nPos
]->moColor
);
127 mrEffectProperties
.m_Effects
.pop_back();
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */