24#include <com/sun/star/beans/XPropertySet.hpp>
25#include <com/sun/star/drawing/TextVerticalAdjust.hpp>
26#include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
37 sal_Int32 nDimensionCount
39 : m_nDimensionCount(nDimensionCount)
40 , m_xLogicTarget(
std::move(xLogicTarget))
58 drawing::TextHorizontalAdjust eHorizontalAdjust = drawing::TextHorizontalAdjust_CENTER;
60 eHorizontalAdjust = drawing::TextHorizontalAdjust_LEFT;
62 eHorizontalAdjust = drawing::TextHorizontalAdjust_RIGHT;
64 if(pHorizontalAdjustAny)
65 *pHorizontalAdjustAny <<= eHorizontalAdjust;
70 drawing::TextVerticalAdjust eVerticalAdjust = drawing::TextVerticalAdjust_CENTER;
72 eVerticalAdjust = drawing::TextVerticalAdjust_BOTTOM;
74 eVerticalAdjust = drawing::TextVerticalAdjust_TOP;
76 if(pVerticalAdjustAny)
77 *pVerticalAdjustAny <<= eVerticalAdjust;
82 ,
const awt::Size& rOldReferenceSize
83 ,
const awt::Size& rNewReferenceSize )
85 double fOldFontHeight = 0;
86 if( pAOldAndNewFontHeightAny && ( *pAOldAndNewFontHeightAny >>= fOldFontHeight ) )
89 *pAOldAndNewFontHeightAny <<= fNewFontHeight;
96 ,
const awt::Size& rNewReferenceSize
100 awt::Size aOldReferenceSize;
101 if( xAxisModelProps->getPropertyValue(
"ReferencePageSize") >>= aOldReferenceSize )
115void lcl_correctRotation_Left(
double& rfXCorrection,
double& rfYCorrection
116 ,
double fAnglePositiveDegree,
const awt::Size& aSize,
bool bRotateAroundCenter )
120 if( fAnglePositiveDegree==0.0 )
123 else if( fAnglePositiveDegree<= 90.0 )
125 rfXCorrection = -aSize.Height*std::sin( fAnglePi )/2.0;
126 if( bRotateAroundCenter )
127 rfYCorrection = -aSize.Width*std::sin( fAnglePi )/2.0;
129 else if( fAnglePositiveDegree<= 180.0 )
131 double beta = fAnglePi-M_PI_2;
132 rfXCorrection = -aSize.Width *std::sin( beta )
133 -aSize.Height *std::cos( beta )/2.0;
134 if( bRotateAroundCenter )
135 rfYCorrection = -aSize.Width *std::cos( beta )/2.0;
137 rfYCorrection = -aSize.Width *std::cos( beta );
139 else if( fAnglePositiveDegree<= 270.0 )
141 double beta = fAnglePi - M_PI;
142 rfXCorrection = -aSize.Width *std::cos( beta )
143 -aSize.Height*std::sin( beta )/2.0;
144 if( bRotateAroundCenter )
145 rfYCorrection = aSize.Width *std::sin( beta )/2.0;
147 rfYCorrection = aSize.Width *std::sin( beta );
151 double beta = 2*M_PI - fAnglePi;
152 rfXCorrection = -aSize.Height*std::sin( beta )/2.0;
153 if( bRotateAroundCenter )
154 rfYCorrection = aSize.Width*std::sin( beta )/2.0;
158void lcl_correctRotation_Right(
double& rfXCorrection,
double& rfYCorrection
159 ,
double fAnglePositiveDegree,
const awt::Size& aSize,
bool bRotateAroundCenter )
163 if( fAnglePositiveDegree== 0.0 )
166 else if( fAnglePositiveDegree<= 90.0 )
168 rfXCorrection = aSize.Height*std::sin( fAnglePi )/2.0;
169 if( bRotateAroundCenter )
170 rfYCorrection = aSize.Width*std::sin( fAnglePi )/2.0;
172 else if( fAnglePositiveDegree<= 180.0 )
174 double beta = M_PI - fAnglePi;
175 rfXCorrection = aSize.Width *std::cos( beta )
176 + aSize.Height*std::sin( beta )/2.0;
177 if( bRotateAroundCenter )
178 rfYCorrection = aSize.Width *std::sin( beta )/2.0;
180 rfYCorrection = aSize.Width *std::sin( beta );
182 else if( fAnglePositiveDegree<= 270.0 )
184 double beta = 3*M_PI_2 - fAnglePi;
185 rfXCorrection = aSize.Width *std::sin( beta )
186 +aSize.Height*std::cos( beta )/2.0;
187 if( bRotateAroundCenter )
188 rfYCorrection = -aSize.Width *std::cos( beta )/2.0;
190 rfYCorrection = -aSize.Width *std::cos( beta );
194 rfXCorrection = aSize.Height*std::sin( 2*M_PI - fAnglePi )/2.0;
195 if( bRotateAroundCenter )
196 rfYCorrection = -aSize.Width*std::sin( 2*M_PI - fAnglePi )/2.0;
200void lcl_correctRotation_Top(
double& rfXCorrection,
double& rfYCorrection
201 ,
double fAnglePositiveDegree,
const awt::Size& aSize,
bool bRotateAroundCenter )
205 if( fAnglePositiveDegree== 0.0 )
208 else if( fAnglePositiveDegree<= 90.0 )
210 rfXCorrection = aSize.Height*std::sin( fAnglePi )/2.0;
211 if( !bRotateAroundCenter )
212 rfXCorrection += aSize.Width*std::cos( fAnglePi )/2.0;
213 rfYCorrection = -aSize.Width*std::sin( fAnglePi )/2.0;
215 else if( fAnglePositiveDegree<= 180.0 )
217 double beta = fAnglePi - M_PI_2;
218 rfXCorrection = aSize.Height*std::cos( beta )/2.0;
219 if( !bRotateAroundCenter )
220 rfXCorrection -= aSize.Width*std::sin( beta )/2.0;
221 rfYCorrection = -aSize.Width*std::cos( beta )/2.0
222 - aSize.Height*std::sin( beta );
224 else if( fAnglePositiveDegree<= 270.0 )
226 double beta = fAnglePi - M_PI;
227 rfXCorrection = -aSize.Height *std::sin( beta )/2.0;
228 if( !bRotateAroundCenter )
229 rfXCorrection += aSize.Width *std::cos( beta )/2.0;
230 rfYCorrection = -aSize.Width *std::sin( beta )/2.0
231 -aSize.Height *std::cos( beta );
235 rfXCorrection = aSize.Height*std::sin( fAnglePi )/2.0;
236 if( !bRotateAroundCenter )
237 rfXCorrection -= aSize.Width*std::cos( fAnglePi )/2.0;
238 rfYCorrection = aSize.Width*std::sin( fAnglePi )/2.0;
242void lcl_correctRotation_Bottom(
double& rfXCorrection,
double& rfYCorrection
243 ,
double fAnglePositiveDegree,
const awt::Size& aSize,
bool bRotateAroundCenter )
247 if( fAnglePositiveDegree==0.0 )
250 else if( fAnglePositiveDegree<= 90.0 )
252 rfXCorrection = -aSize.Height*std::sin( fAnglePi )/2.0;
253 if( !bRotateAroundCenter )
254 rfXCorrection -= aSize.Width *std::cos( fAnglePi )/2.0;
255 rfYCorrection = aSize.Width*std::sin( fAnglePi )/2.0;
257 else if( fAnglePositiveDegree<= 180.0 )
259 double beta = fAnglePi-M_PI_2;
260 rfXCorrection = -aSize.Height*std::cos( beta )/2.0;
261 if( !bRotateAroundCenter )
262 rfXCorrection += aSize.Width *std::sin( beta )/2.0;
263 rfYCorrection = aSize.Width *std::cos( beta )/2.0
264 +aSize.Height*std::sin( beta );
266 else if( fAnglePositiveDegree<= 270.0 )
268 double beta = 3*M_PI_2 - fAnglePi;
269 rfXCorrection = aSize.Height*std::cos( beta )/2.0;
270 if( !bRotateAroundCenter )
271 rfXCorrection -= aSize.Width *std::sin( beta )/2.0;
272 rfYCorrection = aSize.Height*std::sin( beta )
273 +aSize.Width*std::cos( beta )/2.0;
277 double beta = 2*M_PI - fAnglePi;
278 rfXCorrection = aSize.Height*std::sin( beta )/2.0;
279 if( !bRotateAroundCenter )
280 rfXCorrection += aSize.Width*std::cos( beta )/2.0;
281 rfYCorrection = aSize.Width*std::sin( beta )/2.0;
285void lcl_correctRotation_Left_Top(
double& rfXCorrection,
double& rfYCorrection
286 ,
double fAnglePositiveDegree,
const awt::Size& aSize )
290 if( fAnglePositiveDegree==0.0 )
293 else if( fAnglePositiveDegree<= 90.0 )
295 rfYCorrection = -aSize.Width*std::sin( fAnglePi );
297 else if( fAnglePositiveDegree<= 180.0 )
299 double beta = fAnglePi-M_PI_2;
300 rfXCorrection = -aSize.Width*std::sin( beta );
301 rfYCorrection = -aSize.Height*std::sin( beta )
302 -aSize.Width*std::cos( beta );
304 else if( fAnglePositiveDegree<= 270.0 )
306 double beta = 3*M_PI_2 - fAnglePi;
307 rfXCorrection = -aSize.Height*std::cos( beta )
308 -aSize.Width*std::sin( beta );
309 rfYCorrection = -aSize.Height*std::sin( beta );
313 rfXCorrection = aSize.Height*std::sin( fAnglePi );
317void lcl_correctRotation_Left_Bottom(
double& rfXCorrection,
double& rfYCorrection
318 ,
double fAnglePositiveDegree,
const awt::Size& aSize )
322 if( fAnglePositiveDegree==0.0 )
325 else if( fAnglePositiveDegree<= 90.0 )
327 rfXCorrection = -aSize.Height*std::sin( fAnglePi );
329 else if( fAnglePositiveDegree<= 180.0 )
331 double beta = fAnglePi-M_PI_2;
332 rfXCorrection = -aSize.Width*std::sin( beta )
333 -aSize.Height*std::cos( beta );
334 rfYCorrection = aSize.Height*std::sin( beta );
336 else if( fAnglePositiveDegree<= 270.0 )
338 double beta = 3*M_PI_2 - fAnglePi;
339 rfXCorrection = -aSize.Width*std::sin( beta );
340 rfYCorrection = aSize.Width*std::cos( beta )
341 +aSize.Height*std::sin( beta );
345 rfYCorrection = -aSize.Width*std::sin( fAnglePi );
349void lcl_correctRotation_Right_Top(
double& rfXCorrection,
double& rfYCorrection
350 ,
double fAnglePositiveDegree,
const awt::Size& aSize )
354 if( fAnglePositiveDegree==0.0 )
357 else if( fAnglePositiveDegree<= 90.0 )
359 rfXCorrection = aSize.Height*std::sin( fAnglePi );
361 else if( fAnglePositiveDegree<= 180.0 )
363 double beta = fAnglePi-M_PI_2;
364 rfXCorrection = aSize.Width*std::sin( beta )
365 +aSize.Height*std::cos( beta );
366 rfYCorrection = -aSize.Height*std::sin( beta );
368 else if( fAnglePositiveDegree<= 270.0 )
370 double beta = 3*M_PI_2 - fAnglePi;
371 rfXCorrection = aSize.Width*std::sin( beta );
372 rfYCorrection = -aSize.Width*std::cos( beta )
373 -aSize.Height*std::sin( beta );
377 rfYCorrection = aSize.Width*std::sin( fAnglePi );
381void lcl_correctRotation_Right_Bottom(
double& rfXCorrection,
double& rfYCorrection
382 ,
double fAnglePositiveDegree,
const awt::Size& aSize )
386 if( fAnglePositiveDegree==0.0 )
389 else if( fAnglePositiveDegree<= 90.0 )
391 rfYCorrection = aSize.Width*std::sin( fAnglePi );
393 else if( fAnglePositiveDegree<= 180.0 )
395 double beta = fAnglePi-M_PI_2;
396 rfXCorrection = aSize.Width*std::sin( beta );
397 rfYCorrection = aSize.Height*std::sin( beta )
398 +aSize.Width*std::cos( beta );
400 else if( fAnglePositiveDegree<= 270.0 )
402 double beta = 3*M_PI_2 - fAnglePi;
403 rfXCorrection = aSize.Height*std::cos( beta )
404 +aSize.Width*std::sin( beta );
405 rfYCorrection = aSize.Height*std::sin( beta );
409 rfXCorrection = -aSize.Height*std::sin( fAnglePi );
416 ,
LabelAlignment eLabelAlignment,
const double fRotationAngle,
bool bRotateAroundCenter )
418 if( !xShape2DText.is() )
421 awt::Point aOldPos = xShape2DText->getPosition();
422 awt::Size aSize = xShape2DText->getSize();
424 double fYCorrection = 0.0;
425 double fXCorrection = 0.0;
427 double fAnglePositiveDegree = fRotationAngle;
428 while(fAnglePositiveDegree<0.0)
429 fAnglePositiveDegree+=360.0;
431 switch(eLabelAlignment)
434 lcl_correctRotation_Left( fXCorrection, fYCorrection, fAnglePositiveDegree, aSize, bRotateAroundCenter );
437 lcl_correctRotation_Right( fXCorrection, fYCorrection, fAnglePositiveDegree, aSize, bRotateAroundCenter );
440 lcl_correctRotation_Top( fXCorrection, fYCorrection, fAnglePositiveDegree, aSize, bRotateAroundCenter );
443 lcl_correctRotation_Bottom( fXCorrection, fYCorrection, fAnglePositiveDegree, aSize, bRotateAroundCenter );
446 lcl_correctRotation_Left_Top( fXCorrection, fYCorrection, fAnglePositiveDegree, aSize );
449 lcl_correctRotation_Left_Bottom( fXCorrection, fYCorrection, fAnglePositiveDegree, aSize );
452 lcl_correctRotation_Right_Top( fXCorrection, fYCorrection, fAnglePositiveDegree, aSize );
455 lcl_correctRotation_Right_Bottom( fXCorrection, fYCorrection, fAnglePositiveDegree, aSize );
461 xShape2DText->setPosition( awt::Point(
462 static_cast<sal_Int32
>(aOldPos.X + fXCorrection )
463 ,
static_cast<sal_Int32
>(aOldPos.Y + fYCorrection ) ) );
LabelPositionHelper()=delete
css::awt::Point transformSceneToScreenPosition(const css::drawing::Position3D &rScenePosition3D) const
virtual ~LabelPositionHelper()
rtl::Reference< SvxShapeGroupAnyD > m_xLogicTarget
static void correctPositionForRotation(const rtl::Reference< SvxShapeText > &xShape2DText, LabelAlignment eLabelAlignment, const double fRotationAngle, bool bRotateAroundCenter)
static void changeTextAdjustment(tAnySequence &rPropValues, const tNameSequence &rPropNames, LabelAlignment eAlignment)
static void doDynamicFontResize(tAnySequence &rPropValues, const tNameSequence &rPropNames, const css::uno::Reference< css::beans::XPropertySet > &xAxisModelProps, const css::awt::Size &rNewReferenceSize)
sal_Int32 m_nDimensionCount
static css::awt::Point transformSceneToScreenPosition(const css::drawing::Position3D &rScenePosition3D, const rtl::Reference< SvxShapeGroupAnyD > &xSceneTarget, sal_Int32 nDimensionCount)
static css::uno::Any * getValuePointer(tAnySequence &rPropValues, const tNameSequence &rPropNames, std::u16string_view rPropName)
static double calculate(double fValue, const css::awt::Size &rOldReferenceSize, const css::awt::Size &rNewReferenceSize)
constexpr double deg2rad(double v)
static void lcl_doDynamicFontResize(uno::Any *pAOldAndNewFontHeightAny, const awt::Size &rOldReferenceSize, const awt::Size &rNewReferenceSize)
css::uno::Sequence< OUString > tNameSequence
@ LABEL_ALIGN_RIGHT_BOTTOM
@ LABEL_ALIGN_LEFT_BOTTOM
css::uno::Sequence< css::uno::Any > tAnySequence