xref: /AOO41X/main/svx/source/svdraw/impgrfll.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_svx.hxx"
30*cdf0e10cSrcweir #include <svx/rectenum.hxx>
31*cdf0e10cSrcweir #include <vcl/svapp.hxx>
32*cdf0e10cSrcweir #include <vcl/outdev.hxx>
33*cdf0e10cSrcweir #include <vcl/bitmap.hxx>
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////////
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir void ImpCalcBmpFillSizes( Size&			   rStartOffset,
38*cdf0e10cSrcweir                           Size&			   rBmpOutputSize,
39*cdf0e10cSrcweir                           const Rectangle& rOutputRect,
40*cdf0e10cSrcweir                           const MapMode&   rOutputMapMode,
41*cdf0e10cSrcweir                           const Bitmap&    rFillBitmap,
42*cdf0e10cSrcweir                           const Size&      rBmpSize,
43*cdf0e10cSrcweir                           const Size&      rBmpPerCent,
44*cdf0e10cSrcweir                           const Size&	   rBmpOffPerCent,
45*cdf0e10cSrcweir                           sal_Bool             bBmpLogSize,
46*cdf0e10cSrcweir                           sal_Bool             bBmpTile,
47*cdf0e10cSrcweir                           sal_Bool             bBmpStretch,
48*cdf0e10cSrcweir                           RECT_POINT       eBmpRectPoint )
49*cdf0e10cSrcweir {
50*cdf0e10cSrcweir 	sal_Bool	bOriginalSize = sal_False, bScaleSize = sal_False;
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir 	// Falls keine Groessen gegeben sind ( z.B. alte Dokumente )
53*cdf0e10cSrcweir 	// berechnen wir uns die Groesse selber aus der Bitmap
54*cdf0e10cSrcweir 	// ==> altes Verhalten;
55*cdf0e10cSrcweir 	// wenn nur eine Groesse gegeben ist, wird die andere
56*cdf0e10cSrcweir 	// Groesse angepasst berechnet
57*cdf0e10cSrcweir 	if( bBmpLogSize )
58*cdf0e10cSrcweir 	{
59*cdf0e10cSrcweir 		if( !rBmpSize.Width() && !rBmpSize.Height() )
60*cdf0e10cSrcweir 			bOriginalSize = sal_True;
61*cdf0e10cSrcweir 		else if( !rBmpSize.Width() || !rBmpSize.Height() )
62*cdf0e10cSrcweir 			bScaleSize = sal_True;
63*cdf0e10cSrcweir 	}
64*cdf0e10cSrcweir 	else
65*cdf0e10cSrcweir 	{
66*cdf0e10cSrcweir 		if( !rBmpPerCent.Width() && !rBmpPerCent.Height() )
67*cdf0e10cSrcweir 			bOriginalSize = sal_True;
68*cdf0e10cSrcweir 		else if( !rBmpPerCent.Width() || !rBmpPerCent.Height() )
69*cdf0e10cSrcweir 			bScaleSize = sal_True;
70*cdf0e10cSrcweir 	}
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir 	// entweder Originalgroesse oder angepasste Groesse
73*cdf0e10cSrcweir 	if( bOriginalSize || bScaleSize )
74*cdf0e10cSrcweir 	{
75*cdf0e10cSrcweir 		MapMode aBmpPrefMapMode( rFillBitmap.GetPrefMapMode() );
76*cdf0e10cSrcweir 		Size    aBmpPrefSize( rFillBitmap.GetPrefSize() );
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir 		// Falls keine gesetzt ist, nehmen wir Pixel
79*cdf0e10cSrcweir 		if( !aBmpPrefSize.Width() || !aBmpPrefSize.Height() )
80*cdf0e10cSrcweir         {
81*cdf0e10cSrcweir 			aBmpPrefSize = rFillBitmap.GetSizePixel();
82*cdf0e10cSrcweir             aBmpPrefMapMode = MAP_PIXEL;
83*cdf0e10cSrcweir         }
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir 		if( bOriginalSize )
86*cdf0e10cSrcweir 		{
87*cdf0e10cSrcweir 			if( MAP_PIXEL == aBmpPrefMapMode.GetMapUnit() )
88*cdf0e10cSrcweir 				rBmpOutputSize = Application::GetDefaultDevice()->PixelToLogic( aBmpPrefSize, rOutputMapMode );
89*cdf0e10cSrcweir 			else
90*cdf0e10cSrcweir 				rBmpOutputSize = OutputDevice::LogicToLogic( aBmpPrefSize, aBmpPrefMapMode, rOutputMapMode );
91*cdf0e10cSrcweir 		}
92*cdf0e10cSrcweir 		else
93*cdf0e10cSrcweir 		{
94*cdf0e10cSrcweir 			if( bBmpLogSize )
95*cdf0e10cSrcweir 			{
96*cdf0e10cSrcweir 				rBmpOutputSize = rBmpSize;
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir 				if( !rBmpSize.Width() )
99*cdf0e10cSrcweir 					rBmpOutputSize.Width() = basegfx::fround( (double) rBmpSize.Height() * aBmpPrefSize.Width() / aBmpPrefSize.Height() );
100*cdf0e10cSrcweir 				else
101*cdf0e10cSrcweir 					rBmpOutputSize.Height() = basegfx::fround( (double) rBmpSize.Width() * aBmpPrefSize.Height() / aBmpPrefSize.Width() );
102*cdf0e10cSrcweir 			}
103*cdf0e10cSrcweir 			else
104*cdf0e10cSrcweir 			{
105*cdf0e10cSrcweir 				if( !rBmpPerCent.Width() )
106*cdf0e10cSrcweir 				{
107*cdf0e10cSrcweir 					rBmpOutputSize.Height() = basegfx::fround( (double) rOutputRect.GetHeight() * rBmpPerCent.Height() / 100. );
108*cdf0e10cSrcweir 					rBmpOutputSize.Width() = basegfx::fround( (double) rBmpOutputSize.Height() * aBmpPrefSize.Width() / aBmpPrefSize.Height() );
109*cdf0e10cSrcweir 				}
110*cdf0e10cSrcweir 				else
111*cdf0e10cSrcweir 				{
112*cdf0e10cSrcweir 					rBmpOutputSize.Width() = basegfx::fround( (double) rOutputRect.GetWidth() * rBmpPerCent.Width() / 100. );
113*cdf0e10cSrcweir 					rBmpOutputSize.Height() = basegfx::fround( (double) rBmpOutputSize.Width() * aBmpPrefSize.Height() / aBmpPrefSize.Width() );
114*cdf0e10cSrcweir 				}
115*cdf0e10cSrcweir 			}
116*cdf0e10cSrcweir 		}
117*cdf0e10cSrcweir 	}
118*cdf0e10cSrcweir 	// ansonsten koennen wir die Groesse leicht selber berechnen
119*cdf0e10cSrcweir 	else
120*cdf0e10cSrcweir 	{
121*cdf0e10cSrcweir 		if( bBmpLogSize )
122*cdf0e10cSrcweir 			rBmpOutputSize = rBmpSize;
123*cdf0e10cSrcweir 		else
124*cdf0e10cSrcweir 		{
125*cdf0e10cSrcweir 			rBmpOutputSize.Width() = basegfx::fround( (double) rOutputRect.GetWidth() * rBmpPerCent.Width() / 100. );
126*cdf0e10cSrcweir 			rBmpOutputSize.Height() = basegfx::fround( (double) rOutputRect.GetHeight() * rBmpPerCent.Height() / 100. );
127*cdf0e10cSrcweir 		}
128*cdf0e10cSrcweir 	}
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir 	// nur bei Kachelung die anderen Positionen berechnen
131*cdf0e10cSrcweir 	if( bBmpTile )
132*cdf0e10cSrcweir 	{
133*cdf0e10cSrcweir         Point aStartPoint;
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir 		// Grundposition der ersten Kachel berechen;
136*cdf0e10cSrcweir 		// Diese Position wird spaeter zur Berechnung der absoluten
137*cdf0e10cSrcweir 		// Startposition links oberhalb des Objektes benutzt
138*cdf0e10cSrcweir 		switch( eBmpRectPoint )
139*cdf0e10cSrcweir 		{
140*cdf0e10cSrcweir 			case( RP_MT ):
141*cdf0e10cSrcweir 			{
142*cdf0e10cSrcweir 				aStartPoint.X() = rOutputRect.Left() + ( ( rOutputRect.GetWidth() - rBmpOutputSize.Width() ) >> 1 );
143*cdf0e10cSrcweir 				aStartPoint.Y() = rOutputRect.Top();
144*cdf0e10cSrcweir 			}
145*cdf0e10cSrcweir 			break;
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir 			case( RP_RT ):
148*cdf0e10cSrcweir 			{
149*cdf0e10cSrcweir 				aStartPoint.X() = rOutputRect.Right() - rBmpOutputSize.Width();
150*cdf0e10cSrcweir 				aStartPoint.Y() = rOutputRect.Top();
151*cdf0e10cSrcweir 			}
152*cdf0e10cSrcweir 			break;
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir 			case( RP_LM ):
155*cdf0e10cSrcweir 			{
156*cdf0e10cSrcweir 				aStartPoint.X() = rOutputRect.Left();
157*cdf0e10cSrcweir 				aStartPoint.Y() = rOutputRect.Top() + ( ( rOutputRect.GetHeight() - rBmpOutputSize.Height() ) >> 1  );
158*cdf0e10cSrcweir 			}
159*cdf0e10cSrcweir 			break;
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir 			case( RP_MM ):
162*cdf0e10cSrcweir 			{
163*cdf0e10cSrcweir 				aStartPoint.X() = rOutputRect.Left() + ( ( rOutputRect.GetWidth() - rBmpOutputSize.Width() ) >> 1 );
164*cdf0e10cSrcweir 				aStartPoint.Y() = rOutputRect.Top() + ( ( rOutputRect.GetHeight() - rBmpOutputSize.Height() ) >> 1 );
165*cdf0e10cSrcweir 			}
166*cdf0e10cSrcweir 			break;
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir 			case( RP_RM ):
169*cdf0e10cSrcweir 			{
170*cdf0e10cSrcweir 				aStartPoint.X() = rOutputRect.Right() - rBmpOutputSize.Width();
171*cdf0e10cSrcweir 				aStartPoint.Y() = rOutputRect.Top() + ( ( rOutputRect.GetHeight() - rBmpOutputSize.Height() ) >> 1 );
172*cdf0e10cSrcweir 			}
173*cdf0e10cSrcweir 			break;
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir 			case( RP_LB ):
176*cdf0e10cSrcweir 			{
177*cdf0e10cSrcweir 				aStartPoint.X() = rOutputRect.Left();
178*cdf0e10cSrcweir 				aStartPoint.Y() = rOutputRect.Bottom() - rBmpOutputSize.Height();
179*cdf0e10cSrcweir 			}
180*cdf0e10cSrcweir 			break;
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir 			case( RP_MB ):
183*cdf0e10cSrcweir 			{
184*cdf0e10cSrcweir 				aStartPoint.X() = rOutputRect.Left() + ( ( rOutputRect.GetWidth() - rBmpOutputSize.Width() ) >> 1 );
185*cdf0e10cSrcweir 				aStartPoint.Y() = rOutputRect.Bottom() - rBmpOutputSize.Height();
186*cdf0e10cSrcweir 			}
187*cdf0e10cSrcweir 			break;
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir 			case( RP_RB ):
190*cdf0e10cSrcweir 			{
191*cdf0e10cSrcweir 				aStartPoint.X() = rOutputRect.Right() - rBmpOutputSize.Width();
192*cdf0e10cSrcweir 				aStartPoint.Y() = rOutputRect.Bottom() - rBmpOutputSize.Height();
193*cdf0e10cSrcweir 			}
194*cdf0e10cSrcweir 			break;
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir 			// default linke obere Ecke
197*cdf0e10cSrcweir 			default:
198*cdf0e10cSrcweir 				aStartPoint = rOutputRect.TopLeft();
199*cdf0e10cSrcweir 			break;
200*cdf0e10cSrcweir 		}
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir 		// X- oder Y-Positionsoffset beruecksichtigen
203*cdf0e10cSrcweir 		if( rBmpOffPerCent.Width() )
204*cdf0e10cSrcweir 			aStartPoint.X() += ( rBmpOutputSize.Width() * rBmpOffPerCent.Width() / 100 );
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir         if( rBmpOffPerCent.Height() )
207*cdf0e10cSrcweir 			aStartPoint.Y() += ( rBmpOutputSize.Height() * rBmpOffPerCent.Height() / 100 );
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir 		// echten Startpunkt berechnen ( links oben )
210*cdf0e10cSrcweir 		if( rBmpOutputSize.Width() && rBmpOutputSize.Height() )
211*cdf0e10cSrcweir 		{
212*cdf0e10cSrcweir 			const long nDiffX = aStartPoint.X() - rOutputRect.Left();
213*cdf0e10cSrcweir 			const long nDiffY = aStartPoint.Y() - rOutputRect.Top();
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir 			if ( nDiffX )
216*cdf0e10cSrcweir 			{
217*cdf0e10cSrcweir 				long nCount = nDiffX / rBmpOutputSize.Width() + 1;
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir 				if ( rBmpOffPerCent.Height() && ( nCount & 1L ) )
220*cdf0e10cSrcweir 					nCount++;
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir 				aStartPoint.X() -= ( nCount * rBmpOutputSize.Width() );
223*cdf0e10cSrcweir 			}
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir 			if ( nDiffY )
226*cdf0e10cSrcweir 			{
227*cdf0e10cSrcweir 				long nCount = nDiffY / rBmpOutputSize.Height() + 1;
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir 				if ( rBmpOffPerCent.Width() && ( nCount & 1L ) )
230*cdf0e10cSrcweir 					nCount++;
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir 				aStartPoint.Y() -= ( nCount * rBmpOutputSize.Height() );
233*cdf0e10cSrcweir 			}
234*cdf0e10cSrcweir 		}
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir         rStartOffset = Size( aStartPoint.X() - rOutputRect.Left(),
237*cdf0e10cSrcweir                              aStartPoint.Y() - rOutputRect.Top() );
238*cdf0e10cSrcweir 	}
239*cdf0e10cSrcweir     else
240*cdf0e10cSrcweir     {
241*cdf0e10cSrcweir         if( bBmpStretch )
242*cdf0e10cSrcweir         {
243*cdf0e10cSrcweir             rStartOffset = Size(0, 0);
244*cdf0e10cSrcweir             rBmpOutputSize = rOutputRect.GetSize();
245*cdf0e10cSrcweir         }
246*cdf0e10cSrcweir         else
247*cdf0e10cSrcweir         {
248*cdf0e10cSrcweir             rStartOffset = Size( ( rOutputRect.GetWidth() - rBmpOutputSize.Width() ) >> 1,
249*cdf0e10cSrcweir                                  ( rOutputRect.GetHeight() - rBmpOutputSize.Height() ) >> 1 );
250*cdf0e10cSrcweir         }
251*cdf0e10cSrcweir     }
252*cdf0e10cSrcweir }
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
255*cdf0e10cSrcweir // eof
256