From 623e6d94764bcde883ccab83a4fc5f278df96e00 Mon Sep 17 00:00:00 2001 From: calixteman Date: Sun, 21 Jun 2026 22:18:50 +0200 Subject: [PATCH] Reset alpha before drawing a colored glyph in type 3 font It fixes #21430. --- src/display/canvas.js | 8 ++++++++ test/pdfs/issue21430.pdf.link | 1 + test/test_manifest.json | 10 ++++++++++ 3 files changed, 19 insertions(+) create mode 100644 test/pdfs/issue21430.pdf.link diff --git a/src/display/canvas.js b/src/display/canvas.js index 89af70089..01a9a2f7d 100644 --- a/src/display/canvas.js +++ b/src/display/canvas.js @@ -2965,6 +2965,14 @@ class CanvasGraphics { warn(`Type3 character "${glyph.operatorListId}" is not available.`); } else if (this.contentVisible) { this.save(); + // A d0 (setCharWidth) glyph is colored (see Table 113 in pdf 1.7 specs) + // unlike a d1 glyph painted as a stencil mask with the current fill + // color. The constant alphas (ca/CA) are the opacity of that current + // color, so they must not attenuate a d0 glyph. + if (operatorList.fnArray[0] === OPS.setCharWidth) { + current.fillAlpha = current.strokeAlpha = 1; + ctx.globalAlpha = 1; + } ctx.scale(fontSize, fontSize); ctx.transform(...fontMatrix); this.executeOperatorList(operatorList); diff --git a/test/pdfs/issue21430.pdf.link b/test/pdfs/issue21430.pdf.link new file mode 100644 index 000000000..ed7e4d1af --- /dev/null +++ b/test/pdfs/issue21430.pdf.link @@ -0,0 +1 @@ +https://github.com/user-attachments/files/28821514/xxx.pdf diff --git a/test/test_manifest.json b/test/test_manifest.json index e887360d8..08b6dfdbf 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -14429,5 +14429,15 @@ "type": "eq", "annotations": true, "forms": true + }, + { + "id": "issue21430", + "file": "pdfs/issue21430.pdf", + "md5": "e317f63bdfd6f3d1939a52c983379454", + "rounds": 1, + "link": true, + "firstPage": 1, + "lastPage": 1, + "type": "eq" } ]