Line data Source code
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 :
21 : #include <limits.h>
22 :
23 : #include <tools/bigint.hxx>
24 : #include <tools/debug.hxx>
25 : #include <tools/poly.hxx>
26 :
27 : #include <vcl/virdev.hxx>
28 : #include <vcl/region.hxx>
29 : #include <vcl/wrkwin.hxx>
30 : #include <vcl/cursor.hxx>
31 : #include <vcl/metaact.hxx>
32 : #include <vcl/gdimtf.hxx>
33 : #include <vcl/lineinfo.hxx>
34 : #include <vcl/outdev.hxx>
35 :
36 : #include <svdata.hxx>
37 : #include <window.h>
38 : #include <outdev.h>
39 : #include <salgdi.hxx>
40 :
41 : #include <basegfx/matrix/b2dhommatrix.hxx>
42 : #include <basegfx/polygon/b2dpolygon.hxx>
43 : #include <basegfx/polygon/b2dpolypolygon.hxx>
44 :
45 : // =======================================================================
46 :
47 : DBG_NAMEEX( OutputDevice )
48 : DBG_NAMEEX( Polygon )
49 : DBG_NAMEEX( PolyPolygon )
50 : DBG_NAMEEX( Region )
51 :
52 : // =======================================================================
53 :
54 : static int const s_ImplArySize = MAP_PIXEL+1;
55 : static long aImplNumeratorAry[s_ImplArySize] =
56 : { 1, 1, 5, 50, 1, 1, 1, 1, 1, 1, 1 };
57 : static long aImplDenominatorAry[s_ImplArySize] =
58 : { 2540, 254, 127, 127, 1000, 100, 10, 1, 72, 1440, 1 };
59 :
60 : // -----------------------------------------------------------------------
61 :
62 : /*
63 : Reduziert die Genauigkeit bis eine Fraction draus wird (sollte mal
64 : ein Fraction ctor werden) koennte man dann auch mit BigInts machen
65 : */
66 :
67 751256 : static Fraction ImplMakeFraction( long nN1, long nN2, long nD1, long nD2 )
68 : {
69 751256 : long i = 1;
70 :
71 751256 : if ( nN1 < 0 ) { i = -i; nN1 = -nN1; }
72 751256 : if ( nN2 < 0 ) { i = -i; nN2 = -nN2; }
73 751256 : if ( nD1 < 0 ) { i = -i; nD1 = -nD1; }
74 751256 : if ( nD2 < 0 ) { i = -i; nD2 = -nD2; }
75 : // alle positiv; i Vorzeichen
76 :
77 751256 : Fraction aF( i*nN1, nD1 );
78 751256 : aF *= Fraction( nN2, nD2 );
79 :
80 751256 : if( nD1 == 0 || nD2 == 0 ) //under these bad circumstances the following while loop will be endless
81 : {
82 : DBG_ASSERT(false,"Invalid parameter for ImplMakeFraction");
83 0 : return Fraction( 1, 1 );
84 : }
85 :
86 1641106 : while ( aF.GetDenominator() == -1 )
87 : {
88 138594 : if ( nN1 > nN2 )
89 0 : nN1 = (nN1 + 1) / 2;
90 : else
91 138594 : nN2 = (nN2 + 1) / 2;
92 138594 : if ( nD1 > nD2 )
93 0 : nD1 = (nD1 + 1) / 2;
94 : else
95 138594 : nD2 = (nD2 + 1) / 2;
96 :
97 138594 : aF = Fraction( i*nN1, nD1 );
98 138594 : aF *= Fraction( nN2, nD2 );
99 : }
100 :
101 751256 : return aF;
102 : }
103 :
104 : // -----------------------------------------------------------------------
105 :
106 : // Fraction.GetNumerator()
107 : // Fraction.GetDenominator() > 0
108 : // rOutRes.nPixPerInch? > 0
109 : // rMapRes.nMapScNum?
110 : // rMapRes.nMapScDenom? > 0
111 :
112 374435 : static void ImplCalcBigIntThreshold( long nDPIX, long nDPIY,
113 : const ImplMapRes& rMapRes,
114 : ImplThresholdRes& rThresRes )
115 : {
116 374435 : if ( nDPIX && (LONG_MAX / nDPIX < std::abs( rMapRes.mnMapScNumX ) ) ) // #111139# avoid div by zero
117 : {
118 0 : rThresRes.mnThresLogToPixX = 0;
119 0 : rThresRes.mnThresPixToLogX = 0;
120 : }
121 : else
122 : {
123 : // Schwellenwerte fuer BigInt Arithmetik berechnen
124 374435 : long nDenomHalfX = rMapRes.mnMapScDenomX / 2;
125 374435 : sal_uLong nDenomX = rMapRes.mnMapScDenomX;
126 374435 : long nProductX = nDPIX * rMapRes.mnMapScNumX;
127 :
128 374435 : if ( !nProductX )
129 0 : rThresRes.mnThresLogToPixX = LONG_MAX;
130 : else
131 374435 : rThresRes.mnThresLogToPixX = std::abs( (LONG_MAX - nDenomHalfX) / nProductX );
132 :
133 374435 : if ( !nDenomX )
134 0 : rThresRes.mnThresPixToLogX = LONG_MAX;
135 374435 : else if ( nProductX >= 0 )
136 374435 : rThresRes.mnThresPixToLogX = (long)(((sal_uLong)LONG_MAX - (sal_uLong)( nProductX/2)) / nDenomX);
137 : else
138 0 : rThresRes.mnThresPixToLogX = (long)(((sal_uLong)LONG_MAX + (sal_uLong)(-nProductX/2)) / nDenomX);
139 : }
140 :
141 374435 : if ( nDPIY && (LONG_MAX / nDPIY < std::abs( rMapRes.mnMapScNumY ) ) ) // #111139# avoid div by zero
142 : {
143 0 : rThresRes.mnThresLogToPixY = 0;
144 0 : rThresRes.mnThresPixToLogY = 0;
145 : }
146 : else
147 : {
148 : // Schwellenwerte fuer BigInt Arithmetik berechnen
149 374435 : long nDenomHalfY = rMapRes.mnMapScDenomY / 2;
150 374435 : sal_uLong nDenomY = rMapRes.mnMapScDenomY;
151 374435 : long nProductY = nDPIY * rMapRes.mnMapScNumY;
152 :
153 374435 : if ( !nProductY )
154 0 : rThresRes.mnThresLogToPixY = LONG_MAX;
155 : else
156 374435 : rThresRes.mnThresLogToPixY = std::abs( (LONG_MAX - nDenomHalfY) / nProductY );
157 :
158 374435 : if ( !nDenomY )
159 0 : rThresRes.mnThresPixToLogY = LONG_MAX;
160 374435 : else if ( nProductY >= 0 )
161 374435 : rThresRes.mnThresPixToLogY = (long)(((sal_uLong)LONG_MAX - (sal_uLong)( nProductY/2)) / nDenomY);
162 : else
163 0 : rThresRes.mnThresPixToLogY = (long)(((sal_uLong)LONG_MAX + (sal_uLong)(-nProductY/2)) / nDenomY);
164 : }
165 :
166 374435 : rThresRes.mnThresLogToPixX /= 2;
167 374435 : rThresRes.mnThresLogToPixY /= 2;
168 374435 : rThresRes.mnThresPixToLogX /= 2;
169 374435 : rThresRes.mnThresPixToLogY /= 2;
170 374435 : }
171 :
172 : // -----------------------------------------------------------------------
173 :
174 375551 : static void ImplCalcMapResolution( const MapMode& rMapMode,
175 : long nDPIX, long nDPIY, ImplMapRes& rMapRes )
176 : {
177 375551 : switch ( rMapMode.GetMapUnit() )
178 : {
179 : case MAP_RELATIVE:
180 46 : break;
181 : case MAP_100TH_MM:
182 41194 : rMapRes.mnMapScNumX = 1;
183 41194 : rMapRes.mnMapScDenomX = 2540;
184 41194 : rMapRes.mnMapScNumY = 1;
185 41194 : rMapRes.mnMapScDenomY = 2540;
186 41194 : break;
187 : case MAP_10TH_MM:
188 19 : rMapRes.mnMapScNumX = 1;
189 19 : rMapRes.mnMapScDenomX = 254;
190 19 : rMapRes.mnMapScNumY = 1;
191 19 : rMapRes.mnMapScDenomY = 254;
192 19 : break;
193 : case MAP_MM:
194 1 : rMapRes.mnMapScNumX = 5; // 10
195 1 : rMapRes.mnMapScDenomX = 127; // 254
196 1 : rMapRes.mnMapScNumY = 5; // 10
197 1 : rMapRes.mnMapScDenomY = 127; // 254
198 1 : break;
199 : case MAP_CM:
200 12092 : rMapRes.mnMapScNumX = 50; // 100
201 12092 : rMapRes.mnMapScDenomX = 127; // 254
202 12092 : rMapRes.mnMapScNumY = 50; // 100
203 12092 : rMapRes.mnMapScDenomY = 127; // 254
204 12092 : break;
205 : case MAP_1000TH_INCH:
206 1 : rMapRes.mnMapScNumX = 1;
207 1 : rMapRes.mnMapScDenomX = 1000;
208 1 : rMapRes.mnMapScNumY = 1;
209 1 : rMapRes.mnMapScDenomY = 1000;
210 1 : break;
211 : case MAP_100TH_INCH:
212 222216 : rMapRes.mnMapScNumX = 1;
213 222216 : rMapRes.mnMapScDenomX = 100;
214 222216 : rMapRes.mnMapScNumY = 1;
215 222216 : rMapRes.mnMapScDenomY = 100;
216 222216 : break;
217 : case MAP_10TH_INCH:
218 1 : rMapRes.mnMapScNumX = 1;
219 1 : rMapRes.mnMapScDenomX = 10;
220 1 : rMapRes.mnMapScNumY = 1;
221 1 : rMapRes.mnMapScDenomY = 10;
222 1 : break;
223 : case MAP_INCH:
224 362 : rMapRes.mnMapScNumX = 1;
225 362 : rMapRes.mnMapScDenomX = 1;
226 362 : rMapRes.mnMapScNumY = 1;
227 362 : rMapRes.mnMapScDenomY = 1;
228 362 : break;
229 : case MAP_POINT:
230 454 : rMapRes.mnMapScNumX = 1;
231 454 : rMapRes.mnMapScDenomX = 72;
232 454 : rMapRes.mnMapScNumY = 1;
233 454 : rMapRes.mnMapScDenomY = 72;
234 454 : break;
235 : case MAP_TWIP:
236 86163 : rMapRes.mnMapScNumX = 1;
237 86163 : rMapRes.mnMapScDenomX = 1440;
238 86163 : rMapRes.mnMapScNumY = 1;
239 86163 : rMapRes.mnMapScDenomY = 1440;
240 86163 : break;
241 : case MAP_PIXEL:
242 9762 : rMapRes.mnMapScNumX = 1;
243 9762 : rMapRes.mnMapScDenomX = nDPIX;
244 9762 : rMapRes.mnMapScNumY = 1;
245 9762 : rMapRes.mnMapScDenomY = nDPIY;
246 9762 : break;
247 : case MAP_SYSFONT:
248 : case MAP_APPFONT:
249 : case MAP_REALAPPFONT:
250 : {
251 3240 : ImplSVData* pSVData = ImplGetSVData();
252 3240 : if ( !pSVData->maGDIData.mnAppFontX )
253 : {
254 0 : if( pSVData->maWinData.mpFirstFrame )
255 0 : Window::ImplInitAppFontData( pSVData->maWinData.mpFirstFrame );
256 : else
257 : {
258 0 : WorkWindow* pWin = new WorkWindow( NULL, 0 );
259 0 : Window::ImplInitAppFontData( pWin );
260 0 : delete pWin;
261 : }
262 : }
263 3240 : if ( rMapMode.GetMapUnit() == MAP_REALAPPFONT )
264 0 : rMapRes.mnMapScNumX = pSVData->maGDIData.mnRealAppFontX;
265 : else
266 3240 : rMapRes.mnMapScNumX = pSVData->maGDIData.mnAppFontX;
267 3240 : rMapRes.mnMapScDenomX = nDPIX * 40;
268 3240 : rMapRes.mnMapScNumY = pSVData->maGDIData.mnAppFontY;
269 3240 : rMapRes.mnMapScDenomY = nDPIY * 80;
270 : }
271 3240 : break;
272 : default:
273 : OSL_FAIL( "unhandled MapUnit" );
274 0 : break;
275 : }
276 :
277 375551 : Fraction aScaleX = rMapMode.GetScaleX();
278 375551 : Fraction aScaleY = rMapMode.GetScaleY();
279 :
280 : // Offset laut MapMode setzen
281 375551 : Point aOrigin = rMapMode.GetOrigin();
282 375551 : if ( rMapMode.GetMapUnit() != MAP_RELATIVE )
283 : {
284 375505 : rMapRes.mnMapOfsX = aOrigin.X();
285 375505 : rMapRes.mnMapOfsY = aOrigin.Y();
286 : }
287 : else
288 : {
289 46 : BigInt aX( rMapRes.mnMapOfsX );
290 46 : aX *= BigInt( aScaleX.GetDenominator() );
291 46 : if ( rMapRes.mnMapOfsX >= 0 )
292 : {
293 30 : if ( aScaleX.GetNumerator() >= 0 )
294 30 : aX += BigInt( aScaleX.GetNumerator()/2 );
295 : else
296 0 : aX -= BigInt( (aScaleX.GetNumerator()+1)/2 );
297 : }
298 : else
299 : {
300 16 : if ( aScaleX.GetNumerator() >= 0 )
301 16 : aX -= BigInt( (aScaleX.GetNumerator()-1)/2 );
302 : else
303 0 : aX += BigInt( aScaleX.GetNumerator()/2 );
304 : }
305 46 : aX /= BigInt( aScaleX.GetNumerator() );
306 46 : rMapRes.mnMapOfsX = (long)aX + aOrigin.X();
307 46 : BigInt aY( rMapRes.mnMapOfsY );
308 46 : aY *= BigInt( aScaleY.GetDenominator() );
309 46 : if( rMapRes.mnMapOfsY >= 0 )
310 : {
311 30 : if ( aScaleY.GetNumerator() >= 0 )
312 30 : aY += BigInt( aScaleY.GetNumerator()/2 );
313 : else
314 0 : aY -= BigInt( (aScaleY.GetNumerator()+1)/2 );
315 : }
316 : else
317 : {
318 16 : if ( aScaleY.GetNumerator() >= 0 )
319 16 : aY -= BigInt( (aScaleY.GetNumerator()-1)/2 );
320 : else
321 0 : aY += BigInt( aScaleY.GetNumerator()/2 );
322 : }
323 46 : aY /= BigInt( aScaleY.GetNumerator() );
324 46 : rMapRes.mnMapOfsY = (long)aY + aOrigin.Y();
325 : }
326 :
327 : // Scaling Faktor laut MapMode einberechnen
328 : // aTemp? = rMapRes.mnMapSc? * aScale?
329 : Fraction aTempX = ImplMakeFraction( rMapRes.mnMapScNumX,
330 : aScaleX.GetNumerator(),
331 : rMapRes.mnMapScDenomX,
332 375551 : aScaleX.GetDenominator() );
333 : Fraction aTempY = ImplMakeFraction( rMapRes.mnMapScNumY,
334 : aScaleY.GetNumerator(),
335 : rMapRes.mnMapScDenomY,
336 375551 : aScaleY.GetDenominator() );
337 375551 : rMapRes.mnMapScNumX = aTempX.GetNumerator();
338 375551 : rMapRes.mnMapScDenomX = aTempX.GetDenominator();
339 375551 : rMapRes.mnMapScNumY = aTempY.GetNumerator();
340 375551 : rMapRes.mnMapScDenomY = aTempY.GetDenominator();
341 :
342 : // hack: 0/n ungef"ahr 1/max
343 375551 : if ( !rMapRes.mnMapScNumX )
344 : {
345 0 : rMapRes.mnMapScNumX = 1;
346 0 : rMapRes.mnMapScDenomX = LONG_MAX;
347 : }
348 375551 : if ( !rMapRes.mnMapScNumY )
349 : {
350 0 : rMapRes.mnMapScNumY = 1;
351 0 : rMapRes.mnMapScDenomY = LONG_MAX;
352 : }
353 375551 : }
354 :
355 : // -----------------------------------------------------------------------
356 :
357 374435 : inline void ImplCalcMapResolution( const MapMode& rMapMode,
358 : long nDPIX, long nDPIY,
359 : ImplMapRes& rMapRes,
360 : ImplThresholdRes& rThresRes )
361 : {
362 374435 : ImplCalcMapResolution( rMapMode, nDPIX, nDPIY, rMapRes );
363 374435 : ImplCalcBigIntThreshold( nDPIX, nDPIY, rMapRes, rThresRes );
364 374435 : }
365 :
366 : // -----------------------------------------------------------------------
367 :
368 6388494 : static long ImplLogicToPixel( long n, long nDPI, long nMapNum, long nMapDenom,
369 : long nThres )
370 : {
371 : // To "use" it...
372 : (void) nThres;
373 : #if (SAL_TYPES_SIZEOFLONG < 8)
374 6388494 : if( (+n < nThres) && (-n < nThres) )
375 : {
376 6333675 : n *= nMapNum * nDPI;
377 12667350 : if( nMapDenom != 1 )
378 : {
379 6333091 : n = (2 * n) / nMapDenom;
380 6333091 : if( n < 0 ) --n; else ++n;
381 6333091 : n /= 2;
382 : }
383 : }
384 : else
385 : #endif
386 : {
387 54819 : sal_Int64 n64 = n;
388 54819 : n64 *= nMapNum;
389 54819 : n64 *= nDPI;
390 54819 : if( nMapDenom == 1 )
391 0 : n = (long)n64;
392 : else
393 : {
394 54819 : n = (long)(2 * n64 / nMapDenom);
395 54819 : if( n < 0 ) --n; else ++n;
396 54819 : n /= 2;
397 : }
398 : }
399 6388494 : return n;
400 : }
401 :
402 : // -----------------------------------------------------------------------
403 :
404 8882529 : static long ImplPixelToLogic( long n, long nDPI, long nMapNum, long nMapDenom,
405 : long nThres )
406 : {
407 : // To "use" it...
408 : (void) nThres;
409 : #if (SAL_TYPES_SIZEOFLONG < 8)
410 8882529 : if( (+n < nThres) && (-n < nThres) )
411 8838274 : n = (2 * n * nMapDenom) / (nDPI * nMapNum);
412 : else
413 : #endif
414 : {
415 44255 : sal_Int64 n64 = n;
416 44255 : n64 *= nMapDenom;
417 44255 : long nDenom = nDPI * nMapNum;
418 44255 : n = (long)(2 * n64 / nDenom);
419 : }
420 8882529 : if( n < 0 ) --n; else ++n;
421 8882529 : return (n / 2);
422 : }
423 :
424 : // -----------------------------------------------------------------------
425 :
426 318311 : long OutputDevice::ImplLogicXToDevicePixel( long nX ) const
427 : {
428 318311 : if ( !mbMap )
429 313239 : return nX+mnOutOffX;
430 :
431 : return ImplLogicToPixel( nX + maMapRes.mnMapOfsX, mnDPIX,
432 : maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
433 5072 : maThresRes.mnThresLogToPixX )+mnOutOffX+mnOutOffOrigX;
434 : }
435 :
436 : // -----------------------------------------------------------------------
437 :
438 333931 : long OutputDevice::ImplLogicYToDevicePixel( long nY ) const
439 : {
440 333931 : if ( !mbMap )
441 330482 : return nY+mnOutOffY;
442 :
443 : return ImplLogicToPixel( nY + maMapRes.mnMapOfsY, mnDPIY,
444 : maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
445 3449 : maThresRes.mnThresLogToPixY )+mnOutOffY+mnOutOffOrigY;
446 : }
447 :
448 : // -----------------------------------------------------------------------
449 :
450 1066907 : long OutputDevice::ImplLogicWidthToDevicePixel( long nWidth ) const
451 : {
452 1066907 : if ( !mbMap )
453 434924 : return nWidth;
454 :
455 : return ImplLogicToPixel( nWidth, mnDPIX,
456 : maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
457 631983 : maThresRes.mnThresLogToPixX );
458 : }
459 :
460 : // -----------------------------------------------------------------------
461 :
462 295434 : long OutputDevice::ImplLogicHeightToDevicePixel( long nHeight ) const
463 : {
464 295434 : if ( !mbMap )
465 294672 : return nHeight;
466 :
467 : return ImplLogicToPixel( nHeight, mnDPIY,
468 : maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
469 762 : maThresRes.mnThresLogToPixY );
470 : }
471 :
472 748148 : float OutputDevice::ImplFloatLogicHeightToDevicePixel( float fLogicHeight) const
473 : {
474 748148 : if( !mbMap)
475 57477 : return fLogicHeight;
476 690671 : float fPixelHeight = (fLogicHeight * mnDPIY * maMapRes.mnMapScNumY) / maMapRes.mnMapScDenomY;
477 690671 : return fPixelHeight;
478 : }
479 :
480 : // -----------------------------------------------------------------------
481 :
482 2344379 : long OutputDevice::ImplDevicePixelToLogicWidth( long nWidth ) const
483 : {
484 2344379 : if ( !mbMap )
485 476 : return nWidth;
486 :
487 : return ImplPixelToLogic( nWidth, mnDPIX,
488 : maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
489 2343903 : maThresRes.mnThresPixToLogX );
490 : }
491 :
492 : // -----------------------------------------------------------------------
493 :
494 3862096 : long OutputDevice::ImplDevicePixelToLogicHeight( long nHeight ) const
495 : {
496 3862096 : if ( !mbMap )
497 108840 : return nHeight;
498 :
499 : return ImplPixelToLogic( nHeight, mnDPIY,
500 : maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
501 3753256 : maThresRes.mnThresPixToLogY );
502 : }
503 :
504 : // -----------------------------------------------------------------------
505 :
506 1991732 : Point OutputDevice::ImplLogicToDevicePixel( const Point& rLogicPt ) const
507 : {
508 1991732 : if ( !mbMap )
509 1695624 : return Point( rLogicPt.X()+mnOutOffX, rLogicPt.Y()+mnOutOffY );
510 :
511 296108 : return Point( ImplLogicToPixel( rLogicPt.X() + maMapRes.mnMapOfsX, mnDPIX,
512 : maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
513 592216 : maThresRes.mnThresLogToPixX )+mnOutOffX+mnOutOffOrigX,
514 296108 : ImplLogicToPixel( rLogicPt.Y() + maMapRes.mnMapOfsY, mnDPIY,
515 : maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
516 888324 : maThresRes.mnThresLogToPixY )+mnOutOffY+mnOutOffOrigY );
517 : }
518 :
519 : // -----------------------------------------------------------------------
520 :
521 802155 : Size OutputDevice::ImplLogicToDevicePixel( const Size& rLogicSize ) const
522 : {
523 802155 : if ( !mbMap )
524 111109 : return rLogicSize;
525 :
526 : return Size( ImplLogicToPixel( rLogicSize.Width(), mnDPIX,
527 : maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
528 : maThresRes.mnThresLogToPixX ),
529 : ImplLogicToPixel( rLogicSize.Height(), mnDPIY,
530 : maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
531 691046 : maThresRes.mnThresLogToPixY ) );
532 : }
533 :
534 : // -----------------------------------------------------------------------
535 :
536 577427 : Rectangle OutputDevice::ImplLogicToDevicePixel( const Rectangle& rLogicRect ) const
537 : {
538 577427 : if ( rLogicRect.IsEmpty() )
539 10845 : return rLogicRect;
540 :
541 566582 : if ( !mbMap )
542 : {
543 1039742 : return Rectangle( rLogicRect.Left()+mnOutOffX, rLogicRect.Top()+mnOutOffY,
544 1559613 : rLogicRect.Right()+mnOutOffX, rLogicRect.Bottom()+mnOutOffY );
545 : }
546 :
547 46711 : return Rectangle( ImplLogicToPixel( rLogicRect.Left()+maMapRes.mnMapOfsX, mnDPIX,
548 : maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
549 93422 : maThresRes.mnThresLogToPixX )+mnOutOffX+mnOutOffOrigX,
550 46711 : ImplLogicToPixel( rLogicRect.Top()+maMapRes.mnMapOfsY, mnDPIY,
551 : maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
552 93422 : maThresRes.mnThresLogToPixY )+mnOutOffY+mnOutOffOrigY,
553 46711 : ImplLogicToPixel( rLogicRect.Right()+maMapRes.mnMapOfsX, mnDPIX,
554 : maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
555 93422 : maThresRes.mnThresLogToPixX )+mnOutOffX+mnOutOffOrigX,
556 46711 : ImplLogicToPixel( rLogicRect.Bottom()+maMapRes.mnMapOfsY, mnDPIY,
557 : maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
558 233555 : maThresRes.mnThresLogToPixY )+mnOutOffY+mnOutOffOrigY );
559 : }
560 :
561 : // -----------------------------------------------------------------------
562 :
563 348520 : Polygon OutputDevice::ImplLogicToDevicePixel( const Polygon& rLogicPoly ) const
564 : {
565 348520 : if ( !mbMap && !mnOutOffX && !mnOutOffY )
566 200571 : return rLogicPoly;
567 :
568 : sal_uInt16 i;
569 147949 : sal_uInt16 nPoints = rLogicPoly.GetSize();
570 147949 : Polygon aPoly( rLogicPoly );
571 :
572 : // Pointer auf das Point-Array holen (Daten werden kopiert)
573 147949 : const Point* pPointAry = aPoly.GetConstPointAry();
574 :
575 147949 : if ( mbMap )
576 : {
577 1004945 : for ( i = 0; i < nPoints; i++ )
578 : {
579 863288 : const Point* pPt = &(pPointAry[i]);
580 863288 : Point aPt;
581 1726576 : aPt.X() = ImplLogicToPixel( pPt->X()+maMapRes.mnMapOfsX, mnDPIX,
582 : maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
583 1726576 : maThresRes.mnThresLogToPixX )+mnOutOffX+mnOutOffOrigX;
584 1726576 : aPt.Y() = ImplLogicToPixel( pPt->Y()+maMapRes.mnMapOfsY, mnDPIY,
585 : maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
586 1726576 : maThresRes.mnThresLogToPixY )+mnOutOffY+mnOutOffOrigY;
587 863288 : aPoly[i] = aPt;
588 : }
589 : }
590 : else
591 : {
592 87602 : for ( i = 0; i < nPoints; i++ )
593 : {
594 81310 : Point aPt = pPointAry[i];
595 81310 : aPt.X() += mnOutOffX;
596 81310 : aPt.Y() += mnOutOffY;
597 81310 : aPoly[i] = aPt;
598 : }
599 : }
600 :
601 147949 : return aPoly;
602 : }
603 :
604 : // -----------------------------------------------------------------------
605 :
606 49425 : PolyPolygon OutputDevice::ImplLogicToDevicePixel( const PolyPolygon& rLogicPolyPoly ) const
607 : {
608 49425 : if ( !mbMap && !mnOutOffX && !mnOutOffY )
609 1981 : return rLogicPolyPoly;
610 :
611 47444 : PolyPolygon aPolyPoly( rLogicPolyPoly );
612 47444 : sal_uInt16 nPoly = aPolyPoly.Count();
613 95132 : for( sal_uInt16 i = 0; i < nPoly; i++ )
614 : {
615 47688 : Polygon& rPoly = aPolyPoly[i];
616 47688 : rPoly = ImplLogicToDevicePixel( rPoly );
617 : }
618 47444 : return aPolyPoly;
619 : }
620 :
621 : // -----------------------------------------------------------------------
622 :
623 132855 : LineInfo OutputDevice::ImplLogicToDevicePixel( const LineInfo& rLineInfo ) const
624 : {
625 132855 : LineInfo aInfo( rLineInfo );
626 :
627 132855 : if( aInfo.GetStyle() == LINE_DASH )
628 : {
629 0 : if( aInfo.GetDotCount() && aInfo.GetDotLen() )
630 0 : aInfo.SetDotLen( std::max( ImplLogicWidthToDevicePixel( aInfo.GetDotLen() ), 1L ) );
631 : else
632 0 : aInfo.SetDotCount( 0 );
633 :
634 0 : if( aInfo.GetDashCount() && aInfo.GetDashLen() )
635 0 : aInfo.SetDashLen( std::max( ImplLogicWidthToDevicePixel( aInfo.GetDashLen() ), 1L ) );
636 : else
637 0 : aInfo.SetDashCount( 0 );
638 :
639 0 : aInfo.SetDistance( ImplLogicWidthToDevicePixel( aInfo.GetDistance() ) );
640 :
641 0 : if( ( !aInfo.GetDashCount() && !aInfo.GetDotCount() ) || !aInfo.GetDistance() )
642 0 : aInfo.SetStyle( LINE_SOLID );
643 : }
644 :
645 132855 : aInfo.SetWidth( ImplLogicWidthToDevicePixel( aInfo.GetWidth() ) );
646 :
647 132855 : return aInfo;
648 : }
649 :
650 : // -----------------------------------------------------------------------
651 :
652 51215 : Rectangle OutputDevice::ImplDevicePixelToLogic( const Rectangle& rPixelRect ) const
653 : {
654 51215 : if ( rPixelRect.IsEmpty() )
655 0 : return rPixelRect;
656 :
657 51215 : if ( !mbMap )
658 : {
659 91626 : return Rectangle( rPixelRect.Left()-mnOutOffX, rPixelRect.Top()-mnOutOffY,
660 137439 : rPixelRect.Right()-mnOutOffX, rPixelRect.Bottom()-mnOutOffY );
661 : }
662 :
663 5402 : return Rectangle( ImplPixelToLogic( rPixelRect.Left()-mnOutOffX-mnOutOffOrigX, mnDPIX,
664 : maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
665 10804 : maThresRes.mnThresPixToLogX )-maMapRes.mnMapOfsX,
666 5402 : ImplPixelToLogic( rPixelRect.Top()-mnOutOffY-mnOutOffOrigY, mnDPIY,
667 : maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
668 10804 : maThresRes.mnThresPixToLogY )-maMapRes.mnMapOfsY,
669 5402 : ImplPixelToLogic( rPixelRect.Right()-mnOutOffX-mnOutOffOrigX, mnDPIX,
670 : maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
671 10804 : maThresRes.mnThresPixToLogX )-maMapRes.mnMapOfsX,
672 5402 : ImplPixelToLogic( rPixelRect.Bottom()-mnOutOffY-mnOutOffOrigY, mnDPIY,
673 : maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
674 27010 : maThresRes.mnThresPixToLogY )-maMapRes.mnMapOfsY );
675 : }
676 :
677 : // -----------------------------------------------------------------------
678 :
679 205163 : Region OutputDevice::ImplPixelToDevicePixel( const Region& rRegion ) const
680 : {
681 205163 : if ( !mnOutOffX && !mnOutOffY )
682 24775 : return rRegion;
683 :
684 180388 : Region aRegion( rRegion );
685 180388 : aRegion.Move( mnOutOffX+mnOutOffOrigX, mnOutOffY+mnOutOffOrigY );
686 180388 : return aRegion;
687 : }
688 :
689 : // -----------------------------------------------------------------------
690 :
691 533106 : void OutputDevice::EnableMapMode( sal_Bool bEnable )
692 : {
693 533106 : mbMap = (bEnable != 0);
694 :
695 533106 : if( mpAlphaVDev )
696 5058 : mpAlphaVDev->EnableMapMode( bEnable );
697 533106 : }
698 :
699 : // -----------------------------------------------------------------------
700 :
701 51977 : void OutputDevice::SetMapMode()
702 : {
703 : DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice );
704 :
705 51977 : if ( mpMetaFile )
706 0 : mpMetaFile->AddAction( new MetaMapModeAction( MapMode() ) );
707 :
708 51977 : if ( mbMap || !maMapMode.IsDefault() )
709 : {
710 49310 : mbMap = sal_False;
711 49310 : maMapMode = MapMode();
712 :
713 : // create new objects (clip region werden nicht neu skaliert)
714 49310 : mbNewFont = sal_True;
715 49310 : mbInitFont = sal_True;
716 49310 : if ( GetOutDevType() == OUTDEV_WINDOW )
717 : {
718 18832 : if ( ((Window*)this)->mpWindowImpl->mpCursor )
719 18759 : ((Window*)this)->mpWindowImpl->mpCursor->ImplNew();
720 : }
721 :
722 : // #106426# Adapt logical offset when changing mapmode
723 49310 : mnOutOffLogicX = mnOutOffOrigX; // no mapping -> equal offsets
724 49310 : mnOutOffLogicY = mnOutOffOrigY;
725 :
726 : // #i75163#
727 49310 : ImplInvalidateViewTransform();
728 : }
729 :
730 51977 : if( mpAlphaVDev )
731 0 : mpAlphaVDev->SetMapMode();
732 51977 : }
733 :
734 : // -----------------------------------------------------------------------
735 :
736 199587 : void OutputDevice::SetMapMode( const MapMode& rNewMapMode )
737 : {
738 : DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice );
739 :
740 199587 : bool bRelMap = (rNewMapMode.GetMapUnit() == MAP_RELATIVE);
741 :
742 199587 : if ( mpMetaFile )
743 : {
744 203 : mpMetaFile->AddAction( new MetaMapModeAction( rNewMapMode ) );
745 : #ifdef DBG_UTIL
746 : if ( GetOutDevType() != OUTDEV_PRINTER )
747 : DBG_ASSERTWARNING( bRelMap, "Please record only relative MapModes!" );
748 : #endif
749 : }
750 :
751 : // Ist der MapMode der gleiche wie vorher, dann mache nichts
752 199587 : if ( maMapMode == rNewMapMode )
753 91409 : return;
754 :
755 108178 : if( mpAlphaVDev )
756 360 : mpAlphaVDev->SetMapMode( rNewMapMode );
757 :
758 : // Ist Default-MapMode, dann bereche nichts
759 108178 : bool bOldMap = mbMap;
760 108178 : mbMap = !rNewMapMode.IsDefault();
761 108178 : if ( mbMap )
762 : {
763 : // Falls nur der Orign umgesetzt wird, dann scaliere nichts neu
764 212257 : if ( (rNewMapMode.GetMapUnit() == maMapMode.GetMapUnit()) &&
765 23119 : (rNewMapMode.GetScaleX() == maMapMode.GetScaleX()) &&
766 122464 : (rNewMapMode.GetScaleY() == maMapMode.GetScaleY()) &&
767 11095 : (bOldMap == mbMap) )
768 : {
769 : // Offset setzen
770 1567 : Point aOrigin = rNewMapMode.GetOrigin();
771 1567 : maMapRes.mnMapOfsX = aOrigin.X();
772 1567 : maMapRes.mnMapOfsY = aOrigin.Y();
773 1567 : maMapMode = rNewMapMode;
774 :
775 : // #i75163#
776 1567 : ImplInvalidateViewTransform();
777 :
778 1567 : return;
779 : }
780 98602 : if ( !bOldMap && bRelMap )
781 : {
782 0 : maMapRes.mnMapScNumX = 1;
783 0 : maMapRes.mnMapScNumY = 1;
784 0 : maMapRes.mnMapScDenomX = mnDPIX;
785 0 : maMapRes.mnMapScDenomY = mnDPIY;
786 0 : maMapRes.mnMapOfsX = 0;
787 0 : maMapRes.mnMapOfsY = 0;
788 : }
789 :
790 : // Neue MapMode-Aufloesung berechnen
791 98602 : ImplCalcMapResolution( rNewMapMode, mnDPIX, mnDPIY, maMapRes, maThresRes );
792 : }
793 :
794 : // Neuen MapMode setzen
795 106611 : if ( bRelMap )
796 : {
797 46 : Point aOrigin( maMapRes.mnMapOfsX, maMapRes.mnMapOfsY );
798 : // aScale? = maMapMode.GetScale?() * rNewMapMode.GetScale?()
799 46 : Fraction aScaleX = ImplMakeFraction( maMapMode.GetScaleX().GetNumerator(),
800 46 : rNewMapMode.GetScaleX().GetNumerator(),
801 46 : maMapMode.GetScaleX().GetDenominator(),
802 184 : rNewMapMode.GetScaleX().GetDenominator() );
803 46 : Fraction aScaleY = ImplMakeFraction( maMapMode.GetScaleY().GetNumerator(),
804 46 : rNewMapMode.GetScaleY().GetNumerator(),
805 46 : maMapMode.GetScaleY().GetDenominator(),
806 184 : rNewMapMode.GetScaleY().GetDenominator() );
807 46 : maMapMode.SetOrigin( aOrigin );
808 46 : maMapMode.SetScaleX( aScaleX );
809 46 : maMapMode.SetScaleY( aScaleY );
810 : }
811 : else
812 106565 : maMapMode = rNewMapMode;
813 :
814 : // create new objects (clip region werden nicht neu skaliert)
815 106611 : mbNewFont = sal_True;
816 106611 : mbInitFont = sal_True;
817 106611 : if ( GetOutDevType() == OUTDEV_WINDOW )
818 : {
819 23437 : if ( ((Window*)this)->mpWindowImpl->mpCursor )
820 18850 : ((Window*)this)->mpWindowImpl->mpCursor->ImplNew();
821 : }
822 :
823 : // #106426# Adapt logical offset when changing mapmode
824 : mnOutOffLogicX = ImplPixelToLogic( mnOutOffOrigX, mnDPIX,
825 : maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
826 106611 : maThresRes.mnThresPixToLogX );
827 : mnOutOffLogicY = ImplPixelToLogic( mnOutOffOrigY, mnDPIY,
828 : maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
829 106611 : maThresRes.mnThresPixToLogY );
830 :
831 : // #i75163#
832 106611 : ImplInvalidateViewTransform();
833 : }
834 :
835 : // -----------------------------------------------------------------------
836 :
837 2694 : void OutputDevice::SetRelativeMapMode( const MapMode& rNewMapMode )
838 : {
839 : DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice );
840 :
841 : // Ist der MapMode der gleiche wie vorher, dann mache nichts
842 2694 : if ( maMapMode == rNewMapMode )
843 5365 : return;
844 :
845 23 : MapUnit eOld = maMapMode.GetMapUnit();
846 23 : MapUnit eNew = rNewMapMode.GetMapUnit();
847 :
848 : // a?F = rNewMapMode.GetScale?() / maMapMode.GetScale?()
849 23 : Fraction aXF = ImplMakeFraction( rNewMapMode.GetScaleX().GetNumerator(),
850 23 : maMapMode.GetScaleX().GetDenominator(),
851 23 : rNewMapMode.GetScaleX().GetDenominator(),
852 92 : maMapMode.GetScaleX().GetNumerator() );
853 23 : Fraction aYF = ImplMakeFraction( rNewMapMode.GetScaleY().GetNumerator(),
854 23 : maMapMode.GetScaleY().GetDenominator(),
855 23 : rNewMapMode.GetScaleY().GetDenominator(),
856 92 : maMapMode.GetScaleY().GetNumerator() );
857 :
858 23 : Point aPt( LogicToLogic( Point(), NULL, &rNewMapMode ) );
859 23 : if ( eNew != eOld )
860 : {
861 8 : if ( eOld > MAP_PIXEL )
862 : {
863 : SAL_WARN( "vcl.gdi", "Not implemented MapUnit" );
864 : }
865 8 : else if ( eNew > MAP_PIXEL )
866 : {
867 : SAL_WARN( "vcl.gdi", "Not implemented MapUnit" );
868 : }
869 : else
870 : {
871 8 : Fraction aF( aImplNumeratorAry[eNew] * aImplDenominatorAry[eOld],
872 16 : aImplNumeratorAry[eOld] * aImplDenominatorAry[eNew] );
873 :
874 : // a?F = a?F * aF
875 16 : aXF = ImplMakeFraction( aXF.GetNumerator(), aF.GetNumerator(),
876 8 : aXF.GetDenominator(), aF.GetDenominator() );
877 16 : aYF = ImplMakeFraction( aYF.GetNumerator(), aF.GetNumerator(),
878 8 : aYF.GetDenominator(), aF.GetDenominator() );
879 8 : if ( eOld == MAP_PIXEL )
880 : {
881 0 : aXF *= Fraction( mnDPIX, 1 );
882 0 : aYF *= Fraction( mnDPIY, 1 );
883 : }
884 8 : else if ( eNew == MAP_PIXEL )
885 : {
886 0 : aXF *= Fraction( 1, mnDPIX );
887 0 : aYF *= Fraction( 1, mnDPIY );
888 : }
889 : }
890 : }
891 :
892 23 : MapMode aNewMapMode( MAP_RELATIVE, Point( -aPt.X(), -aPt.Y() ), aXF, aYF );
893 23 : SetMapMode( aNewMapMode );
894 :
895 23 : if ( eNew != eOld )
896 8 : maMapMode = rNewMapMode;
897 :
898 : // #106426# Adapt logical offset when changing mapmode
899 : mnOutOffLogicX = ImplPixelToLogic( mnOutOffOrigX, mnDPIX,
900 : maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
901 23 : maThresRes.mnThresPixToLogX );
902 : mnOutOffLogicY = ImplPixelToLogic( mnOutOffOrigY, mnDPIY,
903 : maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
904 23 : maThresRes.mnThresPixToLogY );
905 :
906 23 : if( mpAlphaVDev )
907 0 : mpAlphaVDev->SetRelativeMapMode( rNewMapMode );
908 : }
909 :
910 : // -----------------------------------------------------------------------
911 :
912 : // #i75163#
913 105606 : basegfx::B2DHomMatrix OutputDevice::GetViewTransformation() const
914 : {
915 105606 : if(mbMap)
916 : {
917 : // #i82615#
918 100141 : if(!mpOutDevData)
919 : {
920 943 : const_cast< OutputDevice* >(this)->ImplInitOutDevData();
921 : }
922 :
923 100141 : if(!mpOutDevData->mpViewTransform)
924 : {
925 24858 : mpOutDevData->mpViewTransform = new basegfx::B2DHomMatrix;
926 :
927 24858 : const double fScaleFactorX((double)mnDPIX * (double)maMapRes.mnMapScNumX / (double)maMapRes.mnMapScDenomX);
928 24858 : const double fScaleFactorY((double)mnDPIY * (double)maMapRes.mnMapScNumY / (double)maMapRes.mnMapScDenomY);
929 24858 : const double fZeroPointX(((double)maMapRes.mnMapOfsX * fScaleFactorX) + (double)mnOutOffOrigX);
930 24858 : const double fZeroPointY(((double)maMapRes.mnMapOfsY * fScaleFactorY) + (double)mnOutOffOrigY);
931 :
932 24858 : mpOutDevData->mpViewTransform->set(0, 0, fScaleFactorX);
933 24858 : mpOutDevData->mpViewTransform->set(1, 1, fScaleFactorY);
934 24858 : mpOutDevData->mpViewTransform->set(0, 2, fZeroPointX);
935 24858 : mpOutDevData->mpViewTransform->set(1, 2, fZeroPointY);
936 : }
937 :
938 100141 : return *mpOutDevData->mpViewTransform;
939 : }
940 : else
941 : {
942 5465 : return basegfx::B2DHomMatrix();
943 : }
944 : }
945 :
946 : // -----------------------------------------------------------------------
947 :
948 : // #i75163#
949 27852 : basegfx::B2DHomMatrix OutputDevice::GetInverseViewTransformation() const
950 : {
951 27852 : if(mbMap)
952 : {
953 : // #i82615#
954 27852 : if(!mpOutDevData)
955 : {
956 330 : const_cast< OutputDevice* >(this)->ImplInitOutDevData();
957 : }
958 :
959 27852 : if(!mpOutDevData->mpInverseViewTransform)
960 : {
961 12548 : GetViewTransformation();
962 12548 : mpOutDevData->mpInverseViewTransform = new basegfx::B2DHomMatrix(*mpOutDevData->mpViewTransform);
963 12548 : mpOutDevData->mpInverseViewTransform->invert();
964 : }
965 :
966 27852 : return *mpOutDevData->mpInverseViewTransform;
967 : }
968 : else
969 : {
970 0 : return basegfx::B2DHomMatrix();
971 : }
972 : }
973 :
974 : // -----------------------------------------------------------------------
975 :
976 : // #i75163#
977 0 : basegfx::B2DHomMatrix OutputDevice::GetViewTransformation( const MapMode& rMapMode ) const
978 : {
979 : // #i82615#
980 : ImplMapRes aMapRes;
981 : ImplThresholdRes aThresRes;
982 0 : ImplCalcMapResolution( rMapMode, mnDPIX, mnDPIY, aMapRes, aThresRes );
983 :
984 0 : basegfx::B2DHomMatrix aTransform;
985 :
986 0 : const double fScaleFactorX((double)mnDPIX * (double)aMapRes.mnMapScNumX / (double)aMapRes.mnMapScDenomX);
987 0 : const double fScaleFactorY((double)mnDPIY * (double)aMapRes.mnMapScNumY / (double)aMapRes.mnMapScDenomY);
988 0 : const double fZeroPointX(((double)aMapRes.mnMapOfsX * fScaleFactorX) + (double)mnOutOffOrigX);
989 0 : const double fZeroPointY(((double)aMapRes.mnMapOfsY * fScaleFactorY) + (double)mnOutOffOrigY);
990 :
991 0 : aTransform.set(0, 0, fScaleFactorX);
992 0 : aTransform.set(1, 1, fScaleFactorY);
993 0 : aTransform.set(0, 2, fZeroPointX);
994 0 : aTransform.set(1, 2, fZeroPointY);
995 :
996 0 : return aTransform;
997 : }
998 :
999 : // -----------------------------------------------------------------------
1000 :
1001 : // #i75163#
1002 0 : basegfx::B2DHomMatrix OutputDevice::GetInverseViewTransformation( const MapMode& rMapMode ) const
1003 : {
1004 0 : basegfx::B2DHomMatrix aMatrix( GetViewTransformation( rMapMode ) );
1005 0 : aMatrix.invert();
1006 0 : return aMatrix;
1007 : }
1008 :
1009 : // -----------------------------------------------------------------------
1010 :
1011 0 : basegfx::B2DHomMatrix OutputDevice::ImplGetDeviceTransformation() const
1012 : {
1013 0 : basegfx::B2DHomMatrix aTransformation = GetViewTransformation();
1014 : // TODO: is it worth to cache the transformed result?
1015 0 : if( mnOutOffX || mnOutOffY )
1016 0 : aTransformation.translate( mnOutOffX, mnOutOffY );
1017 0 : return aTransformation;
1018 : }
1019 :
1020 : // -----------------------------------------------------------------------
1021 :
1022 193194 : Point OutputDevice::LogicToPixel( const Point& rLogicPt ) const
1023 : {
1024 : DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice );
1025 :
1026 193194 : if ( !mbMap )
1027 88269 : return rLogicPt;
1028 :
1029 104925 : return Point( ImplLogicToPixel( rLogicPt.X() + maMapRes.mnMapOfsX, mnDPIX,
1030 : maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
1031 209850 : maThresRes.mnThresLogToPixX )+mnOutOffOrigX,
1032 104925 : ImplLogicToPixel( rLogicPt.Y() + maMapRes.mnMapOfsY, mnDPIY,
1033 : maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
1034 314775 : maThresRes.mnThresLogToPixY )+mnOutOffOrigY );
1035 : }
1036 :
1037 : // -----------------------------------------------------------------------
1038 :
1039 198660 : Size OutputDevice::LogicToPixel( const Size& rLogicSize ) const
1040 : {
1041 : DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice );
1042 :
1043 198660 : if ( !mbMap )
1044 82091 : return rLogicSize;
1045 :
1046 : return Size( ImplLogicToPixel( rLogicSize.Width(), mnDPIX,
1047 : maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
1048 : maThresRes.mnThresLogToPixX ),
1049 : ImplLogicToPixel( rLogicSize.Height(), mnDPIY,
1050 : maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
1051 116569 : maThresRes.mnThresLogToPixY ) );
1052 : }
1053 :
1054 : // -----------------------------------------------------------------------
1055 :
1056 498250 : Rectangle OutputDevice::LogicToPixel( const Rectangle& rLogicRect ) const
1057 : {
1058 : DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice );
1059 :
1060 498250 : if ( !mbMap || rLogicRect.IsEmpty() )
1061 273135 : return rLogicRect;
1062 :
1063 225115 : return Rectangle( ImplLogicToPixel( rLogicRect.Left() + maMapRes.mnMapOfsX, mnDPIX,
1064 : maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
1065 450230 : maThresRes.mnThresLogToPixX )+mnOutOffOrigX,
1066 225115 : ImplLogicToPixel( rLogicRect.Top() + maMapRes.mnMapOfsY, mnDPIY,
1067 : maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
1068 450230 : maThresRes.mnThresLogToPixY )+mnOutOffOrigY,
1069 225115 : ImplLogicToPixel( rLogicRect.Right() + maMapRes.mnMapOfsX, mnDPIX,
1070 : maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
1071 450230 : maThresRes.mnThresLogToPixX )+mnOutOffOrigX,
1072 225115 : ImplLogicToPixel( rLogicRect.Bottom() + maMapRes.mnMapOfsY, mnDPIY,
1073 : maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
1074 1125575 : maThresRes.mnThresLogToPixY )+mnOutOffOrigY );
1075 : }
1076 :
1077 : // -----------------------------------------------------------------------
1078 :
1079 446 : Polygon OutputDevice::LogicToPixel( const Polygon& rLogicPoly ) const
1080 : {
1081 : DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice );
1082 : DBG_CHKOBJ( &rLogicPoly, Polygon, NULL );
1083 :
1084 446 : if ( !mbMap )
1085 0 : return rLogicPoly;
1086 :
1087 : sal_uInt16 i;
1088 446 : sal_uInt16 nPoints = rLogicPoly.GetSize();
1089 446 : Polygon aPoly( rLogicPoly );
1090 :
1091 : // Pointer auf das Point-Array holen (Daten werden kopiert)
1092 446 : const Point* pPointAry = aPoly.GetConstPointAry();
1093 :
1094 7476 : for ( i = 0; i < nPoints; i++ )
1095 : {
1096 7030 : const Point* pPt = &(pPointAry[i]);
1097 7030 : Point aPt;
1098 14060 : aPt.X() = ImplLogicToPixel( pPt->X() + maMapRes.mnMapOfsX, mnDPIX,
1099 : maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
1100 14060 : maThresRes.mnThresLogToPixX )+mnOutOffOrigX;
1101 14060 : aPt.Y() = ImplLogicToPixel( pPt->Y() + maMapRes.mnMapOfsY, mnDPIY,
1102 : maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
1103 14060 : maThresRes.mnThresLogToPixY )+mnOutOffOrigY;
1104 7030 : aPoly[i] = aPt;
1105 : }
1106 :
1107 446 : return aPoly;
1108 : }
1109 :
1110 : // -----------------------------------------------------------------------
1111 :
1112 3109 : PolyPolygon OutputDevice::LogicToPixel( const PolyPolygon& rLogicPolyPoly ) const
1113 : {
1114 : DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice );
1115 : DBG_CHKOBJ( &rLogicPolyPoly, PolyPolygon, NULL );
1116 :
1117 3109 : if ( !mbMap )
1118 2674 : return rLogicPolyPoly;
1119 :
1120 435 : PolyPolygon aPolyPoly( rLogicPolyPoly );
1121 435 : sal_uInt16 nPoly = aPolyPoly.Count();
1122 881 : for( sal_uInt16 i = 0; i < nPoly; i++ )
1123 : {
1124 446 : Polygon& rPoly = aPolyPoly[i];
1125 446 : rPoly = LogicToPixel( rPoly );
1126 : }
1127 435 : return aPolyPoly;
1128 : }
1129 :
1130 : // -----------------------------------------------------------------------
1131 :
1132 0 : basegfx::B2DPolygon OutputDevice::LogicToPixel( const basegfx::B2DPolygon& rLogicPoly ) const
1133 : {
1134 0 : basegfx::B2DPolygon aTransformedPoly = rLogicPoly;
1135 0 : const ::basegfx::B2DHomMatrix& rTransformationMatrix = GetViewTransformation();
1136 0 : aTransformedPoly.transform( rTransformationMatrix );
1137 0 : return aTransformedPoly;
1138 : }
1139 :
1140 : // -----------------------------------------------------------------------
1141 :
1142 37 : basegfx::B2DPolyPolygon OutputDevice::LogicToPixel( const basegfx::B2DPolyPolygon& rLogicPolyPoly ) const
1143 : {
1144 37 : basegfx::B2DPolyPolygon aTransformedPoly = rLogicPolyPoly;
1145 74 : const ::basegfx::B2DHomMatrix& rTransformationMatrix = GetViewTransformation();
1146 37 : aTransformedPoly.transform( rTransformationMatrix );
1147 74 : return aTransformedPoly;
1148 : }
1149 :
1150 : // -----------------------------------------------------------------------
1151 :
1152 158465 : Region OutputDevice::LogicToPixel( const Region& rLogicRegion ) const
1153 : {
1154 : DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice );
1155 :
1156 158465 : if(!mbMap || rLogicRegion.IsNull() || rLogicRegion.IsEmpty())
1157 : {
1158 114256 : return rLogicRegion;
1159 : }
1160 :
1161 44209 : Region aRegion;
1162 :
1163 44209 : if(rLogicRegion.getB2DPolyPolygon())
1164 : {
1165 37 : aRegion = Region(LogicToPixel(*rLogicRegion.getB2DPolyPolygon()));
1166 : }
1167 44172 : else if(rLogicRegion.getPolyPolygon())
1168 : {
1169 11 : aRegion = Region(LogicToPixel(*rLogicRegion.getPolyPolygon()));
1170 : }
1171 44161 : else if(rLogicRegion.getRegionBand())
1172 : {
1173 44161 : RectangleVector aRectangles;
1174 44161 : rLogicRegion.GetRegionRectangles(aRectangles);
1175 44161 : const RectangleVector& rRectangles(aRectangles); // needed to make the '!=' work
1176 :
1177 : // make reverse run to fill new region bottom-up, this will speed it up due to the used data structuring
1178 90488 : for(RectangleVector::const_reverse_iterator aRectIter(rRectangles.rbegin()); aRectIter != rRectangles.rend(); ++aRectIter)
1179 : {
1180 46327 : aRegion.Union(LogicToPixel(*aRectIter));
1181 44161 : }
1182 :
1183 : //long nX(0);
1184 : //long nY(0);
1185 : //long nWidth(0);
1186 : //long nHeight(0);
1187 : //ImplRegionInfo aInfo;
1188 : //aRegion.ImplBeginAddRect();
1189 : //bool bRegionRect(rLogicRegion.ImplGetFirstRect(aInfo, nX, nY, nWidth, nHeight));
1190 : //
1191 : //while(bRegionRect)
1192 : //{
1193 : // const Rectangle aRect(Point(nX, nY), Size(nWidth, nHeight));
1194 : // aRegion.ImplAddRect(LogicToPixel(aRect));
1195 : // bRegionRect = rLogicRegion.ImplGetNextRect(aInfo, nX, nY, nWidth, nHeight);
1196 : //}
1197 : //
1198 : //aRegion.ImplEndAddRect();
1199 : }
1200 :
1201 44209 : return aRegion;
1202 : }
1203 :
1204 : // -----------------------------------------------------------------------
1205 :
1206 4065 : Point OutputDevice::LogicToPixel( const Point& rLogicPt,
1207 : const MapMode& rMapMode ) const
1208 : {
1209 : DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice );
1210 :
1211 4065 : if ( rMapMode.IsDefault() )
1212 12 : return rLogicPt;
1213 :
1214 : // MapMode-Aufloesung berechnen und Umrechnen
1215 : ImplMapRes aMapRes;
1216 : ImplThresholdRes aThresRes;
1217 4053 : ImplCalcMapResolution( rMapMode, mnDPIX, mnDPIY, aMapRes, aThresRes );
1218 :
1219 4053 : return Point( ImplLogicToPixel( rLogicPt.X() + aMapRes.mnMapOfsX, mnDPIX,
1220 : aMapRes.mnMapScNumX, aMapRes.mnMapScDenomX,
1221 8106 : aThresRes.mnThresLogToPixX )+mnOutOffOrigX,
1222 4053 : ImplLogicToPixel( rLogicPt.Y() + aMapRes.mnMapOfsY, mnDPIY,
1223 : aMapRes.mnMapScNumY, aMapRes.mnMapScDenomY,
1224 12159 : aThresRes.mnThresLogToPixY )+mnOutOffOrigY );
1225 : }
1226 :
1227 : // -----------------------------------------------------------------------
1228 :
1229 240657 : Size OutputDevice::LogicToPixel( const Size& rLogicSize,
1230 : const MapMode& rMapMode ) const
1231 : {
1232 : DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice );
1233 :
1234 240657 : if ( rMapMode.IsDefault() )
1235 0 : return rLogicSize;
1236 :
1237 : // MapMode-Aufloesung berechnen und Umrechnen
1238 : ImplMapRes aMapRes;
1239 : ImplThresholdRes aThresRes;
1240 240657 : ImplCalcMapResolution( rMapMode, mnDPIX, mnDPIY, aMapRes, aThresRes );
1241 :
1242 : return Size( ImplLogicToPixel( rLogicSize.Width(), mnDPIX,
1243 : aMapRes.mnMapScNumX, aMapRes.mnMapScDenomX,
1244 : aThresRes.mnThresLogToPixX ),
1245 : ImplLogicToPixel( rLogicSize.Height(), mnDPIY,
1246 : aMapRes.mnMapScNumY, aMapRes.mnMapScDenomY,
1247 240657 : aThresRes.mnThresLogToPixY ) );
1248 : }
1249 :
1250 : // -----------------------------------------------------------------------
1251 :
1252 3147 : Rectangle OutputDevice::LogicToPixel( const Rectangle& rLogicRect,
1253 : const MapMode& rMapMode ) const
1254 : {
1255 : DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice );
1256 :
1257 3147 : if ( rMapMode.IsDefault() || rLogicRect.IsEmpty() )
1258 4 : return rLogicRect;
1259 :
1260 : // MapMode-Aufloesung berechnen und Umrechnen
1261 : ImplMapRes aMapRes;
1262 : ImplThresholdRes aThresRes;
1263 3143 : ImplCalcMapResolution( rMapMode, mnDPIX, mnDPIY, aMapRes, aThresRes );
1264 :
1265 3143 : return Rectangle( ImplLogicToPixel( rLogicRect.Left() + aMapRes.mnMapOfsX, mnDPIX,
1266 : aMapRes.mnMapScNumX, aMapRes.mnMapScDenomX,
1267 6286 : aThresRes.mnThresLogToPixX )+mnOutOffOrigX,
1268 3143 : ImplLogicToPixel( rLogicRect.Top() + aMapRes.mnMapOfsY, mnDPIY,
1269 : aMapRes.mnMapScNumY, aMapRes.mnMapScDenomY,
1270 6286 : aThresRes.mnThresLogToPixY )+mnOutOffOrigY,
1271 3143 : ImplLogicToPixel( rLogicRect.Right() + aMapRes.mnMapOfsX, mnDPIX,
1272 : aMapRes.mnMapScNumX, aMapRes.mnMapScDenomX,
1273 6286 : aThresRes.mnThresLogToPixX )+mnOutOffOrigX,
1274 3143 : ImplLogicToPixel( rLogicRect.Bottom() + aMapRes.mnMapOfsY, mnDPIY,
1275 : aMapRes.mnMapScNumY, aMapRes.mnMapScDenomY,
1276 15715 : aThresRes.mnThresLogToPixY )+mnOutOffOrigY );
1277 : }
1278 :
1279 : // -----------------------------------------------------------------------
1280 :
1281 0 : Polygon OutputDevice::LogicToPixel( const Polygon& rLogicPoly,
1282 : const MapMode& rMapMode ) const
1283 : {
1284 : DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice );
1285 : DBG_CHKOBJ( &rLogicPoly, Polygon, NULL );
1286 :
1287 0 : if ( rMapMode.IsDefault() )
1288 0 : return rLogicPoly;
1289 :
1290 : // MapMode-Aufloesung berechnen und Umrechnen
1291 : ImplMapRes aMapRes;
1292 : ImplThresholdRes aThresRes;
1293 0 : ImplCalcMapResolution( rMapMode, mnDPIX, mnDPIY, aMapRes, aThresRes );
1294 :
1295 : sal_uInt16 i;
1296 0 : sal_uInt16 nPoints = rLogicPoly.GetSize();
1297 0 : Polygon aPoly( rLogicPoly );
1298 :
1299 : // Pointer auf das Point-Array holen (Daten werden kopiert)
1300 0 : const Point* pPointAry = aPoly.GetConstPointAry();
1301 :
1302 0 : for ( i = 0; i < nPoints; i++ )
1303 : {
1304 0 : const Point* pPt = &(pPointAry[i]);
1305 0 : Point aPt;
1306 0 : aPt.X() = ImplLogicToPixel( pPt->X() + aMapRes.mnMapOfsX, mnDPIX,
1307 : aMapRes.mnMapScNumX, aMapRes.mnMapScDenomX,
1308 0 : aThresRes.mnThresLogToPixX )+mnOutOffOrigX;
1309 0 : aPt.Y() = ImplLogicToPixel( pPt->Y() + aMapRes.mnMapOfsY, mnDPIY,
1310 : aMapRes.mnMapScNumY, aMapRes.mnMapScDenomY,
1311 0 : aThresRes.mnThresLogToPixY )+mnOutOffOrigY;
1312 0 : aPoly[i] = aPt;
1313 : }
1314 :
1315 0 : return aPoly;
1316 : }
1317 :
1318 : // -----------------------------------------------------------------------
1319 :
1320 0 : PolyPolygon OutputDevice::LogicToPixel( const PolyPolygon& rLogicPolyPoly,
1321 : const MapMode& rMapMode ) const
1322 : {
1323 : DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice );
1324 : DBG_CHKOBJ( &rLogicPolyPoly, PolyPolygon, NULL );
1325 :
1326 0 : if ( rMapMode.IsDefault() )
1327 0 : return rLogicPolyPoly;
1328 :
1329 0 : PolyPolygon aPolyPoly( rLogicPolyPoly );
1330 0 : sal_uInt16 nPoly = aPolyPoly.Count();
1331 0 : for( sal_uInt16 i = 0; i < nPoly; i++ )
1332 : {
1333 0 : Polygon& rPoly = aPolyPoly[i];
1334 0 : rPoly = LogicToPixel( rPoly, rMapMode );
1335 : }
1336 0 : return aPolyPoly;
1337 : }
1338 :
1339 : // -----------------------------------------------------------------------
1340 :
1341 0 : basegfx::B2DPolyPolygon OutputDevice::LogicToPixel( const basegfx::B2DPolyPolygon& rLogicPolyPoly,
1342 : const MapMode& rMapMode ) const
1343 : {
1344 0 : basegfx::B2DPolyPolygon aTransformedPoly = rLogicPolyPoly;
1345 0 : const ::basegfx::B2DHomMatrix& rTransformationMatrix = GetViewTransformation( rMapMode );
1346 0 : aTransformedPoly.transform( rTransformationMatrix );
1347 0 : return aTransformedPoly;
1348 : }
1349 :
1350 : // -----------------------------------------------------------------------
1351 :
1352 0 : basegfx::B2DPolygon OutputDevice::LogicToPixel( const basegfx::B2DPolygon& rLogicPoly,
1353 : const MapMode& rMapMode ) const
1354 : {
1355 0 : basegfx::B2DPolygon aTransformedPoly = rLogicPoly;
1356 0 : const ::basegfx::B2DHomMatrix& rTransformationMatrix = GetViewTransformation( rMapMode );
1357 0 : aTransformedPoly.transform( rTransformationMatrix );
1358 0 : return aTransformedPoly;
1359 : }
1360 :
1361 : // -----------------------------------------------------------------------
1362 :
1363 0 : Region OutputDevice::LogicToPixel( const Region& rLogicRegion, const MapMode& rMapMode ) const
1364 : {
1365 : DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice );
1366 :
1367 0 : if(rMapMode.IsDefault() || rLogicRegion.IsNull() || rLogicRegion.IsEmpty())
1368 : {
1369 0 : return rLogicRegion;
1370 : }
1371 :
1372 0 : Region aRegion;
1373 :
1374 0 : if(rLogicRegion.getB2DPolyPolygon())
1375 : {
1376 0 : aRegion = Region(LogicToPixel(*rLogicRegion.getB2DPolyPolygon(), rMapMode));
1377 : }
1378 0 : else if(rLogicRegion.getPolyPolygon())
1379 : {
1380 0 : aRegion = Region(LogicToPixel(*rLogicRegion.getPolyPolygon(), rMapMode));
1381 : }
1382 0 : else if(rLogicRegion.getRegionBand())
1383 : {
1384 0 : RectangleVector aRectangles;
1385 0 : rLogicRegion.GetRegionRectangles(aRectangles);
1386 0 : const RectangleVector& rRectangles(aRectangles); // needed to make the '!=' work
1387 :
1388 : // make reverse run to fill new region bottom-up, this will speed it up due to the used data structuring
1389 0 : for(RectangleVector::const_reverse_iterator aRectIter(rRectangles.rbegin()); aRectIter != rRectangles.rend(); ++aRectIter)
1390 : {
1391 0 : aRegion.Union(LogicToPixel(*aRectIter, rMapMode));
1392 0 : }
1393 :
1394 : //long nX(0);
1395 : //long nY(0);
1396 : //long nWidth(0);
1397 : //long nHeight(0);
1398 : //ImplRegionInfo aInfo;
1399 : //aRegion.ImplBeginAddRect();
1400 : //bool bRegionRect(rLogicRegion.ImplGetFirstRect(aInfo, nX, nY, nWidth, nHeight));
1401 : //
1402 : //while(bRegionRect)
1403 : //{
1404 : // const Rectangle aRect(Point(nX, nY), Size(nWidth, nHeight));
1405 : // aRegion.ImplAddRect(LogicToPixel(aRect, rMapMode));
1406 : // bRegionRect = rLogicRegion.ImplGetNextRect(aInfo, nX, nY, nWidth, nHeight);
1407 : //}
1408 : //
1409 : //aRegion.ImplEndAddRect();
1410 : }
1411 :
1412 0 : return aRegion;
1413 : }
1414 :
1415 : // -----------------------------------------------------------------------
1416 :
1417 105239 : Point OutputDevice::PixelToLogic( const Point& rDevicePt ) const
1418 : {
1419 : DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice );
1420 :
1421 105239 : if ( !mbMap )
1422 11018 : return rDevicePt;
1423 :
1424 : return Point( ImplPixelToLogic( rDevicePt.X(), mnDPIX,
1425 : maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
1426 94221 : maThresRes.mnThresPixToLogX ) - maMapRes.mnMapOfsX - mnOutOffLogicX,
1427 : ImplPixelToLogic( rDevicePt.Y(), mnDPIY,
1428 : maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
1429 188442 : maThresRes.mnThresPixToLogY ) - maMapRes.mnMapOfsY - mnOutOffLogicY );
1430 : }
1431 :
1432 : // -----------------------------------------------------------------------
1433 :
1434 938333 : Size OutputDevice::PixelToLogic( const Size& rDeviceSize ) const
1435 : {
1436 : DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice );
1437 :
1438 938333 : if ( !mbMap )
1439 240297 : return rDeviceSize;
1440 :
1441 : return Size( ImplPixelToLogic( rDeviceSize.Width(), mnDPIX,
1442 : maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
1443 : maThresRes.mnThresPixToLogX ),
1444 : ImplPixelToLogic( rDeviceSize.Height(), mnDPIY,
1445 : maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
1446 698036 : maThresRes.mnThresPixToLogY ) );
1447 : }
1448 :
1449 : // -----------------------------------------------------------------------
1450 :
1451 297557 : Rectangle OutputDevice::PixelToLogic( const Rectangle& rDeviceRect ) const
1452 : {
1453 : DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice );
1454 :
1455 297557 : if ( !mbMap || rDeviceRect.IsEmpty() )
1456 72269 : return rDeviceRect;
1457 :
1458 : return Rectangle( ImplPixelToLogic( rDeviceRect.Left(), mnDPIX,
1459 : maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
1460 225288 : maThresRes.mnThresPixToLogX ) - maMapRes.mnMapOfsX - mnOutOffLogicX,
1461 : ImplPixelToLogic( rDeviceRect.Top(), mnDPIY,
1462 : maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
1463 225288 : maThresRes.mnThresPixToLogY ) - maMapRes.mnMapOfsY - mnOutOffLogicY,
1464 : ImplPixelToLogic( rDeviceRect.Right(), mnDPIX,
1465 : maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
1466 225288 : maThresRes.mnThresPixToLogX ) - maMapRes.mnMapOfsX - mnOutOffLogicX,
1467 : ImplPixelToLogic( rDeviceRect.Bottom(), mnDPIY,
1468 : maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
1469 901152 : maThresRes.mnThresPixToLogY ) - maMapRes.mnMapOfsY - mnOutOffLogicY );
1470 : }
1471 :
1472 : // -----------------------------------------------------------------------
1473 :
1474 0 : Polygon OutputDevice::PixelToLogic( const Polygon& rDevicePoly ) const
1475 : {
1476 : DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice );
1477 : DBG_CHKOBJ( &rDevicePoly, Polygon, NULL );
1478 :
1479 0 : if ( !mbMap )
1480 0 : return rDevicePoly;
1481 :
1482 : sal_uInt16 i;
1483 0 : sal_uInt16 nPoints = rDevicePoly.GetSize();
1484 0 : Polygon aPoly( rDevicePoly );
1485 :
1486 : // Pointer auf das Point-Array holen (Daten werden kopiert)
1487 0 : const Point* pPointAry = aPoly.GetConstPointAry();
1488 :
1489 0 : for ( i = 0; i < nPoints; i++ )
1490 : {
1491 0 : const Point* pPt = &(pPointAry[i]);
1492 0 : Point aPt;
1493 0 : aPt.X() = ImplPixelToLogic( pPt->X(), mnDPIX,
1494 : maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
1495 0 : maThresRes.mnThresPixToLogX ) - maMapRes.mnMapOfsX - mnOutOffLogicX;
1496 0 : aPt.Y() = ImplPixelToLogic( pPt->Y(), mnDPIY,
1497 : maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
1498 0 : maThresRes.mnThresPixToLogY ) - maMapRes.mnMapOfsY - mnOutOffLogicY;
1499 0 : aPoly[i] = aPt;
1500 : }
1501 :
1502 0 : return aPoly;
1503 : }
1504 :
1505 : // -----------------------------------------------------------------------
1506 :
1507 0 : PolyPolygon OutputDevice::PixelToLogic( const PolyPolygon& rDevicePolyPoly ) const
1508 : {
1509 : DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice );
1510 : DBG_CHKOBJ( &rDevicePolyPoly, PolyPolygon, NULL );
1511 :
1512 0 : if ( !mbMap )
1513 0 : return rDevicePolyPoly;
1514 :
1515 0 : PolyPolygon aPolyPoly( rDevicePolyPoly );
1516 0 : sal_uInt16 nPoly = aPolyPoly.Count();
1517 0 : for( sal_uInt16 i = 0; i < nPoly; i++ )
1518 : {
1519 0 : Polygon& rPoly = aPolyPoly[i];
1520 0 : rPoly = PixelToLogic( rPoly );
1521 : }
1522 0 : return aPolyPoly;
1523 : }
1524 :
1525 14 : basegfx::B2DPolyPolygon OutputDevice::PixelToLogic( const basegfx::B2DPolyPolygon& rPixelPolyPoly ) const
1526 : {
1527 14 : basegfx::B2DPolyPolygon aTransformedPoly = rPixelPolyPoly;
1528 28 : const ::basegfx::B2DHomMatrix& rTransformationMatrix = GetInverseViewTransformation();
1529 14 : aTransformedPoly.transform( rTransformationMatrix );
1530 28 : return aTransformedPoly;
1531 : }
1532 :
1533 : // -----------------------------------------------------------------------
1534 :
1535 183155 : Region OutputDevice::PixelToLogic( const Region& rDeviceRegion ) const
1536 : {
1537 : DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice );
1538 :
1539 183155 : if(!mbMap || rDeviceRegion.IsNull() || rDeviceRegion.IsEmpty())
1540 : {
1541 160343 : return rDeviceRegion;
1542 : }
1543 :
1544 22812 : Region aRegion;
1545 :
1546 22812 : if(rDeviceRegion.getB2DPolyPolygon())
1547 : {
1548 14 : aRegion = Region(PixelToLogic(*rDeviceRegion.getB2DPolyPolygon()));
1549 : }
1550 22798 : else if(rDeviceRegion.getPolyPolygon())
1551 : {
1552 0 : aRegion = Region(PixelToLogic(*rDeviceRegion.getPolyPolygon()));
1553 : }
1554 22798 : else if(rDeviceRegion.getRegionBand())
1555 : {
1556 22798 : RectangleVector aRectangles;
1557 22798 : rDeviceRegion.GetRegionRectangles(aRectangles);
1558 22798 : const RectangleVector& rRectangles(aRectangles); // needed to make the '!=' work
1559 :
1560 : // make reverse run to fill new region bottom-up, this will speed it up due to the used data structuring
1561 47140 : for(RectangleVector::const_reverse_iterator aRectIter(rRectangles.rbegin()); aRectIter != rRectangles.rend(); ++aRectIter)
1562 : {
1563 24342 : aRegion.Union(PixelToLogic(*aRectIter));
1564 22798 : }
1565 :
1566 : //long nX(0);
1567 : //long nY(0);
1568 : //long nWidth(0);
1569 : //long nHeight(0);
1570 : //ImplRegionInfo aInfo;
1571 : //aRegion.ImplBeginAddRect();
1572 : //bool bRegionRect(rDeviceRegion.ImplGetFirstRect(aInfo, nX, nY, nWidth, nHeight));
1573 : //
1574 : //while(bRegionRect)
1575 : //{
1576 : // const Rectangle aRect(Point(nX, nY), Size(nWidth, nHeight));
1577 : // aRegion.ImplAddRect(PixelToLogic(aRect));
1578 : // bRegionRect = rDeviceRegion.ImplGetNextRect(aInfo, nX, nY, nWidth, nHeight);
1579 : //}
1580 : //
1581 : //aRegion.ImplEndAddRect();
1582 : }
1583 :
1584 22812 : return aRegion;
1585 : }
1586 :
1587 : // -----------------------------------------------------------------------
1588 :
1589 17439 : Point OutputDevice::PixelToLogic( const Point& rDevicePt,
1590 : const MapMode& rMapMode ) const
1591 : {
1592 : DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice );
1593 :
1594 : // Ist Default-MapMode, dann bereche nichts
1595 17439 : if ( rMapMode.IsDefault() )
1596 2 : return rDevicePt;
1597 :
1598 : // MapMode-Aufloesung berechnen und Umrechnen
1599 : ImplMapRes aMapRes;
1600 : ImplThresholdRes aThresRes;
1601 17437 : ImplCalcMapResolution( rMapMode, mnDPIX, mnDPIY, aMapRes, aThresRes );
1602 :
1603 : return Point( ImplPixelToLogic( rDevicePt.X(), mnDPIX,
1604 : aMapRes.mnMapScNumX, aMapRes.mnMapScDenomX,
1605 17437 : aThresRes.mnThresPixToLogX ) - aMapRes.mnMapOfsX - mnOutOffLogicX,
1606 : ImplPixelToLogic( rDevicePt.Y(), mnDPIY,
1607 : aMapRes.mnMapScNumY, aMapRes.mnMapScDenomY,
1608 34874 : aThresRes.mnThresPixToLogY ) - aMapRes.mnMapOfsY - mnOutOffLogicY );
1609 : }
1610 :
1611 : // -----------------------------------------------------------------------
1612 :
1613 6254 : Size OutputDevice::PixelToLogic( const Size& rDeviceSize,
1614 : const MapMode& rMapMode ) const
1615 : {
1616 : DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice );
1617 :
1618 : // Ist Default-MapMode, dann bereche nichts
1619 6254 : if ( rMapMode.IsDefault() )
1620 1 : return rDeviceSize;
1621 :
1622 : // MapMode-Aufloesung berechnen und Umrechnen
1623 : ImplMapRes aMapRes;
1624 : ImplThresholdRes aThresRes;
1625 6253 : ImplCalcMapResolution( rMapMode, mnDPIX, mnDPIY, aMapRes, aThresRes );
1626 :
1627 : return Size( ImplPixelToLogic( rDeviceSize.Width(), mnDPIX,
1628 : aMapRes.mnMapScNumX, aMapRes.mnMapScDenomX,
1629 : aThresRes.mnThresPixToLogX ),
1630 : ImplPixelToLogic( rDeviceSize.Height(), mnDPIY,
1631 : aMapRes.mnMapScNumY, aMapRes.mnMapScDenomY,
1632 6253 : aThresRes.mnThresPixToLogY ) );
1633 : }
1634 :
1635 : // -----------------------------------------------------------------------
1636 :
1637 4290 : Rectangle OutputDevice::PixelToLogic( const Rectangle& rDeviceRect,
1638 : const MapMode& rMapMode ) const
1639 : {
1640 : DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice );
1641 :
1642 : // Ist Default-MapMode, dann bereche nichts
1643 4290 : if ( rMapMode.IsDefault() || rDeviceRect.IsEmpty() )
1644 0 : return rDeviceRect;
1645 :
1646 : // MapMode-Aufloesung berechnen und Umrechnen
1647 : ImplMapRes aMapRes;
1648 : ImplThresholdRes aThresRes;
1649 4290 : ImplCalcMapResolution( rMapMode, mnDPIX, mnDPIY, aMapRes, aThresRes );
1650 :
1651 : return Rectangle( ImplPixelToLogic( rDeviceRect.Left(), mnDPIX,
1652 : aMapRes.mnMapScNumX, aMapRes.mnMapScDenomX,
1653 4290 : aThresRes.mnThresPixToLogX ) - aMapRes.mnMapOfsX - mnOutOffLogicX,
1654 : ImplPixelToLogic( rDeviceRect.Top(), mnDPIY,
1655 : aMapRes.mnMapScNumY, aMapRes.mnMapScDenomY,
1656 4290 : aThresRes.mnThresPixToLogY ) - aMapRes.mnMapOfsY - mnOutOffLogicY,
1657 : ImplPixelToLogic( rDeviceRect.Right(), mnDPIX,
1658 : aMapRes.mnMapScNumX, aMapRes.mnMapScDenomX,
1659 4290 : aThresRes.mnThresPixToLogX ) - aMapRes.mnMapOfsX - mnOutOffLogicX,
1660 : ImplPixelToLogic( rDeviceRect.Bottom(), mnDPIY,
1661 : aMapRes.mnMapScNumY, aMapRes.mnMapScDenomY,
1662 17160 : aThresRes.mnThresPixToLogY ) - aMapRes.mnMapOfsY - mnOutOffLogicY );
1663 : }
1664 :
1665 : // -----------------------------------------------------------------------
1666 :
1667 0 : Polygon OutputDevice::PixelToLogic( const Polygon& rDevicePoly,
1668 : const MapMode& rMapMode ) const
1669 : {
1670 : DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice );
1671 : DBG_CHKOBJ( &rDevicePoly, Polygon, NULL );
1672 :
1673 : // Ist Default-MapMode, dann bereche nichts
1674 0 : if ( rMapMode.IsDefault() )
1675 0 : return rDevicePoly;
1676 :
1677 : // MapMode-Aufloesung berechnen und Umrechnen
1678 : ImplMapRes aMapRes;
1679 : ImplThresholdRes aThresRes;
1680 0 : ImplCalcMapResolution( rMapMode, mnDPIX, mnDPIY, aMapRes, aThresRes );
1681 :
1682 : sal_uInt16 i;
1683 0 : sal_uInt16 nPoints = rDevicePoly.GetSize();
1684 0 : Polygon aPoly( rDevicePoly );
1685 :
1686 : // Pointer auf das Point-Array holen (Daten werden kopiert)
1687 0 : const Point* pPointAry = aPoly.GetConstPointAry();
1688 :
1689 0 : for ( i = 0; i < nPoints; i++ )
1690 : {
1691 0 : const Point* pPt = &(pPointAry[i]);
1692 0 : Point aPt;
1693 0 : aPt.X() = ImplPixelToLogic( pPt->X(), mnDPIX,
1694 : aMapRes.mnMapScNumX, aMapRes.mnMapScDenomX,
1695 0 : aThresRes.mnThresPixToLogX ) - aMapRes.mnMapOfsX - mnOutOffLogicX;
1696 0 : aPt.Y() = ImplPixelToLogic( pPt->Y(), mnDPIY,
1697 : aMapRes.mnMapScNumY, aMapRes.mnMapScDenomY,
1698 0 : aThresRes.mnThresPixToLogY ) - aMapRes.mnMapOfsY - mnOutOffLogicY;
1699 0 : aPoly[i] = aPt;
1700 : }
1701 :
1702 0 : return aPoly;
1703 : }
1704 :
1705 : // -----------------------------------------------------------------------
1706 :
1707 0 : PolyPolygon OutputDevice::PixelToLogic( const PolyPolygon& rDevicePolyPoly,
1708 : const MapMode& rMapMode ) const
1709 : {
1710 : DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice );
1711 : DBG_CHKOBJ( &rDevicePolyPoly, PolyPolygon, NULL );
1712 :
1713 0 : if ( rMapMode.IsDefault() )
1714 0 : return rDevicePolyPoly;
1715 :
1716 0 : PolyPolygon aPolyPoly( rDevicePolyPoly );
1717 0 : sal_uInt16 nPoly = aPolyPoly.Count();
1718 0 : for( sal_uInt16 i = 0; i < nPoly; i++ )
1719 : {
1720 0 : Polygon& rPoly = aPolyPoly[i];
1721 0 : rPoly = PixelToLogic( rPoly, rMapMode );
1722 : }
1723 0 : return aPolyPoly;
1724 : }
1725 :
1726 : // -----------------------------------------------------------------------
1727 :
1728 0 : basegfx::B2DPolygon OutputDevice::PixelToLogic( const basegfx::B2DPolygon& rPixelPoly,
1729 : const MapMode& rMapMode ) const
1730 : {
1731 0 : basegfx::B2DPolygon aTransformedPoly = rPixelPoly;
1732 0 : const ::basegfx::B2DHomMatrix& rTransformationMatrix = GetInverseViewTransformation( rMapMode );
1733 0 : aTransformedPoly.transform( rTransformationMatrix );
1734 0 : return aTransformedPoly;
1735 : }
1736 :
1737 : // -----------------------------------------------------------------------
1738 :
1739 0 : basegfx::B2DPolyPolygon OutputDevice::PixelToLogic( const basegfx::B2DPolyPolygon& rPixelPolyPoly,
1740 : const MapMode& rMapMode ) const
1741 : {
1742 0 : basegfx::B2DPolyPolygon aTransformedPoly = rPixelPolyPoly;
1743 0 : const ::basegfx::B2DHomMatrix& rTransformationMatrix = GetInverseViewTransformation( rMapMode );
1744 0 : aTransformedPoly.transform( rTransformationMatrix );
1745 0 : return aTransformedPoly;
1746 : }
1747 :
1748 : // -----------------------------------------------------------------------
1749 :
1750 0 : Region OutputDevice::PixelToLogic( const Region& rDeviceRegion, const MapMode& rMapMode ) const
1751 : {
1752 : DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice );
1753 :
1754 0 : if(rMapMode.IsDefault() || rDeviceRegion.IsNull() || rDeviceRegion.IsEmpty())
1755 : {
1756 0 : return rDeviceRegion;
1757 : }
1758 :
1759 0 : Region aRegion;
1760 :
1761 0 : if(rDeviceRegion.getB2DPolyPolygon())
1762 : {
1763 0 : aRegion = Region(PixelToLogic(*rDeviceRegion.getB2DPolyPolygon(), rMapMode));
1764 : }
1765 0 : else if(rDeviceRegion.getPolyPolygon())
1766 : {
1767 0 : aRegion = Region(PixelToLogic(*rDeviceRegion.getPolyPolygon(), rMapMode));
1768 : }
1769 0 : else if(rDeviceRegion.getRegionBand())
1770 : {
1771 0 : RectangleVector aRectangles;
1772 0 : rDeviceRegion.GetRegionRectangles(aRectangles);
1773 0 : const RectangleVector& rRectangles(aRectangles); // needed to make the '!=' work
1774 :
1775 : // make reverse run to fill new region bottom-up, this will speed it up due to the used data structuring
1776 0 : for(RectangleVector::const_reverse_iterator aRectIter(rRectangles.rbegin()); aRectIter != rRectangles.rend(); ++aRectIter)
1777 : {
1778 0 : aRegion.Union(PixelToLogic(*aRectIter, rMapMode));
1779 0 : }
1780 :
1781 : //long nX(0);
1782 : //long nY(0);
1783 : //long nWidth(0);
1784 : //long nHeight(0);
1785 : //ImplRegionInfo aInfo;
1786 : //aRegion.ImplBeginAddRect();
1787 : //bool bRegionRect(rDeviceRegion.ImplGetFirstRect(aInfo, nX, nY, nWidth, nHeight));
1788 : //
1789 : //while(bRegionRect)
1790 : //{
1791 : // const Rectangle aRect(Point(nX, nY), Size(nWidth, nHeight));
1792 : // aRegion.ImplAddRect(PixelToLogic(aRect, rMapMode));
1793 : // bRegionRect = rDeviceRegion.ImplGetNextRect(aInfo, nX, nY, nWidth, nHeight);
1794 : //}
1795 : //
1796 : //aRegion.ImplEndAddRect();
1797 : }
1798 :
1799 0 : return aRegion;
1800 : }
1801 :
1802 : // -----------------------------------------------------------------------
1803 :
1804 : #define ENTER0( rSource, pMapModeSource, pMapModeDest ) \
1805 : if ( !pMapModeSource ) \
1806 : pMapModeSource = &maMapMode; \
1807 : if ( !pMapModeDest ) \
1808 : pMapModeDest = &maMapMode; \
1809 : if ( *pMapModeSource == *pMapModeDest ) \
1810 : return rSource
1811 :
1812 : // -----------------------------------------------------------------------
1813 :
1814 : #define ENTER1( rSource, pMapModeSource, pMapModeDest ) \
1815 : ENTER0( rSource, pMapModeSource, pMapModeDest ); \
1816 : \
1817 : ImplMapRes aMapResSource; \
1818 : ImplMapRes aMapResDest; \
1819 : \
1820 : if ( !mbMap || pMapModeSource != &maMapMode ) \
1821 : { \
1822 : if ( pMapModeSource->GetMapUnit() == MAP_RELATIVE ) \
1823 : aMapResSource = maMapRes; \
1824 : ImplCalcMapResolution( *pMapModeSource, \
1825 : mnDPIX, mnDPIY, aMapResSource ); \
1826 : } \
1827 : else \
1828 : aMapResSource = maMapRes; \
1829 : if ( !mbMap || pMapModeDest != &maMapMode ) \
1830 : { \
1831 : if ( pMapModeDest->GetMapUnit() == MAP_RELATIVE ) \
1832 : aMapResDest = maMapRes; \
1833 : ImplCalcMapResolution( *pMapModeDest, \
1834 : mnDPIX, mnDPIY, aMapResDest ); \
1835 : } \
1836 : else \
1837 : aMapResDest = maMapRes
1838 :
1839 : // -----------------------------------------------------------------------
1840 :
1841 : #define ENTER2( eUnitSource, eUnitDest ) \
1842 : DBG_ASSERT( eUnitSource != MAP_SYSFONT \
1843 : && eUnitSource != MAP_APPFONT \
1844 : && eUnitSource != MAP_RELATIVE, \
1845 : "Source MapUnit nicht erlaubt" ); \
1846 : DBG_ASSERT( eUnitDest != MAP_SYSFONT \
1847 : && eUnitDest != MAP_APPFONT \
1848 : && eUnitDest != MAP_RELATIVE, \
1849 : "Destination MapUnit nicht erlaubt" ); \
1850 : DBG_ASSERTWARNING( eUnitSource != MAP_PIXEL, \
1851 : "MAP_PIXEL mit 72dpi angenaehert" ); \
1852 : DBG_ASSERTWARNING( eUnitDest != MAP_PIXEL, \
1853 : "MAP_PIXEL mit 72dpi angenaehert" )
1854 :
1855 : // -----------------------------------------------------------------------
1856 :
1857 : #define ENTER3( eUnitSource, eUnitDest ) \
1858 : long nNumerator = 1; \
1859 : long nDenominator = 1; \
1860 : DBG_ASSERT( eUnitSource < s_ImplArySize, "Invalid source map unit"); \
1861 : DBG_ASSERT( eUnitDest < s_ImplArySize, "Invalid destination map unit"); \
1862 : if( (eUnitSource < s_ImplArySize) && (eUnitDest < s_ImplArySize) ) \
1863 : { \
1864 : nNumerator = aImplNumeratorAry[eUnitSource] * \
1865 : aImplDenominatorAry[eUnitDest]; \
1866 : nDenominator = aImplNumeratorAry[eUnitDest] * \
1867 : aImplDenominatorAry[eUnitSource]; \
1868 : } \
1869 : if ( eUnitSource == MAP_PIXEL ) \
1870 : nDenominator *= 72; \
1871 : else if( eUnitDest == MAP_PIXEL ) \
1872 : nNumerator *= 72
1873 :
1874 : // -----------------------------------------------------------------------
1875 :
1876 : #define ENTER4( rMapModeSource, rMapModeDest ) \
1877 : ImplMapRes aMapResSource; \
1878 : ImplMapRes aMapResDest; \
1879 : \
1880 : ImplCalcMapResolution( rMapModeSource, 72, 72, aMapResSource ); \
1881 : ImplCalcMapResolution( rMapModeDest, 72, 72, aMapResDest )
1882 :
1883 : // -----------------------------------------------------------------------
1884 :
1885 : // return (n1 * n2 * n3) / (n4 * n5)
1886 546 : static long fn5( const long n1,
1887 : const long n2,
1888 : const long n3,
1889 : const long n4,
1890 : const long n5 )
1891 : {
1892 546 : if ( n1 == 0 || n2 == 0 || n3 == 0 || n4 == 0 || n5 == 0 )
1893 140 : return 0;
1894 406 : if ( LONG_MAX / std::abs(n2) < std::abs(n3) )
1895 : {
1896 : // a6 wird "ubersprungen
1897 56 : BigInt a7 = n2;
1898 56 : a7 *= n3;
1899 56 : a7 *= n1;
1900 :
1901 56 : if ( LONG_MAX / std::abs(n4) < std::abs(n5) )
1902 : {
1903 56 : BigInt a8 = n4;
1904 56 : a8 *= n5;
1905 :
1906 56 : BigInt a9 = a8;
1907 56 : a9 /= 2;
1908 56 : if ( a7.IsNeg() )
1909 0 : a7 -= a9;
1910 : else
1911 56 : a7 += a9;
1912 :
1913 56 : a7 /= a8;
1914 : } // of if
1915 : else
1916 : {
1917 0 : long n8 = n4 * n5;
1918 :
1919 0 : if ( a7.IsNeg() )
1920 0 : a7 -= n8 / 2;
1921 : else
1922 0 : a7 += n8 / 2;
1923 :
1924 0 : a7 /= n8;
1925 : } // of else
1926 56 : return (long)a7;
1927 : } // of if
1928 : else
1929 : {
1930 350 : long n6 = n2 * n3;
1931 :
1932 350 : if ( LONG_MAX / std::abs(n1) < std::abs(n6) )
1933 : {
1934 40 : BigInt a7 = n1;
1935 40 : a7 *= n6;
1936 :
1937 40 : if ( LONG_MAX / std::abs(n4) < std::abs(n5) )
1938 : {
1939 0 : BigInt a8 = n4;
1940 0 : a8 *= n5;
1941 :
1942 0 : BigInt a9 = a8;
1943 0 : a9 /= 2;
1944 0 : if ( a7.IsNeg() )
1945 0 : a7 -= a9;
1946 : else
1947 0 : a7 += a9;
1948 :
1949 0 : a7 /= a8;
1950 : } // of if
1951 : else
1952 : {
1953 40 : long n8 = n4 * n5;
1954 :
1955 40 : if ( a7.IsNeg() )
1956 0 : a7 -= n8 / 2;
1957 : else
1958 40 : a7 += n8 / 2;
1959 :
1960 40 : a7 /= n8;
1961 : } // of else
1962 40 : return (long)a7;
1963 : } // of if
1964 : else
1965 : {
1966 310 : long n7 = n1 * n6;
1967 :
1968 310 : if ( LONG_MAX / std::abs(n4) < std::abs(n5) )
1969 : {
1970 0 : BigInt a7 = n7;
1971 0 : BigInt a8 = n4;
1972 0 : a8 *= n5;
1973 :
1974 0 : BigInt a9 = a8;
1975 0 : a9 /= 2;
1976 0 : if ( a7.IsNeg() )
1977 0 : a7 -= a9;
1978 : else
1979 0 : a7 += a9;
1980 :
1981 0 : a7 /= a8;
1982 0 : return (long)a7;
1983 : } // of if
1984 : else
1985 : {
1986 310 : const long n8 = n4 * n5;
1987 310 : const long n8_2 = n8 / 2;
1988 :
1989 310 : if( n7 < 0 )
1990 : {
1991 24 : if( ( n7 - LONG_MIN ) >= n8_2 )
1992 24 : n7 -= n8_2;
1993 : }
1994 286 : else if( ( LONG_MAX - n7 ) >= n8_2 )
1995 286 : n7 += n8_2;
1996 :
1997 310 : return n7 / n8;
1998 : } // of else
1999 : } // of else
2000 : } // of else
2001 : }
2002 :
2003 : // -----------------------------------------------------------------------
2004 :
2005 : // return (n1 * n2) / n3
2006 20389 : static long fn3( const long n1, const long n2, const long n3 )
2007 : {
2008 20389 : if ( n1 == 0 || n2 == 0 || n3 == 0 )
2009 7608 : return 0;
2010 12781 : if ( LONG_MAX / std::abs(n1) < std::abs(n2) )
2011 : {
2012 0 : BigInt a4 = n1;
2013 0 : a4 *= n2;
2014 :
2015 0 : if ( a4.IsNeg() )
2016 0 : a4 -= n3 / 2;
2017 : else
2018 0 : a4 += n3 / 2;
2019 :
2020 0 : a4 /= n3;
2021 0 : return (long)a4;
2022 : } // of if
2023 : else
2024 : {
2025 12781 : long n4 = n1 * n2;
2026 12781 : const long n3_2 = n3 / 2;
2027 :
2028 12781 : if( n4 < 0 )
2029 : {
2030 4658 : if( ( n4 - LONG_MIN ) >= n3_2 )
2031 4658 : n4 -= n3_2;
2032 : }
2033 8123 : else if( ( LONG_MAX - n4 ) >= n3_2 )
2034 8123 : n4 += n3_2;
2035 :
2036 12781 : return n4 / n3;
2037 : } // of else
2038 : }
2039 :
2040 : // -----------------------------------------------------------------------
2041 :
2042 2709 : Point OutputDevice::LogicToLogic( const Point& rPtSource,
2043 : const MapMode* pMapModeSource,
2044 : const MapMode* pMapModeDest ) const
2045 : {
2046 2709 : ENTER1( rPtSource, pMapModeSource, pMapModeDest );
2047 :
2048 23 : return Point( fn5( rPtSource.X() + aMapResSource.mnMapOfsX,
2049 : aMapResSource.mnMapScNumX, aMapResDest.mnMapScDenomX,
2050 46 : aMapResSource.mnMapScDenomX, aMapResDest.mnMapScNumX ) -
2051 : aMapResDest.mnMapOfsX,
2052 23 : fn5( rPtSource.Y() + aMapResSource.mnMapOfsY,
2053 : aMapResSource.mnMapScNumY, aMapResDest.mnMapScDenomY,
2054 46 : aMapResSource.mnMapScDenomY, aMapResDest.mnMapScNumY ) -
2055 46 : aMapResDest.mnMapOfsY );
2056 : }
2057 :
2058 : // -----------------------------------------------------------------------
2059 :
2060 2736 : Size OutputDevice::LogicToLogic( const Size& rSzSource,
2061 : const MapMode* pMapModeSource,
2062 : const MapMode* pMapModeDest ) const
2063 : {
2064 2736 : ENTER1( rSzSource, pMapModeSource, pMapModeDest );
2065 :
2066 : return Size( fn5( rSzSource.Width(),
2067 : aMapResSource.mnMapScNumX, aMapResDest.mnMapScDenomX,
2068 : aMapResSource.mnMapScDenomX, aMapResDest.mnMapScNumX ),
2069 : fn5( rSzSource.Height(),
2070 : aMapResSource.mnMapScNumY, aMapResDest.mnMapScDenomY,
2071 34 : aMapResSource.mnMapScDenomY, aMapResDest.mnMapScNumY ) );
2072 : }
2073 :
2074 : // -----------------------------------------------------------------------
2075 :
2076 0 : Rectangle OutputDevice::LogicToLogic( const Rectangle& rRectSource,
2077 : const MapMode* pMapModeSource,
2078 : const MapMode* pMapModeDest ) const
2079 : {
2080 0 : ENTER1( rRectSource, pMapModeSource, pMapModeDest );
2081 :
2082 0 : return Rectangle( fn5( rRectSource.Left() + aMapResSource.mnMapOfsX,
2083 : aMapResSource.mnMapScNumX, aMapResDest.mnMapScDenomX,
2084 0 : aMapResSource.mnMapScDenomX, aMapResDest.mnMapScNumX ) -
2085 : aMapResDest.mnMapOfsX,
2086 0 : fn5( rRectSource.Top() + aMapResSource.mnMapOfsY,
2087 : aMapResSource.mnMapScNumY, aMapResDest.mnMapScDenomY,
2088 0 : aMapResSource.mnMapScDenomY, aMapResDest.mnMapScNumY ) -
2089 : aMapResDest.mnMapOfsY,
2090 0 : fn5( rRectSource.Right() + aMapResSource.mnMapOfsX,
2091 : aMapResSource.mnMapScNumX, aMapResDest.mnMapScDenomX,
2092 0 : aMapResSource.mnMapScDenomX, aMapResDest.mnMapScNumX ) -
2093 : aMapResDest.mnMapOfsX,
2094 0 : fn5( rRectSource.Bottom() + aMapResSource.mnMapOfsY,
2095 : aMapResSource.mnMapScNumY, aMapResDest.mnMapScDenomY,
2096 0 : aMapResSource.mnMapScDenomY, aMapResDest.mnMapScNumY ) -
2097 0 : aMapResDest.mnMapOfsY );
2098 : }
2099 :
2100 : // -----------------------------------------------------------------------
2101 :
2102 5100 : Point OutputDevice::LogicToLogic( const Point& rPtSource,
2103 : const MapMode& rMapModeSource,
2104 : const MapMode& rMapModeDest )
2105 : {
2106 5100 : if ( rMapModeSource == rMapModeDest )
2107 4960 : return rPtSource;
2108 :
2109 140 : MapUnit eUnitSource = rMapModeSource.GetMapUnit();
2110 140 : MapUnit eUnitDest = rMapModeDest.GetMapUnit();
2111 : ENTER2( eUnitSource, eUnitDest );
2112 :
2113 140 : if ( rMapModeSource.mpImplMapMode->mbSimple &&
2114 : rMapModeDest.mpImplMapMode->mbSimple )
2115 : {
2116 70 : ENTER3( eUnitSource, eUnitDest );
2117 :
2118 : return Point( fn3( rPtSource.X(), nNumerator, nDenominator ),
2119 70 : fn3( rPtSource.Y(), nNumerator, nDenominator ) );
2120 : }
2121 : else
2122 : {
2123 70 : ENTER4( rMapModeSource, rMapModeDest );
2124 :
2125 70 : return Point( fn5( rPtSource.X() + aMapResSource.mnMapOfsX,
2126 : aMapResSource.mnMapScNumX, aMapResDest.mnMapScDenomX,
2127 140 : aMapResSource.mnMapScDenomX, aMapResDest.mnMapScNumX ) -
2128 : aMapResDest.mnMapOfsX,
2129 70 : fn5( rPtSource.Y() + aMapResSource.mnMapOfsY,
2130 : aMapResSource.mnMapScNumY, aMapResDest.mnMapScDenomY,
2131 140 : aMapResSource.mnMapScDenomY, aMapResDest.mnMapScNumY ) -
2132 140 : aMapResDest.mnMapOfsY );
2133 : }
2134 : }
2135 :
2136 : // -----------------------------------------------------------------------
2137 :
2138 5239 : Size OutputDevice::LogicToLogic( const Size& rSzSource,
2139 : const MapMode& rMapModeSource,
2140 : const MapMode& rMapModeDest )
2141 : {
2142 5239 : if ( rMapModeSource == rMapModeDest )
2143 2291 : return rSzSource;
2144 :
2145 2948 : MapUnit eUnitSource = rMapModeSource.GetMapUnit();
2146 2948 : MapUnit eUnitDest = rMapModeDest.GetMapUnit();
2147 : ENTER2( eUnitSource, eUnitDest );
2148 :
2149 2948 : if ( rMapModeSource.mpImplMapMode->mbSimple &&
2150 : rMapModeDest.mpImplMapMode->mbSimple )
2151 : {
2152 2810 : ENTER3( eUnitSource, eUnitDest );
2153 :
2154 : return Size( fn3( rSzSource.Width(), nNumerator, nDenominator ),
2155 2810 : fn3( rSzSource.Height(), nNumerator, nDenominator ) );
2156 : }
2157 : else
2158 : {
2159 138 : ENTER4( rMapModeSource, rMapModeDest );
2160 :
2161 : return Size( fn5( rSzSource.Width(),
2162 : aMapResSource.mnMapScNumX, aMapResDest.mnMapScDenomX,
2163 : aMapResSource.mnMapScDenomX, aMapResDest.mnMapScNumX ),
2164 : fn5( rSzSource.Height(),
2165 : aMapResSource.mnMapScNumY, aMapResDest.mnMapScDenomY,
2166 138 : aMapResSource.mnMapScDenomY, aMapResDest.mnMapScNumY ) );
2167 : }
2168 : }
2169 :
2170 : // -----------------------------------------------------------------------
2171 :
2172 0 : basegfx::B2DPolygon OutputDevice::LogicToLogic( const basegfx::B2DPolygon& rPolySource,
2173 : const MapMode& rMapModeSource,
2174 : const MapMode& rMapModeDest )
2175 : {
2176 0 : if(rMapModeSource == rMapModeDest)
2177 : {
2178 0 : return rPolySource;
2179 : }
2180 :
2181 0 : const basegfx::B2DHomMatrix aTransform(LogicToLogic(rMapModeSource, rMapModeDest));
2182 0 : basegfx::B2DPolygon aPoly(rPolySource);
2183 :
2184 0 : aPoly.transform(aTransform);
2185 0 : return aPoly;
2186 : }
2187 :
2188 : // -----------------------------------------------------------------------
2189 :
2190 0 : basegfx::B2DPolyPolygon OutputDevice::LogicToLogic( const basegfx::B2DPolyPolygon& rPolySource,
2191 : const MapMode& rMapModeSource,
2192 : const MapMode& rMapModeDest )
2193 : {
2194 0 : if(rMapModeSource == rMapModeDest)
2195 : {
2196 0 : return rPolySource;
2197 : }
2198 :
2199 0 : const basegfx::B2DHomMatrix aTransform(LogicToLogic(rMapModeSource, rMapModeDest));
2200 0 : basegfx::B2DPolyPolygon aPoly(rPolySource);
2201 :
2202 0 : aPoly.transform(aTransform);
2203 0 : return aPoly;
2204 : }
2205 :
2206 : // -----------------------------------------------------------------------
2207 :
2208 671 : basegfx::B2DHomMatrix OutputDevice::LogicToLogic(const MapMode& rMapModeSource, const MapMode& rMapModeDest)
2209 : {
2210 671 : basegfx::B2DHomMatrix aTransform;
2211 :
2212 671 : if(rMapModeSource == rMapModeDest)
2213 : {
2214 0 : return aTransform;
2215 : }
2216 :
2217 671 : MapUnit eUnitSource = rMapModeSource.GetMapUnit();
2218 671 : MapUnit eUnitDest = rMapModeDest.GetMapUnit();
2219 : ENTER2(eUnitSource, eUnitDest);
2220 :
2221 671 : if(rMapModeSource.mpImplMapMode->mbSimple && rMapModeDest.mpImplMapMode->mbSimple)
2222 : {
2223 671 : ENTER3(eUnitSource, eUnitDest);
2224 :
2225 671 : const double fScaleFactor((double)nNumerator / (double)nDenominator);
2226 671 : aTransform.set(0, 0, fScaleFactor);
2227 671 : aTransform.set(1, 1, fScaleFactor);
2228 : }
2229 : else
2230 : {
2231 0 : ENTER4(rMapModeSource, rMapModeDest);
2232 :
2233 0 : const double fScaleFactorX((double(aMapResSource.mnMapScNumX) * double(aMapResDest.mnMapScDenomX)) / (double(aMapResSource.mnMapScDenomX) * double(aMapResDest.mnMapScNumX)));
2234 0 : const double fScaleFactorY((double(aMapResSource.mnMapScNumY) * double(aMapResDest.mnMapScDenomY)) / (double(aMapResSource.mnMapScDenomY) * double(aMapResDest.mnMapScNumY)));
2235 0 : const double fZeroPointX(double(aMapResSource.mnMapOfsX) * fScaleFactorX - double(aMapResDest.mnMapOfsX));
2236 0 : const double fZeroPointY(double(aMapResSource.mnMapOfsY) * fScaleFactorY - double(aMapResDest.mnMapOfsY));
2237 :
2238 0 : aTransform.set(0, 0, fScaleFactorX);
2239 0 : aTransform.set(1, 1, fScaleFactorY);
2240 0 : aTransform.set(0, 2, fZeroPointX);
2241 0 : aTransform.set(1, 2, fZeroPointY);
2242 : }
2243 :
2244 671 : return aTransform;
2245 : }
2246 :
2247 : // -----------------------------------------------------------------------
2248 :
2249 5571 : Rectangle OutputDevice::LogicToLogic( const Rectangle& rRectSource,
2250 : const MapMode& rMapModeSource,
2251 : const MapMode& rMapModeDest )
2252 : {
2253 5571 : if ( rMapModeSource == rMapModeDest )
2254 2128 : return rRectSource;
2255 :
2256 3443 : MapUnit eUnitSource = rMapModeSource.GetMapUnit();
2257 3443 : MapUnit eUnitDest = rMapModeDest.GetMapUnit();
2258 : ENTER2( eUnitSource, eUnitDest );
2259 :
2260 3443 : if ( rMapModeSource.mpImplMapMode->mbSimple &&
2261 : rMapModeDest.mpImplMapMode->mbSimple )
2262 : {
2263 3439 : ENTER3( eUnitSource, eUnitDest );
2264 :
2265 : return Rectangle( fn3( rRectSource.Left(), nNumerator, nDenominator ),
2266 : fn3( rRectSource.Top(), nNumerator, nDenominator ),
2267 : fn3( rRectSource.Right(), nNumerator, nDenominator ),
2268 3439 : fn3( rRectSource.Bottom(), nNumerator, nDenominator ) );
2269 : }
2270 : else
2271 : {
2272 4 : ENTER4( rMapModeSource, rMapModeDest );
2273 :
2274 4 : return Rectangle( fn5( rRectSource.Left() + aMapResSource.mnMapOfsX,
2275 : aMapResSource.mnMapScNumX, aMapResDest.mnMapScDenomX,
2276 8 : aMapResSource.mnMapScDenomX, aMapResDest.mnMapScNumX ) -
2277 : aMapResDest.mnMapOfsX,
2278 4 : fn5( rRectSource.Top() + aMapResSource.mnMapOfsY,
2279 : aMapResSource.mnMapScNumY, aMapResDest.mnMapScDenomY,
2280 8 : aMapResSource.mnMapScDenomY, aMapResDest.mnMapScNumY ) -
2281 : aMapResDest.mnMapOfsY,
2282 4 : fn5( rRectSource.Right() + aMapResSource.mnMapOfsX,
2283 : aMapResSource.mnMapScNumX, aMapResDest.mnMapScDenomX,
2284 8 : aMapResSource.mnMapScDenomX, aMapResDest.mnMapScNumX ) -
2285 : aMapResDest.mnMapOfsX,
2286 4 : fn5( rRectSource.Bottom() + aMapResSource.mnMapOfsY,
2287 : aMapResSource.mnMapScNumY, aMapResDest.mnMapScDenomY,
2288 8 : aMapResSource.mnMapScDenomY, aMapResDest.mnMapScNumY ) -
2289 16 : aMapResDest.mnMapOfsY );
2290 : }
2291 : }
2292 :
2293 : // -----------------------------------------------------------------------
2294 :
2295 955 : long OutputDevice::LogicToLogic( long nLongSource,
2296 : MapUnit eUnitSource, MapUnit eUnitDest )
2297 : {
2298 955 : if ( eUnitSource == eUnitDest )
2299 82 : return nLongSource;
2300 :
2301 : ENTER2( eUnitSource, eUnitDest );
2302 873 : ENTER3( eUnitSource, eUnitDest );
2303 :
2304 873 : return fn3( nLongSource, nNumerator, nDenominator );
2305 : }
2306 :
2307 : // -----------------------------------------------------------------------
2308 :
2309 144 : void OutputDevice::SetPixelOffset( const Size& rOffset )
2310 : {
2311 144 : mnOutOffOrigX = rOffset.Width();
2312 144 : mnOutOffOrigY = rOffset.Height();
2313 :
2314 : mnOutOffLogicX = ImplPixelToLogic( mnOutOffOrigX, mnDPIX,
2315 : maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
2316 144 : maThresRes.mnThresPixToLogX );
2317 : mnOutOffLogicY = ImplPixelToLogic( mnOutOffOrigY, mnDPIY,
2318 : maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
2319 144 : maThresRes.mnThresPixToLogY );
2320 :
2321 144 : if( mpAlphaVDev )
2322 0 : mpAlphaVDev->SetPixelOffset( rOffset );
2323 144 : }
2324 :
2325 : // -----------------------------------------------------------------------
2326 :
2327 72 : Size OutputDevice::GetPixelOffset() const
2328 : {
2329 72 : return Size(mnOutOffOrigX, mnOutOffOrigY);
2330 : }
2331 :
2332 : // -----------------------------------------------------------------------
2333 :
2334 1399 : long Window::ImplLogicUnitToPixelX( long nX, MapUnit eUnit )
2335 : {
2336 1399 : if ( eUnit != MAP_PIXEL )
2337 : {
2338 1399 : ImplFrameData* pFrameData = mpWindowImpl->mpFrameData;
2339 :
2340 : // Map-Einheit verschieden, dann neu berechnen
2341 1399 : if ( pFrameData->meMapUnit != eUnit )
2342 : {
2343 635 : pFrameData->meMapUnit = eUnit;
2344 : ImplCalcMapResolution( MapMode( eUnit ), mnDPIX, mnDPIY,
2345 635 : pFrameData->maMapUnitRes );
2346 : }
2347 :
2348 : // Es wird kein BigInt gebraucht, da diese Funktion nur zur Umrechnung
2349 : // von Fensterposition benutzt wird
2350 1399 : nX = nX * mnDPIX * pFrameData->maMapUnitRes.mnMapScNumX;
2351 1399 : nX += nX >= 0 ? (pFrameData->maMapUnitRes.mnMapScDenomX/2) :
2352 2798 : -((pFrameData->maMapUnitRes.mnMapScDenomX-1)/2);
2353 1399 : nX /= pFrameData->maMapUnitRes.mnMapScDenomX;
2354 : }
2355 :
2356 1399 : return nX;
2357 : }
2358 :
2359 : // -----------------------------------------------------------------------
2360 :
2361 1399 : long Window::ImplLogicUnitToPixelY( long nY, MapUnit eUnit )
2362 : {
2363 1399 : if ( eUnit != MAP_PIXEL )
2364 : {
2365 1399 : ImplFrameData* pFrameData = mpWindowImpl->mpFrameData;
2366 :
2367 : // Map-Einheit verschieden, dann neu berechnen
2368 1399 : if ( pFrameData->meMapUnit != eUnit )
2369 : {
2370 0 : pFrameData->meMapUnit = eUnit;
2371 : ImplCalcMapResolution( MapMode( eUnit ), mnDPIX, mnDPIY,
2372 0 : pFrameData->maMapUnitRes );
2373 : }
2374 :
2375 : // Es wird kein BigInt gebraucht, da diese Funktion nur zur Umrechnung
2376 : // von Fensterposition benutzt wird
2377 1399 : nY = nY * mnDPIY * pFrameData->maMapUnitRes.mnMapScNumY;
2378 1399 : nY += nY >= 0 ? (pFrameData->maMapUnitRes.mnMapScDenomY/2) :
2379 2798 : -((pFrameData->maMapUnitRes.mnMapScDenomY-1)/2);
2380 1399 : nY /= pFrameData->maMapUnitRes.mnMapScDenomY;
2381 : }
2382 :
2383 1399 : return nY;
2384 465 : }
2385 :
2386 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|