1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
23 #include <vcl/gdimtf.hxx>
24 #include <vcl/lineinfo.hxx>
25 #include <vcl/metaact.hxx>
26 #include <vcl/outdev.hxx>
27 #include <vcl/virdev.hxx>
31 #include <basegfx/matrix/b2dhommatrix.hxx>
32 #include <basegfx/polygon/b2dpolygontools.hxx>
33 #include <basegfx/polygon/b2dpolypolygontools.hxx>
34 #include <basegfx/polygon/b2dlinegeometry.hxx>
36 void OutputDevice::DrawLine( const Point
& rStartPt
, const Point
& rEndPt
,
37 const LineInfo
& rLineInfo
)
39 assert(!is_double_buffered_window());
41 if ( rLineInfo
.IsDefault() )
43 DrawLine( rStartPt
, rEndPt
);
48 mpMetaFile
->AddAction( new MetaLineAction( rStartPt
, rEndPt
, rLineInfo
) );
50 if ( !IsDeviceOutputNecessary() || !mbLineColor
|| ( LineStyle::NONE
== rLineInfo
.GetStyle() ) || ImplIsRecordLayout() )
53 if( !mpGraphics
&& !AcquireGraphics() )
56 if ( mbInitClipRegion
)
59 if ( mbOutputClipped
)
62 const Point
aStartPt( ImplLogicToDevicePixel( rStartPt
) );
63 const Point
aEndPt( ImplLogicToDevicePixel( rEndPt
) );
64 const LineInfo
aInfo( ImplLogicToDevicePixel( rLineInfo
) );
65 const bool bDashUsed(LineStyle::Dash
== aInfo
.GetStyle());
66 const bool bLineWidthUsed(aInfo
.GetWidth() > 1);
68 if ( mbInitLineColor
)
71 if(bDashUsed
|| bLineWidthUsed
)
73 basegfx::B2DPolygon aLinePolygon
;
74 aLinePolygon
.append(basegfx::B2DPoint(aStartPt
.X(), aStartPt
.Y()));
75 aLinePolygon
.append(basegfx::B2DPoint(aEndPt
.X(), aEndPt
.Y()));
77 drawLine( basegfx::B2DPolyPolygon(aLinePolygon
), aInfo
);
81 mpGraphics
->DrawLine( aStartPt
.X(), aStartPt
.Y(), aEndPt
.X(), aEndPt
.Y(), this );
85 mpAlphaVDev
->DrawLine( rStartPt
, rEndPt
, rLineInfo
);
88 void OutputDevice::DrawLine( const Point
& rStartPt
, const Point
& rEndPt
)
90 assert(!is_double_buffered_window());
93 mpMetaFile
->AddAction( new MetaLineAction( rStartPt
, rEndPt
) );
95 if ( !IsDeviceOutputNecessary() || !mbLineColor
|| ImplIsRecordLayout() )
98 if ( !mpGraphics
&& !AcquireGraphics() )
101 if ( mbInitClipRegion
)
104 if ( mbOutputClipped
)
107 if ( mbInitLineColor
)
110 // #i101598# support AA and snap for lines, too
111 if((mnAntialiasing
& AntialiasingFlags::EnableB2dDraw
)
112 && mpGraphics
->supportsOperation(OutDevSupportType::B2DDraw
)
113 && RasterOp::OverPaint
== GetRasterOp()
116 // at least transform with double precision to device coordinates; this will
117 // avoid pixel snap of single, appended lines
118 const basegfx::B2DHomMatrix
aTransform(ImplGetDeviceTransformation());
119 const basegfx::B2DVector
aB2DLineWidth( 1.0, 1.0 );
120 basegfx::B2DPolygon aB2DPolyLine
;
122 aB2DPolyLine
.append(basegfx::B2DPoint(rStartPt
.X(), rStartPt
.Y()));
123 aB2DPolyLine
.append(basegfx::B2DPoint(rEndPt
.X(), rEndPt
.Y()));
124 aB2DPolyLine
.transform( aTransform
);
126 const bool bPixelSnapHairline(mnAntialiasing
& AntialiasingFlags::PixelSnapHairline
);
128 if( mpGraphics
->DrawPolyLine(
129 basegfx::B2DHomMatrix(),
133 basegfx::B2DLineJoin::NONE
,
134 css::drawing::LineCap_BUTT
,
135 basegfx::deg2rad(15.0), // not used with B2DLineJoin::NONE, but the correct default
143 const Point
aStartPt(ImplLogicToDevicePixel(rStartPt
));
144 const Point
aEndPt(ImplLogicToDevicePixel(rEndPt
));
146 mpGraphics
->DrawLine( aStartPt
.X(), aStartPt
.Y(), aEndPt
.X(), aEndPt
.Y(), this );
149 mpAlphaVDev
->DrawLine( rStartPt
, rEndPt
);
152 void OutputDevice::drawLine( basegfx::B2DPolyPolygon aLinePolyPolygon
, const LineInfo
& rInfo
)
154 const bool bTryAA((mnAntialiasing
& AntialiasingFlags::EnableB2dDraw
)
155 && mpGraphics
->supportsOperation(OutDevSupportType::B2DDraw
)
156 && RasterOp::OverPaint
== GetRasterOp()
158 basegfx::B2DPolyPolygon aFillPolyPolygon
;
159 const bool bDashUsed(LineStyle::Dash
== rInfo
.GetStyle());
160 const bool bLineWidthUsed(rInfo
.GetWidth() > 1);
162 if(bDashUsed
&& aLinePolyPolygon
.count())
164 ::std::vector
< double > fDotDashArray
;
165 const double fDashLen(rInfo
.GetDashLen());
166 const double fDotLen(rInfo
.GetDotLen());
167 const double fDistance(rInfo
.GetDistance());
169 for(sal_uInt16
a(0); a
< rInfo
.GetDashCount(); a
++)
171 fDotDashArray
.push_back(fDashLen
);
172 fDotDashArray
.push_back(fDistance
);
175 for(sal_uInt16
b(0); b
< rInfo
.GetDotCount(); b
++)
177 fDotDashArray
.push_back(fDotLen
);
178 fDotDashArray
.push_back(fDistance
);
181 const double fAccumulated(::std::accumulate(fDotDashArray
.begin(), fDotDashArray
.end(), 0.0));
183 if(fAccumulated
> 0.0)
185 basegfx::B2DPolyPolygon aResult
;
187 for(auto const& rPolygon
: aLinePolyPolygon
)
189 basegfx::B2DPolyPolygon aLineTarget
;
190 basegfx::utils::applyLineDashing(
194 aResult
.append(aLineTarget
);
197 aLinePolyPolygon
= aResult
;
201 if(bLineWidthUsed
&& aLinePolyPolygon
.count())
203 const double fHalfLineWidth((rInfo
.GetWidth() * 0.5) + 0.5);
205 if(aLinePolyPolygon
.areControlPointsUsed())
207 // #i110768# When area geometry has to be created, do not
208 // use the fallback bezier decomposition inside createAreaGeometry,
209 // but one that is at least as good as ImplSubdivideBezier was.
210 // There, Polygon::AdaptiveSubdivide was used with default parameter
211 // 1.0 as quality index.
212 aLinePolyPolygon
= basegfx::utils::adaptiveSubdivideByDistance(aLinePolyPolygon
, 1.0);
215 for(auto const& rPolygon
: aLinePolyPolygon
)
217 aFillPolyPolygon
.append(basegfx::utils::createAreaGeometry(
221 rInfo
.GetLineCap()));
224 aLinePolyPolygon
.clear();
227 GDIMetaFile
* pOldMetaFile
= mpMetaFile
;
228 mpMetaFile
= nullptr;
230 if(aLinePolyPolygon
.count())
232 for(auto const& rB2DPolygon
: aLinePolyPolygon
)
234 const bool bPixelSnapHairline(mnAntialiasing
& AntialiasingFlags::PixelSnapHairline
);
239 bDone
= mpGraphics
->DrawPolyLine(
240 basegfx::B2DHomMatrix(),
243 basegfx::B2DVector(1.0,1.0),
244 basegfx::B2DLineJoin::NONE
,
245 css::drawing::LineCap_BUTT
,
246 basegfx::deg2rad(15.0), // not used with B2DLineJoin::NONE, but the correct default
253 tools::Polygon
aPolygon(rB2DPolygon
);
254 mpGraphics
->DrawPolyLine(
256 reinterpret_cast<SalPoint
*>(aPolygon
.GetPointAry()),
262 if(aFillPolyPolygon
.count())
264 const Color
aOldLineColor( maLineColor
);
265 const Color
aOldFillColor( maFillColor
);
269 SetFillColor( aOldLineColor
);
276 bDone
= mpGraphics
->DrawPolyPolygon(
277 basegfx::B2DHomMatrix(),
285 for(auto const& rB2DPolygon
: aFillPolyPolygon
)
287 tools::Polygon
aPolygon(rB2DPolygon
);
289 // need to subdivide, mpGraphics->DrawPolygon ignores curves
290 aPolygon
.AdaptiveSubdivide(aPolygon
);
291 mpGraphics
->DrawPolygon(aPolygon
.GetSize(), reinterpret_cast<const SalPoint
*>(aPolygon
.GetConstPointAry()), this);
295 SetFillColor( aOldFillColor
);
296 SetLineColor( aOldLineColor
);
299 mpMetaFile
= pOldMetaFile
;
303 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */