ppt-codec 1.5.0 → 1.7.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/README.md +91 -75
- package/dist/base64.cjs +48 -0
- package/dist/base64.d.cts +5 -0
- package/dist/base64.d.ts +5 -0
- package/dist/base64.js +46 -0
- package/dist/diagnostics-CqxAnubw.d.cts +16 -0
- package/dist/diagnostics-CqxAnubw.d.ts +16 -0
- package/dist/diagnostics.cjs +11 -0
- package/dist/diagnostics.d.cts +2 -0
- package/dist/diagnostics.d.ts +2 -0
- package/dist/diagnostics.js +9 -0
- package/dist/document/color-scheme.cjs +4 -0
- package/dist/document/color-scheme.d.cts +2 -1
- package/dist/document/color-scheme.d.ts +2 -1
- package/dist/document/color-scheme.js +4 -1
- package/dist/document/master-write.cjs +21 -16
- package/dist/document/master-write.d.cts +2 -1
- package/dist/document/master-write.d.ts +2 -1
- package/dist/document/master-write.js +21 -16
- package/dist/document/notes-write.cjs +15 -7
- package/dist/document/notes-write.d.cts +2 -1
- package/dist/document/notes-write.d.ts +2 -1
- package/dist/document/notes-write.js +15 -7
- package/dist/document/notes.cjs +4 -3
- package/dist/document/notes.js +4 -3
- package/dist/drawing/blips.cjs +81 -0
- package/dist/drawing/blips.d.cts +16 -0
- package/dist/drawing/blips.d.ts +16 -0
- package/dist/drawing/blips.js +77 -0
- package/dist/drawing/properties.cjs +102 -0
- package/dist/drawing/properties.d.cts +29 -0
- package/dist/drawing/properties.d.ts +29 -0
- package/dist/drawing/properties.js +87 -0
- package/dist/drawing/shapes-write.cjs +234 -17
- package/dist/drawing/shapes-write.d.cts +16 -4
- package/dist/drawing/shapes-write.d.ts +16 -4
- package/dist/drawing/shapes-write.js +237 -19
- package/dist/drawing/shapes.cjs +34 -4
- package/dist/drawing/shapes.d.cts +11 -2
- package/dist/drawing/shapes.d.ts +11 -2
- package/dist/drawing/shapes.js +35 -5
- package/dist/index.cjs +48 -3
- package/dist/index.d.cts +12 -8
- package/dist/index.d.ts +12 -8
- package/dist/index.js +11 -7
- package/dist/ole/embedded-write.cjs +66 -0
- package/dist/ole/embedded-write.d.cts +12 -0
- package/dist/ole/embedded-write.d.ts +12 -0
- package/dist/ole/embedded-write.js +63 -0
- package/dist/ole/embedded.cjs +66 -0
- package/dist/ole/embedded.d.cts +12 -0
- package/dist/ole/embedded.d.ts +12 -0
- package/dist/ole/embedded.js +63 -0
- package/dist/read.cjs +145 -22
- package/dist/read.d.cts +13 -5
- package/dist/read.d.ts +13 -5
- package/dist/read.js +148 -26
- package/dist/record/types.cjs +28 -0
- package/dist/record/types.d.cts +15 -1
- package/dist/record/types.d.ts +15 -1
- package/dist/record/types.js +15 -1
- package/dist/stream/current-user.cjs +1 -0
- package/dist/stream/current-user.d.cts +2 -1
- package/dist/stream/current-user.d.ts +2 -1
- package/dist/stream/current-user.js +1 -1
- package/dist/units.cjs +10 -0
- package/dist/units.d.cts +4 -1
- package/dist/units.d.ts +4 -1
- package/dist/units.js +8 -1
- package/dist/write.cjs +137 -38
- package/dist/write.d.cts +14 -5
- package/dist/write.d.ts +14 -5
- package/dist/write.js +137 -38
- package/package.json +2 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { t as PptRecord } from "../tree-PMcPNgd-.js";
|
|
2
|
+
//#region src/drawing/properties.d.ts
|
|
3
|
+
declare const PROPERTY_ROTATION = 4;
|
|
4
|
+
declare const PROPERTY_PIB = 260;
|
|
5
|
+
declare const PROPERTY_TABLE_PROPERTIES = 927;
|
|
6
|
+
declare const PROPERTY_TABLE_ROW_PROPERTIES = 928;
|
|
7
|
+
declare const PROPERTY_DX_TEXT_LEFT = 129;
|
|
8
|
+
declare const PROPERTY_DY_TEXT_TOP = 130;
|
|
9
|
+
declare const PROPERTY_DX_TEXT_RIGHT = 131;
|
|
10
|
+
declare const PROPERTY_DY_TEXT_BOTTOM = 132;
|
|
11
|
+
declare function degreesToFixedPoint(degrees: number): number;
|
|
12
|
+
declare function fixedPointToDegrees(raw: number): number;
|
|
13
|
+
declare const TABLE_FLAG_IS_TABLE: number;
|
|
14
|
+
declare function readIMsoArray(complex: Uint8Array<ArrayBuffer>): readonly number[];
|
|
15
|
+
declare function writeIMsoArray(elements: readonly number[], elementSize: number): Uint8Array<ArrayBuffer>;
|
|
16
|
+
interface ShapeProperty {
|
|
17
|
+
readonly value: number;
|
|
18
|
+
readonly complex: Uint8Array<ArrayBuffer> | undefined;
|
|
19
|
+
}
|
|
20
|
+
declare function readShapeProperties(shape: PptRecord): Map<number, ShapeProperty>;
|
|
21
|
+
interface WritableShapeProperty {
|
|
22
|
+
readonly opid: number;
|
|
23
|
+
readonly op: number;
|
|
24
|
+
readonly fBid?: boolean;
|
|
25
|
+
readonly complex?: Uint8Array<ArrayBuffer>;
|
|
26
|
+
}
|
|
27
|
+
declare function writeShapePropertyTable(recType: number, entries: readonly WritableShapeProperty[]): Uint8Array<ArrayBuffer>;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { PROPERTY_DX_TEXT_LEFT, PROPERTY_DX_TEXT_RIGHT, PROPERTY_DY_TEXT_BOTTOM, PROPERTY_DY_TEXT_TOP, PROPERTY_PIB, PROPERTY_ROTATION, PROPERTY_TABLE_PROPERTIES, PROPERTY_TABLE_ROW_PROPERTIES, ShapeProperty, TABLE_FLAG_IS_TABLE, WritableShapeProperty, degreesToFixedPoint, fixedPointToDegrees, readIMsoArray, readShapeProperties, writeIMsoArray, writeShapePropertyTable };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { PptFormatError } from "../errors.js";
|
|
2
|
+
import { childRecords } from "../record/tree.js";
|
|
3
|
+
import "../record/types.js";
|
|
4
|
+
import { concatBytes, u16le, u32le, writeAtom } from "../record/write.js";
|
|
5
|
+
//#region src/drawing/properties.ts
|
|
6
|
+
const OPID_MASK = 16383;
|
|
7
|
+
const OPID_FCOMPLEX = 16384;
|
|
8
|
+
const OPID_FBID = 32768;
|
|
9
|
+
const PROPERTY_ROTATION = 4;
|
|
10
|
+
const PROPERTY_PIB = 260;
|
|
11
|
+
const PROPERTY_TABLE_PROPERTIES = 927;
|
|
12
|
+
const PROPERTY_TABLE_ROW_PROPERTIES = 928;
|
|
13
|
+
const PROPERTY_DX_TEXT_LEFT = 129;
|
|
14
|
+
const PROPERTY_DY_TEXT_TOP = 130;
|
|
15
|
+
const PROPERTY_DX_TEXT_RIGHT = 131;
|
|
16
|
+
const PROPERTY_DY_TEXT_BOTTOM = 132;
|
|
17
|
+
const FIXED_POINT_ONE = 65536;
|
|
18
|
+
function degreesToFixedPoint(degrees) {
|
|
19
|
+
return Math.round(degrees * FIXED_POINT_ONE);
|
|
20
|
+
}
|
|
21
|
+
function fixedPointToDegrees(raw) {
|
|
22
|
+
return raw / FIXED_POINT_ONE;
|
|
23
|
+
}
|
|
24
|
+
const TABLE_FLAG_IS_TABLE = 1;
|
|
25
|
+
function readIMsoArray(complex) {
|
|
26
|
+
if (complex.length < 6) throw new PptFormatError(`a complex property's IMsoArray carries ${complex.length} bytes, fewer than the 6 its three count fields need`);
|
|
27
|
+
const view = new DataView(complex.buffer, complex.byteOffset, complex.byteLength);
|
|
28
|
+
const elementCount = view.getUint16(0, true);
|
|
29
|
+
const elementSize = view.getUint16(4, true);
|
|
30
|
+
const data = complex.subarray(6);
|
|
31
|
+
if (data.length < elementCount * elementSize) throw new PptFormatError(`a complex property's IMsoArray declares ${elementCount} elements of ${elementSize} bytes but only ${data.length} remain`);
|
|
32
|
+
const elements = [];
|
|
33
|
+
for (let index = 0; index < elementCount; index += 1) elements.push(view.getInt32(6 + index * elementSize, true));
|
|
34
|
+
return elements;
|
|
35
|
+
}
|
|
36
|
+
function writeIMsoArray(elements, elementSize) {
|
|
37
|
+
const data = new Uint8Array(elements.length * elementSize);
|
|
38
|
+
const view = new DataView(data.buffer);
|
|
39
|
+
elements.forEach((element, index) => {
|
|
40
|
+
view.setInt32(index * elementSize, element, true);
|
|
41
|
+
});
|
|
42
|
+
return concatBytes(u16le(elements.length), u16le(elements.length), u16le(elementSize), data);
|
|
43
|
+
}
|
|
44
|
+
function readShapeProperties(shape) {
|
|
45
|
+
const properties = /* @__PURE__ */ new Map();
|
|
46
|
+
for (const record of childRecords(shape)) {
|
|
47
|
+
if (record.header.recType !== 61451 && record.header.recType !== 61729 && record.header.recType !== 61730) continue;
|
|
48
|
+
const count = record.header.recInstance;
|
|
49
|
+
const needed = count * 6;
|
|
50
|
+
if (record.data.length < needed) throw new PptFormatError(`a shape property table declares ${count} properties but its ${record.data.length} bytes of data cannot hold the ${needed} its entries need`);
|
|
51
|
+
const view = new DataView(record.data.buffer, record.data.byteOffset, record.data.byteLength);
|
|
52
|
+
let complexAt = needed;
|
|
53
|
+
for (let index = 0; index < count; index += 1) {
|
|
54
|
+
const at = index * 6;
|
|
55
|
+
const opid = view.getUint16(at, true);
|
|
56
|
+
const value = view.getInt32(at + 2, true);
|
|
57
|
+
const isComplex = (opid & OPID_FCOMPLEX) !== 0;
|
|
58
|
+
let complex;
|
|
59
|
+
if (isComplex) {
|
|
60
|
+
complex = record.data.subarray(complexAt, complexAt + value);
|
|
61
|
+
complexAt += value;
|
|
62
|
+
if (complexAt > record.data.length) throw new PptFormatError(`a shape property table's complex data declares ${complexAt} bytes in total but the table carries only ${record.data.length}`);
|
|
63
|
+
}
|
|
64
|
+
properties.set(opid & OPID_MASK, {
|
|
65
|
+
value,
|
|
66
|
+
complex
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return properties;
|
|
71
|
+
}
|
|
72
|
+
function writeShapePropertyTable(recType, entries) {
|
|
73
|
+
const ordered = [...entries].sort((a, b) => a.opid - b.opid);
|
|
74
|
+
const complexParts = [];
|
|
75
|
+
const entryParts = ordered.map((entry) => {
|
|
76
|
+
const isComplex = entry.complex !== void 0;
|
|
77
|
+
const opidWord = entry.opid | (isComplex ? OPID_FCOMPLEX : 0) | (entry.fBid === true ? OPID_FBID : 0);
|
|
78
|
+
if (isComplex) complexParts.push(entry.complex);
|
|
79
|
+
return concatBytes(u16le(opidWord), u32le(entry.op));
|
|
80
|
+
});
|
|
81
|
+
return writeAtom(recType, concatBytes(...entryParts, ...complexParts), {
|
|
82
|
+
recVer: 3,
|
|
83
|
+
recInstance: ordered.length
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
//#endregion
|
|
87
|
+
export { PROPERTY_DX_TEXT_LEFT, PROPERTY_DX_TEXT_RIGHT, PROPERTY_DY_TEXT_BOTTOM, PROPERTY_DY_TEXT_TOP, PROPERTY_PIB, PROPERTY_ROTATION, PROPERTY_TABLE_PROPERTIES, PROPERTY_TABLE_ROW_PROPERTIES, TABLE_FLAG_IS_TABLE, degreesToFixedPoint, fixedPointToDegrees, readIMsoArray, readShapeProperties, writeIMsoArray, writeShapePropertyTable };
|
|
@@ -1,11 +1,39 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_errors = require("../errors.cjs");
|
|
2
3
|
const require_record_types = require("../record/types.cjs");
|
|
3
4
|
const require_text_atoms = require("../text/atoms.cjs");
|
|
4
5
|
const require_units = require("../units.cjs");
|
|
5
6
|
const require_content_write = require("../content-write.cjs");
|
|
7
|
+
const require_diagnostics = require("../diagnostics.cjs");
|
|
6
8
|
const require_record_write = require("../record/write.cjs");
|
|
9
|
+
const require_drawing_blips = require("./blips.cjs");
|
|
10
|
+
const require_drawing_properties = require("./properties.cjs");
|
|
11
|
+
const require_read = require("../read.cjs");
|
|
7
12
|
const require_text_style_write = require("../text/style-write.cjs");
|
|
8
13
|
//#region src/drawing/shapes-write.ts
|
|
14
|
+
function insetProperties(shape, isPicture) {
|
|
15
|
+
const defaultLeftRight = isPicture ? 0 : require_read.DEFAULT_INSET_LEFT_RIGHT_PT;
|
|
16
|
+
const defaultTopBottom = isPicture ? 0 : require_read.DEFAULT_INSET_TOP_BOTTOM_PT;
|
|
17
|
+
const entries = [];
|
|
18
|
+
if (shape.insetLeftPt !== defaultLeftRight) entries.push({
|
|
19
|
+
opid: 129,
|
|
20
|
+
op: require_units.pointsToEmu(shape.insetLeftPt)
|
|
21
|
+
});
|
|
22
|
+
if (shape.insetTopPt !== defaultTopBottom) entries.push({
|
|
23
|
+
opid: 130,
|
|
24
|
+
op: require_units.pointsToEmu(shape.insetTopPt)
|
|
25
|
+
});
|
|
26
|
+
if (shape.insetRightPt !== defaultLeftRight) entries.push({
|
|
27
|
+
opid: 131,
|
|
28
|
+
op: require_units.pointsToEmu(shape.insetRightPt)
|
|
29
|
+
});
|
|
30
|
+
if (shape.insetBottomPt !== defaultTopBottom) entries.push({
|
|
31
|
+
opid: 132,
|
|
32
|
+
op: require_units.pointsToEmu(shape.insetBottomPt)
|
|
33
|
+
});
|
|
34
|
+
return entries;
|
|
35
|
+
}
|
|
36
|
+
const FSP_CHILD = 2;
|
|
9
37
|
const PATRIARCH_SPID = 1;
|
|
10
38
|
const FIRST_CONTENT_SPID = 2;
|
|
11
39
|
function writeFsp(spid, flags) {
|
|
@@ -21,9 +49,23 @@ function writeClientAnchor(xPt, yPt, widthPt, heightPt) {
|
|
|
21
49
|
function writeTextCharsAtom(text) {
|
|
22
50
|
return require_record_write.writeAtom(require_record_types.RT_TextCharsAtom, require_record_write.utf16le(text));
|
|
23
51
|
}
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
|
|
52
|
+
function writeShapeProperties(shape, pib) {
|
|
53
|
+
const entries = [];
|
|
54
|
+
if (shape.rotationDeg !== void 0) entries.push({
|
|
55
|
+
opid: 4,
|
|
56
|
+
op: require_drawing_properties.degreesToFixedPoint(shape.rotationDeg)
|
|
57
|
+
});
|
|
58
|
+
if (pib !== void 0) entries.push({
|
|
59
|
+
opid: 260,
|
|
60
|
+
op: pib,
|
|
61
|
+
fBid: true
|
|
62
|
+
});
|
|
63
|
+
entries.push(...insetProperties(shape, pib !== void 0));
|
|
64
|
+
return entries.length === 0 ? void 0 : require_drawing_properties.writeShapePropertyTable(require_record_types.OfficeArtFOPT, entries);
|
|
65
|
+
}
|
|
66
|
+
function writeClientTextbox(textBlocks, fontIndexOf) {
|
|
67
|
+
if (textBlocks.length === 0) return;
|
|
68
|
+
const { text, style } = require_content_write.buildTextBody(textBlocks, fontIndexOf);
|
|
27
69
|
const totalParagraphCount = style.paragraphRuns.reduce((sum, run) => sum + run.count, 0);
|
|
28
70
|
if (totalParagraphCount !== require_text_atoms.characterCountOf(text)) throw new Error(`internal error: built ${totalParagraphCount} characters of paragraph runs for a ${require_text_atoms.characterCountOf(text)}-character text body`);
|
|
29
71
|
return require_record_write.writeContainer(require_record_types.OfficeArtClientTextbox, [
|
|
@@ -32,9 +74,12 @@ function writeClientTextbox(shape, fontIndexOf) {
|
|
|
32
74
|
require_text_style_write.writeStyleTextPropAtom(style)
|
|
33
75
|
]);
|
|
34
76
|
}
|
|
35
|
-
function writeShape(spid, shape, fontIndexOf, clientData) {
|
|
36
|
-
const
|
|
37
|
-
const
|
|
77
|
+
function writeShape(spid, shape, pib, textBlocks, fontIndexOf, clientData) {
|
|
78
|
+
const properties = writeShapeProperties(shape, pib);
|
|
79
|
+
const clientTextbox = writeClientTextbox(textBlocks, fontIndexOf);
|
|
80
|
+
const children = [writeFsp(spid, 0)];
|
|
81
|
+
if (properties !== void 0) children.push(properties);
|
|
82
|
+
children.push(writeClientAnchor(shape.frame.xPt, shape.frame.yPt, shape.frame.widthPt, shape.frame.heightPt));
|
|
38
83
|
if (clientData !== void 0) children.push(clientData);
|
|
39
84
|
if (clientTextbox !== void 0) children.push(clientTextbox);
|
|
40
85
|
return require_record_write.writeContainer(require_record_types.OfficeArtSpContainer, children);
|
|
@@ -42,19 +87,191 @@ function writeShape(spid, shape, fontIndexOf, clientData) {
|
|
|
42
87
|
function writePatriarch() {
|
|
43
88
|
return require_record_write.writeContainer(require_record_types.OfficeArtSpContainer, [require_record_write.writeAtom(require_record_types.OfficeArtFSPGR, /* @__PURE__ */ new Uint8Array(16), { recVer: 1 }), writeFsp(PATRIARCH_SPID, 5)]);
|
|
44
89
|
}
|
|
45
|
-
function
|
|
46
|
-
|
|
47
|
-
|
|
90
|
+
function reportDrop(context, diagnostic) {
|
|
91
|
+
context.sink(diagnostic);
|
|
92
|
+
if (context.strict) throw new require_errors.PptUnsupportedContentError(diagnostic.message);
|
|
93
|
+
}
|
|
94
|
+
function planShapeBlocks(blocks, context, hasOleClientData) {
|
|
95
|
+
const textBlocks = [];
|
|
96
|
+
let pib;
|
|
97
|
+
let table;
|
|
98
|
+
const drop = (block, reason) => {
|
|
99
|
+
reportDrop(context, {
|
|
100
|
+
code: require_diagnostics.PptDiagnosticCodes.BLOCK_DROPPED,
|
|
101
|
+
severity: "warning",
|
|
102
|
+
message: `${context.location}: ${reason}`
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
for (const block of blocks) {
|
|
106
|
+
if (block.kind === "embeddedObject" && hasOleClientData) continue;
|
|
107
|
+
if (block.kind === "paragraph") {
|
|
108
|
+
textBlocks.push(block);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (block.kind === "image") {
|
|
112
|
+
if (!require_drawing_blips.isBlipFormat(block.format)) {
|
|
113
|
+
reportDrop(context, {
|
|
114
|
+
code: require_diagnostics.PptDiagnosticCodes.IMAGE_DROPPED,
|
|
115
|
+
severity: "warning",
|
|
116
|
+
message: `${context.location}: an image block in format '${block.format}' is dropped; MSOBLIPTYPE gives this writer a blip record for PNG and JPEG only`
|
|
117
|
+
});
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
if (pib !== void 0) {
|
|
121
|
+
reportDrop(context, {
|
|
122
|
+
code: require_diagnostics.PptDiagnosticCodes.IMAGE_DROPPED,
|
|
123
|
+
severity: "warning",
|
|
124
|
+
message: `${context.location}: a second image block is dropped; a shape carries exactly one blip-store reference, and an earlier image already consumed it`
|
|
125
|
+
});
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
pib = context.blipIndexOf(block);
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (block.kind === "table") {
|
|
132
|
+
if (table !== void 0) {
|
|
133
|
+
drop(block, "a second 'table' block is dropped; a shape becomes one table group, and an earlier table already did");
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
table = block;
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
drop(block, `a '${block.kind}' block is dropped; this writer produces no [MS-PPT] spelling for it`);
|
|
140
|
+
}
|
|
141
|
+
if (table !== void 0) {
|
|
142
|
+
for (const block of textBlocks) drop(block, "a 'paragraph' block is dropped; a shape carrying a table becomes a table group, which holds its text in cells rather than a text body of its own");
|
|
143
|
+
if (pib !== void 0) reportDrop(context, {
|
|
144
|
+
code: require_diagnostics.PptDiagnosticCodes.IMAGE_DROPPED,
|
|
145
|
+
severity: "warning",
|
|
146
|
+
message: `${context.location}: an image block is dropped; a shape carrying a table becomes a table group, which has no blip reference of its own`
|
|
147
|
+
});
|
|
148
|
+
return {
|
|
149
|
+
pib: void 0,
|
|
150
|
+
textBlocks: [],
|
|
151
|
+
table
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
pib,
|
|
156
|
+
textBlocks,
|
|
157
|
+
table
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
function tableRowHeights(table, frameHeightMasterUnits) {
|
|
161
|
+
const stated = table.rows.map((row) => row.heightPt === void 0 ? void 0 : require_units.pointsToMasterUnits(row.heightPt));
|
|
162
|
+
const unstatedCount = stated.filter((height) => height === void 0).length;
|
|
163
|
+
if (unstatedCount === 0) return stated.map((height) => {
|
|
164
|
+
if (height === void 0) throw new Error("internal error: a stated row height became unstated in the same pass");
|
|
165
|
+
return height;
|
|
166
|
+
});
|
|
167
|
+
const remaining = frameHeightMasterUnits - stated.reduce((sum, height) => sum + (height ?? 0), 0);
|
|
168
|
+
const shared = Math.max(1, Math.round(remaining / unstatedCount));
|
|
169
|
+
return stated.map((height) => height ?? shared);
|
|
170
|
+
}
|
|
171
|
+
function writeTableGroup(spid, shape, table, context) {
|
|
172
|
+
const { frame } = shape;
|
|
173
|
+
const rowHeights = tableRowHeights(table, require_units.pointsToMasterUnits(frame.heightPt));
|
|
174
|
+
const declaredWidths = table.columnWidthsPt.map(require_units.pointsToMasterUnits);
|
|
175
|
+
const cellCount = Math.max(1, ...table.rows.map((row) => row.cells.length), declaredWidths.length);
|
|
176
|
+
const lastDeclared = declaredWidths.at(-1);
|
|
177
|
+
const equalShare = Math.max(1, Math.round(require_units.pointsToMasterUnits(frame.widthPt) / cellCount));
|
|
178
|
+
const columnWidthsMasterUnits = Array.from({ length: cellCount }, (_, index) => declaredWidths[index] ?? lastDeclared ?? equalShare);
|
|
179
|
+
const columnBoundaries = [];
|
|
180
|
+
let columnEdge = require_units.pointsToMasterUnits(frame.xPt);
|
|
181
|
+
for (const width of columnWidthsMasterUnits) {
|
|
182
|
+
columnBoundaries.push(columnEdge);
|
|
183
|
+
columnEdge += width;
|
|
184
|
+
}
|
|
185
|
+
columnBoundaries.push(columnEdge);
|
|
186
|
+
const rowBoundaries = [];
|
|
187
|
+
let rowEdge = require_units.pointsToMasterUnits(frame.yPt);
|
|
188
|
+
for (const height of rowHeights) {
|
|
189
|
+
rowBoundaries.push(rowEdge);
|
|
190
|
+
rowEdge += height;
|
|
191
|
+
}
|
|
192
|
+
rowBoundaries.push(rowEdge);
|
|
193
|
+
const rowHeightsPayload = require_drawing_properties.writeIMsoArray(rowHeights, 4);
|
|
194
|
+
const tableLeft = require_units.pointsToMasterUnits(frame.xPt);
|
|
195
|
+
const tableTop = require_units.pointsToMasterUnits(frame.yPt);
|
|
196
|
+
const tableRight = require_units.pointsToMasterUnits(frame.xPt + frame.widthPt);
|
|
197
|
+
const tableBottom = require_units.pointsToMasterUnits(frame.yPt + frame.heightPt);
|
|
198
|
+
const groupShape = require_record_write.writeContainer(require_record_types.OfficeArtSpContainer, [
|
|
199
|
+
require_record_write.writeAtom(require_record_types.OfficeArtFSPGR, require_record_write.concatBytes(require_record_write.i32le(tableLeft), require_record_write.i32le(tableTop), require_record_write.i32le(tableRight), require_record_write.i32le(tableBottom)), { recVer: 1 }),
|
|
200
|
+
writeFsp(spid, 513),
|
|
201
|
+
...shape.rotationDeg === void 0 ? [] : [require_drawing_properties.writeShapePropertyTable(require_record_types.OfficeArtFOPT, [{
|
|
202
|
+
opid: 4,
|
|
203
|
+
op: require_drawing_properties.degreesToFixedPoint(shape.rotationDeg)
|
|
204
|
+
}])],
|
|
205
|
+
require_drawing_properties.writeShapePropertyTable(require_record_types.OfficeArtTertiaryFOPT, [{
|
|
206
|
+
opid: 927,
|
|
207
|
+
op: 1
|
|
208
|
+
}, {
|
|
209
|
+
opid: 928,
|
|
210
|
+
op: rowHeightsPayload.length,
|
|
211
|
+
fBid: true,
|
|
212
|
+
complex: rowHeightsPayload
|
|
213
|
+
}]),
|
|
214
|
+
writeClientAnchor(frame.xPt, frame.yPt, frame.widthPt, frame.heightPt)
|
|
215
|
+
]);
|
|
216
|
+
let cellSpid = spid + 1;
|
|
217
|
+
const cellShapes = table.rows.flatMap((row, rowIndex) => row.cells.map((cell, columnIndex) => {
|
|
218
|
+
const cellLeft = columnBoundaries[columnIndex];
|
|
219
|
+
const cellRight = columnBoundaries[columnIndex + 1];
|
|
220
|
+
const cellTop = rowBoundaries[rowIndex];
|
|
221
|
+
const cellBottom = rowBoundaries[rowIndex + 1];
|
|
222
|
+
if (cellLeft === void 0 || cellRight === void 0 || cellTop === void 0 || cellBottom === void 0) throw new Error("internal error: a table cell sits outside the grid boundaries derived from its own table");
|
|
223
|
+
if (cell.colSpan !== void 0 && cell.colSpan > 1) context.sink({
|
|
224
|
+
code: require_diagnostics.PptDiagnosticCodes.TABLE_SPAN_DROPPED,
|
|
225
|
+
severity: "warning",
|
|
226
|
+
message: `${context.location}: a table cell's colSpan ${String(cell.colSpan)} is dropped; a PowerPoint 97-2003 table is a strict grid of shapes with no merge records, so the cell is written one column wide`
|
|
227
|
+
});
|
|
228
|
+
if (cell.rowSpan !== void 0 && cell.rowSpan > 1) context.sink({
|
|
229
|
+
code: require_diagnostics.PptDiagnosticCodes.TABLE_SPAN_DROPPED,
|
|
230
|
+
severity: "warning",
|
|
231
|
+
message: `${context.location}: a table cell's rowSpan ${String(cell.rowSpan)} is dropped; a PowerPoint 97-2003 table is a strict grid of shapes with no merge records, so the cell is written one row tall`
|
|
232
|
+
});
|
|
233
|
+
const paragraphs = cell.blocks.filter((block) => block.kind === "paragraph");
|
|
234
|
+
for (const block of cell.blocks) if (block.kind !== "paragraph") reportDrop(context, {
|
|
235
|
+
code: require_diagnostics.PptDiagnosticCodes.BLOCK_DROPPED,
|
|
236
|
+
severity: "warning",
|
|
237
|
+
message: `${context.location}: a '${block.kind}' block inside a table cell is dropped; a table cell in this format is a plain text-box shape with no property table or object reference of its own`
|
|
238
|
+
});
|
|
239
|
+
const textbox = writeClientTextbox(paragraphs, context.fontIndexOf);
|
|
240
|
+
const children = [writeFsp(cellSpid, FSP_CHILD), require_record_write.writeAtom(require_record_types.OfficeArtChildAnchor, require_record_write.concatBytes(require_record_write.i32le(cellLeft), require_record_write.i32le(cellTop), require_record_write.i32le(cellRight), require_record_write.i32le(cellBottom)))];
|
|
241
|
+
cellSpid += 1;
|
|
242
|
+
if (textbox !== void 0) children.push(textbox);
|
|
243
|
+
return require_record_write.writeContainer(require_record_types.OfficeArtSpContainer, children);
|
|
244
|
+
}));
|
|
245
|
+
return {
|
|
246
|
+
bytes: require_record_write.writeContainer(require_record_types.OfficeArtSpgrContainer, [groupShape, ...cellShapes]),
|
|
247
|
+
shapeCount: 1 + table.rows.reduce((sum, row) => sum + row.cells.length, 0)
|
|
248
|
+
};
|
|
48
249
|
}
|
|
49
|
-
function
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
250
|
+
function writeDrawing(shapes, context) {
|
|
251
|
+
let nextSpid = FIRST_CONTENT_SPID;
|
|
252
|
+
let shapeCount = 1;
|
|
253
|
+
const shapeContainers = [];
|
|
254
|
+
for (const entry of shapes) {
|
|
255
|
+
const plan = planShapeBlocks(entry.shape.blocks, context, entry.clientData !== void 0);
|
|
256
|
+
if (plan.table !== void 0) {
|
|
257
|
+
const group = writeTableGroup(nextSpid, entry.shape, plan.table, context);
|
|
258
|
+
nextSpid += group.shapeCount;
|
|
259
|
+
shapeCount += group.shapeCount;
|
|
260
|
+
shapeContainers.push(group.bytes);
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
shapeContainers.push(writeShape(nextSpid, entry.shape, plan.pib, plan.textBlocks, context.fontIndexOf, entry.clientData));
|
|
264
|
+
nextSpid += 1;
|
|
265
|
+
shapeCount += 1;
|
|
266
|
+
}
|
|
267
|
+
return {
|
|
268
|
+
bytes: require_record_write.writeContainer(require_record_types.RT_Drawing, [require_record_write.writeContainer(require_record_types.OfficeArtDgContainer, [require_record_write.writeContainer(require_record_types.OfficeArtSpgrContainer, [writePatriarch(), ...shapeContainers])])]),
|
|
269
|
+
shapeCount,
|
|
270
|
+
maxSpid: Math.max(PATRIARCH_SPID, nextSpid - 1)
|
|
271
|
+
};
|
|
54
272
|
}
|
|
55
|
-
function
|
|
56
|
-
return writeDrawing(shapes,
|
|
273
|
+
function writeSlideDrawing(shapes, context) {
|
|
274
|
+
return writeDrawing(shapes, context);
|
|
57
275
|
}
|
|
58
276
|
//#endregion
|
|
59
|
-
exports.writeDrawingWithClientData = writeDrawingWithClientData;
|
|
60
277
|
exports.writeSlideDrawing = writeSlideDrawing;
|
|
@@ -1,10 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as PptDiagnosticSink } from "../diagnostics-CqxAnubw.cjs";
|
|
2
|
+
import { ContentImageBlock, ContentShape } from "document-schema.js";
|
|
2
3
|
//#region src/drawing/shapes-write.d.ts
|
|
3
4
|
interface DrawingShape {
|
|
4
5
|
readonly shape: ContentShape;
|
|
5
6
|
readonly clientData: Uint8Array<ArrayBuffer> | undefined;
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
interface DrawingWritten {
|
|
9
|
+
readonly bytes: Uint8Array<ArrayBuffer>;
|
|
10
|
+
readonly shapeCount: number;
|
|
11
|
+
readonly maxSpid: number;
|
|
12
|
+
}
|
|
13
|
+
interface DrawingWriteContext {
|
|
14
|
+
readonly fontIndexOf: (family: string) => number;
|
|
15
|
+
readonly blipIndexOf: (image: ContentImageBlock) => number;
|
|
16
|
+
readonly sink: PptDiagnosticSink;
|
|
17
|
+
readonly strict: boolean;
|
|
18
|
+
readonly location: string;
|
|
19
|
+
}
|
|
20
|
+
declare function writeSlideDrawing(shapes: readonly DrawingShape[], context: DrawingWriteContext): DrawingWritten;
|
|
9
21
|
//#endregion
|
|
10
|
-
export { DrawingShape,
|
|
22
|
+
export { DrawingShape, DrawingWriteContext, DrawingWritten, writeSlideDrawing };
|
|
@@ -1,10 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as PptDiagnosticSink } from "../diagnostics-CqxAnubw.js";
|
|
2
|
+
import { ContentImageBlock, ContentShape } from "document-schema.js";
|
|
2
3
|
//#region src/drawing/shapes-write.d.ts
|
|
3
4
|
interface DrawingShape {
|
|
4
5
|
readonly shape: ContentShape;
|
|
5
6
|
readonly clientData: Uint8Array<ArrayBuffer> | undefined;
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
interface DrawingWritten {
|
|
9
|
+
readonly bytes: Uint8Array<ArrayBuffer>;
|
|
10
|
+
readonly shapeCount: number;
|
|
11
|
+
readonly maxSpid: number;
|
|
12
|
+
}
|
|
13
|
+
interface DrawingWriteContext {
|
|
14
|
+
readonly fontIndexOf: (family: string) => number;
|
|
15
|
+
readonly blipIndexOf: (image: ContentImageBlock) => number;
|
|
16
|
+
readonly sink: PptDiagnosticSink;
|
|
17
|
+
readonly strict: boolean;
|
|
18
|
+
readonly location: string;
|
|
19
|
+
}
|
|
20
|
+
declare function writeSlideDrawing(shapes: readonly DrawingShape[], context: DrawingWriteContext): DrawingWritten;
|
|
9
21
|
//#endregion
|
|
10
|
-
export { DrawingShape,
|
|
22
|
+
export { DrawingShape, DrawingWriteContext, DrawingWritten, writeSlideDrawing };
|