Skip to content

Commit 9ef5e66

Browse files
Changes required for pdf.js update to 4.4.168 version
1 parent 795874e commit 9ef5e66

File tree

8 files changed

+39
-16
lines changed

8 files changed

+39
-16
lines changed

src/core/bounding_boxes.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import {
22
OPS, Util, IDENTITY_MATRIX
3-
} from '../shared/util';
3+
} from '../shared/util.js';
44
import {
55
StateManager,
66
TextState
7-
} from "./evaluator";
8-
import {isDict} from "./primitives";
7+
} from "./evaluator.js";
8+
import {isDict} from "./primitives.js";
99

1010
var BoundingBoxesCalculator = (function PartialEvaluatorClosure() {
1111
function BoundingBoxesCalculator(ignoreCalculations) {
12+
console.log('HELOOOOOOOOOOOOOOOOOOOOOOOOOOO');
1213
this.textStateManager = new StateManager(new TextState());
1314
this.graphicsStateManager = new StateManager(new GraphicsState());
1415
this.clipping = false;
@@ -59,11 +60,11 @@ var BoundingBoxesCalculator = (function PartialEvaluatorClosure() {
5960
[tx0, ty0] = Util.applyTransform([0, descent + rise], this.textStateManager.state.textMatrix);
6061
//Calculate transformed height and shift to place whole glyph inside of bbox
6162
shift = [tx0 - this.textStateManager.state.textMatrix[4], ty0 - this.textStateManager.state.textMatrix[5]];
62-
height = Util.applyTransform([0, ascent - descent], this.textStateManager.state.textMatrix);
63+
height = Util.applyTransform([0, ascent - descent], this.textStateManager.state.textMatrix);
6364
} else {
6465
[tx0, ty0] = Util.applyTransform([-this.textStateManager.state.fontSize / 2, rise], this.textStateManager.state.textMatrix);
6566
shift = [tx0 - this.textStateManager.state.textMatrix[4], ty0 - this.textStateManager.state.textMatrix[5]];
66-
height = Util.applyTransform([ascent - descent, 0], this.textStateManager.state.textMatrix);
67+
height = Util.applyTransform([ascent - descent, 0], this.textStateManager.state.textMatrix);
6768
}
6869
height[0] -= this.textStateManager.state.textMatrix[4];
6970
height[1] -= this.textStateManager.state.textMatrix[5];
@@ -713,7 +714,7 @@ var BoundingBoxStack = (function BoundingBoxStack() {
713714
var NoMCIDBoundingBoxStack = (function NoMCIDBoundingBoxStack() {
714715
function NoMCIDBoundingBoxStack() {
715716
this.boundingBoxesStack = new BoundingBoxStack();
716-
this.contentCounter = null;
717+
this.contentCounter = null;
717718
this.content = {};
718719
this.pointer = {};
719720
}
@@ -732,7 +733,7 @@ var NoMCIDBoundingBoxStack = (function NoMCIDBoundingBoxStack() {
732733

733734
save: function NoMCIDBoundingBoxStack_save(x, y, w, h) {
734735
if (this.pointer.contentItems) {
735-
this.pointer.contentItems.push({
736+
this.pointer.contentItems.push({
736737
contentItem: { x, y, w, h }
737738
});
738739
this.pointer.final = true;
@@ -761,7 +762,7 @@ var NoMCIDBoundingBoxStack = (function NoMCIDBoundingBoxStack() {
761762
this.content[this.contentCounter.index] = { parent: this.content, contentItems: [] };
762763
this.pointer = this.content[this.contentCounter.index];
763764
} else if (
764-
this.contentCounter.inMarkedContent !== false && isMC ||
765+
this.contentCounter.inMarkedContent !== false && isMC ||
765766
!!this.contentCounter.inMarkedContent === isMC && !Object.keys(this.pointer).length
766767
) {
767768
delete this.content[this.contentCounter.index].parent;

src/core/catalog.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,6 +1789,7 @@ class ExtendedCatalog extends Catalog {
17891789
}
17901790

17911791
getTreeElement(el, page, ref) {
1792+
console.log(el, page, ref);
17921793
//update page for current element
17931794
if (isDict(el) && el.has('Pg')) {
17941795
let pageRef = el.getRaw('Pg');
@@ -1808,7 +1809,7 @@ class ExtendedCatalog extends Catalog {
18081809
roleName: roleName ? stringToUTF8String(roleName) : null,
18091810
children: this.getTreeElement(el.get('K'), page, el.getRaw('K')),
18101811
pageIndex: page,
1811-
ref: ref
1812+
ref: ref instanceof Ref ? ref : null,
18121813
};
18131814
}
18141815

@@ -1867,7 +1868,7 @@ class ExtendedCatalog extends Catalog {
18671868
roleName: roleName ? stringToUTF8String(roleName) : null,
18681869
children: [],
18691870
pageIndex: page,
1870-
ref: ref
1871+
ref: ref instanceof Ref ? ref : null
18711872
};
18721873
}
18731874
}

src/core/evaluator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ import { ImageResizer } from "./image_resizer.js";
7878
import { MurmurHash3_64 } from "../shared/murmurhash3.js";
7979
import { OperatorList } from "./operator_list.js";
8080
import { PDFImage } from "./image.js";
81-
import { BoundingBoxesCalculator } from "./bounding_boxes";
81+
import { BoundingBoxesCalculator } from "./bounding_boxes.js";
8282

8383
const DefaultPartialEvaluatorOptions = Object.freeze({
8484
maxImageSize: -1,

src/core/flate_stream.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,19 @@ class FlateStream extends DecodeStream {
161161
try {
162162
const { readable, writable } = new DecompressionStream("deflate");
163163
const writer = writable.getWriter();
164-
writer.write(bytes);
165-
writer.close();
164+
// SHOULD BE FIXED IN FUTURE PDF.JS VERSIONS - START
165+
await writer.ready;
166+
167+
// We can't await writer.write() because it'll block until the reader
168+
// starts which happens few lines below.
169+
writer
170+
.write(bytes)
171+
.then(async () => {
172+
await writer.ready;
173+
await writer.close();
174+
})
175+
.catch(() => {});
176+
// SHOULD BE FIXED IN FUTURE PDF.JS VERSIONS - END
166177

167178
const chunks = [];
168179
let totalLength = 0;

src/core/worker.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ class WorkerMessageHandler {
332332

333333
function setupDoc(data) {
334334
function onSuccess(doc) {
335+
console.log(doc);
335336
ensureNotTerminated();
336337
handler.send("GetDoc", { pdfInfo: doc });
337338
}

src/core/writer.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,16 @@ async function writeStream(stream, buffer, transform) {
7171
try {
7272
const cs = new CompressionStream("deflate");
7373
const writer = cs.writable.getWriter();
74-
writer.write(bytes);
75-
writer.close();
74+
// SHOULD BE FIXED IN FUTURE PDF.JS VERSIONS - START
75+
await writer.ready;
76+
writer
77+
.write(bytes)
78+
.then(async () => {
79+
await writer.ready;
80+
await writer.close();
81+
})
82+
.catch(() => {});
83+
// SHOULD BE FIXED IN FUTURE PDF.JS VERSIONS - END
7684

7785
// Response::text doesn't return the correct data.
7886
const buf = await new Response(cs.readable).arrayBuffer();

src/display/api.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,6 +1958,7 @@ class LoopbackPort {
19581958
#deferred = Promise.resolve();
19591959

19601960
postMessage(obj, transfer) {
1961+
console.log(obj);
19611962
const event = {
19621963
data: structuredClone(obj, transfer ? { transfer } : null),
19631964
};

version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "2.16.105",
2+
"version": "4.4.168",
33
"build": 305,
44
"commit": "eaaa8b4"
55
}

0 commit comments

Comments
 (0)