"""Draws the Reims-Go wordmark, the README banners and the frontend wordmark data.
The wordmark is monoline lettering: one stroke width, round caps, built
from circles, ellipses and straight lines so it matches the rounded app
icon. Run from the repository root:
python scripts/brand/wordmark.py
It writes .github/readme/banner-{light,dark}.svg,
frontend/src/components/wordmark.gen.ts and frontend/public/logo.svg, and
needs only the standard library.
assets/logo.svg is the source of the icon: this script copies it to
frontend/public/logo.svg and embeds it in the banners. The raster icons
assets/logo.png (embedded by main.go for the tray), build/appicon.png and
build/windows/icon.ico are exported from the same artwork by hand, so
re-export them whenever assets/logo.svg changes.
"""
import math
import re
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
X = 72.0 # x-height, outer edge to outer edge
INK = {"light": "#16182e", "dark": "#f4f5fa"}
MUTED = {"light": "#a3a8bf", "dark": "#5d6382"}
GRADIENT = ("#3b8cff", "#6d5dfc", "#ff7a9a")
BOLT = ("#ffd43b", "#ff9f0a")
PAD = 4 # margin around the wordmark frame
# Roles the frontend loader can paint: CSS classes plus the brand gradient.
TS_INK = {"ink": "ink", "muted": "dash", "go": "brand"}
PATH_ELEMENT = re.compile(r'^" for role, el in parts]
x += width + gap
asc, desc = X + 22 + g.H + 1.5, 22.5 + g.H
pill_el = ""
if pill:
top, bot = -X - 12, desc + 8
x += 14
pill_el = (f'')
asc, desc = max(asc, -top), bot
stops = "".join(f'' for i, c in enumerate(GRADIENT))
bolt = "".join(f'' for i, c in enumerate(BOLT))
defs = (f'{stops}'
f'{bolt}')
body = (f'{defs}{pill_el}{"".join(out)}')
return dict(body=body, width=x, ascent=asc, descent=desc, strokes=strokes, go_start=go0, pill=pill)
def banner(theme, style=STYLE):
logo = (ROOT / "assets/logo.svg").read_text(encoding="utf-8")
icon_body = re.sub(r"^.*?", 1)[0]
wm = wordmark(theme, style)
icon, gap = 180, 26
w = icon + gap + wm["width"] + 6
return (f'\n')
def ts_strokes(strokes):
"""Turns the unpainted (role, element) strokes into TypeScript literals."""
lines = []
for role, el in strokes:
circle = CIRCLE_ELEMENT.match(el)
if circle:
cx, cy, r = circle.groups()
lines.append(f" {{ kind: 'dot', cx: {cx}, cy: {cy}, r: {r} }},")
continue
path = PATH_ELEMENT.match(el)
if path is None or role not in TS_INK:
raise ValueError(f"the frontend loader cannot paint stroke {el!r} with role {role!r}")
lines.append(f" {{ kind: 'path', ink: '{TS_INK[role]}', d: '{path.group(1)}' }},")
return "\n".join(lines)
def ts_module(style=STYLE):
"""Writes the geometry the frontend WordmarkLoader animates.
The loader paints strokes with CSS classes and one gradient, so it needs
the geometry and the gradient extent, not the per-theme colours.
"""
wm = wordmark("light", style)
width, height = wm["width"] + 2 * PAD, wm["ascent"] + wm["descent"] + 2 * PAD
gradient_x1 = wm["go_start"] - (14 if wm["pill"] else 0)
stops = ", ".join(f"'{c}'" for c in GRADIENT)
return (
"// Code generated by scripts/brand/wordmark.py; DO NOT EDIT.\n"
"// Run \"python scripts/brand/wordmark.py\" after changing the wordmark.\n"
"\n"
"export type WordmarkInk = 'ink' | 'dash' | 'brand'\n"
"\n"
"export type WordmarkStroke =\n"
" | { kind: 'path'; ink: WordmarkInk; d: string }\n"
" | { kind: 'dot'; cx: number; cy: number; r: number }\n"
"\n"
"/** viewBox of the wordmark, in generator units. */\n"
f"export const WORDMARK_VIEWBOX = {{ width: {f(width)}, height: {f(height)} }}\n"
"\n"
"/** Translation that puts the generator's baseline frame into the viewBox. */\n"
f"export const WORDMARK_ORIGIN = {{ x: {PAD}, y: {f(PAD + wm['ascent'])} }}\n"
"\n"
f"export const WORDMARK_STROKE_WIDTH = {f(style['stroke'])}\n"
"\n"
"/** Horizontal extent of the brand gradient on the baseline. */\n"
f"export const WORDMARK_GRADIENT = {{ x1: {f(gradient_x1)}, x2: {f(wm['width'])}, stops: [{stops}] }}\n"
"\n"
"/** Strokes in pen order, in the generator's baseline frame. */\n"
"export const WORDMARK_STROKES: WordmarkStroke[] = [\n"
f"{ts_strokes(wm['strokes'])}\n"
"]\n"
)
def main():
# Text outputs use the platform line endings so a rerun leaves the working
# tree clean under core.autocrlf=true as well as on Linux.
for theme in ("light", "dark"):
(ROOT / f".github/readme/banner-{theme}.svg").write_text(banner(theme), encoding="utf-8")
(ROOT / "frontend/src/components/wordmark.gen.ts").write_text(ts_module(), encoding="utf-8")
# The frontend serves the icon from public/, so keep that copy byte-identical.
(ROOT / "frontend/public/logo.svg").write_bytes((ROOT / "assets/logo.svg").read_bytes())
if __name__ == "__main__":
main()