Inherits from NSObject
Conforms to NSCoding
NSCopying

Overview

The class defining the path object

Properties

closed

Set if the path is closed.

@property (nonatomic) BOOL closed

nodes

An array of GSNode objects.

@property (strong, nonatomic) NSArray *nodes

parent

A pointer to the containing GSLayer object

@property (unsafe_unretained, nonatomic, nullable) GSLayer *parent

segments

Calculates a list of segments

@property (nonatomic, strong) NSArray *segments

Return Value

A NSArray containing NSArrays.

Discussion

This might simplify path operations in some cases

The array contains an array for each segment. The arrays contain 2 or 4 NSValue object. Call [Value pointValue] to the the NSPoint object

Instance Methods

addExtremes:

Adds extremes to the path.

- (void)addExtremes:(BOOL)Force

Parameters

Force

Determines if it adds nodes even if there is not enough space and it would add a bump.

Discussion

If there is a node closed to actual extreme, it will try to move it. If Force is not set, it does not add extremes if there is not enough space

addNode:

Adds the node to the end of the paths array.

- (void)addNode:(GSNode *)Node

Parameters

Node

The node to add.

addNodeFast:

Adds the node without notifying the layer

- (void)addNodeFast:(GSNode *)Node

Parameters

Node

The node to add.

Discussion

You need to make sure that the layer is notified

appendPath:

Adds the nodes from Path to the

- (void)appendPath:(GSPath *)Path

Parameters

Path

The Path to add.

bezierPath

Calculates a bezier path representing the path.

- (NSBezierPath *)bezierPath

Return Value

A NSBezierPath representing the path.

Discussion

This is a bit expensive call so you might cache the result.

is is probably better to get the bezier path from the layer

bounds

Returns the bounding box of the receiver’s path.

- (NSRect)bounds

Return Value

The rectangle that encloses the path of the receiver. If the path contains curve segments, the bounding box encloses the curve but may not enclose the control points used to calculate the curve.

checkConnections

Fixes the connection in all nodes

- (void)checkConnections

cleanUp

Cleans up the Path

- (void)cleanUp

Discussion

Removes empty line segments

Converts flat curves into line

Rounds coordinates to the gridLenth specified in the font

countOfNodes

Returns the count of nodes in the path.

- (NSUInteger)countOfNodes

Return Value

The count of nodes in the path.

direction

The path direction

- (GSPathDirection)direction

Return Value

-1 for counter clock wise and 1 for clock wise

drawInPen:

Draws the path using a pen conforming to the GSPenProtocol

- (void)drawInPen:(NSObject<GSPenProtocol> *)pen

Parameters

pen

A pen conforming to the GSPenProtocol

elementDidChange:

Is called from node objects if it has changed.

- (void)elementDidChange:(GSElement *)Element

Parameters

Element

A GSNode object

Discussion

This triggers the update of the interface

endNode

For open paths, returns the last node of the path, otherwise nil.

- (GSNode *)endNode

fastBounds

Returns the bounding box of the receiver’s path.

- (NSRect)fastBounds

Return Value

The rectangle that encloses the path of the receiver. If the path contains curve segments, the bounding box encloses control points.

Discussion

It only calculates the bounds from the control points. This is usually to big for curves

findStartNode

Finds the Node that is used as start Node

- (GSNode *)findStartNode

glyph

A pointer to the containing GSGlyph object

- (GSGlyph *)glyph

indexOfNode:

Returns the index of the Node in nodes.

- (NSUInteger)indexOfNode:(GSNode *)Node

Parameters

Node

A GSNode object

Return Value

The index of the node in the path.

initWithPathDict:

initializes a path with a dictionary loaded from a pList.

- (instancetype)initWithPathDict:(NSDictionary *)pathDict

Parameters

pathDict

A dictionary

insertNode:atIndex:

Inserts a Node at the Index into nodes.

- (void)insertNode:(GSNode *)Node atIndex:(NSInteger)Index

Parameters

Node

A GSNode object to insert.

Index

The index in the receiver at which to insert the Node. This value must not be greater than the count of nodes in the path.

insertNodeWithPathTime:

Tests if pt lays on the path and than inserts a new point and corrects the handles of the other points to preserve the paths appearance.

- (GSNode *)insertNodeWithPathTime:(CGFloat)PathTime

Parameters

PathTime

the “path time” the integer part is the Index of the next on-curve point. The fractional digits contain the time to the point.

Return Value

If the new point object, or nil if something went wrong.

makeNodeFirst:

Makes the Node the first in the path.

- (void)makeNodeFirst:(GSNode *)Node

Parameters

Node

The node that should be the starting node.

Discussion

It checks if the node is in the path. If not, it makes nothing.

moveWithPoint:

Moves the path by the offset given be Point.

- (void)moveWithPoint:(NSPoint)Point

Parameters

Point

A NSPoint

nearestPointOnPath:pathTime:

gives the nearest Point on the path

- (NSPoint)nearestPointOnPath:(NSPoint)aPoint pathTime:(CGFloat *)PathTime

Parameters

aPoint

the point

PathTime

On return the “path time” on reference. The integer part is the Index of the next on-curve point. The fractional digits contain the time to the point.

Return Value

the Point on the path

nodeAtIndex:

Returns the GSNode located at Index.

- (GSNode *)nodeAtIndex:(NSInteger)Index

Parameters

Index

An index.

Return Value

A GSNode object.

Discussion

The Index is corrected for overflow and underflow. Index = -1 retunes the last node…

pathDict

Returns the content of the path to store in pList.

- (NSDictionary *)pathDict

removeNode:

Removes Node from path.

- (void)removeNode:(GSNode *)Node

Parameters

Node

The node to return from the path.

removeNodeAtIndex:

removes the point at Index from the path.

- (void)removeNodeAtIndex:(NSInteger)Index

Parameters

Index

The index of the node to remove.

removeNodeCheck:

Removes Node.

- (void)removeNodeCheck:(GSNode *)Node

Parameters

Node

The node to return from the path.

Discussion

If Node is a off-curve node, it removes the second off-curve node and sets the segment to LINE.

removeNodeCheckKeepShape:

Removes Node and tries to keep the shape of the path.

- (BOOL)removeNodeCheckKeepShape:(GSNode *)Node

Parameters

Node

The node to return from the path.

Discussion

e.g. If Node is a off-curve node, it removes the second off-curve node and sets the segment to LINE.

reverse

Reverses the path direction

- (void)reverse

setClosePath:

Closes or opens the Path. If necessary it adds or removes points.

- (void)setClosePath:(BOOL)Closed

Parameters

Closed

A BOOL

startNode

For open paths, returns the first node of the path, otherwise nil.

- (GSNode *)startNode

tangentAngleAtNode:direction:

Calculates the angle of the tangent at the given node

- (CGFloat)tangentAngleAtNode:(GSNode *)Node direction:(int)Direction

Parameters

Node

The node where to calculate the angle

Direction

-1 for the angle to the previous node, 1 of the next node

Return Value

the angle in degrees

tangentAngleAtNodeAtIndex:direction:

Calculates the angle of the tangent at the node at the given Index

- (CGFloat)tangentAngleAtNodeAtIndex:(NSInteger)Index direction:(int)Direction

Parameters

Index

The index of the node where to calculate the angle

Direction

-1 for the angle to the previous node, 1 of the next node

Return Value

the angle in degrees

undoManager

Returns the undoManager of the containing glyph.

- (NSUndoManager *)undoManager