xref: /AOO41X/main/svx/source/svdraw/impgrfll.cxx (revision f6e50924346d0b8c0b07c91832a97665dd718b0c)
1*f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f6e50924SAndrew Rist  * distributed with this work for additional information
6*f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f6e50924SAndrew Rist  * specific language governing permissions and limitations
18*f6e50924SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*f6e50924SAndrew Rist  *************************************************************/
21*f6e50924SAndrew Rist 
22*f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir #include <svx/rectenum.hxx>
27cdf0e10cSrcweir #include <vcl/svapp.hxx>
28cdf0e10cSrcweir #include <vcl/outdev.hxx>
29cdf0e10cSrcweir #include <vcl/bitmap.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////////
32cdf0e10cSrcweir 
ImpCalcBmpFillSizes(Size & rStartOffset,Size & rBmpOutputSize,const Rectangle & rOutputRect,const MapMode & rOutputMapMode,const Bitmap & rFillBitmap,const Size & rBmpSize,const Size & rBmpPerCent,const Size & rBmpOffPerCent,sal_Bool bBmpLogSize,sal_Bool bBmpTile,sal_Bool bBmpStretch,RECT_POINT eBmpRectPoint)33cdf0e10cSrcweir void ImpCalcBmpFillSizes( Size&			   rStartOffset,
34cdf0e10cSrcweir                           Size&			   rBmpOutputSize,
35cdf0e10cSrcweir                           const Rectangle& rOutputRect,
36cdf0e10cSrcweir                           const MapMode&   rOutputMapMode,
37cdf0e10cSrcweir                           const Bitmap&    rFillBitmap,
38cdf0e10cSrcweir                           const Size&      rBmpSize,
39cdf0e10cSrcweir                           const Size&      rBmpPerCent,
40cdf0e10cSrcweir                           const Size&	   rBmpOffPerCent,
41cdf0e10cSrcweir                           sal_Bool             bBmpLogSize,
42cdf0e10cSrcweir                           sal_Bool             bBmpTile,
43cdf0e10cSrcweir                           sal_Bool             bBmpStretch,
44cdf0e10cSrcweir                           RECT_POINT       eBmpRectPoint )
45cdf0e10cSrcweir {
46cdf0e10cSrcweir 	sal_Bool	bOriginalSize = sal_False, bScaleSize = sal_False;
47cdf0e10cSrcweir 
48cdf0e10cSrcweir 	// Falls keine Groessen gegeben sind ( z.B. alte Dokumente )
49cdf0e10cSrcweir 	// berechnen wir uns die Groesse selber aus der Bitmap
50cdf0e10cSrcweir 	// ==> altes Verhalten;
51cdf0e10cSrcweir 	// wenn nur eine Groesse gegeben ist, wird die andere
52cdf0e10cSrcweir 	// Groesse angepasst berechnet
53cdf0e10cSrcweir 	if( bBmpLogSize )
54cdf0e10cSrcweir 	{
55cdf0e10cSrcweir 		if( !rBmpSize.Width() && !rBmpSize.Height() )
56cdf0e10cSrcweir 			bOriginalSize = sal_True;
57cdf0e10cSrcweir 		else if( !rBmpSize.Width() || !rBmpSize.Height() )
58cdf0e10cSrcweir 			bScaleSize = sal_True;
59cdf0e10cSrcweir 	}
60cdf0e10cSrcweir 	else
61cdf0e10cSrcweir 	{
62cdf0e10cSrcweir 		if( !rBmpPerCent.Width() && !rBmpPerCent.Height() )
63cdf0e10cSrcweir 			bOriginalSize = sal_True;
64cdf0e10cSrcweir 		else if( !rBmpPerCent.Width() || !rBmpPerCent.Height() )
65cdf0e10cSrcweir 			bScaleSize = sal_True;
66cdf0e10cSrcweir 	}
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 	// entweder Originalgroesse oder angepasste Groesse
69cdf0e10cSrcweir 	if( bOriginalSize || bScaleSize )
70cdf0e10cSrcweir 	{
71cdf0e10cSrcweir 		MapMode aBmpPrefMapMode( rFillBitmap.GetPrefMapMode() );
72cdf0e10cSrcweir 		Size    aBmpPrefSize( rFillBitmap.GetPrefSize() );
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 		// Falls keine gesetzt ist, nehmen wir Pixel
75cdf0e10cSrcweir 		if( !aBmpPrefSize.Width() || !aBmpPrefSize.Height() )
76cdf0e10cSrcweir         {
77cdf0e10cSrcweir 			aBmpPrefSize = rFillBitmap.GetSizePixel();
78cdf0e10cSrcweir             aBmpPrefMapMode = MAP_PIXEL;
79cdf0e10cSrcweir         }
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 		if( bOriginalSize )
82cdf0e10cSrcweir 		{
83cdf0e10cSrcweir 			if( MAP_PIXEL == aBmpPrefMapMode.GetMapUnit() )
84cdf0e10cSrcweir 				rBmpOutputSize = Application::GetDefaultDevice()->PixelToLogic( aBmpPrefSize, rOutputMapMode );
85cdf0e10cSrcweir 			else
86cdf0e10cSrcweir 				rBmpOutputSize = OutputDevice::LogicToLogic( aBmpPrefSize, aBmpPrefMapMode, rOutputMapMode );
87cdf0e10cSrcweir 		}
88cdf0e10cSrcweir 		else
89cdf0e10cSrcweir 		{
90cdf0e10cSrcweir 			if( bBmpLogSize )
91cdf0e10cSrcweir 			{
92cdf0e10cSrcweir 				rBmpOutputSize = rBmpSize;
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 				if( !rBmpSize.Width() )
95cdf0e10cSrcweir 					rBmpOutputSize.Width() = basegfx::fround( (double) rBmpSize.Height() * aBmpPrefSize.Width() / aBmpPrefSize.Height() );
96cdf0e10cSrcweir 				else
97cdf0e10cSrcweir 					rBmpOutputSize.Height() = basegfx::fround( (double) rBmpSize.Width() * aBmpPrefSize.Height() / aBmpPrefSize.Width() );
98cdf0e10cSrcweir 			}
99cdf0e10cSrcweir 			else
100cdf0e10cSrcweir 			{
101cdf0e10cSrcweir 				if( !rBmpPerCent.Width() )
102cdf0e10cSrcweir 				{
103cdf0e10cSrcweir 					rBmpOutputSize.Height() = basegfx::fround( (double) rOutputRect.GetHeight() * rBmpPerCent.Height() / 100. );
104cdf0e10cSrcweir 					rBmpOutputSize.Width() = basegfx::fround( (double) rBmpOutputSize.Height() * aBmpPrefSize.Width() / aBmpPrefSize.Height() );
105cdf0e10cSrcweir 				}
106cdf0e10cSrcweir 				else
107cdf0e10cSrcweir 				{
108cdf0e10cSrcweir 					rBmpOutputSize.Width() = basegfx::fround( (double) rOutputRect.GetWidth() * rBmpPerCent.Width() / 100. );
109cdf0e10cSrcweir 					rBmpOutputSize.Height() = basegfx::fround( (double) rBmpOutputSize.Width() * aBmpPrefSize.Height() / aBmpPrefSize.Width() );
110cdf0e10cSrcweir 				}
111cdf0e10cSrcweir 			}
112cdf0e10cSrcweir 		}
113cdf0e10cSrcweir 	}
114cdf0e10cSrcweir 	// ansonsten koennen wir die Groesse leicht selber berechnen
115cdf0e10cSrcweir 	else
116cdf0e10cSrcweir 	{
117cdf0e10cSrcweir 		if( bBmpLogSize )
118cdf0e10cSrcweir 			rBmpOutputSize = rBmpSize;
119cdf0e10cSrcweir 		else
120cdf0e10cSrcweir 		{
121cdf0e10cSrcweir 			rBmpOutputSize.Width() = basegfx::fround( (double) rOutputRect.GetWidth() * rBmpPerCent.Width() / 100. );
122cdf0e10cSrcweir 			rBmpOutputSize.Height() = basegfx::fround( (double) rOutputRect.GetHeight() * rBmpPerCent.Height() / 100. );
123cdf0e10cSrcweir 		}
124cdf0e10cSrcweir 	}
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 	// nur bei Kachelung die anderen Positionen berechnen
127cdf0e10cSrcweir 	if( bBmpTile )
128cdf0e10cSrcweir 	{
129cdf0e10cSrcweir         Point aStartPoint;
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 		// Grundposition der ersten Kachel berechen;
132cdf0e10cSrcweir 		// Diese Position wird spaeter zur Berechnung der absoluten
133cdf0e10cSrcweir 		// Startposition links oberhalb des Objektes benutzt
134cdf0e10cSrcweir 		switch( eBmpRectPoint )
135cdf0e10cSrcweir 		{
136cdf0e10cSrcweir 			case( RP_MT ):
137cdf0e10cSrcweir 			{
138cdf0e10cSrcweir 				aStartPoint.X() = rOutputRect.Left() + ( ( rOutputRect.GetWidth() - rBmpOutputSize.Width() ) >> 1 );
139cdf0e10cSrcweir 				aStartPoint.Y() = rOutputRect.Top();
140cdf0e10cSrcweir 			}
141cdf0e10cSrcweir 			break;
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 			case( RP_RT ):
144cdf0e10cSrcweir 			{
145cdf0e10cSrcweir 				aStartPoint.X() = rOutputRect.Right() - rBmpOutputSize.Width();
146cdf0e10cSrcweir 				aStartPoint.Y() = rOutputRect.Top();
147cdf0e10cSrcweir 			}
148cdf0e10cSrcweir 			break;
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 			case( RP_LM ):
151cdf0e10cSrcweir 			{
152cdf0e10cSrcweir 				aStartPoint.X() = rOutputRect.Left();
153cdf0e10cSrcweir 				aStartPoint.Y() = rOutputRect.Top() + ( ( rOutputRect.GetHeight() - rBmpOutputSize.Height() ) >> 1  );
154cdf0e10cSrcweir 			}
155cdf0e10cSrcweir 			break;
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 			case( RP_MM ):
158cdf0e10cSrcweir 			{
159cdf0e10cSrcweir 				aStartPoint.X() = rOutputRect.Left() + ( ( rOutputRect.GetWidth() - rBmpOutputSize.Width() ) >> 1 );
160cdf0e10cSrcweir 				aStartPoint.Y() = rOutputRect.Top() + ( ( rOutputRect.GetHeight() - rBmpOutputSize.Height() ) >> 1 );
161cdf0e10cSrcweir 			}
162cdf0e10cSrcweir 			break;
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 			case( RP_RM ):
165cdf0e10cSrcweir 			{
166cdf0e10cSrcweir 				aStartPoint.X() = rOutputRect.Right() - rBmpOutputSize.Width();
167cdf0e10cSrcweir 				aStartPoint.Y() = rOutputRect.Top() + ( ( rOutputRect.GetHeight() - rBmpOutputSize.Height() ) >> 1 );
168cdf0e10cSrcweir 			}
169cdf0e10cSrcweir 			break;
170cdf0e10cSrcweir 
171cdf0e10cSrcweir 			case( RP_LB ):
172cdf0e10cSrcweir 			{
173cdf0e10cSrcweir 				aStartPoint.X() = rOutputRect.Left();
174cdf0e10cSrcweir 				aStartPoint.Y() = rOutputRect.Bottom() - rBmpOutputSize.Height();
175cdf0e10cSrcweir 			}
176cdf0e10cSrcweir 			break;
177cdf0e10cSrcweir 
178cdf0e10cSrcweir 			case( RP_MB ):
179cdf0e10cSrcweir 			{
180cdf0e10cSrcweir 				aStartPoint.X() = rOutputRect.Left() + ( ( rOutputRect.GetWidth() - rBmpOutputSize.Width() ) >> 1 );
181cdf0e10cSrcweir 				aStartPoint.Y() = rOutputRect.Bottom() - rBmpOutputSize.Height();
182cdf0e10cSrcweir 			}
183cdf0e10cSrcweir 			break;
184cdf0e10cSrcweir 
185cdf0e10cSrcweir 			case( RP_RB ):
186cdf0e10cSrcweir 			{
187cdf0e10cSrcweir 				aStartPoint.X() = rOutputRect.Right() - rBmpOutputSize.Width();
188cdf0e10cSrcweir 				aStartPoint.Y() = rOutputRect.Bottom() - rBmpOutputSize.Height();
189cdf0e10cSrcweir 			}
190cdf0e10cSrcweir 			break;
191cdf0e10cSrcweir 
192cdf0e10cSrcweir 			// default linke obere Ecke
193cdf0e10cSrcweir 			default:
194cdf0e10cSrcweir 				aStartPoint = rOutputRect.TopLeft();
195cdf0e10cSrcweir 			break;
196cdf0e10cSrcweir 		}
197cdf0e10cSrcweir 
198cdf0e10cSrcweir 		// X- oder Y-Positionsoffset beruecksichtigen
199cdf0e10cSrcweir 		if( rBmpOffPerCent.Width() )
200cdf0e10cSrcweir 			aStartPoint.X() += ( rBmpOutputSize.Width() * rBmpOffPerCent.Width() / 100 );
201cdf0e10cSrcweir 
202cdf0e10cSrcweir         if( rBmpOffPerCent.Height() )
203cdf0e10cSrcweir 			aStartPoint.Y() += ( rBmpOutputSize.Height() * rBmpOffPerCent.Height() / 100 );
204cdf0e10cSrcweir 
205cdf0e10cSrcweir 		// echten Startpunkt berechnen ( links oben )
206cdf0e10cSrcweir 		if( rBmpOutputSize.Width() && rBmpOutputSize.Height() )
207cdf0e10cSrcweir 		{
208cdf0e10cSrcweir 			const long nDiffX = aStartPoint.X() - rOutputRect.Left();
209cdf0e10cSrcweir 			const long nDiffY = aStartPoint.Y() - rOutputRect.Top();
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 			if ( nDiffX )
212cdf0e10cSrcweir 			{
213cdf0e10cSrcweir 				long nCount = nDiffX / rBmpOutputSize.Width() + 1;
214cdf0e10cSrcweir 
215cdf0e10cSrcweir 				if ( rBmpOffPerCent.Height() && ( nCount & 1L ) )
216cdf0e10cSrcweir 					nCount++;
217cdf0e10cSrcweir 
218cdf0e10cSrcweir 				aStartPoint.X() -= ( nCount * rBmpOutputSize.Width() );
219cdf0e10cSrcweir 			}
220cdf0e10cSrcweir 
221cdf0e10cSrcweir 			if ( nDiffY )
222cdf0e10cSrcweir 			{
223cdf0e10cSrcweir 				long nCount = nDiffY / rBmpOutputSize.Height() + 1;
224cdf0e10cSrcweir 
225cdf0e10cSrcweir 				if ( rBmpOffPerCent.Width() && ( nCount & 1L ) )
226cdf0e10cSrcweir 					nCount++;
227cdf0e10cSrcweir 
228cdf0e10cSrcweir 				aStartPoint.Y() -= ( nCount * rBmpOutputSize.Height() );
229cdf0e10cSrcweir 			}
230cdf0e10cSrcweir 		}
231cdf0e10cSrcweir 
232cdf0e10cSrcweir         rStartOffset = Size( aStartPoint.X() - rOutputRect.Left(),
233cdf0e10cSrcweir                              aStartPoint.Y() - rOutputRect.Top() );
234cdf0e10cSrcweir 	}
235cdf0e10cSrcweir     else
236cdf0e10cSrcweir     {
237cdf0e10cSrcweir         if( bBmpStretch )
238cdf0e10cSrcweir         {
239cdf0e10cSrcweir             rStartOffset = Size(0, 0);
240cdf0e10cSrcweir             rBmpOutputSize = rOutputRect.GetSize();
241cdf0e10cSrcweir         }
242cdf0e10cSrcweir         else
243cdf0e10cSrcweir         {
244cdf0e10cSrcweir             rStartOffset = Size( ( rOutputRect.GetWidth() - rBmpOutputSize.Width() ) >> 1,
245cdf0e10cSrcweir                                  ( rOutputRect.GetHeight() - rBmpOutputSize.Height() ) >> 1 );
246cdf0e10cSrcweir         }
247cdf0e10cSrcweir     }
248cdf0e10cSrcweir }
249cdf0e10cSrcweir 
250cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
251cdf0e10cSrcweir // eof
252