#!/usr/bin/env python3 """LaserCutReady house-number vectors · CC BY 4.0 · Python 3 standard library.""" from argparse import ArgumentParser from pathlib import Path import re PROFILE = 'M12 0 H228 L240 12 V93 L228 105 H12 L0 93 V12 Z' SCORE = 'M28 16 H212 M28 89 H212' DIGITS = { '0':'M9 0 H19 Q28 0 28 9 V39 Q28 48 19 48 H9 Q0 48 0 39 V9 Q0 0 9 0 Z M10 7 Q7 7 7 11 V37 Q7 41 10 41 H18 Q21 41 21 37 V11 Q21 7 18 7 Z', '1':'M4 9 L12 0 H20 V41 H27 V48 H6 V41 H13 V10 L8 14 Z', '2':'M1 11 Q1 0 11 0 H18 Q28 0 28 10 V16 Q28 21 23 25 L9 36 Q7 38 7 41 H28 V48 H0 V42 Q0 34 5 30 L18 20 Q21 18 21 15 V11 Q21 7 17 7 H12 Q8 7 8 11 V13 H1 Z', '3':'M1 9 Q1 0 11 0 H18 Q28 0 28 9 V17 Q28 22 24 24 Q28 26 28 31 V39 Q28 48 18 48 H11 Q1 48 1 39 V35 H8 V38 Q8 41 12 41 H16 Q21 41 21 37 V32 Q21 28 17 28 H10 V21 H17 Q21 21 21 17 V11 Q21 7 17 7 H12 Q8 7 8 11 V13 H1 Z', '4':'M16 0 H24 V29 H28 V36 H24 V48 H17 V36 H0 V29 Z M17 12 L7 29 H17 Z', '5':'M2 0 H27 V7 H9 V19 Q11 18 13 18 H18 Q28 18 28 28 V38 Q28 48 18 48 H10 Q0 48 0 38 V34 H7 V37 Q7 41 11 41 H17 Q21 41 21 37 V29 Q21 25 17 25 H12 Q9 25 8 28 H2 Z', '6':'M0 11 Q0 0 11 0 H18 Q28 0 28 10 V13 H21 V11 Q21 7 17 7 H12 Q7 7 7 12 V20 Q9 18 13 18 H18 Q28 18 28 27 V39 Q28 48 18 48 H10 Q0 48 0 38 Z M7 30 V37 Q7 41 11 41 H17 Q21 41 21 37 V29 Q21 25 17 25 H12 Q7 25 7 30 Z', '7':'M0 0 H28 V7 L12 48 H4 L20 7 H0 Z', '8':'M0 10 Q0 0 10 0 H18 Q28 0 28 10 V16 Q28 21 24 24 Q28 27 28 32 V38 Q28 48 18 48 H10 Q0 48 0 38 V32 Q0 27 4 24 Q0 21 0 16 Z M7 12 V16 Q7 21 12 21 H16 Q21 21 21 16 V12 Q21 7 16 7 H12 Q7 7 7 12 Z M7 32 V36 Q7 41 12 41 H16 Q21 41 21 36 V32 Q21 27 16 27 H12 Q7 27 7 32 Z', '9':'M0 10 Q0 0 10 0 H18 Q28 0 28 10 V37 Q28 48 17 48 H10 Q0 48 0 38 V35 H7 V37 Q7 41 11 41 H16 Q21 41 21 36 V28 Q19 30 15 30 H10 Q0 30 0 21 Z M7 11 V19 Q7 23 11 23 H16 Q21 23 21 18 V12 Q21 7 17 7 H11 Q7 7 7 11 Z', } def path(d): return f'' def digit_paths(number): # Use ink bounds for 1, then recenter actual widths with 8 mm gaps. if not re.fullmatch(r'[0-9]{1,5}', number): raise ValueError('Use 1–5 ASCII digits from 0 to 9. No spaces or other characters.') ink_bounds = {'1': (4, 27), '3': (1, 28)} bounds = [ink_bounds.get(digit, (0, 28)) for digit in number] x = (240 - sum(b-a for a,b in bounds) - 8*(len(number)-1))/2 out = [] for digit,(left,right) in zip(number,bounds): out.append(f'') x += right-left+8 return ''.join(out) def group(i,attrs,art): return f'{art}' def engraving(art): return group('ENGRAVE_BLACK','fill="#000000" fill-rule="evenodd" stroke="none"',art) def line_group(i,c,art): return group(i,f'fill="none" stroke="{c}" stroke-width="0.12" stroke-linejoin="round" stroke-linecap="round"',art) def svg(w,h,art,mm=True): u = 'mm' if mm else '' return f'{art}\n' def plaque(number=''): paths = digit_paths(number) if number else '' art = (engraving(paths) if paths else '') + line_group('SCORE_BLUE','#0000ff',path(SCORE)) + line_group('CUT_RED','#ff0000',path(PROFILE)) return svg(256,121,''+art+'') if __name__ == '__main__': p = ArgumentParser(description='Make a local, full-size plaque SVG. Never reads or sends your address.') p.add_argument('digits', help='1 to 5 digits; leading zeros are retained.') p.add_argument('output', type=Path, help='New filename ending in .svg. Existing files are not overwritten.') args=p.parse_args() if not re.fullmatch(r'[0-9]{1,5}',args.digits): p.error('Use 1 to 5 digits from 0 to 9.') if args.output.suffix.lower()!='.svg': p.error('Give the output filename an .svg extension.') try: with args.output.open('x',encoding='utf-8') as f: f.write(plaque(args.digits)) except OSError as exc: p.error(str(exc)) print(f'Wrote {args.output} (256 × 121 mm page; 240 × 105 mm engraved plaque).')