mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-25 17:48:07 +02:00
Merge pull request #4895 from p01/Small_optimizations_1
Small optimizations 1
This commit is contained in:
commit
b2d8e73d54
4 changed files with 109 additions and 107 deletions
|
@ -576,11 +576,11 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
var dict = (isStream(pattern) ? pattern.dict : pattern);
|
||||
var typeNum = dict.get('PatternType');
|
||||
|
||||
if (typeNum == TILING_PATTERN) {
|
||||
if (typeNum === TILING_PATTERN) {
|
||||
var color = cs.base ? cs.base.getRgb(args, 0) : null;
|
||||
return this.handleTilingType(fn, color, resources, pattern,
|
||||
dict, operatorList);
|
||||
} else if (typeNum == SHADING_PATTERN) {
|
||||
} else if (typeNum === SHADING_PATTERN) {
|
||||
var shading = dict.get('Shading');
|
||||
var matrix = dict.get('Matrix');
|
||||
pattern = Pattern.parseShading(shading, matrix, xref, resources);
|
||||
|
@ -954,7 +954,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
}
|
||||
|
||||
var glyphUnicode = glyph.unicode;
|
||||
if (glyphUnicode in NormalizedUnicodes) {
|
||||
if (NormalizedUnicodes[glyphUnicode] !== undefined) {
|
||||
glyphUnicode = NormalizedUnicodes[glyphUnicode];
|
||||
}
|
||||
glyphUnicode = reverseIfRtl(glyphUnicode);
|
||||
|
@ -1486,7 +1486,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
|
||||
var composite = false;
|
||||
var uint8array;
|
||||
if (type.name == 'Type0') {
|
||||
if (type.name === 'Type0') {
|
||||
// If font is a composite
|
||||
// - get the descendant font
|
||||
// - set the type according to the descendant font
|
||||
|
@ -1552,7 +1552,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
var properties;
|
||||
|
||||
if (!descriptor) {
|
||||
if (type.name == 'Type3') {
|
||||
if (type.name === 'Type3') {
|
||||
// FontDescriptor is only required for Type3 fonts when the document
|
||||
// is a tagged pdf. Create a barbebones one to get by.
|
||||
descriptor = new Dict(null);
|
||||
|
@ -2081,7 +2081,7 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
|
|||
}
|
||||
if (!isCmd(obj)) {
|
||||
// argument
|
||||
if (obj !== null && obj !== undefined) {
|
||||
if (obj !== null) {
|
||||
args.push((obj instanceof Dict ? obj.getAll() : obj));
|
||||
assert(args.length <= 33, 'Too many arguments');
|
||||
}
|
||||
|
@ -2097,37 +2097,32 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
|
|||
}
|
||||
|
||||
var fn = opSpec.id;
|
||||
var numArgs = opSpec.numArgs;
|
||||
|
||||
// Some post script commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
|
||||
if (!opSpec.variableArgs && args.length !== opSpec.numArgs) {
|
||||
while (args.length > opSpec.numArgs) {
|
||||
this.nonProcessedArgs.push(args.shift());
|
||||
if (!opSpec.variableArgs) {
|
||||
// Some post script commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
|
||||
if (args.length !== numArgs) {
|
||||
var nonProcessedArgs = this.nonProcessedArgs;
|
||||
while (args.length > numArgs) {
|
||||
nonProcessedArgs.push(args.shift());
|
||||
}
|
||||
while (args.length < numArgs && nonProcessedArgs.length !== 0) {
|
||||
args.unshift(nonProcessedArgs.pop());
|
||||
}
|
||||
}
|
||||
|
||||
while (args.length < opSpec.numArgs && this.nonProcessedArgs.length) {
|
||||
args.unshift(this.nonProcessedArgs.pop());
|
||||
}
|
||||
}
|
||||
|
||||
// Validate the number of arguments for the command
|
||||
if (opSpec.variableArgs) {
|
||||
if (args.length > opSpec.numArgs) {
|
||||
info('Command ' + fn + ': expected [0,' + opSpec.numArgs +
|
||||
'] args, but received ' + args.length + ' args');
|
||||
}
|
||||
} else {
|
||||
if (args.length < opSpec.numArgs) {
|
||||
if (args.length < numArgs) {
|
||||
// If we receive too few args, it's not possible to possible
|
||||
// to execute the command, so skip the command
|
||||
info('Command ' + fn + ': because expected ' +
|
||||
opSpec.numArgs + ' args, but received ' + args.length +
|
||||
numArgs + ' args, but received ' + args.length +
|
||||
' args; skipping');
|
||||
args = [];
|
||||
continue;
|
||||
} else if (args.length > opSpec.numArgs) {
|
||||
info('Command ' + fn + ': expected ' + opSpec.numArgs +
|
||||
' args, but received ' + args.length + ' args');
|
||||
}
|
||||
} else if (args.length > numArgs) {
|
||||
info('Command ' + fn + ': expected [0,' + numArgs +
|
||||
'] args, but received ' + args.length + ' args');
|
||||
}
|
||||
|
||||
// TODO figure out how to type-check vararg functions
|
||||
|
@ -2172,9 +2167,9 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
|
|||
// have been found at index.
|
||||
for (var i = 0; i < count; i++) {
|
||||
var arg = argsArray[index + 4 * i + 2];
|
||||
var imageMask = arg.length == 1 && arg[0];
|
||||
if (imageMask && imageMask.width == 1 && imageMask.height == 1 &&
|
||||
(!imageMask.data.length || (imageMask.data.length == 1 &&
|
||||
var imageMask = arg.length === 1 && arg[0];
|
||||
if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
|
||||
(!imageMask.data.length || (imageMask.data.length === 1 &&
|
||||
imageMask.data[0] === 0))) {
|
||||
fnArray[index + 4 * i + 2] = OPS.paintSolidColorImageMask;
|
||||
continue;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue