LCOV - code coverage report
Current view: top level - vcl/source/gdi - outmap.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 695 965 72.0 %
Date: 2014-04-11 Functions: 59 79 74.7 %
Legend: Lines: hit not hit

          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             : #include <limits.h>
      21             : 
      22             : #include <tools/bigint.hxx>
      23             : #include <tools/debug.hxx>
      24             : #include <tools/poly.hxx>
      25             : 
      26             : #include <vcl/virdev.hxx>
      27             : #include <vcl/region.hxx>
      28             : #include <vcl/wrkwin.hxx>
      29             : #include <vcl/cursor.hxx>
      30             : #include <vcl/metaact.hxx>
      31             : #include <vcl/gdimtf.hxx>
      32             : #include <vcl/lineinfo.hxx>
      33             : #include <vcl/outdev.hxx>
      34             : 
      35             : #include <svdata.hxx>
      36             : #include <window.h>
      37             : #include <outdev.h>
      38             : #include <salgdi.hxx>
      39             : 
      40             : #include <basegfx/matrix/b2dhommatrix.hxx>
      41             : #include <basegfx/polygon/b2dpolygon.hxx>
      42             : #include <basegfx/polygon/b2dpolypolygon.hxx>
      43             : 
      44             : static int const s_ImplArySize = MAP_PIXEL+1;
      45             : static const long aImplNumeratorAry[s_ImplArySize] =
      46             :     {    1,   1,   5,  50,    1,   1,  1, 1,  1,    1, 1 };
      47             : static const long aImplDenominatorAry[s_ImplArySize] =
      48             :      { 2540, 254, 127, 127, 1000, 100, 10, 1, 72, 1440, 1 };
      49             : 
      50             : /*
      51             : Reduces accuracy until it is a fraction (should become
      52             : ctor fraction once); we could also do this with BigInts
      53             : */
      54             : 
      55     2222254 : static Fraction ImplMakeFraction( long nN1, long nN2, long nD1, long nD2 )
      56             : {
      57     2222254 :     long i = 1;
      58             : 
      59     2222254 :     if ( nN1 < 0 ) { i = -i; nN1 = -nN1; }
      60     2222254 :     if ( nN2 < 0 ) { i = -i; nN2 = -nN2; }
      61     2222254 :     if ( nD1 < 0 ) { i = -i; nD1 = -nD1; }
      62     2222254 :     if ( nD2 < 0 ) { i = -i; nD2 = -nD2; }
      63             :     // all positive; i sign
      64             : 
      65     2222254 :     Fraction aF( i*nN1, nD1 );
      66     2222254 :     aF *= Fraction( nN2, nD2 );
      67             : 
      68     2222254 :     if( nD1 == 0 || nD2 == 0 ) //under these bad circumstances the following while loop will be endless
      69             :     {
      70             :         DBG_ASSERT(false,"Invalid parameter for ImplMakeFraction");
      71           0 :         return Fraction( 1, 1 );
      72             :     }
      73             : 
      74     4593788 :     while ( aF.GetDenominator() == -1 )
      75             :     {
      76      149280 :         if ( nN1 > nN2 )
      77           0 :             nN1 = (nN1 + 1) / 2;
      78             :         else
      79      149280 :             nN2 = (nN2 + 1) / 2;
      80      149280 :         if ( nD1 > nD2 )
      81           0 :             nD1 = (nD1 + 1) / 2;
      82             :         else
      83      149280 :             nD2 = (nD2 + 1) / 2;
      84             : 
      85      149280 :         aF = Fraction( i*nN1, nD1 );
      86      149280 :         aF *= Fraction( nN2, nD2 );
      87             :     }
      88             : 
      89     2222254 :     return aF;
      90             : }
      91             : 
      92             : // Fraction.GetNumerator()
      93             : // Fraction.GetDenominator()    > 0
      94             : // rOutRes.nPixPerInch?         > 0
      95             : // rMapRes.nMapScNum?
      96             : // rMapRes.nMapScDenom?         > 0
      97             : 
      98     1105690 : static void ImplCalcBigIntThreshold( long nDPIX, long nDPIY,
      99             :                                      const ImplMapRes& rMapRes,
     100             :                                      ImplThresholdRes& rThresRes )
     101             : {
     102     1105690 :     if ( nDPIX && (LONG_MAX / nDPIX < std::abs( rMapRes.mnMapScNumX ) ) ) // #111139# avoid div by zero
     103             :     {
     104           0 :         rThresRes.mnThresLogToPixX = 0;
     105           0 :         rThresRes.mnThresPixToLogX = 0;
     106             :     }
     107             :     else
     108             :     {
     109             :         // calculate thresholds for BigInt arithmetic
     110     1105690 :         long    nDenomHalfX = rMapRes.mnMapScDenomX / 2;
     111     1105690 :         sal_uLong   nDenomX     = rMapRes.mnMapScDenomX;
     112     1105690 :         long    nProductX   = nDPIX * rMapRes.mnMapScNumX;
     113             : 
     114     1105690 :         if ( !nProductX )
     115           0 :             rThresRes.mnThresLogToPixX = LONG_MAX;
     116             :         else
     117     1105690 :             rThresRes.mnThresLogToPixX = std::abs( (LONG_MAX - nDenomHalfX) / nProductX );
     118             : 
     119     1105690 :         if ( !nDenomX )
     120           0 :             rThresRes.mnThresPixToLogX = LONG_MAX;
     121     1105690 :         else if ( nProductX >= 0 )
     122     1105690 :             rThresRes.mnThresPixToLogX = (long)(((sal_uLong)LONG_MAX - (sal_uLong)( nProductX/2)) / nDenomX);
     123             :         else
     124           0 :             rThresRes.mnThresPixToLogX = (long)(((sal_uLong)LONG_MAX + (sal_uLong)(-nProductX/2)) / nDenomX);
     125             :     }
     126             : 
     127     1105690 :     if ( nDPIY && (LONG_MAX / nDPIY < std::abs( rMapRes.mnMapScNumY ) ) ) // #111139# avoid div by zero
     128             :     {
     129           0 :         rThresRes.mnThresLogToPixY = 0;
     130           0 :         rThresRes.mnThresPixToLogY = 0;
     131             :     }
     132             :     else
     133             :     {
     134             :         // calculate thresholds for BigInt arithmetic
     135     1105690 :         long    nDenomHalfY = rMapRes.mnMapScDenomY / 2;
     136     1105690 :         sal_uLong   nDenomY     = rMapRes.mnMapScDenomY;
     137     1105690 :         long    nProductY   = nDPIY * rMapRes.mnMapScNumY;
     138             : 
     139     1105690 :         if ( !nProductY )
     140           0 :             rThresRes.mnThresLogToPixY = LONG_MAX;
     141             :         else
     142     1105690 :             rThresRes.mnThresLogToPixY = std::abs( (LONG_MAX - nDenomHalfY) / nProductY );
     143             : 
     144     1105690 :         if ( !nDenomY )
     145           0 :             rThresRes.mnThresPixToLogY = LONG_MAX;
     146     1105690 :         else if ( nProductY >= 0 )
     147     1105690 :             rThresRes.mnThresPixToLogY = (long)(((sal_uLong)LONG_MAX - (sal_uLong)( nProductY/2)) / nDenomY);
     148             :         else
     149           0 :             rThresRes.mnThresPixToLogY = (long)(((sal_uLong)LONG_MAX + (sal_uLong)(-nProductY/2)) / nDenomY);
     150             :     }
     151             : 
     152     1105690 :     rThresRes.mnThresLogToPixX /= 2;
     153     1105690 :     rThresRes.mnThresLogToPixY /= 2;
     154     1105690 :     rThresRes.mnThresPixToLogX /= 2;
     155     1105690 :     rThresRes.mnThresPixToLogY /= 2;
     156     1105690 : }
     157             : 
     158     1110963 : static void ImplCalcMapResolution( const MapMode& rMapMode,
     159             :                                    long nDPIX, long nDPIY, ImplMapRes& rMapRes )
     160             : {
     161     1110963 :     switch ( rMapMode.GetMapUnit() )
     162             :     {
     163             :         case MAP_RELATIVE:
     164          93 :             break;
     165             :         case MAP_100TH_MM:
     166       53196 :             rMapRes.mnMapScNumX   = 1;
     167       53196 :             rMapRes.mnMapScDenomX = 2540;
     168       53196 :             rMapRes.mnMapScNumY   = 1;
     169       53196 :             rMapRes.mnMapScDenomY = 2540;
     170       53196 :             break;
     171             :         case MAP_10TH_MM:
     172          46 :             rMapRes.mnMapScNumX   = 1;
     173          46 :             rMapRes.mnMapScDenomX = 254;
     174          46 :             rMapRes.mnMapScNumY   = 1;
     175          46 :             rMapRes.mnMapScDenomY = 254;
     176          46 :             break;
     177             :         case MAP_MM:
     178          10 :             rMapRes.mnMapScNumX   = 5;      // 10
     179          10 :             rMapRes.mnMapScDenomX = 127;    // 254
     180          10 :             rMapRes.mnMapScNumY   = 5;      // 10
     181          10 :             rMapRes.mnMapScDenomY = 127;    // 254
     182          10 :             break;
     183             :         case MAP_CM:
     184       27621 :             rMapRes.mnMapScNumX   = 50;     // 100
     185       27621 :             rMapRes.mnMapScDenomX = 127;    // 254
     186       27621 :             rMapRes.mnMapScNumY   = 50;     // 100
     187       27621 :             rMapRes.mnMapScDenomY = 127;    // 254
     188       27621 :             break;
     189             :         case MAP_1000TH_INCH:
     190      890913 :             rMapRes.mnMapScNumX   = 1;
     191      890913 :             rMapRes.mnMapScDenomX = 1000;
     192      890913 :             rMapRes.mnMapScNumY   = 1;
     193      890913 :             rMapRes.mnMapScDenomY = 1000;
     194      890913 :             break;
     195             :         case MAP_100TH_INCH:
     196           1 :             rMapRes.mnMapScNumX   = 1;
     197           1 :             rMapRes.mnMapScDenomX = 100;
     198           1 :             rMapRes.mnMapScNumY   = 1;
     199           1 :             rMapRes.mnMapScDenomY = 100;
     200           1 :             break;
     201             :         case MAP_10TH_INCH:
     202           1 :             rMapRes.mnMapScNumX   = 1;
     203           1 :             rMapRes.mnMapScDenomX = 10;
     204           1 :             rMapRes.mnMapScNumY   = 1;
     205           1 :             rMapRes.mnMapScDenomY = 10;
     206           1 :             break;
     207             :         case MAP_INCH:
     208        1912 :             rMapRes.mnMapScNumX   = 1;
     209        1912 :             rMapRes.mnMapScDenomX = 1;
     210        1912 :             rMapRes.mnMapScNumY   = 1;
     211        1912 :             rMapRes.mnMapScDenomY = 1;
     212        1912 :             break;
     213             :         case MAP_POINT:
     214         444 :             rMapRes.mnMapScNumX   = 1;
     215         444 :             rMapRes.mnMapScDenomX = 72;
     216         444 :             rMapRes.mnMapScNumY   = 1;
     217         444 :             rMapRes.mnMapScDenomY = 72;
     218         444 :             break;
     219             :         case MAP_TWIP:
     220      120468 :             rMapRes.mnMapScNumX   = 1;
     221      120468 :             rMapRes.mnMapScDenomX = 1440;
     222      120468 :             rMapRes.mnMapScNumY   = 1;
     223      120468 :             rMapRes.mnMapScDenomY = 1440;
     224      120468 :             break;
     225             :         case MAP_PIXEL:
     226       10448 :             rMapRes.mnMapScNumX   = 1;
     227       10448 :             rMapRes.mnMapScDenomX = nDPIX;
     228       10448 :             rMapRes.mnMapScNumY   = 1;
     229       10448 :             rMapRes.mnMapScDenomY = nDPIY;
     230       10448 :             break;
     231             :         case MAP_SYSFONT:
     232             :         case MAP_APPFONT:
     233             :             {
     234        5810 :             ImplSVData* pSVData = ImplGetSVData();
     235        5810 :             if ( !pSVData->maGDIData.mnAppFontX )
     236             :             {
     237          20 :                 if( pSVData->maWinData.mpFirstFrame )
     238          20 :                     Window::ImplInitAppFontData( pSVData->maWinData.mpFirstFrame );
     239             :                 else
     240             :                 {
     241           0 :                     WorkWindow* pWin = new WorkWindow( NULL, 0 );
     242           0 :                     Window::ImplInitAppFontData( pWin );
     243           0 :                     delete pWin;
     244             :                 }
     245             :             }
     246        5810 :             rMapRes.mnMapScNumX   = pSVData->maGDIData.mnAppFontX;
     247        5810 :             rMapRes.mnMapScDenomX = nDPIX * 40;
     248        5810 :             rMapRes.mnMapScNumY   = pSVData->maGDIData.mnAppFontY;
     249        5810 :             rMapRes.mnMapScDenomY = nDPIY * 80;
     250             :             }
     251        5810 :             break;
     252             :         default:
     253             :             OSL_FAIL( "unhandled MapUnit" );
     254           0 :             break;
     255             :     }
     256             : 
     257     1110963 :     Fraction aScaleX = rMapMode.GetScaleX();
     258     1110963 :     Fraction aScaleY = rMapMode.GetScaleY();
     259             : 
     260             :     // set offset according to MapMode
     261     1110963 :     Point aOrigin = rMapMode.GetOrigin();
     262     1110963 :     if ( rMapMode.GetMapUnit() != MAP_RELATIVE )
     263             :     {
     264     1110870 :         rMapRes.mnMapOfsX = aOrigin.X();
     265     1110870 :         rMapRes.mnMapOfsY = aOrigin.Y();
     266             :     }
     267             :     else
     268             :     {
     269          93 :         BigInt aX( rMapRes.mnMapOfsX );
     270          93 :         aX *= BigInt( aScaleX.GetDenominator() );
     271          93 :         if ( rMapRes.mnMapOfsX >= 0 )
     272             :         {
     273          77 :             if ( aScaleX.GetNumerator() >= 0 )
     274          77 :                 aX += BigInt( aScaleX.GetNumerator()/2 );
     275             :             else
     276           0 :                 aX -= BigInt( (aScaleX.GetNumerator()+1)/2 );
     277             :         }
     278             :         else
     279             :         {
     280          16 :             if ( aScaleX.GetNumerator() >= 0 )
     281          16 :                 aX -= BigInt( (aScaleX.GetNumerator()-1)/2 );
     282             :             else
     283           0 :                 aX += BigInt( aScaleX.GetNumerator()/2 );
     284             :         }
     285          93 :         aX /= BigInt( aScaleX.GetNumerator() );
     286          93 :         rMapRes.mnMapOfsX = (long)aX + aOrigin.X();
     287          93 :         BigInt aY( rMapRes.mnMapOfsY );
     288          93 :         aY *= BigInt( aScaleY.GetDenominator() );
     289          93 :         if( rMapRes.mnMapOfsY >= 0 )
     290             :         {
     291          77 :             if ( aScaleY.GetNumerator() >= 0 )
     292          77 :                 aY += BigInt( aScaleY.GetNumerator()/2 );
     293             :             else
     294           0 :                 aY -= BigInt( (aScaleY.GetNumerator()+1)/2 );
     295             :         }
     296             :         else
     297             :         {
     298          16 :             if ( aScaleY.GetNumerator() >= 0 )
     299          16 :                 aY -= BigInt( (aScaleY.GetNumerator()-1)/2 );
     300             :             else
     301           0 :                 aY += BigInt( aScaleY.GetNumerator()/2 );
     302             :         }
     303          93 :         aY /= BigInt( aScaleY.GetNumerator() );
     304          93 :         rMapRes.mnMapOfsY = (long)aY + aOrigin.Y();
     305             :     }
     306             : 
     307             :     // calculate scaling factor according to MapMode
     308             :     // aTemp? = rMapRes.mnMapSc? * aScale?
     309             :     Fraction aTempX = ImplMakeFraction( rMapRes.mnMapScNumX,
     310             :                                         aScaleX.GetNumerator(),
     311             :                                         rMapRes.mnMapScDenomX,
     312     1110963 :                                         aScaleX.GetDenominator() );
     313             :     Fraction aTempY = ImplMakeFraction( rMapRes.mnMapScNumY,
     314             :                                         aScaleY.GetNumerator(),
     315             :                                         rMapRes.mnMapScDenomY,
     316     1110963 :                                         aScaleY.GetDenominator() );
     317     1110963 :     rMapRes.mnMapScNumX   = aTempX.GetNumerator();
     318     1110963 :     rMapRes.mnMapScDenomX = aTempX.GetDenominator();
     319     1110963 :     rMapRes.mnMapScNumY   = aTempY.GetNumerator();
     320     1110963 :     rMapRes.mnMapScDenomY = aTempY.GetDenominator();
     321             : 
     322             :     // hack: 0/n approximately 1/max
     323     1110963 :     if ( !rMapRes.mnMapScNumX )
     324             :     {
     325           0 :         rMapRes.mnMapScNumX = 1;
     326           0 :         rMapRes.mnMapScDenomX = LONG_MAX;
     327             :     }
     328     1110963 :     if ( !rMapRes.mnMapScNumY )
     329             :     {
     330           0 :         rMapRes.mnMapScNumY = 1;
     331           0 :         rMapRes.mnMapScDenomY = LONG_MAX;
     332             :     }
     333     1110963 : }
     334             : 
     335     1105690 : inline void ImplCalcMapResolution( const MapMode& rMapMode,
     336             :                                    long nDPIX, long nDPIY,
     337             :                                    ImplMapRes& rMapRes,
     338             :                                    ImplThresholdRes& rThresRes )
     339             : {
     340     1105690 :     ImplCalcMapResolution( rMapMode, nDPIX, nDPIY, rMapRes );
     341     1105690 :     ImplCalcBigIntThreshold( nDPIX, nDPIY, rMapRes, rThresRes );
     342     1105690 : }
     343             : 
     344     8806624 : static long ImplLogicToPixel( long n, long nDPI, long nMapNum, long nMapDenom,
     345             :                               long nThres )
     346             : {
     347             :     // To "use" it...
     348             :     (void) nThres;
     349             : #if (SAL_TYPES_SIZEOFLONG < 8)
     350     8806624 :     if( (+n < nThres) && (-n < nThres) )
     351             :     {
     352     8722228 :        n *= nMapNum * nDPI;
     353    17444456 :        if( nMapDenom != 1 )
     354             :        {
     355     8720350 :           n = (2 * n) / nMapDenom;
     356     8720350 :           if( n < 0 ) --n; else ++n;
     357     8720350 :           n /= 2;
     358             :        }
     359             :     }
     360             :     else
     361             : #endif
     362             :     {
     363       84396 :        sal_Int64 n64 = n;
     364       84396 :        n64 *= nMapNum;
     365       84396 :        n64 *= nDPI;
     366       84396 :        if( nMapDenom == 1 )
     367           0 :           n = (long)n64;
     368             :        else
     369             :        {
     370       84396 :           n = (long)(2 * n64 / nMapDenom);
     371       84396 :           if( n < 0 ) --n; else ++n;
     372       84396 :           n /= 2;
     373             :        }
     374             :     }
     375     8806624 :     return n;
     376             : }
     377             : 
     378     9523651 : static long ImplPixelToLogic( long n, long nDPI, long nMapNum, long nMapDenom,
     379             :                               long nThres )
     380             : {
     381             :     // To "use" it...
     382             :    (void) nThres;
     383             : #if (SAL_TYPES_SIZEOFLONG < 8)
     384     9523651 :     if( (+n < nThres) && (-n < nThres) )
     385     9462065 :         n = (2 * n * nMapDenom) / (nDPI * nMapNum);
     386             :     else
     387             : #endif
     388             :     {
     389       61586 :         sal_Int64 n64 = n;
     390       61586 :         n64 *= nMapDenom;
     391       61586 :         long nDenom  = nDPI * nMapNum;
     392       61586 :         n = (long)(2 * n64 / nDenom);
     393             :     }
     394     9523651 :     if( n < 0 ) --n; else ++n;
     395     9523651 :     return (n / 2);
     396             : }
     397             : 
     398      362689 : long OutputDevice::ImplLogicXToDevicePixel( long nX ) const
     399             : {
     400      362689 :     if ( !mbMap )
     401      357386 :         return nX+mnOutOffX;
     402             : 
     403             :     return ImplLogicToPixel( nX + maMapRes.mnMapOfsX, mnDPIX,
     404             :                              maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
     405        5303 :                              maThresRes.mnThresLogToPixX )+mnOutOffX+mnOutOffOrigX;
     406             : }
     407             : 
     408      370451 : long OutputDevice::ImplLogicYToDevicePixel( long nY ) const
     409             : {
     410      370451 :     if ( !mbMap )
     411      366826 :         return nY+mnOutOffY;
     412             : 
     413             :     return ImplLogicToPixel( nY + maMapRes.mnMapOfsY, mnDPIY,
     414             :                              maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
     415        3625 :                              maThresRes.mnThresLogToPixY )+mnOutOffY+mnOutOffOrigY;
     416             : }
     417             : 
     418     1185665 : long OutputDevice::ImplLogicWidthToDevicePixel( long nWidth ) const
     419             : {
     420     1185665 :     if ( !mbMap )
     421      480065 :         return nWidth;
     422             : 
     423             :     return ImplLogicToPixel( nWidth, mnDPIX,
     424             :                              maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
     425      705600 :                              maThresRes.mnThresLogToPixX );
     426             : }
     427             : 
     428      335679 : long OutputDevice::ImplLogicHeightToDevicePixel( long nHeight ) const
     429             : {
     430      335679 :     if ( !mbMap )
     431      334861 :         return nHeight;
     432             : 
     433             :     return ImplLogicToPixel( nHeight, mnDPIY,
     434             :                              maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
     435         818 :                              maThresRes.mnThresLogToPixY );
     436             : }
     437             : 
     438      663513 : float OutputDevice::ImplFloatLogicHeightToDevicePixel( float fLogicHeight) const
     439             : {
     440      663513 :     if( !mbMap)
     441       75951 :         return fLogicHeight;
     442      587562 :     float fPixelHeight = (fLogicHeight * mnDPIY * maMapRes.mnMapScNumY) / maMapRes.mnMapScDenomY;
     443      587562 :     return fPixelHeight;
     444             : }
     445             : 
     446     2580554 : long OutputDevice::ImplDevicePixelToLogicWidth( long nWidth ) const
     447             : {
     448     2580554 :     if ( !mbMap )
     449         536 :         return nWidth;
     450             : 
     451             :     return ImplPixelToLogic( nWidth, mnDPIX,
     452             :                              maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
     453     2580018 :                              maThresRes.mnThresPixToLogX );
     454             : }
     455             : 
     456     3366605 : long OutputDevice::ImplDevicePixelToLogicHeight( long nHeight ) const
     457             : {
     458     3366605 :     if ( !mbMap )
     459      129312 :         return nHeight;
     460             : 
     461             :     return ImplPixelToLogic( nHeight, mnDPIY,
     462             :                              maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
     463     3237293 :                              maThresRes.mnThresPixToLogY );
     464             : }
     465             : 
     466     3189261 : Point OutputDevice::ImplLogicToDevicePixel( const Point& rLogicPt ) const
     467             : {
     468     3189261 :     if ( !mbMap )
     469     2833515 :         return Point( rLogicPt.X()+mnOutOffX, rLogicPt.Y()+mnOutOffY );
     470             : 
     471      355746 :     return Point( ImplLogicToPixel( rLogicPt.X() + maMapRes.mnMapOfsX, mnDPIX,
     472             :                                     maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
     473      711492 :                                     maThresRes.mnThresLogToPixX )+mnOutOffX+mnOutOffOrigX,
     474      355746 :                   ImplLogicToPixel( rLogicPt.Y() + maMapRes.mnMapOfsY, mnDPIY,
     475             :                                     maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
     476     1067238 :                                     maThresRes.mnThresLogToPixY )+mnOutOffY+mnOutOffOrigY );
     477             : }
     478             : 
     479      732478 : Size OutputDevice::ImplLogicToDevicePixel( const Size& rLogicSize ) const
     480             : {
     481      732478 :     if ( !mbMap )
     482      144540 :         return rLogicSize;
     483             : 
     484             :     return Size( ImplLogicToPixel( rLogicSize.Width(), mnDPIX,
     485             :                                    maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
     486             :                                    maThresRes.mnThresLogToPixX ),
     487             :                  ImplLogicToPixel( rLogicSize.Height(), mnDPIY,
     488             :                                    maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
     489      587938 :                                    maThresRes.mnThresLogToPixY ) );
     490             : }
     491             : 
     492      817393 : Rectangle OutputDevice::ImplLogicToDevicePixel( const Rectangle& rLogicRect ) const
     493             : {
     494      817393 :     if ( rLogicRect.IsEmpty() )
     495       11403 :         return rLogicRect;
     496             : 
     497      805990 :     if ( !mbMap )
     498             :     {
     499     1493724 :         return Rectangle( rLogicRect.Left()+mnOutOffX, rLogicRect.Top()+mnOutOffY,
     500     2240586 :                           rLogicRect.Right()+mnOutOffX, rLogicRect.Bottom()+mnOutOffY );
     501             :     }
     502             : 
     503       59128 :     return Rectangle( ImplLogicToPixel( rLogicRect.Left()+maMapRes.mnMapOfsX, mnDPIX,
     504             :                                         maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
     505      118256 :                                         maThresRes.mnThresLogToPixX )+mnOutOffX+mnOutOffOrigX,
     506       59128 :                       ImplLogicToPixel( rLogicRect.Top()+maMapRes.mnMapOfsY, mnDPIY,
     507             :                                         maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
     508      118256 :                                         maThresRes.mnThresLogToPixY )+mnOutOffY+mnOutOffOrigY,
     509       59128 :                       ImplLogicToPixel( rLogicRect.Right()+maMapRes.mnMapOfsX, mnDPIX,
     510             :                                         maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
     511      118256 :                                         maThresRes.mnThresLogToPixX )+mnOutOffX+mnOutOffOrigX,
     512       59128 :                       ImplLogicToPixel( rLogicRect.Bottom()+maMapRes.mnMapOfsY, mnDPIY,
     513             :                                         maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
     514      295640 :                                         maThresRes.mnThresLogToPixY )+mnOutOffY+mnOutOffOrigY );
     515             : }
     516             : 
     517      400202 : Polygon OutputDevice::ImplLogicToDevicePixel( const Polygon& rLogicPoly ) const
     518             : {
     519      400202 :     if ( !mbMap && !mnOutOffX && !mnOutOffY )
     520      236734 :         return rLogicPoly;
     521             : 
     522             :     sal_uInt16  i;
     523      163468 :     sal_uInt16  nPoints = rLogicPoly.GetSize();
     524      163468 :     Polygon aPoly( rLogicPoly );
     525             : 
     526             :     // get pointer to Point-array (copy data)
     527      163468 :     const Point* pPointAry = aPoly.GetConstPointAry();
     528             : 
     529      163468 :     if ( mbMap )
     530             :     {
     531     1145979 :         for ( i = 0; i < nPoints; i++ )
     532             :         {
     533      991869 :             const Point* pPt = &(pPointAry[i]);
     534      991869 :             Point aPt;
     535     1983738 :             aPt.X() = ImplLogicToPixel( pPt->X()+maMapRes.mnMapOfsX, mnDPIX,
     536             :                                         maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
     537     1983738 :                                         maThresRes.mnThresLogToPixX )+mnOutOffX+mnOutOffOrigX;
     538     1983738 :             aPt.Y() = ImplLogicToPixel( pPt->Y()+maMapRes.mnMapOfsY, mnDPIY,
     539             :                                         maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
     540     1983738 :                                         maThresRes.mnThresLogToPixY )+mnOutOffY+mnOutOffOrigY;
     541      991869 :             aPoly[i] = aPt;
     542             :         }
     543             :     }
     544             :     else
     545             :     {
     546      147641 :         for ( i = 0; i < nPoints; i++ )
     547             :         {
     548      138283 :             Point aPt = pPointAry[i];
     549      138283 :             aPt.X() += mnOutOffX;
     550      138283 :             aPt.Y() += mnOutOffY;
     551      138283 :             aPoly[i] = aPt;
     552             :         }
     553             :     }
     554             : 
     555      163468 :     return aPoly;
     556             : }
     557             : 
     558       50575 : PolyPolygon OutputDevice::ImplLogicToDevicePixel( const PolyPolygon& rLogicPolyPoly ) const
     559             : {
     560       50575 :     if ( !mbMap && !mnOutOffX && !mnOutOffY )
     561        2934 :         return rLogicPolyPoly;
     562             : 
     563       47641 :     PolyPolygon aPolyPoly( rLogicPolyPoly );
     564       47641 :     sal_uInt16      nPoly = aPolyPoly.Count();
     565       95866 :     for( sal_uInt16 i = 0; i < nPoly; i++ )
     566             :     {
     567       48225 :         Polygon& rPoly = aPolyPoly[i];
     568       48225 :         rPoly = ImplLogicToDevicePixel( rPoly );
     569             :     }
     570       47641 :     return aPolyPoly;
     571             : }
     572             : 
     573      136627 : LineInfo OutputDevice::ImplLogicToDevicePixel( const LineInfo& rLineInfo ) const
     574             : {
     575      136627 :     LineInfo aInfo( rLineInfo );
     576             : 
     577      136627 :     if( aInfo.GetStyle() == LINE_DASH )
     578             :     {
     579           5 :         if( aInfo.GetDotCount() && aInfo.GetDotLen() )
     580           5 :             aInfo.SetDotLen( std::max( ImplLogicWidthToDevicePixel( aInfo.GetDotLen() ), 1L ) );
     581             :         else
     582           0 :             aInfo.SetDotCount( 0 );
     583             : 
     584           5 :         if( aInfo.GetDashCount() && aInfo.GetDashLen() )
     585           0 :             aInfo.SetDashLen( std::max( ImplLogicWidthToDevicePixel( aInfo.GetDashLen() ), 1L ) );
     586             :         else
     587           5 :             aInfo.SetDashCount( 0 );
     588             : 
     589           5 :         aInfo.SetDistance( ImplLogicWidthToDevicePixel( aInfo.GetDistance() ) );
     590             : 
     591           5 :         if( ( !aInfo.GetDashCount() && !aInfo.GetDotCount() ) || !aInfo.GetDistance() )
     592           0 :             aInfo.SetStyle( LINE_SOLID );
     593             :     }
     594             : 
     595      136627 :     aInfo.SetWidth( ImplLogicWidthToDevicePixel( aInfo.GetWidth() ) );
     596             : 
     597      136627 :     return aInfo;
     598             : }
     599             : 
     600       75948 : Rectangle OutputDevice::ImplDevicePixelToLogic( const Rectangle& rPixelRect ) const
     601             : {
     602       75948 :     if ( rPixelRect.IsEmpty() )
     603           0 :         return rPixelRect;
     604             : 
     605       75948 :     if ( !mbMap )
     606             :     {
     607      137934 :         return Rectangle( rPixelRect.Left()-mnOutOffX, rPixelRect.Top()-mnOutOffY,
     608      206901 :                           rPixelRect.Right()-mnOutOffX, rPixelRect.Bottom()-mnOutOffY );
     609             :     }
     610             : 
     611        6981 :     return Rectangle( ImplPixelToLogic( rPixelRect.Left()-mnOutOffX-mnOutOffOrigX, mnDPIX,
     612             :                                         maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
     613       13962 :                                         maThresRes.mnThresPixToLogX )-maMapRes.mnMapOfsX,
     614        6981 :                       ImplPixelToLogic( rPixelRect.Top()-mnOutOffY-mnOutOffOrigY, mnDPIY,
     615             :                                         maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
     616       13962 :                                         maThresRes.mnThresPixToLogY )-maMapRes.mnMapOfsY,
     617        6981 :                       ImplPixelToLogic( rPixelRect.Right()-mnOutOffX-mnOutOffOrigX, mnDPIX,
     618             :                                         maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
     619       13962 :                                         maThresRes.mnThresPixToLogX )-maMapRes.mnMapOfsX,
     620        6981 :                       ImplPixelToLogic( rPixelRect.Bottom()-mnOutOffY-mnOutOffOrigY, mnDPIY,
     621             :                                         maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
     622       34905 :                                         maThresRes.mnThresPixToLogY )-maMapRes.mnMapOfsY );
     623             : }
     624             : 
     625      362639 : Region OutputDevice::ImplPixelToDevicePixel( const Region& rRegion ) const
     626             : {
     627      362639 :     if ( !mnOutOffX && !mnOutOffY )
     628       33667 :         return rRegion;
     629             : 
     630      328972 :     Region aRegion( rRegion );
     631      328972 :     aRegion.Move( mnOutOffX+mnOutOffOrigX, mnOutOffY+mnOutOffOrigY );
     632      328972 :     return aRegion;
     633             : }
     634             : 
     635      777921 : void OutputDevice::EnableMapMode( bool bEnable )
     636             : {
     637      777921 :     mbMap = bEnable;
     638             : 
     639      777921 :     if( mpAlphaVDev )
     640        9272 :         mpAlphaVDev->EnableMapMode( bEnable );
     641      777921 : }
     642             : 
     643       60278 : void OutputDevice::SetMapMode()
     644             : {
     645             : 
     646       60278 :     if ( mpMetaFile )
     647           0 :         mpMetaFile->AddAction( new MetaMapModeAction( MapMode() ) );
     648             : 
     649       60278 :     if ( mbMap || !maMapMode.IsDefault() )
     650             :     {
     651       57416 :         mbMap       = false;
     652       57416 :         maMapMode   = MapMode();
     653             : 
     654             :         // create new objects (clip region are not re-scaled)
     655       57416 :         mbNewFont   = true;
     656       57416 :         mbInitFont  = true;
     657       57416 :         if ( GetOutDevType() == OUTDEV_WINDOW )
     658             :         {
     659       27455 :             if ( ((Window*)this)->mpWindowImpl->mpCursor )
     660       27362 :                 ((Window*)this)->mpWindowImpl->mpCursor->ImplNew();
     661             :         }
     662             : 
     663             :         // #106426# Adapt logical offset when changing mapmode
     664       57416 :         mnOutOffLogicX = mnOutOffOrigX; // no mapping -> equal offsets
     665       57416 :         mnOutOffLogicY = mnOutOffOrigY;
     666             : 
     667             :         // #i75163#
     668       57416 :         ImplInvalidateViewTransform();
     669             :     }
     670             : 
     671       60278 :     if( mpAlphaVDev )
     672           0 :         mpAlphaVDev->SetMapMode();
     673       60278 : }
     674             : 
     675      284456 : void OutputDevice::SetMapMode( const MapMode& rNewMapMode )
     676             : {
     677             : 
     678      284456 :     bool bRelMap = (rNewMapMode.GetMapUnit() == MAP_RELATIVE);
     679             : 
     680      284456 :     if ( mpMetaFile )
     681             :     {
     682         297 :         mpMetaFile->AddAction( new MetaMapModeAction( rNewMapMode ) );
     683             : #ifdef DBG_UTIL
     684             :         if ( GetOutDevType() != OUTDEV_PRINTER )
     685             :             DBG_ASSERTWARNING( bRelMap, "Please record only relative MapModes!" );
     686             : #endif
     687             :     }
     688             : 
     689             :     // do nothing if MapMode was not changed
     690      284456 :     if ( maMapMode == rNewMapMode )
     691      135272 :         return;
     692             : 
     693      149184 :     if( mpAlphaVDev )
     694         488 :         mpAlphaVDev->SetMapMode( rNewMapMode );
     695             : 
     696             :      // if default MapMode calculate nothing
     697      149184 :     bool bOldMap = mbMap;
     698      149184 :     mbMap = !rNewMapMode.IsDefault();
     699      149184 :     if ( mbMap )
     700             :     {
     701             :         // if only the origin is converted, do not scale new
     702      290505 :         if ( (rNewMapMode.GetMapUnit() == maMapMode.GetMapUnit()) &&
     703       24799 :              (rNewMapMode.GetScaleX()  == maMapMode.GetScaleX())  &&
     704      162063 :              (rNewMapMode.GetScaleY()  == maMapMode.GetScaleY())  &&
     705       11627 :              (bOldMap                  == mbMap) )
     706             :         {
     707             :             // set offset
     708        1721 :             Point aOrigin = rNewMapMode.GetOrigin();
     709        1721 :             maMapRes.mnMapOfsX = aOrigin.X();
     710        1721 :             maMapRes.mnMapOfsY = aOrigin.Y();
     711        1721 :             maMapMode = rNewMapMode;
     712             : 
     713             :             // #i75163#
     714        1721 :             ImplInvalidateViewTransform();
     715             : 
     716        1721 :             return;
     717             :         }
     718      136993 :         if ( !bOldMap && bRelMap )
     719             :         {
     720          10 :             maMapRes.mnMapScNumX    = 1;
     721          10 :             maMapRes.mnMapScNumY    = 1;
     722          10 :             maMapRes.mnMapScDenomX  = mnDPIX;
     723          10 :             maMapRes.mnMapScDenomY  = mnDPIY;
     724          10 :             maMapRes.mnMapOfsX      = 0;
     725          10 :             maMapRes.mnMapOfsY      = 0;
     726             :         }
     727             : 
     728             :         // calculate new MapMode-resolution
     729      136993 :         ImplCalcMapResolution( rNewMapMode, mnDPIX, mnDPIY, maMapRes, maThresRes );
     730             :     }
     731             : 
     732             :     // set new MapMode
     733      147463 :     if ( bRelMap )
     734             :     {
     735          93 :         Point aOrigin( maMapRes.mnMapOfsX, maMapRes.mnMapOfsY );
     736             :         // aScale? = maMapMode.GetScale?() * rNewMapMode.GetScale?()
     737          93 :         Fraction aScaleX = ImplMakeFraction( maMapMode.GetScaleX().GetNumerator(),
     738          93 :                                              rNewMapMode.GetScaleX().GetNumerator(),
     739          93 :                                              maMapMode.GetScaleX().GetDenominator(),
     740         372 :                                              rNewMapMode.GetScaleX().GetDenominator() );
     741          93 :         Fraction aScaleY = ImplMakeFraction( maMapMode.GetScaleY().GetNumerator(),
     742          93 :                                              rNewMapMode.GetScaleY().GetNumerator(),
     743          93 :                                              maMapMode.GetScaleY().GetDenominator(),
     744         372 :                                              rNewMapMode.GetScaleY().GetDenominator() );
     745          93 :         maMapMode.SetOrigin( aOrigin );
     746          93 :         maMapMode.SetScaleX( aScaleX );
     747          93 :         maMapMode.SetScaleY( aScaleY );
     748             :     }
     749             :     else
     750      147370 :         maMapMode = rNewMapMode;
     751             : 
     752             :     // create new objects (clip region are not re-scaled)
     753      147463 :     mbNewFont   = true;
     754      147463 :     mbInitFont  = true;
     755      147463 :     if ( GetOutDevType() == OUTDEV_WINDOW )
     756             :     {
     757       34287 :         if ( ((Window*)this)->mpWindowImpl->mpCursor )
     758       27945 :             ((Window*)this)->mpWindowImpl->mpCursor->ImplNew();
     759             :     }
     760             : 
     761             :     // #106426# Adapt logical offset when changing mapmode
     762             :     mnOutOffLogicX = ImplPixelToLogic( mnOutOffOrigX, mnDPIX,
     763             :                                        maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
     764      147463 :                                        maThresRes.mnThresPixToLogX );
     765             :     mnOutOffLogicY = ImplPixelToLogic( mnOutOffOrigY, mnDPIY,
     766             :                                        maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
     767      147463 :                                        maThresRes.mnThresPixToLogY );
     768             : 
     769             :     // #i75163#
     770      147463 :     ImplInvalidateViewTransform();
     771             : }
     772             : 
     773        5060 : void OutputDevice::SetRelativeMapMode( const MapMode& rNewMapMode )
     774             : {
     775             :     // do nothing if MapMode did not change
     776        5060 :     if ( maMapMode == rNewMapMode )
     777       10067 :         return;
     778             : 
     779          53 :     MapUnit eOld = maMapMode.GetMapUnit();
     780          53 :     MapUnit eNew = rNewMapMode.GetMapUnit();
     781             : 
     782             :     // a?F = rNewMapMode.GetScale?() / maMapMode.GetScale?()
     783          53 :     Fraction aXF = ImplMakeFraction( rNewMapMode.GetScaleX().GetNumerator(),
     784          53 :                                      maMapMode.GetScaleX().GetDenominator(),
     785          53 :                                      rNewMapMode.GetScaleX().GetDenominator(),
     786         212 :                                      maMapMode.GetScaleX().GetNumerator() );
     787          53 :     Fraction aYF = ImplMakeFraction( rNewMapMode.GetScaleY().GetNumerator(),
     788          53 :                                      maMapMode.GetScaleY().GetDenominator(),
     789          53 :                                      rNewMapMode.GetScaleY().GetDenominator(),
     790         212 :                                      maMapMode.GetScaleY().GetNumerator() );
     791             : 
     792          53 :     Point aPt( LogicToLogic( Point(), NULL, &rNewMapMode ) );
     793          53 :     if ( eNew != eOld )
     794             :     {
     795          18 :         if ( eOld > MAP_PIXEL )
     796             :         {
     797             :             SAL_WARN( "vcl.gdi", "Not implemented MapUnit" );
     798             :         }
     799          18 :         else if ( eNew > MAP_PIXEL )
     800             :         {
     801             :             SAL_WARN( "vcl.gdi", "Not implemented MapUnit" );
     802             :         }
     803             :         else
     804             :         {
     805          36 :             Fraction aF( aImplNumeratorAry[eNew] * aImplDenominatorAry[eOld],
     806          54 :                          aImplNumeratorAry[eOld] * aImplDenominatorAry[eNew] );
     807             : 
     808             :             // a?F =  a?F * aF
     809          36 :             aXF = ImplMakeFraction( aXF.GetNumerator(),   aF.GetNumerator(),
     810          18 :                                     aXF.GetDenominator(), aF.GetDenominator() );
     811          36 :             aYF = ImplMakeFraction( aYF.GetNumerator(),   aF.GetNumerator(),
     812          18 :                                     aYF.GetDenominator(), aF.GetDenominator() );
     813          18 :             if ( eOld == MAP_PIXEL )
     814             :             {
     815           0 :                 aXF *= Fraction( mnDPIX, 1 );
     816           0 :                 aYF *= Fraction( mnDPIY, 1 );
     817             :             }
     818          18 :             else if ( eNew == MAP_PIXEL )
     819             :             {
     820           0 :                 aXF *= Fraction( 1, mnDPIX );
     821           0 :                 aYF *= Fraction( 1, mnDPIY );
     822             :             }
     823             :         }
     824             :     }
     825             : 
     826          53 :     MapMode aNewMapMode( MAP_RELATIVE, Point( -aPt.X(), -aPt.Y() ), aXF, aYF );
     827          53 :     SetMapMode( aNewMapMode );
     828             : 
     829          53 :     if ( eNew != eOld )
     830          18 :         maMapMode = rNewMapMode;
     831             : 
     832             :     // #106426# Adapt logical offset when changing MapMode
     833             :     mnOutOffLogicX = ImplPixelToLogic( mnOutOffOrigX, mnDPIX,
     834             :                                        maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
     835          53 :                                        maThresRes.mnThresPixToLogX );
     836             :     mnOutOffLogicY = ImplPixelToLogic( mnOutOffOrigY, mnDPIY,
     837             :                                        maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
     838          53 :                                        maThresRes.mnThresPixToLogY );
     839             : 
     840          53 :     if( mpAlphaVDev )
     841           0 :         mpAlphaVDev->SetRelativeMapMode( rNewMapMode );
     842             : }
     843             : 
     844             : // #i75163#
     845      125072 : basegfx::B2DHomMatrix OutputDevice::GetViewTransformation() const
     846             : {
     847      125072 :     if(mbMap)
     848             :     {
     849             :         // #i82615#
     850      118996 :         if(!mpOutDevData)
     851             :         {
     852        2601 :             const_cast< OutputDevice* >(this)->ImplInitOutDevData();
     853             :         }
     854             : 
     855      118996 :         if(!mpOutDevData->mpViewTransform)
     856             :         {
     857       30462 :             mpOutDevData->mpViewTransform = new basegfx::B2DHomMatrix;
     858             : 
     859       30462 :             const double fScaleFactorX((double)mnDPIX * (double)maMapRes.mnMapScNumX / (double)maMapRes.mnMapScDenomX);
     860       30462 :             const double fScaleFactorY((double)mnDPIY * (double)maMapRes.mnMapScNumY / (double)maMapRes.mnMapScDenomY);
     861       30462 :             const double fZeroPointX(((double)maMapRes.mnMapOfsX * fScaleFactorX) + (double)mnOutOffOrigX);
     862       30462 :             const double fZeroPointY(((double)maMapRes.mnMapOfsY * fScaleFactorY) + (double)mnOutOffOrigY);
     863             : 
     864       30462 :             mpOutDevData->mpViewTransform->set(0, 0, fScaleFactorX);
     865       30462 :             mpOutDevData->mpViewTransform->set(1, 1, fScaleFactorY);
     866       30462 :             mpOutDevData->mpViewTransform->set(0, 2, fZeroPointX);
     867       30462 :             mpOutDevData->mpViewTransform->set(1, 2, fZeroPointY);
     868             :         }
     869             : 
     870      118996 :         return *mpOutDevData->mpViewTransform;
     871             :     }
     872             :     else
     873             :     {
     874        6076 :         return basegfx::B2DHomMatrix();
     875             :     }
     876             : }
     877             : 
     878             : // #i75163#
     879       31861 : basegfx::B2DHomMatrix OutputDevice::GetInverseViewTransformation() const
     880             : {
     881       31861 :     if(mbMap)
     882             :     {
     883             :         // #i82615#
     884       31861 :         if(!mpOutDevData)
     885             :         {
     886         351 :             const_cast< OutputDevice* >(this)->ImplInitOutDevData();
     887             :         }
     888             : 
     889       31861 :         if(!mpOutDevData->mpInverseViewTransform)
     890             :         {
     891       15195 :             GetViewTransformation();
     892       15195 :             mpOutDevData->mpInverseViewTransform = new basegfx::B2DHomMatrix(*mpOutDevData->mpViewTransform);
     893       15195 :             mpOutDevData->mpInverseViewTransform->invert();
     894             :         }
     895             : 
     896       31861 :         return *mpOutDevData->mpInverseViewTransform;
     897             :     }
     898             :     else
     899             :     {
     900           0 :         return basegfx::B2DHomMatrix();
     901             :     }
     902             : }
     903             : 
     904             : // #i75163#
     905           0 : basegfx::B2DHomMatrix OutputDevice::GetViewTransformation( const MapMode& rMapMode ) const
     906             : {
     907             :     // #i82615#
     908             :     ImplMapRes          aMapRes;
     909             :     ImplThresholdRes    aThresRes;
     910           0 :     ImplCalcMapResolution( rMapMode, mnDPIX, mnDPIY, aMapRes, aThresRes );
     911             : 
     912           0 :     basegfx::B2DHomMatrix aTransform;
     913             : 
     914           0 :     const double fScaleFactorX((double)mnDPIX * (double)aMapRes.mnMapScNumX / (double)aMapRes.mnMapScDenomX);
     915           0 :     const double fScaleFactorY((double)mnDPIY * (double)aMapRes.mnMapScNumY / (double)aMapRes.mnMapScDenomY);
     916           0 :     const double fZeroPointX(((double)aMapRes.mnMapOfsX * fScaleFactorX) + (double)mnOutOffOrigX);
     917           0 :     const double fZeroPointY(((double)aMapRes.mnMapOfsY * fScaleFactorY) + (double)mnOutOffOrigY);
     918             : 
     919           0 :     aTransform.set(0, 0, fScaleFactorX);
     920           0 :     aTransform.set(1, 1, fScaleFactorY);
     921           0 :     aTransform.set(0, 2, fZeroPointX);
     922           0 :     aTransform.set(1, 2, fZeroPointY);
     923             : 
     924           0 :     return aTransform;
     925             : }
     926             : 
     927             : // #i75163#
     928           0 : basegfx::B2DHomMatrix OutputDevice::GetInverseViewTransformation( const MapMode& rMapMode ) const
     929             : {
     930           0 :     basegfx::B2DHomMatrix aMatrix( GetViewTransformation( rMapMode ) );
     931           0 :     aMatrix.invert();
     932           0 :     return aMatrix;
     933             : }
     934             : 
     935           0 : basegfx::B2DHomMatrix OutputDevice::ImplGetDeviceTransformation() const
     936             : {
     937           0 :     basegfx::B2DHomMatrix aTransformation = GetViewTransformation();
     938             :     // TODO: is it worth to cache the transformed result?
     939           0 :     if( mnOutOffX || mnOutOffY )
     940           0 :         aTransformation.translate( mnOutOffX, mnOutOffY );
     941           0 :     return aTransformation;
     942             : }
     943             : 
     944      239031 : Point OutputDevice::LogicToPixel( const Point& rLogicPt ) const
     945             : {
     946             : 
     947      239031 :     if ( !mbMap )
     948       93191 :         return rLogicPt;
     949             : 
     950      145840 :     return Point( ImplLogicToPixel( rLogicPt.X() + maMapRes.mnMapOfsX, mnDPIX,
     951             :                                     maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
     952      291680 :                                     maThresRes.mnThresLogToPixX )+mnOutOffOrigX,
     953      145840 :                   ImplLogicToPixel( rLogicPt.Y() + maMapRes.mnMapOfsY, mnDPIY,
     954             :                                     maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
     955      437520 :                                     maThresRes.mnThresLogToPixY )+mnOutOffOrigY );
     956             : }
     957             : 
     958      370213 : Size OutputDevice::LogicToPixel( const Size& rLogicSize ) const
     959             : {
     960             : 
     961      370213 :     if ( !mbMap )
     962      169708 :         return rLogicSize;
     963             : 
     964             :     return Size( ImplLogicToPixel( rLogicSize.Width(), mnDPIX,
     965             :                                    maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
     966             :                                    maThresRes.mnThresLogToPixX ),
     967             :                  ImplLogicToPixel( rLogicSize.Height(), mnDPIY,
     968             :                                    maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
     969      200505 :                                    maThresRes.mnThresLogToPixY ) );
     970             : }
     971             : 
     972      640655 : Rectangle OutputDevice::LogicToPixel( const Rectangle& rLogicRect ) const
     973             : {
     974             : 
     975      640655 :     if ( !mbMap || rLogicRect.IsEmpty() )
     976      290280 :         return rLogicRect;
     977             : 
     978      350375 :     return Rectangle( ImplLogicToPixel( rLogicRect.Left() + maMapRes.mnMapOfsX, mnDPIX,
     979             :                                         maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
     980      700750 :                                         maThresRes.mnThresLogToPixX )+mnOutOffOrigX,
     981      350375 :                       ImplLogicToPixel( rLogicRect.Top() + maMapRes.mnMapOfsY, mnDPIY,
     982             :                                         maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
     983      700750 :                                         maThresRes.mnThresLogToPixY )+mnOutOffOrigY,
     984      350375 :                       ImplLogicToPixel( rLogicRect.Right() + maMapRes.mnMapOfsX, mnDPIX,
     985             :                                         maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
     986      700750 :                                         maThresRes.mnThresLogToPixX )+mnOutOffOrigX,
     987      350375 :                       ImplLogicToPixel( rLogicRect.Bottom() + maMapRes.mnMapOfsY, mnDPIY,
     988             :                                         maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
     989     1751875 :                                         maThresRes.mnThresLogToPixY )+mnOutOffOrigY );
     990             : }
     991             : 
     992         458 : Polygon OutputDevice::LogicToPixel( const Polygon& rLogicPoly ) const
     993             : {
     994             : 
     995         458 :     if ( !mbMap )
     996           0 :         return rLogicPoly;
     997             : 
     998             :     sal_uInt16  i;
     999         458 :     sal_uInt16  nPoints = rLogicPoly.GetSize();
    1000         458 :     Polygon aPoly( rLogicPoly );
    1001             : 
    1002             :     // get pointer to Point-array (copy data)
    1003         458 :     const Point* pPointAry = aPoly.GetConstPointAry();
    1004             : 
    1005        7620 :     for ( i = 0; i < nPoints; i++ )
    1006             :     {
    1007        7162 :         const Point* pPt = &(pPointAry[i]);
    1008        7162 :         Point aPt;
    1009       14324 :         aPt.X() = ImplLogicToPixel( pPt->X() + maMapRes.mnMapOfsX, mnDPIX,
    1010             :                                     maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
    1011       14324 :                                     maThresRes.mnThresLogToPixX )+mnOutOffOrigX;
    1012       14324 :         aPt.Y() = ImplLogicToPixel( pPt->Y() + maMapRes.mnMapOfsY, mnDPIY,
    1013             :                                     maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
    1014       14324 :                                     maThresRes.mnThresLogToPixY )+mnOutOffOrigY;
    1015        7162 :         aPoly[i] = aPt;
    1016             :     }
    1017             : 
    1018         458 :     return aPoly;
    1019             : }
    1020             : 
    1021        4774 : PolyPolygon OutputDevice::LogicToPixel( const PolyPolygon& rLogicPolyPoly ) const
    1022             : {
    1023             : 
    1024        4774 :     if ( !mbMap )
    1025        4316 :         return rLogicPolyPoly;
    1026             : 
    1027         458 :     PolyPolygon aPolyPoly( rLogicPolyPoly );
    1028         458 :     sal_uInt16      nPoly = aPolyPoly.Count();
    1029         916 :     for( sal_uInt16 i = 0; i < nPoly; i++ )
    1030             :     {
    1031         458 :         Polygon& rPoly = aPolyPoly[i];
    1032         458 :         rPoly = LogicToPixel( rPoly );
    1033             :     }
    1034         458 :     return aPolyPoly;
    1035             : }
    1036             : 
    1037           0 : basegfx::B2DPolygon OutputDevice::LogicToPixel( const basegfx::B2DPolygon& rLogicPoly ) const
    1038             : {
    1039           0 :     basegfx::B2DPolygon aTransformedPoly = rLogicPoly;
    1040           0 :     const ::basegfx::B2DHomMatrix& rTransformationMatrix = GetViewTransformation();
    1041           0 :     aTransformedPoly.transform( rTransformationMatrix );
    1042           0 :     return aTransformedPoly;
    1043             : }
    1044             : 
    1045          20 : basegfx::B2DPolyPolygon OutputDevice::LogicToPixel( const basegfx::B2DPolyPolygon& rLogicPolyPoly ) const
    1046             : {
    1047          20 :     basegfx::B2DPolyPolygon aTransformedPoly = rLogicPolyPoly;
    1048          40 :     const ::basegfx::B2DHomMatrix& rTransformationMatrix = GetViewTransformation();
    1049          20 :     aTransformedPoly.transform( rTransformationMatrix );
    1050          40 :     return aTransformedPoly;
    1051             : }
    1052             : 
    1053      179452 : Region OutputDevice::LogicToPixel( const Region& rLogicRegion ) const
    1054             : {
    1055             : 
    1056      179452 :     if(!mbMap || rLogicRegion.IsNull() || rLogicRegion.IsEmpty())
    1057             :     {
    1058      126638 :         return rLogicRegion;
    1059             :     }
    1060             : 
    1061       52814 :     Region aRegion;
    1062             : 
    1063       52814 :     if(rLogicRegion.getB2DPolyPolygon())
    1064             :     {
    1065          20 :         aRegion = Region(LogicToPixel(*rLogicRegion.getB2DPolyPolygon()));
    1066             :     }
    1067       52794 :     else if(rLogicRegion.getPolyPolygon())
    1068             :     {
    1069           0 :         aRegion = Region(LogicToPixel(*rLogicRegion.getPolyPolygon()));
    1070             :     }
    1071       52794 :     else if(rLogicRegion.getRegionBand())
    1072             :     {
    1073       52794 :         RectangleVector aRectangles;
    1074       52794 :         rLogicRegion.GetRegionRectangles(aRectangles);
    1075       52794 :         const RectangleVector& rRectangles(aRectangles); // needed to make the '!=' work
    1076             : 
    1077             :         // make reverse run to fill new region bottom-up, this will speed it up due to the used data structuring
    1078      108742 :         for(RectangleVector::const_reverse_iterator aRectIter(rRectangles.rbegin()); aRectIter != rRectangles.rend(); ++aRectIter)
    1079             :         {
    1080       55948 :             aRegion.Union(LogicToPixel(*aRectIter));
    1081       52794 :         }
    1082             :     }
    1083             : 
    1084       52814 :     return aRegion;
    1085             : }
    1086             : 
    1087        6091 : Point OutputDevice::LogicToPixel( const Point& rLogicPt,
    1088             :                                   const MapMode& rMapMode ) const
    1089             : {
    1090             : 
    1091        6091 :     if ( rMapMode.IsDefault() )
    1092          24 :         return rLogicPt;
    1093             : 
    1094             :     // convert MapMode resolution and convert
    1095             :     ImplMapRes          aMapRes;
    1096             :     ImplThresholdRes    aThresRes;
    1097        6067 :     ImplCalcMapResolution( rMapMode, mnDPIX, mnDPIY, aMapRes, aThresRes );
    1098             : 
    1099        6067 :     return Point( ImplLogicToPixel( rLogicPt.X() + aMapRes.mnMapOfsX, mnDPIX,
    1100             :                                     aMapRes.mnMapScNumX, aMapRes.mnMapScDenomX,
    1101       12134 :                                     aThresRes.mnThresLogToPixX )+mnOutOffOrigX,
    1102        6067 :                   ImplLogicToPixel( rLogicPt.Y() + aMapRes.mnMapOfsY, mnDPIY,
    1103             :                                     aMapRes.mnMapScNumY, aMapRes.mnMapScDenomY,
    1104       18201 :                                     aThresRes.mnThresLogToPixY )+mnOutOffOrigY );
    1105             : }
    1106             : 
    1107      925220 : Size OutputDevice::LogicToPixel( const Size& rLogicSize,
    1108             :                                  const MapMode& rMapMode ) const
    1109             : {
    1110             : 
    1111      925220 :     if ( rMapMode.IsDefault() )
    1112           0 :         return rLogicSize;
    1113             : 
    1114             :     // convert MapMode resolution and convert
    1115             :     ImplMapRes          aMapRes;
    1116             :     ImplThresholdRes    aThresRes;
    1117      925220 :     ImplCalcMapResolution( rMapMode, mnDPIX, mnDPIY, aMapRes, aThresRes );
    1118             : 
    1119             :     return Size( ImplLogicToPixel( rLogicSize.Width(), mnDPIX,
    1120             :                                    aMapRes.mnMapScNumX, aMapRes.mnMapScDenomX,
    1121             :                                    aThresRes.mnThresLogToPixX ),
    1122             :                  ImplLogicToPixel( rLogicSize.Height(), mnDPIY,
    1123             :                                    aMapRes.mnMapScNumY, aMapRes.mnMapScDenomY,
    1124      925220 :                                    aThresRes.mnThresLogToPixY ) );
    1125             : }
    1126             : 
    1127        3153 : Rectangle OutputDevice::LogicToPixel( const Rectangle& rLogicRect,
    1128             :                                       const MapMode& rMapMode ) const
    1129             : {
    1130             : 
    1131        3153 :     if ( rMapMode.IsDefault() || rLogicRect.IsEmpty() )
    1132          10 :         return rLogicRect;
    1133             : 
    1134             :     // convert MapMode resolution and convert
    1135             :     ImplMapRes          aMapRes;
    1136             :     ImplThresholdRes    aThresRes;
    1137        3143 :     ImplCalcMapResolution( rMapMode, mnDPIX, mnDPIY, aMapRes, aThresRes );
    1138             : 
    1139        3143 :     return Rectangle( ImplLogicToPixel( rLogicRect.Left() + aMapRes.mnMapOfsX, mnDPIX,
    1140             :                                         aMapRes.mnMapScNumX, aMapRes.mnMapScDenomX,
    1141        6286 :                                         aThresRes.mnThresLogToPixX )+mnOutOffOrigX,
    1142        3143 :                       ImplLogicToPixel( rLogicRect.Top() + aMapRes.mnMapOfsY, mnDPIY,
    1143             :                                         aMapRes.mnMapScNumY, aMapRes.mnMapScDenomY,
    1144        6286 :                                         aThresRes.mnThresLogToPixY )+mnOutOffOrigY,
    1145        3143 :                       ImplLogicToPixel( rLogicRect.Right() + aMapRes.mnMapOfsX, mnDPIX,
    1146             :                                         aMapRes.mnMapScNumX, aMapRes.mnMapScDenomX,
    1147        6286 :                                         aThresRes.mnThresLogToPixX )+mnOutOffOrigX,
    1148        3143 :                       ImplLogicToPixel( rLogicRect.Bottom() + aMapRes.mnMapOfsY, mnDPIY,
    1149             :                                         aMapRes.mnMapScNumY, aMapRes.mnMapScDenomY,
    1150       15715 :                                         aThresRes.mnThresLogToPixY )+mnOutOffOrigY );
    1151             : }
    1152             : 
    1153           0 : Polygon OutputDevice::LogicToPixel( const Polygon& rLogicPoly,
    1154             :                                     const MapMode& rMapMode ) const
    1155             : {
    1156             : 
    1157           0 :     if ( rMapMode.IsDefault() )
    1158           0 :         return rLogicPoly;
    1159             : 
    1160             :     // convert MapMode resolution and convert
    1161             :     ImplMapRes          aMapRes;
    1162             :     ImplThresholdRes    aThresRes;
    1163           0 :     ImplCalcMapResolution( rMapMode, mnDPIX, mnDPIY, aMapRes, aThresRes );
    1164             : 
    1165             :     sal_uInt16  i;
    1166           0 :     sal_uInt16  nPoints = rLogicPoly.GetSize();
    1167           0 :     Polygon aPoly( rLogicPoly );
    1168             : 
    1169             :     // get pointer to Point-array (copy data)
    1170           0 :     const Point* pPointAry = aPoly.GetConstPointAry();
    1171             : 
    1172           0 :     for ( i = 0; i < nPoints; i++ )
    1173             :     {
    1174           0 :         const Point* pPt = &(pPointAry[i]);
    1175           0 :         Point aPt;
    1176           0 :         aPt.X() = ImplLogicToPixel( pPt->X() + aMapRes.mnMapOfsX, mnDPIX,
    1177             :                                     aMapRes.mnMapScNumX, aMapRes.mnMapScDenomX,
    1178           0 :                                     aThresRes.mnThresLogToPixX )+mnOutOffOrigX;
    1179           0 :         aPt.Y() = ImplLogicToPixel( pPt->Y() + aMapRes.mnMapOfsY, mnDPIY,
    1180             :                                     aMapRes.mnMapScNumY, aMapRes.mnMapScDenomY,
    1181           0 :                                     aThresRes.mnThresLogToPixY )+mnOutOffOrigY;
    1182           0 :         aPoly[i] = aPt;
    1183             :     }
    1184             : 
    1185           0 :     return aPoly;
    1186             : }
    1187             : 
    1188           0 : PolyPolygon OutputDevice::LogicToPixel( const PolyPolygon& rLogicPolyPoly,
    1189             :     const MapMode& rMapMode ) const
    1190             : {
    1191             : 
    1192           0 :     if ( rMapMode.IsDefault() )
    1193           0 :         return rLogicPolyPoly;
    1194             : 
    1195           0 :     PolyPolygon aPolyPoly( rLogicPolyPoly );
    1196           0 :     sal_uInt16              nPoly = aPolyPoly.Count();
    1197           0 :     for( sal_uInt16 i = 0; i < nPoly; i++ )
    1198             :     {
    1199           0 :         Polygon& rPoly = aPolyPoly[i];
    1200           0 :         rPoly = LogicToPixel( rPoly, rMapMode );
    1201             :     }
    1202           0 :     return aPolyPoly;
    1203             : }
    1204             : 
    1205           0 : basegfx::B2DPolyPolygon OutputDevice::LogicToPixel( const basegfx::B2DPolyPolygon& rLogicPolyPoly,
    1206             :                                                     const MapMode& rMapMode ) const
    1207             : {
    1208           0 :     basegfx::B2DPolyPolygon aTransformedPoly = rLogicPolyPoly;
    1209           0 :     const ::basegfx::B2DHomMatrix& rTransformationMatrix = GetViewTransformation( rMapMode );
    1210           0 :     aTransformedPoly.transform( rTransformationMatrix );
    1211           0 :     return aTransformedPoly;
    1212             : }
    1213             : 
    1214           0 : basegfx::B2DPolygon OutputDevice::LogicToPixel( const basegfx::B2DPolygon& rLogicPoly,
    1215             :                                                 const MapMode& rMapMode ) const
    1216             : {
    1217           0 :     basegfx::B2DPolygon aTransformedPoly = rLogicPoly;
    1218           0 :     const ::basegfx::B2DHomMatrix& rTransformationMatrix = GetViewTransformation( rMapMode );
    1219           0 :     aTransformedPoly.transform( rTransformationMatrix );
    1220           0 :     return aTransformedPoly;
    1221             : }
    1222             : 
    1223           0 : Region OutputDevice::LogicToPixel( const Region& rLogicRegion, const MapMode& rMapMode ) const
    1224             : {
    1225             : 
    1226           0 :     if(rMapMode.IsDefault() || rLogicRegion.IsNull() || rLogicRegion.IsEmpty())
    1227             :     {
    1228           0 :         return rLogicRegion;
    1229             :     }
    1230             : 
    1231           0 :     Region aRegion;
    1232             : 
    1233           0 :     if(rLogicRegion.getB2DPolyPolygon())
    1234             :     {
    1235           0 :         aRegion = Region(LogicToPixel(*rLogicRegion.getB2DPolyPolygon(), rMapMode));
    1236             :     }
    1237           0 :     else if(rLogicRegion.getPolyPolygon())
    1238             :     {
    1239           0 :         aRegion = Region(LogicToPixel(*rLogicRegion.getPolyPolygon(), rMapMode));
    1240             :     }
    1241           0 :     else if(rLogicRegion.getRegionBand())
    1242             :     {
    1243           0 :         RectangleVector aRectangles;
    1244           0 :         rLogicRegion.GetRegionRectangles(aRectangles);
    1245           0 :         const RectangleVector& rRectangles(aRectangles); // needed to make the '!=' work
    1246             : 
    1247             :         // make reverse run to fill new region bottom-up, this will speed it up due to the used data structuring
    1248           0 :         for(RectangleVector::const_reverse_iterator aRectIter(rRectangles.rbegin()); aRectIter != rRectangles.rend(); ++aRectIter)
    1249             :         {
    1250           0 :             aRegion.Union(LogicToPixel(*aRectIter, rMapMode));
    1251           0 :         }
    1252             :     }
    1253             : 
    1254           0 :     return aRegion;
    1255             : }
    1256             : 
    1257      296826 : Point OutputDevice::PixelToLogic( const Point& rDevicePt ) const
    1258             : {
    1259             : 
    1260      296826 :     if ( !mbMap )
    1261      158566 :         return rDevicePt;
    1262             : 
    1263             :     return Point( ImplPixelToLogic( rDevicePt.X(), mnDPIX,
    1264             :                                     maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
    1265      138260 :                                     maThresRes.mnThresPixToLogX ) - maMapRes.mnMapOfsX - mnOutOffLogicX,
    1266             :                   ImplPixelToLogic( rDevicePt.Y(), mnDPIY,
    1267             :                                     maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
    1268      276520 :                                     maThresRes.mnThresPixToLogY ) - maMapRes.mnMapOfsY - mnOutOffLogicY );
    1269             : }
    1270             : 
    1271     1109649 : Size OutputDevice::PixelToLogic( const Size& rDeviceSize ) const
    1272             : {
    1273             : 
    1274     1109649 :     if ( !mbMap )
    1275      413036 :         return rDeviceSize;
    1276             : 
    1277             :     return Size( ImplPixelToLogic( rDeviceSize.Width(), mnDPIX,
    1278             :                                    maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
    1279             :                                    maThresRes.mnThresPixToLogX ),
    1280             :                  ImplPixelToLogic( rDeviceSize.Height(), mnDPIY,
    1281             :                                    maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
    1282      696613 :                                    maThresRes.mnThresPixToLogY ) );
    1283             : }
    1284             : 
    1285      537652 : Rectangle OutputDevice::PixelToLogic( const Rectangle& rDeviceRect ) const
    1286             : {
    1287             : 
    1288      537652 :     if ( !mbMap || rDeviceRect.IsEmpty() )
    1289      128856 :         return rDeviceRect;
    1290             : 
    1291             :     return Rectangle( ImplPixelToLogic( rDeviceRect.Left(), mnDPIX,
    1292             :                                         maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
    1293      408796 :                                         maThresRes.mnThresPixToLogX ) - maMapRes.mnMapOfsX - mnOutOffLogicX,
    1294             :                       ImplPixelToLogic( rDeviceRect.Top(), mnDPIY,
    1295             :                                         maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
    1296      408796 :                                         maThresRes.mnThresPixToLogY ) - maMapRes.mnMapOfsY - mnOutOffLogicY,
    1297             :                       ImplPixelToLogic( rDeviceRect.Right(), mnDPIX,
    1298             :                                         maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
    1299      408796 :                                         maThresRes.mnThresPixToLogX ) - maMapRes.mnMapOfsX - mnOutOffLogicX,
    1300             :                       ImplPixelToLogic( rDeviceRect.Bottom(), mnDPIY,
    1301             :                                         maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
    1302     1635184 :                                         maThresRes.mnThresPixToLogY ) - maMapRes.mnMapOfsY - mnOutOffLogicY );
    1303             : }
    1304             : 
    1305           0 : Polygon OutputDevice::PixelToLogic( const Polygon& rDevicePoly ) const
    1306             : {
    1307             : 
    1308           0 :     if ( !mbMap )
    1309           0 :         return rDevicePoly;
    1310             : 
    1311             :     sal_uInt16  i;
    1312           0 :     sal_uInt16  nPoints = rDevicePoly.GetSize();
    1313           0 :     Polygon aPoly( rDevicePoly );
    1314             : 
    1315             :     // get pointer to Point-array (copy data)
    1316           0 :     const Point* pPointAry = aPoly.GetConstPointAry();
    1317             : 
    1318           0 :     for ( i = 0; i < nPoints; i++ )
    1319             :     {
    1320           0 :         const Point* pPt = &(pPointAry[i]);
    1321           0 :         Point aPt;
    1322           0 :         aPt.X() = ImplPixelToLogic( pPt->X(), mnDPIX,
    1323             :                                     maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
    1324           0 :                                     maThresRes.mnThresPixToLogX ) - maMapRes.mnMapOfsX - mnOutOffLogicX;
    1325           0 :         aPt.Y() = ImplPixelToLogic( pPt->Y(), mnDPIY,
    1326             :                                     maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
    1327           0 :                                     maThresRes.mnThresPixToLogY ) - maMapRes.mnMapOfsY - mnOutOffLogicY;
    1328           0 :         aPoly[i] = aPt;
    1329             :     }
    1330             : 
    1331           0 :     return aPoly;
    1332             : }
    1333             : 
    1334           0 : PolyPolygon OutputDevice::PixelToLogic( const PolyPolygon& rDevicePolyPoly ) const
    1335             : {
    1336             : 
    1337           0 :     if ( !mbMap )
    1338           0 :         return rDevicePolyPoly;
    1339             : 
    1340           0 :     PolyPolygon aPolyPoly( rDevicePolyPoly );
    1341           0 :     sal_uInt16      nPoly = aPolyPoly.Count();
    1342           0 :     for( sal_uInt16 i = 0; i < nPoly; i++ )
    1343             :     {
    1344           0 :         Polygon& rPoly = aPolyPoly[i];
    1345           0 :         rPoly = PixelToLogic( rPoly );
    1346             :     }
    1347           0 :     return aPolyPoly;
    1348             : }
    1349             : 
    1350           0 : basegfx::B2DPolyPolygon OutputDevice::PixelToLogic( const basegfx::B2DPolyPolygon& rPixelPolyPoly ) const
    1351             : {
    1352           0 :     basegfx::B2DPolyPolygon aTransformedPoly = rPixelPolyPoly;
    1353           0 :     const ::basegfx::B2DHomMatrix& rTransformationMatrix = GetInverseViewTransformation();
    1354           0 :     aTransformedPoly.transform( rTransformationMatrix );
    1355           0 :     return aTransformedPoly;
    1356             : }
    1357             : 
    1358      207362 : Region OutputDevice::PixelToLogic( const Region& rDeviceRegion ) const
    1359             : {
    1360             : 
    1361      207362 :     if(!mbMap || rDeviceRegion.IsNull() || rDeviceRegion.IsEmpty())
    1362             :     {
    1363      171764 :         return rDeviceRegion;
    1364             :     }
    1365             : 
    1366       35598 :     Region aRegion;
    1367             : 
    1368       35598 :     if(rDeviceRegion.getB2DPolyPolygon())
    1369             :     {
    1370           0 :         aRegion = Region(PixelToLogic(*rDeviceRegion.getB2DPolyPolygon()));
    1371             :     }
    1372       35598 :     else if(rDeviceRegion.getPolyPolygon())
    1373             :     {
    1374           0 :         aRegion = Region(PixelToLogic(*rDeviceRegion.getPolyPolygon()));
    1375             :     }
    1376       35598 :     else if(rDeviceRegion.getRegionBand())
    1377             :     {
    1378       35598 :         RectangleVector aRectangles;
    1379       35598 :         rDeviceRegion.GetRegionRectangles(aRectangles);
    1380       35598 :         const RectangleVector& rRectangles(aRectangles); // needed to make the '!=' work
    1381             : 
    1382             :         // make reverse run to fill new region bottom-up, this will speed it up due to the used data structuring
    1383       73196 :         for(RectangleVector::const_reverse_iterator aRectIter(rRectangles.rbegin()); aRectIter != rRectangles.rend(); ++aRectIter)
    1384             :         {
    1385       37598 :             aRegion.Union(PixelToLogic(*aRectIter));
    1386       35598 :         }
    1387             :     }
    1388             : 
    1389       35598 :     return aRegion;
    1390             : }
    1391             : 
    1392       17711 : Point OutputDevice::PixelToLogic( const Point& rDevicePt,
    1393             :                                   const MapMode& rMapMode ) const
    1394             : {
    1395             : 
    1396             :     // calculate nothing if default-MapMode
    1397       17711 :     if ( rMapMode.IsDefault() )
    1398           2 :         return rDevicePt;
    1399             : 
    1400             :     // calculate MapMode-resolution and convert
    1401             :     ImplMapRes          aMapRes;
    1402             :     ImplThresholdRes    aThresRes;
    1403       17709 :     ImplCalcMapResolution( rMapMode, mnDPIX, mnDPIY, aMapRes, aThresRes );
    1404             : 
    1405             :     return Point( ImplPixelToLogic( rDevicePt.X(), mnDPIX,
    1406             :                                     aMapRes.mnMapScNumX, aMapRes.mnMapScDenomX,
    1407       17709 :                                     aThresRes.mnThresPixToLogX ) - aMapRes.mnMapOfsX - mnOutOffLogicX,
    1408             :                   ImplPixelToLogic( rDevicePt.Y(), mnDPIY,
    1409             :                                     aMapRes.mnMapScNumY, aMapRes.mnMapScDenomY,
    1410       35418 :                                     aThresRes.mnThresPixToLogY ) - aMapRes.mnMapOfsY - mnOutOffLogicY );
    1411             : }
    1412             : 
    1413       11833 : Size OutputDevice::PixelToLogic( const Size& rDeviceSize,
    1414             :                                  const MapMode& rMapMode ) const
    1415             : {
    1416             : 
    1417             :     // calculate nothing if default-MapMode
    1418       11833 :     if ( rMapMode.IsDefault() )
    1419           1 :         return rDeviceSize;
    1420             : 
    1421             :     // calculate MapMode-resolution and convert
    1422             :     ImplMapRes          aMapRes;
    1423             :     ImplThresholdRes    aThresRes;
    1424       11832 :     ImplCalcMapResolution( rMapMode, mnDPIX, mnDPIY, aMapRes, aThresRes );
    1425             : 
    1426             :     return Size( ImplPixelToLogic( rDeviceSize.Width(), mnDPIX,
    1427             :                                    aMapRes.mnMapScNumX, aMapRes.mnMapScDenomX,
    1428             :                                    aThresRes.mnThresPixToLogX ),
    1429             :                  ImplPixelToLogic( rDeviceSize.Height(), mnDPIY,
    1430             :                                    aMapRes.mnMapScNumY, aMapRes.mnMapScDenomY,
    1431       11832 :                                    aThresRes.mnThresPixToLogY ) );
    1432             : }
    1433             : 
    1434        4726 : Rectangle OutputDevice::PixelToLogic( const Rectangle& rDeviceRect,
    1435             :                                       const MapMode& rMapMode ) const
    1436             : {
    1437             : 
    1438             :     // calculate nothing if default-MapMode
    1439        4726 :     if ( rMapMode.IsDefault() || rDeviceRect.IsEmpty() )
    1440           0 :         return rDeviceRect;
    1441             : 
    1442             :     // calculate MapMode-resolution and convert
    1443             :     ImplMapRes          aMapRes;
    1444             :     ImplThresholdRes    aThresRes;
    1445        4726 :     ImplCalcMapResolution( rMapMode, mnDPIX, mnDPIY, aMapRes, aThresRes );
    1446             : 
    1447             :     return Rectangle( ImplPixelToLogic( rDeviceRect.Left(), mnDPIX,
    1448             :                                         aMapRes.mnMapScNumX, aMapRes.mnMapScDenomX,
    1449        4726 :                                         aThresRes.mnThresPixToLogX ) - aMapRes.mnMapOfsX - mnOutOffLogicX,
    1450             :                       ImplPixelToLogic( rDeviceRect.Top(), mnDPIY,
    1451             :                                         aMapRes.mnMapScNumY, aMapRes.mnMapScDenomY,
    1452        4726 :                                         aThresRes.mnThresPixToLogY ) - aMapRes.mnMapOfsY - mnOutOffLogicY,
    1453             :                       ImplPixelToLogic( rDeviceRect.Right(), mnDPIX,
    1454             :                                         aMapRes.mnMapScNumX, aMapRes.mnMapScDenomX,
    1455        4726 :                                         aThresRes.mnThresPixToLogX ) - aMapRes.mnMapOfsX - mnOutOffLogicX,
    1456             :                       ImplPixelToLogic( rDeviceRect.Bottom(), mnDPIY,
    1457             :                                         aMapRes.mnMapScNumY, aMapRes.mnMapScDenomY,
    1458       18904 :                                         aThresRes.mnThresPixToLogY ) - aMapRes.mnMapOfsY - mnOutOffLogicY );
    1459             : }
    1460             : 
    1461           0 : Polygon OutputDevice::PixelToLogic( const Polygon& rDevicePoly,
    1462             :                                     const MapMode& rMapMode ) const
    1463             : {
    1464             : 
    1465             :     // calculate nothing if default-MapMode
    1466           0 :     if ( rMapMode.IsDefault() )
    1467           0 :         return rDevicePoly;
    1468             : 
    1469             :     // calculate MapMode-resolution and convert
    1470             :     ImplMapRes          aMapRes;
    1471             :     ImplThresholdRes    aThresRes;
    1472           0 :     ImplCalcMapResolution( rMapMode, mnDPIX, mnDPIY, aMapRes, aThresRes );
    1473             : 
    1474             :     sal_uInt16  i;
    1475           0 :     sal_uInt16  nPoints = rDevicePoly.GetSize();
    1476           0 :     Polygon aPoly( rDevicePoly );
    1477             : 
    1478             :     // get pointer to Point-array (copy data)
    1479           0 :     const Point* pPointAry = aPoly.GetConstPointAry();
    1480             : 
    1481           0 :     for ( i = 0; i < nPoints; i++ )
    1482             :     {
    1483           0 :         const Point* pPt = &(pPointAry[i]);
    1484           0 :         Point aPt;
    1485           0 :         aPt.X() = ImplPixelToLogic( pPt->X(), mnDPIX,
    1486             :                                     aMapRes.mnMapScNumX, aMapRes.mnMapScDenomX,
    1487           0 :                                     aThresRes.mnThresPixToLogX ) - aMapRes.mnMapOfsX - mnOutOffLogicX;
    1488           0 :         aPt.Y() = ImplPixelToLogic( pPt->Y(), mnDPIY,
    1489             :                                     aMapRes.mnMapScNumY, aMapRes.mnMapScDenomY,
    1490           0 :                                     aThresRes.mnThresPixToLogY ) - aMapRes.mnMapOfsY - mnOutOffLogicY;
    1491           0 :         aPoly[i] = aPt;
    1492             :     }
    1493             : 
    1494           0 :     return aPoly;
    1495             : }
    1496             : 
    1497           0 : PolyPolygon OutputDevice::PixelToLogic( const PolyPolygon& rDevicePolyPoly,
    1498             :     const MapMode& rMapMode ) const
    1499             : {
    1500             : 
    1501           0 :     if ( rMapMode.IsDefault() )
    1502           0 :         return rDevicePolyPoly;
    1503             : 
    1504           0 :     PolyPolygon aPolyPoly( rDevicePolyPoly );
    1505           0 :     sal_uInt16      nPoly = aPolyPoly.Count();
    1506           0 :     for( sal_uInt16 i = 0; i < nPoly; i++ )
    1507             :     {
    1508           0 :         Polygon& rPoly = aPolyPoly[i];
    1509           0 :         rPoly = PixelToLogic( rPoly, rMapMode );
    1510             :     }
    1511           0 :     return aPolyPoly;
    1512             : }
    1513             : 
    1514           0 : basegfx::B2DPolygon OutputDevice::PixelToLogic( const basegfx::B2DPolygon& rPixelPoly,
    1515             :                                                 const MapMode& rMapMode ) const
    1516             : {
    1517           0 :     basegfx::B2DPolygon aTransformedPoly = rPixelPoly;
    1518           0 :     const ::basegfx::B2DHomMatrix& rTransformationMatrix = GetInverseViewTransformation( rMapMode );
    1519           0 :     aTransformedPoly.transform( rTransformationMatrix );
    1520           0 :     return aTransformedPoly;
    1521             : }
    1522             : 
    1523           0 : basegfx::B2DPolyPolygon OutputDevice::PixelToLogic( const basegfx::B2DPolyPolygon& rPixelPolyPoly,
    1524             :                                                     const MapMode& rMapMode ) const
    1525             : {
    1526           0 :     basegfx::B2DPolyPolygon aTransformedPoly = rPixelPolyPoly;
    1527           0 :     const ::basegfx::B2DHomMatrix& rTransformationMatrix = GetInverseViewTransformation( rMapMode );
    1528           0 :     aTransformedPoly.transform( rTransformationMatrix );
    1529           0 :     return aTransformedPoly;
    1530             : }
    1531             : 
    1532           0 : Region OutputDevice::PixelToLogic( const Region& rDeviceRegion, const MapMode& rMapMode ) const
    1533             : {
    1534             : 
    1535           0 :     if(rMapMode.IsDefault() || rDeviceRegion.IsNull() || rDeviceRegion.IsEmpty())
    1536             :     {
    1537           0 :         return rDeviceRegion;
    1538             :     }
    1539             : 
    1540           0 :     Region aRegion;
    1541             : 
    1542           0 :     if(rDeviceRegion.getB2DPolyPolygon())
    1543             :     {
    1544           0 :         aRegion = Region(PixelToLogic(*rDeviceRegion.getB2DPolyPolygon(), rMapMode));
    1545             :     }
    1546           0 :     else if(rDeviceRegion.getPolyPolygon())
    1547             :     {
    1548           0 :         aRegion = Region(PixelToLogic(*rDeviceRegion.getPolyPolygon(), rMapMode));
    1549             :     }
    1550           0 :     else if(rDeviceRegion.getRegionBand())
    1551             :     {
    1552           0 :         RectangleVector aRectangles;
    1553           0 :         rDeviceRegion.GetRegionRectangles(aRectangles);
    1554           0 :         const RectangleVector& rRectangles(aRectangles); // needed to make the '!=' work
    1555             : 
    1556             :         // make reverse run to fill new region bottom-up, this will speed it up due to the used data structuring
    1557           0 :         for(RectangleVector::const_reverse_iterator aRectIter(rRectangles.rbegin()); aRectIter != rRectangles.rend(); ++aRectIter)
    1558             :         {
    1559           0 :             aRegion.Union(PixelToLogic(*aRectIter, rMapMode));
    1560           0 :         }
    1561             :     }
    1562             : 
    1563           0 :     return aRegion;
    1564             : }
    1565             : 
    1566             : #define ENTER0( rSource, pMapModeSource, pMapModeDest )                 \
    1567             :     if ( !pMapModeSource )                                              \
    1568             :         pMapModeSource = &maMapMode;                                    \
    1569             :     if ( !pMapModeDest )                                                \
    1570             :         pMapModeDest = &maMapMode;                                      \
    1571             :     if ( *pMapModeSource == *pMapModeDest )                             \
    1572             :         return rSource
    1573             : 
    1574             : #define ENTER1( rSource, pMapModeSource, pMapModeDest )                 \
    1575             :     ENTER0( rSource, pMapModeSource, pMapModeDest );                    \
    1576             :                                                                         \
    1577             :     ImplMapRes aMapResSource;                                           \
    1578             :     aMapResSource.mnMapOfsX          = 0;                               \
    1579             :     aMapResSource.mnMapOfsY          = 0;                               \
    1580             :     aMapResSource.mnMapScNumX        = 1;                               \
    1581             :     aMapResSource.mnMapScNumY        = 1;                               \
    1582             :     aMapResSource.mnMapScDenomX      = 1;                               \
    1583             :     aMapResSource.mnMapScDenomY      = 1;                               \
    1584             :     ImplMapRes aMapResDest(aMapResSource);                              \
    1585             :                                                                         \
    1586             :     if ( !mbMap || pMapModeSource != &maMapMode )                       \
    1587             :     {                                                                   \
    1588             :         if ( pMapModeSource->GetMapUnit() == MAP_RELATIVE )             \
    1589             :             aMapResSource = maMapRes;                                   \
    1590             :         ImplCalcMapResolution( *pMapModeSource,                         \
    1591             :                                mnDPIX, mnDPIY, aMapResSource );         \
    1592             :     }                                                                   \
    1593             :     else                                                                \
    1594             :         aMapResSource = maMapRes;                                       \
    1595             :     if ( !mbMap || pMapModeDest != &maMapMode )                         \
    1596             :     {                                                                   \
    1597             :         if ( pMapModeDest->GetMapUnit() == MAP_RELATIVE )               \
    1598             :             aMapResDest = maMapRes;                                     \
    1599             :         ImplCalcMapResolution( *pMapModeDest,                           \
    1600             :                                mnDPIX, mnDPIY, aMapResDest );           \
    1601             :     }                                                                   \
    1602             :     else                                                                \
    1603             :         aMapResDest = maMapRes
    1604             : 
    1605             : #define ENTER2( eUnitSource, eUnitDest )                                \
    1606             :     DBG_ASSERT( eUnitSource != MAP_SYSFONT                              \
    1607             :                 && eUnitSource != MAP_APPFONT                           \
    1608             :                 && eUnitSource != MAP_RELATIVE,                         \
    1609             :                 "Source MapUnit nicht erlaubt" );                       \
    1610             :     DBG_ASSERT( eUnitDest != MAP_SYSFONT                                \
    1611             :                 && eUnitDest != MAP_APPFONT                             \
    1612             :                 && eUnitDest != MAP_RELATIVE,                           \
    1613             :                 "Destination MapUnit nicht erlaubt" );                  \
    1614             :     DBG_ASSERTWARNING( eUnitSource != MAP_PIXEL,                        \
    1615             :                        "MAP_PIXEL mit 72dpi angenaehert" );             \
    1616             :     DBG_ASSERTWARNING( eUnitDest != MAP_PIXEL,                          \
    1617             :                        "MAP_PIXEL mit 72dpi angenaehert" )
    1618             : 
    1619             : #define ENTER3( eUnitSource, eUnitDest )                                \
    1620             :     long nNumerator      = 1;       \
    1621             :     long nDenominator    = 1;       \
    1622             :     DBG_ASSERT( eUnitSource < s_ImplArySize, "Invalid source map unit");    \
    1623             :     DBG_ASSERT( eUnitDest < s_ImplArySize, "Invalid destination map unit"); \
    1624             :     if( (eUnitSource < s_ImplArySize) && (eUnitDest < s_ImplArySize) )  \
    1625             :     {   \
    1626             :         nNumerator   = aImplNumeratorAry[eUnitSource] *             \
    1627             :                            aImplDenominatorAry[eUnitDest];              \
    1628             :         nDenominator     = aImplNumeratorAry[eUnitDest] *               \
    1629             :                            aImplDenominatorAry[eUnitSource];            \
    1630             :     } \
    1631             :     if ( eUnitSource == MAP_PIXEL )                                     \
    1632             :         nDenominator *= 72;                                             \
    1633             :     else if( eUnitDest == MAP_PIXEL )                                   \
    1634             :         nNumerator *= 72
    1635             : 
    1636             : #define ENTER4( rMapModeSource, rMapModeDest )                          \
    1637             :     ImplMapRes aMapResSource;                                           \
    1638             :     aMapResSource.mnMapOfsX          = 0;                               \
    1639             :     aMapResSource.mnMapOfsY          = 0;                               \
    1640             :     aMapResSource.mnMapScNumX        = 1;                               \
    1641             :     aMapResSource.mnMapScNumY        = 1;                               \
    1642             :     aMapResSource.mnMapScDenomX      = 1;                               \
    1643             :     aMapResSource.mnMapScDenomY      = 1;                               \
    1644             :     ImplMapRes aMapResDest(aMapResSource);                              \
    1645             :                                                                         \
    1646             :     ImplCalcMapResolution( rMapModeSource, 72, 72, aMapResSource );     \
    1647             :     ImplCalcMapResolution( rMapModeDest, 72, 72, aMapResDest )
    1648             : 
    1649             : // return (n1 * n2 * n3) / (n4 * n5)
    1650        4962 : static long fn5( const long n1,
    1651             :                  const long n2,
    1652             :                  const long n3,
    1653             :                  const long n4,
    1654             :                  const long n5 )
    1655             : {
    1656        4962 :     if ( n1 == 0 || n2 == 0 || n3 == 0 || n4 == 0 || n5 == 0 )
    1657         960 :         return 0;
    1658        4002 :     if ( LONG_MAX / std::abs(n2) < std::abs(n3) )
    1659             :     {
    1660             :         // a6 is skipped
    1661          54 :         BigInt a7 = n2;
    1662          54 :         a7 *= n3;
    1663          54 :         a7 *= n1;
    1664             : 
    1665          54 :         if ( LONG_MAX / std::abs(n4) < std::abs(n5) )
    1666             :         {
    1667          54 :             BigInt a8 = n4;
    1668          54 :             a8 *= n5;
    1669             : 
    1670          54 :             BigInt a9 = a8;
    1671          54 :             a9 /= 2;
    1672          54 :             if ( a7.IsNeg() )
    1673           0 :                 a7 -= a9;
    1674             :             else
    1675          54 :                 a7 += a9;
    1676             : 
    1677          54 :             a7 /= a8;
    1678             :         } // of if
    1679             :         else
    1680             :         {
    1681           0 :             long n8 = n4 * n5;
    1682             : 
    1683           0 :             if ( a7.IsNeg() )
    1684           0 :                 a7 -= n8 / 2;
    1685             :             else
    1686           0 :                 a7 += n8 / 2;
    1687             : 
    1688           0 :             a7 /= n8;
    1689             :         } // of else
    1690          54 :         return (long)a7;
    1691             :     } // of if
    1692             :     else
    1693             :     {
    1694        3948 :         long n6 = n2 * n3;
    1695             : 
    1696        3948 :         if ( LONG_MAX / std::abs(n1) < std::abs(n6) )
    1697             :         {
    1698         728 :             BigInt a7 = n1;
    1699         728 :             a7 *= n6;
    1700             : 
    1701         728 :             if ( LONG_MAX / std::abs(n4) < std::abs(n5) )
    1702             :             {
    1703           0 :                 BigInt a8 = n4;
    1704           0 :                 a8 *= n5;
    1705             : 
    1706           0 :                 BigInt a9 = a8;
    1707           0 :                 a9 /= 2;
    1708           0 :                 if ( a7.IsNeg() )
    1709           0 :                     a7 -= a9;
    1710             :                 else
    1711           0 :                     a7 += a9;
    1712             : 
    1713           0 :                 a7 /= a8;
    1714             :             } // of if
    1715             :             else
    1716             :             {
    1717         728 :                 long n8 = n4 * n5;
    1718             : 
    1719         728 :                 if ( a7.IsNeg() )
    1720          28 :                     a7 -= n8 / 2;
    1721             :                 else
    1722         700 :                     a7 += n8 / 2;
    1723             : 
    1724         728 :                 a7 /= n8;
    1725             :             } // of else
    1726         728 :             return (long)a7;
    1727             :         } // of if
    1728             :         else
    1729             :         {
    1730        3220 :             long n7 = n1 * n6;
    1731             : 
    1732        3220 :             if ( LONG_MAX / std::abs(n4) < std::abs(n5) )
    1733             :             {
    1734           0 :                 BigInt a7 = n7;
    1735           0 :                 BigInt a8 = n4;
    1736           0 :                 a8 *= n5;
    1737             : 
    1738           0 :                 BigInt a9 = a8;
    1739           0 :                 a9 /= 2;
    1740           0 :                 if ( a7.IsNeg() )
    1741           0 :                     a7 -= a9;
    1742             :                 else
    1743           0 :                     a7 += a9;
    1744             : 
    1745           0 :                 a7 /= a8;
    1746           0 :                 return (long)a7;
    1747             :             } // of if
    1748             :             else
    1749             :             {
    1750        3220 :                 const long n8 = n4 * n5;
    1751        3220 :                 const long n8_2 = n8 / 2;
    1752             : 
    1753        3220 :                 if( n7 < 0 )
    1754             :                 {
    1755         207 :                     if( ( n7 - LONG_MIN ) >= n8_2 )
    1756         207 :                         n7 -= n8_2;
    1757             :                 }
    1758        3013 :                 else if( ( LONG_MAX - n7 ) >= n8_2 )
    1759        3013 :                     n7 += n8_2;
    1760             : 
    1761        3220 :                 return n7 / n8;
    1762             :             } // of else
    1763             :         } // of else
    1764             :     } // of else
    1765             : }
    1766             : 
    1767             : // return (n1 * n2) / n3
    1768       38329 : static long fn3( const long n1, const long n2, const long n3 )
    1769             : {
    1770       38329 :     if ( n1 == 0 || n2 == 0 || n3 == 0 )
    1771       14747 :         return 0;
    1772       23582 :     if ( LONG_MAX / std::abs(n1) < std::abs(n2) )
    1773             :     {
    1774           0 :         BigInt a4 = n1;
    1775           0 :         a4 *= n2;
    1776             : 
    1777           0 :         if ( a4.IsNeg() )
    1778           0 :             a4 -= n3 / 2;
    1779             :         else
    1780           0 :             a4 += n3 / 2;
    1781             : 
    1782           0 :         a4 /= n3;
    1783           0 :         return (long)a4;
    1784             :     } // of if
    1785             :     else
    1786             :     {
    1787       23582 :         long        n4 = n1 * n2;
    1788       23582 :         const long  n3_2 = n3 / 2;
    1789             : 
    1790       23582 :         if( n4 < 0 )
    1791             :         {
    1792        8528 :             if( ( n4 - LONG_MIN ) >= n3_2 )
    1793        8528 :                 n4 -= n3_2;
    1794             :         }
    1795       15054 :         else if( ( LONG_MAX - n4 ) >= n3_2 )
    1796       15054 :             n4 += n3_2;
    1797             : 
    1798       23582 :         return n4 / n3;
    1799             :     } // of else
    1800             : }
    1801             : 
    1802        5080 : Point OutputDevice::LogicToLogic( const Point& rPtSource,
    1803             :                                   const MapMode* pMapModeSource,
    1804             :                                   const MapMode* pMapModeDest ) const
    1805             : {
    1806        5080 :     ENTER1( rPtSource, pMapModeSource, pMapModeDest );
    1807             : 
    1808          53 :     return Point( fn5( rPtSource.X() + aMapResSource.mnMapOfsX,
    1809             :                        aMapResSource.mnMapScNumX, aMapResDest.mnMapScDenomX,
    1810         106 :                        aMapResSource.mnMapScDenomX, aMapResDest.mnMapScNumX ) -
    1811             :                   aMapResDest.mnMapOfsX,
    1812          53 :                   fn5( rPtSource.Y() + aMapResSource.mnMapOfsY,
    1813             :                        aMapResSource.mnMapScNumY, aMapResDest.mnMapScDenomY,
    1814         106 :                        aMapResSource.mnMapScDenomY, aMapResDest.mnMapScNumY ) -
    1815         106 :                   aMapResDest.mnMapOfsY );
    1816             : }
    1817             : 
    1818        5069 : Size OutputDevice::LogicToLogic( const Size& rSzSource,
    1819             :                                  const MapMode* pMapModeSource,
    1820             :                                  const MapMode* pMapModeDest ) const
    1821             : {
    1822        5069 :     ENTER1( rSzSource, pMapModeSource, pMapModeDest );
    1823             : 
    1824             :     return Size( fn5( rSzSource.Width(),
    1825             :                       aMapResSource.mnMapScNumX, aMapResDest.mnMapScDenomX,
    1826             :                       aMapResSource.mnMapScDenomX, aMapResDest.mnMapScNumX ),
    1827             :                  fn5( rSzSource.Height(),
    1828             :                       aMapResSource.mnMapScNumY, aMapResDest.mnMapScDenomY,
    1829          34 :                       aMapResSource.mnMapScDenomY, aMapResDest.mnMapScNumY ) );
    1830             : }
    1831             : 
    1832           0 : Rectangle OutputDevice::LogicToLogic( const Rectangle& rRectSource,
    1833             :                                       const MapMode* pMapModeSource,
    1834             :                                       const MapMode* pMapModeDest ) const
    1835             : {
    1836           0 :     ENTER1( rRectSource, pMapModeSource, pMapModeDest );
    1837             : 
    1838           0 :     return Rectangle( fn5( rRectSource.Left() + aMapResSource.mnMapOfsX,
    1839             :                            aMapResSource.mnMapScNumX, aMapResDest.mnMapScDenomX,
    1840           0 :                            aMapResSource.mnMapScDenomX, aMapResDest.mnMapScNumX ) -
    1841             :                       aMapResDest.mnMapOfsX,
    1842           0 :                       fn5( rRectSource.Top() + aMapResSource.mnMapOfsY,
    1843             :                            aMapResSource.mnMapScNumY, aMapResDest.mnMapScDenomY,
    1844           0 :                            aMapResSource.mnMapScDenomY, aMapResDest.mnMapScNumY ) -
    1845             :                       aMapResDest.mnMapOfsY,
    1846           0 :                       fn5( rRectSource.Right() + aMapResSource.mnMapOfsX,
    1847             :                            aMapResSource.mnMapScNumX, aMapResDest.mnMapScDenomX,
    1848           0 :                            aMapResSource.mnMapScDenomX, aMapResDest.mnMapScNumX ) -
    1849             :                       aMapResDest.mnMapOfsX,
    1850           0 :                       fn5( rRectSource.Bottom() + aMapResSource.mnMapOfsY,
    1851             :                            aMapResSource.mnMapScNumY, aMapResDest.mnMapScDenomY,
    1852           0 :                            aMapResSource.mnMapScDenomY, aMapResDest.mnMapScNumY ) -
    1853           0 :                       aMapResDest.mnMapOfsY );
    1854             : }
    1855             : 
    1856        7862 : Point OutputDevice::LogicToLogic( const Point& rPtSource,
    1857             :                                   const MapMode& rMapModeSource,
    1858             :                                   const MapMode& rMapModeDest )
    1859             : {
    1860        7862 :     if ( rMapModeSource == rMapModeDest )
    1861        6924 :         return rPtSource;
    1862             : 
    1863         938 :     MapUnit eUnitSource = rMapModeSource.GetMapUnit();
    1864         938 :     MapUnit eUnitDest   = rMapModeDest.GetMapUnit();
    1865             :     ENTER2( eUnitSource, eUnitDest );
    1866             : 
    1867         938 :     if ( rMapModeSource.mpImplMapMode->mbSimple &&
    1868             :          rMapModeDest.mpImplMapMode->mbSimple )
    1869             :     {
    1870          80 :         ENTER3( eUnitSource, eUnitDest );
    1871             : 
    1872             :         return Point( fn3( rPtSource.X(), nNumerator, nDenominator ),
    1873          80 :                       fn3( rPtSource.Y(), nNumerator, nDenominator ) );
    1874             :     }
    1875             :     else
    1876             :     {
    1877         858 :         ENTER4( rMapModeSource, rMapModeDest );
    1878             : 
    1879         858 :         return Point( fn5( rPtSource.X() + aMapResSource.mnMapOfsX,
    1880             :                            aMapResSource.mnMapScNumX, aMapResDest.mnMapScDenomX,
    1881        1716 :                            aMapResSource.mnMapScDenomX, aMapResDest.mnMapScNumX ) -
    1882             :                       aMapResDest.mnMapOfsX,
    1883         858 :                       fn5( rPtSource.Y() + aMapResSource.mnMapOfsY,
    1884             :                            aMapResSource.mnMapScNumY, aMapResDest.mnMapScDenomY,
    1885        1716 :                            aMapResSource.mnMapScDenomY, aMapResDest.mnMapScNumY ) -
    1886        1716 :                       aMapResDest.mnMapOfsY );
    1887             :     }
    1888             : }
    1889             : 
    1890        8737 : Size OutputDevice::LogicToLogic( const Size& rSzSource,
    1891             :                                  const MapMode& rMapModeSource,
    1892             :                                  const MapMode& rMapModeDest )
    1893             : {
    1894        8737 :     if ( rMapModeSource == rMapModeDest )
    1895        2517 :         return rSzSource;
    1896             : 
    1897        6220 :     MapUnit eUnitSource = rMapModeSource.GetMapUnit();
    1898        6220 :     MapUnit eUnitDest   = rMapModeDest.GetMapUnit();
    1899             :     ENTER2( eUnitSource, eUnitDest );
    1900             : 
    1901        6220 :     if ( rMapModeSource.mpImplMapMode->mbSimple &&
    1902             :          rMapModeDest.mpImplMapMode->mbSimple )
    1903             :     {
    1904        4950 :         ENTER3( eUnitSource, eUnitDest );
    1905             : 
    1906             :         return Size( fn3( rSzSource.Width(),  nNumerator, nDenominator ),
    1907        4950 :                      fn3( rSzSource.Height(), nNumerator, nDenominator ) );
    1908             :     }
    1909             :     else
    1910             :     {
    1911        1270 :         ENTER4( rMapModeSource, rMapModeDest );
    1912             : 
    1913             :         return Size( fn5( rSzSource.Width(),
    1914             :                           aMapResSource.mnMapScNumX, aMapResDest.mnMapScDenomX,
    1915             :                           aMapResSource.mnMapScDenomX, aMapResDest.mnMapScNumX ),
    1916             :                      fn5( rSzSource.Height(),
    1917             :                           aMapResSource.mnMapScNumY, aMapResDest.mnMapScDenomY,
    1918        1270 :                           aMapResSource.mnMapScDenomY, aMapResDest.mnMapScNumY ) );
    1919             :     }
    1920             : }
    1921             : 
    1922           0 : basegfx::B2DPolygon OutputDevice::LogicToLogic( const basegfx::B2DPolygon& rPolySource,
    1923             :                                                 const MapMode& rMapModeSource,
    1924             :                                                 const MapMode& rMapModeDest )
    1925             : {
    1926           0 :     if(rMapModeSource == rMapModeDest)
    1927             :     {
    1928           0 :         return rPolySource;
    1929             :     }
    1930             : 
    1931           0 :     const basegfx::B2DHomMatrix aTransform(LogicToLogic(rMapModeSource, rMapModeDest));
    1932           0 :     basegfx::B2DPolygon aPoly(rPolySource);
    1933             : 
    1934           0 :     aPoly.transform(aTransform);
    1935           0 :     return aPoly;
    1936             : }
    1937             : 
    1938           0 : basegfx::B2DPolyPolygon OutputDevice::LogicToLogic( const basegfx::B2DPolyPolygon& rPolySource,
    1939             :                                                     const MapMode& rMapModeSource,
    1940             :                                                     const MapMode& rMapModeDest )
    1941             : {
    1942           0 :     if(rMapModeSource == rMapModeDest)
    1943             :     {
    1944           0 :         return rPolySource;
    1945             :     }
    1946             : 
    1947           0 :     const basegfx::B2DHomMatrix aTransform(LogicToLogic(rMapModeSource, rMapModeDest));
    1948           0 :     basegfx::B2DPolyPolygon aPoly(rPolySource);
    1949             : 
    1950           0 :     aPoly.transform(aTransform);
    1951           0 :     return aPoly;
    1952             : }
    1953             : 
    1954         620 : basegfx::B2DHomMatrix OutputDevice::LogicToLogic(const MapMode& rMapModeSource, const MapMode& rMapModeDest)
    1955             : {
    1956         620 :     basegfx::B2DHomMatrix aTransform;
    1957             : 
    1958         620 :     if(rMapModeSource == rMapModeDest)
    1959             :     {
    1960           0 :         return aTransform;
    1961             :     }
    1962             : 
    1963         620 :     MapUnit eUnitSource = rMapModeSource.GetMapUnit();
    1964         620 :     MapUnit eUnitDest   = rMapModeDest.GetMapUnit();
    1965             :     ENTER2(eUnitSource, eUnitDest);
    1966             : 
    1967         620 :     if(rMapModeSource.mpImplMapMode->mbSimple && rMapModeDest.mpImplMapMode->mbSimple)
    1968             :     {
    1969         620 :         ENTER3(eUnitSource, eUnitDest);
    1970             : 
    1971         620 :         const double fScaleFactor((double)nNumerator / (double)nDenominator);
    1972         620 :         aTransform.set(0, 0, fScaleFactor);
    1973         620 :         aTransform.set(1, 1, fScaleFactor);
    1974             :     }
    1975             :     else
    1976             :     {
    1977           0 :         ENTER4(rMapModeSource, rMapModeDest);
    1978             : 
    1979           0 :         const double fScaleFactorX((double(aMapResSource.mnMapScNumX) * double(aMapResDest.mnMapScDenomX)) / (double(aMapResSource.mnMapScDenomX) * double(aMapResDest.mnMapScNumX)));
    1980           0 :         const double fScaleFactorY((double(aMapResSource.mnMapScNumY) * double(aMapResDest.mnMapScDenomY)) / (double(aMapResSource.mnMapScDenomY) * double(aMapResDest.mnMapScNumY)));
    1981           0 :         const double fZeroPointX(double(aMapResSource.mnMapOfsX) * fScaleFactorX - double(aMapResDest.mnMapOfsX));
    1982           0 :         const double fZeroPointY(double(aMapResSource.mnMapOfsY) * fScaleFactorY - double(aMapResDest.mnMapOfsY));
    1983             : 
    1984           0 :         aTransform.set(0, 0, fScaleFactorX);
    1985           0 :         aTransform.set(1, 1, fScaleFactorY);
    1986           0 :         aTransform.set(0, 2, fZeroPointX);
    1987           0 :         aTransform.set(1, 2, fZeroPointY);
    1988             :     }
    1989             : 
    1990         620 :     return aTransform;
    1991             : }
    1992             : 
    1993       11089 : Rectangle OutputDevice::LogicToLogic( const Rectangle& rRectSource,
    1994             :                                       const MapMode& rMapModeSource,
    1995             :                                       const MapMode& rMapModeDest )
    1996             : {
    1997       11089 :     if ( rMapModeSource == rMapModeDest )
    1998        4326 :         return rRectSource;
    1999             : 
    2000        6763 :     MapUnit eUnitSource = rMapModeSource.GetMapUnit();
    2001        6763 :     MapUnit eUnitDest   = rMapModeDest.GetMapUnit();
    2002             :     ENTER2( eUnitSource, eUnitDest );
    2003             : 
    2004        6763 :     if ( rMapModeSource.mpImplMapMode->mbSimple &&
    2005             :          rMapModeDest.mpImplMapMode->mbSimple )
    2006             :     {
    2007        6630 :         ENTER3( eUnitSource, eUnitDest );
    2008             : 
    2009             :         return Rectangle( fn3( rRectSource.Left(), nNumerator, nDenominator ),
    2010             :                           fn3( rRectSource.Top(), nNumerator, nDenominator ),
    2011             :                           fn3( rRectSource.Right(), nNumerator, nDenominator ),
    2012        6630 :                           fn3( rRectSource.Bottom(), nNumerator, nDenominator ) );
    2013             :     }
    2014             :     else
    2015             :     {
    2016         133 :         ENTER4( rMapModeSource, rMapModeDest );
    2017             : 
    2018         133 :         return Rectangle( fn5( rRectSource.Left() + aMapResSource.mnMapOfsX,
    2019             :                                aMapResSource.mnMapScNumX, aMapResDest.mnMapScDenomX,
    2020         266 :                                aMapResSource.mnMapScDenomX, aMapResDest.mnMapScNumX ) -
    2021             :                           aMapResDest.mnMapOfsX,
    2022         133 :                           fn5( rRectSource.Top() + aMapResSource.mnMapOfsY,
    2023             :                                aMapResSource.mnMapScNumY, aMapResDest.mnMapScDenomY,
    2024         266 :                                aMapResSource.mnMapScDenomY, aMapResDest.mnMapScNumY ) -
    2025             :                           aMapResDest.mnMapOfsY,
    2026         133 :                           fn5( rRectSource.Right() + aMapResSource.mnMapOfsX,
    2027             :                                aMapResSource.mnMapScNumX, aMapResDest.mnMapScDenomX,
    2028         266 :                                aMapResSource.mnMapScDenomX, aMapResDest.mnMapScNumX ) -
    2029             :                           aMapResDest.mnMapOfsX,
    2030         133 :                           fn5( rRectSource.Bottom() + aMapResSource.mnMapOfsY,
    2031             :                                aMapResSource.mnMapScNumY, aMapResDest.mnMapScDenomY,
    2032         266 :                                aMapResSource.mnMapScDenomY, aMapResDest.mnMapScNumY ) -
    2033         532 :                           aMapResDest.mnMapOfsY );
    2034             :     }
    2035             : }
    2036             : 
    2037        1815 : long OutputDevice::LogicToLogic( long nLongSource,
    2038             :                                  MapUnit eUnitSource, MapUnit eUnitDest )
    2039             : {
    2040        1815 :     if ( eUnitSource == eUnitDest )
    2041          66 :         return nLongSource;
    2042             : 
    2043             :     ENTER2( eUnitSource, eUnitDest );
    2044        1749 :     ENTER3( eUnitSource, eUnitDest );
    2045             : 
    2046        1749 :     return fn3( nLongSource, nNumerator, nDenominator );
    2047             : }
    2048             : 
    2049         234 : void OutputDevice::SetPixelOffset( const Size& rOffset )
    2050             : {
    2051         234 :     mnOutOffOrigX  = rOffset.Width();
    2052         234 :     mnOutOffOrigY  = rOffset.Height();
    2053             : 
    2054             :     mnOutOffLogicX = ImplPixelToLogic( mnOutOffOrigX, mnDPIX,
    2055             :                                        maMapRes.mnMapScNumX, maMapRes.mnMapScDenomX,
    2056         234 :                                        maThresRes.mnThresPixToLogX );
    2057             :     mnOutOffLogicY = ImplPixelToLogic( mnOutOffOrigY, mnDPIY,
    2058             :                                        maMapRes.mnMapScNumY, maMapRes.mnMapScDenomY,
    2059         234 :                                        maThresRes.mnThresPixToLogY );
    2060             : 
    2061         234 :     if( mpAlphaVDev )
    2062           0 :         mpAlphaVDev->SetPixelOffset( rOffset );
    2063         234 : }
    2064             : 
    2065         117 : Size OutputDevice::GetPixelOffset() const
    2066             : {
    2067         117 :     return Size(mnOutOffOrigX, mnOutOffOrigY);
    2068             : }
    2069             : 
    2070        1295 : long Window::ImplLogicUnitToPixelX( long nX, MapUnit eUnit )
    2071             : {
    2072        1295 :     if ( eUnit != MAP_PIXEL )
    2073             :     {
    2074        1295 :         ImplFrameData* pFrameData = mpWindowImpl->mpFrameData;
    2075             : 
    2076             :         // shift map unit, then re-calculate
    2077        1295 :         if ( pFrameData->meMapUnit != eUnit )
    2078             :         {
    2079         664 :             pFrameData->meMapUnit = eUnit;
    2080             :             ImplCalcMapResolution( MapMode( eUnit ), mnDPIX, mnDPIY,
    2081         664 :                                    pFrameData->maMapUnitRes );
    2082             :         }
    2083             : 
    2084             :         // BigInt is not required, as this function is only used to
    2085             :         // convert the window position
    2086        1295 :         nX  = nX * mnDPIX * pFrameData->maMapUnitRes.mnMapScNumX;
    2087        1295 :         nX += nX >= 0 ?  (pFrameData->maMapUnitRes.mnMapScDenomX/2) :
    2088        2590 :                         -((pFrameData->maMapUnitRes.mnMapScDenomX-1)/2);
    2089        1295 :         nX /= pFrameData->maMapUnitRes.mnMapScDenomX;
    2090             :     }
    2091             : 
    2092        1295 :     return nX;
    2093             : }
    2094             : 
    2095        1295 : long Window::ImplLogicUnitToPixelY( long nY, MapUnit eUnit )
    2096             : {
    2097        1295 :     if ( eUnit != MAP_PIXEL )
    2098             :     {
    2099        1295 :         ImplFrameData* pFrameData = mpWindowImpl->mpFrameData;
    2100             : 
    2101             :         // shift map unit, then re-calculate
    2102        1295 :         if ( pFrameData->meMapUnit != eUnit )
    2103             :         {
    2104           0 :             pFrameData->meMapUnit = eUnit;
    2105             :             ImplCalcMapResolution( MapMode( eUnit ), mnDPIX, mnDPIY,
    2106           0 :                                    pFrameData->maMapUnitRes );
    2107             :         }
    2108             : 
    2109             :         // BigInt is not required, as this function is only used to
    2110             :         // convert the window position
    2111        1295 :         nY  = nY * mnDPIY * pFrameData->maMapUnitRes.mnMapScNumY;
    2112        1295 :         nY += nY >= 0 ?  (pFrameData->maMapUnitRes.mnMapScDenomY/2) :
    2113        2590 :                         -((pFrameData->maMapUnitRes.mnMapScDenomY-1)/2);
    2114        1295 :         nY /= pFrameData->maMapUnitRes.mnMapScDenomY;
    2115             :     }
    2116             : 
    2117        1295 :     return nY;
    2118         516 : }
    2119             : 
    2120             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10