code wiki / (root) / nx_font_legib_research_fetch.nx

nx_font_legib_research_fetch.nx source

↩ module page · 65 lines · 4002 B

1// nx_font_legib_research_fetch.nx -- Nishi RESEARCHER: ground an S-CLASS-EXCEED bar for LEGIBILITY + ACCESSIBILITY 2// (ADA / dyslexia / low-vision) + beauty. Fetches the real references: Atkinson Hyperlegible (Braille Institute's 3// low-vision typeface -- the gold standard for character disambiguation), dyslexia + OpenDyslexic principles, 4// legibility & readability science, x-height, and Frutiger/Verdana (legibility landmarks). -> knowledge/fetched/leg_*.raw 5// 100% sovereign (own TLS-1.3, Mozilla CA, idempotent). expect_exit: 0 license_tier: ORIGINAL 6import "nx_syscalls.nx" 7import "nx_x509_trust_store.nx" 8import "nx_trust_store_load_from_certdata.nx" 9import "nx_https_fetch_follow.nx" 10const K_MAGIC_4194304: i64 = 4194304 11const K_MAGIC_8388608: i64 = 8388608 12 13func ff_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 14func ff_putn(v: i64) -> i64 { 15 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 } 16 var m: i64 = v 17 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m } 18 let d: *u8 = sys_mmap(24); var k: i64 = 0 19 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 20 var j: i64 = k - 1 21 while j >= 0 { sys_write(1, ((d as i64)+j) as *u8, 1); j = j - 1 } 22 return 0 23} 24func have_file(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 } 25func fetch_save(url: *u8, opath: *u8, store: *TrustStore, out: *u8, cap: i64) -> i64 { 26 if have_file(opath) == 1 { ff_puts(opath); ff_puts(" [have-skip]\n" as *u8); return 1 } 27 let status: *i64 = sys_mmap(8) as *i64 28 let n: i64 = nx_https_fetch_follow(url, store, out, cap, 6, status) 29 ff_puts(url); ff_puts(" status=" as *u8); ff_putn(status[0]); ff_puts(" bytes=" as *u8); ff_putn(n) 30 if n <= 0 { ff_puts(" FETCH-FAIL\n" as *u8); return 0 } 31 var gz: i64 = 0 32 if n >= 2 { if out[0] == 0x1f as u8 { if out[1] == 0x8b as u8 { gz = 1 } } } 33 if gz == 1 { ff_puts(" [GZIP-skip]\n" as *u8); return 0 } 34 let fd: i64 = sys_openat_wr(opath, 0x1a4) 35 if fd < 0 { ff_puts(" SAVE-FAIL\n" as *u8); return 0 } 36 sys_write(fd, out, n); sys_close(fd) 37 ff_puts(" SAVED\n" as *u8) 38 return 1 39} 40 41func main() -> i64 { 42 let r: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, 512, K_MAGIC_4194304) 43 if r <= 0 { ff_puts("LEG: certdata load failed\n" as *u8); return 1 } 44 let store: *TrustStore = r as *TrustStore 45 ff_puts("CA roots=" as *u8); ff_putn(trust_store_count(store)); ff_puts("\n" as *u8) 46 let cap: i64 = K_MAGIC_8388608 47 let out: *u8 = sys_mmap(cap) 48 var ok: i64 = 0 49 50 ff_puts("== LOW-VISION / DISAMBIGUATION (Atkinson Hyperlegible = the gold standard) ==\n" as *u8) 51 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Atkinson_Hyperlegible" as *u8, "knowledge/fetched/leg_atkinson.raw" as *u8, store, out, cap) 52 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Legibility" as *u8, "knowledge/fetched/leg_legibility.raw" as *u8, store, out, cap) 53 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Readability" as *u8, "knowledge/fetched/leg_readability.raw" as *u8, store, out, cap) 54 55 ff_puts("== DYSLEXIA (mirrored-letter disambiguation, weighting) ==\n" as *u8) 56 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Dyslexia" as *u8, "knowledge/fetched/leg_dyslexia.raw" as *u8, store, out, cap) 57 58 ff_puts("== TYPE ANATOMY FOR LEGIBILITY (x-height, aperture, landmarks) ==\n" as *u8) 59 ok = ok + fetch_save("https://en.wikipedia.org/wiki/X-height" as *u8, "knowledge/fetched/leg_xheight.raw" as *u8, store, out, cap) 60 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Frutiger_(typeface)" as *u8, "knowledge/fetched/leg_frutiger.raw" as *u8, store, out, cap) 61 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Verdana" as *u8, "knowledge/fetched/leg_verdana.raw" as *u8, store, out, cap) 62 63 ff_puts("== TOTAL SAVED/HAVE = " as *u8); ff_putn(ok); ff_puts(" ==\n" as *u8) 64 return 0 65}