1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #include "oox/drawingml/shapepropertymap.hxx" 25 26 #include <com/sun/star/awt/Gradient.hpp> 27 #include <com/sun/star/beans/NamedValue.hpp> 28 #include <com/sun/star/drawing/LineDash.hpp> 29 #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp> 30 #include "oox/helper/modelobjecthelper.hxx" 31 32 namespace oox { 33 namespace drawingml { 34 35 // ============================================================================ 36 37 using namespace ::com::sun::star::awt; 38 using namespace ::com::sun::star::beans; 39 using namespace ::com::sun::star::drawing; 40 using namespace ::com::sun::star::uno; 41 42 using ::rtl::OUString; 43 44 // ============================================================================ 45 46 namespace { 47 48 static const sal_Int32 spnDefaultShapeIds[ SHAPEPROP_END ] = 49 { 50 PROP_LineStyle, PROP_LineWidth, PROP_LineColor, PROP_LineTransparence, PROP_LineDash, PROP_LineJoint, 51 PROP_LineStartName, PROP_LineStartWidth, PROP_LineStartCenter, PROP_LineEndName, PROP_LineEndWidth, PROP_LineEndCenter, 52 PROP_FillStyle, PROP_FillColor, PROP_FillTransparence, PROP_FillGradient, 53 PROP_FillBitmapURL, PROP_FillBitmapMode, PROP_FillBitmapSizeX, PROP_FillBitmapSizeY, 54 PROP_FillBitmapPositionOffsetX, PROP_FillBitmapPositionOffsetY, PROP_FillBitmapRectanglePoint 55 }; 56 57 } // namespace 58 59 ShapePropertyInfo ShapePropertyInfo::DEFAULT( spnDefaultShapeIds, true, false, false, false ); 60 61 ShapePropertyInfo::ShapePropertyInfo( const sal_Int32* pnPropertyIds, 62 bool bNamedLineMarker, bool bNamedLineDash, bool bNamedFillGradient, bool bNamedFillBitmapUrl ) : 63 mpnPropertyIds( pnPropertyIds ), 64 mbNamedLineMarker( bNamedLineMarker ), 65 mbNamedLineDash( bNamedLineDash ), 66 mbNamedFillGradient( bNamedFillGradient ), 67 mbNamedFillBitmapUrl( bNamedFillBitmapUrl ) 68 { 69 OSL_ENSURE( mpnPropertyIds != 0, "ShapePropertyInfo::ShapePropertyInfo - missing property identifiers" ); 70 } 71 72 // ============================================================================ 73 74 ShapePropertyMap::ShapePropertyMap( ModelObjectHelper& rModelObjHelper, const ShapePropertyInfo& rShapePropInfo ) : 75 mrModelObjHelper( rModelObjHelper ), 76 maShapePropInfo( rShapePropInfo ) 77 { 78 } 79 80 bool ShapePropertyMap::supportsProperty( ShapePropertyId ePropId ) const 81 { 82 return maShapePropInfo.has( ePropId ); 83 } 84 85 bool ShapePropertyMap::hasNamedLineMarkerInTable( const OUString& rMarkerName ) const 86 { 87 return maShapePropInfo.mbNamedLineMarker && mrModelObjHelper.hasLineMarker( rMarkerName ); 88 } 89 90 bool ShapePropertyMap::setAnyProperty( ShapePropertyId ePropId, const Any& rValue ) 91 { 92 // get current property identifier for the specified property 93 sal_Int32 nPropId = maShapePropInfo[ ePropId ]; 94 if( nPropId < 0 ) return false; 95 96 // special handling for properties supporting named objects in tables 97 switch( ePropId ) 98 { 99 case SHAPEPROP_LineStart: 100 case SHAPEPROP_LineEnd: 101 return setLineMarker( nPropId, rValue ); 102 103 case SHAPEPROP_LineDash: 104 return setLineDash( nPropId, rValue ); 105 106 case SHAPEPROP_FillGradient: 107 return setFillGradient( nPropId, rValue ); 108 109 case SHAPEPROP_FillBitmapUrl: 110 return setFillBitmapUrl( nPropId, rValue ); 111 112 default:; // suppress compiler warnings 113 } 114 115 // set plain property value 116 operator[]( nPropId ) = rValue; 117 return true; 118 } 119 120 // private -------------------------------------------------------------------- 121 122 bool ShapePropertyMap::setLineMarker( sal_Int32 nPropId, const Any& rValue ) 123 { 124 NamedValue aNamedMarker; 125 if( (rValue >>= aNamedMarker) && (aNamedMarker.Name.getLength() > 0) ) 126 { 127 // push line marker explicitly 128 if( !maShapePropInfo.mbNamedLineMarker ) 129 return setAnyProperty( nPropId, aNamedMarker.Value ); 130 131 // create named line marker (if coordinates have been passed) and push its name 132 bool bInserted = !aNamedMarker.Value.has< PolyPolygonBezierCoords >() || 133 mrModelObjHelper.insertLineMarker( aNamedMarker.Name, aNamedMarker.Value.get< PolyPolygonBezierCoords >() ); 134 return bInserted && setProperty( nPropId, aNamedMarker.Name ); 135 } 136 return false; 137 } 138 139 bool ShapePropertyMap::setLineDash( sal_Int32 nPropId, const Any& rValue ) 140 { 141 // push line dash explicitly 142 if( !maShapePropInfo.mbNamedLineDash ) 143 return setAnyProperty( nPropId, rValue ); 144 145 // create named line dash and push its name 146 if( rValue.has< LineDash >() ) 147 { 148 OUString aDashName = mrModelObjHelper.insertLineDash( rValue.get< LineDash >() ); 149 return (aDashName.getLength() > 0) && setProperty( nPropId, aDashName ); 150 } 151 152 return false; 153 } 154 155 bool ShapePropertyMap::setFillGradient( sal_Int32 nPropId, const Any& rValue ) 156 { 157 // push gradient explicitly 158 if( !maShapePropInfo.mbNamedFillGradient ) 159 return setAnyProperty( nPropId, rValue ); 160 161 // create named gradient and push its name 162 if( rValue.has< Gradient >() ) 163 { 164 OUString aGradientName = mrModelObjHelper.insertFillGradient( rValue.get< Gradient >() ); 165 return (aGradientName.getLength() > 0) && setProperty( nPropId, aGradientName ); 166 } 167 168 return false; 169 } 170 171 bool ShapePropertyMap::setFillBitmapUrl( sal_Int32 nPropId, const Any& rValue ) 172 { 173 // push bitmap URL explicitly 174 if( !maShapePropInfo.mbNamedFillBitmapUrl ) 175 return setAnyProperty( nPropId, rValue ); 176 177 // create named bitmap URL and push its name 178 if( rValue.has< OUString >() ) 179 { 180 OUString aBitmapUrlName = mrModelObjHelper.insertFillBitmapUrl( rValue.get< OUString >() ); 181 return (aBitmapUrlName.getLength() > 0) && setProperty( nPropId, aBitmapUrlName ); 182 } 183 184 return false; 185 } 186 187 // ============================================================================ 188 189 } // namespace drawingml 190 } // namespace oox 191