cyrillic-svg.html (2652B)
1 {{- /* 2 Renders a 5×5 dot-matrix page marker as an inline <svg>. The bitmap font 3 ($font dict below) ships with eight Cyrillic glyphs; add more entries to 4 support other characters. 5 6 Context: 7 .word — a slice of single-character strings, in reading order 8 (e.g. (slice "Д" "О" "М") for "ДОМ") 9 .W — optional width (default 320) 10 .H — optional height (default 32) 11 .class — optional class for the <svg> (default "frame-marker") 12 13 Geometry: 14 step=4.5 r=1.45 cy=H/2 rightX = W - step*1.2 15 For each char (iterated right-to-left as col=0, -6, -12, ...) and 16 each bitmap cell (rr,cc) where the bit is "1": 17 x = rightX + (col + cc - 4) * step 18 y = cy + (rr - 2 ) * step 19 */ -}} 20 21 {{- $word := .word -}} 22 {{- $W := (.W | default 320) -}} 23 {{- $H := (.H | default 32) -}} 24 {{- $class := (.class | default "frame-marker") -}} 25 26 {{- /* Scale step / r proportionally to height: 27 step = (H/32)*4.5, r = (H/32)*1.45. */ -}} 28 {{- $hRatio := div (float $H) 32.0 -}} 29 {{- $step := mul $hRatio 4.5 -}} 30 {{- $r := mul $hRatio 1.45 -}} 31 {{- $cy := div (float $H) 2.0 -}} 32 {{- $rightX := sub (float $W) (mul $step 1.2) -}} 33 34 {{- $font := dict 35 "А" (slice "01110" "10001" "11111" "10001" "10001") 36 "Д" (slice "01110" "01010" "01010" "11111" "10001") 37 "К" (slice "10010" "10100" "11000" "10100" "10010") 38 "М" (slice "10001" "11011" "10101" "10001" "10001") 39 "О" (slice "01110" "10001" "10001" "10001" "01110") 40 "П" (slice "11111" "10001" "10001" "10001" "10001") 41 "С" (slice "01111" "10000" "10000" "10000" "01111") 42 "Т" (slice "11111" "00100" "00100" "00100" "00100") 43 -}} 44 45 {{- /* Reverse the word so the rightmost char gets col=0. */ -}} 46 {{- $reversed := collections.Reverse $word -}} 47 48 <svg xmlns="http://www.w3.org/2000/svg" class="{{ $class }}" viewBox="0 0 {{ $W }} {{ $H }}" preserveAspectRatio="none" aria-hidden="true"> 49 <line x1="0" y1="{{ $cy }}" x2="{{ $W }}" y2="{{ $cy }}" stroke="#434c5e" stroke-width="1" shape-rendering="crispEdges"/> 50 {{- range $idx, $ch := $reversed -}} 51 {{- $col := mul $idx -6 -}} 52 {{- with index $font $ch -}} 53 {{- range $rr, $row := . -}} 54 {{- range $cc := seq 0 4 -}} 55 {{- if eq (substr $row $cc 1) "1" -}} 56 {{- $i := add $col (sub $cc 4) -}} 57 {{- $j := sub $rr 2 -}} 58 {{- $x := add $rightX (mul (float $i) $step) -}} 59 {{- $y := add $cy (mul (float $j) $step) -}} 60 <circle cx="{{ printf "%.2f" $x }}" cy="{{ printf "%.2f" $y }}" r="{{ $r }}" fill="#88c0d0"/> 61 {{- end -}} 62 {{- end -}} 63 {{- end -}} 64 {{- end -}} 65 {{- end }} 66 </svg>