Line data Source code
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 :
20 : #include "VLegendSymbolFactory.hxx"
21 : #include "macros.hxx"
22 : #include "PropertyMapper.hxx"
23 : #include "AbstractShapeFactory.hxx"
24 : #include "ObjectIdentifier.hxx"
25 : #include <com/sun/star/drawing/LineStyle.hpp>
26 : #include <com/sun/star/chart2/Symbol.hpp>
27 :
28 : using namespace ::com::sun::star;
29 : using ::com::sun::star::uno::Reference;
30 : using ::com::sun::star::uno::Sequence;
31 :
32 : namespace
33 : {
34 :
35 1201 : void getPropNamesAndValues( const Reference< beans::XPropertySet >& xProp,
36 : ::chart::tNameSequence& rNames,
37 : ::chart::tAnySequence& rValues,
38 : ::chart::VLegendSymbolFactory::tPropertyType ePropertyType,
39 : const awt::Size& aMaxSymbolExtent = awt::Size(0,0))
40 : {
41 1201 : const ::chart::tPropertyNameMap & aFilledSeriesNameMap( ::chart::PropertyMapper::getPropertyNameMapForFilledSeriesProperties());
42 1201 : const ::chart::tPropertyNameMap & aLineSeriesNameMap( ::chart::PropertyMapper::getPropertyNameMapForLineSeriesProperties());
43 1201 : const ::chart::tPropertyNameMap & aLineNameMap( ::chart::PropertyMapper::getPropertyNameMapForLineProperties());
44 1201 : const ::chart::tPropertyNameMap & aFillNameMap( ::chart::PropertyMapper::getPropertyNameMapForFillProperties());
45 1201 : const ::chart::tPropertyNameMap & aFillLineNameMap( ::chart::PropertyMapper::getPropertyNameMapForFillAndLineProperties());
46 :
47 1201 : ::chart::tPropertyNameValueMap aValueMap;
48 1201 : switch( ePropertyType )
49 : {
50 : case ::chart::VLegendSymbolFactory::PROP_TYPE_FILLED_SERIES:
51 1067 : ::chart::PropertyMapper::getValueMap( aValueMap, aFilledSeriesNameMap, xProp );
52 1067 : break;
53 : case ::chart::VLegendSymbolFactory::PROP_TYPE_LINE_SERIES:
54 88 : ::chart::PropertyMapper::getValueMap( aValueMap, aLineSeriesNameMap, xProp );
55 88 : break;
56 : case ::chart::VLegendSymbolFactory::PROP_TYPE_LINE:
57 46 : ::chart::PropertyMapper::getValueMap( aValueMap, aLineNameMap, xProp );
58 46 : break;
59 : case ::chart::VLegendSymbolFactory::PROP_TYPE_FILL:
60 0 : ::chart::PropertyMapper::getValueMap( aValueMap, aFillNameMap, xProp );
61 0 : break;
62 : case ::chart::VLegendSymbolFactory::PROP_TYPE_FILL_AND_LINE:
63 0 : ::chart::PropertyMapper::getValueMap( aValueMap, aFillLineNameMap, xProp );
64 0 : break;
65 : }
66 :
67 1201 : ::chart::PropertyMapper::getMultiPropertyListsFromValueMap( rNames, rValues, aValueMap );
68 :
69 1201 : uno::Any* pLineWidthAny = ::chart::PropertyMapper::getValuePointer(rValues,rNames,"LineWidth");
70 1201 : sal_Int32 nLineWidth = 0;
71 1201 : if( pLineWidthAny && (*pLineWidthAny>>=nLineWidth) )
72 : {
73 : // use legend entry height as upper limit for line width
74 1201 : sal_Int32 nMaxLineWidthForLegend = aMaxSymbolExtent.Height;
75 1201 : if( nLineWidth>nMaxLineWidthForLegend )
76 34 : *pLineWidthAny = uno::makeAny( nMaxLineWidthForLegend );
77 1201 : }
78 1201 : }
79 :
80 134 : void lcl_setPropetiesToShape(
81 : const Reference< beans::XPropertySet > & xProp,
82 : const Reference< drawing::XShape > & xShape,
83 : ::chart::VLegendSymbolFactory::tPropertyType ePropertyType,
84 : const awt::Size& aMaxSymbolExtent = awt::Size(0,0))
85 : {
86 134 : ::chart::tNameSequence aPropNames;
87 268 : ::chart::tAnySequence aPropValues;
88 : getPropNamesAndValues( xProp, aPropNames, aPropValues,
89 134 : ePropertyType, aMaxSymbolExtent );
90 :
91 268 : Reference< beans::XPropertySet > xShapeProp( xShape, uno::UNO_QUERY );
92 268 : ::chart::PropertyMapper::setMultiProperties( aPropNames, aPropValues, xShapeProp );
93 134 : }
94 :
95 : } // anonymous namespace
96 :
97 : namespace chart
98 : {
99 :
100 1201 : Reference< drawing::XShape > VLegendSymbolFactory::createSymbol(
101 : const awt::Size& rEntryKeyAspectRatio,
102 : const Reference< drawing::XShapes > xSymbolContainer,
103 : LegendSymbolStyle eStyle,
104 : const Reference< lang::XMultiServiceFactory > & xShapeFactory,
105 : const Reference< beans::XPropertySet > & xLegendEntryProperties,
106 : tPropertyType ePropertyType, const uno::Any& rExplicitSymbol )
107 : {
108 1201 : Reference< drawing::XShape > xResult;
109 :
110 1201 : if( ! (xSymbolContainer.is() && xShapeFactory.is()))
111 0 : return xResult;
112 :
113 1201 : AbstractShapeFactory* pShapeFactory = AbstractShapeFactory::getOrCreateShapeFactory(xShapeFactory);
114 1201 : xResult.set( pShapeFactory->createGroup2D( xSymbolContainer ), uno::UNO_QUERY );
115 :
116 2402 : Reference< drawing::XShapes > xResultGroup( xResult, uno::UNO_QUERY );
117 1201 : if( ! xResultGroup.is())
118 0 : return xResult;
119 :
120 : // add an invisible square box to maintain aspect ratio
121 : Reference< drawing::XShape > xBound( pShapeFactory->createInvisibleRectangle(
122 2402 : xResultGroup, rEntryKeyAspectRatio ));
123 :
124 : // create symbol
125 : try
126 : {
127 1201 : if( eStyle == LegendSymbolStyle_LINE )
128 : {
129 : Reference< drawing::XShape > xLine =
130 : pShapeFactory->createLine( xResultGroup, awt::Size( rEntryKeyAspectRatio.Width, 0 ),
131 134 : awt::Point( 0, rEntryKeyAspectRatio.Height/2 ));
132 134 : if( xLine.is())
133 : {
134 134 : lcl_setPropetiesToShape( xLegendEntryProperties, xLine, ePropertyType, rEntryKeyAspectRatio );
135 : }
136 :
137 268 : Reference< drawing::XShape > xSymbol;
138 134 : const sal_Int32 nSize = std::min(rEntryKeyAspectRatio.Width,rEntryKeyAspectRatio.Height);
139 268 : chart2::Symbol aSymbol;
140 134 : if( rExplicitSymbol >>= aSymbol )
141 : {
142 86 : drawing::Direction3D aSymbolSize( nSize, nSize, 0 );
143 86 : drawing::Position3D aPos( rEntryKeyAspectRatio.Width/2.0, rEntryKeyAspectRatio.Height/2.0, 0 );
144 86 : AbstractShapeFactory* pFactory = AbstractShapeFactory::getOrCreateShapeFactory( xShapeFactory );
145 86 : if( aSymbol.Style == chart2::SymbolStyle_STANDARD )
146 : {
147 : // take series color as fill color
148 68 : xLegendEntryProperties->getPropertyValue( "Color") >>= aSymbol.FillColor;
149 : // border of symbols always same as fill color
150 68 : aSymbol.BorderColor = aSymbol.FillColor;
151 :
152 : xSymbol.set( pFactory->createSymbol2D(
153 : xResultGroup,
154 : aPos,
155 : aSymbolSize,
156 : aSymbol.StandardSymbol,
157 : aSymbol.BorderColor,
158 68 : aSymbol.FillColor ));
159 : }
160 18 : else if( aSymbol.Style == chart2::SymbolStyle_GRAPHIC )
161 : {
162 : xSymbol.set( pFactory->createGraphic2D(
163 : xResultGroup,
164 : aPos,
165 : aSymbolSize,
166 0 : aSymbol.Graphic ));
167 : }
168 18 : else if( aSymbol.Style == chart2::SymbolStyle_AUTO )
169 : {
170 : SAL_WARN("chart2", "the given parameter is not allowed to contain an automatic symbol style");
171 : }
172 134 : }
173 : }
174 1067 : else if( eStyle == LegendSymbolStyle_CIRCLE )
175 : {
176 0 : sal_Int32 nSize = std::min( rEntryKeyAspectRatio.Width, rEntryKeyAspectRatio.Height );
177 : Reference< drawing::XShape > xShape =
178 : pShapeFactory->createCircle( xResultGroup, awt::Size( nSize, nSize ),
179 0 : awt::Point( rEntryKeyAspectRatio.Width/2-nSize/2, rEntryKeyAspectRatio.Height/2-nSize/2 ));
180 0 : if( xShape.is() )
181 : {
182 0 : lcl_setPropetiesToShape( xLegendEntryProperties, xShape, ePropertyType ); // PROP_TYPE_FILLED_SERIES );
183 0 : }
184 : }
185 : else // eStyle == LegendSymbolStyle_BOX
186 : {
187 1067 : tNameSequence aPropNames;
188 2134 : tAnySequence aPropValues;
189 :
190 : getPropNamesAndValues( xLegendEntryProperties, aPropNames, aPropValues,
191 1067 : ePropertyType );// PROP_TYPE_FILLED_SERIES
192 :
193 : Reference< drawing::XShape > xShape =
194 : pShapeFactory->createRectangle( xResultGroup,
195 : rEntryKeyAspectRatio, awt::Point( 0, 0 ),
196 2134 : aPropNames, aPropValues );
197 : }
198 : }
199 0 : catch( const uno::Exception & ex )
200 : {
201 : ASSERT_EXCEPTION( ex );
202 : }
203 :
204 1201 : return xResult;
205 : }
206 :
207 108 : } // namespace chart
208 :
209 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|