code wiki / _hdl_build / nx_docx.nx
nx_docx.nx
buildroot/runtime/_hdl_build/nx_docx.nx
about
nx_docx.nx -- SOVEREIGN MS-Word (.docx / OOXML) interop for the Nishi Office suite. A .docx is an OPC package
= a ZIP of XML parts (framed by the shared nx_opc). This organ READS and WRITES real .docx with ZERO 3rd-party
code:
write : paragraphs -> a minimal valid OPC package ([Content_Types].xml + _rels/.rels + word/document.xml)
-> a file Microsoft Word / unzip can open.
read : a .docx -> the text of word/document.xml (STORED and DEFLATE entries both handled via nx_opc),
extracting each <w:t> run and joining runs with newlines, unescaping XML entities.
This is the "lawyers make native edits / interop with Microsoft Office" keystone; nx_mailmerge composes on top.
Sovereignty = our own ZIP+OOXML; rigor (non-novel-format doctrine) = the harness ALSO proves a 3rd-party
unzip/zipfile opens what we write and that we read what it writes.
nx_docx write <path.docx> <paragraph1> [paragraph2 ...]
nx_docx read <path.docx>
license_tier: ORIGINAL
dependencies 3 imports · 2 importers
imports: nx_syscalls.nxnx_itoa_lib.nxnx_opc.nx
imported by: nx_mailmerge.nxnx_vizsla_docgen.nx
structs
| none |
consts
| 17 | const K_MAGIC_1048592: i64 = 1048592 |
| 18 | const K_MAGIC_1048576: i64 = 1048576 |
| 19 | const K_MAGIC_262160: i64 = 262160 |
| 20 | const K_MAGIC_2097168: i64 = 2097168 |
| 21 | const K_MAGIC_2097152: i64 = 2097152 |
| 93 | const DX_EMU_PER_PX: i64 = 9525 // 914400 EMU/inch / 96 px/inch (ECMA-376 drawing units) |
functions
| 23 | func dx_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 28 | func dx_num(v: i64) -> i64 { nxi_out(v); return 0 } |
| 29 | func dx_strlen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } |
| 30 | func dx_streq(a: *u8, b: *u8) -> i64 { var i: i64=0; while a[i]!=(0 as u8){ if a[i]!=b[i]{return 0} i=i+1 } if b[i]!=(0 as u8){return 0} return 1 } |
| 31 | func dx_cat(dst: *u8, off: i64, s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8){ dst[off+i]=s[i]; i=i+1 } return off+i } |
| 34 | func dx_match(buf: *u8, pos: i64, n: i64, pat: *u8) -> i64 |
| 40 | func dx_xml_escape(dst: *u8, off: i64, s: *u8) -> i64 called by 7: dx_build_documentdocx_write_document_xmldx_emit_trackdx_cm_adddx_cm_partdx_fn_add+1 calls 1: dx_cat |
| 51 | func dx_build_document(paras: *i64, nparas: i64, out: *u8) -> i64 |
| 66 | func docx_write_document_xml(path: *u8, doc: *u8, doclen: i64) -> i64 |
| 79 | func docx_write(path: *u8, paras: *i64, nparas: i64) -> i64 |
| 96 | func dx_catn(dst: *u8, off: i64, v: i64) -> i64 |
| 109 | func dx_png_dim(png: *u8, n: i64, out_wh: *i64) -> i64 |
| 127 | func dx_emit_drawing(out: *u8, off: i64, rid: *u8, wpx: i64, hpx: i64, pid: i64, name: *u8) -> i64 |
| 153 | func dx_emit_sectpr(out: *u8, off: i64, hdr_rid: *u8, ftr_rid: *u8) -> i64 |
| 165 | func dx_emit_track(out: *u8, off: i64, rev: i64, author: *u8, date: *u8, ins_txt: *u8, del_txt: *u8) -> i64 |
| 192 | func dx_cm_add(out: *u8, off: i64, cid: i64, txt: *u8) -> i64 |
| 207 | func dx_cm_part(out: *u8, off: i64, cid: i64, author: *u8, initials: *u8, date: *u8, body: *u8) -> i64 |
| 225 | func dx_fn_add(out: *u8, off: i64, fid: i64, txt: *u8) -> i64 |
| 236 | func dx_fn_part(out: *u8, off: i64, fid: i64, body: *u8) -> i64 |
| 250 | func dx_esc_span(dst: *u8, off: i64, spec: *u8, s: i64, e: i64) -> i64 |
| 260 | func dx_emit_para(out: *u8, o: i64, rpr: *u8, spec: *u8, s: i64, e: i64) -> i64 |
| 269 | func dx_build_body_rich(spec: *u8, slen: i64, out: *u8) -> i64 |
| 325 | func docx_write_rich(path: *u8, spec: *u8, slen: i64) -> i64 |
| 330 | func dx_readfile(path: *u8, buf: *u8, cap: i64) -> i64 |
| 338 | func docx_read_part(path: *u8, want: *u8, out: *u8, cap: i64) -> i64 |
| 343 | func docx_read_text(path: *u8, out: *u8, cap: i64) -> i64 |
| 383 | func dx_wrapopen(pb: *u8, o: i64, rb: i64, ri: i64) -> i64 |
| 389 | func dx_wrapclose(pb: *u8, o: i64, rb: i64, ri: i64) -> i64 |
| 401 | func dx_to_html(path: *u8, out: *u8, cap: i64, dlurl: *u8) -> i64 |
| 463 | func docx_write_featured(path: *u8, pngdata: *u8, pnglen: i64) -> i64 |
| 507 | func main(argc: i64, argv: *i64) -> i64 |