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 // ============================================================================
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
;
38 // ============================================================================
42 static const sal_Int32 spnDefaultShapeIds
[ SHAPEPROP_END
] =
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
,
55 ShapePropertyInfo
ShapePropertyInfo::DEFAULT( spnDefaultShapeIds
, true, false, false, false );
57 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 mbNamedFillBitmapUrl( bNamedFillBitmapUrl
)
65 OSL_ENSURE( mpnPropertyIds
!= 0, "ShapePropertyInfo::ShapePropertyInfo - missing property identifiers" );
68 // ============================================================================
70 ShapePropertyMap::ShapePropertyMap( ModelObjectHelper
& rModelObjHelper
, const ShapePropertyInfo
& rShapePropInfo
) :
71 mrModelObjHelper( rModelObjHelper
),
72 maShapePropInfo( rShapePropInfo
)
76 bool ShapePropertyMap::supportsProperty( ShapePropertyId ePropId
) const
78 return maShapePropInfo
.has( ePropId
);
81 bool ShapePropertyMap::hasNamedLineMarkerInTable( const OUString
& rMarkerName
) const
83 return maShapePropInfo
.mbNamedLineMarker
&& mrModelObjHelper
.hasLineMarker( rMarkerName
);
86 bool ShapePropertyMap::setAnyProperty( ShapePropertyId ePropId
, const Any
& rValue
)
88 // get current property identifier for the specified property
89 sal_Int32 nPropId
= maShapePropInfo
[ ePropId
];
90 if( nPropId
< 0 ) return false;
92 // special handling for properties supporting named objects in tables
95 case SHAPEPROP_LineStart
:
96 case SHAPEPROP_LineEnd
:
97 return setLineMarker( nPropId
, rValue
);
99 case SHAPEPROP_LineDash
:
100 return setLineDash( nPropId
, rValue
);
102 case SHAPEPROP_FillGradient
:
103 return setFillGradient( nPropId
, rValue
);
105 case SHAPEPROP_GradientTransparency
:
106 return setGradientTrans( nPropId
, rValue
);
108 case SHAPEPROP_FillBitmapUrl
:
109 return setFillBitmapUrl( nPropId
, rValue
);
111 default:; // suppress compiler warnings
114 // set plain property value
115 operator[]( nPropId
) = rValue
;
119 // private --------------------------------------------------------------------
121 bool ShapePropertyMap::setLineMarker( sal_Int32 nPropId
, const Any
& rValue
)
123 NamedValue aNamedMarker
;
124 if( (rValue
>>= aNamedMarker
) && !aNamedMarker
.Name
.isEmpty() )
126 // push line marker explicitly
127 if( !maShapePropInfo
.mbNamedLineMarker
)
128 return setAnyProperty( nPropId
, aNamedMarker
.Value
);
130 // create named line marker (if coordinates have been passed) and push its name
131 bool bInserted
= !aNamedMarker
.Value
.has
< PolyPolygonBezierCoords
>() ||
132 mrModelObjHelper
.insertLineMarker( aNamedMarker
.Name
, aNamedMarker
.Value
.get
< PolyPolygonBezierCoords
>() );
133 return bInserted
&& setProperty( nPropId
, aNamedMarker
.Name
);
138 bool ShapePropertyMap::setLineDash( sal_Int32 nPropId
, const Any
& rValue
)
140 // push line dash explicitly
141 if( !maShapePropInfo
.mbNamedLineDash
)
142 return setAnyProperty( nPropId
, rValue
);
144 // create named line dash and push its name
145 if( rValue
.has
< LineDash
>() )
147 OUString aDashName
= mrModelObjHelper
.insertLineDash( rValue
.get
< LineDash
>() );
148 return !aDashName
.isEmpty() && setProperty( nPropId
, aDashName
);
154 bool ShapePropertyMap::setFillGradient( sal_Int32 nPropId
, const Any
& rValue
)
156 // push gradient explicitly
157 if( !maShapePropInfo
.mbNamedFillGradient
)
158 return setAnyProperty( nPropId
, rValue
);
160 // create named gradient and push its name
161 if( rValue
.has
< awt::Gradient
>() )
163 OUString aGradientName
= mrModelObjHelper
.insertFillGradient( rValue
.get
< awt::Gradient
>() );
164 return !aGradientName
.isEmpty() && setProperty( nPropId
, aGradientName
);
170 bool ShapePropertyMap::setGradientTrans( sal_Int32 nPropId
, const Any
& rValue
)
172 // create named gradient and push its name
173 if( rValue
.has
< awt::Gradient
>() )
175 OUString aGradientName
= mrModelObjHelper
.insertTransGrandient( rValue
.get
< awt::Gradient
>() );
176 return !aGradientName
.isEmpty() && setProperty( nPropId
, aGradientName
);
182 bool ShapePropertyMap::setFillBitmapUrl( sal_Int32 nPropId
, const Any
& rValue
)
184 // push bitmap URL explicitly
185 if( !maShapePropInfo
.mbNamedFillBitmapUrl
)
186 return setAnyProperty( nPropId
, rValue
);
188 // create named bitmap URL and push its name
189 if( rValue
.has
< OUString
>() )
191 OUString aBitmapUrlName
= mrModelObjHelper
.insertFillBitmapUrl( rValue
.get
< OUString
>() );
192 return !aBitmapUrlName
.isEmpty() && setProperty( nPropId
, aBitmapUrlName
);
198 // ============================================================================
200 } // namespace drawingml
203 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */