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