LibreOffice Module oox (master)  1
shapepropertymap.cxx
Go to the documentation of this file.
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 
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/Hatch.hpp>
26 #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
27 #include <com/sun/star/graphic/XGraphic.hpp>
28 
30 #include <oox/token/properties.hxx>
31 
32 namespace oox::drawingml {
33 
34 using namespace ::com::sun::star;
35 using namespace ::com::sun::star::beans;
36 using namespace ::com::sun::star::drawing;
37 using namespace ::com::sun::star::uno;
38 
39 namespace {
40 
41 const ShapePropertyIds spnDefaultShapeIds =
42 {
43  PROP_LineStyle, PROP_LineWidth, PROP_LineColor, PROP_LineTransparence, PROP_LineDash, PROP_LineCap, PROP_LineJoint,
44  PROP_LineStartName, PROP_LineStartWidth, PROP_LineStartCenter, PROP_LineEndName, PROP_LineEndWidth, PROP_LineEndCenter,
45  PROP_FillStyle, PROP_FillColor, PROP_FillTransparence, PROP_FillTransparenceGradientName, PROP_FillGradient,
46  PROP_FillBitmap, PROP_FillBitmapMode, PROP_FillBitmapSizeX, PROP_FillBitmapSizeY,
47  PROP_FillBitmapPositionOffsetX, PROP_FillBitmapPositionOffsetY, PROP_FillBitmapRectanglePoint,
48  PROP_FillHatch,
49  PROP_FillBackground,
50  PROP_FillBitmapName,
51  PROP_ShadowXDistance,
52  PROP_ShadowSizeX,
53  PROP_ShadowSizeY
54 };
55 
56 } // namespace
57 
58 ShapePropertyInfo ShapePropertyInfo::DEFAULT( spnDefaultShapeIds, true, false, false, false, false );
59 
61  bool bNamedLineMarker, bool bNamedLineDash, bool bNamedFillGradient, bool bNamedFillBitmap, bool bNamedFillHatch ) :
62  mrPropertyIds(rnPropertyIds),
63  mbNamedLineMarker( bNamedLineMarker ),
64  mbNamedLineDash( bNamedLineDash ),
65  mbNamedFillGradient( bNamedFillGradient ),
66  mbNamedFillBitmap( bNamedFillBitmap ),
67  mbNamedFillHatch( bNamedFillHatch )
68 {
69 }
70 
71 ShapePropertyMap::ShapePropertyMap( ModelObjectHelper& rModelObjHelper, const ShapePropertyInfo& rShapePropInfo ) :
72  mrModelObjHelper( rModelObjHelper ),
73  maShapePropInfo( rShapePropInfo )
74 {
75 }
76 
78 {
79  return maShapePropInfo.has( ePropId );
80 }
81 
82 bool ShapePropertyMap::hasNamedLineMarkerInTable( const OUString& rMarkerName ) const
83 {
85 }
86 
87 bool ShapePropertyMap::setAnyProperty( ShapeProperty ePropId, const Any& rValue )
88 {
89  // get current property identifier for the specified property
90  sal_Int32 nPropId = maShapePropInfo[ ePropId ];
91  if( nPropId < 0 ) return false;
92 
93  // special handling for properties supporting named objects in tables
94  switch( ePropId )
95  {
98  return setLineMarker( nPropId, rValue );
99 
101  return setLineDash( nPropId, rValue );
102 
104  return setFillGradient( nPropId, rValue );
105 
107  return setGradientTrans( nPropId, rValue );
108 
110  return setFillBitmap(nPropId, rValue);
111 
113  return setFillBitmapName(rValue);
114 
116  return setFillHatch( nPropId, rValue );
117 
118  default:; // suppress compiler warnings
119  }
120 
121  // set plain property value
122  setAnyProperty( nPropId, rValue );
123  return true;
124 }
125 
126 // private --------------------------------------------------------------------
127 
128 bool ShapePropertyMap::setLineMarker( sal_Int32 nPropId, const Any& rValue )
129 {
130  NamedValue aNamedMarker;
131  if( (rValue >>= aNamedMarker) && !aNamedMarker.Name.isEmpty() )
132  {
133  // push line marker explicitly
135  return setAnyProperty( nPropId, aNamedMarker.Value );
136 
137  // create named line marker (if coordinates have been passed) and push its name
138  bool bInserted = !aNamedMarker.Value.has< PolyPolygonBezierCoords >() ||
139  mrModelObjHelper.insertLineMarker( aNamedMarker.Name, aNamedMarker.Value.get< PolyPolygonBezierCoords >() );
140  return bInserted && setProperty( nPropId, aNamedMarker.Name );
141  }
142  return false;
143 }
144 
145 bool ShapePropertyMap::setLineDash( sal_Int32 nPropId, const Any& rValue )
146 {
147  // push line dash explicitly
149  return setAnyProperty( nPropId, rValue );
150 
151  // create named line dash and push its name
152  if( rValue.has< LineDash >() )
153  {
154  OUString aDashName = mrModelObjHelper.insertLineDash( rValue.get< LineDash >() );
155  return !aDashName.isEmpty() && setProperty( nPropId, aDashName );
156  }
157 
158  return false;
159 }
160 
161 bool ShapePropertyMap::setFillGradient( sal_Int32 nPropId, const Any& rValue )
162 {
163  // push gradient explicitly
165  return setAnyProperty( nPropId, rValue );
166 
167  // create named gradient and push its name
168  if( rValue.has< awt::Gradient >() )
169  {
170  OUString aGradientName = mrModelObjHelper.insertFillGradient( rValue.get< awt::Gradient >() );
171  return !aGradientName.isEmpty() && setProperty( nPropId, aGradientName );
172  }
173 
174  return false;
175 }
176 
177 bool ShapePropertyMap::setFillHatch( sal_Int32 nPropId, const Any& rValue )
178 {
179  // push hatch explicitly
181  return setAnyProperty( nPropId, rValue );
182 
183  // create named hatch and push its name
184  if (rValue.has<drawing::Hatch>())
185  {
186  OUString aHatchName = mrModelObjHelper.insertFillHatch(rValue.get<drawing::Hatch>());
187  return !aHatchName.isEmpty() && setProperty( nPropId, aHatchName );
188  }
189 
190  return false;
191 }
192 
193 bool ShapePropertyMap::setGradientTrans( sal_Int32 nPropId, const Any& rValue )
194 {
195  // create named gradient and push its name
196  if( rValue.has< awt::Gradient >() )
197  {
198  OUString aGradientName = mrModelObjHelper.insertTransGrandient( rValue.get< awt::Gradient >() );
199  return !aGradientName.isEmpty() && setProperty( nPropId, aGradientName );
200  }
201 
202  return false;
203 }
204 
205 bool ShapePropertyMap::setFillBitmap(sal_Int32 nPropId, const Any& rValue)
206 {
207  // push bitmap explicitly
209  {
210  return setAnyProperty(nPropId, rValue);
211  }
212 
213  // create named bitmap URL and push its name
214  if (rValue.has<uno::Reference<graphic::XGraphic>>())
215  {
216  auto xGraphic = rValue.get<uno::Reference<graphic::XGraphic>>();
217  OUString aBitmapName = mrModelObjHelper.insertFillBitmapXGraphic(xGraphic);
218  return !aBitmapName.isEmpty() && setProperty(nPropId, aBitmapName);
219  }
220 
221  return false;
222 }
223 
224 bool ShapePropertyMap::setFillBitmapName(const Any& rValue)
225 {
226  if (rValue.has<uno::Reference<graphic::XGraphic>>())
227  {
228  auto xGraphic = rValue.get<uno::Reference<graphic::XGraphic>>();
229  OUString aBitmapUrlName = mrModelObjHelper.insertFillBitmapXGraphic(xGraphic);
230  return !aBitmapUrlName.isEmpty() && setProperty(PROP_FillBitmapName, aBitmapUrlName);
231  }
232  return false;
233 }
234 
235 } // namespace oox::drawingml
236 
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool setGradientTrans(sal_Int32 nPropId, const css::uno::Any &rValue)
Creates a named transparency gradient.
bool setFillBitmapName(const css::uno::Any &rValue)
Sets an explicit fill bitmap and pushes the name to FillBitmapName.
bool hasNamedLineMarkerInTable(const OUString &rMarkerName) const
Returns true, if named line markers are supported, and the specified line marker has already been ins...
bool has(ShapeProperty ePropId) const
bool mbNamedLineDash
True = use named line marker instead of explicit line marker.
ModelObjectHelper & mrModelObjHelper
Converter for text formatting.
bool setProperty(ShapeProperty ePropId, const Type &rValue)
Sets the specified shape property to the passed value.
o3tl::enumarray< ShapeProperty, sal_Int32 > ShapePropertyIds
bool supportsProperty(ShapeProperty ePropId) const
Returns true, if the specified property is supported.
bool hasLineMarker(const OUString &rMarkerName) const
Returns true, if the model contains a line marker with the passed name.
bool mbNamedFillHatch
True = use named fill bitmap instead of explicit fill bitmap.
ShapePropertyInfo(const ShapePropertyIds &rnPropertyIds, bool bNamedLineMarker, bool bNamedLineDash, bool bNamedFillGradient, bool bNamedFillBitmap, bool bNamedFillHatch)
Default property info (used as default parameter of other methods).
ShapePropertyMap(ModelObjectHelper &rModelObjHelper, const ShapePropertyInfo &rShapePropInfo=ShapePropertyInfo::DEFAULT)
OUString insertFillBitmapXGraphic(css::uno::Reference< css::graphic::XGraphic > const &rxGraphic)
Inserts a new named fill graphic, returns the bitmap name, based on an internal constant name with a ...
bool setFillBitmap(sal_Int32 nPropId, const css::uno::Any &rValue)
Sets an explicit fill bitmap, or creates a named fill bitmap.
static ShapePropertyInfo DEFAULT
True = use named fill hatch instead of explicit fill hatch.
bool setLineDash(sal_Int32 nPropId, const css::uno::Any &rValue)
Sets an explicit line dash, or creates a named line dash.
Explicit fill bitmap or name of a fill bitmap stored in a global container.
Contains tables for named drawing objects for a document model.
bool setAnyProperty(ShapeProperty ePropId, const css::uno::Any &rValue)
Sets the specified shape property to the passed value.
OUString insertLineDash(const css::drawing::LineDash &rDash)
Inserts a new named line dash, returns the line dash name, based on an internal constant name with a ...
Explicit fill gradient or name of a fill gradient stored in a global container.
bool insertLineMarker(const OUString &rMarkerName, const css::drawing::PolyPolygonBezierCoords &rMarker)
Inserts a new named line marker, overwrites an existing line marker with the same name...
ShapeProperty
Enumeration for various properties related to drawing shape formatting.
bool setFillGradient(sal_Int32 nPropId, const css::uno::Any &rValue)
Sets an explicit fill gradient, or creates a named fill gradient.
OUString insertFillHatch(const css::drawing::Hatch &rHatch)
bool mbNamedFillBitmap
True = use named fill gradient instead of explicit fill gradient.
OUString insertFillGradient(const css::awt::Gradient &rGradient)
Inserts a new named fill gradient, returns the gradient name, based on an internal constant name with...
bool setLineMarker(sal_Int32 nPropId, const css::uno::Any &rValue)
Sets an explicit line marker, or creates a named line marker.
Explicit fill hatch or name of a fill hatch stored in a global container.
Explicit line dash or name of a line dash stored in a global container.
Explicit line start marker or name of a line marker stored in a global container. ...
bool setFillHatch(sal_Int32 nPropId, const css::uno::Any &rValue)
Sets an explicit fill hatch, or creates a named fill hatch.
OUString insertTransGrandient(const css::awt::Gradient &rGradient)
bool mbNamedFillGradient
True = use named line dash instead of explicit line dash.
Explicit line end marker or name of a line marker stored in a global container.