docxkeun 0.1.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +74 -0
- package/README.md +166 -16
- package/dist/api/editor.d.ts +231 -7
- package/dist/api/editor.js +1125 -26
- package/dist/api/headers.d.ts +51 -0
- package/dist/api/headers.js +133 -0
- package/dist/api/index.d.ts +6 -1
- package/dist/api/index.js +4 -1
- package/dist/api/lists.d.ts +37 -0
- package/dist/api/lists.js +132 -0
- package/dist/api/parts.js +1 -0
- package/dist/api/positions.js +1 -0
- package/dist/api/revisions.d.ts +61 -0
- package/dist/api/revisions.js +401 -0
- package/dist/api/selection.d.ts +57 -0
- package/dist/api/selection.js +91 -0
- package/dist/api/tables.d.ts +60 -0
- package/dist/api/tables.js +138 -0
- package/dist/charts/color.d.ts +45 -0
- package/dist/charts/color.js +322 -0
- package/dist/charts/format.d.ts +12 -0
- package/dist/charts/format.js +459 -0
- package/dist/charts/index.d.ts +11 -0
- package/dist/charts/index.js +8 -0
- package/dist/charts/model.d.ts +225 -0
- package/dist/charts/model.js +758 -0
- package/dist/charts/outline.d.ts +17 -0
- package/dist/charts/outline.js +214 -0
- package/dist/charts/render.d.ts +20 -0
- package/dist/charts/render.js +1772 -0
- package/dist/drawing/arrows.d.ts +37 -0
- package/dist/drawing/arrows.js +99 -0
- package/dist/drawing/formula.d.ts +40 -0
- package/dist/drawing/formula.js +159 -0
- package/dist/drawing/geometry.d.ts +61 -0
- package/dist/drawing/geometry.js +286 -0
- package/dist/drawing/index.d.ts +12 -0
- package/dist/drawing/index.js +8 -0
- package/dist/drawing/presets.d.ts +72 -0
- package/dist/drawing/presets.js +2874 -0
- package/dist/fonts/shaping/apply.d.ts +94 -0
- package/dist/fonts/shaping/apply.js +349 -0
- package/dist/fonts/shaping/arabic.d.ts +28 -0
- package/dist/fonts/shaping/arabic.js +235 -0
- package/dist/fonts/shaping/buffer.d.ts +53 -0
- package/dist/fonts/shaping/buffer.js +95 -0
- package/dist/fonts/shaping/gdef.d.ts +30 -0
- package/dist/fonts/shaping/gdef.js +66 -0
- package/dist/fonts/shaping/gpos.d.ts +86 -0
- package/dist/fonts/shaping/gpos.js +428 -0
- package/dist/fonts/shaping/gsub.d.ts +65 -0
- package/dist/fonts/shaping/gsub.js +313 -0
- package/dist/fonts/shaping/index.d.ts +32 -0
- package/dist/fonts/shaping/index.js +402 -0
- package/dist/fonts/shaping/indic.d.ts +6 -0
- package/dist/fonts/shaping/indic.js +805 -0
- package/dist/fonts/shaping/layout-common.d.ts +124 -0
- package/dist/fonts/shaping/layout-common.js +349 -0
- package/dist/fonts/shaping/plan.d.ts +87 -0
- package/dist/fonts/shaping/plan.js +152 -0
- package/dist/fonts/shaping/scripts.d.ts +26 -0
- package/dist/fonts/shaping/scripts.js +160 -0
- package/dist/fonts/shaping/shaper.d.ts +23 -0
- package/dist/fonts/shaping/shaper.js +5 -0
- package/dist/fonts/shaping/unicode.d.ts +34 -0
- package/dist/fonts/shaping/unicode.js +138 -0
- package/dist/images/bmp.d.ts +9 -0
- package/dist/images/bmp.js +234 -0
- package/dist/images/gif.d.ts +9 -0
- package/dist/images/gif.js +215 -0
- package/dist/images/index.d.ts +18 -0
- package/dist/images/index.js +63 -0
- package/dist/images/png-encode.d.ts +4 -0
- package/dist/images/png-encode.js +73 -0
- package/dist/images/size.d.ts +10 -0
- package/dist/images/size.js +83 -0
- package/dist/images/tiff.d.ts +14 -0
- package/dist/images/tiff.js +407 -0
- package/dist/index.d.ts +7 -2
- package/dist/index.js +5 -0
- package/dist/layout/bidi.d.ts +18 -0
- package/dist/layout/bidi.js +71 -0
- package/dist/layout/blocks.d.ts +20 -3
- package/dist/layout/blocks.js +88 -58
- package/dist/layout/cache.d.ts +31 -0
- package/dist/layout/cache.js +38 -0
- package/dist/layout/drawing.d.ts +30 -0
- package/dist/layout/drawing.js +120 -0
- package/dist/layout/engine.d.ts +3 -0
- package/dist/layout/engine.js +218 -11
- package/dist/layout/index.d.ts +1 -0
- package/dist/layout/index.js +1 -0
- package/dist/layout/lines.d.ts +63 -5
- package/dist/layout/lines.js +245 -20
- package/dist/layout/paint.d.ts +25 -3
- package/dist/layout/paint.js +26 -10
- package/dist/layout/shapes.d.ts +7 -0
- package/dist/layout/shapes.js +338 -0
- package/dist/layout/style.d.ts +4 -0
- package/dist/layout/style.js +2 -0
- package/dist/layout/types.d.ts +89 -2
- package/dist/math/boxes.d.ts +88 -0
- package/dist/math/boxes.js +166 -0
- package/dist/math/index.d.ts +29 -0
- package/dist/math/index.js +44 -0
- package/dist/math/layout.d.ts +13 -0
- package/dist/math/layout.js +771 -0
- package/dist/math/linear.d.ts +3 -0
- package/dist/math/linear.js +152 -0
- package/dist/math/omml.d.ts +15 -0
- package/dist/math/omml.js +57 -0
- package/dist/math/paths.d.ts +61 -0
- package/dist/math/paths.js +450 -0
- package/dist/math/symbols.d.ts +49 -0
- package/dist/math/symbols.js +269 -0
- package/dist/math/text.d.ts +53 -0
- package/dist/math/text.js +316 -0
- package/dist/metafile/canvas.d.ts +80 -0
- package/dist/metafile/canvas.js +515 -0
- package/dist/metafile/dib.d.ts +27 -0
- package/dist/metafile/dib.js +300 -0
- package/dist/metafile/emf.d.ts +31 -0
- package/dist/metafile/emf.js +591 -0
- package/dist/metafile/geometry.d.ts +49 -0
- package/dist/metafile/geometry.js +85 -0
- package/dist/metafile/index.d.ts +27 -0
- package/dist/metafile/index.js +34 -0
- package/dist/metafile/reader.d.ts +28 -0
- package/dist/metafile/reader.js +59 -0
- package/dist/metafile/state.d.ts +118 -0
- package/dist/metafile/state.js +172 -0
- package/dist/metafile/text.d.ts +17 -0
- package/dist/metafile/text.js +130 -0
- package/dist/metafile/wmf.d.ts +33 -0
- package/dist/metafile/wmf.js +395 -0
- package/dist/model/content.d.ts +92 -7
- package/dist/model/content.js +251 -17
- package/dist/model/document.d.ts +34 -1
- package/dist/model/document.js +80 -1
- package/dist/model/fields.d.ts +4 -0
- package/dist/model/fields.js +10 -0
- package/dist/model/numbering.d.ts +2 -0
- package/dist/model/numbering.js +22 -0
- package/dist/model/props.d.ts +2 -0
- package/dist/model/props.js +3 -0
- package/dist/opc/index.d.ts +1 -1
- package/dist/opc/package.d.ts +34 -0
- package/dist/opc/package.js +58 -4
- package/dist/pdf/export.js +97 -6
- package/dist/pdf/images.d.ts +7 -0
- package/dist/pdf/images.js +39 -2
- package/dist/render/activity.d.ts +179 -0
- package/dist/render/activity.js +1003 -0
- package/dist/render/clipboard.d.ts +29 -0
- package/dist/render/clipboard.js +401 -0
- package/dist/render/comments.d.ts +166 -0
- package/dist/render/comments.js +779 -0
- package/dist/render/context-menu.d.ts +124 -0
- package/dist/render/context-menu.js +525 -0
- package/dist/render/editing.d.ts +146 -5
- package/dist/render/editing.js +678 -53
- package/dist/render/index.d.ts +12 -0
- package/dist/render/index.js +11 -0
- package/dist/render/navigation-panel.d.ts +76 -0
- package/dist/render/navigation-panel.js +431 -0
- package/dist/render/selection.js +5 -0
- package/dist/render/svg.d.ts +4 -6
- package/dist/render/svg.js +69 -7
- package/dist/render/toolbar.d.ts +83 -0
- package/dist/render/toolbar.js +505 -0
- package/dist/render/ui/comment-layout.d.ts +39 -0
- package/dist/render/ui/comment-layout.js +79 -0
- package/dist/render/ui/icons.d.ts +6 -0
- package/dist/render/ui/icons.js +38 -0
- package/dist/render/ui/menu.d.ts +38 -0
- package/dist/render/ui/menu.js +274 -0
- package/dist/render/ui/nav-model.d.ts +11 -0
- package/dist/render/ui/nav-model.js +34 -0
- package/dist/render/ui/overflow.d.ts +5 -0
- package/dist/render/ui/overflow.js +18 -0
- package/dist/render/ui/popover.d.ts +18 -0
- package/dist/render/ui/popover.js +109 -0
- package/dist/render/ui/theme.d.ts +2 -0
- package/dist/render/ui/theme.js +29 -0
- package/dist/render/undo.d.ts +76 -0
- package/dist/render/undo.js +144 -0
- package/dist/render/viewer.d.ts +100 -7
- package/dist/render/viewer.js +304 -92
- package/dist/security/policy.d.ts +3 -0
- package/dist/security/policy.js +6 -2
- package/dist/security/protection.d.ts +1 -0
- package/dist/security/protection.js +1 -1
- package/dist/text/bidi-data.d.ts +53 -0
- package/dist/text/bidi-data.js +318 -0
- package/dist/text/bidi.d.ts +37 -0
- package/dist/text/bidi.js +508 -0
- package/dist/xml/ns.d.ts +5 -0
- package/dist/xml/ns.js +7 -0
- package/package.json +9 -2
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Windows metafile player ([MS-WMF]), for the 16-bit pictures old Word documents embed
|
|
3
|
+
* (Equation Editor 3.0 equations, clip art, early charts). Playback follows how applications
|
|
4
|
+
* show a WMF: the viewport is the target frame and the picture's own window origin/extent map
|
|
5
|
+
* onto it (the Aldus placeable header's bounding box is the window until a record sets one).
|
|
6
|
+
* Viewport records and map modes are therefore not applied: they would size the picture in
|
|
7
|
+
* device pixels instead of fitting it to the frame.
|
|
8
|
+
*/
|
|
9
|
+
import type { DisplayItem, FontProvider } from '../layout/types.js';
|
|
10
|
+
interface WmfHeader {
|
|
11
|
+
placeable?: {
|
|
12
|
+
left: number;
|
|
13
|
+
top: number;
|
|
14
|
+
right: number;
|
|
15
|
+
bottom: number;
|
|
16
|
+
inch: number;
|
|
17
|
+
};
|
|
18
|
+
/** Offset of the first record. */
|
|
19
|
+
records: number;
|
|
20
|
+
}
|
|
21
|
+
export declare function readWmfHeader(bytes: Uint8Array): WmfHeader | undefined;
|
|
22
|
+
/** Natural size in points: the placeable bounding box at its units per inch, else the window extent in twips. */
|
|
23
|
+
export declare function wmfSize(bytes: Uint8Array): {
|
|
24
|
+
width: number;
|
|
25
|
+
height: number;
|
|
26
|
+
} | undefined;
|
|
27
|
+
export declare function renderWmf(bytes: Uint8Array, frame: {
|
|
28
|
+
x: number;
|
|
29
|
+
y: number;
|
|
30
|
+
w: number;
|
|
31
|
+
h: number;
|
|
32
|
+
}, fonts: FontProvider): DisplayItem[];
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
import { Canvas } from './canvas.js';
|
|
2
|
+
import { averageColor, cropRaster, decodeDib, dibIsBottomUp } from './dib.js';
|
|
3
|
+
import { RecordReader } from './reader.js';
|
|
4
|
+
import { BLACKNESS, ETO_CLIPPED, ETO_OPAQUE, PATCOPY, SRCCOPY, WHITENESS, colorRef, makeBrush, makePen, selectInto } from './state.js';
|
|
5
|
+
import { decodeAnsi } from './text.js';
|
|
6
|
+
const PLACEABLE_KEY = 0x9ac6cdd7;
|
|
7
|
+
const META_SETWINDOWEXT = 0x020c;
|
|
8
|
+
export function readWmfHeader(bytes) {
|
|
9
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
10
|
+
let off = 0;
|
|
11
|
+
let placeable;
|
|
12
|
+
if (bytes.length >= 22 && view.getUint32(0, true) === PLACEABLE_KEY) {
|
|
13
|
+
placeable = { left: view.getInt16(6, true), top: view.getInt16(8, true), right: view.getInt16(10, true), bottom: view.getInt16(12, true), inch: view.getUint16(14, true) };
|
|
14
|
+
off = 22;
|
|
15
|
+
}
|
|
16
|
+
if (off + 18 > bytes.length)
|
|
17
|
+
return undefined;
|
|
18
|
+
const type = view.getUint16(off, true);
|
|
19
|
+
const headerWords = view.getUint16(off + 2, true);
|
|
20
|
+
const version = view.getUint16(off + 4, true);
|
|
21
|
+
// Without the placeable key the standard header is all there is to recognise the format by.
|
|
22
|
+
if (!placeable && (!(type === 1 || type === 2) || headerWords !== 9 || !(version === 0x100 || version === 0x300)))
|
|
23
|
+
return undefined;
|
|
24
|
+
return { placeable, records: off + Math.max(9, headerWords) * 2 };
|
|
25
|
+
}
|
|
26
|
+
/** Visit records (function number, parameter reader) until META_EOF or the data runs out. */
|
|
27
|
+
function eachRecord(bytes, start, visit) {
|
|
28
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
29
|
+
for (let off = start; off + 6 <= bytes.length;) {
|
|
30
|
+
const words = view.getUint32(off, true);
|
|
31
|
+
const fn = view.getUint16(off + 4, true);
|
|
32
|
+
if (fn === 0 || words < 3)
|
|
33
|
+
break;
|
|
34
|
+
const end = Math.min(bytes.length, off + words * 2);
|
|
35
|
+
if (visit(fn, new RecordReader(bytes, off + 6, end, view)) === false)
|
|
36
|
+
break;
|
|
37
|
+
off += words * 2;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function firstWindowExt(bytes, start) {
|
|
41
|
+
let ext;
|
|
42
|
+
eachRecord(bytes, start, (fn, r) => {
|
|
43
|
+
if (fn !== META_SETWINDOWEXT)
|
|
44
|
+
return;
|
|
45
|
+
ext = { x: r.i16(2), y: r.i16(0) };
|
|
46
|
+
return false;
|
|
47
|
+
});
|
|
48
|
+
return ext;
|
|
49
|
+
}
|
|
50
|
+
/** Natural size in points: the placeable bounding box at its units per inch, else the window extent in twips. */
|
|
51
|
+
export function wmfSize(bytes) {
|
|
52
|
+
const h = readWmfHeader(bytes);
|
|
53
|
+
if (!h)
|
|
54
|
+
return undefined;
|
|
55
|
+
if (h.placeable) {
|
|
56
|
+
const inch = h.placeable.inch || 1440;
|
|
57
|
+
const width = (Math.abs(h.placeable.right - h.placeable.left) / inch) * 72;
|
|
58
|
+
const height = (Math.abs(h.placeable.bottom - h.placeable.top) / inch) * 72;
|
|
59
|
+
if (width > 0 && height > 0)
|
|
60
|
+
return { width, height };
|
|
61
|
+
}
|
|
62
|
+
const ext = firstWindowExt(bytes, h.records);
|
|
63
|
+
if (ext && ext.x && ext.y)
|
|
64
|
+
return { width: (Math.abs(ext.x) / 1440) * 72, height: (Math.abs(ext.y) / 1440) * 72 };
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
export function renderWmf(bytes, frame, fonts) {
|
|
68
|
+
const header = readWmfHeader(bytes);
|
|
69
|
+
if (!header || !(frame.w > 0) || !(frame.h > 0))
|
|
70
|
+
return [];
|
|
71
|
+
let window;
|
|
72
|
+
const p = header.placeable;
|
|
73
|
+
if (p && p.right !== p.left && p.bottom !== p.top)
|
|
74
|
+
window = { org: { x: p.left, y: p.top }, ext: { x: p.right - p.left, y: p.bottom - p.top } };
|
|
75
|
+
if (!window && !firstWindowExt(bytes, header.records)) {
|
|
76
|
+
// Nothing says where the picture is: draw it once in logical units to find out.
|
|
77
|
+
const probe = play(bytes, header, { x: 0, y: 0, w: 1, h: 1 }, fonts, { org: { x: 0, y: 0 }, ext: { x: 1, y: 1 } }, 1);
|
|
78
|
+
const box = itemBounds(probe);
|
|
79
|
+
if (!box)
|
|
80
|
+
return [];
|
|
81
|
+
window = { org: { x: box.x, y: box.y }, ext: { x: box.w || 1, y: box.h || 1 } };
|
|
82
|
+
}
|
|
83
|
+
const natural = wmfSize(bytes);
|
|
84
|
+
return play(bytes, header, frame, fonts, window, natural ? frame.h / natural.height : 1);
|
|
85
|
+
}
|
|
86
|
+
function play(bytes, header, frame, fonts, window, scale) {
|
|
87
|
+
const pageToPoints = (s) => {
|
|
88
|
+
const sx = frame.w / (s.windowExt.x || 1);
|
|
89
|
+
const sy = frame.h / (s.windowExt.y || 1);
|
|
90
|
+
return { a: sx, b: 0, c: 0, d: sy, e: frame.x - s.windowOrg.x * sx, f: frame.y - s.windowOrg.y * sy };
|
|
91
|
+
};
|
|
92
|
+
// One pixel of a 96 dpi screen and its 12pt default font, at the scale the picture is drawn.
|
|
93
|
+
const canvas = new Canvas({ fonts, pageToPoints, pixel: 0.75 * scale, defaultFontSize: 12 * scale });
|
|
94
|
+
if (window) {
|
|
95
|
+
canvas.state.windowOrg = window.org;
|
|
96
|
+
canvas.state.windowExt = window.ext;
|
|
97
|
+
}
|
|
98
|
+
const player = new WmfPlayer(canvas);
|
|
99
|
+
eachRecord(bytes, header.records, (fn, r) => {
|
|
100
|
+
try {
|
|
101
|
+
player.play(fn, r);
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
// A record we cannot make sense of is skipped; the rest of the picture still draws.
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
return canvas.items;
|
|
108
|
+
}
|
|
109
|
+
class WmfPlayer {
|
|
110
|
+
canvas;
|
|
111
|
+
/** The WMF object table: a new object takes the lowest free slot, DeleteObject frees its slot. */
|
|
112
|
+
objects = [];
|
|
113
|
+
constructor(canvas) {
|
|
114
|
+
this.canvas = canvas;
|
|
115
|
+
}
|
|
116
|
+
add(obj) {
|
|
117
|
+
let i = 0;
|
|
118
|
+
while (this.objects[i] !== undefined)
|
|
119
|
+
i++;
|
|
120
|
+
this.objects[i] = obj;
|
|
121
|
+
}
|
|
122
|
+
play(fn, r) {
|
|
123
|
+
const c = this.canvas;
|
|
124
|
+
const s = c.state;
|
|
125
|
+
switch (fn) {
|
|
126
|
+
case 0x0102: // META_SETBKMODE
|
|
127
|
+
s.bkMode = r.u16(0);
|
|
128
|
+
break;
|
|
129
|
+
case 0x0106: // META_SETPOLYFILLMODE
|
|
130
|
+
s.polyFillMode = r.u16(0);
|
|
131
|
+
break;
|
|
132
|
+
case 0x012e: // META_SETTEXTALIGN
|
|
133
|
+
s.textAlign = r.u16(0);
|
|
134
|
+
break;
|
|
135
|
+
case 0x0108: // META_SETTEXTCHAREXTRA
|
|
136
|
+
s.charExtra = r.i16(0);
|
|
137
|
+
break;
|
|
138
|
+
case 0x0201: // META_SETBKCOLOR
|
|
139
|
+
s.bkColor = color(r, 0);
|
|
140
|
+
break;
|
|
141
|
+
case 0x0209: // META_SETTEXTCOLOR
|
|
142
|
+
s.textColor = color(r, 0);
|
|
143
|
+
break;
|
|
144
|
+
case 0x020b: // META_SETWINDOWORG (y, x)
|
|
145
|
+
s.windowOrg = { x: r.i16(2), y: r.i16(0) };
|
|
146
|
+
break;
|
|
147
|
+
case META_SETWINDOWEXT:
|
|
148
|
+
s.windowExt = { x: r.i16(2), y: r.i16(0) };
|
|
149
|
+
break;
|
|
150
|
+
case 0x020f: // META_OFFSETWINDOWORG
|
|
151
|
+
s.windowOrg = { x: s.windowOrg.x + r.i16(2), y: s.windowOrg.y + r.i16(0) };
|
|
152
|
+
break;
|
|
153
|
+
case 0x0410: {
|
|
154
|
+
// META_SCALEWINDOWEXT: yDenom, yNum, xDenom, xNum
|
|
155
|
+
const [yDen, yNum, xDen, xNum] = [r.i16(0), r.i16(2), r.i16(4), r.i16(6)];
|
|
156
|
+
if (xDen && yDen)
|
|
157
|
+
s.windowExt = { x: (s.windowExt.x * xNum) / xDen, y: (s.windowExt.y * yNum) / yDen };
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
case 0x001e: // META_SAVEDC
|
|
161
|
+
c.save();
|
|
162
|
+
break;
|
|
163
|
+
case 0x0127: // META_RESTOREDC
|
|
164
|
+
c.restore(r.i16(0));
|
|
165
|
+
break;
|
|
166
|
+
case 0x02fa: // META_CREATEPENINDIRECT: style, width (POINTS), colour
|
|
167
|
+
this.add(makePen(r.u16(0), r.i16(2), color(r, 6)));
|
|
168
|
+
break;
|
|
169
|
+
case 0x02fc: // META_CREATEBRUSHINDIRECT: style, colour, hatch
|
|
170
|
+
this.add(makeBrush(r.u16(0), color(r, 2)));
|
|
171
|
+
break;
|
|
172
|
+
case 0x0142: {
|
|
173
|
+
// META_DIBCREATEPATTERNBRUSH: drawn as a flat fill of the pattern's average colour.
|
|
174
|
+
const img = decodeDib(r.slice(4, r.size - 4), undefined, { paletteIndices: r.u16(2) === 1 });
|
|
175
|
+
this.add({ kind: 'brush', style: 'pattern', color: img ? averageColor(img) : '808080' });
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
case 0x01f9: // META_CREATEPATTERNBRUSH (device-dependent bitmap)
|
|
179
|
+
this.add(makeBrush(3, '808080'));
|
|
180
|
+
break;
|
|
181
|
+
case 0x02fb: // META_CREATEFONTINDIRECT
|
|
182
|
+
this.add(logFont(r));
|
|
183
|
+
break;
|
|
184
|
+
case 0x00f7: // META_CREATEPALETTE
|
|
185
|
+
case 0x06ff: // META_CREATEREGION
|
|
186
|
+
this.add({ kind: 'other' });
|
|
187
|
+
break;
|
|
188
|
+
case 0x012d: // META_SELECTOBJECT
|
|
189
|
+
selectInto(s, this.objects[r.u16(0)]);
|
|
190
|
+
break;
|
|
191
|
+
case 0x01f0: // META_DELETEOBJECT
|
|
192
|
+
this.objects[r.u16(0)] = undefined;
|
|
193
|
+
break;
|
|
194
|
+
case 0x0214: // META_MOVETO (y, x)
|
|
195
|
+
c.moveTo(r.i16(2), r.i16(0));
|
|
196
|
+
break;
|
|
197
|
+
case 0x0213: // META_LINETO (y, x)
|
|
198
|
+
c.lineTo(r.i16(2), r.i16(0));
|
|
199
|
+
break;
|
|
200
|
+
case 0x0325: // META_POLYLINE
|
|
201
|
+
case 0x0324: // META_POLYGON
|
|
202
|
+
c.poly(readPoints(r, 2, r.fit(2, r.i16(0), 4)), fn === 0x0324);
|
|
203
|
+
break;
|
|
204
|
+
case 0x0538: {
|
|
205
|
+
// META_POLYPOLYGON: count, points per polygon, then all points.
|
|
206
|
+
const polys = r.fit(2, r.u16(0), 2);
|
|
207
|
+
let at = 2 + polys * 2;
|
|
208
|
+
const out = [];
|
|
209
|
+
for (let i = 0; i < polys; i++) {
|
|
210
|
+
const n = r.fit(at, r.u16(2 + i * 2), 4);
|
|
211
|
+
out.push(readPoints(r, at, n));
|
|
212
|
+
at += n * 4;
|
|
213
|
+
}
|
|
214
|
+
c.polyPoly(out, true);
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
case 0x041b: // META_RECTANGLE (bottom, right, top, left)
|
|
218
|
+
c.rectangle(r.i16(6), r.i16(4), r.i16(2), r.i16(0));
|
|
219
|
+
break;
|
|
220
|
+
case 0x0418: // META_ELLIPSE
|
|
221
|
+
c.ellipse(r.i16(6), r.i16(4), r.i16(2), r.i16(0));
|
|
222
|
+
break;
|
|
223
|
+
case 0x061c: // META_ROUNDRECT (height, width, bottom, right, top, left)
|
|
224
|
+
c.roundRect(r.i16(10), r.i16(8), r.i16(6), r.i16(4), r.i16(2), r.i16(0));
|
|
225
|
+
break;
|
|
226
|
+
case 0x0817: // META_ARC
|
|
227
|
+
case 0x081a: // META_PIE
|
|
228
|
+
case 0x0830: {
|
|
229
|
+
// META_CHORD: yEnd, xEnd, yStart, xStart, bottom, right, top, left
|
|
230
|
+
const kind = fn === 0x0817 ? 'arc' : fn === 0x081a ? 'pie' : 'chord';
|
|
231
|
+
c.arc(kind, r.i16(14), r.i16(12), r.i16(10), r.i16(8), r.i16(6), r.i16(4), r.i16(2), r.i16(0));
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
case 0x0521: {
|
|
235
|
+
// META_TEXTOUT: length, string (padded to a word), y, x
|
|
236
|
+
const len = Math.max(0, r.i16(0));
|
|
237
|
+
const padded = len + (len & 1);
|
|
238
|
+
this.text(r.i16(4 + padded), r.i16(2 + padded), r.slice(2, len), undefined);
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
case 0x0a32:
|
|
242
|
+
this.extTextOut(r);
|
|
243
|
+
break;
|
|
244
|
+
case 0x0f43: {
|
|
245
|
+
// META_STRETCHDIB: rop, usage, srcH, srcW, ySrc, xSrc, destH, destW, yDst, xDst, DIB
|
|
246
|
+
const info = r.slice(22, r.size - 22);
|
|
247
|
+
this.dib(info, r.u32(0), r.u16(4) === 1, [r.i16(12), r.i16(10), r.i16(8), r.i16(6)], [r.i16(20), r.i16(18), r.i16(16), r.i16(14)], true);
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
case 0x0b41: {
|
|
251
|
+
// META_DIBSTRETCHBLT; the bitmap-less form is a pattern blit with a reserved word.
|
|
252
|
+
if (r.size <= 22) {
|
|
253
|
+
this.patBlt(r.u32(0), r.i16(20), r.i16(18), r.i16(16), r.i16(14));
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
const info = r.slice(20, r.size - 20);
|
|
257
|
+
this.dib(info, r.u32(0), false, [r.i16(10), r.i16(8), r.i16(6), r.i16(4)], [r.i16(18), r.i16(16), r.i16(14), r.i16(12)], false);
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
case 0x0940: {
|
|
261
|
+
// META_DIBBITBLT: rop, ySrc, xSrc, height, width, yDest, xDest, DIB
|
|
262
|
+
if (r.size <= 18) {
|
|
263
|
+
this.patBlt(r.u32(0), r.i16(16), r.i16(14), r.i16(12), r.i16(10));
|
|
264
|
+
break;
|
|
265
|
+
}
|
|
266
|
+
const [w, h] = [r.i16(10), r.i16(8)];
|
|
267
|
+
this.dib(r.slice(16, r.size - 16), r.u32(0), false, [r.i16(6), r.i16(4), w, h], [r.i16(14), r.i16(12), w, h], false);
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
case 0x061d: // META_PATBLT: rop, height, width, y, x
|
|
271
|
+
this.patBlt(r.u32(0), r.i16(10), r.i16(8), r.i16(6), r.i16(4));
|
|
272
|
+
break;
|
|
273
|
+
// Viewport and map mode records (see the file comment), clipping, palettes, regions,
|
|
274
|
+
// escapes and ROP2 do not change what we draw.
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
text(x, y, bytes, dx, opaque) {
|
|
278
|
+
const font = this.canvas.state.font;
|
|
279
|
+
const decoded = decodeAnsi(bytes, font.charset, font.faceName, dx);
|
|
280
|
+
this.canvas.text(x, y, decoded.chars, decoded.dx, opaque);
|
|
281
|
+
}
|
|
282
|
+
extTextOut(r) {
|
|
283
|
+
// META_EXTTEXTOUT: y, x, length, options, [rectangle], string (padded), [dx per byte]
|
|
284
|
+
const y = r.i16(0);
|
|
285
|
+
const x = r.i16(2);
|
|
286
|
+
const len = Math.max(0, r.i16(4));
|
|
287
|
+
const options = r.u16(6);
|
|
288
|
+
let at = 8;
|
|
289
|
+
let opaque;
|
|
290
|
+
if (options & (ETO_OPAQUE | ETO_CLIPPED)) {
|
|
291
|
+
if (options & ETO_OPAQUE)
|
|
292
|
+
opaque = [r.i16(8), r.i16(10), r.i16(12), r.i16(14)];
|
|
293
|
+
at = 16;
|
|
294
|
+
}
|
|
295
|
+
const str = r.slice(at, len);
|
|
296
|
+
at += len + (len & 1);
|
|
297
|
+
let dx;
|
|
298
|
+
if (len && r.fit(at, len, 2) === len) {
|
|
299
|
+
dx = [];
|
|
300
|
+
for (let i = 0; i < len; i++)
|
|
301
|
+
dx.push(r.i16(at + i * 2));
|
|
302
|
+
}
|
|
303
|
+
this.text(x, y, str, dx, opaque);
|
|
304
|
+
}
|
|
305
|
+
/** Draw a packed DIB: src and dest are [x, y, w, h]; `fromBottom` for StretchDIB's bottom-up source origin. */
|
|
306
|
+
dib(info, rop, paletteIndices, src, dest, fromBottom) {
|
|
307
|
+
if (rop !== SRCCOPY)
|
|
308
|
+
return;
|
|
309
|
+
const img = decodeDib(info, undefined, { paletteIndices });
|
|
310
|
+
if (!img)
|
|
311
|
+
return;
|
|
312
|
+
const [sx, sy, sw, sh] = src;
|
|
313
|
+
const top = fromBottom && dibIsBottomUp(info) ? img.height - sy - sh : sy;
|
|
314
|
+
const [dx, dy, dw, dh] = dest;
|
|
315
|
+
this.canvas.image(cropRaster(img, sx, top, sw, sh), dx, dy, dw, dh);
|
|
316
|
+
}
|
|
317
|
+
patBlt(op, x, y, w, h) {
|
|
318
|
+
const fill = op === PATCOPY ? undefined : op === BLACKNESS ? '000000' : op === WHITENESS ? 'FFFFFF' : null;
|
|
319
|
+
if (fill !== null)
|
|
320
|
+
this.canvas.fillRect(x, y, x + w, y + h, fill);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
function color(r, at) {
|
|
324
|
+
return colorRef(r.u8(at), r.u8(at + 1), r.u8(at + 2));
|
|
325
|
+
}
|
|
326
|
+
function readPoints(r, at, n) {
|
|
327
|
+
const out = [];
|
|
328
|
+
for (let i = 0; i < n; i++)
|
|
329
|
+
out.push({ x: r.i16(at + i * 4), y: r.i16(at + i * 4 + 2) });
|
|
330
|
+
return out;
|
|
331
|
+
}
|
|
332
|
+
/** The 16-bit LOGFONT of META_CREATEFONTINDIRECT (face name in ANSI). */
|
|
333
|
+
function logFont(r) {
|
|
334
|
+
let faceName = '';
|
|
335
|
+
for (let i = 0; i < 32; i++) {
|
|
336
|
+
const b = r.u8(18 + i);
|
|
337
|
+
if (!b)
|
|
338
|
+
break;
|
|
339
|
+
faceName += String.fromCharCode(b);
|
|
340
|
+
}
|
|
341
|
+
return {
|
|
342
|
+
kind: 'font',
|
|
343
|
+
height: r.i16(0),
|
|
344
|
+
weight: r.i16(8),
|
|
345
|
+
italic: r.u8(10) !== 0,
|
|
346
|
+
underline: r.u8(11) !== 0,
|
|
347
|
+
strikeOut: r.u8(12) !== 0,
|
|
348
|
+
charset: r.u8(13),
|
|
349
|
+
faceName,
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
/** Bounding box of display items in page points (for pictures that do not say how big they are). */
|
|
353
|
+
function itemBounds(items) {
|
|
354
|
+
let x0 = Infinity;
|
|
355
|
+
let y0 = Infinity;
|
|
356
|
+
let x1 = -Infinity;
|
|
357
|
+
let y1 = -Infinity;
|
|
358
|
+
const add = (x, y) => {
|
|
359
|
+
if (!Number.isFinite(x) || !Number.isFinite(y))
|
|
360
|
+
return;
|
|
361
|
+
x0 = Math.min(x0, x);
|
|
362
|
+
y0 = Math.min(y0, y);
|
|
363
|
+
x1 = Math.max(x1, x);
|
|
364
|
+
y1 = Math.max(y1, y);
|
|
365
|
+
};
|
|
366
|
+
for (const it of items) {
|
|
367
|
+
switch (it.type) {
|
|
368
|
+
case 'path':
|
|
369
|
+
for (const cmd of it.commands) {
|
|
370
|
+
if (cmd.op === 'Z')
|
|
371
|
+
continue;
|
|
372
|
+
if (cmd.op === 'C') {
|
|
373
|
+
add(cmd.x1, cmd.y1);
|
|
374
|
+
add(cmd.x2, cmd.y2);
|
|
375
|
+
}
|
|
376
|
+
add(cmd.x, cmd.y);
|
|
377
|
+
}
|
|
378
|
+
break;
|
|
379
|
+
case 'text': {
|
|
380
|
+
const width = it.widths.reduce((a, b) => a + b, 0);
|
|
381
|
+
add(it.x, it.y - it.font.ascent * it.size);
|
|
382
|
+
add(it.x + width, it.y + it.font.descent * it.size);
|
|
383
|
+
break;
|
|
384
|
+
}
|
|
385
|
+
case 'line':
|
|
386
|
+
add(it.x1, it.y1);
|
|
387
|
+
add(it.x2, it.y2);
|
|
388
|
+
break;
|
|
389
|
+
default:
|
|
390
|
+
add(it.x, it.y);
|
|
391
|
+
add(it.x + it.w, it.y + it.h);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
return x0 <= x1 && y0 <= y1 ? { x: x0, y: y0, w: x1 - x0, h: y1 - y0 } : undefined;
|
|
395
|
+
}
|
package/dist/model/content.d.ts
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Reads WordprocessingML stories (body, headers, footers, notes, comments) into a flat structure
|
|
3
|
-
* for layout: blocks (paragraphs, tables) whose inlines are runs plus range markers. Wrappers
|
|
4
|
-
* such as hyperlinks, fields, content controls and tracked insertions are flattened into markers;
|
|
5
|
-
* every inline keeps a reference to the XML it came from so edits can go back to the source.
|
|
6
|
-
*/
|
|
7
1
|
import { type XmlElement } from '../xml/index.js';
|
|
8
2
|
import { type DynamicFieldType, type LinkTarget } from './fields.js';
|
|
9
3
|
import type { LevelDef, NumberingDefs } from './numbering.js';
|
|
@@ -48,6 +42,65 @@ export interface FloatInfo {
|
|
|
48
42
|
right: number;
|
|
49
43
|
};
|
|
50
44
|
}
|
|
45
|
+
/** A DrawingML shape: geometry, fill and outline (kept as XML: colours resolve against the theme), text. */
|
|
46
|
+
export interface ShapeInfo {
|
|
47
|
+
/** a:prstGeom or a:custGeom. */
|
|
48
|
+
geometry: XmlElement | undefined;
|
|
49
|
+
/** The shape properties (fill, outline, transform). */
|
|
50
|
+
spPr: XmlElement | undefined;
|
|
51
|
+
/** wps:style: theme references used when spPr leaves fill or outline out. */
|
|
52
|
+
style: XmlElement | undefined;
|
|
53
|
+
/** Text box content (Word paragraphs), when the shape has a text box. */
|
|
54
|
+
text?: {
|
|
55
|
+
blocks: Block[];
|
|
56
|
+
insets: {
|
|
57
|
+
left: number;
|
|
58
|
+
top: number;
|
|
59
|
+
right: number;
|
|
60
|
+
bottom: number;
|
|
61
|
+
};
|
|
62
|
+
anchor: 't' | 'ctr' | 'b';
|
|
63
|
+
vertical: boolean;
|
|
64
|
+
container: XmlElement;
|
|
65
|
+
autoFit?: boolean;
|
|
66
|
+
};
|
|
67
|
+
/** DrawingML text (a:txBody) of SmartArt and canvas shapes, kept as XML. */
|
|
68
|
+
txBody?: XmlElement;
|
|
69
|
+
/** Fill and outline colours of an old-style VML shape (RRGGBB; absent: none). */
|
|
70
|
+
vml?: {
|
|
71
|
+
fill?: string;
|
|
72
|
+
stroke?: string;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/** A placed child of a group or drawing canvas, in points relative to the group's top-left. */
|
|
76
|
+
export interface DrawingChild {
|
|
77
|
+
x: number;
|
|
78
|
+
y: number;
|
|
79
|
+
w: number;
|
|
80
|
+
h: number;
|
|
81
|
+
rotation: number;
|
|
82
|
+
flipH: boolean;
|
|
83
|
+
flipV: boolean;
|
|
84
|
+
content: DrawingContent;
|
|
85
|
+
}
|
|
86
|
+
/** What a drawing shows when it is not a plain picture. */
|
|
87
|
+
export type DrawingContent = {
|
|
88
|
+
type: 'picture';
|
|
89
|
+
target: string | undefined;
|
|
90
|
+
external: boolean;
|
|
91
|
+
} | {
|
|
92
|
+
type: 'shape';
|
|
93
|
+
shape: ShapeInfo;
|
|
94
|
+
} | {
|
|
95
|
+
type: 'group';
|
|
96
|
+
children: DrawingChild[];
|
|
97
|
+
} | {
|
|
98
|
+
type: 'chart';
|
|
99
|
+
part: string | undefined;
|
|
100
|
+
} | {
|
|
101
|
+
type: 'diagram';
|
|
102
|
+
dataPart: string | undefined;
|
|
103
|
+
};
|
|
51
104
|
export interface ImageInline extends RunRef {
|
|
52
105
|
kind: 'image';
|
|
53
106
|
/** Resolved media part name (or external URL when `external`). */
|
|
@@ -58,6 +111,12 @@ export interface ImageInline extends RunRef {
|
|
|
58
111
|
alt?: string;
|
|
59
112
|
float?: FloatInfo;
|
|
60
113
|
drawing: XmlElement;
|
|
114
|
+
/** Shapes, text boxes, groups, charts and SmartArt (absent for a plain picture). */
|
|
115
|
+
content?: DrawingContent;
|
|
116
|
+
/** Rotation in degrees and flips of the whole drawing. */
|
|
117
|
+
rotation?: number;
|
|
118
|
+
flipH?: boolean;
|
|
119
|
+
flipV?: boolean;
|
|
61
120
|
}
|
|
62
121
|
export interface FieldInline extends RunRef {
|
|
63
122
|
kind: 'field';
|
|
@@ -128,7 +187,17 @@ export interface PermEndInline {
|
|
|
128
187
|
id: string;
|
|
129
188
|
el: XmlElement;
|
|
130
189
|
}
|
|
131
|
-
|
|
190
|
+
/** An equation (m:oMath, or m:oMathPara for display equations on their own line). */
|
|
191
|
+
export interface MathInline {
|
|
192
|
+
kind: 'math';
|
|
193
|
+
node: XmlElement;
|
|
194
|
+
/** Display style: an m:oMathPara (big operators, limits above and below). */
|
|
195
|
+
display: boolean;
|
|
196
|
+
/** Linear format ("x=(-b±√(b^2-4ac))/(2a)"), for text extraction and search. */
|
|
197
|
+
text: string;
|
|
198
|
+
props: RunProps;
|
|
199
|
+
}
|
|
200
|
+
export type Inline = MathInline | TextInline | TabInline | BreakInline | ImageInline | FieldInline | NoteRefInline | CommentRefInline | LinkStartInline | LinkEndInline | BookmarkStartInline | BookmarkEndInline | CommentStartInline | CommentEndInline | PermStartInline | PermEndInline | LockStartInline | LockEndInline;
|
|
132
201
|
export interface DocParagraph {
|
|
133
202
|
kind: 'paragraph';
|
|
134
203
|
el: XmlElement;
|
|
@@ -144,7 +213,11 @@ export interface DocParagraph {
|
|
|
144
213
|
};
|
|
145
214
|
/** Set when this paragraph's w:pPr/w:sectPr ends a section. */
|
|
146
215
|
sectionEnd?: SectionProps;
|
|
216
|
+
/** The paragraph mark is a tracked insertion or deletion. */
|
|
217
|
+
markRevision?: 'ins' | 'del';
|
|
147
218
|
}
|
|
219
|
+
/** Word-like colours for revision authors (one per author, in order of first appearance). */
|
|
220
|
+
export declare const REVISION_COLORS: string[];
|
|
148
221
|
export interface DocCell {
|
|
149
222
|
el: XmlElement;
|
|
150
223
|
props: CellProps;
|
|
@@ -198,6 +271,10 @@ export declare class StoryReader {
|
|
|
198
271
|
readBlocks(container: XmlElement, cell?: CellContext): Block[];
|
|
199
272
|
private collectBlocks;
|
|
200
273
|
readParagraph(p: XmlElement, cell?: CellContext): DocParagraph;
|
|
274
|
+
/** Display formatting for text inside a tracked change (only when deletions are shown: "all markup"). */
|
|
275
|
+
private revisionProps;
|
|
276
|
+
private readonly revisions;
|
|
277
|
+
private readonly authors;
|
|
201
278
|
private suppressed;
|
|
202
279
|
private readInlines;
|
|
203
280
|
private runProps;
|
|
@@ -208,7 +285,15 @@ export declare class StoryReader {
|
|
|
208
285
|
private hyperlinkTarget;
|
|
209
286
|
private chooseAlternate;
|
|
210
287
|
private readDrawing;
|
|
288
|
+
/** The content of an a:graphicData: picture, shape, group, canvas, chart or SmartArt. */
|
|
289
|
+
private readGraphic;
|
|
290
|
+
private readPicture;
|
|
291
|
+
private readShape;
|
|
292
|
+
/** Children of a group or canvas, mapped from the group's child coordinates into `frame`. */
|
|
293
|
+
private readGroupChildren;
|
|
211
294
|
private readVml;
|
|
295
|
+
/** An old-style (VML) text box: its Word paragraphs in a plain frame, sized from the VML style. */
|
|
296
|
+
private readVmlTextBox;
|
|
212
297
|
private readMath;
|
|
213
298
|
readTable(tbl: XmlElement): DocTable;
|
|
214
299
|
}
|