Commit 6cf765eb97
Verified · cmc
Layout: unified · split
ios/Orgstar/Assets.xcassets/AppIcon.appiconset/AppIcon-dark.png added
Binary file not shown.
ios/Orgstar/Assets.xcassets/AppIcon.appiconset/AppIcon-tinted.png added
Binary file not shown.
ios/Orgstar/Assets.xcassets/AppIcon.appiconset/Contents.json +25 −1
| @@ -5,10 +5,34 @@ | ||
| 5 | 5 | "idiom" : "universal", |
| 6 | 6 | "platform" : "ios", |
| 7 | 7 | "size" : "1024x1024" |
| 8 | }, | |
| 9 | { | |
| 10 | "appearances" : [ | |
| 11 | { | |
| 12 | "appearance" : "luminosity", | |
| 13 | "value" : "dark" | |
| 14 | } | |
| 15 | ], | |
| 16 | "filename" : "AppIcon-dark.png", | |
| 17 | "idiom" : "universal", | |
| 18 | "platform" : "ios", | |
| 19 | "size" : "1024x1024" | |
| 20 | }, | |
| 21 | { | |
| 22 | "appearances" : [ | |
| 23 | { | |
| 24 | "appearance" : "luminosity", | |
| 25 | "value" : "tinted" | |
| 26 | } | |
| 27 | ], | |
| 28 | "filename" : "AppIcon-tinted.png", | |
| 29 | "idiom" : "universal", | |
| 30 | "platform" : "ios", | |
| 31 | "size" : "1024x1024" | |
| 8 | 32 | } |
| 9 | 33 | ], |
| 10 | 34 | "info" : { |
| 11 | 35 | "author" : "xcode", |
| 12 | 36 | "version" : 1 |
| 13 | 37 | } |
| 14 | } | |
| 38 | } | |
| \ No newline at end of file | ||
ios/Orgstar/Assets.xcassets/IconPreview-default.imageset/Contents.json added +22
| @@ -0,0 +1,22 @@ | ||
| 1 | { | |
| 2 | "images" : [ | |
| 3 | { | |
| 4 | "filename" : "light.png", | |
| 5 | "idiom" : "universal" | |
| 6 | }, | |
| 7 | { | |
| 8 | "appearances" : [ | |
| 9 | { | |
| 10 | "appearance" : "luminosity", | |
| 11 | "value" : "dark" | |
| 12 | } | |
| 13 | ], | |
| 14 | "filename" : "dark.png", | |
| 15 | "idiom" : "universal" | |
| 16 | } | |
| 17 | ], | |
| 18 | "info" : { | |
| 19 | "author" : "xcode", | |
| 20 | "version" : 1 | |
| 21 | } | |
| 22 | } | |
| \ No newline at end of file | ||
ios/Orgstar/Assets.xcassets/IconPreview-default.imageset/dark.png added
Binary file not shown.
ios/Orgstar/Assets.xcassets/IconPreview-default.imageset/light.png added
Binary file not shown.
packaging/AppIcons.xcassets/AppIcon.appiconset/Contents.json added +308
| @@ -0,0 +1,308 @@ | ||
| 1 | { | |
| 2 | "images" : [ | |
| 3 | { | |
| 4 | "filename" : "icon_16x16.png", | |
| 5 | "idiom" : "mac", | |
| 6 | "scale" : "1x", | |
| 7 | "size" : "16x16" | |
| 8 | }, | |
| 9 | { | |
| 10 | "appearances" : [ | |
| 11 | { | |
| 12 | "appearance" : "luminosity", | |
| 13 | "value" : "dark" | |
| 14 | } | |
| 15 | ], | |
| 16 | "filename" : "icon_16x16-dark.png", | |
| 17 | "idiom" : "mac", | |
| 18 | "scale" : "1x", | |
| 19 | "size" : "16x16" | |
| 20 | }, | |
| 21 | { | |
| 22 | "appearances" : [ | |
| 23 | { | |
| 24 | "appearance" : "luminosity", | |
| 25 | "value" : "tinted" | |
| 26 | } | |
| 27 | ], | |
| 28 | "filename" : "icon_16x16-tinted.png", | |
| 29 | "idiom" : "mac", | |
| 30 | "scale" : "1x", | |
| 31 | "size" : "16x16" | |
| 32 | }, | |
| 33 | { | |
| 34 | "filename" : "icon_16x16@2x.png", | |
| 35 | "idiom" : "mac", | |
| 36 | "scale" : "2x", | |
| 37 | "size" : "16x16" | |
| 38 | }, | |
| 39 | { | |
| 40 | "appearances" : [ | |
| 41 | { | |
| 42 | "appearance" : "luminosity", | |
| 43 | "value" : "dark" | |
| 44 | } | |
| 45 | ], | |
| 46 | "filename" : "icon_16x16@2x-dark.png", | |
| 47 | "idiom" : "mac", | |
| 48 | "scale" : "2x", | |
| 49 | "size" : "16x16" | |
| 50 | }, | |
| 51 | { | |
| 52 | "appearances" : [ | |
| 53 | { | |
| 54 | "appearance" : "luminosity", | |
| 55 | "value" : "tinted" | |
| 56 | } | |
| 57 | ], | |
| 58 | "filename" : "icon_16x16@2x-tinted.png", | |
| 59 | "idiom" : "mac", | |
| 60 | "scale" : "2x", | |
| 61 | "size" : "16x16" | |
| 62 | }, | |
| 63 | { | |
| 64 | "filename" : "icon_32x32.png", | |
| 65 | "idiom" : "mac", | |
| 66 | "scale" : "1x", | |
| 67 | "size" : "32x32" | |
| 68 | }, | |
| 69 | { | |
| 70 | "appearances" : [ | |
| 71 | { | |
| 72 | "appearance" : "luminosity", | |
| 73 | "value" : "dark" | |
| 74 | } | |
| 75 | ], | |
| 76 | "filename" : "icon_32x32-dark.png", | |
| 77 | "idiom" : "mac", | |
| 78 | "scale" : "1x", | |
| 79 | "size" : "32x32" | |
| 80 | }, | |
| 81 | { | |
| 82 | "appearances" : [ | |
| 83 | { | |
| 84 | "appearance" : "luminosity", | |
| 85 | "value" : "tinted" | |
| 86 | } | |
| 87 | ], | |
| 88 | "filename" : "icon_32x32-tinted.png", | |
| 89 | "idiom" : "mac", | |
| 90 | "scale" : "1x", | |
| 91 | "size" : "32x32" | |
| 92 | }, | |
| 93 | { | |
| 94 | "filename" : "icon_32x32@2x.png", | |
| 95 | "idiom" : "mac", | |
| 96 | "scale" : "2x", | |
| 97 | "size" : "32x32" | |
| 98 | }, | |
| 99 | { | |
| 100 | "appearances" : [ | |
| 101 | { | |
| 102 | "appearance" : "luminosity", | |
| 103 | "value" : "dark" | |
| 104 | } | |
| 105 | ], | |
| 106 | "filename" : "icon_32x32@2x-dark.png", | |
| 107 | "idiom" : "mac", | |
| 108 | "scale" : "2x", | |
| 109 | "size" : "32x32" | |
| 110 | }, | |
| 111 | { | |
| 112 | "appearances" : [ | |
| 113 | { | |
| 114 | "appearance" : "luminosity", | |
| 115 | "value" : "tinted" | |
| 116 | } | |
| 117 | ], | |
| 118 | "filename" : "icon_32x32@2x-tinted.png", | |
| 119 | "idiom" : "mac", | |
| 120 | "scale" : "2x", | |
| 121 | "size" : "32x32" | |
| 122 | }, | |
| 123 | { | |
| 124 | "filename" : "icon_128x128.png", | |
| 125 | "idiom" : "mac", | |
| 126 | "scale" : "1x", | |
| 127 | "size" : "128x128" | |
| 128 | }, | |
| 129 | { | |
| 130 | "appearances" : [ | |
| 131 | { | |
| 132 | "appearance" : "luminosity", | |
| 133 | "value" : "dark" | |
| 134 | } | |
| 135 | ], | |
| 136 | "filename" : "icon_128x128-dark.png", | |
| 137 | "idiom" : "mac", | |
| 138 | "scale" : "1x", | |
| 139 | "size" : "128x128" | |
| 140 | }, | |
| 141 | { | |
| 142 | "appearances" : [ | |
| 143 | { | |
| 144 | "appearance" : "luminosity", | |
| 145 | "value" : "tinted" | |
| 146 | } | |
| 147 | ], | |
| 148 | "filename" : "icon_128x128-tinted.png", | |
| 149 | "idiom" : "mac", | |
| 150 | "scale" : "1x", | |
| 151 | "size" : "128x128" | |
| 152 | }, | |
| 153 | { | |
| 154 | "filename" : "icon_128x128@2x.png", | |
| 155 | "idiom" : "mac", | |
| 156 | "scale" : "2x", | |
| 157 | "size" : "128x128" | |
| 158 | }, | |
| 159 | { | |
| 160 | "appearances" : [ | |
| 161 | { | |
| 162 | "appearance" : "luminosity", | |
| 163 | "value" : "dark" | |
| 164 | } | |
| 165 | ], | |
| 166 | "filename" : "icon_128x128@2x-dark.png", | |
| 167 | "idiom" : "mac", | |
| 168 | "scale" : "2x", | |
| 169 | "size" : "128x128" | |
| 170 | }, | |
| 171 | { | |
| 172 | "appearances" : [ | |
| 173 | { | |
| 174 | "appearance" : "luminosity", | |
| 175 | "value" : "tinted" | |
| 176 | } | |
| 177 | ], | |
| 178 | "filename" : "icon_128x128@2x-tinted.png", | |
| 179 | "idiom" : "mac", | |
| 180 | "scale" : "2x", | |
| 181 | "size" : "128x128" | |
| 182 | }, | |
| 183 | { | |
| 184 | "filename" : "icon_256x256.png", | |
| 185 | "idiom" : "mac", | |
| 186 | "scale" : "1x", | |
| 187 | "size" : "256x256" | |
| 188 | }, | |
| 189 | { | |
| 190 | "appearances" : [ | |
| 191 | { | |
| 192 | "appearance" : "luminosity", | |
| 193 | "value" : "dark" | |
| 194 | } | |
| 195 | ], | |
| 196 | "filename" : "icon_256x256-dark.png", | |
| 197 | "idiom" : "mac", | |
| 198 | "scale" : "1x", | |
| 199 | "size" : "256x256" | |
| 200 | }, | |
| 201 | { | |
| 202 | "appearances" : [ | |
| 203 | { | |
| 204 | "appearance" : "luminosity", | |
| 205 | "value" : "tinted" | |
| 206 | } | |
| 207 | ], | |
| 208 | "filename" : "icon_256x256-tinted.png", | |
| 209 | "idiom" : "mac", | |
| 210 | "scale" : "1x", | |
| 211 | "size" : "256x256" | |
| 212 | }, | |
| 213 | { | |
| 214 | "filename" : "icon_256x256@2x.png", | |
| 215 | "idiom" : "mac", | |
| 216 | "scale" : "2x", | |
| 217 | "size" : "256x256" | |
| 218 | }, | |
| 219 | { | |
| 220 | "appearances" : [ | |
| 221 | { | |
| 222 | "appearance" : "luminosity", | |
| 223 | "value" : "dark" | |
| 224 | } | |
| 225 | ], | |
| 226 | "filename" : "icon_256x256@2x-dark.png", | |
| 227 | "idiom" : "mac", | |
| 228 | "scale" : "2x", | |
| 229 | "size" : "256x256" | |
| 230 | }, | |
| 231 | { | |
| 232 | "appearances" : [ | |
| 233 | { | |
| 234 | "appearance" : "luminosity", | |
| 235 | "value" : "tinted" | |
| 236 | } | |
| 237 | ], | |
| 238 | "filename" : "icon_256x256@2x-tinted.png", | |
| 239 | "idiom" : "mac", | |
| 240 | "scale" : "2x", | |
| 241 | "size" : "256x256" | |
| 242 | }, | |
| 243 | { | |
| 244 | "filename" : "icon_512x512.png", | |
| 245 | "idiom" : "mac", | |
| 246 | "scale" : "1x", | |
| 247 | "size" : "512x512" | |
| 248 | }, | |
| 249 | { | |
| 250 | "appearances" : [ | |
| 251 | { | |
| 252 | "appearance" : "luminosity", | |
| 253 | "value" : "dark" | |
| 254 | } | |
| 255 | ], | |
| 256 | "filename" : "icon_512x512-dark.png", | |
| 257 | "idiom" : "mac", | |
| 258 | "scale" : "1x", | |
| 259 | "size" : "512x512" | |
| 260 | }, | |
| 261 | { | |
| 262 | "appearances" : [ | |
| 263 | { | |
| 264 | "appearance" : "luminosity", | |
| 265 | "value" : "tinted" | |
| 266 | } | |
| 267 | ], | |
| 268 | "filename" : "icon_512x512-tinted.png", | |
| 269 | "idiom" : "mac", | |
| 270 | "scale" : "1x", | |
| 271 | "size" : "512x512" | |
| 272 | }, | |
| 273 | { | |
| 274 | "filename" : "icon_512x512@2x.png", | |
| 275 | "idiom" : "mac", | |
| 276 | "scale" : "2x", | |
| 277 | "size" : "512x512" | |
| 278 | }, | |
| 279 | { | |
| 280 | "appearances" : [ | |
| 281 | { | |
| 282 | "appearance" : "luminosity", | |
| 283 | "value" : "dark" | |
| 284 | } | |
| 285 | ], | |
| 286 | "filename" : "icon_512x512@2x-dark.png", | |
| 287 | "idiom" : "mac", | |
| 288 | "scale" : "2x", | |
| 289 | "size" : "512x512" | |
| 290 | }, | |
| 291 | { | |
| 292 | "appearances" : [ | |
| 293 | { | |
| 294 | "appearance" : "luminosity", | |
| 295 | "value" : "tinted" | |
| 296 | } | |
| 297 | ], | |
| 298 | "filename" : "icon_512x512@2x-tinted.png", | |
| 299 | "idiom" : "mac", | |
| 300 | "scale" : "2x", | |
| 301 | "size" : "512x512" | |
| 302 | } | |
| 303 | ], | |
| 304 | "info" : { | |
| 305 | "author" : "xcode", | |
| 306 | "version" : 1 | |
| 307 | } | |
| 308 | } | |
| \ No newline at end of file | ||
packaging/AppIcons.xcassets/AppIcon.appiconset/icon_128x128-dark.png added
Binary file not shown.
packaging/AppIcons.xcassets/AppIcon.appiconset/icon_128x128-tinted.png added
Binary file not shown.
packaging/AppIcons.xcassets/AppIcon.appiconset/icon_128x128.png added
Binary file not shown.
packaging/AppIcons.xcassets/AppIcon.appiconset/icon_128x128@2x-dark.png added
Binary file not shown.
packaging/AppIcons.xcassets/AppIcon.appiconset/icon_128x128@2x-tinted.png added
Binary file not shown.
packaging/AppIcons.xcassets/AppIcon.appiconset/icon_128x128@2x.png added
Binary file not shown.
packaging/AppIcons.xcassets/AppIcon.appiconset/icon_16x16-dark.png added
Binary file not shown.
packaging/AppIcons.xcassets/AppIcon.appiconset/icon_16x16-tinted.png added
Binary file not shown.
packaging/AppIcons.xcassets/AppIcon.appiconset/icon_16x16.png added
Binary file not shown.
packaging/AppIcons.xcassets/AppIcon.appiconset/icon_16x16@2x-dark.png added
Binary file not shown.
packaging/AppIcons.xcassets/AppIcon.appiconset/icon_16x16@2x-tinted.png added
Binary file not shown.
packaging/AppIcons.xcassets/AppIcon.appiconset/icon_16x16@2x.png added
Binary file not shown.
packaging/AppIcons.xcassets/AppIcon.appiconset/icon_256x256-dark.png added
Binary file not shown.
packaging/AppIcons.xcassets/AppIcon.appiconset/icon_256x256-tinted.png added
Binary file not shown.
packaging/AppIcons.xcassets/AppIcon.appiconset/icon_256x256.png added
Binary file not shown.
packaging/AppIcons.xcassets/AppIcon.appiconset/icon_256x256@2x-dark.png added
Binary file not shown.
packaging/AppIcons.xcassets/AppIcon.appiconset/icon_256x256@2x-tinted.png added
Binary file not shown.
packaging/AppIcons.xcassets/AppIcon.appiconset/icon_256x256@2x.png added
Binary file not shown.
packaging/AppIcons.xcassets/AppIcon.appiconset/icon_32x32-dark.png added
Binary file not shown.
packaging/AppIcons.xcassets/AppIcon.appiconset/icon_32x32-tinted.png added
Binary file not shown.
packaging/AppIcons.xcassets/AppIcon.appiconset/icon_32x32.png added
Binary file not shown.
packaging/AppIcons.xcassets/AppIcon.appiconset/icon_32x32@2x-dark.png added
Binary file not shown.
packaging/AppIcons.xcassets/AppIcon.appiconset/icon_32x32@2x-tinted.png added
Binary file not shown.
packaging/AppIcons.xcassets/AppIcon.appiconset/icon_32x32@2x.png added
Binary file not shown.
packaging/AppIcons.xcassets/AppIcon.appiconset/icon_512x512-dark.png added
Binary file not shown.
packaging/AppIcons.xcassets/AppIcon.appiconset/icon_512x512-tinted.png added
Binary file not shown.
packaging/AppIcons.xcassets/AppIcon.appiconset/icon_512x512.png added
Binary file not shown.
packaging/AppIcons.xcassets/AppIcon.appiconset/icon_512x512@2x-dark.png added
Binary file not shown.
packaging/AppIcons.xcassets/AppIcon.appiconset/icon_512x512@2x-tinted.png added
Binary file not shown.
packaging/AppIcons.xcassets/AppIcon.appiconset/icon_512x512@2x.png added
Binary file not shown.
packaging/AppIcons.xcassets/Contents.json added +6
| @@ -0,0 +1,6 @@ | ||
| 1 | { | |
| 2 | "info" : { | |
| 3 | "author" : "xcode", | |
| 4 | "version" : 1 | |
| 5 | } | |
| 6 | } | |
| \ No newline at end of file | ||
packaging/IconPreviews/default-dark.png added
Binary file not shown.
packaging/IconPreviews/default-light.png added
Binary file not shown.
scripts/build-app.sh +8 −5
| @@ -57,10 +57,13 @@ fi | ||
| 57 | 57 | # The UI's translations, from l10n/Localizable.xcstrings. |
| 58 | 58 | scripts/localize.sh "$app/Contents/Resources" |
| 59 | 59 | |
| 60 | iconset="$(mktemp -d)/AppIcon.iconset" | |
| 61 | swift scripts/make-icon.swift "$iconset" | |
| 62 | iconutil -c icns "$iconset" -o "$app/Contents/Resources/AppIcon.icns" | |
| 63 | rm -rf "$(dirname "$iconset")" | |
| 60 | # The icon, in the system's default, dark and tinted styles, and the Dock icons Settings offers. | |
| 61 | work="$(mktemp -d)" | |
| 62 | xcrun actool packaging/AppIcons.xcassets --compile "$app/Contents/Resources" --platform macosx \ | |
| 63 | --minimum-deployment-target 26.0 --app-icon AppIcon --output-partial-info-plist "$work/icon.plist" > /dev/null | |
| 64 | rm -rf "$work" | |
| 65 | mkdir -p "$app/Contents/Resources/IconPreviews" | |
| 66 | cp packaging/IconPreviews/*.png "$app/Contents/Resources/IconPreviews/" | |
| 64 | 67 | |
| 65 | 68 | cat > "$app/Contents/Info.plist" <<EOF |
| 66 | 69 | <?xml version="1.0" encoding="UTF-8"?> |
| @@ -81,7 +84,7 @@ cat > "$app/Contents/Info.plist" <<EOF | ||
| 81 | 84 | <string>Orgstar</string> |
| 82 | 85 | <key>CFBundlePackageType</key> |
| 83 | 86 | <string>APPL</string> |
| 84 | <key>CFBundleIconFile</key> | |
| 87 | <key>CFBundleIconName</key> | |
| 85 | 88 | <string>AppIcon</string> |
| 86 | 89 | <key>UTImportedTypeDeclarations</key> |
| 87 | 90 | <array> |
scripts/make-icon.swift +126 −31
| @@ -1,11 +1,34 @@ | ||
| 1 | // Draws orgstar's app icon: an outline's heading star over three indented lines, on a deep | |
| 2 | // blue-to-violet square. Usage: swift scripts/make-icon.swift <dir.iconset> for the Mac's | |
| 3 | // iconset, or swift scripts/make-icon.swift --ios <file.png> for the iOS app's 1024-pixel icon. | |
| 1 | // Draws orgstar's app icons from the variant table below into the committed asset catalogs: | |
| 2 | // ios/Orgstar/Assets.xcassets (iOS app icons and their previews), packaging/AppIcons.xcassets | |
| 3 | // (the Mac's icon) and packaging/IconPreviews (the Mac's Dock icons). | |
| 4 | // Usage: swift scripts/make-icon.swift | |
| 4 | 5 | import AppKit |
| 5 | 6 | |
| 6 | /// The Mac's icon sits on the macOS grid, a rounded square inset in a clear canvas; the iOS | |
| 7 | /// icon is the same square filling an opaque canvas, which iOS rounds itself. | |
| 8 | func draw(_ size: CGFloat, fullBleed: Bool = false) -> NSBitmapImageRep { | |
| 7 | struct Variant { | |
| 8 | enum Style { case filled, outline, unicorn } | |
| 9 | let id: String | |
| 10 | /// The gradient, top-left to bottom-right. | |
| 11 | let top: NSColor, bottom: NSColor | |
| 12 | let glyph: NSColor | |
| 13 | let bars: NSColor | |
| 14 | var style: Style = .filled | |
| 15 | } | |
| 16 | ||
| 17 | func rgb(_ hex: UInt32) -> NSColor { | |
| 18 | NSColor(srgbRed: CGFloat(hex >> 16 & 0xFF) / 255, green: CGFloat(hex >> 8 & 0xFF) / 255, blue: CGFloat(hex & 0xFF) / 255, alpha: 1) | |
| 19 | } | |
| 20 | ||
| 21 | let variants: [Variant] = [ | |
| 22 | Variant(id: "default", top: NSColor(srgbRed: 0.13, green: 0.20, blue: 0.55, alpha: 1), bottom: NSColor(srgbRed: 0.40, green: 0.22, blue: 0.70, alpha: 1), | |
| 23 | glyph: NSColor(srgbRed: 1, green: 0.78, blue: 0.30, alpha: 1), bars: NSColor(white: 1, alpha: 0.92)), | |
| 24 | ] | |
| 25 | ||
| 26 | enum Look { case light, dark, tinted } | |
| 27 | ||
| 28 | /// The macOS icon grid: an 824-point rounded square in a 1024 canvas; `fullBleed` fills the | |
| 29 | /// canvas, as iOS wants. Dark and tinted leave the background clear (dark) or black (tinted) | |
| 30 | /// for the system to fill. | |
| 31 | func draw(_ v: Variant, _ size: CGFloat, look: Look = .light, fullBleed: Bool = false) -> NSBitmapImageRep { | |
| 9 | 32 | let rep = NSBitmapImageRep(bitmapDataPlanes: nil, pixelsWide: Int(size), pixelsHigh: Int(size), bitsPerSample: 8, |
| 10 | 33 | samplesPerPixel: 4, hasAlpha: true, isPlanar: false, colorSpaceName: .deviceRGB, bytesPerRow: 0, bitsPerPixel: 0)! |
| 11 | 34 | NSGraphicsContext.saveGraphicsState() |
| @@ -17,44 +40,116 @@ func draw(_ size: CGFloat, fullBleed: Bool = false) -> NSBitmapImageRep { | ||
| 17 | 40 | transform.translateX(by: -100 * s, yBy: -100 * s) |
| 18 | 41 | transform.concat() |
| 19 | 42 | } |
| 20 | // The macOS icon grid: an 824-point rounded square in a 1024 canvas. | |
| 21 | 43 | let square = NSRect(x: 100 * s, y: 100 * s, width: 824 * s, height: 824 * s) |
| 22 | 44 | let shape = fullBleed ? NSBezierPath(rect: square) : NSBezierPath(roundedRect: square, xRadius: 185 * s, yRadius: 185 * s) |
| 23 | NSGradient(colors: [NSColor(srgbRed: 0.13, green: 0.20, blue: 0.55, alpha: 1), NSColor(srgbRed: 0.40, green: 0.22, blue: 0.70, alpha: 1)])! | |
| 24 | .draw(in: shape, angle: -60) | |
| 25 | // The heading star. | |
| 45 | switch look { | |
| 46 | case .light: NSGradient(colors: [v.top, v.bottom])!.draw(in: shape, angle: -60) | |
| 47 | case .dark: break | |
| 48 | case .tinted: NSColor.black.setFill(); shape.fill() | |
| 49 | } | |
| 50 | let glyph = look == .tinted ? NSColor(white: 0.95, alpha: 1) : v.glyph | |
| 51 | let bars = look == .tinted ? NSColor(white: 0.75, alpha: 1) : v.bars | |
| 52 | switch v.style { | |
| 53 | case .filled: drawOutline(s, glyph: glyph, bars: bars, filled: true) | |
| 54 | case .outline: drawOutline(s, glyph: glyph, bars: bars, filled: false) | |
| 55 | case .unicorn: drawUnicorn(s, glyph: glyph, head: bars) | |
| 56 | } | |
| 57 | NSGraphicsContext.restoreGraphicsState() | |
| 58 | return rep | |
| 59 | } | |
| 60 | ||
| 61 | /// The heading star over three outline lines, indented like a heading's children. | |
| 62 | func drawOutline(_ s: CGFloat, glyph: NSColor, bars: NSColor, filled: Bool) { | |
| 26 | 63 | let star = NSAttributedString(string: "✱", attributes: [ |
| 27 | .font: NSFont.systemFont(ofSize: 330 * s, weight: .heavy), .foregroundColor: NSColor(srgbRed: 1, green: 0.78, blue: 0.30, alpha: 1), | |
| 64 | .font: NSFont.systemFont(ofSize: 330 * s, weight: filled ? .heavy : .light), .foregroundColor: glyph, | |
| 28 | 65 | ]) |
| 29 | 66 | star.draw(at: NSPoint(x: 190 * s, y: 520 * s)) |
| 30 | // Three outline lines, indented like a heading's children. | |
| 31 | NSColor(white: 1, alpha: 0.92).setFill() | |
| 32 | 67 | for (i, (x, width)) in [(470.0, 330.0), (300.0, 500.0), (380.0, 420.0)].enumerated() { |
| 33 | 68 | let y = (650 - Double(i) * 150) * s |
| 34 | let line = i == 0 ? NSRect(x: x * s, y: y, width: width * s, height: 70 * s) : NSRect(x: x * s, y: y, width: width * s, height: 56 * s) | |
| 35 | NSBezierPath(roundedRect: line, xRadius: 28 * s, yRadius: 28 * s).fill() | |
| 69 | let line = NSRect(x: x * s, y: y, width: width * s, height: (i == 0 ? 70 : 56) * s) | |
| 70 | let path = NSBezierPath(roundedRect: line, xRadius: 28 * s, yRadius: 28 * s) | |
| 71 | if filled { | |
| 72 | bars.setFill(); path.fill() | |
| 73 | } else { | |
| 74 | bars.setStroke(); path.lineWidth = 10 * s; path.stroke() | |
| 75 | } | |
| 36 | 76 | } |
| 37 | NSGraphicsContext.restoreGraphicsState() | |
| 38 | return rep | |
| 39 | 77 | } |
| 40 | 78 | |
| 41 | if CommandLine.arguments[1] == "--ios" { | |
| 42 | // Without an alpha channel, as the App Store requires: drawn, then copied into an opaque image. | |
| 43 | let drawn = draw(1024, fullBleed: true).cgImage! | |
| 44 | let opaque = CGContext(data: nil, width: 1024, height: 1024, bitsPerComponent: 8, bytesPerRow: 0, | |
| 45 | space: CGColorSpace(name: CGColorSpace.sRGB)!, bitmapInfo: CGImageAlphaInfo.noneSkipLast.rawValue)! | |
| 46 | opaque.draw(drawn, in: CGRect(x: 0, y: 0, width: 1024, height: 1024)) | |
| 47 | let file = URL(fileURLWithPath: CommandLine.arguments[2]) | |
| 48 | try NSBitmapImageRep(cgImage: opaque.makeImage()!).representation(using: .png, properties: [:])!.write(to: file) | |
| 49 | exit(0) | |
| 79 | /// Task 8 draws the unicorn. | |
| 80 | func drawUnicorn(_ s: CGFloat, glyph: NSColor, head: NSColor) { | |
| 81 | drawOutline(s, glyph: glyph, bars: head, filled: true) | |
| 82 | } | |
| 83 | ||
| 84 | func png(_ rep: NSBitmapImageRep) -> Data { rep.representation(using: .png, properties: [:])! } | |
| 85 | ||
| 86 | /// Without an alpha channel, as the App Store requires for the light icon. | |
| 87 | func opaque(_ rep: NSBitmapImageRep) -> NSBitmapImageRep { | |
| 88 | let size = rep.pixelsWide | |
| 89 | let context = CGContext(data: nil, width: size, height: size, bitsPerComponent: 8, bytesPerRow: 0, | |
| 90 | space: CGColorSpace(name: CGColorSpace.sRGB)!, bitmapInfo: CGImageAlphaInfo.noneSkipLast.rawValue)! | |
| 91 | context.draw(rep.cgImage!, in: CGRect(x: 0, y: 0, width: size, height: size)) | |
| 92 | return NSBitmapImageRep(cgImage: context.makeImage()!) | |
| 93 | } | |
| 94 | ||
| 95 | func write(_ data: Data, _ path: String) throws { | |
| 96 | let url = URL(fileURLWithPath: path) | |
| 97 | try FileManager.default.createDirectory(at: url.deletingLastPathComponent(), withIntermediateDirectories: true) | |
| 98 | try data.write(to: url) | |
| 99 | } | |
| 100 | ||
| 101 | func json(_ object: Any, _ path: String) throws { | |
| 102 | try write(JSONSerialization.data(withJSONObject: object, options: [.prettyPrinted, .sortedKeys]), path) | |
| 103 | } | |
| 104 | ||
| 105 | let info = ["author": "xcode", "version": 1] as [String: Any] | |
| 106 | let appearances: [(Look, String, [[String: String]])] = [ | |
| 107 | (.light, "", []), | |
| 108 | (.dark, "-dark", [["appearance": "luminosity", "value": "dark"]]), | |
| 109 | (.tinted, "-tinted", [["appearance": "luminosity", "value": "tinted"]]), | |
| 110 | ] | |
| 111 | ||
| 112 | for v in variants { | |
| 113 | // iOS: one set per icon, named AppIcon for the default and AppIcon-<Id> for the others. | |
| 114 | let setName = v.id == "default" ? "AppIcon" : "AppIcon-" + v.id.split(separator: "-").map(\.capitalized).joined() | |
| 115 | let set = "ios/Orgstar/Assets.xcassets/\(setName).appiconset" | |
| 116 | var images: [[String: Any]] = [] | |
| 117 | for (look, suffix, appearance) in appearances { | |
| 118 | let rep = draw(v, 1024, look: look, fullBleed: true) | |
| 119 | try write(png(look == .light ? opaque(rep) : rep), "\(set)/AppIcon\(suffix).png") | |
| 120 | var image: [String: Any] = ["filename": "AppIcon\(suffix).png", "idiom": "universal", "platform": "ios", "size": "1024x1024"] | |
| 121 | if !appearance.isEmpty { image["appearances"] = appearance } | |
| 122 | images.append(image) | |
| 123 | } | |
| 124 | try json(["images": images, "info": info], "\(set)/Contents.json") | |
| 125 | ||
| 126 | // Previews for the iOS picker, light and dark. | |
| 127 | let preview = "ios/Orgstar/Assets.xcassets/IconPreview-\(v.id).imageset" | |
| 128 | try write(png(draw(v, 256, fullBleed: true)), "\(preview)/light.png") | |
| 129 | try write(png(draw(v, 256, look: .dark, fullBleed: true)), "\(preview)/dark.png") | |
| 130 | try json(["images": [ | |
| 131 | ["filename": "light.png", "idiom": "universal"], | |
| 132 | ["filename": "dark.png", "idiom": "universal", "appearances": [["appearance": "luminosity", "value": "dark"]]], | |
| 133 | ], "info": info], "\(preview)/Contents.json") | |
| 134 | ||
| 135 | // The Mac's Dock icons and picker previews. | |
| 136 | try write(png(draw(v, 512)), "packaging/IconPreviews/\(v.id)-light.png") | |
| 137 | try write(png(draw(v, 512, look: .dark)), "packaging/IconPreviews/\(v.id)-dark.png") | |
| 50 | 138 | } |
| 51 | 139 | |
| 52 | let folder = URL(fileURLWithPath: CommandLine.arguments[1]) | |
| 53 | try FileManager.default.createDirectory(at: folder, withIntermediateDirectories: true) | |
| 140 | // The Mac's bundle icon: the default variant at the Mac's sizes, in each appearance. | |
| 141 | let mac = "packaging/AppIcons.xcassets/AppIcon.appiconset" | |
| 142 | var macImages: [[String: Any]] = [] | |
| 54 | 143 | for base in [16, 32, 128, 256, 512] { |
| 55 | 144 | for scale in [1, 2] { |
| 56 | let name = scale == 1 ? "icon_\(base)x\(base).png" : "icon_\(base)x\(base)@2x.png" | |
| 57 | let data = draw(CGFloat(base * scale)).representation(using: .png, properties: [:])! | |
| 58 | try data.write(to: folder.appendingPathComponent(name)) | |
| 145 | for (look, suffix, appearance) in appearances { | |
| 146 | let name = "icon_\(base)x\(base)\(scale == 2 ? "@2x" : "")\(suffix).png" | |
| 147 | try write(png(draw(variants[0], CGFloat(base * scale), look: look)), "\(mac)/\(name)") | |
| 148 | var image: [String: Any] = ["filename": name, "idiom": "mac", "scale": "\(scale)x", "size": "\(base)x\(base)"] | |
| 149 | if !appearance.isEmpty { image["appearances"] = appearance } | |
| 150 | macImages.append(image) | |
| 151 | } | |
| 59 | 152 | } |
| 60 | 153 | } |
| 154 | try json(["images": macImages, "info": info], "\(mac)/Contents.json") | |
| 155 | try json(["info": info], "packaging/AppIcons.xcassets/Contents.json") | |