"""Lanna Desk logo: the mark (a Lanna gable with its crossed kalae horns over a desk) and the wordmark in Sarabun, drawn as outlines so it renders the same everywhere. Writes static/brand/ and static/favicon.svg; the header's copy of the mark is templates/_mark.html. The fonts are forms/fonts/Sarabun-*.ttf (OFL). uv run --with fonttools python scripts/gen_logo.py """ import sys from pathlib import Path from fontTools.pens.svgPathPen import SVGPathPen from fontTools.pens.transformPen import TransformPen from fontTools.ttLib import TTFont ROOT = Path(__file__).resolve().parent.parent OUT = Path(sys.argv[1]) if len(sys.argv) > 1 else ROOT / "static" / "brand" FONTS = ROOT / "forms" / "fonts" NAVY = "#071323" GOLD = "#f5c000" WHITE = "#ffffff" # gold dark enough to read on white (contrast about 3:1 for large type) GOLD_ON_LIGHT = "#b88a00" def text_path(font_file, text, size, x=0.0, y=0.0, tracking=0.0): """The text as one SVG path, baseline at y, and its advance width.""" font = TTFont(font_file) glyphs = font.getGlyphSet() cmap = font.getBestCmap() scale = size / font["head"].unitsPerEm pen = SVGPathPen(glyphs) cursor = 0.0 for ch in text: name = cmap[ord(ch)] g = glyphs[name] tp = TransformPen(pen, (scale, 0, 0, -scale, x + cursor, y)) g.draw(tp) cursor += g.width * scale + tracking return pen.getCommands(), cursor - tracking def mark(roof=GOLD, desk=WHITE, ground=NAVY, rx=14): """The mark in a 64 x 64 box: the gable whose two boards cross at the ridge and end in the kalae's horns, curving outwards, over the desk.""" bg = f'' if ground else "" return ( bg + f'' # the left board: eave, ridge, then on as the right horn, its tip # curling outwards as a kalae's carved horn does '' # the right board: eave, ridge, then on as the left horn '' "" # the desk under the roof, and its two legs f'' '' '' "" ) def svg(w, h, body, title): return ( f'' f"{title}{body}\n" ) def lockup(name_fill, tag_fill, roof, desk, ground): """The mark, then "Lanna Desk" and the line under it.""" bold = FONTS / "Sarabun-Bold.ttf" medium = FONTS / "Sarabun-SemiBold.ttf" name, nw = text_path(bold, "Lanna Desk", 46, x=82, y=42, tracking=0.2) tag, tw = text_path(medium, "CONTRACTS · VISAS · STAYS", 11.2, x=83, y=60, tracking=1.9) w = 82 + max(nw, tw) + 4 body = ( mark(roof, desk, ground) + f'' + f'' ) return svg(round(w, 1), 64, body, "Lanna Desk") def main(): OUT.mkdir(parents=True, exist_ok=True) files = { # the app icon and favicon: navy tile, gold roof, white desk "lannadesk-mark.svg": svg(64, 64, mark(), "Lanna Desk"), # on white: navy tile kept, navy name, dark gold line "lannadesk-logo.svg": lockup(NAVY, GOLD_ON_LIGHT, GOLD, WHITE, NAVY), # on navy or dark: no tile, white name, gold line "lannadesk-logo-dark.svg": lockup(WHITE, GOLD, GOLD, WHITE, None), # one colour, for stamps, fax and engraving "lannadesk-logo-mono.svg": lockup(NAVY, NAVY, NAVY, NAVY, None), } for name, text in files.items(): (OUT / name).write_text(text, encoding="utf-8", newline="\n") print(name, len(text), "bytes") if len(sys.argv) == 1: (ROOT / "static" / "favicon.svg").write_text(files["lannadesk-mark.svg"], encoding="utf-8", newline="\n") (ROOT / "templates" / "_mark.html").write_text( f'\n', encoding="utf-8", newline="\n", ) if __name__ == "__main__": main()