Merge pull request #15306 from Snuffleupagus/Type3-only-Path2D
Only compile Type3 glyphs when `Path2D` is supported
This commit is contained in:
commit
f212341d01
@ -54,8 +54,14 @@ const EXECUTION_TIME = 15; // ms
|
|||||||
// Defines the number of steps before checking the execution time.
|
// Defines the number of steps before checking the execution time.
|
||||||
const EXECUTION_STEPS = 10;
|
const EXECUTION_STEPS = 10;
|
||||||
|
|
||||||
const COMPILE_TYPE3_GLYPHS = true;
|
// To disable Type3 compilation, set the value to `-1`.
|
||||||
const MAX_SIZE_TO_COMPILE = 1000;
|
const MAX_SIZE_TO_COMPILE =
|
||||||
|
typeof PDFJSDev !== "undefined" &&
|
||||||
|
PDFJSDev.test("GENERIC") &&
|
||||||
|
isNodeJS &&
|
||||||
|
typeof Path2D === "undefined"
|
||||||
|
? -1
|
||||||
|
: 1000;
|
||||||
|
|
||||||
const FULL_CHUNK_HEIGHT = 16;
|
const FULL_CHUNK_HEIGHT = 16;
|
||||||
|
|
||||||
@ -294,11 +300,7 @@ function drawImageAtIntegerCoords(
|
|||||||
|
|
||||||
function compileType3Glyph(imgData) {
|
function compileType3Glyph(imgData) {
|
||||||
const { width, height } = imgData;
|
const { width, height } = imgData;
|
||||||
if (
|
if (width > MAX_SIZE_TO_COMPILE || height > MAX_SIZE_TO_COMPILE) {
|
||||||
!COMPILE_TYPE3_GLYPHS ||
|
|
||||||
width > MAX_SIZE_TO_COMPILE ||
|
|
||||||
height > MAX_SIZE_TO_COMPILE
|
|
||||||
) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -404,12 +406,7 @@ function compileType3Glyph(imgData) {
|
|||||||
|
|
||||||
// building outlines
|
// building outlines
|
||||||
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]);
|
||||||
let path, outlines, coords;
|
const path = new Path2D();
|
||||||
if (!isNodeJS) {
|
|
||||||
path = new Path2D();
|
|
||||||
} else {
|
|
||||||
outlines = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; count && i <= height; i++) {
|
for (i = 0; count && i <= height; i++) {
|
||||||
let p = i * width1;
|
let p = i * width1;
|
||||||
@ -420,12 +417,7 @@ function compileType3Glyph(imgData) {
|
|||||||
if (p === end) {
|
if (p === end) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
path.moveTo(p % width1, i);
|
||||||
if (path) {
|
|
||||||
path.moveTo(p % width1, i);
|
|
||||||
} else {
|
|
||||||
coords = [p % width1, i];
|
|
||||||
}
|
|
||||||
|
|
||||||
const p0 = p;
|
const p0 = p;
|
||||||
let type = points[p];
|
let type = points[p];
|
||||||
@ -448,21 +440,12 @@ 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);
|
||||||
if (path) {
|
|
||||||
path.lineTo(p % width1, (p / width1) | 0);
|
|
||||||
} else {
|
|
||||||
coords.push(p % width1, (p / width1) | 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!points[p]) {
|
if (!points[p]) {
|
||||||
--count;
|
--count;
|
||||||
}
|
}
|
||||||
} while (p0 !== p);
|
} while (p0 !== p);
|
||||||
|
|
||||||
if (!path) {
|
|
||||||
outlines.push(coords);
|
|
||||||
}
|
|
||||||
--i;
|
--i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -475,18 +458,7 @@ function compileType3Glyph(imgData) {
|
|||||||
// the path shall be painted in [0..1]x[0..1] space
|
// the path shall be painted in [0..1]x[0..1] space
|
||||||
c.scale(1 / width, -1 / height);
|
c.scale(1 / width, -1 / height);
|
||||||
c.translate(0, -height);
|
c.translate(0, -height);
|
||||||
if (path) {
|
c.fill(path);
|
||||||
c.fill(path);
|
|
||||||
} else {
|
|
||||||
c.beginPath();
|
|
||||||
for (const o of outlines) {
|
|
||||||
c.moveTo(o[0], o[1]);
|
|
||||||
for (let l = 2, ll = o.length; l < ll; l += 2) {
|
|
||||||
c.lineTo(o[l], o[l + 1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
c.fill();
|
|
||||||
}
|
|
||||||
c.beginPath();
|
c.beginPath();
|
||||||
c.restore();
|
c.restore();
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user