Coverage Report

Created: 2026-11-06 11:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/chart2/source/tools/CommonConverters.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 <CommonConverters.hxx>
21
#include <com/sun/star/awt/Rectangle.hpp>
22
#include <com/sun/star/drawing/DoubleSequence.hpp>
23
#include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
24
#include <com/sun/star/chart2/data/XDataSequence.hpp>
25
#include <com/sun/star/chart2/data/XNumericalDataSequence.hpp>
26
#include <com/sun/star/chart2/data/XTextualDataSequence.hpp>
27
#include <o3tl/safeint.hxx>
28
#include <osl/diagnose.h>
29
#include <basegfx/matrix/b3dhommatrix.hxx>
30
#include <basegfx/polygon/b2dpolygontools.hxx>
31
32
#include <cstddef>
33
#include <limits>
34
35
namespace chart
36
{
37
38
using namespace ::com::sun::star;
39
40
//  diverse methods for class conversions; e.g. ::basegfx::B3DHomMatrix to HomogenMatrix
41
42
drawing::HomogenMatrix B3DHomMatrixToHomogenMatrix( const ::basegfx::B3DHomMatrix& rM )
43
0
{
44
0
    drawing::HomogenMatrix aHM;
45
0
    aHM.Line1.Column1 = rM.get(0, 0);
46
0
    aHM.Line1.Column2 = rM.get(0, 1);
47
0
    aHM.Line1.Column3 = rM.get(0, 2);
48
0
    aHM.Line1.Column4 = rM.get(0, 3);
49
0
    aHM.Line2.Column1 = rM.get(1, 0);
50
0
    aHM.Line2.Column2 = rM.get(1, 1);
51
0
    aHM.Line2.Column3 = rM.get(1, 2);
52
0
    aHM.Line2.Column4 = rM.get(1, 3);
53
0
    aHM.Line3.Column1 = rM.get(2, 0);
54
0
    aHM.Line3.Column2 = rM.get(2, 1);
55
0
    aHM.Line3.Column3 = rM.get(2, 2);
56
0
    aHM.Line3.Column4 = rM.get(2, 3);
57
0
    aHM.Line4.Column1 = rM.get(3, 0);
58
0
    aHM.Line4.Column2 = rM.get(3, 1);
59
0
    aHM.Line4.Column3 = rM.get(3, 2);
60
0
    aHM.Line4.Column4 = rM.get(3, 3);
61
0
    return aHM;
62
0
}
63
64
::basegfx::B3DHomMatrix HomogenMatrixToB3DHomMatrix( const drawing::HomogenMatrix& rHM )
65
0
{
66
0
    ::basegfx::B3DHomMatrix aM;
67
0
    aM.set(0, 0, rHM.Line1.Column1);
68
0
    aM.set(0, 1, rHM.Line1.Column2);
69
0
    aM.set(0, 2, rHM.Line1.Column3);
70
0
    aM.set(0, 3, rHM.Line1.Column4);
71
0
    aM.set(1, 0, rHM.Line2.Column1);
72
0
    aM.set(1, 1, rHM.Line2.Column2);
73
0
    aM.set(1, 2, rHM.Line2.Column3);
74
0
    aM.set(1, 3, rHM.Line2.Column4);
75
0
    aM.set(2, 0, rHM.Line3.Column1);
76
0
    aM.set(2, 1, rHM.Line3.Column2);
77
0
    aM.set(2, 2, rHM.Line3.Column3);
78
0
    aM.set(2, 3, rHM.Line3.Column4);
79
0
    aM.set(3, 0, rHM.Line4.Column1);
80
0
    aM.set(3, 1, rHM.Line4.Column2);
81
0
    aM.set(3, 2, rHM.Line4.Column3);
82
0
    aM.set(3, 3, rHM.Line4.Column4);
83
0
    return aM;
84
0
}
85
86
::basegfx::B2DHomMatrix IgnoreZ( const ::basegfx::B3DHomMatrix& rM )
87
0
{
88
0
    ::basegfx::B2DHomMatrix aM;
89
0
    aM.set(0, 0, rM.get(0, 0));
90
0
    aM.set(0, 1, rM.get(0, 1));
91
0
    aM.set(0, 2, rM.get(0, 3));
92
0
    aM.set(1, 0, rM.get(1, 0));
93
0
    aM.set(1, 1, rM.get(1, 1));
94
0
    aM.set(1, 2, rM.get(1, 3));
95
    // For this to be a valid 2D transform matrix, the last row must be [0,0,1]
96
0
    assert( rM.get(3, 0) == 0 );
97
0
    assert( rM.get(3, 1) == 0 );
98
0
    assert( rM.get(3, 3) == 1 );
99
0
    return aM;
100
0
}
101
102
drawing::HomogenMatrix3 B2DHomMatrixToHomogenMatrix3( const ::basegfx::B2DHomMatrix& rM )
103
0
{
104
0
    drawing::HomogenMatrix3 aHM;
105
0
    aHM.Line1.Column1 = rM.get(0, 0);
106
0
    aHM.Line1.Column2 = rM.get(0, 1);
107
0
    aHM.Line1.Column3 = rM.get(0, 2);
108
0
    aHM.Line2.Column1 = rM.get(1, 0);
109
0
    aHM.Line2.Column2 = rM.get(1, 1);
110
0
    aHM.Line2.Column3 = rM.get(1, 2);
111
0
    aHM.Line3.Column1 = 0;
112
0
    aHM.Line3.Column2 = 0;
113
0
    aHM.Line3.Column3 = 1;
114
0
    return aHM;
115
0
}
116
117
::basegfx::B3DPoint Position3DToB3DPoint( const drawing::Position3D& rPosition )
118
0
{
119
0
    return ::basegfx::B3DPoint(
120
0
        rPosition.PositionX ,
121
0
        rPosition.PositionY ,
122
0
        rPosition.PositionZ );
123
0
}
124
125
drawing::Direction3D B3DVectorToDirection3D( const ::basegfx::B3DVector& rVector)
126
0
{
127
0
    return drawing::Direction3D(
128
0
          rVector.getX()
129
0
        , rVector.getY()
130
0
        , rVector.getZ()
131
0
        );
132
0
}
133
134
drawing::Position3D B3DPointToPosition3D( const ::basegfx::B3DPoint& rPoint)
135
0
{
136
0
        return drawing::Position3D(
137
0
          rPoint.getX()
138
0
        , rPoint.getY()
139
0
        , rPoint.getZ()
140
0
        );
141
0
}
142
143
::basegfx::B3DVector Direction3DToB3DVector( const drawing::Direction3D& rDirection)
144
0
{
145
0
    return ::basegfx::B3DVector(
146
0
          rDirection.DirectionX
147
0
        , rDirection.DirectionY
148
0
        , rDirection.DirectionZ
149
0
        );
150
0
}
151
152
void AddPointToPoly( drawing::PolyPolygonShape3D& rPoly, const drawing::Position3D& rPos, sal_Int32 nPolygonIndex )
153
0
{
154
0
    if(nPolygonIndex<0)
155
0
    {
156
0
        OSL_FAIL( "The polygon index needs to be > 0");
157
0
        nPolygonIndex=0;
158
0
    }
159
160
    //make sure that we have enough polygons
161
0
    if(nPolygonIndex >= rPoly.SequenceX.getLength() )
162
0
    {
163
0
        rPoly.SequenceX.realloc(nPolygonIndex+1);
164
0
        rPoly.SequenceY.realloc(nPolygonIndex+1);
165
0
        rPoly.SequenceZ.realloc(nPolygonIndex+1);
166
0
    }
167
168
0
    drawing::DoubleSequence* pOuterSequenceX = &rPoly.SequenceX.getArray()[nPolygonIndex];
169
0
    drawing::DoubleSequence* pOuterSequenceY = &rPoly.SequenceY.getArray()[nPolygonIndex];
170
0
    drawing::DoubleSequence* pOuterSequenceZ = &rPoly.SequenceZ.getArray()[nPolygonIndex];
171
172
0
    sal_Int32 nOldPointCount = pOuterSequenceX->getLength();
173
174
0
    pOuterSequenceX->realloc(nOldPointCount+1);
175
0
    pOuterSequenceY->realloc(nOldPointCount+1);
176
0
    pOuterSequenceZ->realloc(nOldPointCount+1);
177
178
0
    double* pInnerSequenceX = pOuterSequenceX->getArray();
179
0
    double* pInnerSequenceY = pOuterSequenceY->getArray();
180
0
    double* pInnerSequenceZ = pOuterSequenceZ->getArray();
181
182
0
    pInnerSequenceX[nOldPointCount] = rPos.PositionX;
183
0
    pInnerSequenceY[nOldPointCount] = rPos.PositionY;
184
0
    pInnerSequenceZ[nOldPointCount] = rPos.PositionZ;
185
0
}
186
187
void AddPointToPoly( std::vector<std::vector<css::drawing::Position3D>>& rPoly, const drawing::Position3D& rPos, sal_Int32 nPolygonIndex )
188
0
{
189
0
    if(nPolygonIndex<0)
190
0
    {
191
0
        OSL_FAIL( "The polygon index needs to be > 0");
192
0
        nPolygonIndex=0;
193
0
    }
194
195
    //make sure that we have enough polygons
196
0
    if(o3tl::make_unsigned(nPolygonIndex) >= rPoly.size() )
197
0
    {
198
0
        rPoly.resize(nPolygonIndex+1);
199
0
    }
200
201
0
    std::vector<css::drawing::Position3D>* pOuterSequence = &rPoly[nPolygonIndex];
202
0
    pOuterSequence->push_back(rPos);
203
0
}
204
205
drawing::Position3D getPointFromPoly( const drawing::PolyPolygonShape3D& rPolygon, sal_Int32 nPointIndex, sal_Int32 nPolyIndex )
206
0
{
207
0
    drawing::Position3D aRet(0.0,0.0,0.0);
208
209
0
    if( nPolyIndex>=0 && nPolyIndex<rPolygon.SequenceX.getLength())
210
0
    {
211
0
        if(nPointIndex<rPolygon.SequenceX[nPolyIndex].getLength())
212
0
        {
213
0
            aRet.PositionX = rPolygon.SequenceX[nPolyIndex][nPointIndex];
214
0
            aRet.PositionY = rPolygon.SequenceY[nPolyIndex][nPointIndex];
215
0
            aRet.PositionZ = rPolygon.SequenceZ[nPolyIndex][nPointIndex];
216
0
        }
217
0
        else
218
0
        {
219
0
            OSL_FAIL("polygon was accessed with a wrong index");
220
0
        }
221
0
    }
222
0
    else
223
0
    {
224
0
        OSL_FAIL("polygon was accessed with a wrong index");
225
0
    }
226
0
    return aRet;
227
0
}
228
229
drawing::Position3D getPointFromPoly( const std::vector<std::vector<css::drawing::Position3D>>& rPolygon, sal_Int32 nPointIndex, sal_Int32 nPolyIndex )
230
0
{
231
0
    drawing::Position3D aRet(0.0,0.0,0.0);
232
233
0
    if( nPolyIndex>=0 && o3tl::make_unsigned(nPolyIndex)<rPolygon.size())
234
0
    {
235
0
        if(nPointIndex<static_cast<sal_Int32>(rPolygon[nPolyIndex].size()))
236
0
        {
237
0
            aRet = rPolygon[nPolyIndex][nPointIndex];
238
0
        }
239
0
        else
240
0
        {
241
0
            OSL_FAIL("polygon was accessed with a wrong index");
242
0
        }
243
0
    }
244
0
    else
245
0
    {
246
0
        OSL_FAIL("polygon was accessed with a wrong index");
247
0
    }
248
0
    return aRet;
249
0
}
250
251
void addPolygon( std::vector<std::vector<css::drawing::Position3D>>& rRet, const std::vector<std::vector<css::drawing::Position3D>>& rAdd )
252
0
{
253
0
    sal_Int32 nAddOuterCount = rAdd.size();
254
0
    sal_Int32 nOuterCount = rRet.size() + nAddOuterCount;
255
0
    rRet.resize( nOuterCount );
256
0
    auto pSequence = rRet.data();
257
258
0
    sal_Int32 nIndex = 0;
259
0
    sal_Int32 nOuter = nOuterCount - nAddOuterCount;
260
0
    for( ; nOuter < nOuterCount; nOuter++ )
261
0
    {
262
0
        if( nIndex >= nAddOuterCount )
263
0
            break;
264
265
0
        pSequence[nOuter] = rAdd[nIndex];
266
267
0
        nIndex++;
268
0
    }
269
0
}
270
271
void appendPoly( std::vector<std::vector<css::drawing::Position3D>>& rRet, const std::vector<std::vector<css::drawing::Position3D>>& rAdd )
272
0
{
273
0
    std::size_t nOuterCount = std::max( rRet.size(), rAdd.size() );
274
0
    rRet.resize(nOuterCount);
275
0
    auto pSequence = rRet.data();
276
277
0
    for( std::size_t nOuter=0;nOuter<nOuterCount;nOuter++ )
278
0
    {
279
0
        sal_Int32 nOldPointCount = rRet[nOuter].size();
280
0
        sal_Int32 nAddPointCount = 0;
281
0
        if(nOuter<rAdd.size())
282
0
            nAddPointCount = rAdd[nOuter].size();
283
0
        if(!nAddPointCount)
284
0
            continue;
285
286
0
        sal_Int32 nNewPointCount = nOldPointCount + nAddPointCount;
287
288
0
        pSequence[nOuter].resize(nNewPointCount);
289
0
        auto pSequence_nOuter = pSequence[nOuter].data();
290
291
0
        sal_Int32 nPointTarget=nOldPointCount;
292
0
        sal_Int32 nPointSource=nAddPointCount;
293
0
        for( ; nPointSource-- ; nPointTarget++ )
294
0
        {
295
0
            pSequence_nOuter[nPointTarget] = rAdd[nOuter][nPointSource];
296
0
        }
297
0
    }
298
0
}
299
300
drawing::PolyPolygonShape3D BezierToPoly(
301
    const drawing::PolyPolygonBezierCoords& rBezier )
302
0
{
303
0
    const drawing::PointSequenceSequence& rPointSequence = rBezier.Coordinates;
304
305
0
    drawing::PolyPolygonShape3D aRet;
306
0
    aRet.SequenceX.realloc( rPointSequence.getLength() );
307
0
    auto pSequenceX = aRet.SequenceX.getArray();
308
0
    aRet.SequenceY.realloc( rPointSequence.getLength() );
309
0
    auto pSequenceY = aRet.SequenceY.getArray();
310
0
    aRet.SequenceZ.realloc( rPointSequence.getLength() );
311
0
    auto pSequenceZ = aRet.SequenceZ.getArray();
312
313
0
    sal_Int32 nRealOuter = 0;
314
0
    for(sal_Int32 nN = 0; nN < rPointSequence.getLength(); nN++)
315
0
    {
316
0
        sal_Int32 nInnerLength = rPointSequence[nN].getLength();
317
0
        pSequenceX[nRealOuter].realloc( nInnerLength );
318
0
        auto pSequenceX_nRealOuter = pSequenceX[nRealOuter].getArray();
319
0
        pSequenceY[nRealOuter].realloc( nInnerLength );
320
0
        auto pSequenceY_nRealOuter = pSequenceY[nRealOuter].getArray();
321
0
        pSequenceZ[nRealOuter].realloc( nInnerLength );
322
0
        auto pSequenceZ_nRealOuter = pSequenceZ[nRealOuter].getArray();
323
324
0
        bool bHasOuterFlags = nN < rBezier.Flags.getLength();
325
326
0
        sal_Int32 nRealInner = 0;
327
0
        for( sal_Int32 nM = 0; nM < nInnerLength; nM++)
328
0
        {
329
0
            bool bHasInnerFlags = bHasOuterFlags && (nM < rBezier.Flags[nN].getLength());
330
331
0
            if( !bHasInnerFlags || (rBezier.Flags[nN][nM] == drawing::PolygonFlags_NORMAL) )
332
0
            {
333
0
                pSequenceX_nRealOuter[nRealInner] = rPointSequence[nN][nM].X;
334
0
                pSequenceY_nRealOuter[nRealInner] = rPointSequence[nN][nM].Y;
335
0
                pSequenceZ_nRealOuter[nRealInner] = 0.0;
336
0
                nRealInner++;
337
0
            }
338
0
        }
339
340
0
        pSequenceX[nRealOuter].realloc( nRealInner );
341
0
        pSequenceY[nRealOuter].realloc( nRealInner );
342
0
        pSequenceZ[nRealOuter].realloc( nRealInner );
343
344
0
        if( nRealInner>0 )
345
0
            nRealOuter++;
346
0
    }
347
348
0
    aRet.SequenceX.realloc( nRealOuter );
349
0
    aRet.SequenceY.realloc( nRealOuter );
350
0
    aRet.SequenceZ.realloc( nRealOuter );
351
352
0
    return aRet;
353
0
}
354
355
drawing::PointSequenceSequence PolyToPointSequence(
356
                const drawing::PolyPolygonShape3D& rPolyPolygon )
357
0
{
358
0
    drawing::PointSequenceSequence aRet;
359
0
    aRet.realloc( rPolyPolygon.SequenceX.getLength() );
360
0
    auto pRet = aRet.getArray();
361
362
0
    for(sal_Int32 nN = 0; nN < rPolyPolygon.SequenceX.getLength(); nN++)
363
0
    {
364
0
        sal_Int32 nInnerLength = rPolyPolygon.SequenceX[nN].getLength();
365
0
        pRet[nN].realloc( nInnerLength );
366
0
        auto pRet_nN = pRet[nN].getArray();
367
0
        for( sal_Int32 nM = 0; nM < nInnerLength; nM++)
368
0
        {
369
0
            pRet_nN[nM].X = static_cast<sal_Int32>(rPolyPolygon.SequenceX[nN][nM]);
370
0
            pRet_nN[nM].Y = static_cast<sal_Int32>(rPolyPolygon.SequenceY[nN][nM]);
371
0
        }
372
0
    }
373
0
    return aRet;
374
0
}
375
376
drawing::PointSequenceSequence PolyToPointSequence(
377
                const std::vector<std::vector<css::drawing::Position3D>>& rPolyPolygon )
378
0
{
379
0
    drawing::PointSequenceSequence aRet;
380
0
    aRet.realloc( rPolyPolygon.size() );
381
0
    auto pRet = aRet.getArray();
382
383
0
    for(std::size_t nN = 0; nN < rPolyPolygon.size(); nN++)
384
0
    {
385
0
        sal_Int32 nInnerLength = rPolyPolygon[nN].size();
386
0
        pRet[nN].realloc( nInnerLength );
387
0
        auto pRet_nN = pRet[nN].getArray();
388
0
        for( sal_Int32 nM = 0; nM < nInnerLength; nM++)
389
0
        {
390
0
            pRet_nN[nM].X = static_cast<sal_Int32>(rPolyPolygon[nN][nM].PositionX);
391
0
            pRet_nN[nM].Y = static_cast<sal_Int32>(rPolyPolygon[nN][nM].PositionY);
392
0
        }
393
0
    }
394
0
    return aRet;
395
0
}
396
397
basegfx::B2DPolyPolygon PolyToB2DPolyPolygon(
398
                const std::vector<std::vector<css::drawing::Position3D>>& rPolyPolygon )
399
0
{
400
0
    basegfx::B2DPolyPolygon aRetval;
401
402
0
    for(auto const & nN: rPolyPolygon)
403
0
    {
404
0
        basegfx::B2DPolygon aNewPolygon;
405
0
        sal_Int32 nInnerLength = nN.size();
406
0
        if(nInnerLength)
407
0
        {
408
0
            aNewPolygon.reserve(nInnerLength);
409
0
            for( sal_Int32 nM = 0; nM < nInnerLength; nM++)
410
0
            {
411
0
                auto X = static_cast<sal_Int32>(nN[nM].PositionX);
412
0
                auto Y = static_cast<sal_Int32>(nN[nM].PositionY);
413
0
                aNewPolygon.append(basegfx::B2DPoint(X, Y));
414
0
            }
415
            // check for closed state flag
416
0
            basegfx::utils::checkClosed(aNewPolygon);
417
0
        }
418
0
        aRetval.append(std::move(aNewPolygon));
419
0
    }
420
421
0
    return aRetval;
422
0
}
423
424
void appendPointSequence( drawing::PointSequenceSequence& rTarget
425
                        , const drawing::PointSequenceSequence& rAdd )
426
0
{
427
0
    sal_Int32 nAddCount = rAdd.getLength();
428
0
    if(!nAddCount)
429
0
        return;
430
0
    sal_Int32 nOldCount = rTarget.getLength();
431
432
0
    rTarget.realloc(nOldCount+nAddCount);
433
0
    auto pTarget = rTarget.getArray();
434
0
    for(sal_Int32 nS=0; nS<nAddCount; nS++ )
435
0
        pTarget[nOldCount+nS]=rAdd[nS];
436
0
}
437
438
drawing::Position3D  operator+( const drawing::Position3D& rPos
439
                           , const drawing::Direction3D& rDirection)
440
0
{
441
0
    return drawing::Position3D(
442
0
          rPos.PositionX + rDirection.DirectionX
443
0
        , rPos.PositionY + rDirection.DirectionY
444
0
        , rPos.PositionZ + rDirection.DirectionZ
445
0
        );
446
0
}
447
448
drawing::Direction3D  operator-( const drawing::Position3D& rPos1
449
                           , const drawing::Position3D& rPos2)
450
0
{
451
0
    return drawing::Direction3D(
452
0
          rPos1.PositionX - rPos2.PositionX
453
0
        , rPos1.PositionY - rPos2.PositionY
454
0
        , rPos1.PositionZ - rPos2.PositionZ
455
0
        );
456
0
}
457
458
awt::Point Position3DToAWTPoint( const drawing::Position3D& rPos )
459
0
{
460
0
    awt::Point aRet;
461
0
    aRet.X = static_cast<sal_Int32>(rPos.PositionX);
462
0
    aRet.Y = static_cast<sal_Int32>(rPos.PositionY);
463
0
    return aRet;
464
0
}
465
466
awt::Point ToPoint( const awt::Rectangle& rRectangle )
467
0
{
468
0
    return awt::Point( rRectangle.X, rRectangle.Y );
469
0
}
470
471
awt::Size ToSize( const awt::Rectangle& rRectangle )
472
0
{
473
0
    return awt::Size( rRectangle.Width, rRectangle.Height );
474
0
}
475
476
awt::Size Direction3DToAWTSize( const drawing::Direction3D& rDirection )
477
0
{
478
0
    awt::Size aRet;
479
0
    aRet.Width = static_cast<sal_Int32>(rDirection.DirectionX);
480
0
    aRet.Height = static_cast<sal_Int32>(rDirection.DirectionY);
481
0
    return aRet;
482
0
}
483
484
drawing::Position3D SequenceToPosition3D( const uno::Sequence< double >& rSeq )
485
0
{
486
0
    OSL_ENSURE(rSeq.getLength()==3,"The sequence needs to have length 3 for conversion into vector");
487
488
0
    drawing::Position3D aRet;
489
0
    aRet.PositionX = rSeq.getLength()>0?rSeq[0]:0.0;
490
0
    aRet.PositionY = rSeq.getLength()>1?rSeq[1]:0.0;
491
0
    aRet.PositionZ = rSeq.getLength()>2?rSeq[2]:0.0;
492
0
    return aRet;
493
0
}
494
495
using namespace ::com::sun::star::chart2;
496
497
uno::Sequence< double > DataSequenceToDoubleSequence(
498
    const uno::Reference< data::XDataSequence >& xDataSequence )
499
0
{
500
0
    uno::Sequence< double > aResult;
501
0
    OSL_ASSERT( xDataSequence.is());
502
0
    if(!xDataSequence.is())
503
0
        return aResult;
504
505
0
    uno::Reference< data::XNumericalDataSequence > xNumericalDataSequence( xDataSequence, uno::UNO_QUERY );
506
0
    if( xNumericalDataSequence.is() )
507
0
    {
508
0
        aResult = xNumericalDataSequence->getNumericalData();
509
0
    }
510
0
    else
511
0
    {
512
0
        uno::Sequence< uno::Any > aValues = xDataSequence->getData();
513
0
        aResult.realloc(aValues.getLength());
514
0
        auto pResult = aResult.getArray();
515
0
        for(sal_Int32 nN=aValues.getLength();nN--;)
516
0
        {
517
0
            if( !(aValues[nN] >>= pResult[nN]) )
518
0
                pResult[nN] = std::numeric_limits<double>::quiet_NaN();
519
0
        }
520
0
    }
521
522
0
    return aResult;
523
0
}
524
525
uno::Sequence< OUString > DataSequenceToStringSequence(
526
    const uno::Reference< data::XDataSequence >& xDataSequence )
527
0
{
528
0
    uno::Sequence< OUString > aResult;
529
0
    if(!xDataSequence.is())
530
0
        return aResult;
531
532
0
    uno::Reference< data::XTextualDataSequence > xTextualDataSequence( xDataSequence, uno::UNO_QUERY );
533
0
    if( xTextualDataSequence.is() )
534
0
    {
535
0
        aResult = xTextualDataSequence->getTextualData();
536
0
    }
537
0
    else
538
0
    {
539
0
        uno::Sequence< uno::Any > aValues = xDataSequence->getData();
540
0
        aResult.realloc(aValues.getLength());
541
0
        auto pResult = aResult.getArray();
542
543
0
        for(sal_Int32 nN=aValues.getLength();nN--;)
544
0
            aValues[nN] >>= pResult[nN];
545
0
    }
546
547
0
    return aResult;
548
0
}
549
550
bool hasDoubleValue( const uno::Any& rAny )
551
0
{
552
0
    bool bRet = false;
553
0
    double fValue = 0.0;
554
0
    if( rAny >>= fValue )
555
0
        bRet = true;
556
0
    return bRet;
557
0
}
558
559
bool hasLongOrShortValue( const uno::Any& rAny )
560
0
{
561
0
    bool bRet = false;
562
0
    sal_Int32 n32 = 0;
563
0
    if( rAny >>= n32 )
564
0
        bRet = true;
565
0
    else
566
0
    {
567
0
        sal_Int16 n16 = 0;
568
0
        if( rAny >>= n16 )
569
0
            bRet = true;
570
0
    }
571
0
    return bRet;
572
0
}
573
sal_Int16 getShortForLongAlso( const uno::Any& rAny )
574
0
{
575
0
    sal_Int16 nRet = 0;
576
577
0
    if( !(rAny >>= nRet) )
578
0
    {
579
0
        sal_Int32 n32 = 0;
580
0
        if( rAny >>= n32 )
581
0
            nRet = static_cast<sal_Int16>(n32);
582
0
    }
583
0
    return nRet;
584
0
}
585
586
bool replaceParamterInString( OUString & rInOutResourceString,
587
                            std::u16string_view rParamToReplace,
588
                            std::u16string_view rReplaceWith )
589
0
{
590
0
    sal_Int32 nPos = rInOutResourceString.indexOf( rParamToReplace );
591
0
    if( nPos == -1 )
592
0
        return false;
593
594
0
    rInOutResourceString = rInOutResourceString.replaceAt( nPos
595
0
                        , rParamToReplace.size(), rReplaceWith );
596
0
    return true;
597
0
}
598
599
} //namespace chart
600
601
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */