19f62ea84SAndrew Rist /**************************************************************
2*1738ad43Smseidel  *
39f62ea84SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
49f62ea84SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
59f62ea84SAndrew Rist  * distributed with this work for additional information
69f62ea84SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
79f62ea84SAndrew Rist  * to you under the Apache License, Version 2.0 (the
89f62ea84SAndrew Rist  * "License"); you may not use this file except in compliance
99f62ea84SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*1738ad43Smseidel  *
119f62ea84SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*1738ad43Smseidel  *
139f62ea84SAndrew Rist  * Unless required by applicable law or agreed to in writing,
149f62ea84SAndrew Rist  * software distributed under the License is distributed on an
159f62ea84SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169f62ea84SAndrew Rist  * KIND, either express or implied.  See the License for the
179f62ea84SAndrew Rist  * specific language governing permissions and limitations
189f62ea84SAndrew Rist  * under the License.
19*1738ad43Smseidel  *
209f62ea84SAndrew Rist  *************************************************************/
219f62ea84SAndrew Rist 
22*1738ad43Smseidel 
23*1738ad43Smseidel 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_vcl.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <stdio.h>
28cdf0e10cSrcweir #include <string.h>
29cdf0e10cSrcweir #include <tools/svwin.h>
30cdf0e10cSrcweir #include <tools/debug.hxx>
31cdf0e10cSrcweir #include <win/wincomp.hxx>
32cdf0e10cSrcweir #include <win/saldata.hxx>
33cdf0e10cSrcweir #include <win/salgdi.h>
345f27b83cSArmin Le Grand #include <win/salbmp.h>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #ifndef min
37cdf0e10cSrcweir #define min(a,b)	(((a) < (b)) ? (a) : (b))
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir #ifndef max
40cdf0e10cSrcweir #define max(a,b)	(((a) > (b)) ? (a) : (b))
41cdf0e10cSrcweir #endif
42cdf0e10cSrcweir 
43cdf0e10cSrcweir #if defined _MSC_VER
44cdf0e10cSrcweir #pragma warning(push, 1)
45cdf0e10cSrcweir #endif
46cdf0e10cSrcweir 
47cdf0e10cSrcweir #include <GdiPlus.h>
48cdf0e10cSrcweir #include <GdiPlusEnums.h>
49cdf0e10cSrcweir #include <GdiPlusColor.h>
50cdf0e10cSrcweir 
51cdf0e10cSrcweir #if defined _MSC_VER
52cdf0e10cSrcweir #pragma warning(pop)
53cdf0e10cSrcweir #endif
54cdf0e10cSrcweir 
55cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
56cdf0e10cSrcweir 
57cdf0e10cSrcweir // -----------------------------------------------------------------------
58cdf0e10cSrcweir 
impAddB2DPolygonToGDIPlusGraphicsPathReal(Gdiplus::GraphicsPath & rPath,const basegfx::B2DPolygon & rPolygon,bool bNoLineJoin)59cdf0e10cSrcweir void impAddB2DPolygonToGDIPlusGraphicsPathReal(Gdiplus::GraphicsPath& rPath, const basegfx::B2DPolygon& rPolygon, bool bNoLineJoin)
60cdf0e10cSrcweir {
61cdf0e10cSrcweir     sal_uInt32 nCount(rPolygon.count());
62cdf0e10cSrcweir 
63cdf0e10cSrcweir     if(nCount)
64cdf0e10cSrcweir     {
65cdf0e10cSrcweir         const sal_uInt32 nEdgeCount(rPolygon.isClosed() ? nCount : nCount - 1);
66cdf0e10cSrcweir         const bool bControls(rPolygon.areControlPointsUsed());
67cdf0e10cSrcweir         basegfx::B2DPoint aCurr(rPolygon.getB2DPoint(0));
68cdf0e10cSrcweir         Gdiplus::PointF aFCurr(Gdiplus::REAL(aCurr.getX()), Gdiplus::REAL(aCurr.getY()));
69cdf0e10cSrcweir 
70cdf0e10cSrcweir         for(sal_uInt32 a(0); a < nEdgeCount; a++)
71cdf0e10cSrcweir         {
72cdf0e10cSrcweir 	        const sal_uInt32 nNextIndex((a + 1) % nCount);
73cdf0e10cSrcweir 	        const basegfx::B2DPoint aNext(rPolygon.getB2DPoint(nNextIndex));
74cdf0e10cSrcweir 	        const Gdiplus::PointF aFNext(Gdiplus::REAL(aNext.getX()), Gdiplus::REAL(aNext.getY()));
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 	        if(bControls && (rPolygon.isNextControlPointUsed(a) || rPolygon.isPrevControlPointUsed(nNextIndex)))
77cdf0e10cSrcweir 	        {
78cdf0e10cSrcweir 		        const basegfx::B2DPoint aCa(rPolygon.getNextControlPoint(a));
79cdf0e10cSrcweir 		        const basegfx::B2DPoint aCb(rPolygon.getPrevControlPoint(nNextIndex));
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 		        rPath.AddBezier(
82*1738ad43Smseidel 			        aFCurr,
83cdf0e10cSrcweir 			        Gdiplus::PointF(Gdiplus::REAL(aCa.getX()), Gdiplus::REAL(aCa.getY())),
84cdf0e10cSrcweir 			        Gdiplus::PointF(Gdiplus::REAL(aCb.getX()), Gdiplus::REAL(aCb.getY())),
85cdf0e10cSrcweir 			        aFNext);
86cdf0e10cSrcweir 	        }
87cdf0e10cSrcweir 	        else
88cdf0e10cSrcweir 	        {
89cdf0e10cSrcweir 		        rPath.AddLine(aFCurr, aFNext);
90cdf0e10cSrcweir 	        }
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 	        if(a + 1 < nEdgeCount)
93cdf0e10cSrcweir 	        {
94cdf0e10cSrcweir 		        aFCurr = aFNext;
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 			    if(bNoLineJoin)
97cdf0e10cSrcweir 			    {
98cdf0e10cSrcweir 				    rPath.StartFigure();
99cdf0e10cSrcweir 			    }
100cdf0e10cSrcweir 	        }
101cdf0e10cSrcweir         }
102cdf0e10cSrcweir     }
103cdf0e10cSrcweir }
104cdf0e10cSrcweir 
impAddB2DPolygonToGDIPlusGraphicsPathInteger(Gdiplus::GraphicsPath & rPath,const basegfx::B2DPolygon & rPolygon,bool bNoLineJoin)105cdf0e10cSrcweir void impAddB2DPolygonToGDIPlusGraphicsPathInteger(Gdiplus::GraphicsPath& rPath, const basegfx::B2DPolygon& rPolygon, bool bNoLineJoin)
106cdf0e10cSrcweir {
107cdf0e10cSrcweir     sal_uInt32 nCount(rPolygon.count());
108cdf0e10cSrcweir 
109cdf0e10cSrcweir     if(nCount)
110cdf0e10cSrcweir     {
111cdf0e10cSrcweir         const sal_uInt32 nEdgeCount(rPolygon.isClosed() ? nCount : nCount - 1);
112cdf0e10cSrcweir         const bool bControls(rPolygon.areControlPointsUsed());
113cdf0e10cSrcweir         basegfx::B2DPoint aCurr(rPolygon.getB2DPoint(0));
114cdf0e10cSrcweir         Gdiplus::Point aICurr(INT(aCurr.getX()), INT(aCurr.getY()));
115cdf0e10cSrcweir 
116cdf0e10cSrcweir         for(sal_uInt32 a(0); a < nEdgeCount; a++)
117cdf0e10cSrcweir         {
118cdf0e10cSrcweir 	        const sal_uInt32 nNextIndex((a + 1) % nCount);
119cdf0e10cSrcweir 	        const basegfx::B2DPoint aNext(rPolygon.getB2DPoint(nNextIndex));
120cdf0e10cSrcweir 	        const Gdiplus::Point aINext(INT(aNext.getX()), INT(aNext.getY()));
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 	        if(bControls && (rPolygon.isNextControlPointUsed(a) || rPolygon.isPrevControlPointUsed(nNextIndex)))
123cdf0e10cSrcweir 	        {
124cdf0e10cSrcweir 		        const basegfx::B2DPoint aCa(rPolygon.getNextControlPoint(a));
125cdf0e10cSrcweir 		        const basegfx::B2DPoint aCb(rPolygon.getPrevControlPoint(nNextIndex));
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 		        rPath.AddBezier(
128*1738ad43Smseidel 			        aICurr,
129cdf0e10cSrcweir 			        Gdiplus::Point(INT(aCa.getX()), INT(aCa.getY())),
130cdf0e10cSrcweir 			        Gdiplus::Point(INT(aCb.getX()), INT(aCb.getY())),
131cdf0e10cSrcweir 			        aINext);
132cdf0e10cSrcweir 	        }
133cdf0e10cSrcweir 	        else
134cdf0e10cSrcweir 	        {
135cdf0e10cSrcweir 		        rPath.AddLine(aICurr, aINext);
136cdf0e10cSrcweir 	        }
137cdf0e10cSrcweir 
138cdf0e10cSrcweir 	        if(a + 1 < nEdgeCount)
139cdf0e10cSrcweir 	        {
140cdf0e10cSrcweir 		        aICurr = aINext;
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 			    if(bNoLineJoin)
143cdf0e10cSrcweir 			    {
144cdf0e10cSrcweir 				    rPath.StartFigure();
145cdf0e10cSrcweir 			    }
146cdf0e10cSrcweir 	        }
147cdf0e10cSrcweir         }
148cdf0e10cSrcweir     }
149cdf0e10cSrcweir }
150cdf0e10cSrcweir 
drawPolyPolygon(const::basegfx::B2DPolyPolygon & rPolyPolygon,double fTransparency)151cdf0e10cSrcweir bool WinSalGraphics::drawPolyPolygon( const ::basegfx::B2DPolyPolygon& rPolyPolygon, double fTransparency)
152cdf0e10cSrcweir {
153cdf0e10cSrcweir 	const sal_uInt32 nCount(rPolyPolygon.count());
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 	if(mbBrush && nCount && (fTransparency >= 0.0 && fTransparency < 1.0))
156cdf0e10cSrcweir 	{
1575f27b83cSArmin Le Grand 		Gdiplus::Graphics aGraphics(getHDC());
158cdf0e10cSrcweir 		const sal_uInt8 aTrans((sal_uInt8)255 - (sal_uInt8)basegfx::fround(fTransparency * 255.0));
159cdf0e10cSrcweir 		Gdiplus::Color aTestColor(aTrans, SALCOLOR_RED(maFillColor), SALCOLOR_GREEN(maFillColor), SALCOLOR_BLUE(maFillColor));
160cdf0e10cSrcweir 		Gdiplus::SolidBrush aTestBrush(aTestColor);
161cdf0e10cSrcweir 		Gdiplus::GraphicsPath aPath;
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 		for(sal_uInt32 a(0); a < nCount; a++)
164cdf0e10cSrcweir 		{
165cdf0e10cSrcweir             if(0 != a)
166cdf0e10cSrcweir             {
167cdf0e10cSrcweir                 aPath.StartFigure(); // #i101491# not needed for first run
168cdf0e10cSrcweir             }
169cdf0e10cSrcweir 
170cdf0e10cSrcweir 			impAddB2DPolygonToGDIPlusGraphicsPathReal(aPath, rPolyPolygon.getB2DPolygon(a), false);
171cdf0e10cSrcweir             aPath.CloseFigure();
172cdf0e10cSrcweir 		}
173cdf0e10cSrcweir 
174cdf0e10cSrcweir         if(getAntiAliasB2DDraw())
175cdf0e10cSrcweir         {
176cdf0e10cSrcweir             aGraphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
177cdf0e10cSrcweir         }
178cdf0e10cSrcweir         else
179cdf0e10cSrcweir         {
180cdf0e10cSrcweir     		aGraphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
181cdf0e10cSrcweir         }
182cdf0e10cSrcweir 
1834aeb9d34SArmin Le Grand         if(mbPrinter)
1844aeb9d34SArmin Le Grand         {
1854aeb9d34SArmin Le Grand             // #121591#
1864aeb9d34SArmin Le Grand             // Normally GdiPlus should not be used for printing at all since printers cannot
1874aeb9d34SArmin Le Grand             // print transparent filled polygon geometry and normally this does not happen
1884aeb9d34SArmin Le Grand             // since OutputDevice::RemoveTransparenciesFromMetaFile is used as preparation
189*1738ad43Smseidel             // and no transparent parts should remain for printing. But this can be overridden
190*1738ad43Smseidel             // by the user and thus happens. This call can only come (currently) from
191*1738ad43Smseidel             // OutputDevice::DrawTransparent, see comments there with the same TaskID.
1924aeb9d34SArmin Le Grand             // If it is used, the mapping for the printer is wrong and needs to be corrected. I
1934aeb9d34SArmin Le Grand             // checked that there is *no* transformation set (testcode commented out below) and
1944aeb9d34SArmin Le Grand             // estimated that a stable factor dependent of the printer's DPI is used. Create
1954aeb9d34SArmin Le Grand             // and set a transformation here to correct this
1964aeb9d34SArmin Le Grand             const Gdiplus::REAL aDpiX(aGraphics.GetDpiX());
1974aeb9d34SArmin Le Grand             const Gdiplus::REAL aDpiY(aGraphics.GetDpiY());
1984aeb9d34SArmin Le Grand 
1994aeb9d34SArmin Le Grand             // test code to check the current transformation at the graphics device
2004aeb9d34SArmin Le Grand             //Gdiplus::Matrix matrix;
2014aeb9d34SArmin Le Grand             //aGraphics.GetTransform(&matrix);
2024aeb9d34SArmin Le Grand             //Gdiplus::REAL elements[6];
2034aeb9d34SArmin Le Grand             //matrix.GetElements(elements);
2044aeb9d34SArmin Le Grand 
2054aeb9d34SArmin Le Grand             Gdiplus::Matrix aPrinterTransform;
2064aeb9d34SArmin Le Grand             aPrinterTransform.Scale(Gdiplus::REAL(100.0) / aDpiX, Gdiplus::REAL(100.0) / aDpiY);
2074aeb9d34SArmin Le Grand             aGraphics.SetTransform(&aPrinterTransform);
2084aeb9d34SArmin Le Grand         }
2094aeb9d34SArmin Le Grand 
210cdf0e10cSrcweir 		aGraphics.FillPath(&aTestBrush, &aPath);
211cdf0e10cSrcweir 	}
212cdf0e10cSrcweir 
213cdf0e10cSrcweir  	return true;
214cdf0e10cSrcweir }
215cdf0e10cSrcweir 
drawPolyLine(const basegfx::B2DPolygon & rPolygon,double fTransparency,const basegfx::B2DVector & rLineWidths,basegfx::B2DLineJoin eLineJoin,com::sun::star::drawing::LineCap eLineCap)216*1738ad43Smseidel bool WinSalGraphics::drawPolyLine(
217*1738ad43Smseidel 	const basegfx::B2DPolygon& rPolygon,
218*1738ad43Smseidel 	double fTransparency,
219*1738ad43Smseidel 	const basegfx::B2DVector& rLineWidths,
220*1738ad43Smseidel 	basegfx::B2DLineJoin eLineJoin,
221*1738ad43Smseidel 	com::sun::star::drawing::LineCap eLineCap)
222cdf0e10cSrcweir {
223*1738ad43Smseidel 	const sal_uInt32 nCount(rPolygon.count());
224cdf0e10cSrcweir 
225cdf0e10cSrcweir 	if(mbPen && nCount)
226cdf0e10cSrcweir 	{
2275f27b83cSArmin Le Grand 		Gdiplus::Graphics aGraphics(getHDC());
228cdf0e10cSrcweir 		const sal_uInt8 aTrans = (sal_uInt8)basegfx::fround( 255 * (1.0 - fTransparency) );
229cdf0e10cSrcweir 		Gdiplus::Color aTestColor(aTrans, SALCOLOR_RED(maLineColor), SALCOLOR_GREEN(maLineColor), SALCOLOR_BLUE(maLineColor));
230cdf0e10cSrcweir 		Gdiplus::Pen aTestPen(aTestColor, Gdiplus::REAL(rLineWidths.getX()));
231cdf0e10cSrcweir 		Gdiplus::GraphicsPath aPath;
232cdf0e10cSrcweir 		bool bNoLineJoin(false);
233cdf0e10cSrcweir 
234cdf0e10cSrcweir 		switch(eLineJoin)
235cdf0e10cSrcweir 		{
236cdf0e10cSrcweir 			default : // basegfx::B2DLINEJOIN_NONE :
237cdf0e10cSrcweir 			{
238cdf0e10cSrcweir 				if(basegfx::fTools::more(rLineWidths.getX(), 0.0))
239cdf0e10cSrcweir 				{
240cdf0e10cSrcweir 					bNoLineJoin = true;
241cdf0e10cSrcweir 				}
242cdf0e10cSrcweir 				break;
243cdf0e10cSrcweir 			}
244cdf0e10cSrcweir 			case basegfx::B2DLINEJOIN_BEVEL :
245cdf0e10cSrcweir 			{
246cdf0e10cSrcweir 				aTestPen.SetLineJoin(Gdiplus::LineJoinBevel);
247cdf0e10cSrcweir 				break;
248cdf0e10cSrcweir 			}
249cdf0e10cSrcweir 			case basegfx::B2DLINEJOIN_MIDDLE :
250cdf0e10cSrcweir 			case basegfx::B2DLINEJOIN_MITER :
251cdf0e10cSrcweir 			{
252cdf0e10cSrcweir 				const Gdiplus::REAL aMiterLimit(15.0);
253cdf0e10cSrcweir 				aTestPen.SetMiterLimit(aMiterLimit);
254cdf0e10cSrcweir 				aTestPen.SetLineJoin(Gdiplus::LineJoinMiter);
255cdf0e10cSrcweir 				break;
256cdf0e10cSrcweir 			}
257cdf0e10cSrcweir 			case basegfx::B2DLINEJOIN_ROUND :
258cdf0e10cSrcweir 			{
259cdf0e10cSrcweir 				aTestPen.SetLineJoin(Gdiplus::LineJoinRound);
260cdf0e10cSrcweir 				break;
261cdf0e10cSrcweir 			}
262cdf0e10cSrcweir 		}
263cdf0e10cSrcweir 
2645aaf853bSArmin Le Grand         switch(eLineCap)
2655aaf853bSArmin Le Grand         {
2665aaf853bSArmin Le Grand             default: /*com::sun::star::drawing::LineCap_BUTT*/
2675aaf853bSArmin Le Grand             {
2685aaf853bSArmin Le Grand                 // nothing to do
2695aaf853bSArmin Le Grand                 break;
2705aaf853bSArmin Le Grand             }
2715aaf853bSArmin Le Grand             case com::sun::star::drawing::LineCap_ROUND:
2725aaf853bSArmin Le Grand             {
2735aaf853bSArmin Le Grand                 aTestPen.SetStartCap(Gdiplus::LineCapRound);
2745aaf853bSArmin Le Grand                 aTestPen.SetEndCap(Gdiplus::LineCapRound);
2755aaf853bSArmin Le Grand                 break;
2765aaf853bSArmin Le Grand             }
2775aaf853bSArmin Le Grand             case com::sun::star::drawing::LineCap_SQUARE:
2785aaf853bSArmin Le Grand             {
2795aaf853bSArmin Le Grand                 aTestPen.SetStartCap(Gdiplus::LineCapSquare);
2805aaf853bSArmin Le Grand                 aTestPen.SetEndCap(Gdiplus::LineCapSquare);
2815aaf853bSArmin Le Grand                 break;
2825aaf853bSArmin Le Grand             }
2835aaf853bSArmin Le Grand         }
2845aaf853bSArmin Le Grand 
285cdf0e10cSrcweir 		if(nCount > 250 && basegfx::fTools::more(rLineWidths.getX(), 1.5))
286cdf0e10cSrcweir         {
287cdf0e10cSrcweir     		impAddB2DPolygonToGDIPlusGraphicsPathInteger(aPath, rPolygon, bNoLineJoin);
288cdf0e10cSrcweir         }
289cdf0e10cSrcweir         else
290cdf0e10cSrcweir         {
291cdf0e10cSrcweir     		impAddB2DPolygonToGDIPlusGraphicsPathReal(aPath, rPolygon, bNoLineJoin);
292cdf0e10cSrcweir         }
293cdf0e10cSrcweir 
294cdf0e10cSrcweir         if(rPolygon.isClosed() && !bNoLineJoin)
295cdf0e10cSrcweir         {
296cdf0e10cSrcweir             // #i101491# needed to create the correct line joins
297cdf0e10cSrcweir             aPath.CloseFigure();
298cdf0e10cSrcweir         }
299*1738ad43Smseidel 
300cdf0e10cSrcweir         if(getAntiAliasB2DDraw())
301cdf0e10cSrcweir         {
302cdf0e10cSrcweir     		aGraphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
303cdf0e10cSrcweir         }
304cdf0e10cSrcweir         else
305cdf0e10cSrcweir         {
306cdf0e10cSrcweir     		aGraphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
307cdf0e10cSrcweir         }
308cdf0e10cSrcweir 
309cdf0e10cSrcweir 		aGraphics.DrawPath(&aTestPen, &aPath);
310cdf0e10cSrcweir 	}
311cdf0e10cSrcweir 
312cdf0e10cSrcweir 	return true;
313cdf0e10cSrcweir }
314cdf0e10cSrcweir 
315cdf0e10cSrcweir // -----------------------------------------------------------------------
3165f27b83cSArmin Le Grand 
paintToGdiPlus(Gdiplus::Graphics & rGraphics,const SalTwoRect & rTR,Gdiplus::Bitmap & rBitmap)3175f27b83cSArmin Le Grand void paintToGdiPlus(
3185f27b83cSArmin Le Grand     Gdiplus::Graphics& rGraphics,
3195f27b83cSArmin Le Grand     const SalTwoRect& rTR,
3205f27b83cSArmin Le Grand     Gdiplus::Bitmap& rBitmap)
3215f27b83cSArmin Le Grand {
3225f27b83cSArmin Le Grand     // only parts of source are used
3235f27b83cSArmin Le Grand     Gdiplus::PointF aDestPoints[3];
3245f27b83cSArmin Le Grand     Gdiplus::ImageAttributes aAttributes;
3255f27b83cSArmin Le Grand 
326*1738ad43Smseidel     // define target region as parallelogram
3275f27b83cSArmin Le Grand     aDestPoints[0].X = Gdiplus::REAL(rTR.mnDestX);
3285f27b83cSArmin Le Grand     aDestPoints[0].Y = Gdiplus::REAL(rTR.mnDestY);
3295f27b83cSArmin Le Grand     aDestPoints[1].X = Gdiplus::REAL(rTR.mnDestX + rTR.mnDestWidth);
3305f27b83cSArmin Le Grand     aDestPoints[1].Y = Gdiplus::REAL(rTR.mnDestY);
3315f27b83cSArmin Le Grand     aDestPoints[2].X = Gdiplus::REAL(rTR.mnDestX);
3325f27b83cSArmin Le Grand     aDestPoints[2].Y = Gdiplus::REAL(rTR.mnDestY + rTR.mnDestHeight);
3335f27b83cSArmin Le Grand 
3345f27b83cSArmin Le Grand     aAttributes.SetWrapMode(Gdiplus::WrapModeTileFlipXY);
3355f27b83cSArmin Le Grand 
3365f27b83cSArmin Le Grand     rGraphics.DrawImage(
337*1738ad43Smseidel         &rBitmap,
3385f27b83cSArmin Le Grand         aDestPoints,
3395f27b83cSArmin Le Grand         3,
3405f27b83cSArmin Le Grand         Gdiplus::REAL(rTR.mnSrcX),
3415f27b83cSArmin Le Grand         Gdiplus::REAL(rTR.mnSrcY),
3425f27b83cSArmin Le Grand         Gdiplus::REAL(rTR.mnSrcWidth),
3435f27b83cSArmin Le Grand         Gdiplus::REAL(rTR.mnSrcHeight),
3445f27b83cSArmin Le Grand         Gdiplus::UnitPixel,
3455f27b83cSArmin Le Grand         &aAttributes,
3465f27b83cSArmin Le Grand         0,
3475f27b83cSArmin Le Grand         0);
3485f27b83cSArmin Le Grand }
3495f27b83cSArmin Le Grand 
3505f27b83cSArmin Le Grand // -----------------------------------------------------------------------
3515f27b83cSArmin Le Grand 
setInterpolationMode(Gdiplus::Graphics & rGraphics,const long & rSrcWidth,const long & rDestWidth,const long & rSrcHeight,const long & rDestHeight)3525f27b83cSArmin Le Grand void setInterpolationMode(
3535f27b83cSArmin Le Grand     Gdiplus::Graphics& rGraphics,
3545f27b83cSArmin Le Grand     const long& rSrcWidth,
3555f27b83cSArmin Le Grand     const long& rDestWidth,
3565f27b83cSArmin Le Grand     const long& rSrcHeight,
3575f27b83cSArmin Le Grand     const long& rDestHeight)
3585f27b83cSArmin Le Grand {
3595f27b83cSArmin Le Grand     const bool bSameWidth(rSrcWidth == rDestWidth);
3605f27b83cSArmin Le Grand     const bool bSameHeight(rSrcHeight == rDestHeight);
3615f27b83cSArmin Le Grand 
3625f27b83cSArmin Le Grand     if(bSameWidth && bSameHeight)
3635f27b83cSArmin Le Grand     {
3645f27b83cSArmin Le Grand         rGraphics.SetInterpolationMode(Gdiplus::InterpolationModeInvalid);
3655f27b83cSArmin Le Grand     }
3665f27b83cSArmin Le Grand     else if(rDestWidth > rSrcWidth && rDestHeight > rSrcHeight)
3675f27b83cSArmin Le Grand     {
3685f27b83cSArmin Le Grand         rGraphics.SetInterpolationMode(Gdiplus::InterpolationModeDefault);
3695f27b83cSArmin Le Grand     }
3705f27b83cSArmin Le Grand     else if(rDestWidth < rSrcWidth && rDestHeight < rSrcHeight)
3715f27b83cSArmin Le Grand     {
3725f27b83cSArmin Le Grand         rGraphics.SetInterpolationMode(Gdiplus::InterpolationModeBicubic);
3735f27b83cSArmin Le Grand     }
3745f27b83cSArmin Le Grand     else
3755f27b83cSArmin Le Grand     {
3765f27b83cSArmin Le Grand         rGraphics.SetInterpolationMode(Gdiplus::InterpolationModeDefault);
3775f27b83cSArmin Le Grand     }
3785f27b83cSArmin Le Grand }
3795f27b83cSArmin Le Grand 
3805f27b83cSArmin Le Grand 
tryDrawBitmapGdiPlus(const SalTwoRect & rTR,const SalBitmap & rSrcBitmap)3815f27b83cSArmin Le Grand bool WinSalGraphics::tryDrawBitmapGdiPlus(const SalTwoRect& rTR, const SalBitmap& rSrcBitmap)
3825f27b83cSArmin Le Grand {
3835f27b83cSArmin Le Grand     if(rTR.mnSrcWidth && rTR.mnSrcHeight && rTR.mnDestWidth && rTR.mnDestHeight)
3845f27b83cSArmin Le Grand     {
3855f27b83cSArmin Le Grand         const WinSalBitmap& rSalBitmap = static_cast< const WinSalBitmap& >(rSrcBitmap);
3865f27b83cSArmin Le Grand         GdiPlusBmpPtr aARGB(rSalBitmap.ImplGetGdiPlusBitmap());
3875f27b83cSArmin Le Grand 
3885f27b83cSArmin Le Grand         if(aARGB.get())
3895f27b83cSArmin Le Grand         {
3905f27b83cSArmin Le Grand             Gdiplus::Graphics aGraphics(getHDC());
3915f27b83cSArmin Le Grand 
3925f27b83cSArmin Le Grand             setInterpolationMode(
393*1738ad43Smseidel                 aGraphics,
3945f27b83cSArmin Le Grand                 rTR.mnSrcWidth,
395*1738ad43Smseidel                 rTR.mnDestWidth,
3965f27b83cSArmin Le Grand                 rTR.mnSrcHeight,
3975f27b83cSArmin Le Grand                 rTR.mnDestHeight);
3985f27b83cSArmin Le Grand 
3995f27b83cSArmin Le Grand             paintToGdiPlus(
400*1738ad43Smseidel                 aGraphics,
401*1738ad43Smseidel                 rTR,
4025f27b83cSArmin Le Grand                 *aARGB.get());
4035f27b83cSArmin Le Grand 
4045f27b83cSArmin Le Grand             return true;
4055f27b83cSArmin Le Grand         }
4065f27b83cSArmin Le Grand     }
4075f27b83cSArmin Le Grand 
4085f27b83cSArmin Le Grand     return false;
4095f27b83cSArmin Le Grand }
4105f27b83cSArmin Le Grand 
drawAlphaBitmap(const SalTwoRect & rTR,const SalBitmap & rSrcBitmap,const SalBitmap & rAlphaBmp)411*1738ad43Smseidel bool WinSalGraphics::drawAlphaBitmap(
4125f27b83cSArmin Le Grand     const SalTwoRect& rTR,
413*1738ad43Smseidel     const SalBitmap& rSrcBitmap,
4145f27b83cSArmin Le Grand     const SalBitmap& rAlphaBmp)
4155f27b83cSArmin Le Grand {
4165f27b83cSArmin Le Grand     if(rTR.mnSrcWidth && rTR.mnSrcHeight && rTR.mnDestWidth && rTR.mnDestHeight)
4175f27b83cSArmin Le Grand     {
4185f27b83cSArmin Le Grand         const WinSalBitmap& rSalBitmap = static_cast< const WinSalBitmap& >(rSrcBitmap);
4195f27b83cSArmin Le Grand         const WinSalBitmap& rSalAlpha = static_cast< const WinSalBitmap& >(rAlphaBmp);
4205f27b83cSArmin Le Grand         GdiPlusBmpPtr aARGB(rSalBitmap.ImplGetGdiPlusBitmap(&rSalAlpha));
4215f27b83cSArmin Le Grand 
4225f27b83cSArmin Le Grand         if(aARGB.get())
4235f27b83cSArmin Le Grand         {
4245f27b83cSArmin Le Grand             Gdiplus::Graphics aGraphics(getHDC());
4255f27b83cSArmin Le Grand 
4265f27b83cSArmin Le Grand             setInterpolationMode(
427*1738ad43Smseidel                 aGraphics,
4285f27b83cSArmin Le Grand                 rTR.mnSrcWidth,
429*1738ad43Smseidel                 rTR.mnDestWidth,
4305f27b83cSArmin Le Grand                 rTR.mnSrcHeight,
4315f27b83cSArmin Le Grand                 rTR.mnDestHeight);
4325f27b83cSArmin Le Grand 
4335f27b83cSArmin Le Grand             paintToGdiPlus(
434*1738ad43Smseidel                 aGraphics,
435*1738ad43Smseidel                 rTR,
4365f27b83cSArmin Le Grand                 *aARGB.get());
4375f27b83cSArmin Le Grand 
4385f27b83cSArmin Le Grand             return true;
4395f27b83cSArmin Le Grand         }
4405f27b83cSArmin Le Grand     }
4415f27b83cSArmin Le Grand 
4425f27b83cSArmin Le Grand     return false;
4435f27b83cSArmin Le Grand }
4445f27b83cSArmin Le Grand 
4455f27b83cSArmin Le Grand // -----------------------------------------------------------------------
4465f27b83cSArmin Le Grand 
drawTransformedBitmap(const basegfx::B2DPoint & rNull,const basegfx::B2DPoint & rX,const basegfx::B2DPoint & rY,const SalBitmap & rSourceBitmap,const SalBitmap * pAlphaBitmap)4475f27b83cSArmin Le Grand bool WinSalGraphics::drawTransformedBitmap(
4485f27b83cSArmin Le Grand     const basegfx::B2DPoint& rNull,
4495f27b83cSArmin Le Grand     const basegfx::B2DPoint& rX,
4505f27b83cSArmin Le Grand     const basegfx::B2DPoint& rY,
4515f27b83cSArmin Le Grand     const SalBitmap& rSourceBitmap,
4525f27b83cSArmin Le Grand     const SalBitmap* pAlphaBitmap)
4535f27b83cSArmin Le Grand {
4545f27b83cSArmin Le Grand     const WinSalBitmap& rSalBitmap = static_cast< const WinSalBitmap& >(rSourceBitmap);
4555f27b83cSArmin Le Grand     const WinSalBitmap* pSalAlpha = static_cast< const WinSalBitmap* >(pAlphaBitmap);
4565f27b83cSArmin Le Grand     GdiPlusBmpPtr aARGB(rSalBitmap.ImplGetGdiPlusBitmap(pSalAlpha));
4575f27b83cSArmin Le Grand 
4585f27b83cSArmin Le Grand     if(aARGB.get())
4595f27b83cSArmin Le Grand     {
4605f27b83cSArmin Le Grand         const long nSrcWidth(aARGB->GetWidth());
4615f27b83cSArmin Le Grand         const long nSrcHeight(aARGB->GetHeight());
4625f27b83cSArmin Le Grand 
4635f27b83cSArmin Le Grand         if(nSrcWidth && nSrcHeight)
4645f27b83cSArmin Le Grand         {
4655f27b83cSArmin Le Grand             const long nDestWidth(basegfx::fround(basegfx::B2DVector(rX - rNull).getLength()));
4665f27b83cSArmin Le Grand             const long nDestHeight(basegfx::fround(basegfx::B2DVector(rY - rNull).getLength()));
4675f27b83cSArmin Le Grand 
4685f27b83cSArmin Le Grand             if(nDestWidth && nDestHeight)
4695f27b83cSArmin Le Grand             {
4705f27b83cSArmin Le Grand                 Gdiplus::Graphics aGraphics(getHDC());
4715f27b83cSArmin Le Grand                 Gdiplus::PointF aDestPoints[3];
4725f27b83cSArmin Le Grand                 Gdiplus::ImageAttributes aAttributes;
4735f27b83cSArmin Le Grand 
4745f27b83cSArmin Le Grand                 setInterpolationMode(
475*1738ad43Smseidel                     aGraphics,
4765f27b83cSArmin Le Grand                     nSrcWidth,
477*1738ad43Smseidel                     nDestWidth,
4785f27b83cSArmin Le Grand                     nSrcHeight,
4795f27b83cSArmin Le Grand                     nDestHeight);
4805f27b83cSArmin Le Grand 
481*1738ad43Smseidel                 // this mode is only capable of drawing the whole bitmap to a parallelogram
4825f27b83cSArmin Le Grand                 aDestPoints[0].X = Gdiplus::REAL(rNull.getX());
4835f27b83cSArmin Le Grand                 aDestPoints[0].Y = Gdiplus::REAL(rNull.getY());
4845f27b83cSArmin Le Grand                 aDestPoints[1].X = Gdiplus::REAL(rX.getX());
4855f27b83cSArmin Le Grand                 aDestPoints[1].Y = Gdiplus::REAL(rX.getY());
4865f27b83cSArmin Le Grand                 aDestPoints[2].X = Gdiplus::REAL(rY.getX());
4875f27b83cSArmin Le Grand                 aDestPoints[2].Y = Gdiplus::REAL(rY.getY());
4885f27b83cSArmin Le Grand 
4895f27b83cSArmin Le Grand                 aAttributes.SetWrapMode(Gdiplus::WrapModeTileFlipXY);
4905f27b83cSArmin Le Grand 
4915f27b83cSArmin Le Grand                 aGraphics.DrawImage(
492*1738ad43Smseidel                     aARGB.get(),
493*1738ad43Smseidel                     aDestPoints,
4945f27b83cSArmin Le Grand                     3,
4955f27b83cSArmin Le Grand                     Gdiplus::REAL(0.0),
4965f27b83cSArmin Le Grand                     Gdiplus::REAL(0.0),
4975f27b83cSArmin Le Grand                     Gdiplus::REAL(nSrcWidth),
4985f27b83cSArmin Le Grand                     Gdiplus::REAL(nSrcHeight),
4995f27b83cSArmin Le Grand                     Gdiplus::UnitPixel,
5005f27b83cSArmin Le Grand                     &aAttributes,
5015f27b83cSArmin Le Grand                     0,
5025f27b83cSArmin Le Grand                     0);
5035f27b83cSArmin Le Grand             }
5045f27b83cSArmin Le Grand         }
5055f27b83cSArmin Le Grand 
5065f27b83cSArmin Le Grand         return true;
5075f27b83cSArmin Le Grand     }
5085f27b83cSArmin Le Grand 
5095f27b83cSArmin Le Grand     return false;
5105f27b83cSArmin Le Grand }
5115f27b83cSArmin Le Grand 
512*1738ad43Smseidel /* vim: set noet sw=4 ts=4: */
513