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

Pre-apply the transform when building the Path2D objects for Type3-fonts

Rather than updating the transform every time that we're painting a Type3-glyph, we can instead just compute the "final" coordinates during building of the `Path2D` objects.
This commit is contained in:
Jonas Jenwald 2025-03-28 13:26:41 +01:00
parent 31ec357282
commit 852b7e407a

View file

@ -406,6 +406,11 @@ function compileType3Glyph(imgData) {
const steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
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++) {
let p = i * width1;
const end = p + width;
@ -415,7 +420,9 @@ function compileType3Glyph(imgData) {
if (p === end) {
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;
let type = points[p];
@ -438,7 +445,9 @@ function compileType3Glyph(imgData) {
// set new type for "future hit"
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]) {
--count;
@ -451,14 +460,11 @@ function compileType3Glyph(imgData) {
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();
const drawOutline = function (ctx) {
ctx.save();
ctx.fill(path);
ctx.beginPath();
ctx.restore();
};
return drawOutline;