main
John Lauer Save native two-sided contact artwork and recorded GLB material correction; qualification remains open 57e2489
#!/usr/bin/env python3
"""Add compact side-by-side alternatives from the same native glyph extents."""
import json,copy
from pathlib import Path
p=Path(__file__).resolve().parents[1]/'design/silkscreen-review/bottom-candidates.json';s=json.loads(p.read_text());count=0
for g in s['labels']:
 if g['id'] not in ['R'+str(n) for n in range(17,24)]:continue
 original=[c for c in g['candidates'] if c['children'][0].get('angle',0)==0 and not c.get('inline')]
 for t in original:
  if len(t['children'])!=2:continue
  c=copy.deepcopy(t);x,y=c['position'];widths=[z['box'][2]-z['box'][0] for z in c['children']];total=sum(widths)+.2
  # From below, larger X is to the left: reference precedes value.
  centers=[x+total/2-widths[0]/2,x-total/2+widths[1]/2]
  for child,cx in zip(c['children'],centers):
   b=child['box'];dx=cx-(b[0]+b[2])/2;dy=y-(b[1]+b[3])/2;child['x']+=dx;child['y']+=dy;child['box']=[b[0]+dx,b[1]+dy,b[2]+dx,b[3]+dy]
  c['boxes']=[z['box'] for z in c['children']];b=c['boxes'];c['box']=[min(z[0] for z in b),min(z[1] for z in b),max(z[2] for z in b),max(z[3] for z in b)];c['inline']=True;c['qualityPenalty']=.05;g['candidates'].append(c);count+=1
s['candidatesPerLabel']=5000;s['milpPerFont']=256;p.write_text(json.dumps(s)+'\n');print('Added',count,'native-metric inline alternatives')