1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: impgrfll.cxx,v $
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
,
42 const Rectangle
& rOutputRect
,
43 const MapMode
& rOutputMapMode
,
44 const Bitmap
& rFillBitmap
,
46 const Size
& rBmpPerCent
,
47 const Size
& rBmpOffPerCent
,
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
62 if( !rBmpSize
.Width() && !rBmpSize
.Height() )
64 else if( !rBmpSize
.Width() || !rBmpSize
.Height() )
69 if( !rBmpPerCent
.Width() && !rBmpPerCent
.Height() )
71 else if( !rBmpPerCent
.Width() || !rBmpPerCent
.Height() )
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
;
90 if( MAP_PIXEL
== aBmpPrefMapMode
.GetMapUnit() )
91 rBmpOutputSize
= Application::GetDefaultDevice()->PixelToLogic( aBmpPrefSize
, rOutputMapMode
);
93 rBmpOutputSize
= OutputDevice::LogicToLogic( aBmpPrefSize
, aBmpPrefMapMode
, rOutputMapMode
);
99 rBmpOutputSize
= rBmpSize
;
101 if( !rBmpSize
.Width() )
102 rBmpOutputSize
.Width() = basegfx::fround( (double) rBmpSize
.Height() * aBmpPrefSize
.Width() / aBmpPrefSize
.Height() );
104 rBmpOutputSize
.Height() = basegfx::fround( (double) rBmpSize
.Width() * aBmpPrefSize
.Height() / aBmpPrefSize
.Width() );
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() );
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
125 rBmpOutputSize
= rBmpSize
;
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
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
)
145 aStartPoint
.X() = rOutputRect
.Left() + ( ( rOutputRect
.GetWidth() - rBmpOutputSize
.Width() ) >> 1 );
146 aStartPoint
.Y() = rOutputRect
.Top();
152 aStartPoint
.X() = rOutputRect
.Right() - rBmpOutputSize
.Width();
153 aStartPoint
.Y() = rOutputRect
.Top();
159 aStartPoint
.X() = rOutputRect
.Left();
160 aStartPoint
.Y() = rOutputRect
.Top() + ( ( rOutputRect
.GetHeight() - rBmpOutputSize
.Height() ) >> 1 );
166 aStartPoint
.X() = rOutputRect
.Left() + ( ( rOutputRect
.GetWidth() - rBmpOutputSize
.Width() ) >> 1 );
167 aStartPoint
.Y() = rOutputRect
.Top() + ( ( rOutputRect
.GetHeight() - rBmpOutputSize
.Height() ) >> 1 );
173 aStartPoint
.X() = rOutputRect
.Right() - rBmpOutputSize
.Width();
174 aStartPoint
.Y() = rOutputRect
.Top() + ( ( rOutputRect
.GetHeight() - rBmpOutputSize
.Height() ) >> 1 );
180 aStartPoint
.X() = rOutputRect
.Left();
181 aStartPoint
.Y() = rOutputRect
.Bottom() - rBmpOutputSize
.Height();
187 aStartPoint
.X() = rOutputRect
.Left() + ( ( rOutputRect
.GetWidth() - rBmpOutputSize
.Width() ) >> 1 );
188 aStartPoint
.Y() = rOutputRect
.Bottom() - rBmpOutputSize
.Height();
194 aStartPoint
.X() = rOutputRect
.Right() - rBmpOutputSize
.Width();
195 aStartPoint
.Y() = rOutputRect
.Bottom() - rBmpOutputSize
.Height();
199 // default linke obere Ecke
201 aStartPoint
= rOutputRect
.TopLeft();
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();
220 long nCount
= nDiffX
/ rBmpOutputSize
.Width() + 1;
222 if ( rBmpOffPerCent
.Height() && ( nCount
& 1L ) )
225 aStartPoint
.X() -= ( nCount
* rBmpOutputSize
.Width() );
230 long nCount
= nDiffY
/ rBmpOutputSize
.Height() + 1;
232 if ( rBmpOffPerCent
.Width() && ( nCount
& 1L ) )
235 aStartPoint
.Y() -= ( nCount
* rBmpOutputSize
.Height() );
239 rStartOffset
= Size( aStartPoint
.X() - rOutputRect
.Left(),
240 aStartPoint
.Y() - rOutputRect
.Top() );
246 rStartOffset
= Size(0, 0);
247 rBmpOutputSize
= rOutputRect
.GetSize();
251 rStartOffset
= Size( ( rOutputRect
.GetWidth() - rBmpOutputSize
.Width() ) >> 1,
252 ( rOutputRect
.GetHeight() - rBmpOutputSize
.Height() ) >> 1 );
257 //////////////////////////////////////////////////////////////////////////////