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: salgdi.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_vcl.hxx"
36 #include <tools/svwin.h>
37 #include <wincomp.hxx>
38 #include <saldata.hxx>
40 #include <tools/debug.hxx>
43 #define min(a,b) (((a) < (b)) ? (a) : (b))
46 #define max(a,b) (((a) > (b)) ? (a) : (b))
50 #pragma warning(push, 1)
54 #include <GdiPlusEnums.h>
55 #include <GdiPlusColor.h>
61 #include <basegfx/polygon/b2dpolygon.hxx>
63 // -----------------------------------------------------------------------
65 void impAddB2DPolygonToGDIPlusGraphicsPath(Gdiplus::GraphicsPath
& rPath
, const basegfx::B2DPolygon
& rPolygon
)
67 const sal_uInt32
nCount(rPolygon
.count());
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
));
89 Gdiplus::PointF(Gdiplus::REAL(aCa
.getX()), Gdiplus::REAL(aCa
.getY())),
90 Gdiplus::PointF(Gdiplus::REAL(aCb
.getX()), Gdiplus::REAL(aCb
.getY())),
95 rPath
.AddLine(aFCurr
, aFNext
);
98 if(a
+ 1 < nEdgeCount
)
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
++)
123 aPath
.StartFigure(); // #i101491# not needed for first run
126 impAddB2DPolygonToGDIPlusGraphicsPath(aPath
, rPolyPolygon
.getB2DPolygon(a
));
130 if(getAntiAliasB2DDraw())
132 aGraphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
136 aGraphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
139 aGraphics
.FillPath(&aTestBrush
, &aPath
);
145 bool WinSalGraphics::drawPolyLine(const basegfx::B2DPolygon
& rPolygon
, const basegfx::B2DVector
& rLineWidths
, basegfx::B2DLineJoin eLineJoin
)
147 const sal_uInt32
nCount(rPolygon
.count());
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
;
158 default : // basegfx::B2DLINEJOIN_NONE :
162 case basegfx::B2DLINEJOIN_BEVEL
:
164 aTestPen
.SetLineJoin(Gdiplus::LineJoinBevel
);
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
);
175 case basegfx::B2DLINEJOIN_ROUND
:
177 aTestPen
.SetLineJoin(Gdiplus::LineJoinRound
);
182 impAddB2DPolygonToGDIPlusGraphicsPath(aPath
, rPolygon
);
184 if(rPolygon
.isClosed())
186 // #i101491# needed to create the correct line joins
190 if(getAntiAliasB2DDraw())
192 aGraphics
.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias
);
196 aGraphics
.SetSmoothingMode(Gdiplus::SmoothingModeNone
);
199 aGraphics
.DrawPath(&aTestPen
, &aPath
);
205 // -----------------------------------------------------------------------