Skip to content

Commit 93a3541

Browse files
committed
[feat]: fixed toolkit
1 parent 1814b6e commit 93a3541

File tree

2 files changed

+11
-61
lines changed

2 files changed

+11
-61
lines changed

Sources/ScriptToolkit/NSImageExtension.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public extension NSImage {
9393
return finalResult
9494
}
9595

96-
func image(withText text: String, attributes: [NSAttributedString.Key: Any], horizontalPosition: CGFloat, verticalPosition: CGFloat) -> NSImage {
96+
func image(withText text: String, attributes: [NSAttributedString.Key: Any], horizontalTitlePosition: CGFloat, verticalTitlePosition: CGFloat) -> NSImage {
9797
let image = self
9898
let text = text as NSString
9999
let options: NSString.DrawingOptions = [.usesLineFragmentOrigin, .usesFontLeading]
@@ -102,7 +102,7 @@ public extension NSImage {
102102

103103
let x = (image.size.width - textSize.width) / 2
104104
let y = (image.size.height - textSize.height) / 2
105-
let point = NSMakePoint(x * horizontalPosition, y * verticalPosition)
105+
let point = NSMakePoint(x * horizontalTitlePosition, y * verticalTitlePosition)
106106

107107
image.lockFocus()
108108
text.draw(at: point, withAttributes: attributes)
@@ -125,26 +125,29 @@ public extension NSImage {
125125

126126
guard let titleFont = NSFont(name: font, size: size) else { throw ScriptError.argumentError(message: "Unable to find font \(font)") }
127127

128-
var alignmentMode: CATextLayerAlignmentMode
128+
var alignmentMode: NSTextAlignment
129129

130130
switch titleAlignment {
131131
case "left":
132132
alignmentMode = .left
133133

134-
case "center":
135-
alignmentMode = .center
136-
137134
case "right":
138135
alignmentMode = .right
136+
137+
default:
138+
alignmentMode = .center
139139
}
140140

141+
let paragraph = NSMutableParagraphStyle()
142+
paragraph.alignment = alignmentMode
143+
141144
// Solid color text
142145
let fillText = image(
143146
withText: text,
144147
attributes: [
145148
.foregroundColor: fill,
146149
.font: titleFont,
147-
.alignmentMode: alignmentMode
150+
.paragraphStyle: paragraph
148151
],
149152
horizontalTitlePosition: horizontalTitlePosition,
150153
verticalTitlePosition: verticalTitlePosition
@@ -158,7 +161,7 @@ public extension NSImage {
158161
.strokeColor: stroke,
159162
.strokeWidth: strokeWidth * size,
160163
.font: titleFont,
161-
.alignmentMode: alignmentMode
164+
.paragraphStyle: paragraph
162165
],
163166
horizontalTitlePosition: horizontalTitlePosition,
164167
verticalTitlePosition: verticalTitlePosition)

Sources/ScriptToolkit/ScriptToolkit.swift

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -10,59 +10,6 @@ import Files
1010
import SwiftShell
1111
import Moderator
1212

13-
public protocol PrintableError {
14-
var errorDescription: String { get }
15-
}
16-
17-
public enum ScriptError: Error {
18-
case generalError(message: String)
19-
case fileExists(message: String)
20-
case fileNotFound(message: String)
21-
case folderExists(message: String)
22-
case folderNotFound(message: String)
23-
case argumentError(message: String)
24-
case moreInfoNeeded(message: String)
25-
}
26-
27-
extension ScriptError: PrintableError {
28-
public var errorDescription: String {
29-
let prefix = "💥 error: "
30-
var errorDescription = ""
31-
32-
switch self {
33-
case let .generalError(message):
34-
errorDescription = message
35-
36-
case let .fileExists(message):
37-
errorDescription = "file exists: \(message)"
38-
39-
case let .fileNotFound(message):
40-
errorDescription = "file not found: \(message)"
41-
42-
case let .folderExists(message):
43-
errorDescription = "folder exists: \(message)"
44-
45-
case let .folderNotFound(message):
46-
errorDescription = "folder not found: \(message)"
47-
48-
case let .argumentError(message):
49-
errorDescription = "invalid argument: \(message)"
50-
51-
case let .moreInfoNeeded(message):
52-
errorDescription = "more info needed: \(message)"
53-
}
54-
55-
return prefix + errorDescription
56-
}
57-
}
58-
59-
60-
extension ArgumentError: PrintableError {
61-
public var errorDescription: String {
62-
return "💥 error: \(errormessage)"
63-
}
64-
}
65-
6613
public struct ScriptToolkit {
6714

6815
// Setup of absolute paths

0 commit comments

Comments
 (0)