1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 06:38:07 +02:00

Merge pull request #19731 from Snuffleupagus/Type3-Path2D-pre-transform

Pre-apply the transform when building the `Path2D` objects for Type3-fonts
This commit is contained in:
Jonas Jenwald 2025-03-28 16:29:18 +01:00 committed by GitHub
commit 34136d7775
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 26 additions and 21 deletions

View file

@ -308,13 +308,13 @@ function compileType3Glyph(imgData) {
]); ]);
const width1 = width + 1; const width1 = width + 1;
let points = new Uint8Array(width1 * (height + 1)); const points = new Uint8Array(width1 * (height + 1));
let i, j, j0; let i, j, j0;
// decodes bit-packed mask data // decodes bit-packed mask data
const lineSize = (width + 7) & ~7; const lineSize = (width + 7) & ~7;
let data = new Uint8Array(lineSize * height), const data = new Uint8Array(lineSize * height);
pos = 0; let pos = 0;
for (const elem of imgData.data) { for (const elem of imgData.data) {
let mask = 128; let mask = 128;
while (mask > 0) { while (mask > 0) {
@ -406,6 +406,11 @@ function compileType3Glyph(imgData) {
const steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]); const steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
const path = new Path2D(); const path = new Path2D();
// the path shall be painted in [0..1]x[0..1] space
const { a, b, c, d, e, f } = new DOMMatrix()
.scaleSelf(1 / width, -1 / height)
.translateSelf(0, -height);
for (i = 0; count && i <= height; i++) { for (i = 0; count && i <= height; i++) {
let p = i * width1; let p = i * width1;
const end = p + width; const end = p + width;
@ -415,7 +420,9 @@ function compileType3Glyph(imgData) {
if (p === end) { if (p === end) {
continue; continue;
} }
path.moveTo(p % width1, i); let x = p % width1;
let y = i;
path.moveTo(a * x + c * y + e, b * x + d * y + f);
const p0 = p; const p0 = p;
let type = points[p]; let type = points[p];
@ -438,7 +445,9 @@ function compileType3Glyph(imgData) {
// set new type for "future hit" // set new type for "future hit"
points[p] &= (type >> 2) | (type << 2); points[p] &= (type >> 2) | (type << 2);
} }
path.lineTo(p % width1, (p / width1) | 0); x = p % width1;
y = (p / width1) | 0;
path.lineTo(a * x + c * y + e, b * x + d * y + f);
if (!points[p]) { if (!points[p]) {
--count; --count;
@ -447,21 +456,7 @@ function compileType3Glyph(imgData) {
--i; --i;
} }
// Immediately release the, potentially large, `Uint8Array`s after parsing. return path;
data = null;
points = null;
const drawOutline = function (c) {
c.save();
// the path shall be painted in [0..1]x[0..1] space
c.scale(1 / width, -1 / height);
c.translate(0, -height);
c.fill(path);
c.beginPath();
c.restore();
};
return drawOutline;
} }
class CanvasExtraState { class CanvasExtraState {
@ -2720,7 +2715,7 @@ class CanvasGraphics {
} }
if (glyph.compiled) { if (glyph.compiled) {
glyph.compiled(ctx); ctx.fill(glyph.compiled);
return; return;
} }
} }

View file

@ -0,0 +1 @@
https://bugzilla.mozilla.org/attachment.cgi?id=9254990

View file

@ -2834,6 +2834,15 @@
"rounds": 1, "rounds": 1,
"type": "eq" "type": "eq"
}, },
{
"id": "bug810214",
"file": "pdfs/bug810214.pdf",
"md5": "2b7243178f5dd5fd3edc7b6649e4bdf3",
"link": true,
"rounds": 1,
"lastPage": 1,
"type": "eq"
},
{ {
"id": "issue13372", "id": "issue13372",
"file": "pdfs/issue13372.pdf", "file": "pdfs/issue13372.pdf",