Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-office/blob/main/src/docx.om # omega-office Omega office documents: read and write office files in Omega Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-office / src / docx.om` 357 lines ยท 6255 bytes Raw Blame History 1 note ======== src/docx.om: the text of a WordprocessingML main document part (ECMA-376 Part 1, 5th edition) ======== 2 note Mode MDOC. Inside document/body (17.2.3, 17.2.2) it prints the character data of every t (17.3.3.31) 3 note in a run r (17.3.2.25), a tab for tab (17.3.3.32) and ptab (17.3.3.23), a line end for br (17.3.3.1, 4 note type textWrapping or absent; page and column breaks print nothing) and cr (17.3.3.4), U+2011 for 5 note noBreakHyphen (17.3.3.18), U+00AD for softHyphen (17.3.3.29), and ends each paragraph p (17.3.1.22) 6 note with a line end. Tables tbl (17.4.37): the cells tc (17.4.65) of a row tr (17.4.78) are separated by 7 note a tab and the row ends with a line end; inside a table, paragraphs of one cell, tabs and breaks are 8 note separated by a space, and a nested table's cells are joined with spaces into the outer cell. 9 note Not printed: deleted runs del (17.13.5.14) and moveFrom (17.13.5.22), so deleted text delText 10 note (17.3.3.7) never prints; field codes instrText (17.16.23) and delInstrText (17.16.13), while field 11 note results print (fldSimple 17.16.19, the runs after fldChar separate 17.16.18); ruby text rt (17.3.3.24); 12 note drawings, VML pictures and embedded objects (drawing 17.3.3.9, pict, object 17.3.3.19) with any text 13 note box inside them; sym (17.3.3.30); properties (pPr, rPr, sectPr, tblPr, trPr, tcPr, tblGrid, 14 note tblPrEx, sdtPr, sdtEndPr). Markup compatibility (ECMA-376 Part 3): AlternateContent is read 15 note through its Fallback; Choice is skipped (no Choice namespace is understood here). 16 note Footnotes, endnotes, comments, headers and footers are other parts: not read. 17 18 global ds ulong 16 19 const DBODY ulong 0 20 const DSKIP ulong 1 21 const DTD ulong 2 22 const DTCN ulong 3 23 const DCPN ulong 4 24 const DRUN ulong 5 25 const DINT ulong 6 26 27 text kbody "body" 28 text kp "p" 29 text kr "r" 30 text kt "t" 31 text ktab "tab" 32 text kptab "ptab" 33 text kbr "br" 34 text kcr "cr" 35 text knbh "noBreakHyphen" 36 text ksfh "softHyphen" 37 text ktbl "tbl" 38 text ktr "tr" 39 text ktc "tc" 40 text kbtype "type" 41 text ktwrap "textWrapping" 42 text kchoice "Choice" 43 text kspPr "pPr" 44 text ksrPr "rPr" 45 text kssect "sectPr" 46 text kstblPr "tblPr" 47 text kstrPr "trPr" 48 text kstcPr "tcPr" 49 text ksgrid "tblGrid" 50 text ksprex "tblPrEx" 51 text ksdel "del" 52 text ksmovf "moveFrom" 53 text ksdraw "drawing" 54 text kspict "pict" 55 text ksobj "object" 56 text ksinst "instrText" 57 text ksdtext "delText" 58 text ksdinst "delInstrText" 59 text ksfdata "fldData" 60 text ksrt "rt" 61 text kssym "sym" 62 text ksdtpr "sdtPr" 63 text ksdtend "sdtEndPr" 64 65 note dskipw: a WordprocessingML element whose whole content is not printed. 66 fn dskipw to bool 67 if or eis NSW kspPr eis NSW ksrPr 68 ret true 69 end 70 if or eis NSW kssect eis NSW kstblPr 71 ret true 72 end 73 if or eis NSW kstrPr eis NSW kstcPr 74 ret true 75 end 76 if or eis NSW ksgrid eis NSW ksprex 77 ret true 78 end 79 if or eis NSW ksdel eis NSW ksmovf 80 ret true 81 end 82 if or eis NSW ksdraw eis NSW kspict 83 ret true 84 end 85 if or eis NSW ksobj eis NSW ksinst 86 ret true 87 end 88 if or eis NSW ksdtext eis NSW ksdinst 89 ret true 90 end 91 if or eis NSW ksfdata eis NSW ksrt 92 ret true 93 end 94 if or eis NSW kssym eis NSW ksdtpr 95 ret true 96 end 97 ret eis NSW ksdtend 98 end 99 100 note dsep: a tab, or a line end, or (inside a table) a space. 101 fn dsep c ulong to void 102 if gt get ds DTD 0 103 oput 32 104 ret 105 end 106 oput c 107 end 108 109 note drunc: the event element is a direct child of the open run. 110 fn drunc to bool 111 r = get ds DRUN 112 if eq r 0 113 ret false 114 end 115 ret eq r sub get xs QDEP 1 116 end 117 118 fn dinrun to void 119 if eis NSW kt 120 put ds DINT 1 121 ret 122 end 123 if or eis NSW ktab eis NSW kptab 124 dsep 9 125 ret 126 end 127 if eis NSW kbr 128 a = afind NSW kbtype 129 if ne a txnone 130 if not aveq a ktwrap false 131 ret 132 end 133 end 134 dsep 10 135 ret 136 end 137 if eis NSW kcr 138 dsep 10 139 ret 140 end 141 if eis NSW knbh 142 oput 0xe2 143 oput 0x80 144 oput 0x91 145 ret 146 end 147 if eis NSW ksfh 148 oput 0xc2 149 oput 0xad 150 end 151 end 152 153 note dname: the event element's local name has n bytes, the first f and (n >= 2) the second g; one 154 note value (n << 16 | f << 8 | g) so the handlers below pick an element with one comparison. 155 fn dname to ulong 156 o = get xs QELO 157 n = sub get xs QNL o 158 f = ulong get xname o 159 g = ulong 0 160 if ge n 2 161 g = ulong get xname add o 1 162 end 163 ret or or shl n 16 shl f 8 g 164 end 165 166 note dlong: the start of a WordprocessingML element whose local name has 4 or more bytes. 167 fn dlong d ulong to void 168 if dskipw 169 put ds DSKIP d 170 ret 171 end 172 if drunc 173 dinrun 174 end 175 end 176 177 fn dstart to void 178 d = get xs QDEP 179 if ne get ds DSKIP 0 180 ret 181 end 182 if eq get ds DBODY 0 183 if and eq d 2 eis NSW kbody 184 put ds DBODY d 185 end 186 ret 187 end 188 e = eid 189 if eq e NSMC 190 if eis NSMC kchoice 191 put ds DSKIP d 192 end 193 ret 194 end 195 if ne e NSW 196 ret 197 end 198 k = dname 199 if eq k 0x17000 200 dpstart 201 ret 202 end 203 if eq k 0x17200 204 put ds DRUN d 205 ret 206 end 207 if eq k 0x17400 208 if drunc 209 put ds DINT 1 210 end 211 ret 212 end 213 if lt k 0x30000 214 dtwo k d 215 ret 216 end 217 if lt k 0x40000 218 dthree k d 219 ret 220 end 221 dlong d 222 end 223 224 fn dpstart to void 225 if gt get ds DTD 0 226 if gt get ds DCPN 0 227 oput 32 228 end 229 put ds DCPN add get ds DCPN 1 230 end 231 end 232 233 note dtwo: tc, tr (the outer table only), br, cr (in a run), rt (skipped). 234 fn dtwo k ulong d ulong to void 235 if eq k 0x27463 236 if eq get ds DTD 1 237 if gt get ds DTCN 0 238 oput 9 239 end 240 put ds DTCN add get ds DTCN 1 241 put ds DCPN 0 242 end 243 ret 244 end 245 if eq k 0x27472 246 if eq get ds DTD 1 247 put ds DTCN 0 248 end 249 ret 250 end 251 if eq k 0x27274 252 put ds DSKIP d 253 ret 254 end 255 if or eq k 0x26272 eq k 0x26372 256 if drunc 257 dinrun 258 end 259 end 260 end 261 262 note dthree: tab (in a run), tbl, and pPr, rPr, del, sym (skipped). 263 fn dthree k ulong d ulong to void 264 if eis NSW ktbl 265 put ds DTD add get ds DTD 1 266 ret 267 end 268 if eis NSW ktab 269 if drunc 270 dsep 9 271 end 272 ret 273 end 274 if dskipw 275 put ds DSKIP d 276 end 277 end 278 279 fn dend to void 280 d = get xs QDEP 281 s = get ds DSKIP 282 if ne s 0 283 if eq s d 284 put ds DSKIP 0 285 end 286 ret 287 end 288 b = get ds DBODY 289 if eq b 0 290 ret 291 end 292 if eq b d 293 put ds DBODY 0 294 ret 295 end 296 if ne eid NSW 297 ret 298 end 299 k = dname 300 if eq k 0x17400 301 put ds DINT 0 302 ret 303 end 304 if eq k 0x17200 305 if eq get ds DRUN d 306 put ds DRUN 0 307 end 308 ret 309 end 310 if eq k 0x17000 311 if eq get ds DTD 0 312 oput 10 313 end 314 ret 315 end 316 if eq k 0x27472 317 if eq get ds DTD 1 318 oput 10 319 end 320 ret 321 end 322 if eis NSW ktbl 323 put ds DTD sub get ds DTD 1 324 end 325 end 326 327 fn dtext to void 328 if eq get ds DINT 0 329 ret 330 end 331 if ne get ds DSKIP 0 332 ret 333 end 334 n = get xs QTL 335 i = ulong 0 336 while lt i n bound 65537 337 m = get on 0 338 k = sub 65536 m 339 if gt k sub n i 340 k = sub n i 341 end 342 for j ulong k bound 65536 343 put obuf add m j get tbuf add i j 344 end 345 put on 0 add m k 346 i = add i k 347 if eq add m k 65536 348 oflush 349 end 350 end 351 end 352 353 fn dreset to void 354 for i ulong 16 355 put ds i 0 356 end 357 end