code wiki / _hdl_build / nx_glyph_ink_probe.nx
nx_glyph_ink_probe.nx source
↩ module page · 81 lines · 3005 B
1// nx_glyph_ink_probe.nx -- F1177 comma-no-ink probe: for each probe char, at em sizes 12..24,
2// emit the vector glyph and report contour count + rasterized ink pixels. A zero at any size
3// names the vec-font/raster gap that erases punctuation in the CSS-on styled paint path.
4// license_tier: ORIGINAL expect_exit: 0
5import "nx_syscalls.nx"
6import "nx_font.nx"
7import "nx_aa_raster.nx"
8const K_MAGIC_200000: i64 = 200000
9const K_MAGIC_20000: i64 = 20000
10
11func pw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
12func pn(v: i64) -> i64 { let b: *u8=sys_mmap(28); var m: i64=v; if m<0{pw("-\x00" as *u8);m=0-m} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 }
13
14func probe(ch: i64, empx: i64) -> i64 {
15 let xs: *i64 = sys_mmap(8*K_MAGIC_200000) as *i64
16 let ys: *i64 = sys_mmap(8*K_MAGIC_200000) as *i64
17 let cst: *i64 = sys_mmap(8*K_MAGIC_20000) as *i64
18 let cln: *i64 = sys_mmap(8*K_MAGIC_20000) as *i64
19 let np: *i64 = sys_mmap(16) as *i64
20 let nc: *i64 = sys_mmap(16) as *i64
21 let cs: *i64 = sys_mmap(8*16) as *i64
22 let sn: *i64 = sys_mmap(8*16) as *i64
23 font_trig_init(cs, sn) // ⚠zero trig tables collapse every gs_disc vertex to the centre --
24 // the probe's own first run was vacuous (cynical-instruments class)
25 np[0] = 0
26 nc[0] = 0
27 let ss: i64 = 3
28 let S: i64 = empx * ss
29 let mgn: i64 = 4
30 font_emit(ch, xs, ys, cst, cln, np, nc, cs, sn, mgn*ss, 2*ss, S)
31 let adv: i64 = font_vec_adv_px(ch, empx)
32 var gw: i64 = adv + 2*mgn
33 if gw < empx + 2*mgn { gw = empx + 2*mgn }
34 let gh: i64 = empx + (empx*35)/100 + 2
35 let gh2: i64 = gh * 2
36 let cov: *u8 = sys_mmap(gw*gh2 + 16)
37 var z: i64 = 0
38 while z < gw*gh2 { cov[z] = 0 as u8; z = z + 1 }
39 aa_render(xs, ys, cst, cln, nc[0], cov, gw, gh2, ss)
40 var ink: i64 = 0
41 var maxcov: i64 = 0
42 var frow: i64 = 0 - 1
43 var lrow: i64 = 0 - 1
44 z = 0
45 while z < gw*gh2 {
46 let c: i64 = cov[z]&0xff
47 if c > maxcov { maxcov = c }
48 if c > 32 {
49 ink = ink + 1
50 let r: i64 = z / gw
51 if frow == (0 - 1) { frow = r }
52 lrow = r
53 }
54 z = z + 1
55 }
56 pw("ch=\x00" as *u8); pn(ch)
57 pw(" empx=\x00" as *u8); pn(empx)
58 pw(" contours=\x00" as *u8); pn(nc[0])
59 pw(" ink=\x00" as *u8); pn(ink)
60 pw(" maxcov=\x00" as *u8); pn(maxcov)
61 pw(" rows=\x00" as *u8); pn(frow); pw("..\x00" as *u8); pn(lrow)
62 pw(" cell_gh=\x00" as *u8); pn(gh)
63 pw("\n\x00" as *u8)
64 return 0
65}
66
67func main() -> i64 {
68 // ',' '.' ';' ':' plus controls 'a' and 'M' (must always ink)
69 var szi: i64 = 12
70 while szi <= 24 {
71 probe(44, szi)
72 szi = szi + 4
73 }
74 probe(46, 16)
75 probe(59, 16)
76 probe(58, 16)
77 probe(97, 16)
78 probe(77, 16)
79 sys_exit(0)
80 return 0
81}