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