From 0c789ecc9701e7cd077c47f11da6f89bc7ebb730 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Mon, 13 Apr 2026 11:52:43 +0200 Subject: [PATCH] Use a TypedArray when building the "maxp" TrueType table --- src/core/fonts.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/core/fonts.js b/src/core/fonts.js index 5cc6324be..ec1f83ca4 100644 --- a/src/core/fonts.js +++ b/src/core/fonts.js @@ -327,6 +327,11 @@ function safeString16(value) { return String.fromCharCode((value >> 8) & 0xff, value & 0xff); } +function setArray(data, pos, arr) { + data.set(arr, pos); + return pos + arr.length; +} + function setInt16(view, pos, val) { if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) { assert( @@ -3338,8 +3343,15 @@ class Font { // Maximum profile builder.addTable( "maxp", - "\x00\x00\x50\x00" + // Version number - string16(numGlyphs) // Num of glyphs + (function fontTableMaxp() { + const data = new Uint8Array(6), + view = new DataView(data.buffer); + + setArray(data, 0, [0x00, 0x00, 0x50, 0x00]); // Version number + setInt16(view, 4, numGlyphs); // Num of glyphs + + return data; + })() ); // Naming tables