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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "oox/drawingml/shapepropertymap.hxx"
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"
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
;
38 static const sal_Int32 spnDefaultShapeIds
[ SHAPEPROP_END
+ 1 ] = // one for the PROP_END_LIST
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
,
53 ShapePropertyInfo
ShapePropertyInfo::DEFAULT( spnDefaultShapeIds
, true, false, false, false );
55 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 mbNamedFillBitmapUrl( bNamedFillBitmapUrl
)
62 assert(pnPropertyIds
);
63 // normally we should not reach PROP_COUNT but it prevents infinite loops if we hit a bug
64 for(size_t i
= 0; i
< static_cast<size_t>(PROP_COUNT
); ++i
)
66 if(pnPropertyIds
[i
] == PROP_END_LIST
)
69 maPropertyIds
.push_back(pnPropertyIds
[i
]);
73 ShapePropertyMap::ShapePropertyMap( ModelObjectHelper
& rModelObjHelper
, const ShapePropertyInfo
& rShapePropInfo
) :
74 mrModelObjHelper( rModelObjHelper
),
75 maShapePropInfo( rShapePropInfo
)
79 bool ShapePropertyMap::supportsProperty( ShapePropertyId ePropId
) const
81 return maShapePropInfo
.has( ePropId
);
84 bool ShapePropertyMap::hasNamedLineMarkerInTable( const OUString
& rMarkerName
) const
86 return maShapePropInfo
.mbNamedLineMarker
&& mrModelObjHelper
.hasLineMarker( rMarkerName
);
89 bool ShapePropertyMap::setAnyProperty( ShapePropertyId ePropId
, const Any
& rValue
)
91 // get current property identifier for the specified property
92 sal_Int32 nPropId
= maShapePropInfo
[ ePropId
];
93 if( nPropId
< 0 ) return false;
95 // special handling for properties supporting named objects in tables
98 case SHAPEPROP_LineStart
:
99 case SHAPEPROP_LineEnd
:
100 return setLineMarker( nPropId
, rValue
);
102 case SHAPEPROP_LineDash
:
103 return setLineDash( nPropId
, rValue
);
105 case SHAPEPROP_FillGradient
:
106 return setFillGradient( nPropId
, rValue
);
108 case SHAPEPROP_GradientTransparency
:
109 return setGradientTrans( nPropId
, rValue
);
111 case SHAPEPROP_FillBitmapUrl
:
112 return setFillBitmapUrl( nPropId
, rValue
);
114 case SHAPEPROP_FillBitmapNameFromUrl
:
115 return setFillBitmapNameFromUrl( nPropId
, rValue
);
117 default:; // suppress compiler warnings
120 // set plain property value
121 setAnyProperty( nPropId
, rValue
);
125 // private --------------------------------------------------------------------
127 bool ShapePropertyMap::setLineMarker( sal_Int32 nPropId
, const Any
& rValue
)
129 NamedValue aNamedMarker
;
130 if( (rValue
>>= aNamedMarker
) && !aNamedMarker
.Name
.isEmpty() )
132 // push line marker explicitly
133 if( !maShapePropInfo
.mbNamedLineMarker
)
134 return setAnyProperty( nPropId
, aNamedMarker
.Value
);
136 // create named line marker (if coordinates have been passed) and push its name
137 bool bInserted
= !aNamedMarker
.Value
.has
< PolyPolygonBezierCoords
>() ||
138 mrModelObjHelper
.insertLineMarker( aNamedMarker
.Name
, aNamedMarker
.Value
.get
< PolyPolygonBezierCoords
>() );
139 return bInserted
&& setProperty( nPropId
, aNamedMarker
.Name
);
144 bool ShapePropertyMap::setLineDash( sal_Int32 nPropId
, const Any
& rValue
)
146 // push line dash explicitly
147 if( !maShapePropInfo
.mbNamedLineDash
)
148 return setAnyProperty( nPropId
, rValue
);
150 // create named line dash and push its name
151 if( rValue
.has
< LineDash
>() )
153 OUString aDashName
= mrModelObjHelper
.insertLineDash( rValue
.get
< LineDash
>() );
154 return !aDashName
.isEmpty() && setProperty( nPropId
, aDashName
);
160 bool ShapePropertyMap::setFillGradient( sal_Int32 nPropId
, const Any
& rValue
)
162 // push gradient explicitly
163 if( !maShapePropInfo
.mbNamedFillGradient
)
164 return setAnyProperty( nPropId
, rValue
);
166 // create named gradient and push its name
167 if( rValue
.has
< awt::Gradient
>() )
169 OUString aGradientName
= mrModelObjHelper
.insertFillGradient( rValue
.get
< awt::Gradient
>() );
170 return !aGradientName
.isEmpty() && setProperty( nPropId
, aGradientName
);
176 bool ShapePropertyMap::setGradientTrans( sal_Int32 nPropId
, const Any
& rValue
)
178 // create named gradient and push its name
179 if( rValue
.has
< awt::Gradient
>() )
181 OUString aGradientName
= mrModelObjHelper
.insertTransGrandient( rValue
.get
< awt::Gradient
>() );
182 return !aGradientName
.isEmpty() && setProperty( nPropId
, aGradientName
);
188 bool ShapePropertyMap::setFillBitmapUrl( sal_Int32 nPropId
, const Any
& rValue
)
190 // push bitmap URL explicitly
191 if( !maShapePropInfo
.mbNamedFillBitmapUrl
)
192 return setAnyProperty( nPropId
, rValue
);
194 // create named bitmap URL and push its name
195 if( rValue
.has
< OUString
>() )
197 OUString aBitmapUrlName
= mrModelObjHelper
.insertFillBitmapUrl( rValue
.get
< OUString
>() );
198 return !aBitmapUrlName
.isEmpty() && setProperty( nPropId
, aBitmapUrlName
);
204 bool ShapePropertyMap::setFillBitmapNameFromUrl( sal_Int32
/*nPropId*/, const Any
& rValue
)
206 if( rValue
.has
< OUString
>() )
208 OUString aBitmapUrlName
= mrModelObjHelper
.insertFillBitmapUrl( rValue
.get
< OUString
>() );
209 return !aBitmapUrlName
.isEmpty() && setProperty( PROP_FillBitmapName
, aBitmapUrlName
);
214 } // namespace drawingml
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */