interplane.Get Omega
Read in your language

omega-office

Omega office documents: read and write office files in Omega

Brought by drakestapleton

branch main Branches Tags History

omega-office / src / docx.om

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