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:
Jonas Jenwald 2020-07-05 12:06:56 +02:00
parent c4255fdbfd
commit 32a0b6fa73

View File

@ -85,58 +85,20 @@ import { MurmurHash3_64 } from "./murmurhash3.js";
import { OperatorList } from "./operator_list.js"; import { OperatorList } from "./operator_list.js";
import { PDFImage } from "./image.js"; import { PDFImage } from "./image.js";
var PartialEvaluator = (function PartialEvaluatorClosure() { const DefaultPartialEvaluatorOptions = Object.freeze({
const DefaultPartialEvaluatorOptions = {
maxImageSize: -1, maxImageSize: -1,
disableFontFace: false, disableFontFace: false,
ignoreErrors: false, ignoreErrors: false,
isEvalSupported: true, isEvalSupported: true,
fontExtraProperties: false, fontExtraProperties: false,
});
const PatternType = {
TILING: 1,
SHADING: 2,
}; };
// eslint-disable-next-line no-shadow const deferred = Promise.resolve();
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;
this._fetchBuiltInCMapBound = this.fetchBuiltInCMap.bind(this);
}
// 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. // Convert PDF blend mode names to HTML5 blend mode names.
function normalizeBlendMode(value, parsingArray = false) { function normalizeBlendMode(value, parsingArray = false) {
@ -200,10 +162,50 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
return "source-over"; return "source-over";
} }
var 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;
},
};
var TILING_PATTERN = 1, var PartialEvaluator = (function PartialEvaluatorClosure() {
SHADING_PATTERN = 2; // 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;
this._fetchBuiltInCMapBound = this.fetchBuiltInCMap.bind(this);
}
PartialEvaluator.prototype = { PartialEvaluator.prototype = {
/** /**
@ -1193,7 +1195,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var dict = isStream(pattern) ? pattern.dict : pattern; var dict = isStream(pattern) ? pattern.dict : pattern;
var typeNum = dict.get("PatternType"); var typeNum = dict.get("PatternType");
if (typeNum === TILING_PATTERN) { if (typeNum === PatternType.TILING) {
var color = cs.base ? cs.base.getRgb(args, 0) : null; var color = cs.base ? cs.base.getRgb(args, 0) : null;
return this.handleTilingType( return this.handleTilingType(
fn, fn,
@ -1204,7 +1206,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
operatorList, operatorList,
task task
); );
} else if (typeNum === SHADING_PATTERN) { } else if (typeNum === PatternType.SHADING) {
var shading = dict.get("Shading"); var shading = dict.get("Shading");
var matrix = dict.getArray("Matrix"); var matrix = dict.getArray("Matrix");
pattern = Pattern.parseShading( pattern = Pattern.parseShading(