21 lines
1.2 KiB
Python
21 lines
1.2 KiB
Python
import sys,math
|
|
from sample_support import load_docs,BASE
|
|
from render_sample_geometry import entities
|
|
from PIL import Image,ImageDraw,ImageFont
|
|
BOXES={4:(5320,5680,285,370),9:(208400,208530,428000,428120),10:(50,330,60,155),11:(5890,6150,-4900,-4810),12:(16870,17070,-3940,-3850)}
|
|
for n in map(int,sys.argv[1:]):
|
|
m,d=next((m,d) for m,d in load_docs(n) if '01' in m['roles'])
|
|
objs=entities(m['path'],f'profile{n}');xmin,xmax,ymin,ymax=BOXES[n]
|
|
scale=min(2300/(xmax-xmin),1400/(ymax-ymin));im=Image.new('RGB',(2400,1500),'white');dr=ImageDraw.Draw(im)
|
|
def pt(p):return (40+(p[0]-xmin)*scale,1450-(p[1]-ymin)*scale)
|
|
for o in objs:
|
|
segs=[]
|
|
if o['entity']=='LINE':segs=[(o['start'],o['end'])]
|
|
elif o['entity']=='LWPOLYLINE':ps=o.get('points',[]);segs=list(zip(ps,ps[1:]))
|
|
for a,b in segs:
|
|
if all(math.isfinite(v) for v in [*a,*b]):dr.line([pt(a),pt(b)],fill='black',width=1)
|
|
font=ImageFont.truetype('C:/Windows/Fonts/malgun.ttf',14)
|
|
for e in d['texts']:
|
|
if xmin<e['x']<xmax and ymin<e['y']<ymax and len(e['t'])<55:dr.text(pt([e['x'],e['y']]),e['t'],font=font,fill='blue')
|
|
im.save(BASE/f'profile{n}.png');print(n,flush=True)
|