"""1:1 cutting templates, US Letter landscape (content also fits A4). Counts come from the manifest.""" import os, asyncio from collections import Counter import geom as G, manifest as M, draw as D from draw import f, path, line from geom import TOP import shot, fonts from paths import OUT, WORK PW, PH = 279.4, 215.9 FONT = "Inter, 'Helvetica Neue', Helvetica, Arial, sans-serif" CUT, GUIDE, RED, SCALE = '#111111', '#8a8a8a', '#b3261e', '#0057ff' def T(x, y, s, size=3.1, weight=400, fill='#111', anchor='start'): return f'{s}' def lines(x, y, rows, size=3.1, lead=4.4, **kw): return ''.join(T(x, y+i*lead, r, size, **kw) for i, r in enumerate(rows)) def page(body, title, sub, n, total): head = T(12, 14, title, 5.2, 700) + T(12, 20, sub, 3.1, 400, '#444') + T(PW-12, 14, f'Green Man mask kit · templates {n}/{total}', 2.8, 400, '#666', 'end') bar = (f'' + T(PW-72, PH-13, '100 mm. Measure this bar after printing. Print at 100% / actual size, never “fit to page”.', 2.6, 400, '#333', 'middle')) return f'{head}{body}{bar}' def base_page(base, n, total): ox, oy = PW/2, 124.0 g = f'' g += f'' g += f'' for sl, pt in zip(base['slits'], base['patches']): g += f'' g += f'' g += T(34, -(TOP+62), 'optional top-strap slit (dotted, under the knot): decide in Stage C', 2.4, 400, '#666') + f'' g += T(G.SLIT_X+18, -(TOP+30), 'strap slit', 2.6, 600, RED) + T(G.SLIT_X+18, -(TOP+26.3), '3 × 20 mm, cut through', 2.4, 400, RED) + T(G.SLIT_X+18, -(TOP+22.9), 'band and patch together', 2.4, 400, RED) g += T(-G.SLIT_X-18, -(TOP+30), 'patch on the BACK', 2.6, 600, RED, 'end') + T(-G.SLIT_X-18, -(TOP+26.3), '30 × 36 mm of 2 mm foam', 2.4, 400, RED, 'end') # where things land, lightly, so the template doubles as a placement map g += f'' + T(30, -(G.STRIP_Y-1), 'brow strip', 2.4, 400, '#777', 'middle') g += f'' + T(-12, -(G.KNOT_C[1]+12), 'knot', 2.4, 400, '#777', 'middle') if base['kind'] == 'glasses': for sg in (-1, 1): g += f'' g += f'' g += T(G.LENS_CX, 3, 'your lens', 2.6, 400, '#777', 'middle') + T(-G.LENS_CX, 3, 'no foam here', 2.6, 400, '#777', 'middle') for sg in (-1, 1): g += f'' g += T(G.FRAME_W/2+36, -(TOP-1), 'glasses arm', 2.4, 400, '#777') else: g += T(0, 24, 'eye holes 46 × 24 mm, 64 mm between centres', 2.6, 400, '#777', 'middle') g += '' if base['kind'] == 'glasses': title, sub = 'Base, for glasses wearers · cut 1 from 6 mm EVA', 'Worn BEHIND the glasses. Drawn for a frame 140 mm wide; see the fit table to resize.' notes = ['Paper fit first: cut this page on the solid line, hold it to your face, put your glasses on over it.', '· The band lies flat on your forehead and the frame’s top bar sits along its lower edge.', '· The nose strip drops between the nose pads; the pads still touch skin.', '· Each cheek tab sits outside the frame; the arms pass over the tabs.', 'Fold on the centre line to cut both halves at once.'] table = [(125, 89), (130, 93), (135, 97), (140, 100), (145, 104), (150, 107)] tb = T(12, 178, 'Frame width → print scale for THIS page only', 2.8, 700) + ''.join(T(12 + i*17, 183.5, f'{w} mm', 2.6, 600) + T(12 + i*17, 187.5, f'{p}%', 2.6) for i, (w, p) in enumerate(table)) tb += T(12, 193, 'Scale brow_strip.stl by the same percentage. Leaf pages always print at 100%.', 2.5, 400, '#555') else: title, sub = 'Base, no glasses · cut 1 from 6 mm EVA', 'Same band, nose and cheeks as the glasses base, joined under the eyes.' notes = ['Paper fit first: cut the outline and both eye holes from paper and hold it to your face.', '· You see clearly through both holes without the edges touching your lashes.', '· The band lies flat on your forehead; the nose strip follows the bridge of your nose.', 'Eyes closer or wider than the holes: reprint this page a few percent smaller or larger.', 'Fold on the centre line to cut both halves at once.'] tb = (f'' + T(15, 180, 'UNTESTED VARIANT', 3.4, 700, RED) + T(15, 185.5, 'Drawn from the glasses base but never built. Paper-fit before cutting foam.', 2.5, 400, RED)) body = g + lines(12, 27, notes, 2.75, 4.0, fill='#222') + tb return page(body, title, sub, n, total) def leaf_counts(): """(size, variant) -> [as drawn, flipped], from the manifest; spares are added to variant 0 as drawn.""" c = Counter() for p in M.PLACEMENTS: if p['part'] in 'LMST': c[(p['part'], p['variant'], bool(p['flip']))] += 1 for k, n in M.SPARES.items(): c[(k, 1, False)] += n return c def leaf_cell(size, variant, cx, base_y, c): name = {'L': 'Large', 'M': 'Medium', 'S': 'Small', 'T': 'Tip'}[size] + ' ' + 'AB'[variant] leaf = G.oak(size, variant); n0, n1 = c[(size, variant, False)], c[(size, variant, True)] g = f'' g += f'' y = base_y + G.STEM_L + 6 g += T(cx, y, name, 3.3, 700, anchor='middle') box = lambda k: ''.join(f'' for i in range(k)) g += T(cx, y+4.8, f'cut {n0 + n1}', 2.9, 600, anchor='middle') + box(n0 + n1) return g, n0 + n1 def leaf_pages(n0, total): c = leaf_counts(); ml = M.make_list(); pages = [] # page: large body, tot = '', 0 for v, cx in ((0, 78), (1, 170)): g, k = leaf_cell('L', v, cx, 148, c); body += g; tot += k assert tot == ml['L']['total'] body += lines(214, 60, ['Large leaves make the tall back', 'of the crown.', '', 'Print on card stock, cut the two', 'shapes out, trace onto 2 mm foam.', 'Turn the card over for every', 'other leaf, so they are not all', 'identical.', '', 'Dashed lines: where the veins go', '(stamp or score them later).', '', 'The stem is part of the leaf.', 'Do not cut it off.'], 2.75, 4.1, fill='#222') pages.append(page(body, f'Large oak leaf, 95 mm · cut {ml["L"]["total"]} from 2 mm EVA', 'Tick a box for each one you cut. These counts are everything the mask uses: nothing is left over.', n0, total)) # page: medium, small, tip, patch body, chk = '', Counter(); xs = {('M', 0): 34, ('M', 1): 92, ('S', 0): 142, ('S', 1): 184, ('T', 0): 220, ('T', 1): 248} for (size, v), cx in xs.items(): g, k = leaf_cell(size, v, cx, {'M': 122, 'S': 100, 'T': 82}[size], c); body += g; chk[size] += k for k in 'MST': assert chk[k] == ml[k]['total'], (k, chk[k], ml[k]['total']) px, py = 205, 132 body += f'' + T(px+G.PATCH_W/2, py+G.PATCH_H/2-1, 'Strap patch', 3.0, 700, anchor='middle') + T(px+G.PATCH_W/2, py+G.PATCH_H/2+3.5, 'cut 2', 2.7, anchor='middle') sp = ', '.join(f'{n} {"medium" if k == "M" else "small"}' for k, n in M.SPARES.items()) body += lines(12, 172, [f'Counts include {sp} as spares. Keep the spares unsealed and unpainted: they are your repair kit.', 'Medium: 6 for the front row of the crown, 2 for the cheeks. Small: 4 for the cheeks, 1 for the nose. Tip: one on the end of each tendril.'], 2.75, 4.2, fill='#222') pages.append(page(body, f'Medium, small and tip leaves · cut {ml["M"]["total"]} + {ml["S"]["total"]} + {ml["T"]["total"]} from 2 mm EVA, plus 2 strap patches', 'Tick a box for each one you cut.', n0+1, total)) return pages def build(out=str(OUT / 'GreenMan_templates.pdf')): total = 4 pages = [base_page(G.base_glasses(), 1, total), base_page(G.base_plain(), 2, total)] + leaf_pages(3, total) html = ('' + ''.join(pages) + '') src = str(WORK / 'templates.html'); open(src, 'w').write(html) asyncio.run(shot.go(src, out)); return out if __name__ == '__main__': print(build())