code wiki / _hdl_build / nx_ttf_fontlib.nx
nx_ttf_fontlib.nx
buildroot/runtime/_hdl_build/nx_ttf_fontlib.nx
about
nx_ttf_fontlib.nx -- the sovereign TrueType FONT ENGINE as a LIBRARY (the browser's text renderer).
Canonical home of the TTF read path first proven in the nx_ttf_raster demo (which has a main() and so
cannot be imported): sfnt dir -> head/cmap/loca/glyf/hhea/hmtx, cmap format-4, glyf outline decode
(flags/short/same/repeat), quadratic Bezier flattening, NONZERO-WINDING scan conversion with SSxSS
supersampled ANTI-ALIASED coverage -- plus what the demo lacked: a per-(char,size) COVERAGE CACHE
(each glyph rasterizes once per size), REAL per-glyph advances from hmtx (proportional metrics), a
mild contrast curve (stem darkening at small sizes), and an RGBA-framebuffer ALPHA-BLEND draw
(nx_framebuffer px = R,G,B,A) -- the piece the CSS-on-native arc named as "R4b the browser wire-in".
Fonts: our own emitted web_assets/nishi_sans.ttf (96 glyphs, FULL printable ASCII). No FreeType, no GDI.
license_tier: ORIGINAL
dependencies 2 imports · 2 importers
imports: nx_syscalls.nxnx_paint_solid_rect.nx
imported by: nx_font_mockup.nxnx_ttf_fontlib_gate.nx
structs
| none |
consts
| 13 | const TF_MAGIC_32768: i64 = 32768 |
| 14 | const TF_MAGIC_65536: i64 = 65536 |
| 15 | const TF_MAGIC_16777216: i64 = 16777216 |
| 16 | const TF_MAGIC_2048: i64 = 2048 |
| 141 | const TF_MAXSZ: i64 = 16 |
| 142 | const TF_ASC: i64 = 760 // em top of the pixel box (hhea ascent); box spans [ASC-1000 .. ASC] |
functions
| 18 | func tf_rd16(b: *u8, o: i64) -> i64 { return (b[o] as i64)*256 + (b[o+1] as i64) } |
| 19 | func tf_rd16s(b: *u8, o: i64) -> i64 { let v: i64=tf_rd16(b,o); if v>=TF_MAGIC_32768 { return v-TF_MAGIC_65536 } return v } |
| 20 | func tf_rd32(b: *u8, o: i64) -> i64 { return (b[o] as i64)*TF_MAGIC_16777216 + (b[o+1] as i64)*TF_MAGIC_65536 + (b[o+2] as i64)*256 + (b[o+3] as i64) } |
| 21 | func tf_bit(f: i64, m: i64) -> i64 { if (f/m)%2 == 1 { return 1 } return 0 } called by 1: tf_glyph_edges |
| 23 | func tf_find_table(b: *u8, t0: i64, t1: i64, t2: i64, t3: i64) -> i64 |
| 31 | func tf_cmap_lookup(b: *u8, sub: i64, c: i64) -> i64 |
| 51 | func tf_glyph_edges(b: *u8, glyf: i64, loca: i64, locfmt: i64, gid: i64, ex0: *i64, ey0: *i64, ex1: *i64, ey1: *i64) -> i64 |
| 121 | func tf_inside(gx: i64, gy: i64, ex0: *i64, ey0: *i64, ex1: *i64, ey1: *i64, ne: i64) -> i64 called by 1: tf_glyph |
| 147 | func tf_load_buf(b: *u8, len: i64) -> *i64 |
| 176 | func tf_load(path: *u8) -> *i64 |
| 208 | func tf_glyph(fh: *i64, ch: i64, ph: i64) -> *i64 called by 3: tf_draw_texttf_char_advmain calls 5: tf_cmap_lookuptf_rd16sys_mmaptf_glyph_edgestf_inside |
| 276 | func tf_draw_text(fh: *i64, fb: *Framebuffer, x: i64, y: i64, s: *u8, n: i64, ph: i64, cr: i64, cg: i64, cb: i64, cellw: i64) -> i64 |
| 336 | func tf_char_adv(fh: *i64, ch: i64, ph: i64) -> i64 |