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