Skip to content

Commit

Permalink
Changes required for pdf.js update to 4.4.168 version
Browse files Browse the repository at this point in the history
  • Loading branch information
ekaterina-chubrick committed Oct 29, 2024
1 parent 795874e commit 9ef5e66
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 16 deletions.
17 changes: 9 additions & 8 deletions src/core/bounding_boxes.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import {

Check failure on line 1 in src/core/bounding_boxes.js

View workflow job for this annotation

GitHub Actions / Lint (lts/*)

Replace `⏎··OPS,·Util,·IDENTITY_MATRIX⏎}·from·'../shared/util.js'` with `·OPS,·Util,·IDENTITY_MATRIX·}·from·"../shared/util.js"`
OPS, Util, IDENTITY_MATRIX

Check failure on line 2 in src/core/bounding_boxes.js

View workflow job for this annotation

GitHub Actions / Lint (lts/*)

Member 'IDENTITY_MATRIX' of the import declaration should be sorted alphabetically
} from '../shared/util';
} from '../shared/util.js';
import {

Check failure on line 4 in src/core/bounding_boxes.js

View workflow job for this annotation

GitHub Actions / Lint (lts/*)

Dependency cycle detected

Check failure on line 4 in src/core/bounding_boxes.js

View workflow job for this annotation

GitHub Actions / Lint (lts/*)

Replace `⏎··StateManager,⏎··TextState⏎` with `·StateManager,·TextState·`
StateManager,
TextState
} from "./evaluator";
import {isDict} from "./primitives";
} from "./evaluator.js";
import {isDict} from "./primitives.js";

Check failure on line 8 in src/core/bounding_boxes.js

View workflow job for this annotation

GitHub Actions / Lint (lts/*)

Replace `isDict` with `·isDict·`

var BoundingBoxesCalculator = (function PartialEvaluatorClosure() {

Check failure on line 10 in src/core/bounding_boxes.js

View workflow job for this annotation

GitHub Actions / Lint (lts/*)

Unexpected var, use let or const instead

Check failure on line 10 in src/core/bounding_boxes.js

View workflow job for this annotation

GitHub Actions / Lint (lts/*)

Exporting mutable 'var' binding, use 'const' instead
function BoundingBoxesCalculator(ignoreCalculations) {

Check failure on line 11 in src/core/bounding_boxes.js

View workflow job for this annotation

GitHub Actions / Lint (lts/*)

'BoundingBoxesCalculator' is already declared in the upper scope on line 10 column 5
console.log('HELOOOOOOOOOOOOOOOOOOOOOOOOOOO');

Check failure on line 12 in src/core/bounding_boxes.js

View workflow job for this annotation

GitHub Actions / Lint (lts/*)

Replace `'HELOOOOOOOOOOOOOOOOOOOOOOOOOOO'` with `"HELOOOOOOOOOOOOOOOOOOOOOOOOOOO"`
this.textStateManager = new StateManager(new TextState());
this.graphicsStateManager = new StateManager(new GraphicsState());
this.clipping = false;
Expand Down Expand Up @@ -59,11 +60,11 @@ var BoundingBoxesCalculator = (function PartialEvaluatorClosure() {
[tx0, ty0] = Util.applyTransform([0, descent + rise], this.textStateManager.state.textMatrix);
//Calculate transformed height and shift to place whole glyph inside of bbox
shift = [tx0 - this.textStateManager.state.textMatrix[4], ty0 - this.textStateManager.state.textMatrix[5]];
height = Util.applyTransform([0, ascent - descent], this.textStateManager.state.textMatrix);
height = Util.applyTransform([0, ascent - descent], this.textStateManager.state.textMatrix);
} else {
[tx0, ty0] = Util.applyTransform([-this.textStateManager.state.fontSize / 2, rise], this.textStateManager.state.textMatrix);
shift = [tx0 - this.textStateManager.state.textMatrix[4], ty0 - this.textStateManager.state.textMatrix[5]];
height = Util.applyTransform([ascent - descent, 0], this.textStateManager.state.textMatrix);
height = Util.applyTransform([ascent - descent, 0], this.textStateManager.state.textMatrix);
}
height[0] -= this.textStateManager.state.textMatrix[4];
height[1] -= this.textStateManager.state.textMatrix[5];
Expand Down Expand Up @@ -713,7 +714,7 @@ var BoundingBoxStack = (function BoundingBoxStack() {
var NoMCIDBoundingBoxStack = (function NoMCIDBoundingBoxStack() {
function NoMCIDBoundingBoxStack() {
this.boundingBoxesStack = new BoundingBoxStack();
this.contentCounter = null;
this.contentCounter = null;
this.content = {};
this.pointer = {};
}
Expand All @@ -732,7 +733,7 @@ var NoMCIDBoundingBoxStack = (function NoMCIDBoundingBoxStack() {

save: function NoMCIDBoundingBoxStack_save(x, y, w, h) {
if (this.pointer.contentItems) {
this.pointer.contentItems.push({
this.pointer.contentItems.push({
contentItem: { x, y, w, h }
});
this.pointer.final = true;
Expand Down Expand Up @@ -761,7 +762,7 @@ var NoMCIDBoundingBoxStack = (function NoMCIDBoundingBoxStack() {
this.content[this.contentCounter.index] = { parent: this.content, contentItems: [] };
this.pointer = this.content[this.contentCounter.index];
} else if (
this.contentCounter.inMarkedContent !== false && isMC ||
this.contentCounter.inMarkedContent !== false && isMC ||
!!this.contentCounter.inMarkedContent === isMC && !Object.keys(this.pointer).length
) {
delete this.content[this.contentCounter.index].parent;
Expand Down
5 changes: 3 additions & 2 deletions src/core/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -1789,6 +1789,7 @@ class ExtendedCatalog extends Catalog {
}

getTreeElement(el, page, ref) {
console.log(el, page, ref);
//update page for current element
if (isDict(el) && el.has('Pg')) {
let pageRef = el.getRaw('Pg');
Expand All @@ -1808,7 +1809,7 @@ class ExtendedCatalog extends Catalog {
roleName: roleName ? stringToUTF8String(roleName) : null,
children: this.getTreeElement(el.get('K'), page, el.getRaw('K')),
pageIndex: page,
ref: ref
ref: ref instanceof Ref ? ref : null,
};
}

Expand Down Expand Up @@ -1867,7 +1868,7 @@ class ExtendedCatalog extends Catalog {
roleName: roleName ? stringToUTF8String(roleName) : null,
children: [],
pageIndex: page,
ref: ref
ref: ref instanceof Ref ? ref : null
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ import { ImageResizer } from "./image_resizer.js";
import { MurmurHash3_64 } from "../shared/murmurhash3.js";
import { OperatorList } from "./operator_list.js";
import { PDFImage } from "./image.js";
import { BoundingBoxesCalculator } from "./bounding_boxes";
import { BoundingBoxesCalculator } from "./bounding_boxes.js";

const DefaultPartialEvaluatorOptions = Object.freeze({
maxImageSize: -1,
Expand Down
15 changes: 13 additions & 2 deletions src/core/flate_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,19 @@ class FlateStream extends DecodeStream {
try {
const { readable, writable } = new DecompressionStream("deflate");
const writer = writable.getWriter();
writer.write(bytes);
writer.close();
// SHOULD BE FIXED IN FUTURE PDF.JS VERSIONS - START
await writer.ready;

// We can't await writer.write() because it'll block until the reader
// starts which happens few lines below.
writer
.write(bytes)
.then(async () => {
await writer.ready;
await writer.close();
})
.catch(() => {});
// SHOULD BE FIXED IN FUTURE PDF.JS VERSIONS - END

const chunks = [];
let totalLength = 0;
Expand Down
1 change: 1 addition & 0 deletions src/core/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ class WorkerMessageHandler {

function setupDoc(data) {
function onSuccess(doc) {
console.log(doc);
ensureNotTerminated();
handler.send("GetDoc", { pdfInfo: doc });
}
Expand Down
12 changes: 10 additions & 2 deletions src/core/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,16 @@ async function writeStream(stream, buffer, transform) {
try {
const cs = new CompressionStream("deflate");
const writer = cs.writable.getWriter();
writer.write(bytes);
writer.close();
// SHOULD BE FIXED IN FUTURE PDF.JS VERSIONS - START
await writer.ready;
writer
.write(bytes)
.then(async () => {
await writer.ready;
await writer.close();
})
.catch(() => {});
// SHOULD BE FIXED IN FUTURE PDF.JS VERSIONS - END

// Response::text doesn't return the correct data.
const buf = await new Response(cs.readable).arrayBuffer();
Expand Down
1 change: 1 addition & 0 deletions src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1958,6 +1958,7 @@ class LoopbackPort {
#deferred = Promise.resolve();

postMessage(obj, transfer) {
console.log(obj);
const event = {
data: structuredClone(obj, transfer ? { transfer } : null),
};
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.16.105",
"version": "4.4.168",
"build": 305,
"commit": "eaaa8b4"
}

0 comments on commit 9ef5e66

Please sign in to comment.