feat(assets): the Parsimony logo
- Add the mark (an envelope in a rounded square) and the wordmark, drawn with monoline strokes so no font is needed - Add light and dark versions, and the generator script - Embed them in a Go package and ship the same files with the admin UI - Test that the SVGs are well formed, need nothing from outside, stay in sync with the admin copies and have enough contrast
This commit is contained in:
parent
6f745e9b25
commit
5f5deb3e30
7 changed files with 243 additions and 1 deletions
19
assets/assets.go
Normal file
19
assets/assets.go
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
// Package assets holds the Parsimony logo. The files are generated by make-logo.py.
|
||||
package assets
|
||||
|
||||
import _ "embed"
|
||||
|
||||
// Mark is the square mark: an envelope in a rounded square. It is also the favicon.
|
||||
//
|
||||
//go:embed logo-mark.svg
|
||||
var Mark string
|
||||
|
||||
// Logo is the mark with the wordmark, for light backgrounds.
|
||||
//
|
||||
//go:embed logo.svg
|
||||
var Logo string
|
||||
|
||||
// LogoDark is the mark with the wordmark, for dark backgrounds.
|
||||
//
|
||||
//go:embed logo-dark.svg
|
||||
var LogoDark string
|
||||
123
assets/assets_test.go
Normal file
123
assets/assets_test.go
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
package assets
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/xml"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var files = map[string]string{"logo-mark.svg": Mark, "logo.svg": Logo, "logo-dark.svg": LogoDark}
|
||||
|
||||
func TestLogosAreWellFormedSVG(t *testing.T) {
|
||||
for name, src := range files {
|
||||
if src == "" {
|
||||
t.Fatalf("%s is empty", name)
|
||||
}
|
||||
dec := xml.NewDecoder(strings.NewReader(src))
|
||||
var root *xml.StartElement
|
||||
for {
|
||||
tok, err := dec.Token()
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("%s: %v", name, err)
|
||||
}
|
||||
if se, ok := tok.(xml.StartElement); ok && root == nil {
|
||||
se := se
|
||||
root = &se
|
||||
}
|
||||
}
|
||||
if root == nil || root.Name.Local != "svg" || root.Name.Space != "http://www.w3.org/2000/svg" {
|
||||
t.Fatalf("%s: root element %+v", name, root)
|
||||
}
|
||||
attrs := map[string]string{}
|
||||
for _, a := range root.Attr {
|
||||
attrs[a.Name.Local] = a.Value
|
||||
}
|
||||
if attrs["viewBox"] == "" || attrs["role"] != "img" || attrs["aria-label"] != "Parsimony" {
|
||||
t.Errorf("%s: it must scale (viewBox) and be named for screen readers: %v", name, attrs)
|
||||
}
|
||||
if attrs["width"] != "" || attrs["height"] != "" {
|
||||
t.Errorf("%s: no fixed size: the page decides", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLogosNeedNothingFromOutside(t *testing.T) {
|
||||
// Inline in a page with a strict CSP, in a README, on a dark background: no fonts, scripts, images or links.
|
||||
for name, src := range files {
|
||||
for _, bad := range []string{"<text", "<script", "<image", "<use", "<style", "xlink:", "href=", "url(", "@import", "font-family", "<foreignObject"} {
|
||||
if strings.Contains(src, bad) {
|
||||
t.Errorf("%s contains %q", name, bad)
|
||||
}
|
||||
}
|
||||
if n := strings.Count(src, "http"); n != 1 {
|
||||
t.Errorf("%s: only the SVG namespace may mention http, found %d", name, n)
|
||||
}
|
||||
if len(src) > 4000 {
|
||||
t.Errorf("%s is %d bytes: a logo should stay tiny", name, len(src))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestTheWordmarkLogosDifferOnlyInColour(t *testing.T) {
|
||||
strip := func(s string) string {
|
||||
for _, c := range []string{"#0f172a", "#ffffff", "#0f766e", "#2dd4bf"} {
|
||||
s = strings.ReplaceAll(s, c, "#")
|
||||
}
|
||||
return s
|
||||
}
|
||||
if strip(Logo) != strip(LogoDark) {
|
||||
t.Fatal("the light and dark logos must have the same shapes")
|
||||
}
|
||||
if Logo == LogoDark {
|
||||
t.Fatal("the dark logo must use light colours")
|
||||
}
|
||||
if !strings.Contains(LogoDark, "#ffffff") || strings.Contains(LogoDark, "#0f172a") {
|
||||
t.Fatal("the dark logo draws the letters in white, not in the dark ink")
|
||||
}
|
||||
if !strings.Contains(Logo, "#0f172a") {
|
||||
t.Fatal("the light logo draws the letters in the dark ink")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTheAdminUIShipsTheSameLogos(t *testing.T) {
|
||||
for public, want := range map[string]string{"../admin/public/favicon.svg": Mark, "../admin/public/logo.svg": Logo} {
|
||||
got, err := os.ReadFile(public)
|
||||
if err != nil {
|
||||
t.Fatalf("%s: %v (copy it from assets/)", public, err)
|
||||
}
|
||||
if !bytes.Equal(got, []byte(want)) {
|
||||
t.Errorf("%s differs from the file in assets/: run `python3 assets/make-logo.py assets` and copy it", public)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The mark is white on teal: that pair must stay readable (WCAG AA for graphics asks 3:1).
|
||||
func TestTheMarkHasEnoughContrast(t *testing.T) {
|
||||
lum := func(hex string) float64 {
|
||||
var r, g, b int
|
||||
if _, err := fmtSscanf(hex, &r, &g, &b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
f := func(c int) float64 {
|
||||
v := float64(c) / 255
|
||||
if v <= 0.03928 {
|
||||
return v / 12.92
|
||||
}
|
||||
return pow((v+0.055)/1.055, 2.4)
|
||||
}
|
||||
return 0.2126*f(r) + 0.7152*f(g) + 0.0722*f(b)
|
||||
}
|
||||
l1, l2 := lum("#ffffff"), lum("#0f766e")
|
||||
if ratio := (l1 + 0.05) / (l2 + 0.05); ratio < 4.5 {
|
||||
t.Fatalf("contrast %.2f:1", ratio)
|
||||
}
|
||||
if !strings.Contains(Mark, "#0f766e") || !strings.Contains(Mark, "#ffffff") {
|
||||
t.Fatal("the contrast test checks the colours the mark really uses")
|
||||
}
|
||||
}
|
||||
11
assets/helpers_test.go
Normal file
11
assets/helpers_test.go
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package assets
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
)
|
||||
|
||||
func fmtSscanf(hex string, r, g, b *int) (int, error) {
|
||||
return fmt.Sscanf(hex, "#%02x%02x%02x", r, g, b)
|
||||
}
|
||||
func pow(x, y float64) float64 { return math.Pow(x, y) }
|
||||
1
assets/logo-dark.svg
Normal file
1
assets/logo-dark.svg
Normal file
|
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 338.7 56.4" role="img" aria-label="Parsimony"><g transform="translate(0 0.2)"><g transform="scale(0.875)"><rect width="64" height="64" rx="15" fill="#2dd4bf"/><g fill="none" stroke="#fff" stroke-width="4.2" stroke-linecap="round" stroke-linejoin="round"><path d="M16 21H48V45H16Z"/><path d="M16 21L32 37.32L48 21"/></g></g></g><g transform="translate(80.2 0.2)" fill="none" stroke="#ffffff" stroke-width="4.4" stroke-linecap="round" stroke-linejoin="round"><g transform="translate(0.0 0)"><path d="M0 16V54"/><circle cx="12" cy="28" r="12"/></g><g transform="translate(32.0 0)"><circle cx="12" cy="28" r="12"/><path d="M24 16V40"/></g><g transform="translate(64.5 0)"><path d="M0 16V40"/><path d="M0 29A13 13 0 0 1 13 16"/></g><g transform="translate(82.0 0)"><path d="M18 21C15 17 11 16 9 16C4 16 2 19.5 2 22.5C2 27 7 28 10.5 29C15 30 18 32 18 35C18 38.5 14 40 9 40C5 40 2 38.5 1 35"/></g><g transform="translate(108.5 0)"><path d="M0 16V40"/><path stroke="#2dd4bf" d="M0 6v0.01"/></g><g transform="translate(117.0 0)"><path d="M0 16V40"/><path d="M0 26A10 10 0 0 1 20 26V40"/><path d="M20 26A10 10 0 0 1 40 26V40"/></g><g transform="translate(165.5 0)"><circle cx="12" cy="28" r="12"/></g><g transform="translate(198.0 0)"><path d="M0 16V40"/><path d="M0 28A12 12 0 0 1 24 28V40"/></g><g transform="translate(230.5 0)"><path d="M0 16L12.6 40"/><path d="M24 16L6 54"/></g></g></svg>
|
||||
|
After Width: | Height: | Size: 1.4 KiB |
1
assets/logo-mark.svg
Normal file
1
assets/logo-mark.svg
Normal file
|
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" role="img" aria-label="Parsimony"><rect width="64" height="64" rx="15" fill="#0f766e"/><g fill="none" stroke="#ffffff" stroke-width="4.2" stroke-linecap="round" stroke-linejoin="round"><path d="M16 21H48V45H16Z"/><path d="M16 21L32 37.32L48 21"/></g></svg>
|
||||
|
After Width: | Height: | Size: 316 B |
1
assets/logo.svg
Normal file
1
assets/logo.svg
Normal file
|
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 338.7 56.4" role="img" aria-label="Parsimony"><g transform="translate(0 0.2)"><g transform="scale(0.875)"><rect width="64" height="64" rx="15" fill="#0f766e"/><g fill="none" stroke="#fff" stroke-width="4.2" stroke-linecap="round" stroke-linejoin="round"><path d="M16 21H48V45H16Z"/><path d="M16 21L32 37.32L48 21"/></g></g></g><g transform="translate(80.2 0.2)" fill="none" stroke="#0f172a" stroke-width="4.4" stroke-linecap="round" stroke-linejoin="round"><g transform="translate(0.0 0)"><path d="M0 16V54"/><circle cx="12" cy="28" r="12"/></g><g transform="translate(32.0 0)"><circle cx="12" cy="28" r="12"/><path d="M24 16V40"/></g><g transform="translate(64.5 0)"><path d="M0 16V40"/><path d="M0 29A13 13 0 0 1 13 16"/></g><g transform="translate(82.0 0)"><path d="M18 21C15 17 11 16 9 16C4 16 2 19.5 2 22.5C2 27 7 28 10.5 29C15 30 18 32 18 35C18 38.5 14 40 9 40C5 40 2 38.5 1 35"/></g><g transform="translate(108.5 0)"><path d="M0 16V40"/><path stroke="#0f766e" d="M0 6v0.01"/></g><g transform="translate(117.0 0)"><path d="M0 16V40"/><path d="M0 26A10 10 0 0 1 20 26V40"/><path d="M20 26A10 10 0 0 1 40 26V40"/></g><g transform="translate(165.5 0)"><circle cx="12" cy="28" r="12"/></g><g transform="translate(198.0 0)"><path d="M0 16V40"/><path d="M0 28A12 12 0 0 1 24 28V40"/></g><g transform="translate(230.5 0)"><path d="M0 16L12.6 40"/><path d="M24 16L6 54"/></g></g></svg>
|
||||
|
After Width: | Height: | Size: 1.4 KiB |
85
assets/make-logo.py
Normal file
85
assets/make-logo.py
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
# Generates the Parsimony logo files: python3 assets/make-logo.py assets
|
||||
# The wordmark is drawn with monoline strokes, not typeset: it needs no font and looks the same everywhere.
|
||||
# The mark is an envelope in a rounded square; the dot of the i echoes it in the accent colour.
|
||||
import math, sys
|
||||
|
||||
INK, TEAL, WHITE = "#0f172a", "#0f766e", "#ffffff"
|
||||
SW = 4.4 # stroke width of the letters
|
||||
H = 24 # x-height
|
||||
B = 40 # baseline y in the wordmark box
|
||||
T = B - H
|
||||
GAP = 8.5
|
||||
|
||||
def circle(cx, cy, r): return f'<circle cx="{cx}" cy="{cy}" r="{r}"/>'
|
||||
def path(d): return f'<path d="{d}"/>'
|
||||
|
||||
def letter(ch):
|
||||
"""returns (svg elements, advance width) with x from 0"""
|
||||
if ch == "o": return circle(12, B-12, 12), 24
|
||||
if ch == "a": return circle(12, B-12, 12) + path(f"M24 {T}V{B}"), 24
|
||||
if ch == "p": return path(f"M0 {T}V{B+14}") + circle(12, B-12, 12), 24
|
||||
if ch == "n": return path(f"M0 {T}V{B}") + path(f"M0 {T+12}A12 12 0 0 1 24 {T+12}V{B}"), 24
|
||||
if ch == "m": return path(f"M0 {T}V{B}") + path(f"M0 {T+10}A10 10 0 0 1 20 {T+10}V{B}") + path(f"M20 {T+10}A10 10 0 0 1 40 {T+10}V{B}"), 40
|
||||
if ch == "r": return path(f"M0 {T}V{B}") + path(f"M0 {T+13}A13 13 0 0 1 13 {T}"), 13
|
||||
if ch == "i": return path(f"M0 {T}V{B}") + f'<path class="dot" d="M0 {T-10}v0.01"/>', 0
|
||||
if ch == "y": return path(f"M0 {T}L12.6 {B}") + path(f"M24 {T}L6 {B+14}"), 24
|
||||
if ch == "s":
|
||||
d = (f"M18 {T+5}C15 {T+1} 11 {T} 9 {T}C4 {T} 2 {T+3.5} 2 {T+6.5}C2 {T+11} 7 {T+12} 10.5 {T+13}"
|
||||
f"C15 {T+14} 18 {T+16} 18 {T+19}C18 {T+22.5} 14 {B} 9 {B}C5 {B} 2 {B-1.5} 1 {B-5}")
|
||||
return path(d), 18
|
||||
raise ValueError(ch)
|
||||
|
||||
def wordmark(text="parsimony"):
|
||||
kern = {("r", "s"): -4.0, ("p", "a"): -0.5}
|
||||
x = 0; out = []; prev = None
|
||||
for ch in text:
|
||||
x += kern.get((prev, ch), 0)
|
||||
svg, w = letter(ch)
|
||||
out.append(f'<g transform="translate({x:.1f} 0)">{svg}</g>')
|
||||
x += w + GAP
|
||||
prev = ch
|
||||
return "".join(out), x - GAP
|
||||
|
||||
def envelope(cx, cy, w=30, h=22, sw=4):
|
||||
"""envelope outline with its flap, centred on cx,cy"""
|
||||
x0, y0, x1, y1 = cx-w/2, cy-h/2, cx+w/2, cy+h/2
|
||||
f = lambda v: f"{v:g}"
|
||||
return (f'<path d="M{f(x0)} {f(y0)}H{f(x1)}V{f(y1)}H{f(x0)}Z"/>'
|
||||
f'<path d="M{f(x0)} {f(y0)}L{f(cx)} {f(cy+h*0.18)}L{f(x1)} {f(y0)}"/>')
|
||||
|
||||
def mark_svg(bg=True, fg=WHITE, bgc=TEAL):
|
||||
s = f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" role="img" aria-label="Parsimony">'
|
||||
if bg: s += f'<rect width="64" height="64" rx="15" fill="{bgc}"/>'
|
||||
s += f'<g fill="none" stroke="{fg}" stroke-width="4.2" stroke-linecap="round" stroke-linejoin="round">{envelope(32, 33, 32, 24)}</g>'
|
||||
s += '</svg>'
|
||||
return s
|
||||
|
||||
def logo_svg(dark=False):
|
||||
ink = WHITE if dark else INK
|
||||
teal = "#2dd4bf" if dark else TEAL
|
||||
wm, ww = wordmark()
|
||||
gap = 22
|
||||
scale = 1.0
|
||||
mark = 56
|
||||
total_w = mark + gap + ww + 4
|
||||
# vertical: mark centred on the x-height band of the wordmark
|
||||
top = T - 14 - 2.2 # i-dot top
|
||||
bottom = B + 14 + 2.2 # descenders
|
||||
h = bottom - top
|
||||
my = (h - mark) / 2
|
||||
tx = mark + gap + 2.2
|
||||
ty = -top
|
||||
s = (f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 {total_w+2.2:.1f} {h:.1f}" role="img" aria-label="Parsimony">'
|
||||
f'<g transform="translate(0 {my:.1f})">'
|
||||
f'<g transform="scale({mark/64})"><rect width="64" height="64" rx="15" fill="{teal}"/>'
|
||||
f'<g fill="none" stroke="#fff" stroke-width="4.2" stroke-linecap="round" stroke-linejoin="round">{envelope(32,33,32,24)}</g></g></g>'
|
||||
f'<g transform="translate({tx:.1f} {ty:.1f})" fill="none" stroke="{ink}" stroke-width="{SW}" stroke-linecap="round" stroke-linejoin="round">{wm}</g>'
|
||||
f'</svg>')
|
||||
s = s.replace('class="dot"', f'stroke="{teal}"')
|
||||
return s
|
||||
|
||||
if __name__ == "__main__":
|
||||
out = sys.argv[1]
|
||||
open(f"{out}/logo.svg","w").write(logo_svg(False))
|
||||
open(f"{out}/logo-dark.svg","w").write(logo_svg(True))
|
||||
open(f"{out}/logo-mark.svg","w").write(mark_svg())
|
||||
Loading…
Reference in a new issue