Fix 'print to pdf' on Mac with a cid font (bug 1961423)

This commit is contained in:
Calixte Denizet 2025-04-24 19:22:51 +02:00
parent de2a44a558
commit 785991a97c
2 changed files with 7 additions and 3 deletions

View File

@ -1769,12 +1769,16 @@ class CFFCompiler {
if (isCIDFont) { if (isCIDFont) {
// In a CID font, the charset is a mapping of CIDs not SIDs so just // In a CID font, the charset is a mapping of CIDs not SIDs so just
// create an identity mapping. // 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([ out = new Uint8Array([
2, // format 2, // format
0, // first CID upper byte 0, // first CID upper byte
0, // first CID lower byte 0, // first CID lower byte
(numGlyphsLessNotDef >> 8) & 0xff, (nLeft >> 8) & 0xff,
numGlyphsLessNotDef & 0xff, nLeft & 0xff,
]); ]);
} else { } else {
const length = 1 + numGlyphsLessNotDef * 2; const length = 1 + numGlyphsLessNotDef * 2;

View File

@ -481,7 +481,7 @@ describe("CFFCompiler", function () {
0, // cid (high) 0, // cid (high)
0, // cid (low) 0, // cid (low)
0, // nLeft (high) 0, // nLeft (high)
numGlyphs - 1, // nLeft (low) numGlyphs - 2, // nLeft (low)
]); ]);
}); });