Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/core/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,14 @@ function getQuadPoints(dict, rect) {
function getTransformMatrix(rect, bbox, matrix) {
// 12.5.5: Algorithm: Appearance streams
const minMax = F32_BBOX_INIT.slice();
Util.axialAlignedBoundingBox(bbox, matrix, minMax);
Util.transformedRectBoundingBox(
bbox[0],
bbox[1],
bbox[2],
bbox[3],
matrix,
minMax
);
const [minX, minY, maxX, maxY] = minMax;
if (minX === maxX || minY === maxY) {
// From real-life file, bbox was [0, 0, 0, 0]. In this case,
Expand Down
6 changes: 6 additions & 0 deletions src/core/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,12 @@ class Page {
RESOURCES_KEYS_OPERATOR_LIST
);
const opList = new OperatorList(intent, sink);
if (
intent & RenderingIntentFlag.DISPLAY &&
!(intent & RenderingIntentFlag.OPLIST)
) {
opList.enableBBoxes(this.view);
}
handler.send("StartRenderPage", {
transparency: partialEvaluator.hasBlendModes(
resources,
Expand Down
1 change: 1 addition & 0 deletions src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,7 @@ class PartialEvaluator {
}

state.font = translated.font;
operatorList.addFont(translated.loadedName, translated.font);
translated.send(this.handler);
return translated.loadedName;
}
Expand Down
35 changes: 33 additions & 2 deletions src/core/operator_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
Util,
warn,
} from "../shared/util.js";
import { OperatorListBBoxTracker } from "./operator_list_bbox_tracker.js";

function addState(parentState, pattern, checkFn, iterateFn, processFn) {
let state = parentState;
Expand Down Expand Up @@ -522,7 +523,14 @@ addState(

if (minMax) {
const newBBox = F32_BBOX_INIT.slice();
Util.axialAlignedBoundingBox(minMax, transform, newBBox);
Util.transformedRectBoundingBox(
minMax[0],
minMax[1],
minMax[2],
minMax[3],
transform,
newBBox
);
minMax.set(newBBox);
for (let k = 0, kk = buffer.length; k < kk;) {
switch (buffer[k++]) {
Expand Down Expand Up @@ -669,6 +677,8 @@ class OperatorList {
this.dependencies = new Set();
this.weight = 0;
this._resolved = streamSink ? null : Promise.resolve();
this._bboxTracker = null;
this._bboxFonts = new Map();
}

static setOptions({ isOffscreenCanvasSupported }) {
Expand All @@ -683,6 +693,14 @@ class OperatorList {
return this._resolved || this._streamSink.ready;
}

enableBBoxes(pageBBox) {
this._bboxTracker = new OperatorListBBoxTracker(pageBBox, this._bboxFonts);
}

addFont(loadedName, font) {
this._bboxFonts.set(loadedName, font);
}

addOp(fn, args) {
this.optimizer.push(fn, args);
this.weight++;
Expand Down Expand Up @@ -740,6 +758,9 @@ class OperatorList {
for (const dependency of opList.dependencies) {
this.dependencies.add(dependency);
}
for (const [loadedName, font] of opList._bboxFonts) {
this.addFont(loadedName, font);
}
for (let i = 0, ii = opList.length; i < ii; i++) {
this.addOp(opList.fnArray[i], opList.argsArray[i]);
}
Expand Down Expand Up @@ -793,6 +814,15 @@ class OperatorList {

flush(lastChunk = false, separateAnnots = null) {
this.optimizer.flush();
const transfers = this._transfers;
let bboxes = null;
if (this._bboxTracker) {
this._bboxTracker.process(this.fnArray, this.argsArray);
if (lastChunk) {
bboxes = this._bboxTracker.finish();
transfers.push(bboxes.buffer);
}
}

this._streamSink.enqueue(
{
Expand All @@ -801,9 +831,10 @@ class OperatorList {
lastChunk,
separateAnnots,
length: this.length,
bboxes,
},
1,
this._transfers
transfers
);

this.dependencies.clear();
Expand Down
Loading
Loading