Compare commits

..

No commits in common. "6cc37c8415e937b63d21cb13e491b05bbed3fc1a" and "7eef7dfc7820648b36bd083c11d4fae867306e80" have entirely different histories.

4 changed files with 82 additions and 101 deletions

View File

@ -728,6 +728,8 @@ class PartialEvaluator {
/* forceRGBA = */ true,
/* isOffscreenCanvasSupported = */ false
);
operatorList.isOffscreenCanvasSupported =
this.options.isOffscreenCanvasSupported;
operatorList.addImageOps(
OPS.paintInlineImageXObject,
[imgData],
@ -2237,9 +2239,6 @@ class PartialEvaluator {
}
continue;
}
case OPS.setTextMatrix:
operatorList.addOp(fn, [new Float32Array(args)]);
continue;
case OPS.markPoint:
case OPS.markPointProps:
case OPS.beginCompat:

View File

@ -567,12 +567,17 @@ class QueueOptimizer extends NullOptimizer {
iCurr: 0,
fnArray: queue.fnArray,
argsArray: queue.argsArray,
isOffscreenCanvasSupported: OperatorList.isOffscreenCanvasSupported,
isOffscreenCanvasSupported: false,
};
this.match = null;
this.lastProcessed = 0;
}
// eslint-disable-next-line accessor-pairs
set isOffscreenCanvasSupported(value) {
this.context.isOffscreenCanvasSupported = value;
}
_optimize() {
// Process new fnArray item(s) chunk.
const fnArray = this.queue.fnArray;
@ -651,8 +656,6 @@ class OperatorList {
// Close to chunk size.
static CHUNK_SIZE_ABOUT = this.CHUNK_SIZE - 5;
static isOffscreenCanvasSupported = false;
constructor(intent = 0, streamSink) {
this._streamSink = streamSink;
this.fnArray = [];
@ -667,8 +670,9 @@ class OperatorList {
this._resolved = streamSink ? null : Promise.resolve();
}
static setOptions({ isOffscreenCanvasSupported }) {
this.isOffscreenCanvasSupported = isOffscreenCanvasSupported;
// eslint-disable-next-line accessor-pairs
set isOffscreenCanvasSupported(value) {
this.optimizer.isOffscreenCanvasSupported = value;
}
get length() {
@ -787,9 +791,6 @@ class OperatorList {
transfers.push(bbox.buffer);
}
break;
case OPS.setTextMatrix:
transfers.push(argsArray[i][0].buffer);
break;
}
}
return transfers;

View File

@ -25,7 +25,6 @@ import { ImageResizer } from "./image_resizer.js";
import { JpegStream } from "./jpeg_stream.js";
import { JpxImage } from "./jpx.js";
import { MissingDataException } from "./core_utils.js";
import { OperatorList } from "./operator_list.js";
import { PDFDocument } from "./document.js";
import { Stream } from "./stream.js";
@ -75,7 +74,6 @@ class BasePdfManager {
// Initialize image-options once per document.
ImageResizer.setOptions(evaluatorOptions);
JpegStream.setOptions(evaluatorOptions);
OperatorList.setOptions(evaluatorOptions);
const options = { ...evaluatorOptions, handler };
JpxImage.setOptions(options);

View File

@ -17,8 +17,10 @@ import {
DrawOPS,
FeatureTest,
FONT_IDENTITY_MATRIX,
IDENTITY_MATRIX,
ImageKind,
info,
isNodeJS,
OPS,
shadow,
TextRenderingMode,
@ -123,47 +125,47 @@ function mirrorContextOperations(ctx, destCtx) {
delete ctx._removeMirroring;
};
ctx.save = function () {
ctx.save = function ctxSave() {
destCtx.save();
this.__originalSave();
};
ctx.restore = function () {
ctx.restore = function ctxRestore() {
destCtx.restore();
this.__originalRestore();
};
ctx.translate = function (x, y) {
ctx.translate = function ctxTranslate(x, y) {
destCtx.translate(x, y);
this.__originalTranslate(x, y);
};
ctx.scale = function (x, y) {
ctx.scale = function ctxScale(x, y) {
destCtx.scale(x, y);
this.__originalScale(x, y);
};
ctx.transform = function (a, b, c, d, e, f) {
ctx.transform = function ctxTransform(a, b, c, d, e, f) {
destCtx.transform(a, b, c, d, e, f);
this.__originalTransform(a, b, c, d, e, f);
};
ctx.setTransform = function (a, b, c, d, e, f) {
ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
destCtx.setTransform(a, b, c, d, e, f);
this.__originalSetTransform(a, b, c, d, e, f);
};
ctx.resetTransform = function () {
ctx.resetTransform = function ctxResetTransform() {
destCtx.resetTransform();
this.__originalResetTransform();
};
ctx.rotate = function (angle) {
ctx.rotate = function ctxRotate(angle) {
destCtx.rotate(angle);
this.__originalRotate(angle);
};
ctx.clip = function (rule) {
ctx.clip = function ctxRotate(rule) {
destCtx.clip(rule);
this.__originalClip(rule);
};
@ -303,63 +305,39 @@ function drawImageAtIntegerCoords(
}
class CanvasExtraState {
// Are soft masks and alpha values shapes or opacities?
alphaIsShape = false;
fontSize = 0;
fontSizeScale = 1;
textMatrix = null;
textMatrixScale = 1;
fontMatrix = FONT_IDENTITY_MATRIX;
leading = 0;
// Current point (in user coordinates)
x = 0;
y = 0;
// Start of text line (in text coordinates)
lineX = 0;
lineY = 0;
// Character and word spacing
charSpacing = 0;
wordSpacing = 0;
textHScale = 1;
textRenderingMode = TextRenderingMode.FILL;
textRise = 0;
// Default fore and background colors
fillColor = "#000000";
strokeColor = "#000000";
patternFill = false;
patternStroke = false;
// Note: fill alpha applies to all non-stroking operations
fillAlpha = 1;
strokeAlpha = 1;
lineWidth = 1;
activeSMask = null;
transferMaps = "none";
constructor(width, height) {
// Are soft masks and alpha values shapes or opacities?
this.alphaIsShape = false;
this.fontSize = 0;
this.fontSizeScale = 1;
this.textMatrix = IDENTITY_MATRIX;
this.textMatrixScale = 1;
this.fontMatrix = FONT_IDENTITY_MATRIX;
this.leading = 0;
// Current point (in user coordinates)
this.x = 0;
this.y = 0;
// Start of text line (in text coordinates)
this.lineX = 0;
this.lineY = 0;
// Character and word spacing
this.charSpacing = 0;
this.wordSpacing = 0;
this.textHScale = 1;
this.textRenderingMode = TextRenderingMode.FILL;
this.textRise = 0;
// Default fore and background colors
this.fillColor = "#000000";
this.strokeColor = "#000000";
this.patternFill = false;
this.patternStroke = false;
// Note: fill alpha applies to all non-stroking operations
this.fillAlpha = 1;
this.strokeAlpha = 1;
this.lineWidth = 1;
this.activeSMask = null;
this.transferMaps = "none";
this.clipBox = new Float32Array([0, 0, width, height]);
this.minMax = MIN_MAX_INIT.slice();
}
@ -611,9 +589,14 @@ function resetCtxToDefault(ctx) {
ctx.setLineDash([]);
ctx.lineDashOffset = 0;
}
const { filter } = ctx;
if (filter !== "none" && filter !== "") {
ctx.filter = "none";
if (
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
!isNodeJS
) {
const { filter } = ctx;
if (filter !== "none" && filter !== "") {
ctx.filter = "none";
}
}
}
@ -1610,7 +1593,7 @@ class CanvasGraphics {
// Text
beginText() {
this.current.textMatrix = null;
this.current.textMatrix = IDENTITY_MATRIX;
this.current.textMatrixScale = 1;
this.current.x = this.current.lineX = 0;
this.current.y = this.current.lineY = 0;
@ -1731,13 +1714,12 @@ class CanvasGraphics {
this.moveText(x, y);
}
setTextMatrix(matrix) {
const { current } = this;
current.textMatrix = matrix;
current.textMatrixScale = Math.hypot(matrix[0], matrix[1]);
setTextMatrix(a, b, c, d, e, f) {
this.current.textMatrix = [a, b, c, d, e, f];
this.current.textMatrixScale = Math.hypot(a, b);
current.x = current.lineX = 0;
current.y = current.lineY = 0;
this.current.x = this.current.lineX = 0;
this.current.y = this.current.lineY = 0;
}
nextLine() {
@ -1904,9 +1886,7 @@ class CanvasGraphics {
!current.patternFill;
ctx.save();
if (current.textMatrix) {
ctx.transform(...current.textMatrix);
}
ctx.transform(...current.textMatrix);
ctx.translate(current.x, current.y + current.textRise);
if (fontDirection > 0) {
@ -2101,9 +2081,7 @@ class CanvasGraphics {
this._cachedGetSinglePixelWidth = null;
ctx.save();
if (current.textMatrix) {
ctx.transform(...current.textMatrix);
}
ctx.transform(...current.textMatrix);
ctx.translate(current.x, current.y + current.textRise);
ctx.scale(textHScale, fontDirection);
@ -2756,13 +2734,18 @@ class CanvasGraphics {
this.save();
// The filter, if any, will be applied in applyTransferMapsToBitmap.
// It must be applied to the image before rescaling else some artifacts
// could appear.
// The final restore will reset it to its value.
const { filter } = ctx;
if (filter !== "none" && filter !== "") {
ctx.filter = "none";
if (
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
!isNodeJS
) {
// The filter, if any, will be applied in applyTransferMapsToBitmap.
// It must be applied to the image before rescaling else some artifacts
// could appear.
// The final restore will reset it to its value.
const { filter } = ctx;
if (filter !== "none" && filter !== "") {
ctx.filter = "none";
}
}
// scale the image to the unit square