1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _BGFX_POLYGON_B2DLINEGEOMETRY_HXX
25 #define _BGFX_POLYGON_B2DLINEGEOMETRY_HXX
26 
27 #include <sal/types.h>
28 #include <basegfx/numeric/ftools.hxx>
29 #include <basegfx/polygon/b2dpolypolygon.hxx>
30 #include <basegfx/polygon/b2dpolygon.hxx>
31 #include <com/sun/star/drawing/LineCap.hpp>
32 
33 //////////////////////////////////////////////////////////////////////////////
34 
35 namespace basegfx
36 {
37 	namespace tools
38 	{
39 		/** Create line start/end geometry element, mostly arrows and things like that.
40 
41             @param rCandidate
42             The polygon which needs to get that line ends and needs to have two points
43             at least.
44 
45 		    @param rArrow
46             The line start/end geometry. It is assumed that the tip is pointing
47 		    upwards. Result will be rotated and scaled to fit.
48 
49             @param bStart
50             describes if creation is for start or end of candidate.
51 
52 		    @param fWidth
53             defines the size of the element, it's describing the target width in X
54 		    of the arrow.
55 
56             @param fDockingPosition needs to be in [0.0 ..1.0] range, where 0.0 means
57             that the tip of the arrow will be aligned with the polygon start, 1.0 means
58             the bottom. The default of 0.5 describes a centered arrow.
59 
60             @param pConsumedLength
61             Using this parameter it is possible to get back how much from the candidate
62 		    geometry is overlapped by the created element (consumed).
63 
64             @param fCandidateLength
65             This should contain the length of rCandidate to allow work without
66 		    again calculating the length (which may be expensive with beziers). If 0.0 is
67 		    given, the length is calculated on demand.
68 
69             @return
70             The Line start and end polygon, correctly rotated and scaled
71         */
72 		B2DPolyPolygon createAreaGeometryForLineStartEnd(
73 			const B2DPolygon& rCandidate,
74 			const B2DPolyPolygon& rArrow,
75 			bool bStart,
76 			double fWidth,
77 			double fCandidateLength = 0.0, // 0.0 -> calculate self
78 			double fDockingPosition = 0.5, // 0->top, 1->bottom
79 			double* pConsumedLength = 0L);
80 
81         /** create filled polygon geometry for lines with a line width
82 
83             This method will create bezier based, fillable polygons which
84             will resample the curve if it was extended for the given half
85             line width. It will remove extrema positions from contained
86             bezier segments and get as close as possible and defined by
87             the given parameters to the ideal result.
88 
89             It will check edges for trivial bezier to avoid unnecessary
90             bezier polygons. Care is taken to produce the in-between
91             polygon points (the ones original on the source poygon) since
92             it has showed that without those, the raster converters leave
93             non-filled gaps.
94 
95             @param rCandidate
96             The source polygon defining the hairline polygon path
97 
98             @param fHalfLineWidth
99             The width of the line to one side
100 
101             @param eJoin
102             The LineJoin if the edges meeting in a point do not have a C1
103             or C2 continuity
104 
105             @param eCap
106             The kind of cap, which is added to the line.
107 
108             @param fMaxAllowedAngle
109             Allows to hand over the maximum allowed angle between an edge and
110             it's control vectors. The smaller, the more subdivisions will be
111             needed to create the filled geometry. Allowed range is cropped to
112             [F_PI2 .. 0.01 * F_PI2].
113 
114             @param fMaxPartOfEdge
115             Allows to influence from with relative length of a control vector
116             compared to it's edge a split is forced. The smaller, the more
117             subdivisions will be needed to create the filled geometry. Allowed
118             range is cropped to [1.0 .. 0.01]
119 
120             @praram fMiterMinimumAngle
121             The minimum wanted angle between two edges when edge rounding
122             is using miter. When an edge is smaller than this (tighter)
123             the usual fallback to bevel is used. Allowed range is cropped
124             to [F_PI .. 0.01 * F_PI].
125 
126             @return
127             The PolyPolygon containing the geometry of the extended line by
128             it's line width. Contains bezier segments and edge roundings as
129             needed and defined.
130         */
131         B2DPolyPolygon createAreaGeometry(
132             const B2DPolygon& rCandidate,
133             double fHalfLineWidth,
134             B2DLineJoin eJoin = B2DLINEJOIN_ROUND,
135             com::sun::star::drawing::LineCap eCap = com::sun::star::drawing::LineCap_BUTT,
136             double fMaxAllowedAngle = (12.5 * F_PI180),
137 			double fMaxPartOfEdge = 0.4,
138             double fMiterMinimumAngle = (15.0 * F_PI180));
139 	} // end of namespace tools
140 } // end of namespace basegfx
141 
142 //////////////////////////////////////////////////////////////////////////////
143 
144 #endif /* _BGFX_POLYGON_B2DLINEGEOMETRY_HXX */
145 // eof
146