Skip to content

Commit 50502e2

Browse files
authored
Merge pull request #496 from Harbour-Enterprises/artem-HAR-9657
HAR-9657 - fix fonts issue
2 parents b2650f3 + 5b8d7a2 commit 50502e2

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

packages/super-editor/src/core/DocxZipper.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ class DocxZipper {
6868
const imageUrl = URL.createObjectURL(file);
6969
this.media[zipEntry.name] = imageUrl;
7070
}
71-
} else if (!isNode && zipEntry.name.startsWith('word/fonts') && zipEntry.name !== 'word/fonts/') {
72-
const arraybuffer = await zipEntry.async('arraybuffer');
73-
this.fonts[zipEntry.name] = arraybuffer;
71+
} else if (zipEntry.name.startsWith('word/fonts') && zipEntry.name !== 'word/fonts/') {
72+
const uint8array = await zipEntry.async('uint8array');
73+
this.fonts[zipEntry.name] = uint8array;
7474
}
7575
}
7676

packages/super-editor/src/core/Editor.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,11 @@ export class Editor extends EventEmitter {
145145
this.#createSchema();
146146
this.#createConverter();
147147
this.#initMedia();
148-
this.#initFonts();
149-
150148

149+
if (!this.options.isHeadless) {
150+
this.#initFonts();
151+
}
152+
151153
this.on('beforeCreate', this.options.onBeforeCreate);
152154
this.emit('beforeCreate', { editor: this });
153155
this.on('contentError', this.options.onContentError);

packages/super-editor/src/core/super-converter/SuperConverter.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,11 @@ class SuperConverter {
261261
const filePath = elements.find((el) => el.attributes.Id === font.attributes['r:id'])?.attributes?.Target;
262262
if (!filePath) return;
263263

264-
const ttfBuffer = deobfuscateFont(this.fonts[`word/${filePath}`], font.attributes['w:fontKey']);
264+
const fontUint8Array = this.fonts[`word/${filePath}`];
265+
const fontBuffer = fontUint8Array?.buffer;
266+
if (!fontBuffer) return;
267+
268+
const ttfBuffer = deobfuscateFont(fontBuffer, font.attributes['w:fontKey']);
265269
if (!ttfBuffer) return;
266270

267271
// Convert to a blob and inject @font-face

0 commit comments

Comments
 (0)