Avoid potential negative array index access to cached text.
[LibreOffice.git] / chart2 / source / inc / CommonConverters.hxx
blobc6dc7b2ecd1d127ab6588fb93d7b587381b43966
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #pragma once
21 #include <com/sun/star/awt/Point.hpp>
22 #include <com/sun/star/awt/Size.hpp>
23 #include <com/sun/star/drawing/Direction3D.hpp>
24 #include <com/sun/star/drawing/HomogenMatrix.hpp>
25 #include <com/sun/star/drawing/HomogenMatrix3.hpp>
26 #include <com/sun/star/drawing/PointSequenceSequence.hpp>
27 #include <com/sun/star/drawing/Position3D.hpp>
28 #include <com/sun/star/drawing/PolyPolygonShape3D.hpp>
29 #include <basegfx/matrix/b2dhommatrix.hxx>
30 #include <basegfx/point/b3dpoint.hxx>
31 #include <basegfx/vector/b3dvector.hxx>
32 #include <basegfx/polygon/b2dpolypolygon.hxx>
33 #include "charttoolsdllapi.hxx"
35 namespace com::sun::star::awt { struct Rectangle; }
36 namespace com::sun::star::chart2::data { class XDataSequence; }
37 namespace com::sun::star::drawing { struct PolyPolygonBezierCoords; }
39 namespace chart
42 /**
43 diverse methods for class conversions; e.g. ::basegfx::B3DHomMatrix to HomogenMatrix
44 and operations e.g drawing::Position3D + drawing::Direction3D
47 /** ::basegfx::B3DHomMatrix -> HomogenMatrix
49 OOO_DLLPUBLIC_CHARTTOOLS css::drawing::HomogenMatrix
50 B3DHomMatrixToHomogenMatrix( const ::basegfx::B3DHomMatrix& rM );
52 /** HomogenMatrix -> ::basegfx::B3DHomMatrix
54 OOO_DLLPUBLIC_CHARTTOOLS ::basegfx::B3DHomMatrix HomogenMatrixToB3DHomMatrix( const css::drawing::HomogenMatrix& rHM );
56 /** ::basegfx::B3DHomMatrix -> B2DHomMatrix
58 OOO_DLLPUBLIC_CHARTTOOLS
59 ::basegfx::B2DHomMatrix IgnoreZ( const ::basegfx::B3DHomMatrix& rM );
61 /** B2DHomMatrix <-> HomogenMatrix3
63 OOO_DLLPUBLIC_CHARTTOOLS css::drawing::HomogenMatrix3
64 B2DHomMatrixToHomogenMatrix3( const ::basegfx::B2DHomMatrix& rM );
66 /** Position3D -> B3DPoint
68 OOO_DLLPUBLIC_CHARTTOOLS ::basegfx::B3DPoint Position3DToB3DPoint( const css::drawing::Position3D& rPosition );
70 /** B3DVector -> Direction3D
72 OOO_DLLPUBLIC_CHARTTOOLS css::drawing::Direction3D B3DVectorToDirection3D( const ::basegfx::B3DVector& rVector);
74 /** B3DPoint -> Position3D
76 OOO_DLLPUBLIC_CHARTTOOLS css::drawing::Position3D B3DPointToPosition3D( const ::basegfx::B3DPoint& rPoint);
78 /** Direction3D -> B3DVector
80 OOO_DLLPUBLIC_CHARTTOOLS ::basegfx::B3DVector Direction3DToB3DVector( const css::drawing::Direction3D& rDirection);
82 /** PolyPolygonShape3D + drawing::Position3D -> PolyPolygonShape3D
84 OOO_DLLPUBLIC_CHARTTOOLS
85 void AddPointToPoly( css::drawing::PolyPolygonShape3D& rPoly
86 , const css::drawing::Position3D& rPos
87 , sal_Int32 nSequenceIndex=0 );
88 OOO_DLLPUBLIC_CHARTTOOLS
89 void AddPointToPoly( std::vector<std::vector<css::drawing::Position3D>>& rPoly
90 , const css::drawing::Position3D& rPos
91 , sal_Int32 nSequenceIndex=0 );
93 /** get a single Point from a Polygon
95 OOO_DLLPUBLIC_CHARTTOOLS css::drawing::Position3D getPointFromPoly(
96 const std::vector<std::vector<css::drawing::Position3D>>& rPolygon
97 , sal_Int32 nPointIndex, sal_Int32 nPolyIndex );
98 OOO_DLLPUBLIC_CHARTTOOLS css::drawing::Position3D getPointFromPoly(
99 const css::drawing::PolyPolygonShape3D& rPolygon
100 , sal_Int32 nPointIndex, sal_Int32 nPolyIndex );
102 OOO_DLLPUBLIC_CHARTTOOLS
103 void addPolygon( std::vector<std::vector<css::drawing::Position3D>>& rRet
104 , const std::vector<std::vector<css::drawing::Position3D>>& rAdd );
105 /** PolyPolygonShape3D + PolyPolygonShape3D -> PolyPolygonShape3D
107 OOO_DLLPUBLIC_CHARTTOOLS
108 void appendPoly( std::vector<std::vector<css::drawing::Position3D>>& rRet
109 , const std::vector<std::vector<css::drawing::Position3D>>& rAdd );
111 /** PolyPolygonBezierCoords -> PolyPolygonShape3D
113 OOO_DLLPUBLIC_CHARTTOOLS
114 css::drawing::PolyPolygonShape3D BezierToPoly(
115 const css::drawing::PolyPolygonBezierCoords& rBezier );
117 /** PolyPolygonShape3D -> drawing::PointSequenceSequence (2D)
119 OOO_DLLPUBLIC_CHARTTOOLS
120 css::drawing::PointSequenceSequence PolyToPointSequence(
121 const css::drawing::PolyPolygonShape3D& rPolyPolygon );
122 OOO_DLLPUBLIC_CHARTTOOLS
123 css::drawing::PointSequenceSequence PolyToPointSequence(
124 const std::vector<std::vector<css::drawing::Position3D>>& rPolyPolygon );
126 /** PolyPolygonShape3D -> basegfx::B2DPolyPolygon (2D)
128 OOO_DLLPUBLIC_CHARTTOOLS
129 basegfx::B2DPolyPolygon PolyToB2DPolyPolygon(
130 const std::vector<std::vector<css::drawing::Position3D>>& rPolyPolygon );
132 /** drawing::PointSequenceSequence + drawing::PointSequenceSequence
134 OOO_DLLPUBLIC_CHARTTOOLS
135 void appendPointSequence( css::drawing::PointSequenceSequence& rTarget
136 , const css::drawing::PointSequenceSequence& rAdd );
138 /** Position3D + Direction3D == Position3D
140 OOO_DLLPUBLIC_CHARTTOOLS css::drawing::Position3D
141 operator+( const css::drawing::Position3D& rPos
142 , const css::drawing::Direction3D& rDirection);
144 /** Position3D - Position3D == Direction3D
146 OOO_DLLPUBLIC_CHARTTOOLS css::drawing::Direction3D
147 operator-( const css::drawing::Position3D& rPos1
148 , const css::drawing::Position3D& rPos2);
150 /** awt::Rect --> awt::Point (2D)
152 OOO_DLLPUBLIC_CHARTTOOLS css::awt::Point ToPoint( const css::awt::Rectangle& rRectangle );
154 /** awt::Rect --> awt::Size (2D)
156 OOO_DLLPUBLIC_CHARTTOOLS css::awt::Size ToSize( const css::awt::Rectangle& rRectangle );
158 /** Position3D --> awt::Point (2D)
160 OOO_DLLPUBLIC_CHARTTOOLS css::awt::Point Position3DToAWTPoint( const css::drawing::Position3D& rPos );
162 /** Direction3D --> awt::Size (2D)
164 OOO_DLLPUBLIC_CHARTTOOLS css::awt::Size Direction3DToAWTSize( const css::drawing::Direction3D& rDirection );
166 /** Sequence<double> -> drawing::Position3D
168 OOO_DLLPUBLIC_CHARTTOOLS css::drawing::Position3D
169 SequenceToPosition3D( const css::uno::Sequence< double >& rSeq );
171 /** chart2::XDataSequence -> uno::Sequence< double >
174 OOO_DLLPUBLIC_CHARTTOOLS
175 css::uno::Sequence< double > DataSequenceToDoubleSequence(
176 const css::uno::Reference< css::chart2::data::XDataSequence > & xDataSequence );
178 OOO_DLLPUBLIC_CHARTTOOLS
179 css::uno::Sequence< OUString > DataSequenceToStringSequence(
180 const css::uno::Reference< css::chart2::data::XDataSequence > & xDataSequence );
182 /** std::vector< std::vector< T > > -> std::vector< T >
184 template< typename T >
185 std::vector< T >
186 FlattenSequence( const std::vector< std::vector< T > > & aSeqSeq )
188 sal_Int32 nOuter, nInner, nCount = 0,
189 nResultSize = 0;
190 const sal_Int32 nOuterSize = aSeqSeq.size();
191 for( nOuter=0; nOuter<nOuterSize; ++nOuter )
192 nResultSize += aSeqSeq[nOuter].size();
193 std::vector< T > aResult( nResultSize );
195 for( nOuter=0; nOuter<nOuterSize; ++nOuter )
197 const sal_Int32 nInnerSize = aSeqSeq[nOuter].size();
198 for( nInner=0; nInner<nInnerSize; ++nInner, ++nCount )
199 aResult[nCount] = aSeqSeq[nOuter][nInner];
201 return aResult;
204 OOO_DLLPUBLIC_CHARTTOOLS
205 bool hasDoubleValue( const css::uno::Any& rAny );
207 OOO_DLLPUBLIC_CHARTTOOLS
208 bool hasLongOrShortValue( const css::uno::Any& rAny );
209 OOO_DLLPUBLIC_CHARTTOOLS
210 sal_Int16 getShortForLongAlso( const css::uno::Any& rAny );
212 OOO_DLLPUBLIC_CHARTTOOLS
213 bool replaceParamterInString( OUString & rInOutResourceString,
214 std::u16string_view rParamToReplace,
215 std::u16string_view rReplaceWith );
217 } //namespace chart
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */