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"
27 #include <oox/token/properties.hxx>
32 using namespace ::com::sun::star
;
33 using namespace ::com::sun::star::beans
;
34 using namespace ::com::sun::star::drawing
;
35 using namespace ::com::sun::star::uno
;
39 static const ShapePropertyIds spnDefaultShapeIds
=
41 PROP_LineStyle
, PROP_LineWidth
, PROP_LineColor
, PROP_LineTransparence
, PROP_LineDash
, PROP_LineJoint
,
42 PROP_LineStartName
, PROP_LineStartWidth
, PROP_LineStartCenter
, PROP_LineEndName
, PROP_LineEndWidth
, PROP_LineEndCenter
,
43 PROP_FillStyle
, PROP_FillColor
, PROP_FillTransparence
, PROP_FillTransparenceGradientName
, PROP_FillGradient
,
44 PROP_FillBitmapURL
, PROP_FillBitmapMode
, PROP_FillBitmapSizeX
, PROP_FillBitmapSizeY
,
45 PROP_FillBitmapPositionOffsetX
, PROP_FillBitmapPositionOffsetY
, PROP_FillBitmapRectanglePoint
,
53 ShapePropertyInfo
ShapePropertyInfo::DEFAULT( spnDefaultShapeIds
, true, false, false, false );
55 ShapePropertyInfo::ShapePropertyInfo( const ShapePropertyIds
& rnPropertyIds
,
56 bool bNamedLineMarker
, bool bNamedLineDash
, bool bNamedFillGradient
, bool bNamedFillBitmapUrl
) :
57 mrPropertyIds(rnPropertyIds
),
58 mbNamedLineMarker( bNamedLineMarker
),
59 mbNamedLineDash( bNamedLineDash
),
60 mbNamedFillGradient( bNamedFillGradient
),
61 mbNamedFillBitmapUrl( bNamedFillBitmapUrl
)
65 ShapePropertyMap::ShapePropertyMap( ModelObjectHelper
& rModelObjHelper
, const ShapePropertyInfo
& rShapePropInfo
) :
66 mrModelObjHelper( rModelObjHelper
),
67 maShapePropInfo( rShapePropInfo
)
71 bool ShapePropertyMap::supportsProperty( ShapeProperty ePropId
) const
73 return maShapePropInfo
.has( ePropId
);
76 bool ShapePropertyMap::hasNamedLineMarkerInTable( const OUString
& rMarkerName
) const
78 return maShapePropInfo
.mbNamedLineMarker
&& mrModelObjHelper
.hasLineMarker( rMarkerName
);
81 bool ShapePropertyMap::setAnyProperty( ShapeProperty ePropId
, const Any
& rValue
)
83 // get current property identifier for the specified property
84 sal_Int32 nPropId
= maShapePropInfo
[ ePropId
];
85 if( nPropId
< 0 ) return false;
87 // special handling for properties supporting named objects in tables
90 case ShapeProperty::LineStart
:
91 case ShapeProperty::LineEnd
:
92 return setLineMarker( nPropId
, rValue
);
94 case ShapeProperty::LineDash
:
95 return setLineDash( nPropId
, rValue
);
97 case ShapeProperty::FillGradient
:
98 return setFillGradient( nPropId
, rValue
);
100 case ShapeProperty::GradientTransparency
:
101 return setGradientTrans( nPropId
, rValue
);
103 case ShapeProperty::FillBitmapUrl
:
104 return setFillBitmapUrl( nPropId
, rValue
);
106 case ShapeProperty::FillBitmapNameFromUrl
:
107 return setFillBitmapNameFromUrl( rValue
);
109 default:; // suppress compiler warnings
112 // set plain property value
113 setAnyProperty( nPropId
, rValue
);
117 // private --------------------------------------------------------------------
119 bool ShapePropertyMap::setLineMarker( sal_Int32 nPropId
, const Any
& rValue
)
121 NamedValue aNamedMarker
;
122 if( (rValue
>>= aNamedMarker
) && !aNamedMarker
.Name
.isEmpty() )
124 // push line marker explicitly
125 if( !maShapePropInfo
.mbNamedLineMarker
)
126 return setAnyProperty( nPropId
, aNamedMarker
.Value
);
128 // create named line marker (if coordinates have been passed) and push its name
129 bool bInserted
= !aNamedMarker
.Value
.has
< PolyPolygonBezierCoords
>() ||
130 mrModelObjHelper
.insertLineMarker( aNamedMarker
.Name
, aNamedMarker
.Value
.get
< PolyPolygonBezierCoords
>() );
131 return bInserted
&& setProperty( nPropId
, aNamedMarker
.Name
);
136 bool ShapePropertyMap::setLineDash( sal_Int32 nPropId
, const Any
& rValue
)
138 // push line dash explicitly
139 if( !maShapePropInfo
.mbNamedLineDash
)
140 return setAnyProperty( nPropId
, rValue
);
142 // create named line dash and push its name
143 if( rValue
.has
< LineDash
>() )
145 OUString aDashName
= mrModelObjHelper
.insertLineDash( rValue
.get
< LineDash
>() );
146 return !aDashName
.isEmpty() && setProperty( nPropId
, aDashName
);
152 bool ShapePropertyMap::setFillGradient( sal_Int32 nPropId
, const Any
& rValue
)
154 // push gradient explicitly
155 if( !maShapePropInfo
.mbNamedFillGradient
)
156 return setAnyProperty( nPropId
, rValue
);
158 // create named gradient and push its name
159 if( rValue
.has
< awt::Gradient
>() )
161 OUString aGradientName
= mrModelObjHelper
.insertFillGradient( rValue
.get
< awt::Gradient
>() );
162 return !aGradientName
.isEmpty() && setProperty( nPropId
, aGradientName
);
168 bool ShapePropertyMap::setGradientTrans( sal_Int32 nPropId
, const Any
& rValue
)
170 // create named gradient and push its name
171 if( rValue
.has
< awt::Gradient
>() )
173 OUString aGradientName
= mrModelObjHelper
.insertTransGrandient( rValue
.get
< awt::Gradient
>() );
174 return !aGradientName
.isEmpty() && setProperty( nPropId
, aGradientName
);
180 bool ShapePropertyMap::setFillBitmapUrl( sal_Int32 nPropId
, const Any
& rValue
)
182 // push bitmap URL explicitly
183 if( !maShapePropInfo
.mbNamedFillBitmapUrl
)
184 return setAnyProperty( nPropId
, rValue
);
186 // create named bitmap URL and push its name
187 if( rValue
.has
< OUString
>() )
189 OUString aBitmapUrlName
= mrModelObjHelper
.insertFillBitmapUrl( rValue
.get
< OUString
>() );
190 return !aBitmapUrlName
.isEmpty() && setProperty( nPropId
, aBitmapUrlName
);
196 bool ShapePropertyMap::setFillBitmapNameFromUrl( const Any
& rValue
)
198 if( rValue
.has
< OUString
>() )
200 OUString aBitmapUrlName
= mrModelObjHelper
.insertFillBitmapUrl( rValue
.get
< OUString
>() );
201 return !aBitmapUrlName
.isEmpty() && setProperty( PROP_FillBitmapName
, aBitmapUrlName
);
206 } // namespace drawingml
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */