Files
VCCPlusOSS/platforms/macos/Tools/make-orchestra-label.swift
T

85 lines
5.1 KiB
Swift

// SPDX-License-Identifier: GPL-3.0-or-later
// Outlined vector adaptation of the historical Tandy Orchestra-90 label.
// Usage: swift platforms/macos/Tools/make-orchestra-label.swift > docs/media/orchestra-90-label.svg
import AppKit
import CoreText
func number(_ x: CGFloat) -> String { String(format: "%.4f", Double(x)) }
func glyphPath(_ text: String, size: CGFloat) -> CGPath {
let font = CTFontCreateWithName("EurostileBold" as CFString, size, nil)
precondition(CTFontCopyPostScriptName(font) as String == "EurostileBold", "Label authoring requires Eurostile Bold; ordinary builds use the committed SVG/PDF assets.")
let line = CTLineCreateWithAttributedString(NSAttributedString(string: text, attributes: [.font: font]))
let path = CGMutablePath()
for run in CTLineGetGlyphRuns(line) as! [CTRun] {
let count = CTRunGetGlyphCount(run)
var glyphs = [CGGlyph](repeating: 0, count: count), points = [CGPoint](repeating: .zero, count: count)
CTRunGetGlyphs(run, CFRange(location: 0, length: 0), &glyphs)
CTRunGetPositions(run, CFRange(location: 0, length: 0), &points)
for i in 0..<count {
if let glyph = CTFontCreatePathForGlyph(font, glyphs[i], nil) {
path.addPath(glyph, transform: CGAffineTransform(translationX: points[i].x, y: points[i].y))
}
}
}
return path
}
func outline(_ text: String, x: CGFloat, y: CGFloat, width: CGFloat, size: CGFloat, color: String, centered: Bool = false) -> String {
let path = glyphPath(text, size: size)
let box = path.boundingBoxOfPath, scale = min(1, width / box.width)
let originX = centered ? x + (width - box.width * scale) / 2 : x
var d = ""
func point(_ p: CGPoint) -> String { "\(number(originX + (p.x-box.minX)*scale)) \(number(y + (box.maxY-p.y)*scale))" }
path.applyWithBlock { e in
let e = e.pointee
switch e.type {
case .moveToPoint: d += "M " + point(e.points[0])
case .addLineToPoint: d += " L " + point(e.points[0])
case .addQuadCurveToPoint: d += " Q " + point(e.points[0]) + " " + point(e.points[1])
case .addCurveToPoint: d += " C " + point(e.points[0]) + " " + point(e.points[1]) + " " + point(e.points[2])
case .closeSubpath: d += " Z "
@unknown default: break
}
}
return "<path aria-label=\"\(text)\" fill=\"\(color)\" d=\"\(d)\"/>"
}
if CommandLine.arguments.contains("--sdc") {
// Center the color bars and title as one logo using the actual glyph ink,
// rather than the maximum width reserved for text that may be shorter.
let logoWidth = 90 + min(343, glyphPath("CoCo SDC", size: 58).boundingBoxOfPath.width)
let logoX = (480 - logoWidth) / 2
print("""
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 480 280" width="480" height="280">
<title>CoCo SDC cartridge label</title>
<desc>Original outlined label based on the Retro Rewind CoCo SDC cartridge reference. No reference-photograph pixels or font files are embedded. See ATTRIBUTION.md.</desc>
<rect width="480" height="280" rx="12" fill="#eeefed"/>
<g transform="translate(\(number(logoX - 20)) 0)">
<path d="M27 53 h19 l-7 40 h-19z" fill="#df5737"/>
<path d="M52 53 h19 l-7 40 h-19z" fill="#239c71"/>
<path d="M77 53 h19 l-7 40 h-19z" fill="#249bc9"/>
</g>
<path d="M210 207 h48 l14 14 v37 h-62z" fill="none" stroke="#53595a" stroke-width="5"/>
<path d="M219 212 v15 m10-15 v15 m10-15 v15" stroke="#53595a" stroke-width="5"/>
""")
print(outline("CoCo SDC", x: logoX + 90, y: 48, width: 343, size: 58, color: "#171d20"))
print(outline("FLOPPY DISK EMULATOR", x: 35, y: 123, width: 410, size: 29, color: "#343b3e", centered: true))
print(outline("FOR COLOR COMPUTERS", x: 40, y: 164, width: 400, size: 27, color: "#343b3e", centered: true))
print("</svg>")
exit(0)
}
let speech = CommandLine.arguments.contains("--speech")
print("""
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 480 280" width="480" height="280">
<title>\(speech ? "Speech/Sound" : "Orchestra-90") cartridge label</title>
<desc>Vector label adapted from historical Tandy cartridge-label references. Eurostile Bold lettering is outlined; no scanned pixels or font files are embedded. See ATTRIBUTION.md.</desc>
<defs><linearGradient id="orchestra-silver" x2="0.2" y2="1"><stop stop-color="#c5c7c9"/><stop offset="0.5" stop-color="#e0e1df"/><stop offset="1" stop-color="#b6b9bc"/></linearGradient></defs>
<rect width="480" height="280" rx="8" fill="url(#orchestra-silver)"/>
<path d="M0 21 H480 M0 259 H480" stroke="#283c92" stroke-width="5"/>
<path d="M0 29 H480 M0 251 H480" stroke="#68964b" stroke-width="5"/>
<path d="M0 37 H480 M0 243 H480" stroke="#b93528" stroke-width="5"/>
""")
print(outline("TANDY", x: 22, y: 63, width: 130, size: 33, color: "#283c92"))
print(outline(speech ? "COLOR COMPUTER" : "ORCHESTRA 90-CC", x: 174, y: 69, width: 280, size: 25, color: "#171c20"))
for (i, line) in (speech ? ["SPEECH", "SOUND", "CARTRIDGE"] : ["STEREO", "MUSIC", "SYNTHESIZER"]).enumerated() {
print(outline(line, x: 174, y: CGFloat(124+i*33), width: 280, size: 31, color: "#171c20"))
}
print("</svg>")