nx_font_research_fetch.nx source
↩ module page · 73 lines · 4869 B
1// nx_font_research_fetch.nx -- the Nishi RESEARCHER's sovereign LIVE fetch to ground a SOVEREIGN FONT capability
2// (our own typeface, hardware-rung-up): glyph geometry (Bezier contours), the TrueType/OpenType/WOFF file formats
3// (the binary tables a browser/OS loads), rasterization (glyph->antialiased pixels), hinting, shaping, and digital
4// typography. Mirrors the proven nx_award_ui_research_fetch pattern (own TLS-1.3, Mozilla CA, idempotent have-skip)
5// -> knowledge/fetched/font_*.raw. 100% sovereign. 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("FONT: 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("== GLYPH GEOMETRY (the lowest rung: outline as contours) ==\n" as *u8)
51 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Glyph" as *u8, "knowledge/fetched/font_glyph.raw" as *u8, store, out, cap)
52 ok = ok + fetch_save("https://en.wikipedia.org/wiki/B%C3%A9zier_curve" as *u8, "knowledge/fetched/font_bezier.raw" as *u8, store, out, cap)
53 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Vector_graphics" as *u8, "knowledge/fetched/font_vector.raw" as *u8, store, out, cap)
54
55 ff_puts("== FONT FILE FORMATS (the tables a browser/OS loads) ==\n" as *u8)
56 ok = ok + fetch_save("https://en.wikipedia.org/wiki/TrueType" as *u8, "knowledge/fetched/font_truetype.raw" as *u8, store, out, cap)
57 ok = ok + fetch_save("https://en.wikipedia.org/wiki/OpenType" as *u8, "knowledge/fetched/font_opentype.raw" as *u8, store, out, cap)
58 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Web_Open_Font_Format" as *u8, "knowledge/fetched/font_woff.raw" as *u8, store, out, cap)
59 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Computer_font" as *u8, "knowledge/fetched/font_computer.raw" as *u8, store, out, cap)
60
61 ff_puts("== RASTERIZATION / HINTING / SHAPING ==\n" as *u8)
62 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Font_rasterization" as *u8, "knowledge/fetched/font_raster.raw" as *u8, store, out, cap)
63 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Font_hinting" as *u8, "knowledge/fetched/font_hinting.raw" as *u8, store, out, cap)
64 ok = ok + fetch_save("https://en.wikipedia.org/wiki/FreeType" as *u8, "knowledge/fetched/font_freetype.raw" as *u8, store, out, cap)
65 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Complex_text_layout" as *u8, "knowledge/fetched/font_shaping.raw" as *u8, store, out, cap)
66
67 ff_puts("== TYPOGRAPHY (design of the letterforms) ==\n" as *u8)
68 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Typeface" as *u8, "knowledge/fetched/font_typeface.raw" as *u8, store, out, cap)
69 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Digital_typography" as *u8, "knowledge/fetched/font_digitaltype.raw" as *u8, store, out, cap)
70
71 ff_puts("== TOTAL SAVED/HAVE = " as *u8); ff_putn(ok); ff_puts(" ==\n" as *u8)
72 return 0
73}