Compare commits
2 Commits
7ec573a373
...
7eff63a3c4
| Author | SHA1 | Date | |
|---|---|---|---|
| 7eff63a3c4 | |||
| d729d732a1 |
@ -170,3 +170,5 @@ satisfies them — Flutter, web and Python/Tkinter — is in
|
|||||||
app actually uses that status (success/warning/etc.) before adding it.
|
app actually uses that status (success/warning/etc.) before adding it.
|
||||||
- Don't touch `../gatelock` without the production-path verification above;
|
- Don't touch `../gatelock` without the production-path verification above;
|
||||||
a broken import there takes down 3 services at once.
|
a broken import there takes down 3 services at once.
|
||||||
|
|
||||||
|
`logo/` holds the six personal-logo candidates (A-F) and `contact-sheet.png`; regenerate the sheet with `python3 scripts/make_logo_sheet.py` and check one SVG with `python3 scripts/logo_check.py <svg>`.
|
||||||
|
|||||||
9
unified-design-system/logo/a-grid-kuhy.svg
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="512" height="512">
|
||||||
|
<rect id="field" width="512" height="512" fill="#211D1B"/>
|
||||||
|
<g fill="none" stroke="#B8862E" stroke-width="40" stroke-linecap="round" stroke-linejoin="round">
|
||||||
|
<path d="M116 116V236M216 116L116 176L216 236"/>
|
||||||
|
<path d="M296 116V186A50 50 0 0 0 396 186V116"/>
|
||||||
|
<path d="M116 276V396M216 276V396M116 336H216"/>
|
||||||
|
<path d="M296 276L346 336M396 276L346 336V396"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 475 B |
6
unified-design-system/logo/b-k.svg
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="512" height="512">
|
||||||
|
<rect id="field" width="512" height="512" fill="#211D1B"/>
|
||||||
|
<g fill="none" stroke="#B8862E" stroke-width="40" stroke-linecap="round" stroke-linejoin="round">
|
||||||
|
<path d="M176 116V396M346 116L176 256L346 396"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 316 B |
9
unified-design-system/logo/c-kuhy-wordmark.svg
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="512" height="512">
|
||||||
|
<rect id="field" width="512" height="512" fill="#211D1B"/>
|
||||||
|
<g fill="none" stroke="#B8862E" stroke-width="40" stroke-linecap="round" stroke-linejoin="round">
|
||||||
|
<path d="M32 146V326M96 216L32 276L96 326"/>
|
||||||
|
<path d="M160 216V294A32 32 0 0 0 224 294M224 216V326"/>
|
||||||
|
<path d="M288 146V326M288 248A32 32 0 0 1 352 248V326"/>
|
||||||
|
<path d="M416 216L452 306M480 216L430 386"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 483 B |
BIN
unified-design-system/logo/contact-sheet.png
Normal file
|
After Width: | Height: | Size: 251 KiB |
7
unified-design-system/logo/d-ky-ligature.svg
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="512" height="512">
|
||||||
|
<rect id="field" width="512" height="512" fill="#211D1B"/>
|
||||||
|
<g fill="none" stroke="#B8862E" stroke-width="40" stroke-linecap="round" stroke-linejoin="round">
|
||||||
|
<path d="M156 126V386M376 126L156 296L246 386"/>
|
||||||
|
<path d="M236 126L316 172V386"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 353 B |
7
unified-design-system/logo/e-glyph.svg
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="512" height="512">
|
||||||
|
<rect id="field" width="512" height="512" fill="#211D1B"/>
|
||||||
|
<g fill="none" stroke="#B8862E" stroke-width="40" stroke-linecap="round" stroke-linejoin="round">
|
||||||
|
<circle cx="256" cy="256" r="150"/>
|
||||||
|
<path d="M196 119V393M362 150L196 256L362 362"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 356 B |
7
unified-design-system/logo/f-kr.svg
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="512" height="512">
|
||||||
|
<rect id="field" width="512" height="512" fill="#211D1B"/>
|
||||||
|
<g fill="none" stroke="#B8862E" stroke-width="40" stroke-linecap="round" stroke-linejoin="round">
|
||||||
|
<path d="M116 136V376M226 136L116 256L226 376"/>
|
||||||
|
<path d="M286 376V136H336A60 60 0 0 1 336 256H286M336 256L396 376"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 389 B |
138
unified-design-system/scripts/logo_check.py
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
"""Render the four logo legibility checks for one SVG into one PNG.
|
||||||
|
|
||||||
|
Panels, left to right (order is the only label: the PNG is a dev artifact
|
||||||
|
and carries no text):
|
||||||
|
|
||||||
|
1. full colour at 16 px, enlarged to 128 px nearest-neighbour
|
||||||
|
2. one-colour: field dropped, every mark in ink, on paper
|
||||||
|
3. inverted: ink and accent swapped (accent field, ink mark)
|
||||||
|
4. squint: 128 px render blurred, reduced to 16 px, enlarged nearest-neighbour
|
||||||
|
|
||||||
|
A candidate SVG paints its background as an element with ``id="field"`` and
|
||||||
|
uses only the palette's ink and accent. Rendering goes through
|
||||||
|
``rsvg-convert``; compositing through Pillow.
|
||||||
|
|
||||||
|
Run: python3 unified-design-system/scripts/logo_check.py <svg> [--out PNG]
|
||||||
|
Exit 0 = PNG written; 1 = SVG missing or render failed.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import io
|
||||||
|
import re
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import xml.etree.ElementTree as ET
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from PIL import Image, ImageFilter
|
||||||
|
|
||||||
|
INK = "#211D1B"
|
||||||
|
ACCENT = "#B8862E"
|
||||||
|
PAPER = "#F6F4F3"
|
||||||
|
|
||||||
|
PANEL = 128 # every panel is shown at this size
|
||||||
|
SMALL = 16 # favicon-size check
|
||||||
|
SQUINT = 16 # squint grid: blur, then this many pixels across
|
||||||
|
SQUINT_BLUR = 6 # Gaussian radius at PANEL size
|
||||||
|
GAP = 8
|
||||||
|
|
||||||
|
SVG_NS = "http://www.w3.org/2000/svg"
|
||||||
|
ET.register_namespace("", SVG_NS)
|
||||||
|
|
||||||
|
_INK_RE = re.compile(re.escape(INK), re.IGNORECASE)
|
||||||
|
_ACCENT_RE = re.compile(re.escape(ACCENT), re.IGNORECASE)
|
||||||
|
|
||||||
|
|
||||||
|
def render(svg_text: str, size: int) -> Image.Image:
|
||||||
|
"""Rasterise SVG text to a square RGBA image of ``size`` pixels."""
|
||||||
|
png = subprocess.run(
|
||||||
|
["rsvg-convert", "-w", str(size), "-h", str(size), "-f", "png"],
|
||||||
|
input=svg_text.encode(),
|
||||||
|
capture_output=True,
|
||||||
|
check=True,
|
||||||
|
).stdout
|
||||||
|
return Image.open(io.BytesIO(png)).convert("RGBA")
|
||||||
|
|
||||||
|
|
||||||
|
def on_background(image: Image.Image, colour: str) -> Image.Image:
|
||||||
|
"""Flatten an RGBA image onto a solid colour, returning RGB."""
|
||||||
|
base = Image.new("RGBA", image.size, colour)
|
||||||
|
base.alpha_composite(image)
|
||||||
|
return base.convert("RGB")
|
||||||
|
|
||||||
|
|
||||||
|
def enlarge(image: Image.Image, size: int = PANEL) -> Image.Image:
|
||||||
|
"""Scale up with hard pixel edges so small-size artefacts stay visible."""
|
||||||
|
return image.resize((size, size), Image.Resampling.NEAREST)
|
||||||
|
|
||||||
|
|
||||||
|
def inverted(svg_text: str) -> str:
|
||||||
|
"""Swap ink and accent everywhere, so the field turns accent."""
|
||||||
|
placeholder = "#__SWAP__"
|
||||||
|
text = _INK_RE.sub(placeholder, svg_text)
|
||||||
|
text = _ACCENT_RE.sub(INK, text)
|
||||||
|
return text.replace(placeholder, ACCENT)
|
||||||
|
|
||||||
|
|
||||||
|
def one_colour(svg_text: str) -> str:
|
||||||
|
"""Drop the field and paint every mark in ink."""
|
||||||
|
root = ET.fromstring(svg_text)
|
||||||
|
for parent in root.iter():
|
||||||
|
for child in list(parent):
|
||||||
|
if child.get("id") == "field":
|
||||||
|
parent.remove(child)
|
||||||
|
return _ACCENT_RE.sub(INK, ET.tostring(root, encoding="unicode"))
|
||||||
|
|
||||||
|
|
||||||
|
def squint(svg_text: str) -> Image.Image:
|
||||||
|
"""Blur and coarsen the render, the way the mark reads at a glance."""
|
||||||
|
blurred = on_background(render(svg_text, PANEL), PAPER).filter(
|
||||||
|
ImageFilter.GaussianBlur(SQUINT_BLUR)
|
||||||
|
)
|
||||||
|
return blurred.resize((SQUINT, SQUINT), Image.Resampling.BOX)
|
||||||
|
|
||||||
|
|
||||||
|
def panels(svg_text: str) -> list[Image.Image]:
|
||||||
|
"""The four check panels in their fixed order, each PANEL px square."""
|
||||||
|
return [
|
||||||
|
enlarge(on_background(render(svg_text, SMALL), PAPER)),
|
||||||
|
on_background(render(one_colour(svg_text), PANEL), PAPER),
|
||||||
|
on_background(render(inverted(svg_text), PANEL), PAPER),
|
||||||
|
enlarge(squint(svg_text)),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def compose(images: list[Image.Image]) -> Image.Image:
|
||||||
|
"""Lay the panels out in one row with a paper gutter."""
|
||||||
|
width = len(images) * PANEL + (len(images) + 1) * GAP
|
||||||
|
sheet = Image.new("RGB", (width, PANEL + 2 * GAP), PAPER)
|
||||||
|
for index, image in enumerate(images):
|
||||||
|
sheet.paste(image, (GAP + index * (PANEL + GAP), GAP))
|
||||||
|
return sheet
|
||||||
|
|
||||||
|
|
||||||
|
def main(argv: list[str] | None = None) -> int:
|
||||||
|
"""Write ``<svg stem>-check.png`` (or ``--out``) for one candidate SVG."""
|
||||||
|
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
||||||
|
parser.add_argument("svg", type=Path)
|
||||||
|
parser.add_argument("--out", type=Path)
|
||||||
|
args = parser.parse_args(argv)
|
||||||
|
svg: Path = args.svg
|
||||||
|
if not svg.is_file():
|
||||||
|
print(f"logo_check: no such file: {svg}", file=sys.stderr)
|
||||||
|
return 1
|
||||||
|
out: Path = args.out or svg.with_name(f"{svg.stem}-check.png")
|
||||||
|
try:
|
||||||
|
sheet = compose(panels(svg.read_text()))
|
||||||
|
except (subprocess.CalledProcessError, ET.ParseError) as exc:
|
||||||
|
print(f"logo_check: cannot render {svg}: {exc}", file=sys.stderr)
|
||||||
|
return 1
|
||||||
|
sheet.save(out, optimize=True)
|
||||||
|
print(out)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
sys.exit(main())
|
||||||
152
unified-design-system/scripts/make_logo_sheet.py
Normal file
@ -0,0 +1,152 @@
|
|||||||
|
"""Build the logo contact sheet from the candidate SVGs in ``logo/``.
|
||||||
|
|
||||||
|
One row per candidate (``a-*.svg`` .. ``f-*.svg``, sorted by name). Columns,
|
||||||
|
left to right: full colour, one-colour, inverted, each at 512, 64 and 16 px
|
||||||
|
true size, centred in a 512 px cell. No labels: row order is file order and
|
||||||
|
column order is fixed, because the sheet is a dev artifact and carries no text.
|
||||||
|
|
||||||
|
Every SVG is validated first, and the sheet is not written if any fails:
|
||||||
|
flat 512 viewBox, an ``id="field"`` background, only ink and accent, one
|
||||||
|
stroke weight, and no gradients, filters, text, fonts, styles or images.
|
||||||
|
|
||||||
|
Run: python3 unified-design-system/scripts/make_logo_sheet.py
|
||||||
|
Exit 0 = sheet written; 1 = no candidates or an invalid SVG.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
import xml.etree.ElementTree as ET
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from logo_check import ACCENT, INK, PAPER, inverted, on_background, one_colour, render
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
|
LOGO_DIR = Path(__file__).resolve().parents[1] / "logo"
|
||||||
|
STROKE = 40 # the one stroke weight every candidate uses, on a 512 canvas
|
||||||
|
VIEWBOX = "0 0 512 512"
|
||||||
|
SIZES = (512, 64, 16)
|
||||||
|
VARIANTS = ("colour", "one-colour", "inverted")
|
||||||
|
CELL = 512
|
||||||
|
GAP = 32
|
||||||
|
|
||||||
|
BANNED_TAGS = frozenset(
|
||||||
|
{
|
||||||
|
"linearGradient",
|
||||||
|
"radialGradient",
|
||||||
|
"filter",
|
||||||
|
"text",
|
||||||
|
"tspan",
|
||||||
|
"textPath",
|
||||||
|
"font",
|
||||||
|
"font-face",
|
||||||
|
"style",
|
||||||
|
"image",
|
||||||
|
"pattern",
|
||||||
|
"mask",
|
||||||
|
"foreignObject",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
BANNED_ATTRS = frozenset({"filter", "style", "font-family", "font", "class"})
|
||||||
|
ALLOWED_PAINT = frozenset({INK.lower(), ACCENT.lower(), "none"})
|
||||||
|
|
||||||
|
_STROKE_RE = re.compile(r'stroke-width="([^"]+)"')
|
||||||
|
|
||||||
|
|
||||||
|
def _local(name: str) -> str:
|
||||||
|
"""Strip an ``{namespace}`` prefix from an element or attribute name."""
|
||||||
|
return name.rsplit("}", 1)[-1]
|
||||||
|
|
||||||
|
|
||||||
|
def candidates(directory: Path) -> list[Path]:
|
||||||
|
"""Candidate SVGs, sorted by file name (a..f)."""
|
||||||
|
return sorted(directory.glob("*.svg"))
|
||||||
|
|
||||||
|
|
||||||
|
def stroke_widths(svg_text: str) -> set[str]:
|
||||||
|
"""Every distinct ``stroke-width`` value in the SVG."""
|
||||||
|
return set(_STROKE_RE.findall(svg_text))
|
||||||
|
|
||||||
|
|
||||||
|
def problems(svg_text: str) -> list[str]:
|
||||||
|
"""Reasons the SVG breaks the flat-logo rules; empty when it is valid."""
|
||||||
|
try:
|
||||||
|
root = ET.fromstring(svg_text)
|
||||||
|
except ET.ParseError as exc:
|
||||||
|
return [f"not XML: {exc}"]
|
||||||
|
found: list[str] = []
|
||||||
|
if root.get("viewBox") != VIEWBOX:
|
||||||
|
found.append(f"viewBox must be {VIEWBOX!r}")
|
||||||
|
if not any(el.get("id") == "field" for el in root.iter()):
|
||||||
|
found.append('no id="field" background')
|
||||||
|
for el in root.iter():
|
||||||
|
tag = _local(el.tag)
|
||||||
|
if tag in BANNED_TAGS:
|
||||||
|
found.append(f"banned element <{tag}>")
|
||||||
|
for attr, value in el.attrib.items():
|
||||||
|
name = _local(attr)
|
||||||
|
if name in BANNED_ATTRS:
|
||||||
|
found.append(f"banned attribute {name} on <{tag}>")
|
||||||
|
if name in {"fill", "stroke"} and value.lower() not in ALLOWED_PAINT:
|
||||||
|
found.append(f"{name}={value!r} on <{tag}> is not ink or accent")
|
||||||
|
widths = stroke_widths(svg_text) - {str(STROKE)}
|
||||||
|
if widths:
|
||||||
|
found.append(f"stroke-width {sorted(widths)} is not {STROKE}")
|
||||||
|
return found
|
||||||
|
|
||||||
|
|
||||||
|
def variant_text(svg_text: str, variant: str) -> str:
|
||||||
|
"""The SVG source for one column variant."""
|
||||||
|
if variant == "one-colour":
|
||||||
|
return one_colour(svg_text)
|
||||||
|
if variant == "inverted":
|
||||||
|
return inverted(svg_text)
|
||||||
|
return svg_text
|
||||||
|
|
||||||
|
|
||||||
|
def build_sheet(svgs: list[Path]) -> Image.Image:
|
||||||
|
"""Render every candidate in every variant and size into one image."""
|
||||||
|
cols = len(VARIANTS) * len(SIZES)
|
||||||
|
width = cols * CELL + (cols + 1) * GAP
|
||||||
|
height = len(svgs) * CELL + (len(svgs) + 1) * GAP
|
||||||
|
sheet = Image.new("RGB", (width, height), PAPER)
|
||||||
|
for row, svg in enumerate(svgs):
|
||||||
|
source = svg.read_text()
|
||||||
|
top = GAP + row * (CELL + GAP)
|
||||||
|
for v, variant in enumerate(VARIANTS):
|
||||||
|
text = variant_text(source, variant)
|
||||||
|
for s, size in enumerate(SIZES):
|
||||||
|
left = GAP + (v * len(SIZES) + s) * (CELL + GAP)
|
||||||
|
offset = (CELL - size) // 2
|
||||||
|
image = on_background(render(text, size), PAPER)
|
||||||
|
sheet.paste(image, (left + offset, top + offset))
|
||||||
|
return sheet
|
||||||
|
|
||||||
|
|
||||||
|
def main(argv: list[str] | None = None) -> int:
|
||||||
|
"""Validate the candidates, then write the contact sheet PNG."""
|
||||||
|
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
||||||
|
parser.add_argument("--dir", type=Path, default=LOGO_DIR)
|
||||||
|
parser.add_argument("--out", type=Path)
|
||||||
|
args = parser.parse_args(argv)
|
||||||
|
svgs = candidates(args.dir)
|
||||||
|
if not svgs:
|
||||||
|
print(f"make_logo_sheet: no SVGs in {args.dir}", file=sys.stderr)
|
||||||
|
return 1
|
||||||
|
bad = {svg.name: problems(svg.read_text()) for svg in svgs}
|
||||||
|
bad = {name: found for name, found in bad.items() if found}
|
||||||
|
for name, found in bad.items():
|
||||||
|
for problem in found:
|
||||||
|
print(f"make_logo_sheet: {name}: {problem}", file=sys.stderr)
|
||||||
|
if bad:
|
||||||
|
return 1
|
||||||
|
out: Path = args.out or args.dir / "contact-sheet.png"
|
||||||
|
build_sheet(svgs).save(out, optimize=True)
|
||||||
|
print(out)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
sys.exit(main())
|
||||||
4
unified-design-system/tests/fixtures/logo-fixture.svg
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="512" height="512">
|
||||||
|
<rect id="field" width="512" height="512" fill="#211D1B"/>
|
||||||
|
<path d="M176 136V376M336 136L176 256L336 376" fill="none" stroke="#B8862E" stroke-width="40" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 301 B |
80
unified-design-system/tests/test_logo_check.py
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
"""Tests for logo_check.py: one PNG, four panels, hard pixel edges, no text."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import shutil
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
Image = pytest.importorskip("PIL.Image")
|
||||||
|
if shutil.which("rsvg-convert") is None: # pragma: no cover - env guard
|
||||||
|
pytest.skip("rsvg-convert not installed", allow_module_level=True)
|
||||||
|
|
||||||
|
import logo_check
|
||||||
|
|
||||||
|
FIXTURE = Path(__file__).parent / "fixtures" / "logo-fixture.svg"
|
||||||
|
INK = (0x21, 0x1D, 0x1B)
|
||||||
|
ACCENT = (0xB8, 0x86, 0x2E)
|
||||||
|
|
||||||
|
|
||||||
|
def _panel(sheet: Image.Image, index: int) -> Image.Image:
|
||||||
|
left = logo_check.GAP + index * (logo_check.PANEL + logo_check.GAP)
|
||||||
|
top = logo_check.GAP
|
||||||
|
return sheet.crop((left, top, left + logo_check.PANEL, top + logo_check.PANEL))
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def sheet(tmp_path: Path) -> Image.Image:
|
||||||
|
out = tmp_path / "check.png"
|
||||||
|
assert logo_check.main([str(FIXTURE), "--out", str(out)]) == 0
|
||||||
|
assert out.is_file()
|
||||||
|
return Image.open(out).convert("RGB")
|
||||||
|
|
||||||
|
|
||||||
|
def test_sheet_has_four_panels_side_by_side(sheet: Image.Image) -> None:
|
||||||
|
gap, panel = logo_check.GAP, logo_check.PANEL
|
||||||
|
assert sheet.size == (4 * panel + 5 * gap, panel + 2 * gap)
|
||||||
|
|
||||||
|
|
||||||
|
def test_small_panel_is_nearest_neighbour_blocks(sheet: Image.Image) -> None:
|
||||||
|
"""The 16 px render is enlarged 8x with hard edges: every 8x8 block is flat."""
|
||||||
|
small = _panel(sheet, 0)
|
||||||
|
step = logo_check.PANEL // logo_check.SMALL
|
||||||
|
for by in range(logo_check.SMALL):
|
||||||
|
for bx in range(logo_check.SMALL):
|
||||||
|
block = small.crop((bx * step, by * step, (bx + 1) * step, (by + 1) * step))
|
||||||
|
assert len(block.getcolors()) == 1
|
||||||
|
|
||||||
|
|
||||||
|
def test_squint_panel_is_nearest_neighbour_blocks(sheet: Image.Image) -> None:
|
||||||
|
squint = _panel(sheet, 3)
|
||||||
|
step = logo_check.PANEL // logo_check.SQUINT
|
||||||
|
block = squint.crop((0, 0, step, step))
|
||||||
|
assert len(block.getcolors()) == 1
|
||||||
|
assert len(squint.getcolors(maxcolors=4096)) > 2 # blurred, not flat
|
||||||
|
|
||||||
|
|
||||||
|
def test_one_colour_panel_uses_ink_on_paper_only(sheet: Image.Image) -> None:
|
||||||
|
panel = _panel(sheet, 1)
|
||||||
|
colours = {c for _, c in panel.getcolors(maxcolors=4096)}
|
||||||
|
assert INK in colours
|
||||||
|
assert ACCENT not in colours
|
||||||
|
|
||||||
|
|
||||||
|
def test_inverted_panel_swaps_field_and_mark(sheet: Image.Image) -> None:
|
||||||
|
panel = _panel(sheet, 2)
|
||||||
|
assert panel.getpixel((2, 2)) == ACCENT # field corner is now accent
|
||||||
|
colours = {c for _, c in panel.getcolors(maxcolors=4096)}
|
||||||
|
assert INK in colours
|
||||||
|
|
||||||
|
|
||||||
|
def test_default_out_path_sits_next_to_svg(tmp_path: Path) -> None:
|
||||||
|
svg = tmp_path / "x.svg"
|
||||||
|
svg.write_text(FIXTURE.read_text())
|
||||||
|
assert logo_check.main([str(svg)]) == 0
|
||||||
|
assert (tmp_path / "x-check.png").is_file()
|
||||||
|
|
||||||
|
|
||||||
|
def test_missing_svg_exits_nonzero(tmp_path: Path) -> None:
|
||||||
|
assert logo_check.main([str(tmp_path / "nope.svg")]) == 1
|
||||||
91
unified-design-system/tests/test_make_logo_sheet.py
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
"""Tests for make_logo_sheet.py: valid flat SVGs in, one contact sheet out."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import shutil
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
Image = pytest.importorskip("PIL.Image")
|
||||||
|
if shutil.which("rsvg-convert") is None: # pragma: no cover - env guard
|
||||||
|
pytest.skip("rsvg-convert not installed", allow_module_level=True)
|
||||||
|
|
||||||
|
import make_logo_sheet
|
||||||
|
|
||||||
|
LOGO_DIR = Path(__file__).resolve().parents[1] / "logo"
|
||||||
|
GOOD = (Path(__file__).parent / "fixtures" / "logo-fixture.svg").read_text()
|
||||||
|
|
||||||
|
|
||||||
|
def test_six_candidates_exist() -> None:
|
||||||
|
names = [p.name[0] for p in make_logo_sheet.candidates(LOGO_DIR)]
|
||||||
|
assert names == list("abcdef")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("svg", sorted(LOGO_DIR.glob("*.svg")), ids=lambda p: p.name)
|
||||||
|
def test_candidate_is_valid_flat_svg(svg: Path) -> None:
|
||||||
|
assert make_logo_sheet.problems(svg.read_text()) == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_one_stroke_weight_across_candidates() -> None:
|
||||||
|
widths = {
|
||||||
|
w
|
||||||
|
for svg in make_logo_sheet.candidates(LOGO_DIR)
|
||||||
|
for w in make_logo_sheet.stroke_widths(svg.read_text())
|
||||||
|
}
|
||||||
|
assert widths == {str(make_logo_sheet.STROKE)}
|
||||||
|
|
||||||
|
|
||||||
|
def test_fixture_is_valid() -> None:
|
||||||
|
assert make_logo_sheet.problems(GOOD) == []
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("needle", "replacement"),
|
||||||
|
[
|
||||||
|
("<path", '<linearGradient id="g"/><path'),
|
||||||
|
("<path", '<radialGradient id="g"/><path'),
|
||||||
|
("<path", '<filter id="f"/><path'),
|
||||||
|
("<path", "<text>k</text><path"),
|
||||||
|
("<path", '<path font-family="Inter"'),
|
||||||
|
("<path", '<path filter="url(#f)"'),
|
||||||
|
("<path", '<path style="fill:red"'),
|
||||||
|
('stroke="#B8862E"', 'stroke="#FF0000"'),
|
||||||
|
('id="field" ', ""),
|
||||||
|
('viewBox="0 0 512 512"', 'viewBox="0 0 100 100"'),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_banned_content_is_reported(needle: str, replacement: str) -> None:
|
||||||
|
assert make_logo_sheet.problems(GOOD.replace(needle, replacement, 1))
|
||||||
|
|
||||||
|
|
||||||
|
def test_unparseable_svg_is_reported() -> None:
|
||||||
|
assert make_logo_sheet.problems("<svg") != []
|
||||||
|
|
||||||
|
|
||||||
|
def test_main_writes_sheet(tmp_path: Path) -> None:
|
||||||
|
out = tmp_path / "sheet.png"
|
||||||
|
assert make_logo_sheet.main(["--dir", str(LOGO_DIR), "--out", str(out)]) == 0
|
||||||
|
sheet = Image.open(out)
|
||||||
|
rows, cols = 6, len(make_logo_sheet.VARIANTS) * len(make_logo_sheet.SIZES)
|
||||||
|
cell, gap = make_logo_sheet.CELL, make_logo_sheet.GAP
|
||||||
|
assert sheet.size == (
|
||||||
|
cols * cell + (cols + 1) * gap,
|
||||||
|
rows * cell + (rows + 1) * gap,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_main_refuses_invalid_svg(tmp_path: Path) -> None:
|
||||||
|
(tmp_path / "a-bad.svg").write_text(GOOD.replace("<path", "<text>k</text><path"))
|
||||||
|
assert (
|
||||||
|
make_logo_sheet.main(["--dir", str(tmp_path), "--out", str(tmp_path / "s.png")])
|
||||||
|
== 1
|
||||||
|
)
|
||||||
|
assert not (tmp_path / "s.png").exists()
|
||||||
|
|
||||||
|
|
||||||
|
def test_main_refuses_empty_dir(tmp_path: Path) -> None:
|
||||||
|
assert (
|
||||||
|
make_logo_sheet.main(["--dir", str(tmp_path), "--out", str(tmp_path / "s.png")])
|
||||||
|
== 1
|
||||||
|
)
|
||||||