Compare commits

..

No commits in common. "4b1875c8c08a5e634690ae9f6a4b3357a53c0b39" and "2f7d163dfdf40225479d1cc8f6d8ebd9e5273ca6" have entirely different histories.

5 changed files with 23 additions and 30 deletions

View File

@ -707,18 +707,10 @@ class Page {
// Ensure that the structTree will contain the page's annotations.
await this._parsedAnnotations;
try {
const structTree = await this.pdfManager.ensure(
this,
"_parseStructTree",
[structTreeRoot]
);
const data = await this.pdfManager.ensure(structTree, "serializable");
return data;
} catch (ex) {
warn(`getStructTree: "${ex}".`);
return null;
}
const structTree = await this.pdfManager.ensure(this, "_parseStructTree", [
structTreeRoot,
]);
return this.pdfManager.ensure(structTree, "serializable");
}
/**

View File

@ -745,9 +745,12 @@ class Commands {
add(cmd, args) {
if (args) {
const { currentTransform } = this;
const [a, b, c, d, e, f] = this.currentTransform;
for (let i = 0, ii = args.length; i < ii; i += 2) {
Util.applyTransform(args, currentTransform, i);
const x = args[i];
const y = args[i + 1];
args[i] = a * x + c * y + e;
args[i + 1] = b * x + d * y + f;
}
this.cmds.push(`${cmd}${args.join(" ")}`);
} else {

View File

@ -524,11 +524,11 @@ addState(
switch (buffer[k++]) {
case DrawOPS.moveTo:
case DrawOPS.lineTo:
Util.applyTransform(buffer, transform, k);
Util.applyTransform(buffer.subarray(k), transform);
k += 2;
break;
case DrawOPS.curveTo:
Util.applyTransformToBezier(buffer, transform, k);
Util.applyTransformToBezier(buffer.subarray(k), transform);
k += 6;
break;
}

View File

@ -757,10 +757,7 @@ class StructTreePage {
const parent = dict.get("P");
if (
!(parent instanceof Dict) ||
isName(parent.get("Type"), "StructTreeRoot")
) {
if (!parent || isName(parent.get("Type"), "StructTreeRoot")) {
if (!this.addTopLevelNode(dict, element)) {
map.delete(dict);
}

View File

@ -730,14 +730,15 @@ class Util {
}
// For 2d affine transforms
static applyTransform(p, m, pos = 0) {
const p0 = p[pos];
const p1 = p[pos + 1];
p[pos] = p0 * m[0] + p1 * m[2] + m[4];
p[pos + 1] = p0 * m[1] + p1 * m[3] + m[5];
static applyTransform(p, m) {
const p0 = p[0];
const p1 = p[1];
p[0] = p0 * m[0] + p1 * m[2] + m[4];
p[1] = p0 * m[1] + p1 * m[3] + m[5];
}
static applyTransformToBezier(p, transform, pos = 0) {
// For 2d affine transforms
static applyTransformToBezier(p, transform) {
const m0 = transform[0];
const m1 = transform[1];
const m2 = transform[2];
@ -745,10 +746,10 @@ class Util {
const m4 = transform[4];
const m5 = transform[5];
for (let i = 0; i < 6; i += 2) {
const pI = p[pos + i];
const pI1 = p[pos + i + 1];
p[pos + i] = pI * m0 + pI1 * m2 + m4;
p[pos + i + 1] = pI * m1 + pI1 * m3 + m5;
const pI = p[i];
const pI1 = p[i + 1];
p[i] = pI * m0 + pI1 * m2 + m4;
p[i + 1] = pI * m1 + pI1 * m3 + m5;
}
}