Skip to content

Commit 7b9b474

Browse files
authored
Fix: custom fonts support on the Browser (#2898)
1 parent e80a50d commit 7b9b474

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/file/fonts/obfuscate-ttf-to-odttf.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const obfuscatedStartOffset = 0;
22
const obfuscatedEndOffset = 32;
33
const guidSize = 32;
44

5-
export const obfuscate = (buf: Buffer, fontKey: string): Buffer => {
5+
export const obfuscate = (buf: Uint8Array, fontKey: string): Uint8Array => {
66
const guid = fontKey.replace(/-/g, "");
77
if (guid.length !== guidSize) {
88
throw new Error(`Error: Cannot extract GUID from font filename: ${fontKey}`);
@@ -17,6 +17,9 @@ export const obfuscate = (buf: Buffer, fontKey: string): Buffer => {
1717
// eslint-disable-next-line no-bitwise
1818
const obfuscatedBytes = bytesToObfuscate.map((byte, i) => byte ^ hexNumbers[i % hexNumbers.length]);
1919

20-
const out = Buffer.concat([buf.slice(0, obfuscatedStartOffset), obfuscatedBytes, buf.slice(obfuscatedEndOffset)]);
20+
const out = new Uint8Array(obfuscatedStartOffset + obfuscatedBytes.length + Math.max(0, buf.length - obfuscatedEndOffset));
21+
out.set(buf.slice(0, obfuscatedStartOffset));
22+
out.set(obfuscatedBytes, obfuscatedStartOffset);
23+
out.set(buf.slice(obfuscatedEndOffset), obfuscatedStartOffset + obfuscatedBytes.length);
2124
return out;
2225
};

0 commit comments

Comments
 (0)