Move some constants and helper functions out of the PartialEvaluator
closure
This will simplify the `class` conversion in the next patch, and with modern JavaScript the moved code is still limited to the current module scope. *Please note:* For improved consistency with our usual formatting, the `TILING_PATTERN`/`SHADING_PATTERN` constants where re-factored slightly.
This commit is contained in:
parent
c4255fdbfd
commit
32a0b6fa73
@ -85,61 +85,23 @@ import { MurmurHash3_64 } from "./murmurhash3.js";
|
||||
import { OperatorList } from "./operator_list.js";
|
||||
import { PDFImage } from "./image.js";
|
||||
|
||||
var PartialEvaluator = (function PartialEvaluatorClosure() {
|
||||
const DefaultPartialEvaluatorOptions = {
|
||||
const DefaultPartialEvaluatorOptions = Object.freeze({
|
||||
maxImageSize: -1,
|
||||
disableFontFace: false,
|
||||
ignoreErrors: false,
|
||||
isEvalSupported: true,
|
||||
fontExtraProperties: false,
|
||||
};
|
||||
});
|
||||
|
||||
// eslint-disable-next-line no-shadow
|
||||
function PartialEvaluator({
|
||||
xref,
|
||||
handler,
|
||||
pageIndex,
|
||||
idFactory,
|
||||
fontCache,
|
||||
builtInCMapCache,
|
||||
globalImageCache,
|
||||
options = null,
|
||||
}) {
|
||||
this.xref = xref;
|
||||
this.handler = handler;
|
||||
this.pageIndex = pageIndex;
|
||||
this.idFactory = idFactory;
|
||||
this.fontCache = fontCache;
|
||||
this.builtInCMapCache = builtInCMapCache;
|
||||
this.globalImageCache = globalImageCache;
|
||||
this.options = options || DefaultPartialEvaluatorOptions;
|
||||
this.parsingType3Font = false;
|
||||
const PatternType = {
|
||||
TILING: 1,
|
||||
SHADING: 2,
|
||||
};
|
||||
|
||||
this._fetchBuiltInCMapBound = this.fetchBuiltInCMap.bind(this);
|
||||
}
|
||||
const deferred = Promise.resolve();
|
||||
|
||||
// Trying to minimize Date.now() usage and check every 100 time
|
||||
var TIME_SLOT_DURATION_MS = 20;
|
||||
var CHECK_TIME_EVERY = 100;
|
||||
function TimeSlotManager() {
|
||||
this.reset();
|
||||
}
|
||||
TimeSlotManager.prototype = {
|
||||
check: function TimeSlotManager_check() {
|
||||
if (++this.checked < CHECK_TIME_EVERY) {
|
||||
return false;
|
||||
}
|
||||
this.checked = 0;
|
||||
return this.endTime <= Date.now();
|
||||
},
|
||||
reset: function TimeSlotManager_reset() {
|
||||
this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
|
||||
this.checked = 0;
|
||||
},
|
||||
};
|
||||
|
||||
// Convert PDF blend mode names to HTML5 blend mode names.
|
||||
function normalizeBlendMode(value, parsingArray = false) {
|
||||
// Convert PDF blend mode names to HTML5 blend mode names.
|
||||
function normalizeBlendMode(value, parsingArray = false) {
|
||||
if (Array.isArray(value)) {
|
||||
// Use the first *supported* BM value in the Array (fixes issue11279.pdf).
|
||||
for (let i = 0, ii = value.length; i < ii; i++) {
|
||||
@ -198,12 +160,52 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
||||
}
|
||||
warn(`Unsupported blend mode: ${value.name}`);
|
||||
return "source-over";
|
||||
}
|
||||
|
||||
// Trying to minimize Date.now() usage and check every 100 time.
|
||||
var TIME_SLOT_DURATION_MS = 20;
|
||||
var CHECK_TIME_EVERY = 100;
|
||||
function TimeSlotManager() {
|
||||
this.reset();
|
||||
}
|
||||
TimeSlotManager.prototype = {
|
||||
check: function TimeSlotManager_check() {
|
||||
if (++this.checked < CHECK_TIME_EVERY) {
|
||||
return false;
|
||||
}
|
||||
this.checked = 0;
|
||||
return this.endTime <= Date.now();
|
||||
},
|
||||
reset: function TimeSlotManager_reset() {
|
||||
this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
|
||||
this.checked = 0;
|
||||
},
|
||||
};
|
||||
|
||||
var deferred = Promise.resolve();
|
||||
var PartialEvaluator = (function PartialEvaluatorClosure() {
|
||||
// eslint-disable-next-line no-shadow
|
||||
function PartialEvaluator({
|
||||
xref,
|
||||
handler,
|
||||
pageIndex,
|
||||
idFactory,
|
||||
fontCache,
|
||||
builtInCMapCache,
|
||||
globalImageCache,
|
||||
options = null,
|
||||
}) {
|
||||
this.xref = xref;
|
||||
this.handler = handler;
|
||||
this.pageIndex = pageIndex;
|
||||
this.idFactory = idFactory;
|
||||
this.fontCache = fontCache;
|
||||
this.builtInCMapCache = builtInCMapCache;
|
||||
this.globalImageCache = globalImageCache;
|
||||
this.options = options || DefaultPartialEvaluatorOptions;
|
||||
this.parsingType3Font = false;
|
||||
|
||||
var TILING_PATTERN = 1,
|
||||
SHADING_PATTERN = 2;
|
||||
this._fetchBuiltInCMapBound = this.fetchBuiltInCMap.bind(this);
|
||||
}
|
||||
|
||||
PartialEvaluator.prototype = {
|
||||
/**
|
||||
@ -1193,7 +1195,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
||||
var dict = isStream(pattern) ? pattern.dict : pattern;
|
||||
var typeNum = dict.get("PatternType");
|
||||
|
||||
if (typeNum === TILING_PATTERN) {
|
||||
if (typeNum === PatternType.TILING) {
|
||||
var color = cs.base ? cs.base.getRgb(args, 0) : null;
|
||||
return this.handleTilingType(
|
||||
fn,
|
||||
@ -1204,7 +1206,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
||||
operatorList,
|
||||
task
|
||||
);
|
||||
} else if (typeNum === SHADING_PATTERN) {
|
||||
} else if (typeNum === PatternType.SHADING) {
|
||||
var shading = dict.get("Shading");
|
||||
var matrix = dict.getArray("Matrix");
|
||||
pattern = Pattern.parseShading(
|
||||
|
Loading…
x
Reference in New Issue
Block a user