code wiki / _hdl_build / nx_font_specimen.nx
nx_font_specimen.nx source
↩ module page · 119 lines · 6142 B
1// nx_font_specimen.nx -- one comprehensive SPECIMEN SHEET of the sovereign parametric typeface, rendered
2// through the real engine so the results can be EYEBALLED: title + all 6 styles (pangram each) + the full
3// alphabet in Regular and Geometric + a body paragraph in each (the real reading test). One tall PNG.
4// license_tier: ORIGINAL expect_exit: 0
5import "nx_font.nx"
6import "nx_aa_raster.nx"
7import "nx_png_write.nx"
8const K_MAGIC_400000: i64 = 400000
9const K_MAGIC_40000: i64 = 40000
10
11func sp_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
12func sp_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
13
14const CW: i64 = 1560
15const CH: i64 = 2260
16
17// render one line of `text` at (x, ytop) into the canvas, em size empx, ink colour col (0xRRGGBB).
18func sp_line(canvas: *u8, x: i64, ytop: i64, text: *u8, empx: i64, col: i64) -> i64 {
19 let n: i64 = sp_slen(text)
20 let ss: i64 = 3
21 let S: i64 = empx * ss
22 let LH: i64 = empx + empx/4
23 let xs: *i64 = sys_mmap(8*K_MAGIC_400000) as *i64
24 let ys: *i64 = sys_mmap(8*K_MAGIC_400000) as *i64
25 let cstart: *i64 = sys_mmap(8*K_MAGIC_40000) as *i64
26 let clen: *i64 = sys_mmap(8*K_MAGIC_40000) as *i64
27 let np: *i64 = sys_mmap(16) as *i64; np[0]=0
28 let nc: *i64 = sys_mmap(16) as *i64; nc[0]=0
29 let cs: *i64 = sys_mmap(8*20) as *i64
30 let sn: *i64 = sys_mmap(8*20) as *i64
31 font_trig_init(cs, sn)
32 font_text(text, n, xs, ys, cstart, clen, np, nc, cs, sn, x*ss, 0, S)
33 let cov: *u8 = sys_mmap(CW*LH + 16)
34 var z: i64 = 0
35 while z < CW*LH { cov[z]=0 as u8; z=z+1 }
36 aa_render(xs, ys, cstart, clen, nc[0], cov, CW, LH, ss)
37 let r: i64 = (col>>16)&255
38 let g: i64 = (col>>8)&255
39 let b: i64 = col&255
40 aa_blit(canvas, CW, CH, 0, ytop, cov, CW, LH, r, g, b)
41 return 0
42}
43
44func main() -> i64 {
45 sp_puts("rendering the specimen sheet...\n" as *u8)
46 let canvas: *u8 = sys_mmap(CW*CH*3 + 64)
47 var i: i64 = 0
48 while i < CW*CH*3 { canvas[i]=255 as u8; i=i+1 } // white
49
50 let INK: i64 = 0x141422
51 let GRY: i64 = 0x8a90a0
52 let pangram: *u8 = "The quick brown fox jumps over the lazy dog\x00" as *u8
53
54 font_spec_reset()
55 sp_line(canvas, 60, 40, "Nishi Sans\x00" as *u8, 92, INK)
56 sp_line(canvas, 66, 150, "a sovereign parametric typeface -- six styles from one glyph program\x00" as *u8, 26, GRY)
57
58 var y: i64 = 250
59 // --- Light ---
60 font_spec_reset()
61 sp_line(canvas, 66, y, "LIGHT\x00" as *u8, 18, GRY); sp_line(canvas, 220, y-8, pangram, 38, INK)
62 y = y + 100
63 // --- Regular ---
64 font_spec_reset()
65 sp_line(canvas, 66, y, "REGULAR\x00" as *u8, 18, GRY)
66 font_spec_reset()
67 sp_line(canvas, 220, y-8, pangram, 38, INK)
68 y = y + 100
69 // --- Bold ---
70 font_spec_reset()
71 sp_line(canvas, 66, y, "BOLD\x00" as *u8, 18, GRY)
72 font_spec(160,0,0,0); sp_line(canvas, 220, y-8, pangram, 38, INK); font_spec_reset()
73 y = y + 100
74 // --- Soft ---
75 sp_line(canvas, 66, y, "SOFT\x00" as *u8, 18, GRY)
76 font_spec(123,12,1,1); sp_line(canvas, 220, y-8, pangram, 38, INK); font_spec_reset()
77 y = y + 100
78 // --- Oblique ---
79 sp_line(canvas, 66, y, "OBLIQUE\x00" as *u8, 18, GRY)
80 font_spec_slant(18); sp_line(canvas, 220, y-8, pangram, 38, INK); font_spec_reset()
81 y = y + 100
82 // --- Geometric ---
83 sp_line(canvas, 66, y, "GEOMETRIC\x00" as *u8, 18, GRY)
84 font_spec_geo(1); font_spec_mod(100); font_spec_swell(100); sp_line(canvas, 220, y-8, pangram, 38, INK); font_spec_reset()
85 y = y + 140
86
87 // --- alphabet: Regular then Geometric ---
88 sp_line(canvas, 66, y, "REGULAR alphabet\x00" as *u8, 18, GRY); y = y + 44
89 font_spec_reset()
90 sp_line(canvas, 66, y, "ABCDEFGHIJKLMNOPQRSTUVWXYZ\x00" as *u8, 40, INK); y = y + 70
91 sp_line(canvas, 66, y, "abcdefghijklmnopqrstuvwxyz 0123456789\x00" as *u8, 40, INK); y = y + 100
92 sp_line(canvas, 66, y, "GEOMETRIC alphabet\x00" as *u8, 18, GRY); y = y + 44
93 font_spec_geo(1); font_spec_mod(100); font_spec_swell(100)
94 sp_line(canvas, 66, y, "ABCDEFGHIJKLMNOPQRSTUVWXYZ\x00" as *u8, 40, INK); y = y + 70
95 sp_line(canvas, 66, y, "abcdefghijklmnopqrstuvwxyz 0123456789\x00" as *u8, 40, INK); y = y + 110
96 font_spec_reset()
97
98 // --- VARIATION: one professional (Geometric) face across three axes ---
99 let hb: *u8 = "Hamburgevons 2026\x00" as *u8
100 sp_line(canvas, 66, y, "VARIATION -- one geometric face, three axes\x00" as *u8, 20, 0x2b6cb0); y = y + 54
101 sp_line(canvas, 66, y, "WEIGHT\x00" as *u8, 15, GRY); y = y + 26
102 font_spec_geo(1); font_spec_mod(100); font_spec_swell(100); font_spec(95,0,0,0); font_spec_geo(1); font_spec_mod(100); font_spec_swell(100); sp_line(canvas, 66, y, hb, 34, INK); y=y+56
103 font_spec_reset(); font_spec_geo(1); font_spec_mod(100); font_spec_swell(100); sp_line(canvas, 66, y, hb, 34, INK); y=y+56
104 font_spec_reset(); font_spec_geo(1); font_spec_mod(100); font_spec_swell(100); font_spec(160,0,0,0); font_spec_geo(1); font_spec_mod(100); font_spec_swell(100); sp_line(canvas, 66, y, hb, 34, INK); y=y+72
105 font_spec_reset()
106 sp_line(canvas, 66, y, "WIDTH\x00" as *u8, 15, GRY); y = y + 26
107 font_spec_geo(1); font_spec_mod(100); font_spec_swell(100); font_spec_wdth(78); sp_line(canvas, 66, y, hb, 34, INK); y=y+56
108 font_spec_reset(); font_spec_geo(1); font_spec_mod(100); font_spec_swell(100); sp_line(canvas, 66, y, hb, 34, INK); y=y+56
109 font_spec_reset(); font_spec_geo(1); font_spec_mod(100); font_spec_swell(100); font_spec_wdth(128); sp_line(canvas, 66, y, hb, 34, INK); y=y+72
110 font_spec_reset()
111 sp_line(canvas, 66, y, "SLANT\x00" as *u8, 15, GRY); y = y + 26
112 font_spec_geo(1); font_spec_mod(100); font_spec_swell(100); sp_line(canvas, 66, y, hb, 34, INK); y=y+56
113 font_spec_reset(); font_spec_geo(1); font_spec_mod(100); font_spec_swell(100); font_spec_slant(16); sp_line(canvas, 66, y, hb, 34, INK)
114 font_spec_reset()
115
116 nx_png_write_rgb("knowledge/status/font_specimen.png\x00" as *u8, canvas, CW, CH)
117 sp_puts("wrote knowledge/status/font_specimen.png\n" as *u8)
118 return 0
119}