Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <numeric>
21 :
22 : #include <vcl/virdev.hxx>
23 : #include <vcl/outdev.hxx>
24 :
25 : #include <salgdi.hxx>
26 :
27 : #include "outdata.hxx"
28 :
29 : #include <basegfx/matrix/b2dhommatrix.hxx>
30 : #include <basegfx/polygon/b2dpolygontools.hxx>
31 : #include <basegfx/polygon/b2dpolypolygontools.hxx>
32 : #include <basegfx/polygon/b2dlinegeometry.hxx>
33 :
34 428 : void OutputDevice::DrawLine( const Point& rStartPt, const Point& rEndPt,
35 : const LineInfo& rLineInfo )
36 : {
37 :
38 428 : if ( rLineInfo.IsDefault() )
39 : {
40 0 : DrawLine( rStartPt, rEndPt );
41 416 : return;
42 : }
43 :
44 428 : if ( mpMetaFile )
45 416 : mpMetaFile->AddAction( new MetaLineAction( rStartPt, rEndPt, rLineInfo ) );
46 :
47 428 : if ( !IsDeviceOutputNecessary() || !mbLineColor || ( LINE_NONE == rLineInfo.GetStyle() ) || ImplIsRecordLayout() )
48 416 : return;
49 :
50 12 : if( !mpGraphics )
51 : {
52 0 : if ( !AcquireGraphics() )
53 0 : return;
54 : }
55 :
56 12 : if ( mbInitClipRegion )
57 2 : InitClipRegion();
58 :
59 12 : if ( mbOutputClipped )
60 0 : return;
61 :
62 12 : const Point aStartPt( ImplLogicToDevicePixel( rStartPt ) );
63 12 : const Point aEndPt( ImplLogicToDevicePixel( rEndPt ) );
64 12 : const LineInfo aInfo( ImplLogicToDevicePixel( rLineInfo ) );
65 12 : const bool bDashUsed(LINE_DASH == aInfo.GetStyle());
66 12 : const bool bLineWidthUsed(aInfo.GetWidth() > 1);
67 :
68 12 : if ( mbInitLineColor )
69 12 : InitLineColor();
70 :
71 12 : if(bDashUsed || bLineWidthUsed)
72 : {
73 0 : basegfx::B2DPolygon aLinePolygon;
74 0 : aLinePolygon.append(basegfx::B2DPoint(aStartPt.X(), aStartPt.Y()));
75 0 : aLinePolygon.append(basegfx::B2DPoint(aEndPt.X(), aEndPt.Y()));
76 :
77 0 : PaintLineGeometryWithEvtlExpand(aInfo, basegfx::B2DPolyPolygon(aLinePolygon));
78 : }
79 : else
80 : {
81 12 : mpGraphics->DrawLine( aStartPt.X(), aStartPt.Y(), aEndPt.X(), aEndPt.Y(), this );
82 : }
83 :
84 12 : if( mpAlphaVDev )
85 0 : mpAlphaVDev->DrawLine( rStartPt, rEndPt, rLineInfo );
86 : }
87 :
88 3307820 : void OutputDevice::DrawLine( const Point& rStartPt, const Point& rEndPt )
89 : {
90 :
91 3307820 : if ( mpMetaFile )
92 27895 : mpMetaFile->AddAction( new MetaLineAction( rStartPt, rEndPt ) );
93 :
94 3307820 : if ( !IsDeviceOutputNecessary() || !mbLineColor || ImplIsRecordLayout() )
95 48896 : return;
96 :
97 3297542 : if ( !mpGraphics )
98 : {
99 1328 : if ( !AcquireGraphics() )
100 0 : return;
101 : }
102 :
103 3297542 : if ( mbInitClipRegion )
104 94406 : InitClipRegion();
105 :
106 3297542 : if ( mbOutputClipped )
107 28340 : return;
108 :
109 3269202 : if ( mbInitLineColor )
110 772675 : InitLineColor();
111 :
112 : // #i101598# support AA and snap for lines, too
113 6538404 : if((mnAntialiasing & ANTIALIASING_ENABLE_B2DDRAW)
114 0 : && mpGraphics->supportsOperation(OutDevSupport_B2DDraw)
115 0 : && ROP_OVERPAINT == GetRasterOp()
116 3269202 : && IsLineColor())
117 : {
118 : // at least transform with double precision to device coordinates; this will
119 : // avoid pixel snap of single, appended lines
120 0 : const basegfx::B2DHomMatrix aTransform(ImplGetDeviceTransformation());
121 0 : const basegfx::B2DVector aB2DLineWidth( 1.0, 1.0 );
122 0 : basegfx::B2DPolygon aB2DPolyLine;
123 :
124 0 : aB2DPolyLine.append(basegfx::B2DPoint(rStartPt.X(), rStartPt.Y()));
125 0 : aB2DPolyLine.append(basegfx::B2DPoint(rEndPt.X(), rEndPt.Y()));
126 0 : aB2DPolyLine.transform( aTransform );
127 :
128 0 : if(mnAntialiasing & ANTIALIASING_PIXELSNAPHAIRLINE)
129 : {
130 0 : aB2DPolyLine = basegfx::tools::snapPointsOfHorizontalOrVerticalEdges(aB2DPolyLine);
131 : }
132 :
133 0 : if( mpGraphics->DrawPolyLine( aB2DPolyLine, 0.0, aB2DLineWidth, basegfx::B2DLINEJOIN_NONE, css::drawing::LineCap_BUTT, this))
134 : {
135 0 : return;
136 0 : }
137 : }
138 :
139 3269202 : const Point aStartPt(ImplLogicToDevicePixel(rStartPt));
140 3269202 : const Point aEndPt(ImplLogicToDevicePixel(rEndPt));
141 :
142 3269202 : mpGraphics->DrawLine( aStartPt.X(), aStartPt.Y(), aEndPt.X(), aEndPt.Y(), this );
143 :
144 3269202 : if( mpAlphaVDev )
145 27475 : mpAlphaVDev->DrawLine( rStartPt, rEndPt );
146 : }
147 :
148 38 : void OutputDevice::PaintLineGeometryWithEvtlExpand(
149 : const LineInfo& rInfo,
150 : basegfx::B2DPolyPolygon aLinePolyPolygon)
151 : {
152 38 : const bool bTryAA((mnAntialiasing & ANTIALIASING_ENABLE_B2DDRAW)
153 0 : && mpGraphics->supportsOperation(OutDevSupport_B2DDraw)
154 0 : && ROP_OVERPAINT == GetRasterOp()
155 38 : && IsLineColor());
156 38 : basegfx::B2DPolyPolygon aFillPolyPolygon;
157 38 : const bool bDashUsed(LINE_DASH == rInfo.GetStyle());
158 38 : const bool bLineWidthUsed(rInfo.GetWidth() > 1);
159 :
160 38 : if(bDashUsed && aLinePolyPolygon.count())
161 : {
162 18 : ::std::vector< double > fDotDashArray;
163 18 : const double fDashLen(rInfo.GetDashLen());
164 18 : const double fDotLen(rInfo.GetDotLen());
165 18 : const double fDistance(rInfo.GetDistance());
166 :
167 18 : for(sal_uInt16 a(0); a < rInfo.GetDashCount(); a++)
168 : {
169 0 : fDotDashArray.push_back(fDashLen);
170 0 : fDotDashArray.push_back(fDistance);
171 : }
172 :
173 36 : for(sal_uInt16 b(0); b < rInfo.GetDotCount(); b++)
174 : {
175 18 : fDotDashArray.push_back(fDotLen);
176 18 : fDotDashArray.push_back(fDistance);
177 : }
178 :
179 18 : const double fAccumulated(::std::accumulate(fDotDashArray.begin(), fDotDashArray.end(), 0.0));
180 :
181 18 : if(fAccumulated > 0.0)
182 : {
183 18 : basegfx::B2DPolyPolygon aResult;
184 :
185 36 : for(sal_uInt32 c(0); c < aLinePolyPolygon.count(); c++)
186 : {
187 18 : basegfx::B2DPolyPolygon aLineTraget;
188 : basegfx::tools::applyLineDashing(
189 : aLinePolyPolygon.getB2DPolygon(c),
190 : fDotDashArray,
191 18 : &aLineTraget);
192 18 : aResult.append(aLineTraget);
193 18 : }
194 :
195 18 : aLinePolyPolygon = aResult;
196 18 : }
197 : }
198 :
199 38 : if(bLineWidthUsed && aLinePolyPolygon.count())
200 : {
201 20 : const double fHalfLineWidth((rInfo.GetWidth() * 0.5) + 0.5);
202 :
203 20 : if(aLinePolyPolygon.areControlPointsUsed())
204 : {
205 : // #i110768# When area geometry has to be created, do not
206 : // use the fallback bezier decomposition inside createAreaGeometry,
207 : // but one that is at least as good as ImplSubdivideBezier was.
208 : // There, Polygon::AdaptiveSubdivide was used with default parameter
209 : // 1.0 as quality index.
210 0 : aLinePolyPolygon = basegfx::tools::adaptiveSubdivideByDistance(aLinePolyPolygon, 1.0);
211 : }
212 :
213 40 : for(sal_uInt32 a(0); a < aLinePolyPolygon.count(); a++)
214 : {
215 : aFillPolyPolygon.append(basegfx::tools::createAreaGeometry(
216 : aLinePolyPolygon.getB2DPolygon(a),
217 : fHalfLineWidth,
218 : rInfo.GetLineJoin(),
219 20 : rInfo.GetLineCap()));
220 : }
221 :
222 20 : aLinePolyPolygon.clear();
223 : }
224 :
225 38 : GDIMetaFile* pOldMetaFile = mpMetaFile;
226 38 : mpMetaFile = NULL;
227 :
228 38 : if(aLinePolyPolygon.count())
229 : {
230 2556 : for(sal_uInt32 a(0); a < aLinePolyPolygon.count(); a++)
231 : {
232 2538 : const basegfx::B2DPolygon aCandidate(aLinePolyPolygon.getB2DPolygon(a));
233 2538 : bool bDone(false);
234 :
235 2538 : if(bTryAA)
236 : {
237 0 : bDone = mpGraphics->DrawPolyLine( aCandidate, 0.0, basegfx::B2DVector(1.0,1.0), basegfx::B2DLINEJOIN_NONE, css::drawing::LineCap_BUTT, this);
238 : }
239 :
240 2538 : if(!bDone)
241 : {
242 2538 : const Polygon aPolygon(aCandidate);
243 2538 : mpGraphics->DrawPolyLine(aPolygon.GetSize(), (const SalPoint*)aPolygon.GetConstPointAry(), this);
244 : }
245 2538 : }
246 : }
247 :
248 38 : if(aFillPolyPolygon.count())
249 : {
250 20 : const Color aOldLineColor( maLineColor );
251 20 : const Color aOldFillColor( maFillColor );
252 :
253 20 : SetLineColor();
254 20 : InitLineColor();
255 20 : SetFillColor( aOldLineColor );
256 20 : InitFillColor();
257 :
258 20 : bool bDone(false);
259 :
260 20 : if(bTryAA)
261 : {
262 0 : bDone = mpGraphics->DrawPolyPolygon(aFillPolyPolygon, 0.0, this);
263 : }
264 :
265 20 : if(!bDone)
266 : {
267 318 : for(sal_uInt32 a(0); a < aFillPolyPolygon.count(); a++)
268 : {
269 298 : Polygon aPolygon(aFillPolyPolygon.getB2DPolygon(a));
270 :
271 : // need to subdivide, mpGraphics->DrawPolygon ignores curves
272 298 : aPolygon.AdaptiveSubdivide(aPolygon);
273 298 : mpGraphics->DrawPolygon(aPolygon.GetSize(), (const SalPoint*)aPolygon.GetConstPointAry(), this);
274 298 : }
275 : }
276 :
277 20 : SetFillColor( aOldFillColor );
278 20 : SetLineColor( aOldLineColor );
279 : }
280 :
281 38 : mpMetaFile = pOldMetaFile;
282 1271 : }
283 :
284 :
285 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|