ppt-codec 1.3.0 → 1.4.1

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.
@@ -1,5 +1,5 @@
1
1
  import { PptFormatError } from "../errors.js";
2
- import { RT_StyleTextPropAtom } from "../record/types.js";
2
+ import { RT_StyleTextPropAtom, RT_TextMasterStyleAtom } from "../record/types.js";
3
3
  //#region src/text/style.ts
4
4
  const ALIGN_LEFT = 0;
5
5
  const ALIGN_CENTER = 1;
@@ -50,6 +50,8 @@ const STYLE_UNDERLINE = 4;
50
50
  const STYLE_SHADOW = 16;
51
51
  const STYLE_EMBOSS = 512;
52
52
  const COLOR_INDEX_SRGB = 254;
53
+ const COLOR_INDEX_UNDEFINED = 255;
54
+ const COLOR_SCHEME_SLOT_COUNT = 8;
53
55
  var FieldCursor = class {
54
56
  data;
55
57
  describe;
@@ -90,11 +92,20 @@ var FieldCursor = class {
90
92
  function readColorIndexStruct(cursor) {
91
93
  const [red, green, blue, index] = cursor.bytes(4);
92
94
  if (red === void 0 || green === void 0 || blue === void 0 || index === void 0) throw new PptFormatError("ColorIndexStruct read returned fewer than its four bytes");
93
- return index === 254 ? {
94
- red,
95
- green,
96
- blue
97
- } : void 0;
95
+ if (index === 254) return {
96
+ kind: "rgb",
97
+ rgb: {
98
+ red,
99
+ green,
100
+ blue
101
+ }
102
+ };
103
+ if (index === 255) return;
104
+ if (index < 8) return {
105
+ kind: "scheme",
106
+ schemeIndex: index
107
+ };
108
+ throw new PptFormatError(`ColorIndexStruct index 0x${index.toString(16)} is none of a colour-scheme slot (0x00-0x07), the literal-colour sentinel (0x${254 .toString(16)}), or the undefined-colour sentinel (0x${255 .toString(16)})`);
98
109
  }
99
110
  function readTextPFException(cursor, indentLevel) {
100
111
  const masks = cursor.u32();
@@ -174,5 +185,29 @@ function readStyleTextPropAtom(record, characterCount) {
174
185
  characterRuns: readRuns(cursor, characterCount, "StyleTextPropAtom character runs", readTextCFException)
175
186
  };
176
187
  }
188
+ const MASTER_STYLE_MAX_LEVELS = 5;
189
+ const MASTER_STYLE_TYPES_WITH_EXPLICIT_LEVEL = 5;
190
+ function readTextMasterStyleAtom(record) {
191
+ if (record.header.recType !== 4003) throw new PptFormatError(`expected RT_TextMasterStyleAtom (0x${RT_TextMasterStyleAtom.toString(16)}) at offset ${record.offset}, found record type 0x${record.header.recType.toString(16)}`);
192
+ const textType = record.header.recInstance;
193
+ const cursor = new FieldCursor(record.data, 0, "TextMasterStyleAtom");
194
+ const cLevels = cursor.u16();
195
+ if (cLevels > MASTER_STYLE_MAX_LEVELS) throw new PptFormatError(`TextMasterStyleAtom at offset ${record.offset} declares cLevels ${cLevels}, more than the mandated maximum of ${MASTER_STYLE_MAX_LEVELS}`);
196
+ const hasExplicitLevel = textType >= MASTER_STYLE_TYPES_WITH_EXPLICIT_LEVEL;
197
+ const levels = [];
198
+ for (let i = 0; i < cLevels; i += 1) {
199
+ if (hasExplicitLevel) cursor.u16();
200
+ const paragraph = readTextPFException(cursor, i);
201
+ const character = readTextCFException(cursor);
202
+ levels.push({
203
+ paragraph,
204
+ character
205
+ });
206
+ }
207
+ return {
208
+ textType,
209
+ levels
210
+ };
211
+ }
177
212
  //#endregion
178
- export { ALIGN_CENTER, ALIGN_DISTRIBUTED, ALIGN_JUSTIFY, ALIGN_JUSTIFY_LOW, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_THAI_DISTRIBUTED, CF_ANSI_TYPEFACE, CF_BOLD, CF_COLOR, CF_EMBOSS, CF_FEHINT, CF_HAS_STYLE, CF_ITALIC, CF_KUMI, CF_OLD_EA_TYPEFACE, CF_POSITION, CF_SHADOW, CF_SIZE, CF_SYMBOL_TYPEFACE, CF_TYPEFACE, CF_UNDERLINE, COLOR_INDEX_SRGB, PF_ALIGN, PF_BULLET_CHAR, PF_BULLET_COLOR, PF_BULLET_FONT, PF_BULLET_HAS_COLOR, PF_BULLET_HAS_FONT, PF_BULLET_HAS_SIZE, PF_BULLET_SIZE, PF_CHAR_WRAP, PF_DEFAULT_TAB_SIZE, PF_FONT_ALIGN, PF_HAS_BULLET, PF_INDENT, PF_LEFT_MARGIN, PF_LINE_SPACING, PF_OVERFLOW, PF_SPACE_AFTER, PF_SPACE_BEFORE, PF_TAB_STOPS, PF_TEXT_DIRECTION, PF_WORD_WRAP, STYLE_BOLD, STYLE_EMBOSS, STYLE_ITALIC, STYLE_SHADOW, STYLE_UNDERLINE, readStyleTextPropAtom };
213
+ export { ALIGN_CENTER, ALIGN_DISTRIBUTED, ALIGN_JUSTIFY, ALIGN_JUSTIFY_LOW, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_THAI_DISTRIBUTED, CF_ANSI_TYPEFACE, CF_BOLD, CF_COLOR, CF_EMBOSS, CF_FEHINT, CF_HAS_STYLE, CF_ITALIC, CF_KUMI, CF_OLD_EA_TYPEFACE, CF_POSITION, CF_SHADOW, CF_SIZE, CF_SYMBOL_TYPEFACE, CF_TYPEFACE, CF_UNDERLINE, COLOR_INDEX_SRGB, COLOR_INDEX_UNDEFINED, COLOR_SCHEME_SLOT_COUNT, PF_ALIGN, PF_BULLET_CHAR, PF_BULLET_COLOR, PF_BULLET_FONT, PF_BULLET_HAS_COLOR, PF_BULLET_HAS_FONT, PF_BULLET_HAS_SIZE, PF_BULLET_SIZE, PF_CHAR_WRAP, PF_DEFAULT_TAB_SIZE, PF_FONT_ALIGN, PF_HAS_BULLET, PF_INDENT, PF_LEFT_MARGIN, PF_LINE_SPACING, PF_OVERFLOW, PF_SPACE_AFTER, PF_SPACE_BEFORE, PF_TAB_STOPS, PF_TEXT_DIRECTION, PF_WORD_WRAP, STYLE_BOLD, STYLE_EMBOSS, STYLE_ITALIC, STYLE_SHADOW, STYLE_UNDERLINE, readStyleTextPropAtom, readTextMasterStyleAtom };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ppt-codec",
3
- "version": "1.3.0",
3
+ "version": "1.4.1",
4
4
  "description": "Hand-written PowerPoint 97-2003 binary (.ppt, [MS-PPT]) reader and writer against the shared document-schema.js content pivot.",
5
5
  "type": "module",
6
6
  "repository": {
@@ -78,8 +78,8 @@
78
78
  "license": "MIT",
79
79
  "packageManager": "pnpm@11.6.0",
80
80
  "dependencies": {
81
- "archive-codec": "1.9.0",
82
- "document-schema.js": "7.3.1"
81
+ "archive-codec": "1.9.1",
82
+ "document-schema.js": "7.4.0"
83
83
  },
84
84
  "devDependencies": {
85
85
  "@arethetypeswrong/cli": "0.18.5",