code wiki / _hdl_build / nx_ttf_fontlib.nx

nx_ttf_fontlib.nx

buildroot/runtime/_hdl_build/nx_ttf_fontlib.nx

13954 B341 linesdepth 4pulls 4 transitivereach 2 importersview sourcekind librarytopic ttf
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_paint_solid_rect.nx nx_ttf_fontlib.nx nx_font_mockup.nx nx_ttf_fontlib_gate.nx

imports: nx_syscalls.nxnx_paint_solid_rect.nx

imported by: nx_font_mockup.nxnx_ttf_fontlib_gate.nx

structs

none

consts

13const TF_MAGIC_32768: i64 = 32768
14const TF_MAGIC_65536: i64 = 65536
15const TF_MAGIC_16777216: i64 = 16777216
16const TF_MAGIC_2048: i64 = 2048
141const TF_MAXSZ: i64 = 16
142const TF_ASC: i64 = 760 // em top of the pixel box (hhea ascent); box spans [ASC-1000 .. ASC]

functions

18func tf_rd16(b: *u8, o: i64) -> i64 { return (b[o] as i64)*256 + (b[o+1] as i64) }
19func 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 }
20func 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) }
21func tf_bit(f: i64, m: i64) -> i64 { if (f/m)%2 == 1 { return 1 } return 0 }
called by 1: tf_glyph_edges
23func tf_find_table(b: *u8, t0: i64, t1: i64, t2: i64, t3: i64) -> i64
called by 2: tf_load_buftf_load calls 2: tf_rd16tf_rd32
31func tf_cmap_lookup(b: *u8, sub: i64, c: i64) -> i64
called by 1: tf_glyph calls 2: tf_rd16tf_rd16s
51func tf_glyph_edges(b: *u8, glyf: i64, loca: i64, locfmt: i64, gid: i64, ex0: *i64, ey0: *i64, ex1: *i64, ey1: *i64) -> i64
121func tf_inside(gx: i64, gy: i64, ex0: *i64, ey0: *i64, ex1: *i64, ey1: *i64, ne: i64) -> i64
called by 1: tf_glyph
147func tf_load_buf(b: *u8, len: i64) -> *i64
176func tf_load(path: *u8) -> *i64
208func tf_glyph(fh: *i64, ch: i64, ph: i64) -> *i64
276func 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
called by 2: mk_para_vecmain calls 1: tf_glyph
336func tf_char_adv(fh: *i64, ch: i64, ph: i64) -> i64
called by 2: mk_para_vecmain calls 1: tf_glyph