nx_font_gen_research_fetch.nx source
↩ module page · 72 lines · 4717 B
1// nx_font_gen_research_fetch.nx -- the Nishi RESEARCHER's sovereign LIVE fetch to DEFINE what "s-class exceed"
2// means for a FONT GENERATOR + ALL LANGUAGES (operator's ask). Grounds the bar in real SOTA: parametric font
3// generation (Metafont), variable fonts, pan-Unicode coverage (Noto = the "every language" benchmark), the
4// character universe (Unicode / CJK / Han / Arabic / Devanagari / writing systems), complex-text shaping
5// (HarfBuzz), and the incumbent generator toolchain (FontForge). Mirrors the proven fetch pattern (own TLS-1.3,
6// Mozilla CA, idempotent have-skip) -> knowledge/fetched/fg_*.raw. 100% sovereign. expect_exit: 0 license_tier: ORIGINAL
7import "nx_syscalls.nx"
8import "nx_x509_trust_store.nx"
9import "nx_trust_store_load_from_certdata.nx"
10import "nx_https_fetch_follow.nx"
11const K_MAGIC_4194304: i64 = 4194304
12const K_MAGIC_8388608: i64 = 8388608
13
14func 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 }
15func ff_putn(v: i64) -> i64 {
16 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 }
17 var m: i64 = v
18 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
19 let d: *u8 = sys_mmap(24); var k: i64 = 0
20 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
21 var j: i64 = k - 1
22 while j >= 0 { sys_write(1, ((d as i64)+j) as *u8, 1); j = j - 1 }
23 return 0
24}
25func have_file(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 }
26func fetch_save(url: *u8, opath: *u8, store: *TrustStore, out: *u8, cap: i64) -> i64 {
27 if have_file(opath) == 1 { ff_puts(opath); ff_puts(" [have-skip]\n" as *u8); return 1 }
28 let status: *i64 = sys_mmap(8) as *i64
29 let n: i64 = nx_https_fetch_follow(url, store, out, cap, 6, status)
30 ff_puts(url); ff_puts(" status=" as *u8); ff_putn(status[0]); ff_puts(" bytes=" as *u8); ff_putn(n)
31 if n <= 0 { ff_puts(" FETCH-FAIL\n" as *u8); return 0 }
32 var gz: i64 = 0
33 if n >= 2 { if out[0] == 0x1f as u8 { if out[1] == 0x8b as u8 { gz = 1 } } }
34 if gz == 1 { ff_puts(" [GZIP-skip]\n" as *u8); return 0 }
35 let fd: i64 = sys_openat_wr(opath, 0x1a4)
36 if fd < 0 { ff_puts(" SAVE-FAIL\n" as *u8); return 0 }
37 sys_write(fd, out, n); sys_close(fd)
38 ff_puts(" SAVED\n" as *u8)
39 return 1
40}
41
42func main() -> i64 {
43 let r: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, 512, K_MAGIC_4194304)
44 if r <= 0 { ff_puts("FG: certdata load failed\n" as *u8); return 1 }
45 let store: *TrustStore = r as *TrustStore
46 ff_puts("CA roots=" as *u8); ff_putn(trust_store_count(store)); ff_puts("\n" as *u8)
47 let cap: i64 = K_MAGIC_8388608
48 let out: *u8 = sys_mmap(cap)
49 var ok: i64 = 0
50
51 ff_puts("== PARAMETRIC / VARIABLE GENERATION (the 'generator not one font' bar) ==\n" as *u8)
52 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Metafont" as *u8, "knowledge/fetched/fg_metafont.raw" as *u8, store, out, cap)
53 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Variable_font" as *u8, "knowledge/fetched/fg_variable.raw" as *u8, store, out, cap)
54 ok = ok + fetch_save("https://en.wikipedia.org/wiki/FontForge" as *u8, "knowledge/fetched/fg_fontforge.raw" as *u8, store, out, cap)
55
56 ff_puts("== ALL LANGUAGES: pan-Unicode coverage (Noto = the benchmark) ==\n" as *u8)
57 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Noto_fonts" as *u8, "knowledge/fetched/fg_noto.raw" as *u8, store, out, cap)
58 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Unicode" as *u8, "knowledge/fetched/fg_unicode.raw" as *u8, store, out, cap)
59 ok = ok + fetch_save("https://en.wikipedia.org/wiki/List_of_writing_systems" as *u8, "knowledge/fetched/fg_writingsystems.raw" as *u8, store, out, cap)
60
61 ff_puts("== THE HARD SCRIPTS (CJK scale + complex shaping) ==\n" as *u8)
62 ok = ok + fetch_save("https://en.wikipedia.org/wiki/CJK_Unified_Ideographs" as *u8, "knowledge/fetched/fg_cjk.raw" as *u8, store, out, cap)
63 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Han_unification" as *u8, "knowledge/fetched/fg_hanunif.raw" as *u8, store, out, cap)
64 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Arabic_script" as *u8, "knowledge/fetched/fg_arabic.raw" as *u8, store, out, cap)
65 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Devanagari" as *u8, "knowledge/fetched/fg_devanagari.raw" as *u8, store, out, cap)
66
67 ff_puts("== SHAPING ENGINE (complex text layout) ==\n" as *u8)
68 ok = ok + fetch_save("https://en.wikipedia.org/wiki/HarfBuzz" as *u8, "knowledge/fetched/fg_harfbuzz.raw" as *u8, store, out, cap)
69
70 ff_puts("== TOTAL SAVED/HAVE = " as *u8); ff_putn(ok); ff_puts(" ==\n" as *u8)
71 return 0
72}