code wiki / _hdl_build / nx_css_fontsize_frac_gate.nx
nx_css_fontsize_frac_gate.nx source
↩ module page · 85 lines · 4966 B
1// nx_css_fontsize_frac_gate.nx -- PROOF (re-runnable) of the S21 F1 root-cause fix: a FRACTIONAL CSS
2// font-size ("13.5px") must layout as 13px (integer-truncate), NOT 135px. The old _layout_fontsize_decl_px
3// skipped the '.' and kept accumulating digits -> 135px -> tscale=3 -> every line reserved 3x tall ->
4// /experiential's 19-row table stretched to 8 scroll screens while paint (which stops at '.') drew small
5// text. Tests run the REAL br_layout. T2 is the CAN-FAIL control: a genuinely-big font must STILL scale.
6// license_tier: ORIGINAL expect_exit: 0
7import "nx_syscalls.nx"
8import "nx_browser_render.nx"
9
10func fg_w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
11func fg_n(v: i64) -> i64 { let t: *u8=sys_mmap(24); var m: i64=v; if m<0{sys_write(1,"-" as *u8,1);m=0-m} 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} let b: *u8=sys_mmap(24); var j: i64=0; while j<k{b[j]=t[k-1-j];j=j+1} sys_write(1,b,k); return 0 }
12
13func fg_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
14
15func fg_box(t: *LayoutTree, i: i64) -> *LayoutBox {
16 return (t.boxes as *u8 + (i as nx_size) * (NX_LAYOUT_BOX_BYTES as nx_size)) as *LayoutBox
17}
18func fg_has(src: *u8, off: i64, len: i64, m: *u8) -> i64 {
19 let ml: i64 = fg_slen(m)
20 if ml == 0 { return 0 }
21 var i: i64 = 0
22 while i + ml <= len {
23 var k: i64 = 0
24 var ok: i64 = 1
25 while k < ml { if (src[off+i+k]&0xff) != (m[k]&0xff) { ok = 0; k = ml } else { k = k + 1 } }
26 if ok == 1 { return 1 }
27 i = i + 1
28 }
29 return 0
30}
31// layout an HTML string, return the height of the text box containing `marker` (-1 if not found)
32func fg_text_h(html: *u8, marker: *u8) -> i64 {
33 let page: *Page = sys_mmap(NX_PAGE_BYTES) as *Page
34 page.raw = html
35 page.raw_len = fg_slen(html)
36 page.dark_mode = 0
37 br_layout(page, 1024)
38 let t: *LayoutTree = page.tree
39 var i: i64 = 0
40 while i < t.count {
41 let b: *LayoutBox = fg_box(t, i)
42 if b.text_len > 0 {
43 if fg_has(page.buf, b.text_off, b.text_len, marker) == 1 { return b.h }
44 }
45 i = i + 1
46 }
47 return 0 - 1
48}
49
50func main() -> i64 {
51 fg_w("=== nx_css_fontsize_frac_gate -- fractional font-size must not inflate layout (S21 F1 root cause) ===\n" as *u8)
52 var fails: i64 = 0
53
54 // T1: 13.5px (the /experiential table size) -> 13px -> tscale 1 -> ONE 17px line
55 let h1: i64 = fg_text_h("<html><head><style>td{font-size:13.5px}</style></head><body><table><tr><td>alphabeta</td></tr></table></body></html>\x00" as *u8, "alphabeta\x00" as *u8)
56 fg_w(" T1 font-size:13.5px text-box h=" as *u8); fg_n(h1)
57 if h1 >= 0 { if h1 <= 24 { fg_w(" PASS (one 1x line)\n" as *u8) } else { fails=fails+1; fg_w(" FAIL (inflated -- frac parse regressed)\n" as *u8) } } else { fails=fails+1; fg_w(" FAIL (marker not laid out)\n" as *u8) }
58
59 // T2 CAN-FAIL control: a genuinely large font must STILL reserve big lines (tscale=3 path alive)
60 let h2: i64 = fg_text_h("<html><head><style>td{font-size:37px}</style></head><body><table><tr><td>alphabeta</td></tr></table></body></html>\x00" as *u8, "alphabeta\x00" as *u8)
61 fg_w(" T2 font-size:37px text-box h=" as *u8); fg_n(h2)
62 if h2 >= 51 { fg_w(" PASS (big font still reserves 3x lines -- fix did not kill scaling)\n" as *u8) } else { fails=fails+1; fg_w(" FAIL (scale path broken)\n" as *u8) }
63
64 // T3: another fractional (22.9px -> 22 -> tscale 1)
65 let h3: i64 = fg_text_h("<html><head><style>td{font-size:22.9px}</style></head><body><table><tr><td>alphabeta</td></tr></table></body></html>\x00" as *u8, "alphabeta\x00" as *u8)
66 fg_w(" T3 font-size:22.9px text-box h=" as *u8); fg_n(h3)
67 if h3 >= 0 { if h3 <= 24 { fg_w(" PASS (truncates to 22, still 1x)\n" as *u8) } else { fails=fails+1; fg_w(" FAIL\n" as *u8) } } else { fails=fails+1; fg_w(" FAIL (marker not laid out)\n" as *u8) }
68
69 // T4 E2E: the REAL /experiential page source -- total page height collapses from the 3x bloat
70 let lb: *i64 = sys_mmap(16) as *i64
71 let html: *u8 = sys_read_file("knowledge/experiential_index.html\x00" as *u8, lb)
72 if (html as i64) != 0 {
73 let page: *Page = sys_mmap(NX_PAGE_BYTES) as *Page
74 page.raw = html
75 page.raw_len = lb[0]
76 page.dark_mode = 0
77 br_layout(page, 1024)
78 fg_w(" T4 /experiential page_h=" as *u8); fg_n(page.page_h); fg_w(" (was 4580 with the bug)" as *u8)
79 if page.page_h < 3200 { fg_w(" PASS\n" as *u8) } else { fails=fails+1; fg_w(" FAIL (still bloated)\n" as *u8) }
80 } else { fails=fails+1; fg_w(" T4 FAIL (page source missing)\n" as *u8) }
81
82 if fails == 0 { fg_w("NX-FONTSIZE-FRAC GREEN -- fractional font-size lays out truthfully; scale path intact\n" as *u8); sys_exit(0); return 0 }
83 fg_w("NX-FONTSIZE-FRAC RED fails=" as *u8); fg_n(fails); fg_w("\n" as *u8)
84 sys_exit(1); return 1
85}