code wiki / _hdl_build / nx_float_inline_gate.nx

nx_float_inline_gate.nx source

↩ module page · 90 lines · 4978 B

1// nx_float_inline_gate.nx -- VERDICT gate for INLINE content flowing BESIDE a float (the Wikipedia header 2// fix). A container with a float:right box (#fb, 300px) + INLINE text directly inside it: the inline text 3// must wrap into the LEFT ~500px and NOT paint into the float's right region. Before the fix inline text 4// ignored the float and overflowed full-width, painting black ink under the float box. Asserts: black text 5// ink present on the left, and (near-)NONE in the float's right strip [x>=520]. LIAR-KILL: green absent. 6// 100% sovereign. license_tier: ORIGINAL 7import "nx_syscalls.nx" 8import "nx_render_html.nx" 9 10func g_w(s: *u8) -> i64 { var k: i64=0; while s[k]!=(0 as u8){k=k+1} sys_write(1,s,k); return 0 } 11func pn(v0: i64) -> i64 { var v: i64=v0; if v<0 { let m: *u8=sys_mmap(8); m[0]=45 as u8; sys_write(1,m,1); v=0-v } let b: *u8=sys_mmap(24); var k: i64=0; if v==0 {b[0]=48;k=1} while v>0 {b[k]=(48+(v%10)) as u8; v=v/10; k=k+1} let o: *u8=sys_mmap(24); var j: i64=0; while j<k {o[j]=b[k-1-j];j=j+1} sys_write(1,o,k); return 0 } 12func u32le(d: *u8, p: i64) -> i64 { return (d[p]&0xff) + ((d[p+1]&0xff)<<8) + ((d[p+2]&0xff)<<16) + ((d[p+3]&0xff)<<24) } 13// count black (0,0,0) pixels in the x-range [xlo, xhi) 14func black_in(data: *u8, off: i64, w: i64, h: i64, xlo: i64, xhi: i64) -> i64 { 15 let row3: i64 = w*3 16 let pad: i64 = (4-(row3%4))%4 17 let rowstride: i64 = row3+pad 18 var n: i64 = 0 19 var y: i64 = 0 20 while y < h { 21 var x: i64 = xlo 22 let rb: i64 = off + y*rowstride 23 while x < xhi { 24 let p: i64 = rb + x*3 25 if (data[p]&0xff)==0 { if (data[p+1]&0xff)==0 { if (data[p+2]&0xff)==0 { n=n+1 } } } 26 x = x+1 27 } 28 y = y+1 29 } 30 return n 31} 32func green_any(data: *u8, off: i64, w: i64, h: i64) -> i64 { 33 let row3: i64 = w*3 34 let pad: i64 = (4-(row3%4))%4 35 let rowstride: i64 = row3+pad 36 var y: i64 = 0 37 while y < h { 38 var x: i64 = 0 39 let rb: i64 = off + y*rowstride 40 while x < w { 41 let p: i64 = rb + x*3 42 if (data[p]&0xff)==0 { if (data[p+1]&0xff)==255 { if (data[p+2]&0xff)==0 { return 1 } } } 43 x = x+1 44 } 45 y = y+1 46 } 47 return 0 48} 49func chk(cond: i64, label: *u8, pass: *i64) -> i64 { 50 g_w(" " as *u8); g_w(label); g_w(": " as *u8) 51 if cond==1 { g_w("OK\n" as *u8); pass[0]=pass[0]+1 } else { g_w("FAIL\n" as *u8) } 52 return cond 53} 54 55func main() -> i64 { 56 let pass: *i64 = sys_mmap(8) as *i64; pass[0]=0 57 g_w("=== FLOAT-INLINE GATE (inline text flows beside a float, sovereign nx_cc->nxasm) ===\n" as *u8) 58 59 // #fb is float:right width 300 (occupies x=[500,800)); the inline text inside #c must wrap into the 60 // LEFT ~500px and leave the float's right strip [x>=520] black-ink-free. 61 // #fb float:right width 300 (occupies x=[500,800)); inline text inside #c must flow into the LEFT. 62 let html2: *u8 = "<body><style>#fb{float:right;width:300px;background-color:#dddddd;height:80px}</style><div id=\"c\"><div id=\"fb\">BOX</div>This is a long run of intro text that should flow to the LEFT of the floated box and wrap within the remaining width instead of overlapping the floated box on the right side of the container area here.</div></body>\x00" as *u8 63 var hlen: i64 = 0 64 while html2[hlen]!=(0 as u8) { hlen=hlen+1 } 65 nx_render_html_to_bmp(html2, hlen, "knowledge/status/float_inline_gate.bmp\x00" as *u8) 66 nx_render_html_to_png(html2, hlen, "knowledge/status/float_inline_gate.png\x00" as *u8) 67 68 let lp: *i64 = sys_mmap(8) as *i64 69 let bmp: *u8 = sys_read_file("knowledge/status/float_inline_gate.bmp\x00" as *u8, lp) 70 let blen: i64 = lp[0] 71 chk((blen >= 54) as i64, "bmp file >= 54 bytes\x00" as *u8, pass) 72 if blen < 54 { g_w("FLOAT-INLINE rows=4 pass=" as *u8); pn(pass[0]); g_w(" verdict=RED (no image)\n" as *u8); sys_exit(1); return 1 } 73 let off: i64 = u32le(bmp, 10) 74 let w: i64 = u32le(bmp, 18) 75 let h: i64 = u32le(bmp, 22) 76 77 let left_ink: i64 = black_in(bmp, off, w, h, 0, 500) 78 let right_ink: i64 = black_in(bmp, off, w, h, 520, w) 79 g_w(" measured: left_black[0,500)=" as *u8); pn(left_ink); g_w(" right_black[520,800)=" as *u8); pn(right_ink); g_w(" height=" as *u8); pn(h); g_w("\n" as *u8) 80 81 chk((left_ink > 200) as i64, "inline text painted on the LEFT (>200 black px)\x00" as *u8, pass) 82 // right strip should be (near) free of text ink -- allow a tiny tolerance for the 'BOX' label glyphs 83 // are at the float TOP only; the wrapped intro text must not bleed under the float. 84 chk((right_ink < 80) as i64, "intro text does NOT overlap float region [x>=520] (<80 black px)\x00" as *u8, pass) 85 chk((green_any(bmp, off, w, h) == 0) as i64, "LIAR-KILL: green #00ff00 absent\x00" as *u8, pass) 86 87 g_w("FLOAT-INLINE rows=4 pass=" as *u8); pn(pass[0]) 88 if pass[0]==4 { g_w(" verdict=GREEN\n" as *u8); sys_exit(0); return 0 } 89 g_w(" verdict=RED\n" as *u8); sys_exit(1); return 1 90}