// SPDX-License-Identifier: GPL-3.0-or-later // Author the native Printer Output nameplate using the approved joystick frame. // Run from the repository root: // swift platforms/macos/Tools/make-printer-badge.swift > docs/media/tandy-thermal-printer-tp-10-badge.svg // rsvg-convert -f pdf -o platforms/macos/Resources/Hardware/printer.pdf docs/media/tandy-thermal-printer-tp-10-badge.svg // An optional first argument supplies a different local Eurostile Bold font path. // Ordinary app builds use the committed vector assets, without font dependencies. import AppKit import CoreText // Direct font loading also works when the authoring shell cannot reach fontd. let fontPath = CommandLine.arguments.dropFirst().first ?? "/Library/Fonts/Microsoft/Eurostile Bold.ttf" guard let provider = CGDataProvider(url: URL(fileURLWithPath: fontPath) as CFURL), let graphicsFont = CGFont(provider) else { fatalError("Supply the path to a locally licensed Eurostile Bold font.") } func number(_ x: CGFloat) -> String { String(format: "%.4f", Double(x)) } func outline(_ text: String, x: CGFloat, y: CGFloat, width: CGFloat, size: CGFloat, color: String) -> String { let font = CTFontCreateWithGraphicsFont(graphicsFont, size, nil, 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.. String { "\(number(x + (width-box.width*scale)/2 + (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 "" } let template = URL(fileURLWithPath: "docs/media/tandy-deluxe-joystick-badge.svg") let doc = try XMLDocument(contentsOf: template) guard let root = doc.rootElement(), let artwork = try root.nodes(forXPath: "./*[local-name()='g']").first as? XMLElement, let oldLabel = artwork.children?.last(where: { ($0 as? XMLElement)?.attribute(forName: "aria-label")?.stringValue == "DELUXE JOYSTICK" }) else { fatalError("The approved joystick badge structure changed.") } oldLabel.detach() let label = try XMLElement(xmlString: "" + outline("THERMAL PRINTER", x: 468, y: 49, width: 672, size: 53, color: "url(#joystick-badge-ink)") + outline("TP-10", x: 468, y: 99, width: 672, size: 49, color: "url(#joystick-badge-ink)") + "") artwork.addChild(label) for title in try root.nodes(forXPath: "./*[local-name()='title']") { title.stringValue = "Tandy Thermal Printer TP-10 badge" } for title in try artwork.nodes(forXPath: "./*[local-name()='title']") { title.stringValue = "TANDY THERMAL PRINTER TP-10" } for desc in try root.nodes(forXPath: "./*[local-name()='desc']") { desc.stringValue = "Silver-bordered black nameplate for the native Printer Output window. A custom TANDY THERMAL PRINTER TP-10 nameplate using the joystick badge style; it does not imply printer graphics or control-code emulation." } for metadata in try root.nodes(forXPath: "./*[local-name()='metadata']") { metadata.stringValue = "Original TP-10 window nameplate with a custom TANDY caption adapting the hardware's Radio Shack/TRS-80 identity. No reference-photograph pixels are embedded. TANDY wordmark: Tandy Corporation; https://commons.wikimedia.org/wiki/File:Tandy_computer_logo.svg (identified there as PD-textlogo and trademarked). Frame and wordmark reuse the Deluxe Joystick badge master. Model lettering is outlined from Eurostile Bold. See ATTRIBUTION.md." } // Give this standalone asset its own stable identifiers. let svg = String(data: doc.xmlData(options: [.nodePrettyPrint]), encoding: .utf8)! print(svg.replacingOccurrences(of: "joystick-", with: "printer-"))