Files
AutoZhuyin/scripts/make-icon.swift
T
ays953andClaude Opus 5.5 6443f771a0 Show English mode in the input method icon
macOS: the input method now has two input modes in Info.plist, 中英自動 ("注")
and 英文 ("A"), each with its own menu-bar icon. A Shift tap with nothing typed
switches the mode (TISSelectInputSource), and choosing a mode in the menu bar
switches the engine (setValue:forTag:). --register enables both modes.
Windows: the taskbar IME icon switches between icon.ico and icon-en.ico.
Linux: the IBus mode property also switches its icon.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 16:56:08 +08:00

24 lines
1.3 KiB
Swift

// Renders a menu-bar icon (one character, "注" by default; "A" for English mode) to a TIFF.
// Usage: swift scripts/make-icon.swift <output.tiff> [character]
import AppKit
let out = CommandLine.arguments.count > 1 ? CommandLine.arguments[1] : "icon.tiff"
let glyph = CommandLine.arguments.count > 2 ? CommandLine.arguments[2] : "注"
let reps: [NSBitmapImageRep] = [16, 32].map { size in
let rep = NSBitmapImageRep(bitmapDataPlanes: nil, pixelsWide: size, pixelsHigh: size,
bitsPerSample: 8, samplesPerPixel: 4, hasAlpha: true, isPlanar: false,
colorSpaceName: .deviceRGB, bytesPerRow: 0, bitsPerPixel: 0)!
rep.size = NSSize(width: 16, height: 16)
NSGraphicsContext.saveGraphicsState()
NSGraphicsContext.current = NSGraphicsContext(bitmapImageRep: rep)
let font = NSFont.systemFont(ofSize: 13, weight: .semibold)
let text = NSAttributedString(string: glyph, attributes: [.font: font, .foregroundColor: NSColor.black])
let s = text.size()
text.draw(at: NSPoint(x: (16 - s.width) / 2, y: (16 - s.height) / 2))
NSGraphicsContext.restoreGraphicsState()
return rep
}
let data = NSBitmapImageRep.tiffRepresentationOfImageReps(in: reps, using: .none, factor: 0)!
try! data.write(to: URL(fileURLWithPath: out))
print("wrote \(out)")