Coverage Report

Created: 2025-12-08 09:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/chart2/source/view/main/VLegendSymbolFactory.cxx
Line
Count
Source
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 <PropertyMapper.hxx>
22
#include <ShapeFactory.hxx>
23
#include <com/sun/star/drawing/Position3D.hpp>
24
#include <com/sun/star/chart2/Symbol.hpp>
25
#include <com/sun/star/drawing/Direction3D.hpp>
26
#include <comphelper/diagnose_ex.hxx>
27
#include <sal/log.hxx>
28
29
using namespace ::com::sun::star;
30
using ::com::sun::star::uno::Reference;
31
32
namespace
33
{
34
35
void getPropNamesAndValues( const Reference< beans::XPropertySet >& xProp,
36
        ::chart::tNameSequence& rNames,
37
        ::chart::tAnySequence& rValues,
38
        ::chart::VLegendSymbolFactory::PropertyType ePropertyType,
39
        const awt::Size& aMaxSymbolExtent)
40
0
{
41
0
    const ::chart::tPropertyNameMap & aFilledSeriesNameMap( ::chart::PropertyMapper::getPropertyNameMapForFilledSeriesProperties());
42
0
    const ::chart::tPropertyNameMap & aLineSeriesNameMap( ::chart::PropertyMapper::getPropertyNameMapForLineSeriesProperties());
43
0
    const ::chart::tPropertyNameMap & aLineNameMap( ::chart::PropertyMapper::getPropertyNameMapForLineProperties());
44
45
0
    ::chart::tPropertyNameValueMap aValueMap;
46
0
    switch( ePropertyType )
47
0
    {
48
0
        case ::chart::VLegendSymbolFactory::PropertyType::FilledSeries:
49
0
            ::chart::PropertyMapper::getValueMap( aValueMap, aFilledSeriesNameMap, xProp );
50
0
            break;
51
0
        case ::chart::VLegendSymbolFactory::PropertyType::LineSeries:
52
0
            ::chart::PropertyMapper::getValueMap( aValueMap, aLineSeriesNameMap, xProp );
53
0
            break;
54
0
        case ::chart::VLegendSymbolFactory::PropertyType::Line:
55
0
            ::chart::PropertyMapper::getValueMap( aValueMap, aLineNameMap, xProp );
56
0
            break;
57
0
    }
58
59
0
    ::chart::PropertyMapper::getMultiPropertyListsFromValueMap( rNames, rValues, aValueMap );
60
61
0
    uno::Any* pLineWidthAny = ::chart::PropertyMapper::getValuePointer(rValues,rNames,u"LineWidth");
62
0
    sal_Int32 nLineWidth = 0;
63
0
    if( pLineWidthAny && (*pLineWidthAny>>=nLineWidth) )
64
0
    {
65
        // use legend entry height as upper limit for line width
66
0
        sal_Int32 nMaxLineWidthForLegend = aMaxSymbolExtent.Height;
67
0
        if( nLineWidth>nMaxLineWidthForLegend )
68
0
            *pLineWidthAny <<= nMaxLineWidthForLegend;
69
0
    }
70
0
}
71
72
void lcl_setPropertiesToShape(
73
    const Reference< beans::XPropertySet > & xProp,
74
    const rtl::Reference< SvxShape > & xShape,
75
    ::chart::VLegendSymbolFactory::PropertyType ePropertyType,
76
    const awt::Size& aMaxSymbolExtent)
77
0
{
78
0
    ::chart::tNameSequence aPropNames;
79
0
    ::chart::tAnySequence aPropValues;
80
0
    getPropNamesAndValues( xProp, aPropNames, aPropValues,
81
0
            ePropertyType, aMaxSymbolExtent );
82
83
0
    ::chart::PropertyMapper::setMultiProperties( aPropNames, aPropValues, *xShape );
84
0
}
85
86
} // anonymous namespace
87
88
namespace chart
89
{
90
91
rtl::Reference< SvxShapeGroup > VLegendSymbolFactory::createSymbol(
92
    const awt::Size& rEntryKeyAspectRatio,
93
    const rtl::Reference<SvxShapeGroupAnyD>& rSymbolContainer,
94
    LegendSymbolStyle eStyle,
95
    const Reference< beans::XPropertySet > & xLegendEntryProperties,
96
    PropertyType ePropertyType, const uno::Any& rExplicitSymbol )
97
0
{
98
0
    rtl::Reference< SvxShapeGroup > xResult;
99
100
0
    if( !rSymbolContainer)
101
0
        return xResult;
102
103
0
    xResult = ShapeFactory::createGroup2D( rSymbolContainer );
104
0
    if( ! xResult)
105
0
        return xResult;
106
107
0
    rtl::Reference<SvxShapeGroupAnyD> xResultGroup = xResult;
108
109
    // add an invisible square box to maintain aspect ratio
110
0
    ShapeFactory::createInvisibleRectangle( xResultGroup, rEntryKeyAspectRatio );
111
112
    // create symbol
113
0
    try
114
0
    {
115
0
        if( eStyle == LegendSymbolStyle::Line )
116
0
        {
117
0
            rtl::Reference<SvxShapePolyPolygon> xLine =
118
0
                ShapeFactory::createLine( xResultGroup, awt::Size( rEntryKeyAspectRatio.Width, 0 ),
119
0
                        awt::Point( 0, rEntryKeyAspectRatio.Height/2 ));
120
0
            lcl_setPropertiesToShape( xLegendEntryProperties, xLine, ePropertyType, rEntryKeyAspectRatio );
121
122
0
            const sal_Int32 nSize = std::min(rEntryKeyAspectRatio.Width,rEntryKeyAspectRatio.Height);
123
0
            chart2::Symbol aSymbol;
124
0
            if( rExplicitSymbol >>= aSymbol )
125
0
            {
126
0
                drawing::Direction3D aSymbolSize( nSize, nSize, 0 );
127
0
                drawing::Position3D aPos( rEntryKeyAspectRatio.Width/2.0, rEntryKeyAspectRatio.Height/2.0, 0 );
128
0
                if( aSymbol.Style == chart2::SymbolStyle_STANDARD )
129
0
                {
130
                    // take series color as fill color
131
0
                    xLegendEntryProperties->getPropertyValue( u"Color"_ustr) >>= aSymbol.FillColor;
132
                    // border of symbols always same as fill color
133
0
                    aSymbol.BorderColor = aSymbol.FillColor;
134
135
0
                    ShapeFactory::createSymbol2D(
136
0
                                     xResultGroup,
137
0
                                     aPos,
138
0
                                     aSymbolSize,
139
0
                                     aSymbol.StandardSymbol,
140
0
                                     aSymbol.BorderColor,
141
0
                                     aSymbol.FillColor );
142
0
                }
143
0
                else if( aSymbol.Style == chart2::SymbolStyle_GRAPHIC )
144
0
                {
145
0
                    ShapeFactory::createGraphic2D(
146
0
                                     xResultGroup,
147
0
                                     aPos,
148
0
                                     aSymbolSize,
149
0
                                     aSymbol.Graphic );
150
0
                }
151
0
                else if( aSymbol.Style == chart2::SymbolStyle_AUTO )
152
0
                {
153
0
                    SAL_WARN("chart2", "the given parameter is not allowed to contain an automatic symbol style");
154
0
                }
155
0
            }
156
0
        }
157
0
        else if( eStyle == LegendSymbolStyle::Circle )
158
0
        {
159
0
            sal_Int32 nSize = std::min( rEntryKeyAspectRatio.Width, rEntryKeyAspectRatio.Height );
160
0
            rtl::Reference<SvxShapeCircle> xShape =
161
0
                ShapeFactory::createCircle( xResultGroup, awt::Size( nSize, nSize ),
162
0
                        awt::Point( rEntryKeyAspectRatio.Width/2-nSize/2, rEntryKeyAspectRatio.Height/2-nSize/2 ));
163
0
            lcl_setPropertiesToShape( xLegendEntryProperties, xShape, ePropertyType, awt::Size(0,0) ); // PropertyType::FilledSeries );
164
0
        }
165
0
        else // eStyle == LegendSymbolStyle::Box
166
0
        {
167
0
            tNameSequence aPropNames;
168
0
            tAnySequence aPropValues;
169
170
0
            getPropNamesAndValues( xLegendEntryProperties, aPropNames, aPropValues,
171
0
                    ePropertyType, awt::Size(0,0) );// PropertyType::FilledSeries
172
173
0
            ShapeFactory::createRectangle( xResultGroup,
174
0
                        rEntryKeyAspectRatio, awt::Point( 0, 0 ),
175
0
                        aPropNames, aPropValues );
176
0
        }
177
0
    }
178
0
    catch( const uno::Exception & )
179
0
    {
180
0
        DBG_UNHANDLED_EXCEPTION("chart2");
181
0
    }
182
183
0
    return xResult;
184
0
}
185
186
} //  namespace chart
187
188
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */