/src/libreoffice/chart2/source/view/main/LabelPositionHelper.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 <LabelPositionHelper.hxx> |
21 | | #include <PlottingPositionHelper.hxx> |
22 | | #include <PropertyMapper.hxx> |
23 | | #include <RelativeSizeHelper.hxx> |
24 | | #include <com/sun/star/beans/XPropertySet.hpp> |
25 | | #include <com/sun/star/drawing/TextVerticalAdjust.hpp> |
26 | | #include <com/sun/star/drawing/TextHorizontalAdjust.hpp> |
27 | | |
28 | | #include <cmath> |
29 | | #include <utility> |
30 | | |
31 | | namespace chart |
32 | | { |
33 | | using namespace ::com::sun::star; |
34 | | |
35 | | LabelPositionHelper::LabelPositionHelper( |
36 | | sal_Int32 nDimensionCount |
37 | | , rtl::Reference<SvxShapeGroupAnyD> xLogicTarget) |
38 | 0 | : m_nDimensionCount(nDimensionCount) |
39 | 0 | , m_xLogicTarget(std::move(xLogicTarget)) |
40 | 0 | { |
41 | 0 | } |
42 | | |
43 | | LabelPositionHelper::~LabelPositionHelper() |
44 | 0 | { |
45 | 0 | } |
46 | | |
47 | | awt::Point LabelPositionHelper::transformSceneToScreenPosition( const drawing::Position3D& rScenePosition3D ) const |
48 | 0 | { |
49 | 0 | return PlottingPositionHelper::transformSceneToScreenPosition( |
50 | 0 | rScenePosition3D, m_xLogicTarget, m_nDimensionCount ); |
51 | 0 | } |
52 | | |
53 | | void LabelPositionHelper::changeTextAdjustment( tAnySequence& rPropValues, const tNameSequence& rPropNames, LabelAlignment eAlignment) |
54 | 0 | { |
55 | 0 | uno::Any* pHorizontalAdjustAny |
56 | 0 | = PropertyMapper::getValuePointer(rPropValues, rPropNames, u"TextHorizontalAdjust"); |
57 | 0 | if (pHorizontalAdjustAny) |
58 | 0 | { |
59 | 0 | drawing::TextHorizontalAdjust eHorizontalAdjust = drawing::TextHorizontalAdjust_CENTER; |
60 | 0 | if( eAlignment==LABEL_ALIGN_RIGHT || eAlignment==LABEL_ALIGN_RIGHT_TOP || eAlignment==LABEL_ALIGN_RIGHT_BOTTOM ) |
61 | 0 | eHorizontalAdjust = drawing::TextHorizontalAdjust_LEFT; |
62 | 0 | else if( eAlignment==LABEL_ALIGN_LEFT || eAlignment==LABEL_ALIGN_LEFT_TOP || eAlignment==LABEL_ALIGN_LEFT_BOTTOM ) |
63 | 0 | eHorizontalAdjust = drawing::TextHorizontalAdjust_RIGHT; |
64 | 0 | *pHorizontalAdjustAny <<= eHorizontalAdjust; |
65 | 0 | } |
66 | |
|
67 | 0 | uno::Any* pVerticalAdjustAny |
68 | 0 | = PropertyMapper::getValuePointer(rPropValues, rPropNames, u"TextVerticalAdjust"); |
69 | 0 | if (pVerticalAdjustAny) |
70 | 0 | { |
71 | 0 | drawing::TextVerticalAdjust eVerticalAdjust = drawing::TextVerticalAdjust_CENTER; |
72 | 0 | if( eAlignment==LABEL_ALIGN_TOP || eAlignment==LABEL_ALIGN_RIGHT_TOP || eAlignment==LABEL_ALIGN_LEFT_TOP ) |
73 | 0 | eVerticalAdjust = drawing::TextVerticalAdjust_BOTTOM; |
74 | 0 | else if( eAlignment==LABEL_ALIGN_BOTTOM || eAlignment==LABEL_ALIGN_RIGHT_BOTTOM || eAlignment==LABEL_ALIGN_LEFT_BOTTOM ) |
75 | 0 | eVerticalAdjust = drawing::TextVerticalAdjust_TOP; |
76 | 0 | *pVerticalAdjustAny <<= eVerticalAdjust; |
77 | 0 | } |
78 | 0 | } |
79 | | |
80 | | static void lcl_doDynamicFontResize( uno::Any* pAOldAndNewFontHeightAny |
81 | | , const awt::Size& rOldReferenceSize |
82 | | , const awt::Size& rNewReferenceSize ) |
83 | 0 | { |
84 | 0 | double fOldFontHeight = 0; |
85 | 0 | if( pAOldAndNewFontHeightAny && ( *pAOldAndNewFontHeightAny >>= fOldFontHeight ) ) |
86 | 0 | { |
87 | 0 | double fNewFontHeight = RelativeSizeHelper::calculate( fOldFontHeight, rOldReferenceSize, rNewReferenceSize ); |
88 | 0 | *pAOldAndNewFontHeightAny <<= fNewFontHeight; |
89 | 0 | } |
90 | 0 | } |
91 | | |
92 | | void LabelPositionHelper::doDynamicFontResize( tAnySequence& rPropValues |
93 | | , const tNameSequence& rPropNames |
94 | | , const uno::Reference< beans::XPropertySet >& xAxisModelProps |
95 | | , const awt::Size& rNewReferenceSize |
96 | | ) |
97 | 0 | { |
98 | | //handle dynamic font resize: |
99 | 0 | awt::Size aOldReferenceSize; |
100 | 0 | if( xAxisModelProps->getPropertyValue( u"ReferencePageSize"_ustr) >>= aOldReferenceSize ) |
101 | 0 | { |
102 | 0 | uno::Any* pAOldAndNewFontHeightAny = PropertyMapper::getValuePointer( rPropValues, rPropNames, u"CharHeight" ); |
103 | 0 | lcl_doDynamicFontResize( pAOldAndNewFontHeightAny, aOldReferenceSize, rNewReferenceSize ); |
104 | 0 | pAOldAndNewFontHeightAny = PropertyMapper::getValuePointer( rPropValues, rPropNames, u"CharHeightAsian" ); |
105 | 0 | lcl_doDynamicFontResize( pAOldAndNewFontHeightAny, aOldReferenceSize, rNewReferenceSize ); |
106 | 0 | pAOldAndNewFontHeightAny = PropertyMapper::getValuePointer( rPropValues, rPropNames, u"CharHeightComplex" ); |
107 | 0 | lcl_doDynamicFontResize( pAOldAndNewFontHeightAny, aOldReferenceSize, rNewReferenceSize ); |
108 | 0 | } |
109 | 0 | } |
110 | | |
111 | | namespace |
112 | | { |
113 | | |
114 | | void lcl_correctRotation_Left( double& rfXCorrection, double& rfYCorrection |
115 | | , double fAnglePositiveDegree, const awt::Size& aSize, bool bRotateAroundCenter ) |
116 | 0 | { |
117 | | //correct label positions for labels on a left side of something with a right centered alignment |
118 | 0 | double fAnglePi = basegfx::deg2rad(fAnglePositiveDegree); |
119 | 0 | if( fAnglePositiveDegree==0.0 ) |
120 | 0 | { |
121 | 0 | } |
122 | 0 | else if( fAnglePositiveDegree<= 90.0 ) |
123 | 0 | { |
124 | 0 | rfXCorrection = -aSize.Height*std::sin( fAnglePi )/2.0; |
125 | 0 | if( bRotateAroundCenter ) |
126 | 0 | rfYCorrection = -aSize.Width*std::sin( fAnglePi )/2.0; |
127 | 0 | } |
128 | 0 | else if( fAnglePositiveDegree<= 180.0 ) |
129 | 0 | { |
130 | 0 | double beta = fAnglePi-M_PI_2; |
131 | 0 | rfXCorrection = -aSize.Width *std::sin( beta ) |
132 | 0 | -aSize.Height *std::cos( beta )/2.0; |
133 | 0 | if( bRotateAroundCenter ) |
134 | 0 | rfYCorrection = -aSize.Width *std::cos( beta )/2.0; |
135 | 0 | else |
136 | 0 | rfYCorrection = -aSize.Width *std::cos( beta ); |
137 | 0 | } |
138 | 0 | else if( fAnglePositiveDegree<= 270.0 ) |
139 | 0 | { |
140 | 0 | double beta = fAnglePi - M_PI; |
141 | 0 | rfXCorrection = -aSize.Width *std::cos( beta ) |
142 | 0 | -aSize.Height*std::sin( beta )/2.0; |
143 | 0 | if( bRotateAroundCenter ) |
144 | 0 | rfYCorrection = aSize.Width *std::sin( beta )/2.0; |
145 | 0 | else |
146 | 0 | rfYCorrection = aSize.Width *std::sin( beta ); |
147 | 0 | } |
148 | 0 | else |
149 | 0 | { |
150 | 0 | double beta = 2*M_PI - fAnglePi; |
151 | 0 | rfXCorrection = -aSize.Height*std::sin( beta )/2.0; |
152 | 0 | if( bRotateAroundCenter ) |
153 | 0 | rfYCorrection = aSize.Width*std::sin( beta )/2.0; |
154 | 0 | } |
155 | 0 | } |
156 | | |
157 | | void lcl_correctRotation_Right( double& rfXCorrection, double& rfYCorrection |
158 | | , double fAnglePositiveDegree, const awt::Size& aSize, bool bRotateAroundCenter ) |
159 | 0 | { |
160 | | //correct label positions for labels on a right side of something with a left centered alignment |
161 | 0 | double fAnglePi = basegfx::deg2rad(fAnglePositiveDegree); |
162 | 0 | if( fAnglePositiveDegree== 0.0 ) |
163 | 0 | { |
164 | 0 | } |
165 | 0 | else if( fAnglePositiveDegree<= 90.0 ) |
166 | 0 | { |
167 | 0 | rfXCorrection = aSize.Height*std::sin( fAnglePi )/2.0; |
168 | 0 | if( bRotateAroundCenter ) |
169 | 0 | rfYCorrection = aSize.Width*std::sin( fAnglePi )/2.0; |
170 | 0 | } |
171 | 0 | else if( fAnglePositiveDegree<= 180.0 ) |
172 | 0 | { |
173 | 0 | double beta = M_PI - fAnglePi; |
174 | 0 | rfXCorrection = aSize.Width *std::cos( beta ) |
175 | 0 | + aSize.Height*std::sin( beta )/2.0; |
176 | 0 | if( bRotateAroundCenter ) |
177 | 0 | rfYCorrection = aSize.Width *std::sin( beta )/2.0; |
178 | 0 | else |
179 | 0 | rfYCorrection = aSize.Width *std::sin( beta ); |
180 | 0 | } |
181 | 0 | else if( fAnglePositiveDegree<= 270.0 ) |
182 | 0 | { |
183 | 0 | double beta = 3*M_PI_2 - fAnglePi; |
184 | 0 | rfXCorrection = aSize.Width *std::sin( beta ) |
185 | 0 | +aSize.Height*std::cos( beta )/2.0; |
186 | 0 | if( bRotateAroundCenter ) |
187 | 0 | rfYCorrection = -aSize.Width *std::cos( beta )/2.0; |
188 | 0 | else |
189 | 0 | rfYCorrection = -aSize.Width *std::cos( beta ); |
190 | 0 | } |
191 | 0 | else |
192 | 0 | { |
193 | 0 | rfXCorrection = aSize.Height*std::sin( 2*M_PI - fAnglePi )/2.0; |
194 | 0 | if( bRotateAroundCenter ) |
195 | 0 | rfYCorrection = -aSize.Width*std::sin( 2*M_PI - fAnglePi )/2.0; |
196 | 0 | } |
197 | 0 | } |
198 | | |
199 | | void lcl_correctRotation_Top( double& rfXCorrection, double& rfYCorrection |
200 | | , double fAnglePositiveDegree, const awt::Size& aSize, bool bRotateAroundCenter ) |
201 | 0 | { |
202 | | //correct label positions for labels on top of something with a bottom centered alignment |
203 | 0 | double fAnglePi = basegfx::deg2rad(fAnglePositiveDegree); |
204 | 0 | if( fAnglePositiveDegree== 0.0 ) |
205 | 0 | { |
206 | 0 | } |
207 | 0 | else if( fAnglePositiveDegree<= 90.0 ) |
208 | 0 | { |
209 | 0 | rfXCorrection = aSize.Height*std::sin( fAnglePi )/2.0; |
210 | 0 | if( !bRotateAroundCenter ) |
211 | 0 | rfXCorrection += aSize.Width*std::cos( fAnglePi )/2.0; |
212 | 0 | rfYCorrection = -aSize.Width*std::sin( fAnglePi )/2.0; |
213 | 0 | } |
214 | 0 | else if( fAnglePositiveDegree<= 180.0 ) |
215 | 0 | { |
216 | 0 | double beta = fAnglePi - M_PI_2; |
217 | 0 | rfXCorrection = aSize.Height*std::cos( beta )/2.0; |
218 | 0 | if( !bRotateAroundCenter ) |
219 | 0 | rfXCorrection -= aSize.Width*std::sin( beta )/2.0; |
220 | 0 | rfYCorrection = -aSize.Width*std::cos( beta )/2.0 |
221 | 0 | - aSize.Height*std::sin( beta ); |
222 | 0 | } |
223 | 0 | else if( fAnglePositiveDegree<= 270.0 ) |
224 | 0 | { |
225 | 0 | double beta = fAnglePi - M_PI; |
226 | 0 | rfXCorrection = -aSize.Height *std::sin( beta )/2.0; |
227 | 0 | if( !bRotateAroundCenter ) |
228 | 0 | rfXCorrection += aSize.Width *std::cos( beta )/2.0; |
229 | 0 | rfYCorrection = -aSize.Width *std::sin( beta )/2.0 |
230 | 0 | -aSize.Height *std::cos( beta ); |
231 | 0 | } |
232 | 0 | else |
233 | 0 | { |
234 | 0 | rfXCorrection = aSize.Height*std::sin( fAnglePi )/2.0; |
235 | 0 | if( !bRotateAroundCenter ) |
236 | 0 | rfXCorrection -= aSize.Width*std::cos( fAnglePi )/2.0; |
237 | 0 | rfYCorrection = aSize.Width*std::sin( fAnglePi )/2.0; |
238 | 0 | } |
239 | 0 | } |
240 | | |
241 | | void lcl_correctRotation_Bottom( double& rfXCorrection, double& rfYCorrection |
242 | | , double fAnglePositiveDegree, const awt::Size& aSize, bool bRotateAroundCenter ) |
243 | 0 | { |
244 | | //correct label positions for labels below something with a top centered alignment |
245 | 0 | double fAnglePi = basegfx::deg2rad(fAnglePositiveDegree); |
246 | 0 | if( fAnglePositiveDegree==0.0 ) |
247 | 0 | { |
248 | 0 | } |
249 | 0 | else if( fAnglePositiveDegree<= 90.0 ) |
250 | 0 | { |
251 | 0 | rfXCorrection = -aSize.Height*std::sin( fAnglePi )/2.0; |
252 | 0 | if( !bRotateAroundCenter ) |
253 | 0 | rfXCorrection -= aSize.Width *std::cos( fAnglePi )/2.0; |
254 | 0 | rfYCorrection = aSize.Width*std::sin( fAnglePi )/2.0; |
255 | 0 | } |
256 | 0 | else if( fAnglePositiveDegree<= 180.0 ) |
257 | 0 | { |
258 | 0 | double beta = fAnglePi-M_PI_2; |
259 | 0 | rfXCorrection = -aSize.Height*std::cos( beta )/2.0; |
260 | 0 | if( !bRotateAroundCenter ) |
261 | 0 | rfXCorrection += aSize.Width *std::sin( beta )/2.0; |
262 | 0 | rfYCorrection = aSize.Width *std::cos( beta )/2.0 |
263 | 0 | +aSize.Height*std::sin( beta ); |
264 | 0 | } |
265 | 0 | else if( fAnglePositiveDegree<= 270.0 ) |
266 | 0 | { |
267 | 0 | double beta = 3*M_PI_2 - fAnglePi; |
268 | 0 | rfXCorrection = aSize.Height*std::cos( beta )/2.0; |
269 | 0 | if( !bRotateAroundCenter ) |
270 | 0 | rfXCorrection -= aSize.Width *std::sin( beta )/2.0; |
271 | 0 | rfYCorrection = aSize.Height*std::sin( beta ) |
272 | 0 | +aSize.Width*std::cos( beta )/2.0; |
273 | 0 | } |
274 | 0 | else |
275 | 0 | { |
276 | 0 | double beta = 2*M_PI - fAnglePi; |
277 | 0 | rfXCorrection = aSize.Height*std::sin( beta )/2.0; |
278 | 0 | if( !bRotateAroundCenter ) |
279 | 0 | rfXCorrection += aSize.Width*std::cos( beta )/2.0; |
280 | 0 | rfYCorrection = aSize.Width*std::sin( beta )/2.0; |
281 | 0 | } |
282 | 0 | } |
283 | | |
284 | | void lcl_correctRotation_Left_Top( double& rfXCorrection, double& rfYCorrection |
285 | | , double fAnglePositiveDegree, const awt::Size& aSize ) |
286 | 0 | { |
287 | | //correct position for labels at the left top corner of something with a bottom right alignment |
288 | 0 | double fAnglePi = basegfx::deg2rad(fAnglePositiveDegree); |
289 | 0 | if( fAnglePositiveDegree==0.0 ) |
290 | 0 | { |
291 | 0 | } |
292 | 0 | else if( fAnglePositiveDegree<= 90.0 ) |
293 | 0 | { |
294 | 0 | rfYCorrection = -aSize.Width*std::sin( fAnglePi ); |
295 | 0 | } |
296 | 0 | else if( fAnglePositiveDegree<= 180.0 ) |
297 | 0 | { |
298 | 0 | double beta = fAnglePi-M_PI_2; |
299 | 0 | rfXCorrection = -aSize.Width*std::sin( beta ); |
300 | 0 | rfYCorrection = -aSize.Height*std::sin( beta ) |
301 | 0 | -aSize.Width*std::cos( beta ); |
302 | 0 | } |
303 | 0 | else if( fAnglePositiveDegree<= 270.0 ) |
304 | 0 | { |
305 | 0 | double beta = 3*M_PI_2 - fAnglePi; |
306 | 0 | rfXCorrection = -aSize.Height*std::cos( beta ) |
307 | 0 | -aSize.Width*std::sin( beta ); |
308 | 0 | rfYCorrection = -aSize.Height*std::sin( beta ); |
309 | 0 | } |
310 | 0 | else |
311 | 0 | { |
312 | 0 | rfXCorrection = aSize.Height*std::sin( fAnglePi ); |
313 | 0 | } |
314 | 0 | } |
315 | | |
316 | | void lcl_correctRotation_Left_Bottom( double& rfXCorrection, double& rfYCorrection |
317 | | , double fAnglePositiveDegree, const awt::Size& aSize ) |
318 | 0 | { |
319 | | //correct position for labels at the left bottom corner of something with a top right alignment |
320 | 0 | double fAnglePi = basegfx::deg2rad(fAnglePositiveDegree); |
321 | 0 | if( fAnglePositiveDegree==0.0 ) |
322 | 0 | { |
323 | 0 | } |
324 | 0 | else if( fAnglePositiveDegree<= 90.0 ) |
325 | 0 | { |
326 | 0 | rfXCorrection = -aSize.Height*std::sin( fAnglePi ); |
327 | 0 | } |
328 | 0 | else if( fAnglePositiveDegree<= 180.0 ) |
329 | 0 | { |
330 | 0 | double beta = fAnglePi-M_PI_2; |
331 | 0 | rfXCorrection = -aSize.Width*std::sin( beta ) |
332 | 0 | -aSize.Height*std::cos( beta ); |
333 | 0 | rfYCorrection = aSize.Height*std::sin( beta ); |
334 | 0 | } |
335 | 0 | else if( fAnglePositiveDegree<= 270.0 ) |
336 | 0 | { |
337 | 0 | double beta = 3*M_PI_2 - fAnglePi; |
338 | 0 | rfXCorrection = -aSize.Width*std::sin( beta ); |
339 | 0 | rfYCorrection = aSize.Width*std::cos( beta ) |
340 | 0 | +aSize.Height*std::sin( beta ); |
341 | 0 | } |
342 | 0 | else |
343 | 0 | { |
344 | 0 | rfYCorrection = -aSize.Width*std::sin( fAnglePi ); |
345 | 0 | } |
346 | 0 | } |
347 | | |
348 | | void lcl_correctRotation_Right_Top( double& rfXCorrection, double& rfYCorrection |
349 | | , double fAnglePositiveDegree, const awt::Size& aSize ) |
350 | 0 | { |
351 | | //correct position for labels at the right top corner of something with a bottom left alignment |
352 | 0 | double fAnglePi = basegfx::deg2rad(fAnglePositiveDegree); |
353 | 0 | if( fAnglePositiveDegree==0.0 ) |
354 | 0 | { |
355 | 0 | } |
356 | 0 | else if( fAnglePositiveDegree<= 90.0 ) |
357 | 0 | { |
358 | 0 | rfXCorrection = aSize.Height*std::sin( fAnglePi ); |
359 | 0 | } |
360 | 0 | else if( fAnglePositiveDegree<= 180.0 ) |
361 | 0 | { |
362 | 0 | double beta = fAnglePi-M_PI_2; |
363 | 0 | rfXCorrection = aSize.Width*std::sin( beta ) |
364 | 0 | +aSize.Height*std::cos( beta ); |
365 | 0 | rfYCorrection = -aSize.Height*std::sin( beta ); |
366 | 0 | } |
367 | 0 | else if( fAnglePositiveDegree<= 270.0 ) |
368 | 0 | { |
369 | 0 | double beta = 3*M_PI_2 - fAnglePi; |
370 | 0 | rfXCorrection = aSize.Width*std::sin( beta ); |
371 | 0 | rfYCorrection = -aSize.Width*std::cos( beta ) |
372 | 0 | -aSize.Height*std::sin( beta ); |
373 | 0 | } |
374 | 0 | else |
375 | 0 | { |
376 | 0 | rfYCorrection = aSize.Width*std::sin( fAnglePi ); |
377 | 0 | } |
378 | 0 | } |
379 | | |
380 | | void lcl_correctRotation_Right_Bottom( double& rfXCorrection, double& rfYCorrection |
381 | | , double fAnglePositiveDegree, const awt::Size& aSize ) |
382 | 0 | { |
383 | | //correct position for labels at the right bottom corner of something with a top left alignment |
384 | 0 | double fAnglePi = basegfx::deg2rad(fAnglePositiveDegree); |
385 | 0 | if( fAnglePositiveDegree==0.0 ) |
386 | 0 | { |
387 | 0 | } |
388 | 0 | else if( fAnglePositiveDegree<= 90.0 ) |
389 | 0 | { |
390 | 0 | rfYCorrection = aSize.Width*std::sin( fAnglePi ); |
391 | 0 | } |
392 | 0 | else if( fAnglePositiveDegree<= 180.0 ) |
393 | 0 | { |
394 | 0 | double beta = fAnglePi-M_PI_2; |
395 | 0 | rfXCorrection = aSize.Width*std::sin( beta ); |
396 | 0 | rfYCorrection = aSize.Height*std::sin( beta ) |
397 | 0 | +aSize.Width*std::cos( beta ); |
398 | 0 | } |
399 | 0 | else if( fAnglePositiveDegree<= 270.0 ) |
400 | 0 | { |
401 | 0 | double beta = 3*M_PI_2 - fAnglePi; |
402 | 0 | rfXCorrection = aSize.Height*std::cos( beta ) |
403 | 0 | +aSize.Width*std::sin( beta ); |
404 | 0 | rfYCorrection = aSize.Height*std::sin( beta ); |
405 | 0 | } |
406 | 0 | else |
407 | 0 | { |
408 | 0 | rfXCorrection = -aSize.Height*std::sin( fAnglePi ); |
409 | 0 | } |
410 | 0 | } |
411 | | |
412 | | }//end anonymous namespace |
413 | | |
414 | | void LabelPositionHelper::correctPositionForRotation( const rtl::Reference<SvxShapeText>& xShape2DText |
415 | | , LabelAlignment eLabelAlignment, const double fRotationAngle, bool bRotateAroundCenter ) |
416 | 0 | { |
417 | 0 | if( !xShape2DText.is() ) |
418 | 0 | return; |
419 | | |
420 | 0 | awt::Point aOldPos = xShape2DText->getPosition(); |
421 | 0 | awt::Size aSize = xShape2DText->getSize(); |
422 | |
|
423 | 0 | double fYCorrection = 0.0; |
424 | 0 | double fXCorrection = 0.0; |
425 | |
|
426 | 0 | double fAnglePositiveDegree = fRotationAngle; |
427 | 0 | while(fAnglePositiveDegree<0.0) |
428 | 0 | fAnglePositiveDegree+=360.0; |
429 | |
|
430 | 0 | switch(eLabelAlignment) |
431 | 0 | { |
432 | 0 | case LABEL_ALIGN_LEFT: |
433 | 0 | lcl_correctRotation_Left( fXCorrection, fYCorrection, fAnglePositiveDegree, aSize, bRotateAroundCenter ); |
434 | 0 | break; |
435 | 0 | case LABEL_ALIGN_RIGHT: |
436 | 0 | lcl_correctRotation_Right( fXCorrection, fYCorrection, fAnglePositiveDegree, aSize, bRotateAroundCenter ); |
437 | 0 | break; |
438 | 0 | case LABEL_ALIGN_TOP: |
439 | 0 | lcl_correctRotation_Top( fXCorrection, fYCorrection, fAnglePositiveDegree, aSize, bRotateAroundCenter ); |
440 | 0 | break; |
441 | 0 | case LABEL_ALIGN_BOTTOM: |
442 | 0 | lcl_correctRotation_Bottom( fXCorrection, fYCorrection, fAnglePositiveDegree, aSize, bRotateAroundCenter ); |
443 | 0 | break; |
444 | 0 | case LABEL_ALIGN_LEFT_TOP: |
445 | 0 | lcl_correctRotation_Left_Top( fXCorrection, fYCorrection, fAnglePositiveDegree, aSize ); |
446 | 0 | break; |
447 | 0 | case LABEL_ALIGN_LEFT_BOTTOM: |
448 | 0 | lcl_correctRotation_Left_Bottom( fXCorrection, fYCorrection, fAnglePositiveDegree, aSize ); |
449 | 0 | break; |
450 | 0 | case LABEL_ALIGN_RIGHT_TOP: |
451 | 0 | lcl_correctRotation_Right_Top( fXCorrection, fYCorrection, fAnglePositiveDegree, aSize ); |
452 | 0 | break; |
453 | 0 | case LABEL_ALIGN_RIGHT_BOTTOM: |
454 | 0 | lcl_correctRotation_Right_Bottom( fXCorrection, fYCorrection, fAnglePositiveDegree, aSize ); |
455 | 0 | break; |
456 | 0 | default: //LABEL_ALIGN_CENTER |
457 | 0 | break; |
458 | 0 | } |
459 | | |
460 | 0 | xShape2DText->setPosition( awt::Point( |
461 | 0 | static_cast<sal_Int32>(aOldPos.X + fXCorrection ) |
462 | 0 | , static_cast<sal_Int32>(aOldPos.Y + fYCorrection ) ) ); |
463 | 0 | } |
464 | | |
465 | | } //namespace chart |
466 | | |
467 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |