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