From 94f8934d05a6e41ca649876d46f99ec3f0aaf865 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 9 Apr 2026 22:55:38 +0200 Subject: [PATCH 1/2] Move some TrueType header comments to the correct lines This is most likely fallout from the introduction of Prettier. --- src/core/fonts.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/core/fonts.js b/src/core/fonts.js index b2c72caa4..a55163d45 100644 --- a/src/core/fonts.js +++ b/src/core/fonts.js @@ -876,8 +876,8 @@ function createOS2Table(properties, charstrings, override) { string16(properties.capHeight) + // sCapHeight string16(0) + // usDefaultChar string16(firstCharIndex || properties.firstChar) + // usBreakChar - "\x00\x03" - ); // usMaxContext + "\x00\x03" // usMaxContext + ); } function createPostTable(properties) { @@ -891,8 +891,8 @@ function createPostTable(properties) { "\x00\x00\x00\x00" + // minMemType42 "\x00\x00\x00\x00" + // maxMemType42 "\x00\x00\x00\x00" + // minMemType1 - "\x00\x00\x00\x00" - ); // maxMemType1 + "\x00\x00\x00\x00" // maxMemType1 + ); } function createPostscriptName(name) { @@ -3281,8 +3281,8 @@ class Font { "\x00\x11" + // lowestRecPPEM "\x00\x00" + // fontDirectionHint "\x00\x00" + // indexToLocFormat - "\x00\x00" - ); // glyphDataFormat + "\x00\x00" // glyphDataFormat + ); // Horizontal header builder.addTable( @@ -3303,8 +3303,8 @@ class Font { "\x00\x00" + // -reserved- "\x00\x00" + // -reserved- "\x00\x00" + // metricDataFormat - string16(numGlyphs) - ); // Number of HMetrics + string16(numGlyphs) // Number of HMetrics + ); // Horizontal metrics builder.addTable( @@ -3336,8 +3336,9 @@ class Font { // Maximum profile builder.addTable( "maxp", - "\x00\x00\x50\x00" + string16(numGlyphs) // Version number - ); // Num of glyphs + "\x00\x00\x50\x00" + // Version number + string16(numGlyphs) // Num of glyphs + ); // Naming tables builder.addTable("name", createNameTable(fontName)); From a69b9ad033cfb97e8d3a110c8337606a283e1366 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 9 Apr 2026 23:07:30 +0200 Subject: [PATCH 2/2] Ensure that the built "hmtx" font table has valid widths (PR 21072 follow-up) With the changes in PR 21072 the `string16` helper is no longer being used when building the "hmtx" table, which accidentally removed the development mode assert. --- src/core/fonts.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/core/fonts.js b/src/core/fonts.js index a55163d45..30f3d6b32 100644 --- a/src/core/fonts.js +++ b/src/core/fonts.js @@ -332,6 +332,15 @@ function safeString16(value) { return String.fromCharCode((value >> 8) & 0xff, value & 0xff); } +function ensureInt16(v) { + if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) { + assert( + typeof v === "number" && Math.abs(v) < 2 ** 16, + `ensureInt16: Unexpected input "${v}".` + ); + } +} + function isTrueTypeFile(file) { const header = file.peekBytes(4); return ( @@ -3324,6 +3333,7 @@ class Font { } else if (cffWidths) { width = Math.ceil(cffWidths[i] || 0); } + ensureInt16(width); data[pos++] = (width >> 8) & 0xff; data[pos++] = width & 0xff; // Use lsb=0, skip redundant assignment.