Skip to content

Free fork of NotProton: Windows Steam games in Mac Steam, on CodeWeavers' Wine and Apple's Game Porting Toolkit

fix(app): build the Bridgeplay icon and ship licence texts in the bundle

raymondchinsb8e76c8072e1
diff --git a/LICENSE.dobby b/LICENSE.dobby
new file mode 100644
index 0000000..f49a4e1
--- /dev/null
+++ b/LICENSE.dobby
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
\ No newline at end of file
diff --git a/LICENSE.sparkle b/LICENSE.sparkle
new file mode 100644
index 0000000..abe6e04
--- /dev/null
+++ b/LICENSE.sparkle
@@ -0,0 +1,134 @@
+Copyright (c) 2006-2013 Andy Matuschak.
+Copyright (c) 2009-2013 Elgato Systems GmbH.
+Copyright (c) 2011-2014 Kornel Lesiński.
+Copyright (c) 2015-2017 Mayur Pawashe.
+Copyright (c) 2014 C.W. Betts.
+Copyright (c) 2014 Petroules Corporation.
+Copyright (c) 2014 Big Nerd Ranch.
+All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+=================
+EXTERNAL LICENSES
+=================
+
+bspatch.c and bsdiff.c, from bsdiff 4.3 <http://www.daemonology.net/bsdiff/>:
+
+Copyright 2003-2005 Colin Percival
+All rights reserved
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted providing that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+
+--
+
+sais.c and sais.h, from sais-lite (2010/08/07) <https://sites.google.com/site/yuta256/sais>:
+
+The sais-lite copyright is as follows:
+
+Copyright (c) 2008-2010 Yuta Mori All Rights Reserved.
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+--
+
+Portable C implementation of Ed25519, from https://github.com/orlp/ed25519
+
+Copyright (c) 2015 Orson Peters <[email protected]>
+
+This software is provided 'as-is', without any express or implied warranty. In no event will the
+authors be held liable for any damages arising from the use of this software.
+
+Permission is granted to anyone to use this software for any purpose, including commercial
+applications, and to alter it and redistribute it freely, subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must not claim that you wrote the
+ original software. If you use this software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+2. Altered source versions must be plainly marked as such, and must not be misrepresented as
+ being the original software.
+
+3. This notice may not be removed or altered from any source distribution.
+
+--
+
+SUSignatureVerifier.m:
+
+Copyright (c) 2011 Mark Hamlin.
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted providing that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
diff --git a/Makefile b/Makefile
index d8cf057..1ede76b 100644
--- a/Makefile
+++ b/Makefile
@@ -719,25 +719,33 @@ APP_BUILD := $(shell echo '$(APP_VERSION)' | sed -E 's/^([0-9.]+)-.*-ray\.([0-9]
APP_SIGN_ID ?= -
-ICONGEN := $(OUT_DIR)/icongen
-ICON_DOC := $(OUT_DIR)/NotProton.icon
-ICON_DIR := $(OUT_DIR)/icon
-ICON_CAR := $(ICON_DIR)/Assets.car
+# The icon name must match CFBundleIconFile/CFBundleIconName in app/Info.plist.
+ICON_NAME := Bridgeplay
+ICON_MARK := helpers/icon/bridgeplay-mark.svg
+ICONGEN := $(OUT_DIR)/icongen
+ICON_DOC := $(OUT_DIR)/$(ICON_NAME).icon
+ICON_DIR := $(OUT_DIR)/icon
+ICON_CAR := $(ICON_DIR)/Assets.car
+
+# Licence texts copied into Contents/Resources: GPL-3.0, NOTICE and every
+# third-party licence the bundle needs (LICENSE.dobby, LICENSE.sparkle, ...).
+APP_LICENSES := LICENSE $(sort $(wildcard LICENSE.*)) NOTICE
icon: $(ICON_CAR)
-$(ICONGEN): helpers/icon.swift
+$(ICONGEN): helpers/icon/icongen.swift
@mkdir -p $(OUT_DIR)
swiftc -O -o $@ $<
@echo "==> Built $@"
-$(ICON_CAR): $(ICONGEN)
+$(ICON_CAR): $(ICONGEN) $(ICON_MARK)
rm -rf "$(ICON_DOC)" "$(ICON_DIR)"
- $(ICONGEN) "$(ICON_DOC)"
+ $(ICONGEN) "$(ICON_MARK)" "$(ICON_DOC)"
@mkdir -p "$(ICON_DIR)"
xcrun actool "$(ICON_DOC)" --compile "$(ICON_DIR)" --platform macosx \
- --minimum-deployment-target 15.0 --app-icon NotProton \
+ --minimum-deployment-target 15.0 --app-icon $(ICON_NAME) \
--output-partial-info-plist "$(ICON_DIR)/partial.plist" >/dev/null
+ @test -s "$(ICON_DIR)/$(ICON_NAME).icns" || { echo "actool wrote no $(ICON_NAME).icns" >&2; exit 1; }
@echo "==> Built $@"
app: app-payload $(ICON_CAR)
@@ -763,8 +771,9 @@ app: app-payload $(ICON_CAR)
"$(APP_BUNDLE)/Contents/Resources/"
cp -R "$(APP_BUNDLE)/Contents/Resources/NotProtonApp_NotProtonApp.bundle/Contents/Resources/"*.lproj \
"$(APP_BUNDLE)/Contents/Resources/"
- cp "$(ICON_DIR)/Assets.car" "$(ICON_DIR)/NotProton.icns" \
+ cp "$(ICON_DIR)/Assets.car" "$(ICON_DIR)/$(ICON_NAME).icns" \
"$(APP_BUNDLE)/Contents/Resources/"
+ cp $(APP_LICENSES) "$(APP_BUNDLE)/Contents/Resources/"
@missing=$$(cd "$(APP_PAYLOAD)" && find . -type f ! -name '.DS_Store' | sed 's|^\./||' \
| while read -r rel; do \
[ -s "$(CURDIR)/$(APP_BUNDLE_PAYLOAD)/$$rel" ] || echo "$$rel"; \
diff --git a/helpers/icon.swift b/helpers/icon.swift
deleted file mode 100644
index f66967f..0000000
--- a/helpers/icon.swift
+++ /dev/null
@@ -1,265 +0,0 @@
-import CoreGraphics
-import Foundation
-import ImageIO
-import UniformTypeIdentifiers
-
-let canvas: CGFloat = 1024
-let center = CGPoint(x: canvas / 2, y: canvas / 2)
-let space = CGColorSpace(name: CGColorSpace.sRGB)!
-let white = CGColor(red: 1, green: 1, blue: 1, alpha: 1)
-let coverage: CGFloat = 0.90
-
-let orbitRadiusX: CGFloat = 492
-let orbitRadiusY: CGFloat = 95
-let strokeWidth: CGFloat = 38
-let knockoutGap: CGFloat = 22
-let ringOuterRadius: CGFloat = 219
-let ringBand: CGFloat = 48
-let coreRadius: CGFloat = 137
-let orbitAngle: CGFloat = -21
-let orbitShiftY: CGFloat = -44
-
-enum Element: String, CaseIterable {
- case orbitBack = "Orbit Back"
- case sphereRing = "Sphere Ring"
- case sphereCore = "Sphere Core"
- case orbitFront = "Orbit Front"
-
- var fileName: String {
- rawValue.lowercased().replacingOccurrences(of: " ", with: "-") + ".png"
- }
-
- var depth: Double {
- switch self {
- case .orbitBack: 0.40
- case .sphereRing: 0.70
- case .sphereCore: 0.90
- case .orbitFront: 1.00
- }
- }
-
- var translucency: Double {
- switch self {
- case .orbitBack: 0.30
- case .sphereRing: 0.35
- case .sphereCore: 0.50
- case .orbitFront: 0.30
- }
- }
-}
-
-func makeContext(size: CGFloat) -> CGContext {
- let context = CGContext(
- data: nil,
- width: Int(size),
- height: Int(size),
- bitsPerComponent: 8,
- bytesPerRow: 0,
- space: space,
- bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue
- )!
- context.setAllowsAntialiasing(true)
- context.interpolationQuality = .high
- return context
-}
-
-func circle(_ radius: CGFloat) -> CGRect {
- CGRect(
- x: center.x - radius,
- y: center.y - radius,
- width: radius * 2,
- height: radius * 2
- )
-}
-
-func orbitFrame() -> CGAffineTransform {
- CGAffineTransform(translationX: center.x, y: center.y + orbitShiftY)
- .rotated(by: orbitAngle * .pi / 180)
-}
-
-func orbitPath() -> CGPath {
- var transform = orbitFrame()
- let box = CGRect(
- x: -orbitRadiusX,
- y: -orbitRadiusY,
- width: orbitRadiusX * 2,
- height: orbitRadiusY * 2
- )
- return CGPath(ellipseIn: box, transform: &transform)
-}
-
-func halfPlane(front: Bool) -> CGPath {
- let big = canvas * 2
- let overlap: CGFloat = 6
- let rect = front
- ? CGRect(x: -big, y: -big, width: big * 2, height: big + overlap)
- : CGRect(x: -big, y: -overlap, width: big * 2, height: big + overlap)
- var transform = orbitFrame()
- return CGPath(rect: rect, transform: &transform)
-}
-
-func strokeHalf(front: Bool, into context: CGContext) {
- context.saveGState()
- context.addPath(halfPlane(front: front))
- context.clip()
- context.setLineWidth(strokeWidth)
- context.addPath(orbitPath())
- context.strokePath()
- context.restoreGState()
-}
-
-func cutNearHalf(from context: CGContext) {
- context.saveGState()
- context.addPath(halfPlane(front: true))
- context.clip()
- context.setBlendMode(.clear)
- context.setLineWidth(strokeWidth + knockoutGap * 2)
- context.addPath(orbitPath())
- context.strokePath()
- context.restoreGState()
-}
-
-func draw(_ element: Element, into context: CGContext) {
- context.setStrokeColor(white)
- context.setFillColor(white)
-
- switch element {
- case .orbitBack:
- strokeHalf(front: false, into: context)
- context.setBlendMode(.clear)
- context.fillEllipse(in: circle(ringOuterRadius + knockoutGap))
- context.setBlendMode(.normal)
-
- case .sphereRing:
- context.setLineWidth(ringBand)
- context.strokeEllipse(in: circle(ringOuterRadius - ringBand / 2))
- cutNearHalf(from: context)
-
- case .sphereCore:
- context.fillEllipse(in: circle(coreRadius))
- cutNearHalf(from: context)
-
- case .orbitFront:
- strokeHalf(front: true, into: context)
- }
-}
-
-func render(_ elements: [Element]) -> CGImage {
- let context = makeContext(size: canvas)
- for element in elements {
- draw(element, into: context)
- }
- return context.makeImage()!
-}
-
-func inkBounds(_ image: CGImage) -> CGRect {
- let width = image.width
- let height = image.height
- var pixels = [UInt8](repeating: 0, count: width * height * 4)
- pixels.withUnsafeMutableBytes { buffer in
- let scan = CGContext(
- data: buffer.baseAddress,
- width: width,
- height: height,
- bitsPerComponent: 8,
- bytesPerRow: width * 4,
- space: space,
- bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue
- )!
- scan.draw(image, in: CGRect(x: 0, y: 0, width: width, height: height))
- }
- var minX = width, minY = height, maxX = -1, maxY = -1
- for y in 0..<height {
- for x in 0..<width where pixels[(y * width + x) * 4 + 3] > 8 {
- if x < minX { minX = x }
- if x > maxX { maxX = x }
- if y < minY { minY = y }
- if y > maxY { maxY = y }
- }
- }
- guard maxX >= minX, maxY >= minY else {
- return CGRect(x: 0, y: 0, width: CGFloat(width), height: CGFloat(height))
- }
- return CGRect(
- x: CGFloat(minX),
- y: CGFloat(minY),
- width: CGFloat(maxX - minX + 1),
- height: CGFloat(maxY - minY + 1)
- )
-}
-
-func normalized(_ image: CGImage, sharedInk ink: CGRect) -> CGImage {
- let scale = canvas * coverage / max(ink.width, ink.height)
- let context = makeContext(size: canvas)
- context.translateBy(x: canvas / 2, y: canvas / 2)
- context.scaleBy(x: scale, y: scale)
- context.translateBy(x: -ink.midX, y: -ink.midY)
- context.draw(image, in: CGRect(x: 0, y: 0, width: canvas, height: canvas))
- return context.makeImage()!
-}
-
-func write(_ image: CGImage, to url: URL) throws {
- guard
- let destination = CGImageDestinationCreateWithURL(
- url as CFURL,
- UTType.png.identifier as CFString,
- 1,
- nil
- )
- else {
- throw CocoaError(.fileWriteUnknown)
- }
- CGImageDestinationAddImage(destination, image, nil)
- guard CGImageDestinationFinalize(destination) else {
- throw CocoaError(.fileWriteUnknown)
- }
-}
-
-func group(for element: Element) -> [String: Any] {
- [
- "blur-material": NSNull(),
- "layers": [
- [
- "fill": ["solid": "srgb:1.00000,1.00000,1.00000,1.00000"],
- "image-name": element.fileName,
- "name": element.rawValue,
- ]
- ],
- "opacity": 1,
- "refractivity": ["depth": element.depth, "enabled": true, "strength": 0.005],
- "shadow": ["kind": "neutral", "opacity": 0.5],
- "specular": "inside",
- "translucency": ["enabled": true, "value": element.translucency],
- ]
-}
-
-guard CommandLine.arguments.count == 2 else {
- FileHandle.standardError.write("usage: icon <output.icon>\n".data(using: .utf8)!)
- exit(2)
-}
-
-let root = URL(fileURLWithPath: CommandLine.arguments[1], isDirectory: true)
-let assets = root.appendingPathComponent("Assets", isDirectory: true)
-try? FileManager.default.removeItem(at: root)
-try FileManager.default.createDirectory(at: assets, withIntermediateDirectories: true)
-
-let sharedInk = inkBounds(render(Element.allCases))
-for element in Element.allCases {
- let layer = normalized(render([element]), sharedInk: sharedInk)
- try write(layer, to: assets.appendingPathComponent(element.fileName))
-}
-
-let document: [String: Any] = [
- "features": ["refractivity", "specular-location"],
- "fill": [
- "linear-gradient": [
- "srgb:0.25882,0.25882,0.26667,1.00000",
- "srgb:0.12549,0.12549,0.13333,1.00000",
- ]
- ],
- "groups": Element.allCases.map(group(for:)),
- "supported-platforms": ["circles": ["watchOS"], "squares": "shared"],
-]
-try JSONSerialization
- .data(withJSONObject: document, options: [.prettyPrinted, .sortedKeys])
- .write(to: root.appendingPathComponent("icon.json"))
diff --git a/helpers/icon/bridgeplay-mark.svg b/helpers/icon/bridgeplay-mark.svg
new file mode 100644
index 0000000..c11c624
--- /dev/null
+++ b/helpers/icon/bridgeplay-mark.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><rect width="24" height="24" rx="6" fill="#000"/><g transform="translate(2.4 2.4) scale(.8)"><path d="M2 14h20" stroke="#f5f5f7" stroke-width="1.8" stroke-linecap="round"/><path d="M6.5 4v10M17.5 4v10" stroke="#f5f5f7" stroke-width="1.8" stroke-linecap="round"/><path d="M2 7c2.5 0 3.5-3 4.5-3S9.5 11 12 11s4.5-7 5.5-7 2 3 4.5 3" fill="none" stroke="#f5f5f7" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/><path d="M6.5 16.5v3M17.5 16.5v3M2 21c2.5 0 3.5-1.6 4.5-1.6S9.5 17.3 12 17.3s4.5 2.1 5.5 2.1 2 1.6 4.5 1.6" fill="none" stroke="#f5f5f7" stroke-width="1.2" stroke-linecap="round" opacity=".35"/></g></svg>
diff --git a/helpers/icon/icongen.swift b/helpers/icon/icongen.swift
new file mode 100644
index 0000000..21b95c4
--- /dev/null
+++ b/helpers/icon/icongen.swift
@@ -0,0 +1,262 @@
+// Builds the Bridgeplay app icon as an Icon Composer document (.icon) that
+// actool compiles into Assets.car and <name>.icns.
+//
+// icongen <bridgeplay-mark.svg> <output.icon>
+//
+// The artwork is the brand mark from bridgeplay-mark.svg (the bridgeplay.dev
+// favicon): a suspension bridge drawn with strokes. Its background <rect> is
+// dropped, the icon fill below supplies the dark squircle. Paths at full
+// opacity become the "Bridge" layer, the faded ones the "Reflection" layer.
+// Only the SVG subset the mark uses is understood: one <g> with
+// translate()+scale(), and <path> elements with stroke, stroke-width, opacity
+// and M/L/H/V/C/S/Z commands.
+
+import CoreGraphics
+import Foundation
+import ImageIO
+import UniformTypeIdentifiers
+
+let canvas: CGFloat = 1024
+let space = CGColorSpace(name: CGColorSpace.sRGB)!
+
+func fail(_ message: String) -> Never {
+ FileHandle.standardError.write("icongen: \(message)\n".data(using: .utf8)!)
+ exit(1)
+}
+
+// MARK: SVG subset
+
+struct Stroke {
+ var path: CGPath
+ var width: CGFloat
+ var opacity: CGFloat
+}
+
+func attribute(_ name: String, in tag: String) -> String? {
+ let pattern = "\\s\(name)=\"([^\"]*)\""
+ guard
+ let regex = try? NSRegularExpression(pattern: pattern),
+ let match = regex.firstMatch(in: tag, range: NSRange(tag.startIndex..., in: tag)),
+ let range = Range(match.range(at: 1), in: tag)
+ else { return nil }
+ return String(tag[range])
+}
+
+func numbers(_ text: String) -> [CGFloat] {
+ let regex = try! NSRegularExpression(pattern: "-?(?:\\d+\\.?\\d*|\\.\\d+)(?:[eE][-+]?\\d+)?")
+ return regex.matches(in: text, range: NSRange(text.startIndex..., in: text)).map {
+ CGFloat(Double(text[Range($0.range, in: text)!])!)
+ }
+}
+
+func tags(_ name: String, in svg: String) -> [String] {
+ let regex = try! NSRegularExpression(pattern: "<\(name)\\b[^>]*>")
+ return regex.matches(in: svg, range: NSRange(svg.startIndex..., in: svg)).map {
+ String(svg[Range($0.range, in: svg)!])
+ }
+}
+
+func parsePath(_ data: String, transform: CGAffineTransform) -> CGPath {
+ let regex = try! NSRegularExpression(
+ pattern: "[MmLlHhVvCcSsZz]|-?(?:\\d+\\.?\\d*|\\.\\d+)(?:[eE][-+]?\\d+)?")
+ let tokens = regex.matches(in: data, range: NSRange(data.startIndex..., in: data)).map {
+ String(data[Range($0.range, in: data)!])
+ }
+ let path = CGMutablePath()
+ var index = 0
+ var command: Character = "M"
+ var current = CGPoint.zero
+ var start = CGPoint.zero
+ var lastControl: CGPoint?
+
+ func next() -> CGFloat {
+ guard index < tokens.count, let value = Double(tokens[index]) else {
+ fail("bad path data: \(data)")
+ }
+ index += 1
+ return CGFloat(value)
+ }
+ func point(relative: Bool) -> CGPoint {
+ let x = next(), y = next()
+ return relative ? CGPoint(x: current.x + x, y: current.y + y) : CGPoint(x: x, y: y)
+ }
+
+ while index < tokens.count {
+ if let letter = tokens[index].first, letter.isLetter {
+ command = letter
+ index += 1
+ }
+ let relative = command.isLowercase
+ switch command.uppercased().first! {
+ case "M":
+ current = point(relative: relative)
+ start = current
+ path.move(to: current, transform: transform)
+ lastControl = nil
+ // Extra coordinate pairs after a move are lines.
+ command = relative ? "l" : "L"
+ case "L":
+ current = point(relative: relative)
+ path.addLine(to: current, transform: transform)
+ lastControl = nil
+ case "H":
+ let x = next()
+ current.x = relative ? current.x + x : x
+ path.addLine(to: current, transform: transform)
+ lastControl = nil
+ case "V":
+ let y = next()
+ current.y = relative ? current.y + y : y
+ path.addLine(to: current, transform: transform)
+ lastControl = nil
+ case "C":
+ let c1 = point(relative: relative)
+ let c2 = point(relative: relative)
+ let end = point(relative: relative)
+ path.addCurve(to: end, control1: c1, control2: c2, transform: transform)
+ lastControl = c2
+ current = end
+ case "S":
+ let c1 = lastControl.map { CGPoint(x: 2 * current.x - $0.x, y: 2 * current.y - $0.y) }
+ ?? current
+ let c2 = point(relative: relative)
+ let end = point(relative: relative)
+ path.addCurve(to: end, control1: c1, control2: c2, transform: transform)
+ lastControl = c2
+ current = end
+ case "Z":
+ path.closeSubpath()
+ current = start
+ lastControl = nil
+ default:
+ fail("unsupported path command \(command)")
+ }
+ }
+ return path
+}
+
+func loadMark(_ url: URL) -> [Stroke] {
+ guard let svg = try? String(contentsOf: url, encoding: .utf8) else {
+ fail("cannot read \(url.path)")
+ }
+ guard
+ let root = tags("svg", in: svg).first,
+ let viewBox = attribute("viewBox", in: root).map(numbers), viewBox.count == 4
+ else { fail("\(url.lastPathComponent) has no viewBox") }
+
+ // SVG space (y down, viewBox units) to the canvas (y up, pixels).
+ let scale = canvas / max(viewBox[2], viewBox[3])
+ var transform = CGAffineTransform(a: scale, b: 0, c: 0, d: -scale,
+ tx: -viewBox[0] * scale, ty: canvas + viewBox[1] * scale)
+ if let group = tags("g", in: svg).first, let spec = attribute("transform", in: group) {
+ var inner = CGAffineTransform.identity
+ let parts = try! NSRegularExpression(pattern: "(translate|scale)\\(([^)]*)\\)")
+ for match in parts.matches(in: spec, range: NSRange(spec.startIndex..., in: spec)) {
+ let kind = String(spec[Range(match.range(at: 1), in: spec)!])
+ let args = numbers(String(spec[Range(match.range(at: 2), in: spec)!]))
+ if kind == "translate", args.count >= 1 {
+ inner = inner.translatedBy(x: args[0], y: args.count > 1 ? args[1] : 0)
+ } else if kind == "scale", args.count >= 1 {
+ inner = inner.scaledBy(x: args[0], y: args.count > 1 ? args[1] : args[0])
+ } else {
+ fail("unsupported group transform \(spec)")
+ }
+ }
+ transform = inner.concatenating(transform)
+ }
+
+ let strokes = tags("path", in: svg).compactMap { tag -> Stroke? in
+ guard let data = attribute("d", in: tag), attribute("stroke", in: tag) != nil else {
+ return nil
+ }
+ let width = attribute("stroke-width", in: tag).flatMap { numbers($0).first } ?? 1
+ let opacity = attribute("opacity", in: tag).flatMap { numbers($0).first } ?? 1
+ return Stroke(path: parsePath(data, transform: transform),
+ width: width * transform.a, opacity: opacity)
+ }
+ guard !strokes.isEmpty else { fail("\(url.lastPathComponent) has no stroked paths") }
+ return strokes
+}
+
+// MARK: Icon document
+
+func render(_ strokes: [Stroke]) -> CGImage {
+ let context = CGContext(
+ data: nil, width: Int(canvas), height: Int(canvas), bitsPerComponent: 8,
+ bytesPerRow: 0, space: space, bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue)!
+ context.setAllowsAntialiasing(true)
+ context.setStrokeColor(CGColor(red: 1, green: 1, blue: 1, alpha: 1))
+ context.setLineCap(.round)
+ context.setLineJoin(.round)
+ for stroke in strokes {
+ context.setLineWidth(stroke.width)
+ context.addPath(stroke.path)
+ context.strokePath()
+ }
+ return context.makeImage()!
+}
+
+func write(_ image: CGImage, to url: URL) {
+ guard
+ let destination = CGImageDestinationCreateWithURL(
+ url as CFURL, UTType.png.identifier as CFString, 1, nil)
+ else { fail("cannot write \(url.path)") }
+ CGImageDestinationAddImage(destination, image, nil)
+ guard CGImageDestinationFinalize(destination) else { fail("cannot write \(url.path)") }
+}
+
+// #f5f5f7, the mark's colour on bridgeplay.dev.
+let glyphFill = "srgb:0.96078,0.96078,0.96863,1.00000"
+
+func group(name: String, file: String, opacity: Double) -> [String: Any] {
+ [
+ "blur-material": NSNull(),
+ "layers": [
+ [
+ "fill": ["solid": glyphFill],
+ "image-name": file,
+ "name": name,
+ ]
+ ],
+ "opacity": opacity,
+ "shadow": ["kind": "neutral", "opacity": 0.5],
+ "specular": "inside",
+ "translucency": ["enabled": true, "value": 0.2],
+ ]
+}
+
+guard CommandLine.arguments.count == 3 else {
+ FileHandle.standardError.write("usage: icongen <mark.svg> <output.icon>\n".data(using: .utf8)!)
+ exit(2)
+}
+
+let strokes = loadMark(URL(fileURLWithPath: CommandLine.arguments[1]))
+let root = URL(fileURLWithPath: CommandLine.arguments[2], isDirectory: true)
+let assets = root.appendingPathComponent("Assets", isDirectory: true)
+try? FileManager.default.removeItem(at: root)
+try FileManager.default.createDirectory(at: assets, withIntermediateDirectories: true)
+
+let bridge = strokes.filter { $0.opacity >= 1 }
+let reflection = strokes.filter { $0.opacity < 1 }
+var groups: [[String: Any]] = []
+// Icon Composer lists groups front to back.
+write(render(bridge), to: assets.appendingPathComponent("bridge.png"))
+groups.append(group(name: "Bridge", file: "bridge.png", opacity: 1))
+if let faded = reflection.first?.opacity {
+ write(render(reflection), to: assets.appendingPathComponent("reflection.png"))
+ groups.append(group(name: "Reflection", file: "reflection.png", opacity: Double(faded)))
+}
+
+let document: [String: Any] = [
+ "fill": [
+ "linear-gradient": [
+ "srgb:0.11373,0.11373,0.12157,1.00000",
+ "srgb:0.03137,0.03137,0.03529,1.00000",
+ ]
+ ],
+ "groups": groups,
+ "supported-platforms": ["circles": ["watchOS"], "squares": "shared"],
+]
+try JSONSerialization
+ .data(withJSONObject: document, options: [.prettyPrinted, .sortedKeys])
+ .write(to: root.appendingPathComponent("icon.json"))