Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Sources/UFOKit/GLIFPointPen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,29 @@ public class GLIFPointPen: PointPen {
prevOffCurveCount = 0
}

public func closePath() throws {
print ("Close Path")
if let currentContour = currentContour {
if firstSegmentType == .move && lastSegmentType == .offCurve {
throw UFOError.openContourEndsOffCurve
}
let length = currentContour.childCount
guard length != 0,
let first = currentContour.children?[0] as? XMLElement,
let last = currentContour.children? [length - 1] as? XMLElement,
first.name == "point",
last.name == "point",
let connectionType = last.attribute(forName: "type" )
else { throw UFOError.pathTooShort }
first.attribute(forName: "type")?.stringValue = connectionType.stringValue
currentContour.removeChild(at: length - 1)
outlineElement.addChild(currentContour)
} else {
throw UFOError.pathNotBegun
}
currentContour = nil
}

public func endPath() throws {
if let currentContour = currentContour {
if firstSegmentType == .move && lastSegmentType == .offCurve {
Expand Down
1 change: 1 addition & 0 deletions Sources/UFOKit/UFOKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public enum UFOError: Error {
case offCurveNotFollowedByCurve
case tooManyOffCurvesBeforeCurve
case offCurveCannotBeSmooth
case pathTooShort
}

public enum UFOFormatVersion: Int, Codable {
Expand Down