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