PDFBezierPath
public class PDFBezierPath : CustomStringConvertible
extension PDFBezierPath: NSCopying
Structure to create a bezier path, similar to UIKit.UIBezierPath
A bezier path consists of a set of elements relative to a reference frame, to produce a path.
When using the close
as the last element, the path will be considered as a shape instead.
Example for a diamond shape:
let size = CGSize(width: 100, height: 100)
let path = PDFBezierPath(ref: CGRect(origin: .zero, size: size))
path.move(to: PDFBezierPathVertex(
position: CGPoint(x: size.width / 2, y: 0),
anchor: .topCenter
))
path.addLine(to: PDFBezierPathVertex(
position: CGPoint(x: size.width, y: size.height / 2),
anchor: .middleRight
))
path.addLine(to: PDFBezierPathVertex(
position: CGPoint(x: size.width / 2, y: size.height),
anchor: .bottomCenter
))
path.addLine(to: PDFBezierPathVertex(
position: CGPoint(x: 0, y: size.height / 2),
anchor: .middleLeft
))
path.close()
The anchor
is used to handle differences between the PDFBezierPath/refFrame
-
Creates a new bezier path with the given reference frame.
When creating a new path, the path cursor is set to the default origin at
(0,0)
.Declaration
Swift
public init(ref: CGRect)
Parameters
ref
Reference frame
-
Moves the path’s current point to the specified location.
This method implicitly ends the current subpath (if any) and sets the current point to the value in the
point
parameter. When ending the previous subpath, this method does not actually close the subpath. Therefore, the first and last points of the previous subpath are not connected to each other.For many path operations, you must call this method before issuing any commands that cause a line or curve segment to be drawn.
Declaration
Swift
public func move(to point: PDFBezierPathVertex)
Parameters
point
A point in the current coordinate system.
-
Appends a straight line to the path.
This method creates a straight line segment starting at the current point and ending at the point specified by the
point
parameter. After adding the line segment, this method updates the current point to the value inpoint
. You must set the path’s current point (using themove(to:)
method or through the previous creation of a line or curve segment) before you call this method. If the path is empty, this method does nothing.Declaration
Swift
public func addLine(to point: PDFBezierPathVertex)
Parameters
point
The destination point of the line segment, specified in the current coordinate system.
-
Appends a cubic Bézier curve to the path.
This method appends a cubic Bézier curve from the current point to the end point specified by the
endPoint
parameter. The two control points define the curvature of the segment. Figure 1 shows an approximation of a cubic Bézier curve given a set of initial points. The exact curvature of the segment involves a complex mathematical relationship between all of the points and is well documented online.You must set the path’s current point (using the
move(to:)
method or through the previous creation of a line or curve segment) before you call this method. If the path is empty, this method does nothing. After adding the curve segment, this method updates the current point to the value inpoint
.Declaration
Swift
public func addCurve(to endPoint: PDFBezierPathVertex, controlPoint1: PDFBezierPathVertex, controlPoint2: PDFBezierPathVertex)
Parameters
endPoint
The end point of the curve.
controlPoint1
The first control point to use when computing the curve.
controlPoint2
The second control point to use when computing the curve.
-
Appends a quadratic Bézier curve to the path.
This method appends a quadratic Bézier curve from the current point to the end point specified by the endPoint parameter. The relationships between the current point, control point, and end point are what defines the actual curve. The exact curvature of the segment involves a complex mathematical relationship between the points and is well documented online.
You must set the path’s current point (using the
move(to:)
method or through the previous creation of a line or curve segment) before you call this method. If the path is empty, this method does nothing. After adding the curve segment, this method updates the current point to the value in point.See
UIBezierPath/addQuadCurve
for more details.Declaration
Swift
public func addQuadCurve(to endPoint: PDFBezierPathVertex, controlPoint: PDFBezierPathVertex)
Parameters
endPoint
The end point of the curve.
controlPoint
The control point of the curve.
-
Appends an arc to the path.
This method adds the specified arc beginning at the current point. The created arc lies on the perimeter of the specified circle. When drawn in the default coordinate system, the start of the circle is at the right end. For example, specifying a start angle of 0 radians, an end angle of π radians, and setting the
clockwise
parameter totrue
draws the bottom half of the circle. However, specifying the same start and end angles but setting theclockwise
parameter set to false draws the top half of the circle. After calling this method, the current point is set to the point on the arc at the end angle of the circle.See
UIBezierPath/addArc
for more details.Declaration
Swift
public func addArc(withCenter center: PDFBezierPathVertex, radius: CGFloat, startAngle: CGFloat, endAngle: CGFloat, clockwise: Bool)
Parameters
center
Specifies the center point of the circle (in the current coordinate system) used to define the arc.
radius
Specifies the radius of the circle used to define the arc.
startAngle
Specifies the starting angle of the arc (measured in radians).
endAngle
Specifies the end angle of the arc (measured in radians).
clockwise
The direction in which to draw the arc.
-
Closes the most recent subpath.
Declaration
Swift
public func close()
-
Converts this path into an
UIBezierPath
/NSBezierPath
As an instance of
PDFBezierPath
uses a reference frame for anchoring coordinates, the given parameterframe
is used as the target frame, for scaling in relative values using each element’s anchorDeclaration
Swift
public func bezierPath(in frame: CGRect) -> BezierPath
Parameters
frame
Target frame for scaling this path
Return Value
UIBezierPath
for iOS orNSBezierPath
for macOS
-
Creates a copy of this path with references to the same vertices
Declaration
Swift
public func copy(with _: NSZone? = nil) -> Any