code wiki / _hdl_build / nx_chrome_drop_gate.nx

nx_chrome_drop_gate.nx source

↩ module page · 98 lines · 5571 B

1// nx_chrome_drop_gate.nx -- VERDICT gate for LAYOUT-LEVEL chrome dropping. A collapsed-dropdown menu 2// (class "vector-dropdown") whose content is force-VISIBLE by the page's OWN CSS must still be DROPPED 3// (we can't honor the checkbox-collapse, and leaving it expanded buries the article). The article <p> 4// must still render. Asserts: the dropdown's unique text ("ZZMENUITEM") is ABSENT from the pixels, while 5// the article's text band IS present. LIAR-KILL: a never-used color absent. 100% sovereign. 6// 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// total black (text) pixels in the image 14func black_total(data: *u8, off: i64, w: i64, h: 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 = 0 22 let rb: i64 = off + y*rowstride 23 while x < w { 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("=== CHROME-DROP GATE (layout-level chrome subtree drop, sovereign nx_cc->nxasm) ===\n" as *u8) 58 59 // A .vector-dropdown menu whose page CSS force-shows it (display:block !important-style) + an article. 60 // height the page styles the menu tall; our layout drop must remove it regardless so its rows DON'T 61 // paint. Render TWO variants and compare black-pixel totals: WITH the dropdown vs an article-ONLY page. 62 let with_menu: *u8 = "<body><style>.vector-dropdown{display:block;background-color:#ffffff}.vrow{height:10px}</style><div class=\"vector-dropdown\"><div class=\"vrow\">ZZMENUITEM ONE TWO THREE FOUR FIVE SIX SEVEN EIGHT NINE TEN</div><div class=\"vrow\">ZZMENUITEM ELEVEN TWELVE THIRTEEN FOURTEEN FIFTEEN</div></div><p>Article body paragraph that should remain after the dropdown is dropped from layout.</p></body>\x00" as *u8 63 let article_only: *u8 = "<body><p>Article body paragraph that should remain after the dropdown is dropped from layout.</p></body>\x00" as *u8 64 65 var l1: i64 = 0 66 while with_menu[l1]!=(0 as u8) { l1=l1+1 } 67 var l2: i64 = 0 68 while article_only[l2]!=(0 as u8) { l2=l2+1 } 69 nx_render_html_to_bmp(with_menu, l1, "knowledge/status/chrome_drop_with.bmp\x00" as *u8) 70 nx_render_html_to_bmp(article_only, l2, "knowledge/status/chrome_drop_only.bmp\x00" as *u8) 71 nx_render_html_to_png(with_menu, l1, "knowledge/status/chrome_drop_with.png\x00" as *u8) 72 73 let lp: *i64 = sys_mmap(8) as *i64 74 let b1: *u8 = sys_read_file("knowledge/status/chrome_drop_with.bmp\x00" as *u8, lp) 75 let bl1: i64 = lp[0] 76 let b2: *u8 = sys_read_file("knowledge/status/chrome_drop_only.bmp\x00" as *u8, lp) 77 let bl2: i64 = lp[0] 78 chk((bl1 >= 54) as i64, "both images rendered\x00" as *u8, pass) 79 if bl1 < 54 { g_w("CHROME-DROP rows=4 pass=" as *u8); pn(pass[0]); g_w(" verdict=RED (no image)\n" as *u8); sys_exit(1); return 1 } 80 81 let o1: i64 = u32le(b1,10); let w1: i64 = u32le(b1,18); let h1: i64 = u32le(b1,22) 82 let o2: i64 = u32le(b2,10); let w2: i64 = u32le(b2,18); let h2: i64 = u32le(b2,22) 83 let blk1: i64 = black_total(b1, o1, w1, h1) 84 let blk2: i64 = black_total(b2, o2, w2, h2) 85 g_w(" measured: with_menu black=\x00" as *u8); pn(blk1); g_w(" h=\x00" as *u8); pn(h1); g_w(" | article_only black=\x00" as *u8); pn(blk2); g_w(" h=\x00" as *u8); pn(h2); g_w("\n" as *u8) 86 87 // If the dropdown were rendered, with_menu would have FAR more black text (2 long menu rows). Dropping 88 // it -> with_menu ink ~= article_only ink (within a small tolerance). The menu text contributes >500 px. 89 var diff: i64 = blk1 - blk2 90 if diff < 0 { diff = 0 - diff } 91 chk((diff < 200) as i64, "dropdown DROPPED (with-menu ink ~= article-only ink, diff<200)\x00" as *u8, pass) 92 chk((blk2 > 200) as i64, "article text still renders (>200 black px)\x00" as *u8, pass) 93 chk((green_any(b1, o1, w1, h1) == 0) as i64, "LIAR-KILL: green #00ff00 absent\x00" as *u8, pass) 94 95 g_w("CHROME-DROP rows=4 pass=" as *u8); pn(pass[0]) 96 if pass[0]==4 { g_w(" verdict=GREEN\n" as *u8); sys_exit(0); return 0 } 97 g_w(" verdict=RED\n" as *u8); sys_exit(1); return 1 98}