From 785991a97cba7f006efc27e82f64cf8bc0bbad19 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Thu, 24 Apr 2025 19:22:51 +0200 Subject: [PATCH] Fix 'print to pdf' on Mac with a cid font (bug 1961423) --- src/core/cff_parser.js | 8 ++++++-- test/unit/cff_parser_spec.js | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/core/cff_parser.js b/src/core/cff_parser.js index cdb662240..00db63f97 100644 --- a/src/core/cff_parser.js +++ b/src/core/cff_parser.js @@ -1769,12 +1769,16 @@ class CFFCompiler { if (isCIDFont) { // In a CID font, the charset is a mapping of CIDs not SIDs so just // create an identity mapping. + // nLeft: Glyphs left in range (excluding first) (see the CFF specs). + // Having a wrong value for nLeft induces a print issue on MacOS (see + // https://bugzilla.mozilla.org/1961423). + const nLeft = numGlyphsLessNotDef - 1; out = new Uint8Array([ 2, // format 0, // first CID upper byte 0, // first CID lower byte - (numGlyphsLessNotDef >> 8) & 0xff, - numGlyphsLessNotDef & 0xff, + (nLeft >> 8) & 0xff, + nLeft & 0xff, ]); } else { const length = 1 + numGlyphsLessNotDef * 2; diff --git a/test/unit/cff_parser_spec.js b/test/unit/cff_parser_spec.js index e7b7410a5..c15e4acf5 100644 --- a/test/unit/cff_parser_spec.js +++ b/test/unit/cff_parser_spec.js @@ -481,7 +481,7 @@ describe("CFFCompiler", function () { 0, // cid (high) 0, // cid (low) 0, // nLeft (high) - numGlyphs - 1, // nLeft (low) + numGlyphs - 2, // nLeft (low) ]); });