Line data Source code
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 :
20 : #include "oox/drawingml/shapepropertymap.hxx"
21 :
22 : #include <com/sun/star/awt/Gradient.hpp>
23 : #include <com/sun/star/beans/NamedValue.hpp>
24 : #include <com/sun/star/drawing/LineDash.hpp>
25 : #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
26 : #include "oox/helper/modelobjecthelper.hxx"
27 :
28 : namespace oox {
29 : namespace drawingml {
30 :
31 : // ============================================================================
32 :
33 : using namespace ::com::sun::star;
34 : using namespace ::com::sun::star::beans;
35 : using namespace ::com::sun::star::drawing;
36 : using namespace ::com::sun::star::uno;
37 :
38 : // ============================================================================
39 :
40 : namespace {
41 :
42 : static const sal_Int32 spnDefaultShapeIds[ SHAPEPROP_END ] =
43 : {
44 : PROP_LineStyle, PROP_LineWidth, PROP_LineColor, PROP_LineTransparence, PROP_LineDash, PROP_LineJoint,
45 : PROP_LineStartName, PROP_LineStartWidth, PROP_LineStartCenter, PROP_LineEndName, PROP_LineEndWidth, PROP_LineEndCenter,
46 : PROP_FillStyle, PROP_FillColor, PROP_FillTransparence, PROP_FillTransparenceGradientName, PROP_FillGradient,
47 : PROP_FillBitmapURL, PROP_FillBitmapMode, PROP_FillBitmapSizeX, PROP_FillBitmapSizeY,
48 : PROP_FillBitmapPositionOffsetX, PROP_FillBitmapPositionOffsetY, PROP_FillBitmapRectanglePoint,
49 : PROP_FillHatch,
50 : PROP_ShadowXDistance
51 : };
52 :
53 : } // namespace
54 :
55 47 : ShapePropertyInfo ShapePropertyInfo::DEFAULT( spnDefaultShapeIds, true, false, false, false );
56 :
57 188 : ShapePropertyInfo::ShapePropertyInfo( const sal_Int32* pnPropertyIds,
58 : bool bNamedLineMarker, bool bNamedLineDash, bool bNamedFillGradient, bool bNamedFillBitmapUrl ) :
59 : mpnPropertyIds( pnPropertyIds ),
60 : mbNamedLineMarker( bNamedLineMarker ),
61 : mbNamedLineDash( bNamedLineDash ),
62 : mbNamedFillGradient( bNamedFillGradient ),
63 188 : mbNamedFillBitmapUrl( bNamedFillBitmapUrl )
64 : {
65 : OSL_ENSURE( mpnPropertyIds != 0, "ShapePropertyInfo::ShapePropertyInfo - missing property identifiers" );
66 188 : }
67 :
68 : // ============================================================================
69 :
70 225 : ShapePropertyMap::ShapePropertyMap( ModelObjectHelper& rModelObjHelper, const ShapePropertyInfo& rShapePropInfo ) :
71 : mrModelObjHelper( rModelObjHelper ),
72 225 : maShapePropInfo( rShapePropInfo )
73 : {
74 225 : }
75 :
76 64 : bool ShapePropertyMap::supportsProperty( ShapePropertyId ePropId ) const
77 : {
78 64 : return maShapePropInfo.has( ePropId );
79 : }
80 :
81 9 : bool ShapePropertyMap::hasNamedLineMarkerInTable( const OUString& rMarkerName ) const
82 : {
83 9 : return maShapePropInfo.mbNamedLineMarker && mrModelObjHelper.hasLineMarker( rMarkerName );
84 : }
85 :
86 966 : bool ShapePropertyMap::setAnyProperty( ShapePropertyId ePropId, const Any& rValue )
87 : {
88 : // get current property identifier for the specified property
89 966 : sal_Int32 nPropId = maShapePropInfo[ ePropId ];
90 966 : if( nPropId < 0 ) return false;
91 :
92 : // special handling for properties supporting named objects in tables
93 966 : switch( ePropId )
94 : {
95 : case SHAPEPROP_LineStart:
96 : case SHAPEPROP_LineEnd:
97 9 : return setLineMarker( nPropId, rValue );
98 :
99 : case SHAPEPROP_LineDash:
100 0 : return setLineDash( nPropId, rValue );
101 :
102 : case SHAPEPROP_FillGradient:
103 13 : return setFillGradient( nPropId, rValue );
104 :
105 : case SHAPEPROP_GradientTransparency:
106 3 : return setGradientTrans( nPropId, rValue );
107 :
108 : case SHAPEPROP_FillBitmapUrl:
109 0 : return setFillBitmapUrl( nPropId, rValue );
110 :
111 : default:; // suppress compiler warnings
112 : }
113 :
114 : // set plain property value
115 941 : operator[]( nPropId ) = rValue;
116 941 : return true;
117 : }
118 :
119 : // private --------------------------------------------------------------------
120 :
121 9 : bool ShapePropertyMap::setLineMarker( sal_Int32 nPropId, const Any& rValue )
122 : {
123 9 : NamedValue aNamedMarker;
124 9 : if( (rValue >>= aNamedMarker) && !aNamedMarker.Name.isEmpty() )
125 : {
126 : // push line marker explicitly
127 9 : if( !maShapePropInfo.mbNamedLineMarker )
128 0 : return setAnyProperty( nPropId, aNamedMarker.Value );
129 :
130 : // create named line marker (if coordinates have been passed) and push its name
131 17 : bool bInserted = !aNamedMarker.Value.has< PolyPolygonBezierCoords >() ||
132 17 : mrModelObjHelper.insertLineMarker( aNamedMarker.Name, aNamedMarker.Value.get< PolyPolygonBezierCoords >() );
133 9 : return bInserted && setProperty( nPropId, aNamedMarker.Name );
134 : }
135 0 : return false;
136 : }
137 :
138 0 : bool ShapePropertyMap::setLineDash( sal_Int32 nPropId, const Any& rValue )
139 : {
140 : // push line dash explicitly
141 0 : if( !maShapePropInfo.mbNamedLineDash )
142 0 : return setAnyProperty( nPropId, rValue );
143 :
144 : // create named line dash and push its name
145 0 : if( rValue.has< LineDash >() )
146 : {
147 0 : OUString aDashName = mrModelObjHelper.insertLineDash( rValue.get< LineDash >() );
148 0 : return !aDashName.isEmpty() && setProperty( nPropId, aDashName );
149 : }
150 :
151 0 : return false;
152 : }
153 :
154 13 : bool ShapePropertyMap::setFillGradient( sal_Int32 nPropId, const Any& rValue )
155 : {
156 : // push gradient explicitly
157 13 : if( !maShapePropInfo.mbNamedFillGradient )
158 13 : return setAnyProperty( nPropId, rValue );
159 :
160 : // create named gradient and push its name
161 0 : if( rValue.has< awt::Gradient >() )
162 : {
163 0 : OUString aGradientName = mrModelObjHelper.insertFillGradient( rValue.get< awt::Gradient >() );
164 0 : return !aGradientName.isEmpty() && setProperty( nPropId, aGradientName );
165 : }
166 :
167 0 : return false;
168 : }
169 :
170 3 : bool ShapePropertyMap::setGradientTrans( sal_Int32 nPropId, const Any& rValue )
171 : {
172 : // create named gradient and push its name
173 3 : if( rValue.has< awt::Gradient >() )
174 : {
175 3 : OUString aGradientName = mrModelObjHelper.insertTransGrandient( rValue.get< awt::Gradient >() );
176 3 : return !aGradientName.isEmpty() && setProperty( nPropId, aGradientName );
177 : }
178 :
179 0 : return false;
180 : }
181 :
182 0 : bool ShapePropertyMap::setFillBitmapUrl( sal_Int32 nPropId, const Any& rValue )
183 : {
184 : // push bitmap URL explicitly
185 0 : if( !maShapePropInfo.mbNamedFillBitmapUrl )
186 0 : return setAnyProperty( nPropId, rValue );
187 :
188 : // create named bitmap URL and push its name
189 0 : if( rValue.has< OUString >() )
190 : {
191 0 : OUString aBitmapUrlName = mrModelObjHelper.insertFillBitmapUrl( rValue.get< OUString >() );
192 0 : return !aBitmapUrlName.isEmpty() && setProperty( nPropId, aBitmapUrlName );
193 : }
194 :
195 0 : return false;
196 : }
197 :
198 : // ============================================================================
199 :
200 : } // namespace drawingml
201 141 : } // namespace oox
202 :
203 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|