code wiki / (root) / nx_font_universal.nx

nx_font_universal.nx source

↩ module page · 302 lines · 21541 B

1// nx_font_universal.nx -- "all languages in ONE font": a single sovereign .ttf carrying THREE scripts generated 2// by the same stroke engine -- Latin (H I T), Han/Chinese (8 chars), and Hangul/Korean (10 jamo) -- each mapped to 3// its true Unicode codepoint via one generic cmap. Proves the generator spans scripts in a single artifact. 4// -> web_assets/nishi_universal.ttf + nishi_universal.html (English + Chinese + Korean in one font). HONEST: a 5// breadth PROOF (21 codepoints), not coverage. license_tier: ORIGINAL expect_exit: 0 6import "nx_syscalls_x86_64.nx" 7const MAGIC_MAGIC_65536: i64 = 65536 8const MAGIC_MAGIC_16777216: i64 = 16777216 9const MAGIC_MAGIC_4294967296: i64 = 4294967296 10const MAGIC_MAGIC_12593: i64 = 12593 11const MAGIC_MAGIC_12596: i64 = 12596 12const MAGIC_MAGIC_12599: i64 = 12599 13const MAGIC_MAGIC_12609: i64 = 12609 14const MAGIC_MAGIC_12610: i64 = 12610 15const MAGIC_MAGIC_12623: i64 = 12623 16const MAGIC_MAGIC_12627: i64 = 12627 17const MAGIC_MAGIC_12631: i64 = 12631 18const MAGIC_MAGIC_12636: i64 = 12636 19const MAGIC_MAGIC_12643: i64 = 12643 20const MAGIC_MAGIC_20096: i64 = 20096 21const MAGIC_MAGIC_20105: i64 = 20105 22const MAGIC_MAGIC_20108: i64 = 20108 23const MAGIC_MAGIC_21313: i64 = 21313 24const MAGIC_MAGIC_21475: i64 = 21475 25const MAGIC_MAGIC_26085: i64 = 26085 26const MAGIC_MAGIC_29579: i64 = 29579 27const MAGIC_MAGIC_30000: i64 = 30000 28const MAGIC_MAGIC_1024: i64 = 1024 29const MAGIC_MAGIC_16384: i64 = 16384 30const MAGIC_MAGIC_24576: i64 = 24576 31const MAGIC_MAGIC_65535: i64 = 65535 32const MAGIC_MAGIC_1594834165: i64 = 1594834165 33const MAGIC_MAGIC_1033: i64 = 1033 34const MAGIC_MAGIC_196608: i64 = 196608 35const MAGIC_MAGIC_131072: i64 = 131072 36const MAGIC_MAGIC_262144: i64 = 262144 37 38const MAGIC_ADJ: i64 = 2981146554 39 40func sw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 41func sn(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)} 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{bb[i]=t[k-1-i];i=i+1} sys_write(1,bb,k); return 0 } 42 43func si16(v: i64) -> i64 { if v<0 { return v+MAGIC_MAGIC_65536 } return v } 44func w8(b: *u8, o: i64, v: i64) -> i64 { b[o]=(v%256) as u8; return o+1 } 45func w16(b: *u8, o: i64, v: i64) -> i64 { b[o]=((v/256)%256) as u8; b[o+1]=(v%256) as u8; return o+2 } 46func w32(b: *u8, o: i64, v: i64) -> i64 { b[o]=((v/MAGIC_MAGIC_16777216)%256) as u8; b[o+1]=((v/MAGIC_MAGIC_65536)%256) as u8; b[o+2]=((v/256)%256) as u8; b[o+3]=(v%256) as u8; return o+4 } 47func r32(b: *u8, o: i64) -> i64 { return (b[o] as i64)*MAGIC_MAGIC_16777216 + (b[o+1] as i64)*MAGIC_MAGIC_65536 + (b[o+2] as i64)*256 + (b[o+3] as i64) } 48func align4(o: i64) -> i64 { while o%4 != 0 { o=o+1 } return o } 49func csum(b: *u8, off: i64, len: i64) -> i64 { var s: i64=0; var i: i64=off; while i < off+len { s = (s + r32(b,i)) % MAGIC_MAGIC_4294967296; i=i+4 } return s } 50func he_puts(buf: *u8, off: i64, s: *u8) -> i64 { var o: i64=off; var i: i64=0; while s[i]!=0 { buf[o]=s[i]; o=o+1; i=i+1 } return o } 51func b64c(v: i64) -> i64 { if v<26 { return 65+v } if v<52 { return 97+(v-26) } if v<62 { return 48+(v-52) } if v==62 { return 43 } return 47 } 52func b64_encode(inb: *u8, n: i64, out: *u8) -> i64 { 53 var o: i64=0; var i: i64=0 54 while i+3<=n { let a: i64=inb[i] as i64; let b: i64=inb[i+1] as i64; let c: i64=inb[i+2] as i64 55 out[o]=b64c(a/4) as u8; o=o+1; out[o]=b64c((a%4)*16 + b/16) as u8; o=o+1; out[o]=b64c((b%16)*4 + c/64) as u8; o=o+1; out[o]=b64c(c%64) as u8; o=o+1; i=i+3 } 56 let rem: i64=n-i 57 if rem==1 { let a: i64=inb[i] as i64; out[o]=b64c(a/4) as u8; o=o+1; out[o]=b64c((a%4)*16) as u8; o=o+1; out[o]=61 as u8; o=o+1; out[o]=61 as u8; o=o+1 } 58 if rem==2 { let a: i64=inb[i] as i64; let b: i64=inb[i+1] as i64; out[o]=b64c(a/4) as u8; o=o+1; out[o]=b64c((a%4)*16 + b/16) as u8; o=o+1; out[o]=b64c((b%16)*4) as u8; o=o+1; out[o]=61 as u8; o=o+1 } 59 out[o]=0 as u8; return o 60} 61func add_rect(px: *i64, py: *i64, ep: *i64, pc: i64, cc: i64, x0: i64, y0: i64, x1: i64, y1: i64) -> i64 { 62 px[pc]=x0; py[pc]=y0; px[pc+1]=x1; py[pc+1]=y0; px[pc+2]=x1; py[pc+2]=y1; px[pc+3]=x0; py[pc+3]=y1 63 ep[cc]=pc+3; return pc+4 64} 65 66// LATIN: 0 .notdef, 1 space, 2 H, 3 I, 4 T 67func gen_latin(gid: i64, wr: i64, ep: *i64, px: *i64, py: *i64, meta: *i64) -> i64 { 68 if gid==0 { add_rect(px,py,ep,0,0, 80,0,520,700); meta[0]=1; meta[1]=4; return 0 } 69 if gid==1 { meta[0]=0; meta[1]=0; return 0 } 70 if gid==2 { var pc: i64=0 71 pc=add_rect(px,py,ep,pc,0, 210-wr,0,210+wr,700); pc=add_rect(px,py,ep,pc,1, 560-wr,0,560+wr,700); pc=add_rect(px,py,ep,pc,2, 210,350-wr,560,350+wr) 72 meta[0]=3; meta[1]=12; return 0 } 73 if gid==3 { add_rect(px,py,ep,0,0, 385-wr,0,385+wr,700); meta[0]=1; meta[1]=4; return 0 } 74 var tc: i64=0 75 tc=add_rect(px,py,ep,tc,0, 60,700-2*wr,660,700); tc=add_rect(px,py,ep,tc,1, 360-wr,0,360+wr,700) 76 meta[0]=2; meta[1]=8; return 0 77} 78// HANGUL (Korean) jamo: 1 ㄱ, 2 ㄴ, 3 ㄷ, 4 ㅁ, 5 ㅂ, 6 ㅏ, 7 ㅓ, 8 ㅗ, 9 ㅜ, 10 ㅣ 79func gen_hangul(j: i64, wr: i64, ep: *i64, px: *i64, py: *i64, meta: *i64) -> i64 { 80 if j==1 { var pc: i64=0; pc=add_rect(px,py,ep,pc,0, 220,720-2*wr,780,720); pc=add_rect(px,py,ep,pc,1, 780-2*wr,300,780,720); meta[0]=2; meta[1]=8; return 0 } 81 if j==2 { var pc: i64=0; pc=add_rect(px,py,ep,pc,0, 250,280,250+2*wr,720); pc=add_rect(px,py,ep,pc,1, 250,280,780,280+2*wr); meta[0]=2; meta[1]=8; return 0 } 82 if j==3 { var pc: i64=0; pc=add_rect(px,py,ep,pc,0, 250,720-2*wr,780,720); pc=add_rect(px,py,ep,pc,1, 250,280,250+2*wr,720); pc=add_rect(px,py,ep,pc,2, 250,280,780,280+2*wr); meta[0]=3; meta[1]=12; return 0 } 83 if j==4 { var pc: i64=0; pc=add_rect(px,py,ep,pc,0, 280,280,280+2*wr,720); pc=add_rect(px,py,ep,pc,1, 720-2*wr,280,720,720); pc=add_rect(px,py,ep,pc,2, 280,720-2*wr,720,720); pc=add_rect(px,py,ep,pc,3, 280,280,720,280+2*wr); meta[0]=4; meta[1]=16; return 0 } 84 if j==5 { var pc: i64=0; pc=add_rect(px,py,ep,pc,0, 300,260,300+2*wr,740); pc=add_rect(px,py,ep,pc,1, 700-2*wr,260,700,740); pc=add_rect(px,py,ep,pc,2, 300,500-wr,700,500+wr); pc=add_rect(px,py,ep,pc,3, 300,260,700,260+2*wr); meta[0]=4; meta[1]=16; return 0 } 85 if j==6 { var pc: i64=0; pc=add_rect(px,py,ep,pc,0, 440,180,440+2*wr,820); pc=add_rect(px,py,ep,pc,1, 440,500-wr,660,500+wr); meta[0]=2; meta[1]=8; return 0 } 86 if j==7 { var pc: i64=0; pc=add_rect(px,py,ep,pc,0, 540,180,540+2*wr,820); pc=add_rect(px,py,ep,pc,1, 340,500-wr,540,500+wr); meta[0]=2; meta[1]=8; return 0 } 87 if j==8 { var pc: i64=0; pc=add_rect(px,py,ep,pc,0, 220,380-wr,780,380+wr); pc=add_rect(px,py,ep,pc,1, 500-wr,380,500+wr,640); meta[0]=2; meta[1]=8; return 0 } 88 if j==9 { var pc: i64=0; pc=add_rect(px,py,ep,pc,0, 220,560-wr,780,560+wr); pc=add_rect(px,py,ep,pc,1, 500-wr,300,500+wr,560); meta[0]=2; meta[1]=8; return 0 } 89 add_rect(px,py,ep,0,0, 500-wr,180,500+wr,820); meta[0]=1; meta[1]=4; return 0 90} 91// HAN (Chinese): 1 一, 2 三, 3 二, 4 十, 5 口, 6 日, 7 田, 8 王 92func gen_han(h: i64, wr: i64, ep: *i64, px: *i64, py: *i64, meta: *i64) -> i64 { 93 if h==1 { add_rect(px,py,ep,0,0, 120,490-wr,880,490+wr); meta[0]=1; meta[1]=4; return 0 } 94 if h==2 { var pc: i64=0; pc=add_rect(px,py,ep,pc,0, 200,720-wr,800,720+wr); pc=add_rect(px,py,ep,pc,1, 260,490-wr,740,490+wr); pc=add_rect(px,py,ep,pc,2, 140,210-wr,860,210+wr); meta[0]=3; meta[1]=12; return 0 } 95 if h==3 { var pc: i64=0; pc=add_rect(px,py,ep,pc,0, 220,610-wr,780,610+wr); pc=add_rect(px,py,ep,pc,1, 140,290-wr,860,290+wr); meta[0]=2; meta[1]=8; return 0 } 96 if h==4 { var pc: i64=0; pc=add_rect(px,py,ep,pc,0, 120,490-wr,880,490+wr); pc=add_rect(px,py,ep,pc,1, 500-wr,140,500+wr,850); meta[0]=2; meta[1]=8; return 0 } 97 if h==5 { var pc: i64=0; pc=add_rect(px,py,ep,pc,0, 220,220,220+2*wr,780); pc=add_rect(px,py,ep,pc,1, 780-2*wr,220,780,780); pc=add_rect(px,py,ep,pc,2, 220,780-2*wr,780,780); pc=add_rect(px,py,ep,pc,3, 220,220,780,220+2*wr); meta[0]=4; meta[1]=16; return 0 } 98 if h==6 { var pc: i64=0; pc=add_rect(px,py,ep,pc,0, 260,220,260+2*wr,780); pc=add_rect(px,py,ep,pc,1, 740-2*wr,220,740,780); pc=add_rect(px,py,ep,pc,2, 260,780-2*wr,740,780); pc=add_rect(px,py,ep,pc,3, 260,220,740,220+2*wr); pc=add_rect(px,py,ep,pc,4, 260,500-wr,740,500+wr); meta[0]=5; meta[1]=20; return 0 } 99 if h==7 { var pc: i64=0; pc=add_rect(px,py,ep,pc,0, 220,220,220+2*wr,780); pc=add_rect(px,py,ep,pc,1, 780-2*wr,220,780,780); pc=add_rect(px,py,ep,pc,2, 220,780-2*wr,780,780); pc=add_rect(px,py,ep,pc,3, 220,220,780,220+2*wr); pc=add_rect(px,py,ep,pc,4, 220,500-wr,780,500+wr); pc=add_rect(px,py,ep,pc,5, 500-wr,220,500+wr,780); meta[0]=6; meta[1]=24; return 0 } 100 var pc: i64=0 101 pc=add_rect(px,py,ep,pc,0, 220,755-wr,780,755+wr); pc=add_rect(px,py,ep,pc,1, 300,490-wr,700,490+wr); pc=add_rect(px,py,ep,pc,2, 180,225-wr,820,225+wr); pc=add_rect(px,py,ep,pc,3, 500-wr,225,500+wr,755) 102 meta[0]=4; meta[1]=16; return 0 103} 104// dispatch by glyph index: 0-4 Latin, 5-14 Hangul, 15-22 Han 105func gen_uni(gg: i64, wr: i64, ep: *i64, px: *i64, py: *i64, meta: *i64) -> i64 { 106 if gg<=4 { return gen_latin(gg, wr, ep, px, py, meta) } 107 if gg<=14 { return gen_hangul(gg-4, wr, ep, px, py, meta) } 108 return gen_han(gg-14, wr, ep, px, py, meta) 109} 110 111func append_glyph(g: *u8, go: i64, ep: *i64, px: *i64, py: *i64, meta: *i64) -> i64 { 112 let nc: i64=meta[0]; let np: i64=meta[1] 113 if nc==0 { return go } 114 var xmin: i64=px[0]; var xmax: i64=px[0]; var ymin: i64=py[0]; var ymax: i64=py[0] 115 var i: i64=0 116 while i<np { if px[i]<xmin{xmin=px[i]} if px[i]>xmax{xmax=px[i]} if py[i]<ymin{ymin=py[i]} if py[i]>ymax{ymax=py[i]} i=i+1 } 117 var o: i64=go 118 o=w16(g,o,si16(nc)); o=w16(g,o,si16(xmin)); o=w16(g,o,si16(ymin)); o=w16(g,o,si16(xmax)); o=w16(g,o,si16(ymax)) 119 i=0; while i<nc { o=w16(g,o,ep[i]); i=i+1 } 120 o=w16(g,o,0) 121 i=0; while i<np { o=w8(g,o,1); i=i+1 } 122 var prev: i64=0; i=0; while i<np { o=w16(g,o,si16(px[i]-prev)); prev=px[i]; i=i+1 } 123 prev=0; i=0; while i<np { o=w16(g,o,si16(py[i]-prev)); prev=py[i]; i=i+1 } 124 if o%2 != 0 { o=w8(g,o,0) } 125 return o 126} 127 128func main() -> i64 { 129 let NG: i64=23 130 let NCP: i64=22 131 let cp: *i64=sys_mmap(256) as *i64 132 let gd: *i64=sys_mmap(256) as *i64 133 cp[0]=32; gd[0]=1 134 cp[1]=72; gd[1]=2 135 cp[2]=73; gd[2]=3 136 cp[3]=84; gd[3]=4 137 cp[4]=MAGIC_MAGIC_12593; gd[4]=5 138 cp[5]=MAGIC_MAGIC_12596; gd[5]=6 139 cp[6]=MAGIC_MAGIC_12599; gd[6]=7 140 cp[7]=MAGIC_MAGIC_12609; gd[7]=8 141 cp[8]=MAGIC_MAGIC_12610; gd[8]=9 142 cp[9]=MAGIC_MAGIC_12623; gd[9]=10 143 cp[10]=MAGIC_MAGIC_12627; gd[10]=11 144 cp[11]=MAGIC_MAGIC_12631; gd[11]=12 145 cp[12]=MAGIC_MAGIC_12636; gd[12]=13 146 cp[13]=MAGIC_MAGIC_12643; gd[13]=14 147 cp[14]=MAGIC_MAGIC_20096; gd[14]=15 148 cp[15]=MAGIC_MAGIC_20105; gd[15]=16 149 cp[16]=MAGIC_MAGIC_20108; gd[16]=17 150 cp[17]=MAGIC_MAGIC_21313; gd[17]=18 151 cp[18]=MAGIC_MAGIC_21475; gd[18]=19 152 cp[19]=MAGIC_MAGIC_26085; gd[19]=20 153 cp[20]=MAGIC_MAGIC_29579; gd[20]=22 154 cp[21]=MAGIC_MAGIC_30000; gd[21]=21 155 156 let ep: *i64=sys_mmap(256) as *i64 157 let px: *i64=sys_mmap(MAGIC_MAGIC_1024) as *i64 158 let py: *i64=sys_mmap(MAGIC_MAGIC_1024) as *i64 159 let meta: *i64=sys_mmap(16) as *i64 160 let g: *u8=sys_mmap(MAGIC_MAGIC_16384) 161 let goff: *i64=sys_mmap(256) as *i64 162 let wr: i64=58 163 var go: i64=0 164 var q: i64=0 165 while q<NG { goff[q]=go; gen_uni(q,wr,ep,px,py,meta); go=append_glyph(g,go,ep,px,py,meta); q=q+1 } 166 goff[NG]=go 167 let glyf_len: i64=go 168 169 let buf: *u8=sys_mmap(MAGIC_MAGIC_24576) 170 let toff: *i64=sys_mmap(128) as *i64 171 let tlen: *i64=sys_mmap(128) as *i64 172 let tcs: *i64=sys_mmap(128) as *i64 173 let NT: i64=10 174 var o: i64=12 + 16*NT 175 176 o=align4(o); toff[0]=o 177 o=w16(buf,o,4); o=w16(buf,o,si16(800)); o=w16(buf,o,400); o=w16(buf,o,5); o=w16(buf,o,0) 178 o=w16(buf,o,si16(650));o=w16(buf,o,si16(700));o=w16(buf,o,si16(0));o=w16(buf,o,si16(140)) 179 o=w16(buf,o,si16(650));o=w16(buf,o,si16(700));o=w16(buf,o,si16(0));o=w16(buf,o,si16(480)) 180 o=w16(buf,o,si16(50));o=w16(buf,o,si16(260)); o=w16(buf,o,si16(0)) 181 var pi: i64=0; while pi<10 { o=w8(buf,o,0); pi=pi+1 } 182 o=w32(buf,o,0);o=w32(buf,o,0);o=w32(buf,o,0);o=w32(buf,o,0) 183 o=w8(buf,o,78);o=w8(buf,o,73);o=w8(buf,o,83);o=w8(buf,o,72) 184 o=w16(buf,o,64); o=w16(buf,o,32); o=w16(buf,o,MAGIC_MAGIC_30000) 185 o=w16(buf,o,si16(800));o=w16(buf,o,si16(-200));o=w16(buf,o,si16(0)) 186 o=w16(buf,o,880);o=w16(buf,o,150) 187 o=w32(buf,o,0);o=w32(buf,o,0) 188 o=w16(buf,o,si16(500));o=w16(buf,o,si16(700)); o=w16(buf,o,0);o=w16(buf,o,32);o=w16(buf,o,1) 189 tlen[0]=o-toff[0]; o=align4(o); tcs[0]=csum(buf,toff[0],o-toff[0]) 190 191 o=align4(o); toff[1]=o 192 o=w16(buf,o,0); o=w16(buf,o,1); o=w16(buf,o,3); o=w16(buf,o,1); o=w32(buf,o,12) 193 let sub0: i64=o 194 let segCount: i64=NCP+1 195 o=w16(buf,o,4) 196 let lenpos: i64=o; o=w16(buf,o,0) 197 o=w16(buf,o,0) 198 o=w16(buf,o,segCount*2) 199 var p2: i64=1; while p2*2<=segCount { p2=p2*2 } 200 o=w16(buf,o,p2*2) 201 var es: i64=0; var tp: i64=p2; while tp>1 { tp=tp/2; es=es+1 } 202 o=w16(buf,o,es) 203 o=w16(buf,o,segCount*2 - p2*2) 204 var ci: i64=0; while ci<NCP { o=w16(buf,o,cp[ci]); ci=ci+1 } 205 o=w16(buf,o,MAGIC_MAGIC_65535) 206 o=w16(buf,o,0) 207 ci=0; while ci<NCP { o=w16(buf,o,cp[ci]); ci=ci+1 } 208 o=w16(buf,o,MAGIC_MAGIC_65535) 209 ci=0; while ci<NCP { var dd: i64=gd[ci]-cp[ci]; if dd<0 { dd=dd+MAGIC_MAGIC_65536 } o=w16(buf,o,dd); ci=ci+1 } 210 o=w16(buf,o,1) 211 ci=0; while ci<segCount { o=w16(buf,o,0); ci=ci+1 } 212 w16(buf, lenpos, o - sub0) 213 tlen[1]=o-toff[1]; o=align4(o); tcs[1]=csum(buf,toff[1],o-toff[1]) 214 215 o=align4(o); toff[2]=o 216 var gj: i64=0; while gj<glyf_len { buf[o]=g[gj]; o=o+1; gj=gj+1 } 217 tlen[2]=o-toff[2]; o=align4(o); tcs[2]=csum(buf,toff[2],o-toff[2]) 218 219 o=align4(o); toff[3]=o 220 o=w32(buf,o,MAGIC_MAGIC_65536); o=w32(buf,o,MAGIC_MAGIC_65536); o=w32(buf,o,0); o=w32(buf,o,MAGIC_MAGIC_1594834165) 221 o=w16(buf,o,11); o=w16(buf,o,1000) 222 o=w32(buf,o,0);o=w32(buf,o,0); o=w32(buf,o,0);o=w32(buf,o,0) 223 o=w16(buf,o,si16(0));o=w16(buf,o,si16(0));o=w16(buf,o,1000);o=w16(buf,o,850) 224 o=w16(buf,o,0); o=w16(buf,o,8); o=w16(buf,o,2); o=w16(buf,o,0); o=w16(buf,o,0) 225 tlen[3]=o-toff[3]; o=align4(o); tcs[3]=csum(buf,toff[3],o-toff[3]) 226 227 o=align4(o); toff[4]=o 228 o=w32(buf,o,MAGIC_MAGIC_65536); o=w16(buf,o,si16(850)); o=w16(buf,o,si16(-150)); o=w16(buf,o,si16(0)) 229 o=w16(buf,o,1000); o=w16(buf,o,si16(0)); o=w16(buf,o,si16(0)); o=w16(buf,o,si16(1000)) 230 o=w16(buf,o,si16(1)); o=w16(buf,o,si16(0)); o=w16(buf,o,si16(0)) 231 o=w16(buf,o,0);o=w16(buf,o,0);o=w16(buf,o,0);o=w16(buf,o,0) 232 o=w16(buf,o,si16(0)); o=w16(buf,o,NG) 233 tlen[4]=o-toff[4]; o=align4(o); tcs[4]=csum(buf,toff[4],o-toff[4]) 234 235 o=align4(o); toff[5]=o 236 o=w16(buf,o,600);o=w16(buf,o,si16(0)); o=w16(buf,o,400);o=w16(buf,o,si16(0)); o=w16(buf,o,770);o=w16(buf,o,si16(0)); o=w16(buf,o,600);o=w16(buf,o,si16(0)); o=w16(buf,o,720);o=w16(buf,o,si16(0)) 237 var jm: i64=0; while jm<10 { o=w16(buf,o,760); o=w16(buf,o,si16(0)); jm=jm+1 } 238 var hm: i64=0; while hm<8 { o=w16(buf,o,1000); o=w16(buf,o,si16(0)); hm=hm+1 } 239 tlen[5]=o-toff[5]; o=align4(o); tcs[5]=csum(buf,toff[5],o-toff[5]) 240 241 o=align4(o); toff[6]=o 242 var li: i64=0; while li<NG+1 { o=w16(buf,o,goff[li]/2); li=li+1 } 243 tlen[6]=o-toff[6]; o=align4(o); tcs[6]=csum(buf,toff[6],o-toff[6]) 244 245 o=align4(o); toff[7]=o 246 o=w32(buf,o,MAGIC_MAGIC_65536); o=w16(buf,o,NG); o=w16(buf,o,24); o=w16(buf,o,6) 247 o=w16(buf,o,0);o=w16(buf,o,0); o=w16(buf,o,2); o=w16(buf,o,0);o=w16(buf,o,0);o=w16(buf,o,0);o=w16(buf,o,0);o=w16(buf,o,0);o=w16(buf,o,0);o=w16(buf,o,0);o=w16(buf,o,0) 248 tlen[7]=o-toff[7]; o=align4(o); tcs[7]=csum(buf,toff[7],o-toff[7]) 249 250 o=align4(o); toff[8]=o 251 o=w16(buf,o,0); o=w16(buf,o,4); o=w16(buf,o,54) 252 o=w16(buf,o,3);o=w16(buf,o,1);o=w16(buf,o,MAGIC_MAGIC_1033);o=w16(buf,o,1);o=w16(buf,o,30);o=w16(buf,o,0) 253 o=w16(buf,o,3);o=w16(buf,o,1);o=w16(buf,o,MAGIC_MAGIC_1033);o=w16(buf,o,2);o=w16(buf,o,14);o=w16(buf,o,30) 254 o=w16(buf,o,3);o=w16(buf,o,1);o=w16(buf,o,MAGIC_MAGIC_1033);o=w16(buf,o,4);o=w16(buf,o,30);o=w16(buf,o,0) 255 o=w16(buf,o,3);o=w16(buf,o,1);o=w16(buf,o,MAGIC_MAGIC_1033);o=w16(buf,o,6);o=w16(buf,o,18);o=w16(buf,o,44) 256 o=w8(buf,o,0);o=w8(buf,o,78);o=w8(buf,o,0);o=w8(buf,o,105);o=w8(buf,o,0);o=w8(buf,o,115);o=w8(buf,o,0);o=w8(buf,o,104);o=w8(buf,o,0);o=w8(buf,o,105);o=w8(buf,o,0);o=w8(buf,o,32);o=w8(buf,o,0);o=w8(buf,o,85);o=w8(buf,o,0);o=w8(buf,o,110);o=w8(buf,o,0);o=w8(buf,o,105);o=w8(buf,o,0);o=w8(buf,o,118);o=w8(buf,o,0);o=w8(buf,o,101);o=w8(buf,o,0);o=w8(buf,o,114);o=w8(buf,o,0);o=w8(buf,o,115);o=w8(buf,o,0);o=w8(buf,o,97);o=w8(buf,o,0);o=w8(buf,o,108) 257 o=w8(buf,o,0);o=w8(buf,o,82);o=w8(buf,o,0);o=w8(buf,o,101);o=w8(buf,o,0);o=w8(buf,o,103);o=w8(buf,o,0);o=w8(buf,o,117);o=w8(buf,o,0);o=w8(buf,o,108);o=w8(buf,o,0);o=w8(buf,o,97);o=w8(buf,o,0);o=w8(buf,o,114) 258 o=w8(buf,o,0);o=w8(buf,o,78);o=w8(buf,o,0);o=w8(buf,o,105);o=w8(buf,o,0);o=w8(buf,o,115);o=w8(buf,o,0);o=w8(buf,o,104);o=w8(buf,o,0);o=w8(buf,o,105);o=w8(buf,o,0);o=w8(buf,o,85);o=w8(buf,o,0);o=w8(buf,o,110);o=w8(buf,o,0);o=w8(buf,o,105);o=w8(buf,o,0);o=w8(buf,o,118) 259 tlen[8]=o-toff[8]; o=align4(o); tcs[8]=csum(buf,toff[8],o-toff[8]) 260 261 o=align4(o); toff[9]=o 262 o=w32(buf,o,MAGIC_MAGIC_196608); o=w32(buf,o,0); o=w16(buf,o,si16(-100)); o=w16(buf,o,50); o=w32(buf,o,0);o=w32(buf,o,0);o=w32(buf,o,0);o=w32(buf,o,0);o=w32(buf,o,0) 263 tlen[9]=o-toff[9]; o=align4(o); tcs[9]=csum(buf,toff[9],o-toff[9]) 264 265 let total: i64=o 266 var hh: i64=0 267 hh=w32(buf,hh,MAGIC_MAGIC_65536); hh=w16(buf,hh,NT); hh=w16(buf,hh,128); hh=w16(buf,hh,3); hh=w16(buf,hh,32) 268 let tags: *u8="OS/2cmapglyfheadhheahmtxlocamaxpnamepost" as *u8 269 var d: i64=12; var ti: i64=0 270 while ti<NT { buf[d]=tags[ti*4]; buf[d+1]=tags[ti*4+1]; buf[d+2]=tags[ti*4+2]; buf[d+3]=tags[ti*4+3] 271 w32(buf,d+4,tcs[ti]); w32(buf,d+8,toff[ti]); w32(buf,d+12,tlen[ti]); d=d+16; ti=ti+1 } 272 let fsum0: i64=csum(buf,0,total) 273 var adj: i64=MAGIC_ADJ - fsum0 274 if adj<0 { adj=adj+MAGIC_MAGIC_4294967296 } 275 w32(buf, toff[3]+8, adj) 276 277 let fd: i64=sys_openat_wr("web_assets/nishi_universal.ttf" as *u8, 420) 278 if fd<0 { sw("SAVE-FAIL\n" as *u8); return 6 } 279 sys_write(fd, buf, total); sys_close(fd) 280 let fs: i64=csum(buf,0,total) 281 sw("nx_font_universal: Latin+Chinese+Korean in ONE font -> web_assets/nishi_universal.ttf (" as *u8); sn(total); sw("B) self-check=" as *u8) 282 if fs==MAGIC_ADJ { sw("PASS\n" as *u8) } else { sw("FAIL\n" as *u8) } 283 284 let b64: *u8=sys_mmap(MAGIC_MAGIC_131072) 285 b64_encode(buf, total, b64) 286 let pg: *u8=sys_mmap(MAGIC_MAGIC_262144) 287 var po: i64=0 288 po=he_puts(pg,po,"<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><meta name=\"color-scheme\" content=\"dark\"><title>Nishi Universal &mdash; one sovereign font, three scripts</title><style>@font-face{font-family:'Nishi Universal';src:url(data:font/ttf;base64," as *u8) 289 po=he_puts(pg,po,b64) 290 po=he_puts(pg,po,") format('truetype')}*{box-sizing:border-box}body{margin:0;min-height:100vh;display:grid;place-items:center;background:radial-gradient(1100px 560px at 50% -10%,#161326,#0A0A0F);color:#F5F5FA;font-family:ui-sans-serif,system-ui,sans-serif}.wrap{text-align:center;padding:32px;max-width:1000px}.tag{display:inline-block;font-size:.8rem;letter-spacing:.2em;text-transform:uppercase;color:#9EA0B8;margin-bottom:18px}.big{font-family:'Nishi Universal';font-size:clamp(2.6rem,11vw,7rem);line-height:1.25;letter-spacing:.08em;background:linear-gradient(100deg,#8A7BFF,#FF7A59);-webkit-background-clip:text;background-clip:text;color:transparent}.lbl{font-size:.72rem;letter-spacing:.16em;text-transform:uppercase;color:#6f7290;margin:2px 0 18px}.note{color:#9EA0B8;max-width:54ch;margin:30px auto 0;font-size:1.05rem;line-height:1.65}.note b{color:#F5F5FA}.mono{font-family:ui-monospace,Consolas,monospace;color:#8A7BFF}</style></head><body><div class=\"wrap\">" as *u8) 291 po=he_puts(pg,po,"<span class=\"tag\">&#9733; ONE sovereign font &middot; three writing systems</span>" as *u8) 292 po=he_puts(pg,po,"<div class=\"big\">HI IT</div><div class=\"lbl\">Latin &mdash; English</div>" as *u8) 293 po=he_puts(pg,po,"<div class=\"big\">&#x4E00;&#x4E8C;&#x4E09;&#x5341;&#x53E3;&#x65E5;&#x7530;&#x738B;</div><div class=\"lbl\">Han &mdash; Chinese</div>" as *u8) 294 po=he_puts(pg,po,"<div class=\"big\">&#x3131;&#x3134;&#x3137;&#x3141;&#x3142; &#x314F;&#x3153;&#x3157;&#x315C;&#x3163;</div><div class=\"lbl\">Hangul &mdash; Korean</div>" as *u8) 295 po=he_puts(pg,po,"<p class=\"note\">Every glyph above &mdash; Latin, Chinese Han, and Korean Hangul &mdash; is generated by the SAME stroke engine (<span class=\"mono\">nx_font_universal</span>) into ONE self-validated <span class=\"mono\">.ttf</span>, each mapped to its true Unicode codepoint. That is the &ldquo;all languages&rdquo; direction, sovereign and reproducible. HONEST: 21 codepoints is a breadth <b>proof</b>, not coverage &mdash; full pan-Unicode is the long climb (CJK alone = 101,000+ characters).</p>" as *u8) 296 po=he_puts(pg,po,"</div></body></html>" as *u8) 297 let pfd: i64=sys_openat_wr("web_assets/nishi_universal.html" as *u8, 420) 298 if pfd<0 { sw("PAGE-FAIL\n" as *u8); return 7 } 299 sys_write(pfd, pg, po); sys_close(pfd) 300 sw(" -> web_assets/nishi_universal.html (English + Chinese + Korean, one font)\n" as *u8) 301 return 0 302}