Skip to content

Commit

Permalink
Prefer using Apple’s API to convert CGPath into NSBezierPath
Browse files Browse the repository at this point in the history
  • Loading branch information
1024jp committed Jul 29, 2023
1 parent 1271413 commit 1801683
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 61 deletions.
4 changes: 0 additions & 4 deletions CotEditor.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@
2A63FBE41D1D90E70081C84E /* ThemeDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A63FBE21D1D90E70081C84E /* ThemeDetailView.swift */; };
2A6416A31D2F9F7200FA9E1A /* LineNumberView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A6416A21D2F9F7200FA9E1A /* LineNumberView.swift */; };
2A6416A41D2F9F7200FA9E1A /* LineNumberView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A6416A21D2F9F7200FA9E1A /* LineNumberView.swift */; };
2A643BB3245172EB00B2AD54 /* NSBezierPathTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A643BB2245172EB00B2AD54 /* NSBezierPathTests.swift */; };
2A64A2362387754000646BE4 /* UserDefaultsObservationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A64A2352387754000646BE4 /* UserDefaultsObservationTests.swift */; };
2A64F2421D256FCB001B229F /* KeyBindingManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A64F2411D256FCB001B229F /* KeyBindingManager.swift */; };
2A64F2431D256FCB001B229F /* KeyBindingManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A64F2411D256FCB001B229F /* KeyBindingManager.swift */; };
Expand Down Expand Up @@ -1075,7 +1074,6 @@
2A63CECA1D0B0E7800ED8186 /* sample.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = sample.html; path = TestFiles/sample.html; sourceTree = "<group>"; };
2A63FBE21D1D90E70081C84E /* ThemeDetailView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ThemeDetailView.swift; sourceTree = "<group>"; };
2A6416A21D2F9F7200FA9E1A /* LineNumberView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LineNumberView.swift; sourceTree = "<group>"; };
2A643BB2245172EB00B2AD54 /* NSBezierPathTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSBezierPathTests.swift; sourceTree = "<group>"; };
2A64A2352387754000646BE4 /* UserDefaultsObservationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDefaultsObservationTests.swift; sourceTree = "<group>"; };
2A64F2411D256FCB001B229F /* KeyBindingManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyBindingManager.swift; sourceTree = "<group>"; };
2A64F2441D259E49001B229F /* SnippetManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SnippetManager.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2303,7 +2301,6 @@
2AF0C1271D3DA6F800B6FCB6 /* FourCharCodeTests.swift */,
2A8E47E6299B2F5C006A40D8 /* NSRangeTests.swift */,
2AEBD259246BB4C200EC97A3 /* NSAttributedStringTests.swift */,
2A643BB2245172EB00B2AD54 /* NSBezierPathTests.swift */,
2A89160B2394B87100AC13EE /* NSLayoutManagerTests.swift */,
);
name = Extensions;
Expand Down Expand Up @@ -3191,7 +3188,6 @@
2A1125C123F180FF006A1DB2 /* LineRangeCacheableTests.swift in Sources */,
2A1893AD1FFF6A0100AD244F /* LineSortTests.swift in Sources */,
2AEBD25A246BB4C200EC97A3 /* NSAttributedStringTests.swift in Sources */,
2A643BB3245172EB00B2AD54 /* NSBezierPathTests.swift in Sources */,
2A89160C2394B87100AC13EE /* NSLayoutManagerTests.swift in Sources */,
2A8E47E7299B2F5C006A40D8 /* NSRangeTests.swift in Sources */,
2A7B279924E435FE00F02304 /* OutlineTests.swift in Sources */,
Expand Down
14 changes: 7 additions & 7 deletions CotEditor/Sources/NSBezierPath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@

import AppKit.NSBezierPath

extension NSBezierPath {
public extension NSBezierPath {

convenience init(path: CGPath, transform: AffineTransform? = nil) {
/// A back deployed version of the NSBezierPath creation from a CGPath.
///
/// - Parameter cgPath: A CGPath to convert to NSBezierPath.
@backDeployed(before: macOS 14)
convenience init(cgPath: CGPath) {

self.init()

path.applyWithBlock { (pointer) in
cgPath.applyWithBlock { (pointer) in
let element = pointer.pointee

switch element.type {
Expand All @@ -58,10 +62,6 @@ extension NSBezierPath {
assertionFailure()
}
}

if let transform {
self.transform(using: transform)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion CotEditor/Sources/NSLayoutManager+InvisibleDrawing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ extension InvisibleDrawing {

let size = CGSize(width: glyphWidth, height: glyphHeight)
let cgPath = invisible.path(in: size, lineWidth: lineWidth, isRTL: isRTL)
path = NSBezierPath(path: cgPath)
path = NSBezierPath(cgPath: cgPath)

if cacheableInvisibles.contains(invisible) {
pathCache[codeUnit] = path
Expand Down
49 changes: 0 additions & 49 deletions Tests/NSBezierPathTests.swift

This file was deleted.

0 comments on commit 1801683

Please sign in to comment.