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,61 +85,23 @@ 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,
}; });
// eslint-disable-next-line no-shadow const PatternType = {
function PartialEvaluator({ TILING: 1,
xref, SHADING: 2,
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); const deferred = Promise.resolve();
}
// Trying to minimize Date.now() usage and check every 100 time // Convert PDF blend mode names to HTML5 blend mode names.
var TIME_SLOT_DURATION_MS = 20; function normalizeBlendMode(value, parsingArray = false) {
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) {
if (Array.isArray(value)) { if (Array.isArray(value)) {
// Use the first *supported* BM value in the Array (fixes issue11279.pdf). // Use the first *supported* BM value in the Array (fixes issue11279.pdf).
for (let i = 0, ii = value.length; i < ii; i++) { for (let i = 0, ii = value.length; i < ii; i++) {
@ -198,12 +160,52 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
} }
warn(`Unsupported blend mode: ${value.name}`); warn(`Unsupported blend mode: ${value.name}`);
return "source-over"; 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, this._fetchBuiltInCMapBound = this.fetchBuiltInCMap.bind(this);
SHADING_PATTERN = 2; }
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(