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 .
22 #include <basegfx/numeric/ftools.hxx>
23 #include <basegfx/polygon/b2dpolypolygon.hxx>
24 #include <basegfx/polygon/b2dpolygon.hxx>
25 #include <com/sun/star/drawing/LineCap.hpp>
26 #include <basegfx/basegfxdllapi.h>
27 #include <basegfx/polygon/b2dpolygontriangulator.hxx>
29 namespace basegfx::utils
31 /** Create line start/end geometry element, mostly arrows and things like that.
34 The polygon which needs to get that line ends and needs to have two points
38 The line start/end geometry. It is assumed that the tip is pointing
39 upwards. Result will be rotated and scaled to fit.
42 describes if creation is for start or end of candidate.
45 defines the size of the element, it's describing the target width in X
48 @param fDockingPosition needs to be in [0.0 ..1.0] range, where 0.0 means
49 that the tip of the arrow will be aligned with the polygon start, 1.0 means
50 the bottom. The default of 0.5 describes a centered arrow.
52 @param pConsumedLength
53 Using this parameter it is possible to get back how much from the candidate
54 geometry is overlapped by the created element (consumed).
56 @param fCandidateLength
57 This should contain the length of rCandidate to allow work without
58 again calculating the length (which may be expensive with beziers). If 0.0 is
59 given, the length is calculated on demand.
62 When it is necessary to count with the thickness of the line, it
63 makes sense to move the start position slightly - so define the shift.
66 The Line start and end polygon, correctly rotated and scaled
68 BASEGFX_DLLPUBLIC B2DPolyPolygon
createAreaGeometryForLineStartEnd(
69 const B2DPolygon
& rCandidate
,
70 const B2DPolyPolygon
& rArrow
,
73 double fCandidateLength
, // 0.0 -> calculate self
74 double fDockingPosition
, // 0->top, 1->bottom
75 double* pConsumedLength
= nullptr,
78 /** create filled polygon geometry for lines with a line width
80 This method will create bezier based, fillable polygons which
81 will resample the curve if it was extended for the given half
82 line width. It will remove extrema positions from contained
83 bezier segments and get as close as possible and defined by
84 the given parameters to the ideal result.
86 It will check edges for trivial bezier to avoid unnecessary
87 bezier polygons. Care is taken to produce the in-between
88 polygon points (the ones original on the source polygon) since
89 it has showed that without those, the raster converters leave
93 The source polygon defining the hairline polygon path
96 The width of the line to one side
99 The LineJoin if the edges meeting in a point do not have a C1
103 The kind of cap, which is added to the line.
105 @param fMaxAllowedAngle
106 Allows to hand over the maximum allowed angle between an edge and
107 it's control vectors. The smaller, the more subdivisions will be
108 needed to create the filled geometry. Allowed range is cropped to
109 [M_PI_2 .. 0.01 * M_PI_2].
111 @param fMaxPartOfEdge
112 Allows to influence from with relative length of a control vector
113 compared to its edge a split is forced. The smaller, the more
114 subdivisions will be needed to create the filled geometry. Allowed
115 range is cropped to [1.0 .. 0.01]
117 @param fMiterMinimumAngle
118 The minimum wanted angle between two edges when edge rounding
119 is using miter. When an edge is smaller than this (tighter)
120 the usual fallback to bevel is used. Allowed range is cropped
121 to [M_PI .. 0.01 * M_PI].
123 Commit 51b5b93092d6231615de470c62494c24e54828a1 needs
124 revert, we need the triangulation for X11 fat line drawing
127 If given, the method will additionally add the created geometry as
131 The tools::PolyPolygon containing the geometry of the extended line by
132 it's line width. Contains bezier segments and edge roundings as
135 BASEGFX_DLLPUBLIC B2DPolyPolygon
createAreaGeometry(
136 const B2DPolygon
& rCandidate
,
137 double fHalfLineWidth
,
139 css::drawing::LineCap eCap
,
140 double fMaxAllowedAngle
= basegfx::deg2rad(12.5),
141 double fMaxPartOfEdge
= 0.4,
142 double fMiterMinimumAngle
= basegfx::deg2rad(15.0),
143 basegfx::triangulator::B2DTriangleVector
* pTriangles
= nullptr);
145 } // end of namespace basegfx::utils
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */