/src/libreoffice/include/basegfx/polygon/b2dpolypolygontools.hxx
Line | Count | Source |
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 | | #pragma once |
21 | | |
22 | | #include <com/sun/star/drawing/PointSequenceSequence.hpp> |
23 | | #include <vector> |
24 | | #include <basegfx/basegfxdllapi.h> |
25 | | #include <o3tl/sorted_vector.hxx> |
26 | | |
27 | | namespace com::sun::star::drawing { struct PolyPolygonBezierCoords; } |
28 | | |
29 | | namespace basegfx |
30 | | { |
31 | | class B2DPoint; |
32 | | class B2DPolyPolygon; |
33 | | class B2DRange; |
34 | | class B3DHomMatrix; |
35 | | class B3DPolyPolygon; |
36 | | } |
37 | | |
38 | | namespace basegfx::utils |
39 | | { |
40 | | // B2DPolyPolygon tools |
41 | | |
42 | | // Check and evtl. correct orientations of all contained Polygons so that |
43 | | // the orientations of contained polygons will variate to express areas and |
44 | | // holes |
45 | | BASEGFX_DLLPUBLIC B2DPolyPolygon correctOrientations(const B2DPolyPolygon& rCandidate); |
46 | | |
47 | | // make sure polygon with index 0L is not a hole. This may evtl. change the |
48 | | // sequence of polygons, but allows to use polygon with index 0L to |
49 | | // get the correct normal for the whole polyPolygon |
50 | | BASEGFX_DLLPUBLIC B2DPolyPolygon correctOutmostPolygon(const B2DPolyPolygon& rCandidate); |
51 | | |
52 | | // Subdivide all contained curves. Use distanceBound value if given. |
53 | | BASEGFX_DLLPUBLIC B2DPolyPolygon adaptiveSubdivideByDistance(const B2DPolyPolygon& rCandidate, double fDistanceBound, int nRecurseLimit = 30); |
54 | | |
55 | | // Subdivide all contained curves. Use distanceBound value if given. Else, a convenient one |
56 | | // is created. |
57 | | BASEGFX_DLLPUBLIC B2DPolyPolygon adaptiveSubdivideByAngle(const B2DPolyPolygon& rCandidate, double fAngleBound = 0.0); |
58 | | |
59 | | // isInside test for B2dPoint. On border is not inside as long as not true is given |
60 | | // in bWithBorder flag. It is assumed that the orientations of the given polygon are correct. |
61 | | BASEGFX_DLLPUBLIC bool isInside(const B2DPolyPolygon& rCandidate, const B2DPoint& rPoint, bool bWithBorder = false); |
62 | | |
63 | | // get signed area of polygon |
64 | | BASEGFX_DLLPUBLIC double getSignedArea(const B2DPolyPolygon& rCandidate); |
65 | | |
66 | | // get area of polygon |
67 | | BASEGFX_DLLPUBLIC double getArea(const B2DPolyPolygon& rCandidate); |
68 | | |
69 | | /** Apply given LineDashing to given polyPolygon |
70 | | |
71 | | For a description see applyLineDashing in b2dpolygontoos.hxx |
72 | | */ |
73 | | BASEGFX_DLLPUBLIC void applyLineDashing( |
74 | | const B2DPolyPolygon& rCandidate, |
75 | | const ::std::vector<double>& rDotDashArray, |
76 | | B2DPolyPolygon* pLineTarget, |
77 | | double fFullDashDotLen = 0.0); |
78 | | |
79 | | // test if point is inside epsilon-range around the given PolyPolygon. Can be used |
80 | | // for HitTesting. The epsilon-range is defined to be the tube around the PolyPolygon |
81 | | // with distance fDistance and rounded edges (start and end point). |
82 | | BASEGFX_DLLPUBLIC bool isInEpsilonRange(const B2DPolyPolygon& rCandidate, const B2DPoint& rTestPosition, double fDistance); |
83 | | |
84 | | /** Helper class to transport PointIndices to a PolyPolygon, |
85 | | with an operator< for convenient sorting in a std::set usage |
86 | | */ |
87 | | class SAL_WARN_UNUSED BASEGFX_DLLPUBLIC PointIndex |
88 | | { |
89 | | private: |
90 | | sal_uInt32 mnPolygonIndex; |
91 | | sal_uInt32 mnPointIndex; |
92 | | |
93 | | public: |
94 | | PointIndex(sal_uInt32 nPolygonIndex, sal_uInt32 nPointIndex) |
95 | | : mnPolygonIndex(nPolygonIndex), |
96 | | mnPointIndex(nPointIndex) |
97 | 0 | {} |
98 | | |
99 | 0 | sal_uInt32 getPolygonIndex() const { return mnPolygonIndex; } |
100 | 0 | sal_uInt32 getPointIndex() const { return mnPointIndex; } |
101 | | bool operator<(const PointIndex& rComp) const; |
102 | | }; |
103 | | |
104 | | /** the PointIndexSet itself; it allows to define a 'selection'of |
105 | | points in a tools::PolyPolygon by giving the polygon and point index. |
106 | | Adding points double makes no sense, hence the std::set |
107 | | */ |
108 | | typedef o3tl::sorted_vector< PointIndex > PointIndexSet; |
109 | | |
110 | | /** Read poly-polygon from SVG. |
111 | | |
112 | | This function imports a poly-polygon from an SVG-D |
113 | | attribute. |
114 | | |
115 | | @param o_rPolyPoly |
116 | | The output poly-polygon |
117 | | |
118 | | @param rSvgDAttribute |
119 | | A valid SVG-D attribute string |
120 | | |
121 | | @param bHandleRelativeNextPointCompatible |
122 | | If set to true, the old error that after a relative 'z' command |
123 | | the current point was not reset to the first point of the current |
124 | | polygon is kept; this is needed to read odf files. |
125 | | If false, pure svg is used; this is needed for svg import. |
126 | | |
127 | | @param pHelpPointIndexSet |
128 | | If given, all points created in the target PolyPolygon |
129 | | which are only helper points are added here using their |
130 | | point indices; this are currently points created from |
131 | | import of the 'a' and 'A' svg:d statements which create |
132 | | bezier curve info as representation and maybe points |
133 | | which are no 'real' svg:d points, but helper points. It |
134 | | is necessary to identify these e.g. when markers need to |
135 | | be created in the svg import |
136 | | |
137 | | @return true, if the string was successfully parsed |
138 | | */ |
139 | | BASEGFX_DLLPUBLIC bool importFromSvgD( |
140 | | B2DPolyPolygon& o_rPolyPoly, |
141 | | std::u16string_view rSvgDAttribute, |
142 | | bool bHandleRelativeNextPointCompatible, |
143 | | PointIndexSet* pHelpPointIndexSet); |
144 | | |
145 | | // grow for polyPolygon. Move all geometry in each point in the direction of the normal in that point |
146 | | // with the given amount. Value may be negative. |
147 | | BASEGFX_DLLPUBLIC B2DPolyPolygon growInNormalDirection(const B2DPolyPolygon& rCandidate, double fValue); |
148 | | |
149 | | // force all sub-polygons to a point count of nSegments |
150 | | BASEGFX_DLLPUBLIC B2DPolyPolygon reSegmentPolyPolygon(const B2DPolyPolygon& rCandidate, sal_uInt32 nSegments); |
151 | | |
152 | | // create polygon state at t from 0.0 to 1.0 between the two polygons. Both polygons must have the same |
153 | | // organisation, e.g. same amount of polygons |
154 | | BASEGFX_DLLPUBLIC B2DPolyPolygon interpolate(const B2DPolyPolygon& rOld1, const B2DPolyPolygon& rOld2, double t); |
155 | | |
156 | | // create 3d tools::PolyPolygon from given 2d PolyPolygon. The given fZCoordinate is used to expand the |
157 | | // third coordinate. |
158 | | BASEGFX_DLLPUBLIC B3DPolyPolygon createB3DPolyPolygonFromB2DPolyPolygon(const B2DPolyPolygon& rCandidate, double fZCoordinate = 0.0); |
159 | | |
160 | | // create 2d tools::PolyPolygon from given 3d PolyPolygon. All coordinates are transformed using the given |
161 | | // matrix and the resulting x,y is used to form the new polygon. |
162 | | BASEGFX_DLLPUBLIC B2DPolyPolygon createB2DPolyPolygonFromB3DPolyPolygon(const B3DPolyPolygon& rCandidate, const B3DHomMatrix& rMat); |
163 | | |
164 | | // for each contained edge in each contained polygon calculate the smallest distance. Return the index to the smallest |
165 | | // edge in rEdgeIndex and the index to the polygon in rPolygonIndex. The relative position on the edge is returned in rCut. |
166 | | // If nothing was found (e.g. empty input plygon), DBL_MAX is returned. |
167 | | BASEGFX_DLLPUBLIC double getSmallestDistancePointToPolyPolygon(const B2DPolyPolygon& rCandidate, const B2DPoint& rTestPoint, sal_uInt32& rPolygonIndex, sal_uInt32& rEdgeIndex, double& rCut); |
168 | | |
169 | | // distort PolyPolygon. rOriginal describes the original range, where the given points describe the distorted |
170 | | // corresponding points. |
171 | | BASEGFX_DLLPUBLIC B2DPolyPolygon distort(const B2DPolyPolygon& rCandidate, const B2DRange& rOriginal, const B2DPoint& rTopLeft, const B2DPoint& rTopRight, const B2DPoint& rBottomLeft, const B2DPoint& rBottomRight); |
172 | | |
173 | | // expand all segments (which are not yet) to curve segments. This is done with setting the control |
174 | | // vectors on the 1/3 resp. 2/3 distances on each segment. |
175 | | BASEGFX_DLLPUBLIC B2DPolyPolygon expandToCurve(const B2DPolyPolygon& rCandidate); |
176 | | |
177 | | /** Predicate whether a given poly-polygon is a rectangle. |
178 | | |
179 | | @param rPoly |
180 | | tools::PolyPolygon to check |
181 | | |
182 | | @return true, if the poly-polygon describes a rectangle |
183 | | (contains exactly one polygon, polygon is closed, and the |
184 | | points are either cw or ccw enumerations of a rectangle's |
185 | | vertices). Note that intermediate points and duplicate |
186 | | points are ignored. |
187 | | */ |
188 | | BASEGFX_DLLPUBLIC bool isRectangle( const B2DPolyPolygon& rPoly ); |
189 | | |
190 | | /** Export poly-polygon to SVG. |
191 | | |
192 | | This function exports a poly-polygon into an SVG-D |
193 | | statement. Currently, output of relative point sequences |
194 | | is not yet supported (might cause slightly larger output) |
195 | | |
196 | | @param rPolyPoly |
197 | | The poly-polygon to export |
198 | | |
199 | | @param bUseRelativeCoordinates |
200 | | When true, all coordinate values are exported as relative |
201 | | to the current position. This tends to save some space, |
202 | | since fewer digits needs to be written. |
203 | | |
204 | | @param bDetectQuadraticBeziers |
205 | | When true, the export tries to detect cubic bezier |
206 | | segments in the input polygon, which can be represented by |
207 | | quadratic bezier segments. Note that the generated string |
208 | | causes versions prior to OOo2.0 to crash. |
209 | | |
210 | | @param bHandleRelativeNextPointCompatible |
211 | | If set to true, the old error that after a relative 'z' command |
212 | | the current point was not reset to the first point of the current |
213 | | polygon is kept; this is needed to read odf files. |
214 | | If false, pure svg is used; this is needed for svg import. |
215 | | |
216 | | @param bOOXMLMotionPath |
217 | | If set to true, export string format that is acceptable for |
218 | | for animation motion path for PowerPoint: always space delimited, |
219 | | never neglect command char, always end with E, and do not export |
220 | | H or V. |
221 | | |
222 | | @return the generated SVG-D statement (the XML d attribute |
223 | | value alone, without any "<path ...>" or "d="...") |
224 | | */ |
225 | | BASEGFX_DLLPUBLIC OUString exportToSvgD( |
226 | | const B2DPolyPolygon& rPolyPoly, |
227 | | bool bUseRelativeCoordinates, |
228 | | bool bDetectQuadraticBeziers, |
229 | | bool bHandleRelativeNextPointCompatible, |
230 | | bool bOOXMLMotionPath = false); |
231 | | |
232 | | // #i76891# Try to remove existing curve segments if they are simply edges |
233 | | BASEGFX_DLLPUBLIC B2DPolyPolygon simplifyCurveSegments(const B2DPolyPolygon& rCandidate); |
234 | | |
235 | | /** Creates polypolygon for seven-segment display number |
236 | | |
237 | | This function takes an integer number between 0 and 9 and |
238 | | convert it into the well-known seven-segment display |
239 | | number (like most digital clocks show their numbers). The |
240 | | digit will exactly fit the unit rectangle. The polypolygon |
241 | | will be a line polygon, i.e. if you need the segment parts |
242 | | to have width, use createAreaGeometry() on the result. |
243 | | |
244 | | @param cNumber |
245 | | Number from '0' to '9' as ASCII char, or '-', 'E' and '.' |
246 | | to convert to 7 segment code |
247 | | |
248 | | @param bLitSegments |
249 | | When true, return a polygon containing the segments that |
250 | | are 'lit' for the given number. Return un-lit segments |
251 | | otherwise. |
252 | | */ |
253 | | B2DPolyPolygon createSevenSegmentPolyPolygon(char cNumber, bool bLitSegments); |
254 | | |
255 | | /** snap some polygon coordinates to discrete coordinates |
256 | | |
257 | | This method allows to snap some polygon points to discrete (integer) values |
258 | | which equals e.g. a snap to discrete coordinates. It will snap points of |
259 | | horizontal and vertical edges |
260 | | |
261 | | @param rCandidate |
262 | | The source polygon |
263 | | |
264 | | @return |
265 | | The modified version of the source polygon |
266 | | */ |
267 | | BASEGFX_DLLPUBLIC B2DPolyPolygon snapPointsOfHorizontalOrVerticalEdges(const B2DPolyPolygon& rCandidate); |
268 | | |
269 | | /// converters for css::drawing::PointSequence |
270 | | BASEGFX_DLLPUBLIC B2DPolyPolygon UnoPointSequenceSequenceToB2DPolyPolygon( |
271 | | const css::drawing::PointSequenceSequence& rPointSequenceSequenceSource); |
272 | | BASEGFX_DLLPUBLIC void B2DPolyPolygonToUnoPointSequenceSequence( |
273 | | const B2DPolyPolygon& rPolyPolygon, |
274 | | css::drawing::PointSequenceSequence& rPointSequenceSequenceRetval); |
275 | | |
276 | | /// converters for css::drawing::PolyPolygonBezierCoords (curved polygons) |
277 | | BASEGFX_DLLPUBLIC B2DPolyPolygon UnoPolyPolygonBezierCoordsToB2DPolyPolygon( |
278 | | const css::drawing::PolyPolygonBezierCoords& rPolyPolygonBezierCoordsSource); |
279 | | BASEGFX_DLLPUBLIC void B2DPolyPolygonToUnoPolyPolygonBezierCoords( |
280 | | const B2DPolyPolygon& rPolyPolygon, |
281 | | css::drawing::PolyPolygonBezierCoords& rPolyPolygonBezierCoordsRetval); |
282 | | |
283 | | } // end of namespace basegfx::utils |
284 | | |
285 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |