"""Shared SVG helpers for figures. Import what you need in a project's figs.py: from mpmdoc.figkit import T, svg_open, markers, INK, GOLD, KICK, ... Conventions (MPM_Document_Standard.md §7): * labels Montserrat 700, uppercase, letter-spaced; values/dimensions JetBrains Mono 700 * strokes INK; brand accent GOLD/KICK; limits and warnings RED (dashed) * draw at viewBox width 700 for full-width figures, ~240 for step side-figures """ from .brand import INK, GOLD, KICK, MUTE, CREAM, LINE, RED, REDBG, GRN, GRNBG, BLU, GRY # noqa: F401 def T(x, y, s, size=8, w=600, fill=INK, anchor="start", rot=None, fam="Montserrat", ls=0.4, halo=False): """One element. halo=True adds a white outline so labels read over linework.""" r = f' transform="rotate({rot} {x} {y})"' if rot is not None else "" h = ' stroke="#fff" stroke-width="3" paint-order="stroke"' if halo else "" return (f'{s}') def svg_open(w, h, grid=False, prefix="f"): """Open an at width 100% with shared markers; grid=True adds the faint drafting grid.""" s = f'' + markers(prefix) if grid: s += f'' return s def markers(p="f"): """Arrowheads (#{p}a ink, #{p}g gold), hatches (#{p}h grey, #{p}r red) and grid (#{p}grid).""" return (f'' f'' f'' f'' f'' f'' f'' f'' f'' f'') def dim_h(x1, x2, y, label, ext_from=None, p="f", size=8.5): """Horizontal dimension line from x1 to x2 at height y with centred label. ext_from: y the extension lines start from (the feature edge).""" o = [] if ext_from is not None: for x in (x1, x2): o.append(f'') o.append(f'') o.append(T((x1 + x2) / 2, y - 4, label, size=size, w=700, anchor="middle", fam="JetBrains Mono", ls=0, halo=True)) return "".join(o) def dim_v(x, y1, y2, label, ext_from=None, p="f", size=8.5): """Vertical dimension line from y1 to y2 at x, label rotated alongside.""" o = [] if ext_from is not None: for y in (y1, y2): o.append(f'') o.append(f'') cy = (y1 + y2) / 2 o.append(T(x - 5, cy, label, size=size, w=700, anchor="middle", fam="JetBrains Mono", ls=0, rot=-90, halo=True)) return "".join(o) def tag(x, y, t, r=10): """Gold callout bubble matching the drawing schedule tags (B-1, F-1 …).""" return (f'' + T(x, y + 3, t, size=7, w=800, anchor="middle", ls=0))