"""Generate the S.E.W.F logo files (text converted to outlines so they render identically everywhere)."""
from fontTools.ttLib import TTFont
from fontTools.pens.svgPathPen import SVGPathPen
from fontTools.pens.transformPen import TransformPen
B="/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf"
F=TTFont(B); gs=F.getGlyphSet(); cmap=F.getBestCmap(); upm=F["head"].unitsPerEm
def text(t,x,y,size,track=0):
    s=size/upm; pen=SVGPathPen(gs); cx=x
    for ch in t:
        g=cmap[ord(ch)]; tp=TransformPen(pen,(s,0,0,-s,cx,y)); gs[g].draw(tp); cx+=gs[g].width*s+track
    return pen.getCommands(), cx
GREEN="#0a3328"; SUN="#f0b323"; BLUE="#1d3fa8"; CREAM="#f3f1e8"
MARK=f'''<clipPath id="c"><rect width="64" height="64" rx="14"/></clipPath><g clip-path="url(#c)">
<rect width="64" height="64" fill="{GREEN}"/><circle cx="40" cy="25" r="16" fill="#134d3b"/><circle cx="40" cy="25" r="9.5" fill="{SUN}"/>
<path d="M0 41Q16 29 34 39T64 35V64H0Z" fill="{BLUE}"/><path d="M0 49Q18 41 36 48T64 46V64H0Z" fill="#0f4a3a"/>
<path d="M0 56Q20 51 38 55T64 54V64H0Z" fill="{CREAM}"/></g>'''
open("brand/logo-mark.svg","w").write(f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" role="img" aria-label="S.E.W.F logo mark">{MARK}</svg>')
open("brand/favicon.svg","w").write(f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64">{MARK}</svg>')
def full(color,name):
    d1,x1=text("S.E.W.F",84,40,34,1.5); d2,_=text("SOCIAL AND ECONOMIC",85,54,9.2,1.1); d3,_=text("WELFARE FOUNDATION",85,66,9.2,1.1)
    svg=(f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 248 72" role="img" aria-label="Social and Economic Welfare Foundation (S.E.W.F)">'
         f'<g transform="translate(4 4)">{MARK}</g><path d="{d1}" fill="{color}"/><path d="{d2}" fill="{color}" opacity=".85"/><path d="{d3}" fill="{color}" opacity=".85"/></svg>')
    open(f"brand/{name}","w").write(svg)
full(GREEN,"logo-full.svg"); full(CREAM,"logo-full-light.svg")
