Update ooo320-m1
[ooovba.git] / vcl / win / source / gdi / salgdi_gdiplus.cxx
blob0e91f2e96ae8b21460f43b65ec29d7fb032f2141
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: salgdi.cxx,v $
10 * $Revision: 1.36 $
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_vcl.hxx"
34 #include <stdio.h>
35 #include <string.h>
36 #include <tools/svwin.h>
37 #include <wincomp.hxx>
38 #include <saldata.hxx>
39 #include <salgdi.h>
40 #include <tools/debug.hxx>
42 #ifndef min
43 #define min(a,b) (((a) < (b)) ? (a) : (b))
44 #endif
45 #ifndef max
46 #define max(a,b) (((a) > (b)) ? (a) : (b))
47 #endif
49 #if defined _MSC_VER
50 #pragma warning(push, 1)
51 #endif
53 #include <GdiPlus.h>
54 #include <GdiPlusEnums.h>
55 #include <GdiPlusColor.h>
57 #if defined _MSC_VER
58 #pragma warning(pop)
59 #endif
61 #include <basegfx/polygon/b2dpolygon.hxx>
63 // -----------------------------------------------------------------------
65 void impAddB2DPolygonToGDIPlusGraphicsPath(Gdiplus::GraphicsPath& rPath, const basegfx::B2DPolygon& rPolygon)
67 const sal_uInt32 nCount(rPolygon.count());
69 if(nCount)
71 const sal_uInt32 nEdgeCount(rPolygon.isClosed() ? nCount : nCount - 1);
72 const bool bControls(rPolygon.areControlPointsUsed());
73 basegfx::B2DPoint aCurr(rPolygon.getB2DPoint(0));
74 Gdiplus::PointF aFCurr(Gdiplus::REAL(aCurr.getX()), Gdiplus::REAL(aCurr.getY()));
76 for(sal_uInt32 a(0); a < nEdgeCount; a++)
78 const sal_uInt32 nNextIndex((a + 1) % nCount);
79 const basegfx::B2DPoint aNext(rPolygon.getB2DPoint(nNextIndex));
80 const Gdiplus::PointF aFNext(Gdiplus::REAL(aNext.getX()), Gdiplus::REAL(aNext.getY()));
82 if(bControls && (rPolygon.isNextControlPointUsed(a) || rPolygon.isPrevControlPointUsed(nNextIndex)))
84 const basegfx::B2DPoint aCa(rPolygon.getNextControlPoint(a));
85 const basegfx::B2DPoint aCb(rPolygon.getPrevControlPoint(nNextIndex));
87 rPath.AddBezier(
88 aFCurr,
89 Gdiplus::PointF(Gdiplus::REAL(aCa.getX()), Gdiplus::REAL(aCa.getY())),
90 Gdiplus::PointF(Gdiplus::REAL(aCb.getX()), Gdiplus::REAL(aCb.getY())),
91 aFNext);
93 else
95 rPath.AddLine(aFCurr, aFNext);
98 if(a + 1 < nEdgeCount)
100 aCurr = aNext;
101 aFCurr = aFNext;
107 bool WinSalGraphics::drawPolyPolygon( const ::basegfx::B2DPolyPolygon& rPolyPolygon, double fTransparency)
109 const sal_uInt32 nCount(rPolyPolygon.count());
111 if(mbBrush && nCount && (fTransparency >= 0.0 && fTransparency < 1.0))
113 Gdiplus::Graphics aGraphics(mhDC);
114 const sal_uInt8 aTrans((sal_uInt8)255 - (sal_uInt8)basegfx::fround(fTransparency * 255.0));
115 Gdiplus::Color aTestColor(aTrans, SALCOLOR_RED(maFillColor), SALCOLOR_GREEN(maFillColor), SALCOLOR_BLUE(maFillColor));
116 Gdiplus::SolidBrush aTestBrush(aTestColor);
117 Gdiplus::GraphicsPath aPath;
119 for(sal_uInt32 a(0); a < nCount; a++)
121 if(0 != a)
123 aPath.StartFigure(); // #i101491# not needed for first run
126 impAddB2DPolygonToGDIPlusGraphicsPath(aPath, rPolyPolygon.getB2DPolygon(a));
127 aPath.CloseFigure();
130 if(getAntiAliasB2DDraw())
132 aGraphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
134 else
136 aGraphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
139 aGraphics.FillPath(&aTestBrush, &aPath);
142 return true;
145 bool WinSalGraphics::drawPolyLine(const basegfx::B2DPolygon& rPolygon, const basegfx::B2DVector& rLineWidths, basegfx::B2DLineJoin eLineJoin)
147 const sal_uInt32 nCount(rPolygon.count());
149 if(mbPen && nCount)
151 Gdiplus::Graphics aGraphics(mhDC);
152 Gdiplus::Color aTestColor(255, SALCOLOR_RED(maLineColor), SALCOLOR_GREEN(maLineColor), SALCOLOR_BLUE(maLineColor));
153 Gdiplus::Pen aTestPen(aTestColor, Gdiplus::REAL(rLineWidths.getX()));
154 Gdiplus::GraphicsPath aPath;
156 switch(eLineJoin)
158 default : // basegfx::B2DLINEJOIN_NONE :
160 break;
162 case basegfx::B2DLINEJOIN_BEVEL :
164 aTestPen.SetLineJoin(Gdiplus::LineJoinBevel);
165 break;
167 case basegfx::B2DLINEJOIN_MIDDLE :
168 case basegfx::B2DLINEJOIN_MITER :
170 const Gdiplus::REAL aMiterLimit(15.0);
171 aTestPen.SetMiterLimit(aMiterLimit);
172 aTestPen.SetLineJoin(Gdiplus::LineJoinMiter);
173 break;
175 case basegfx::B2DLINEJOIN_ROUND :
177 aTestPen.SetLineJoin(Gdiplus::LineJoinRound);
178 break;
182 impAddB2DPolygonToGDIPlusGraphicsPath(aPath, rPolygon);
184 if(rPolygon.isClosed())
186 // #i101491# needed to create the correct line joins
187 aPath.CloseFigure();
190 if(getAntiAliasB2DDraw())
192 aGraphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
194 else
196 aGraphics.SetSmoothingMode(Gdiplus::SmoothingModeNone);
199 aGraphics.DrawPath(&aTestPen, &aPath);
202 return true;
205 // -----------------------------------------------------------------------