| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- import Foundation
- import CoreGraphics
- import CoreText
- import ImageIO
- import UniformTypeIdentifiers
- // Native vector layout around unmodified simulator screenshots. No fabricated app UI.
- let root = URL(fileURLWithPath: FileManager.default.currentDirectoryPath)
- let outputRoot = root.appendingPathComponent("AppStoreAssets")
- let english = CommandLine.arguments.contains("--english")
- let locale = english ? "en" : "zh-Hans"
- let rawPrefix = english ? "Screenshots/appstore-raw/en" : "Screenshots/appstore-raw"
- let space = CGColorSpace(name: CGColorSpace.sRGB)!
- struct Slide {
- let name: String, screen: String, tag: String, title: [String], subtitle: String, footer: String
- }
- let slides: [Slide] = english ? [
- .init(name: "01-classic", screen: "game", tag: "CLASSIC SUDOKU", title: ["One square.", "New possibilities."], subtitle: "Find a moment of focus, one number at a time.", footer: "Notes · Highlights · Hints & Undo"),
- .init(name: "02-difficulty", screen: "difficulty", tag: "FIVE DIFFICULTIES", title: ["Your level.", "Your challenge."], subtitle: "From Easy to Master, find your next challenge.", footer: "Easy · Medium · Hard · Expert · Master"),
- .init(name: "03-daily", screen: "daily", tag: "DAILY CHALLENGE", title: ["One puzzle a day.", "A star to earn."], subtitle: "Finish a daily puzzle. Light up your calendar.", footer: "Daily puzzles · Past dates to revisit"),
- .init(name: "04-continue", screen: "continue", tag: "SAVE YOUR PROGRESS", title: ["Take a break.", "Pick up your game."], subtitle: "Keep your unfinished puzzle ready for later.", footer: "Automatic saves · Offline play"),
- .init(name: "05-settings", screen: "settings", tag: "MAKE IT YOURS", title: ["Your settings.", "Your way to play."], subtitle: "Fine-tune the little things that help you focus.", footer: "English & Chinese · Highlights · Haptics")
- ] : [
- .init(name: "01-classic", screen: "game", tag: "经典数独", title: ["每一格", "都有新可能"], subtitle: "在数字之间,享受专注思考的片刻", footer: "候选笔记 · 关联高亮 · 提示与撤销"),
- .init(name: "02-difficulty", screen: "difficulty", tag: "五档难度", title: ["从第一题", "到新高度"], subtitle: "简单到大师,找到适合自己的挑战", footer: "简单 · 中等 · 困难 · 专家 · 大师"),
- .init(name: "03-daily", screen: "daily", tag: "每日挑战", title: ["每天一题", "点亮你的日历"], subtitle: "完成每日挑战,让坚持留下星标", footer: "每日固定题目 · 历史日期回顾"),
- .init(name: "04-continue", screen: "continue", tag: "进度接续", title: ["暂停一下", "随时继续"], subtitle: "保留未完成对局,接着上次的思考", footer: "自动保存进度 · 离线也能玩"),
- .init(name: "05-settings", screen: "settings", tag: "随心设置", title: ["顺手的设置", "专注的体验"], subtitle: "按自己的习惯,调整每一次操作", footer: "中英文切换 · 高亮设置 · 触感反馈")
- ]
- func color(_ hex: UInt32, alpha: CGFloat = 1) -> CGColor {
- CGColor(colorSpace: space, components: [CGFloat(hex >> 16 & 255) / 255, CGFloat(hex >> 8 & 255) / 255, CGFloat(hex & 255) / 255, alpha])!
- }
- func load(_ path: String) -> CGImage {
- let source = CGImageSourceCreateWithURL(root.appendingPathComponent(path) as CFURL, nil)!
- return CGImageSourceCreateImageAtIndex(source, 0, nil)!
- }
- func context(_ width: Int, _ height: Int) -> CGContext {
- let context = CGContext(data: nil, width: width, height: height, bitsPerComponent: 8, bytesPerRow: 0, space: space, bitmapInfo: CGImageAlphaInfo.noneSkipLast.rawValue)!
- context.translateBy(x: 0, y: CGFloat(height)); context.scaleBy(x: 1, y: -1)
- context.interpolationQuality = .high
- return context
- }
- func write(_ image: CGImage, to url: URL) {
- let destination = CGImageDestinationCreateWithURL(url as CFURL, UTType.png.identifier as CFString, 1, nil)!
- CGImageDestinationAddImage(destination, image, nil)
- precondition(CGImageDestinationFinalize(destination))
- }
- func drawImage(_ image: CGImage, in rect: CGRect, context c: CGContext) {
- c.saveGState(); c.translateBy(x: rect.minX, y: rect.maxY); c.scaleBy(x: 1, y: -1)
- c.draw(image, in: CGRect(origin: .zero, size: rect.size)); c.restoreGState()
- }
- func line(_ text: String, top: CGFloat, size: CGFloat, ink: UInt32, center: CGFloat = 603, maxWidth: CGFloat = 1100, semibold: Bool = false, tracking: CGFloat = 0, context c: CGContext) {
- var fontSize = size
- var result: CTLine!
- repeat {
- let fontName = english ? (semibold ? "AvenirNext-DemiBold" : "AvenirNext-Regular") : (semibold ? "PingFangSC-Semibold" : "PingFangSC-Regular")
- let font = CTFontCreateWithName(fontName as CFString, fontSize, nil)
- let string = NSAttributedString(string: text, attributes: [NSAttributedString.Key(kCTFontAttributeName as String): font, NSAttributedString.Key(kCTForegroundColorAttributeName as String): color(ink), NSAttributedString.Key(kCTKernAttributeName as String): tracking])
- result = CTLineCreateWithAttributedString(string)
- if CTLineGetTypographicBounds(result, nil, nil, nil) <= maxWidth { break }
- fontSize -= 1
- } while fontSize > 10
- var ascent: CGFloat = 0
- let width = CGFloat(CTLineGetTypographicBounds(result, &ascent, nil, nil))
- c.saveGState(); c.translateBy(x: center - width / 2, y: top + ascent); c.scaleBy(x: 1, y: -1)
- c.textMatrix = .identity; c.textPosition = .zero; CTLineDraw(result, c); c.restoreGState()
- }
- let crown = load("JokerSudoku/Assets.xcassets/JokerCrown.imageset/JokerCrown.png")
- for family in ["iphone", "ipad"] {
- let isPad = family == "ipad"
- let width = isPad ? 2048 : 1206, height = isPad ? 2732 : 2622
- let scale = CGFloat(width) / 1206
- let h = CGFloat(height) / scale
- for (index, slide) in slides.enumerated() {
- let c = context(width, height)
- c.scaleBy(x: scale, y: scale)
- let gradient = CGGradient(colorsSpace: space, colors: [color(0xFBFCFE), color(0xE4EFFC)] as CFArray, locations: [0, 1])!
- c.drawLinearGradient(gradient, start: .zero, end: CGPoint(x: 1206, y: h), options: [])
- c.setFillColor(color(0x338CF2, alpha: 0.07))
- c.fillEllipse(in: CGRect(x: 700, y: isPad ? 140 : 400, width: 1000, height: 1000))
- c.setFillColor(color(0xF2C45C, alpha: 0.10))
- c.fillEllipse(in: CGRect(x: -440, y: h - 800, width: 1000, height: 1000))
- // Quiet nine-box motif, behind the screenshot rather than over the app.
- c.saveGState(); c.translateBy(x: 50, y: h - 350); c.rotate(by: -.pi / 18)
- for number in 0...3 {
- let position = CGFloat(number) * 120
- c.move(to: CGPoint(x: position, y: 0)); c.addLine(to: CGPoint(x: position, y: 360))
- c.move(to: CGPoint(x: 0, y: position)); c.addLine(to: CGPoint(x: 360, y: position))
- }
- c.setStrokeColor(color(0x3979B9, alpha: 0.05)); c.setLineWidth(2); c.strokePath(); c.restoreGState()
- let brandY: CGFloat = isPad ? 35 : 66
- drawImage(crown, in: CGRect(x: 350, y: brandY, width: 64, height: 53), context: c)
- line("JOKER SUDOKU", top: brandY + 10, size: 27, ink: 0x29435E, center: 640, maxWidth: 460, semibold: true, tracking: 5, context: c)
- let kickerTop: CGFloat = isPad ? 104 : 174
- line(String(format: "%02d", index + 1) + " / " + slide.tag, top: kickerTop, size: isPad ? 18 : 22, ink: 0x327DD2, tracking: 2, context: c)
- let titleTop: CGFloat = isPad ? 146 : 242
- let titleSize: CGFloat = isPad ? 65 : 96
- for (row, title) in slide.title.enumerated() {
- line(title, top: titleTop + CGFloat(row) * (isPad ? 79 : 121), size: titleSize, ink: row == 1 ? 0x277DDE : 0x243F5B, semibold: true, tracking: 1, context: c)
- }
- line(slide.subtitle, top: isPad ? 320 : 516, size: isPad ? 24 : 29, ink: 0x60768D, maxWidth: 1050, context: c)
- let screenshot = load("\(rawPrefix)/\(family)/\(slide.screen).png")
- let imageWidth: CGFloat = isPad ? 862 : 852
- let imageHeight = imageWidth * CGFloat(screenshot.height) / CGFloat(screenshot.width)
- let rect = CGRect(x: (1206 - imageWidth) / 2, y: isPad ? 380 : 650, width: imageWidth, height: imageHeight)
- precondition(rect.maxY < h - 45, "Screenshot must fit without cropping")
- let outer = rect.insetBy(dx: -10, dy: -10)
- let rounding: CGFloat = isPad ? 24 : 58
- let bezel = CGPath(roundedRect: outer, cornerWidth: rounding + 9, cornerHeight: rounding + 9, transform: nil)
- c.saveGState(); c.setShadow(offset: CGSize(width: 0, height: 18), blur: 40, color: color(0x163D68, alpha: 0.18))
- c.addPath(bezel); c.setFillColor(color(0x1A304A)); c.fillPath(); c.restoreGState()
- c.saveGState()
- c.addPath(CGPath(roundedRect: rect, cornerWidth: rounding, cornerHeight: rounding, transform: nil)); c.clip()
- drawImage(screenshot, in: rect, context: c); c.restoreGState()
- line(slide.footer, top: h - (isPad ? 52 : 70), size: isPad ? 18 : 22, ink: 0x627A92, tracking: 1, context: c)
- let url = outputRoot.appendingPathComponent("\(locale)/\(family)/\(slide.name).png")
- write(c.makeImage()!, to: url)
- print("\(family)/\(slide.name).png \(width)x\(height)")
- }
- }
- // One contact sheet for reviewing the two complete five-image sets.
- let preview = context(1600, 1340)
- preview.setFillColor(color(0xFFFFFF)); preview.fill(CGRect(x: 0, y: 0, width: 1600, height: 1340))
- for (row, family) in ["iphone", "ipad"].enumerated() {
- let top: CGFloat = row == 0 ? 65 : 805
- line(family == "iphone" ? "iPhone · 1206 × 2622" : "iPad · 2048 × 2732", top: top - 48, size: 26, ink: 0x243F5B, center: 800, semibold: true, context: preview)
- for (column, slide) in slides.enumerated() {
- let image = load("AppStoreAssets/\(locale)/\(family)/\(slide.name).png")
- let w: CGFloat = 292
- drawImage(image, in: CGRect(x: 22 + CGFloat(column) * 316, y: top, width: w, height: w * CGFloat(image.height) / CGFloat(image.width)), context: preview)
- }
- }
- write(preview.makeImage()!, to: outputRoot.appendingPathComponent(english ? "preview-en.png" : "preview.png"))
|