import re,subprocess,os,sys,math,shutil LOGO,MAGPDF,SPKPDF,OUT=sys.argv[1:5] NAVY='#002664'; NAVY_L='#123D85'; RED='#B12332'; INK='#0B0F12'; GHOST='#1C2229'; BLUE_L='#2F62C4'; K=0.2679 def find(b): for p in ['/opt/homebrew/bin/'+b,shutil.which(b) or '']: if p and os.path.exists(p): return p def die(pdf): svg=os.path.join(OUT,'_src.svg') subprocess.check_call([find('pdftocairo'),'-svg',pdf,svg]) s=open(svg).read(); os.remove(svg); body=s[s.index(''):] W,H=map(float,re.search(r'viewBox="0 0 ([\d.]+) ([\d.]+)"',s).groups()) paths=re.findall(r']*fill="([^"]+)"[^>]* d="([^"]+)"',body) i=max(k for k,(c,d) in enumerate(paths) if not c.replace(' ','').startswith('rgb(100%,100%,100%)')) return W,H,paths[i][1] s=open(LOGO).read() LW,LH=map(float,re.search(r'viewBox="[\d.]+ [\d.]+ ([\d.]+) ([\d.]+)"',s).groups()) inner=s[s.index('>',s.index('')].replace(' vector-effect="non-scaling-stroke"','') def _bb(d): n=list(map(float,re.findall(r'-?\d+\.?\d*',re.sub(r'A [^LQCMZAHV]*','',d)))); return max(n[0::2])-min(n[0::2]) for m in list(re.finditer(r'',inner,flags=re.S)): if _bb(m.group(1))>LW*0.97: inner=inner.replace(m.group(0),'') def _box(d): n=list(map(float,re.findall(r'-?\d+\.?\d*',re.sub(r'A [^LQCMZAHV]*','',d)))); return min(n[0::2]),min(n[1::2]),max(n[0::2]),max(n[1::2]) CUT=[(241,102,319,190),(958,65,1079,210)] for m in list(re.finditer(r'',inner,flags=re.S)): b=_box(m.group(1)) if any(max(abs(b[i]-c[i]) for i in range(4))<3 for c in CUT): inner=inner.replace(m.group(0),'') STAR='' fills=re.findall(r'%s%s' %(x,y,sc,key,key,kw,k,STAR+inner)), w*LH/LW def star(cx,cy,r,fill,rot=-90): pts=[] for i in range(10): a=math.radians(rot+i*36); rr=r if i%2==0 else r*0.382 pts.append('%.2f,%.2f'%(cx+rr*math.cos(a),cy+rr*math.sin(a))) return ''%(' '.join(pts),fill) def slant(x,w,y0,y1,fill): return ''%(x-K*y0,y0,x+w-K*y0,y0,x+w-K*y1,y1,x-K*y1,y1,fill) def wrap(W,H,d,g): return ('' '%s')%(W,H,W,H,d,g) def place(W,cy): w=W*0.86; h=w*LH/LW; return (W-w)/2,cy-h/2,w,h def starfield(W,H,d,cy): g=''%(d,NAVY) r=0; y=6 while y