update dev300-m58
[ooovba.git] / svx / source / svdraw / impgrfll.cxx
blobd0aeb60b77c467871a4d16495e1a12f7782e5b8d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: impgrfll.cxx,v $
10 * $Revision: 1.17 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include <svx/rectenum.hxx>
34 #include <vcl/svapp.hxx>
35 #include <vcl/outdev.hxx>
36 #include <vcl/bitmap.hxx>
38 ///////////////////////////////////////////////////////////////////////////////
40 void ImpCalcBmpFillSizes( Size& rStartOffset,
41 Size& rBmpOutputSize,
42 const Rectangle& rOutputRect,
43 const MapMode& rOutputMapMode,
44 const Bitmap& rFillBitmap,
45 const Size& rBmpSize,
46 const Size& rBmpPerCent,
47 const Size& rBmpOffPerCent,
48 BOOL bBmpLogSize,
49 BOOL bBmpTile,
50 BOOL bBmpStretch,
51 RECT_POINT eBmpRectPoint )
53 BOOL bOriginalSize = FALSE, bScaleSize = FALSE;
55 // Falls keine Groessen gegeben sind ( z.B. alte Dokumente )
56 // berechnen wir uns die Groesse selber aus der Bitmap
57 // ==> altes Verhalten;
58 // wenn nur eine Groesse gegeben ist, wird die andere
59 // Groesse angepasst berechnet
60 if( bBmpLogSize )
62 if( !rBmpSize.Width() && !rBmpSize.Height() )
63 bOriginalSize = TRUE;
64 else if( !rBmpSize.Width() || !rBmpSize.Height() )
65 bScaleSize = TRUE;
67 else
69 if( !rBmpPerCent.Width() && !rBmpPerCent.Height() )
70 bOriginalSize = TRUE;
71 else if( !rBmpPerCent.Width() || !rBmpPerCent.Height() )
72 bScaleSize = TRUE;
75 // entweder Originalgroesse oder angepasste Groesse
76 if( bOriginalSize || bScaleSize )
78 MapMode aBmpPrefMapMode( rFillBitmap.GetPrefMapMode() );
79 Size aBmpPrefSize( rFillBitmap.GetPrefSize() );
81 // Falls keine gesetzt ist, nehmen wir Pixel
82 if( !aBmpPrefSize.Width() || !aBmpPrefSize.Height() )
84 aBmpPrefSize = rFillBitmap.GetSizePixel();
85 aBmpPrefMapMode = MAP_PIXEL;
88 if( bOriginalSize )
90 if( MAP_PIXEL == aBmpPrefMapMode.GetMapUnit() )
91 rBmpOutputSize = Application::GetDefaultDevice()->PixelToLogic( aBmpPrefSize, rOutputMapMode );
92 else
93 rBmpOutputSize = OutputDevice::LogicToLogic( aBmpPrefSize, aBmpPrefMapMode, rOutputMapMode );
95 else
97 if( bBmpLogSize )
99 rBmpOutputSize = rBmpSize;
101 if( !rBmpSize.Width() )
102 rBmpOutputSize.Width() = basegfx::fround( (double) rBmpSize.Height() * aBmpPrefSize.Width() / aBmpPrefSize.Height() );
103 else
104 rBmpOutputSize.Height() = basegfx::fround( (double) rBmpSize.Width() * aBmpPrefSize.Height() / aBmpPrefSize.Width() );
106 else
108 if( !rBmpPerCent.Width() )
110 rBmpOutputSize.Height() = basegfx::fround( (double) rOutputRect.GetHeight() * rBmpPerCent.Height() / 100. );
111 rBmpOutputSize.Width() = basegfx::fround( (double) rBmpOutputSize.Height() * aBmpPrefSize.Width() / aBmpPrefSize.Height() );
113 else
115 rBmpOutputSize.Width() = basegfx::fround( (double) rOutputRect.GetWidth() * rBmpPerCent.Width() / 100. );
116 rBmpOutputSize.Height() = basegfx::fround( (double) rBmpOutputSize.Width() * aBmpPrefSize.Height() / aBmpPrefSize.Width() );
121 // ansonsten koennen wir die Groesse leicht selber berechnen
122 else
124 if( bBmpLogSize )
125 rBmpOutputSize = rBmpSize;
126 else
128 rBmpOutputSize.Width() = basegfx::fround( (double) rOutputRect.GetWidth() * rBmpPerCent.Width() / 100. );
129 rBmpOutputSize.Height() = basegfx::fround( (double) rOutputRect.GetHeight() * rBmpPerCent.Height() / 100. );
133 // nur bei Kachelung die anderen Positionen berechnen
134 if( bBmpTile )
136 Point aStartPoint;
138 // Grundposition der ersten Kachel berechen;
139 // Diese Position wird spaeter zur Berechnung der absoluten
140 // Startposition links oberhalb des Objektes benutzt
141 switch( eBmpRectPoint )
143 case( RP_MT ):
145 aStartPoint.X() = rOutputRect.Left() + ( ( rOutputRect.GetWidth() - rBmpOutputSize.Width() ) >> 1 );
146 aStartPoint.Y() = rOutputRect.Top();
148 break;
150 case( RP_RT ):
152 aStartPoint.X() = rOutputRect.Right() - rBmpOutputSize.Width();
153 aStartPoint.Y() = rOutputRect.Top();
155 break;
157 case( RP_LM ):
159 aStartPoint.X() = rOutputRect.Left();
160 aStartPoint.Y() = rOutputRect.Top() + ( ( rOutputRect.GetHeight() - rBmpOutputSize.Height() ) >> 1 );
162 break;
164 case( RP_MM ):
166 aStartPoint.X() = rOutputRect.Left() + ( ( rOutputRect.GetWidth() - rBmpOutputSize.Width() ) >> 1 );
167 aStartPoint.Y() = rOutputRect.Top() + ( ( rOutputRect.GetHeight() - rBmpOutputSize.Height() ) >> 1 );
169 break;
171 case( RP_RM ):
173 aStartPoint.X() = rOutputRect.Right() - rBmpOutputSize.Width();
174 aStartPoint.Y() = rOutputRect.Top() + ( ( rOutputRect.GetHeight() - rBmpOutputSize.Height() ) >> 1 );
176 break;
178 case( RP_LB ):
180 aStartPoint.X() = rOutputRect.Left();
181 aStartPoint.Y() = rOutputRect.Bottom() - rBmpOutputSize.Height();
183 break;
185 case( RP_MB ):
187 aStartPoint.X() = rOutputRect.Left() + ( ( rOutputRect.GetWidth() - rBmpOutputSize.Width() ) >> 1 );
188 aStartPoint.Y() = rOutputRect.Bottom() - rBmpOutputSize.Height();
190 break;
192 case( RP_RB ):
194 aStartPoint.X() = rOutputRect.Right() - rBmpOutputSize.Width();
195 aStartPoint.Y() = rOutputRect.Bottom() - rBmpOutputSize.Height();
197 break;
199 // default linke obere Ecke
200 default:
201 aStartPoint = rOutputRect.TopLeft();
202 break;
205 // X- oder Y-Positionsoffset beruecksichtigen
206 if( rBmpOffPerCent.Width() )
207 aStartPoint.X() += ( rBmpOutputSize.Width() * rBmpOffPerCent.Width() / 100 );
209 if( rBmpOffPerCent.Height() )
210 aStartPoint.Y() += ( rBmpOutputSize.Height() * rBmpOffPerCent.Height() / 100 );
212 // echten Startpunkt berechnen ( links oben )
213 if( rBmpOutputSize.Width() && rBmpOutputSize.Height() )
215 const long nDiffX = aStartPoint.X() - rOutputRect.Left();
216 const long nDiffY = aStartPoint.Y() - rOutputRect.Top();
218 if ( nDiffX )
220 long nCount = nDiffX / rBmpOutputSize.Width() + 1;
222 if ( rBmpOffPerCent.Height() && ( nCount & 1L ) )
223 nCount++;
225 aStartPoint.X() -= ( nCount * rBmpOutputSize.Width() );
228 if ( nDiffY )
230 long nCount = nDiffY / rBmpOutputSize.Height() + 1;
232 if ( rBmpOffPerCent.Width() && ( nCount & 1L ) )
233 nCount++;
235 aStartPoint.Y() -= ( nCount * rBmpOutputSize.Height() );
239 rStartOffset = Size( aStartPoint.X() - rOutputRect.Left(),
240 aStartPoint.Y() - rOutputRect.Top() );
242 else
244 if( bBmpStretch )
246 rStartOffset = Size(0, 0);
247 rBmpOutputSize = rOutputRect.GetSize();
249 else
251 rStartOffset = Size( ( rOutputRect.GetWidth() - rBmpOutputSize.Width() ) >> 1,
252 ( rOutputRect.GetHeight() - rBmpOutputSize.Height() ) >> 1 );
257 //////////////////////////////////////////////////////////////////////////////
258 // eof