fastlane-plugin-wpmreleasetoolkit 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/drawText +1 -0
- data/ext/drawText/drawText Tests/DigitParsingTests.swift +21 -0
- data/ext/drawText/drawText Tests/ExtensionsTests.swift +5 -0
- data/ext/drawText/drawText Tests/Info.plist +22 -0
- data/ext/drawText/drawText Tests/StylesheetTests.swift +31 -0
- data/ext/drawText/drawText Tests/Test Cases/default-stylesheet.txt +10 -0
- data/ext/drawText/drawText Tests/Test Cases/external-styles-sample.css +3 -0
- data/ext/drawText/drawText Tests/Test Cases/external-styles-test.txt +13 -0
- data/ext/drawText/drawText Tests/Test Cases/large-text-block.txt +1 -0
- data/ext/drawText/drawText Tests/Test Cases/regular-text-block.txt +2 -0
- data/ext/drawText/drawText Tests/Test Cases/rtl-text-block.txt +2 -0
- data/ext/drawText/drawText Tests/Test Cases/text-size-adjustment-test.txt +10 -0
- data/ext/drawText/drawText Tests/TextImageTests.swift +99 -0
- data/ext/drawText/drawText Tests/drawText_Tests.swift +14 -0
- data/ext/drawText/drawText.xcodeproj/project.pbxproj +508 -0
- data/ext/drawText/drawText.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- data/ext/drawText/drawText.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- data/ext/drawText/drawText.xcodeproj/xcshareddata/xcschemes/drawText Tests.xcscheme +57 -0
- data/ext/drawText/drawText.xcodeproj/xcshareddata/xcschemes/drawText.xcscheme +109 -0
- data/ext/drawText/drawText/Assets/style.css +1 -0
- data/ext/drawText/drawText/CoreTextStack.swift +113 -0
- data/ext/drawText/drawText/Helpers/CommandLineHelpers.swift +36 -0
- data/ext/drawText/drawText/Helpers/Extensions.swift +27 -0
- data/ext/drawText/drawText/Helpers/FileSystemHelper.swift +24 -0
- data/ext/drawText/drawText/Stylesheet.swift +48 -0
- data/ext/drawText/drawText/TextImage.swift +100 -0
- data/ext/drawText/drawText/main.swift +61 -0
- data/ext/drawText/makefile.example +8 -0
- data/lib/fastlane/plugin/wpmreleasetoolkit/version.rb +1 -1
- metadata +41 -14
@@ -0,0 +1,100 @@
|
|
1
|
+
import Foundation
|
2
|
+
import Cocoa
|
3
|
+
import CoreText
|
4
|
+
|
5
|
+
class TextImage {
|
6
|
+
|
7
|
+
var color = "white"
|
8
|
+
var fontSize = 12 {
|
9
|
+
didSet {
|
10
|
+
stylesheet.fontSize = self.fontSize
|
11
|
+
}
|
12
|
+
}
|
13
|
+
var alignment: NSTextAlignment = .natural
|
14
|
+
|
15
|
+
lazy var stylesheet = Stylesheet(color: self.color, fontSize: self.fontSize)
|
16
|
+
|
17
|
+
internal var html: String = ""
|
18
|
+
|
19
|
+
internal let drawingOptions: NSString.DrawingOptions = [
|
20
|
+
.usesLineFragmentOrigin,
|
21
|
+
.usesFontLeading
|
22
|
+
]
|
23
|
+
|
24
|
+
init(string: String) throws {
|
25
|
+
|
26
|
+
if isValidFilePath(path: string) {
|
27
|
+
html = try contentsOfFile(at: string).trimmingCharacters(in: .whitespacesAndNewlines)
|
28
|
+
}
|
29
|
+
else {
|
30
|
+
html = string
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
func draw(inSize size: CGSize) throws -> CGImage? {
|
35
|
+
let coreTextStack = try CoreTextStack(html: self.getHTMLData(), size: size, alignment: alignment)
|
36
|
+
var fontSize = stylesheet.fontSize
|
37
|
+
|
38
|
+
while(!coreTextStack.fits) {
|
39
|
+
fontSize -= 1
|
40
|
+
coreTextStack.setFontSize(CGFloat(fontSize))
|
41
|
+
}
|
42
|
+
|
43
|
+
return try coreTextStack.draw(inContext: try self.graphicsContext(forSize: size))
|
44
|
+
}
|
45
|
+
|
46
|
+
internal func getHTMLData(withConvertedNewlines: Bool = true) -> Data {
|
47
|
+
let html = withConvertedNewlines ? self.html.withNewlinesConvertedToBreakTags : self.html
|
48
|
+
let fullString = stylesheet.contents + html
|
49
|
+
return fullString.data(using: .utf16)!
|
50
|
+
}
|
51
|
+
|
52
|
+
func isValidFilePath(path: String) -> Bool {
|
53
|
+
return FileManager.default.fileExists(atPath: path)
|
54
|
+
}
|
55
|
+
|
56
|
+
private func contentsOfFile(at path: String) throws -> String {
|
57
|
+
return try String(contentsOfFile: path, encoding: .utf8)
|
58
|
+
}
|
59
|
+
|
60
|
+
private func graphicsContext(forSize size: CGSize) throws -> NSGraphicsContext {
|
61
|
+
|
62
|
+
let canvas = NSBitmapImageRep(
|
63
|
+
bitmapDataPlanes: nil,
|
64
|
+
pixelsWide: Int(size.width),
|
65
|
+
pixelsHigh: Int(size.height),
|
66
|
+
bitsPerSample: 8,
|
67
|
+
samplesPerPixel: 4,
|
68
|
+
hasAlpha: true,
|
69
|
+
isPlanar: false,
|
70
|
+
colorSpaceName: .calibratedRGB,
|
71
|
+
bitmapFormat: .alphaFirst,
|
72
|
+
bytesPerRow: 0,
|
73
|
+
bitsPerPixel: 0
|
74
|
+
)!
|
75
|
+
|
76
|
+
/// Set up the graphics context
|
77
|
+
guard let context = NSGraphicsContext(bitmapImageRep: canvas) else {
|
78
|
+
throw TextImageProcessingError(kind: .unableToInitializeGraphicsContext)
|
79
|
+
}
|
80
|
+
|
81
|
+
return context
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
85
|
+
struct TextImageProcessingError: Error {
|
86
|
+
enum ErrorKind: Int {
|
87
|
+
case unableToInitializeGraphicsContext
|
88
|
+
case unableToDrawImage
|
89
|
+
case unableToReadHTMLString
|
90
|
+
}
|
91
|
+
|
92
|
+
let kind: ErrorKind
|
93
|
+
var localizedDescription: String {
|
94
|
+
switch self.kind {
|
95
|
+
case .unableToInitializeGraphicsContext: return "Unable to initialize graphics context"
|
96
|
+
case .unableToDrawImage: return "Unable to draw image"
|
97
|
+
case .unableToReadHTMLString: return "Unable to read input HTML string. It may not be valid HTML"
|
98
|
+
}
|
99
|
+
}
|
100
|
+
}
|
@@ -0,0 +1,61 @@
|
|
1
|
+
import Foundation
|
2
|
+
import Cocoa
|
3
|
+
|
4
|
+
let args = readCommandLineArguments()
|
5
|
+
|
6
|
+
// Read the HTML string out of the args. This can either be raw HTML, or a path to an HTML file
|
7
|
+
guard let htmlString = args["html"] else {
|
8
|
+
printError("Unable to read HTML string")
|
9
|
+
printUsageAndExit()
|
10
|
+
}
|
11
|
+
|
12
|
+
guard let maxWidthString = args["maxWidth"] else {
|
13
|
+
printError("Missing maxWidth argument")
|
14
|
+
printUsageAndExit()
|
15
|
+
}
|
16
|
+
|
17
|
+
guard let maxHeightString = args["maxHeight"] else {
|
18
|
+
printError("Missing maxHeight argument")
|
19
|
+
printUsageAndExit()
|
20
|
+
}
|
21
|
+
|
22
|
+
guard let maxWidth = Int(maxWidthString) else {
|
23
|
+
printError("maxWidth must be an integer")
|
24
|
+
printUsageAndExit()
|
25
|
+
}
|
26
|
+
|
27
|
+
guard let maxHeight = Int(maxHeightString) else {
|
28
|
+
printError("maxHeight must be an integer")
|
29
|
+
printUsageAndExit()
|
30
|
+
}
|
31
|
+
|
32
|
+
do {
|
33
|
+
let textImage = try TextImage(string: htmlString)
|
34
|
+
|
35
|
+
if let color = args["color"] {
|
36
|
+
textImage.color = color
|
37
|
+
}
|
38
|
+
|
39
|
+
if let fontSize = args["fontSize"]?.digits {
|
40
|
+
textImage.fontSize = fontSize
|
41
|
+
}
|
42
|
+
|
43
|
+
if let alignment = args["alignment"] {
|
44
|
+
textImage.alignment = NSTextAlignment.fromString(alignment)
|
45
|
+
}
|
46
|
+
|
47
|
+
if let stylesheetPath = args["stylesheet"] {
|
48
|
+
textImage.stylesheet.updateWith(filePath: stylesheetPath)
|
49
|
+
}
|
50
|
+
|
51
|
+
let outputPath = args["output"] ?? "output.png"
|
52
|
+
|
53
|
+
let size = CGSize(width: maxWidth, height: maxHeight)
|
54
|
+
let image = try textImage.draw(inSize: size)!
|
55
|
+
|
56
|
+
File.write(image: image, toFileAtPath: outputPath)
|
57
|
+
}
|
58
|
+
catch let err {
|
59
|
+
print(err.localizedDescription)
|
60
|
+
exit(1)
|
61
|
+
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fastlane-plugin-wpmreleasetoolkit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lorenzo Mattei
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-05-
|
11
|
+
date: 2021-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: diffy
|
@@ -196,16 +196,16 @@ dependencies:
|
|
196
196
|
name: bundler
|
197
197
|
requirement: !ruby/object:Gem::Requirement
|
198
198
|
requirements:
|
199
|
-
- - "
|
199
|
+
- - "~>"
|
200
200
|
- !ruby/object:Gem::Version
|
201
|
-
version: '
|
201
|
+
version: '2.0'
|
202
202
|
type: :development
|
203
203
|
prerelease: false
|
204
204
|
version_requirements: !ruby/object:Gem::Requirement
|
205
205
|
requirements:
|
206
|
-
- - "
|
206
|
+
- - "~>"
|
207
207
|
- !ruby/object:Gem::Version
|
208
|
-
version: '
|
208
|
+
version: '2.0'
|
209
209
|
- !ruby/object:Gem::Dependency
|
210
210
|
name: rspec
|
211
211
|
requirement: !ruby/object:Gem::Requirement
|
@@ -238,30 +238,30 @@ dependencies:
|
|
238
238
|
name: rubocop
|
239
239
|
requirement: !ruby/object:Gem::Requirement
|
240
240
|
requirements:
|
241
|
-
- -
|
241
|
+
- - "~>"
|
242
242
|
- !ruby/object:Gem::Version
|
243
|
-
version: '0
|
243
|
+
version: '1.0'
|
244
244
|
type: :development
|
245
245
|
prerelease: false
|
246
246
|
version_requirements: !ruby/object:Gem::Requirement
|
247
247
|
requirements:
|
248
|
-
- -
|
248
|
+
- - "~>"
|
249
249
|
- !ruby/object:Gem::Version
|
250
|
-
version: '0
|
250
|
+
version: '1.0'
|
251
251
|
- !ruby/object:Gem::Dependency
|
252
252
|
name: rubocop-rspec
|
253
253
|
requirement: !ruby/object:Gem::Requirement
|
254
254
|
requirements:
|
255
|
-
- -
|
255
|
+
- - '='
|
256
256
|
- !ruby/object:Gem::Version
|
257
|
-
version:
|
257
|
+
version: 2.3.0
|
258
258
|
type: :development
|
259
259
|
prerelease: false
|
260
260
|
version_requirements: !ruby/object:Gem::Requirement
|
261
261
|
requirements:
|
262
|
-
- -
|
262
|
+
- - '='
|
263
263
|
- !ruby/object:Gem::Version
|
264
|
-
version:
|
264
|
+
version: 2.3.0
|
265
265
|
- !ruby/object:Gem::Dependency
|
266
266
|
name: rubocop-require_tools
|
267
267
|
requirement: !ruby/object:Gem::Requirement
|
@@ -329,7 +329,34 @@ files:
|
|
329
329
|
- LICENSE
|
330
330
|
- README.md
|
331
331
|
- bin/drawText
|
332
|
+
- ext/drawText/drawText Tests/DigitParsingTests.swift
|
333
|
+
- ext/drawText/drawText Tests/ExtensionsTests.swift
|
334
|
+
- ext/drawText/drawText Tests/Info.plist
|
335
|
+
- ext/drawText/drawText Tests/StylesheetTests.swift
|
336
|
+
- ext/drawText/drawText Tests/Test Cases/default-stylesheet.txt
|
337
|
+
- ext/drawText/drawText Tests/Test Cases/external-styles-sample.css
|
338
|
+
- ext/drawText/drawText Tests/Test Cases/external-styles-test.txt
|
339
|
+
- ext/drawText/drawText Tests/Test Cases/large-text-block.txt
|
340
|
+
- ext/drawText/drawText Tests/Test Cases/regular-text-block.txt
|
341
|
+
- ext/drawText/drawText Tests/Test Cases/rtl-text-block.txt
|
342
|
+
- ext/drawText/drawText Tests/Test Cases/text-size-adjustment-test.txt
|
343
|
+
- ext/drawText/drawText Tests/TextImageTests.swift
|
344
|
+
- ext/drawText/drawText Tests/drawText_Tests.swift
|
345
|
+
- ext/drawText/drawText.xcodeproj/project.pbxproj
|
346
|
+
- ext/drawText/drawText.xcodeproj/project.xcworkspace/contents.xcworkspacedata
|
347
|
+
- ext/drawText/drawText.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
|
348
|
+
- ext/drawText/drawText.xcodeproj/xcshareddata/xcschemes/drawText Tests.xcscheme
|
349
|
+
- ext/drawText/drawText.xcodeproj/xcshareddata/xcschemes/drawText.xcscheme
|
350
|
+
- ext/drawText/drawText/Assets/style.css
|
351
|
+
- ext/drawText/drawText/CoreTextStack.swift
|
352
|
+
- ext/drawText/drawText/Helpers/CommandLineHelpers.swift
|
353
|
+
- ext/drawText/drawText/Helpers/Extensions.swift
|
354
|
+
- ext/drawText/drawText/Helpers/FileSystemHelper.swift
|
355
|
+
- ext/drawText/drawText/Stylesheet.swift
|
356
|
+
- ext/drawText/drawText/TextImage.swift
|
357
|
+
- ext/drawText/drawText/main.swift
|
332
358
|
- ext/drawText/extconf.rb
|
359
|
+
- ext/drawText/makefile.example
|
333
360
|
- lib/fastlane/plugin/wpmreleasetoolkit.rb
|
334
361
|
- lib/fastlane/plugin/wpmreleasetoolkit/actions/README.md
|
335
362
|
- lib/fastlane/plugin/wpmreleasetoolkit/actions/android/an_localize_libs_action.rb
|