mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-10 10:15:37 +02:00
Add braces to single line statements in src/shared/function.js
This commit is contained in:
parent
635466fcd2
commit
e8a68f12df
1 changed files with 72 additions and 40 deletions
|
@ -28,8 +28,9 @@ var PDFFunction = (function PDFFunctionClosure() {
|
||||||
getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
|
getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
|
||||||
str) {
|
str) {
|
||||||
var length = 1;
|
var length = 1;
|
||||||
for (var i = 0, ii = size.length; i < ii; i++)
|
for (var i = 0, ii = size.length; i < ii; i++) {
|
||||||
length *= size[i];
|
length *= size[i];
|
||||||
|
}
|
||||||
length *= outputSize;
|
length *= outputSize;
|
||||||
|
|
||||||
var array = [];
|
var array = [];
|
||||||
|
@ -55,8 +56,9 @@ var PDFFunction = (function PDFFunctionClosure() {
|
||||||
|
|
||||||
getIR: function PDFFunction_getIR(xref, fn) {
|
getIR: function PDFFunction_getIR(xref, fn) {
|
||||||
var dict = fn.dict;
|
var dict = fn.dict;
|
||||||
if (!dict)
|
if (!dict) {
|
||||||
dict = fn;
|
dict = fn;
|
||||||
|
}
|
||||||
|
|
||||||
var types = [this.constructSampled,
|
var types = [this.constructSampled,
|
||||||
null,
|
null,
|
||||||
|
@ -66,8 +68,9 @@ var PDFFunction = (function PDFFunctionClosure() {
|
||||||
|
|
||||||
var typeNum = dict.get('FunctionType');
|
var typeNum = dict.get('FunctionType');
|
||||||
var typeFn = types[typeNum];
|
var typeFn = types[typeNum];
|
||||||
if (!typeFn)
|
if (!typeFn) {
|
||||||
error('Unknown type of function');
|
error('Unknown type of function');
|
||||||
|
}
|
||||||
|
|
||||||
return typeFn.call(this, fn, dict, xref);
|
return typeFn.call(this, fn, dict, xref);
|
||||||
},
|
},
|
||||||
|
@ -107,8 +110,9 @@ var PDFFunction = (function PDFFunctionClosure() {
|
||||||
var domain = dict.get('Domain');
|
var domain = dict.get('Domain');
|
||||||
var range = dict.get('Range');
|
var range = dict.get('Range');
|
||||||
|
|
||||||
if (!domain || !range)
|
if (!domain || !range) {
|
||||||
error('No domain or range');
|
error('No domain or range');
|
||||||
|
}
|
||||||
|
|
||||||
var inputSize = domain.length / 2;
|
var inputSize = domain.length / 2;
|
||||||
var outputSize = range.length / 2;
|
var outputSize = range.length / 2;
|
||||||
|
@ -136,10 +140,11 @@ var PDFFunction = (function PDFFunctionClosure() {
|
||||||
encode = toMultiArray(encode);
|
encode = toMultiArray(encode);
|
||||||
|
|
||||||
var decode = dict.get('Decode');
|
var decode = dict.get('Decode');
|
||||||
if (!decode)
|
if (!decode) {
|
||||||
decode = range;
|
decode = range;
|
||||||
else
|
} else {
|
||||||
decode = toMultiArray(decode);
|
decode = toMultiArray(decode);
|
||||||
|
}
|
||||||
|
|
||||||
var samples = this.getSampleArray(size, outputSize, bps, str);
|
var samples = this.getSampleArray(size, outputSize, bps, str);
|
||||||
|
|
||||||
|
@ -167,9 +172,10 @@ var PDFFunction = (function PDFFunctionClosure() {
|
||||||
var mask = IR[8];
|
var mask = IR[8];
|
||||||
var range = IR[9];
|
var range = IR[9];
|
||||||
|
|
||||||
if (m != args.length)
|
if (m != args.length) {
|
||||||
error('Incorrect number of arguments: ' + m + ' != ' +
|
error('Incorrect number of arguments: ' + m + ' != ' +
|
||||||
args.length);
|
args.length);
|
||||||
|
}
|
||||||
|
|
||||||
var x = args;
|
var x = args;
|
||||||
|
|
||||||
|
@ -178,8 +184,9 @@ var PDFFunction = (function PDFFunctionClosure() {
|
||||||
var cubeVertices = 1 << m;
|
var cubeVertices = 1 << m;
|
||||||
var cubeN = new Float64Array(cubeVertices);
|
var cubeN = new Float64Array(cubeVertices);
|
||||||
var cubeVertex = new Uint32Array(cubeVertices);
|
var cubeVertex = new Uint32Array(cubeVertices);
|
||||||
for (var j = 0; j < cubeVertices; j++)
|
for (var j = 0; j < cubeVertices; j++) {
|
||||||
cubeN[j] = 1;
|
cubeN[j] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
var k = n, pos = 1;
|
var k = n, pos = 1;
|
||||||
// Map x_i to y_j for 0 <= i < m using the sampled function.
|
// Map x_i to y_j for 0 <= i < m using the sampled function.
|
||||||
|
@ -222,8 +229,9 @@ var PDFFunction = (function PDFFunctionClosure() {
|
||||||
for (var j = 0; j < n; ++j) {
|
for (var j = 0; j < n; ++j) {
|
||||||
// Sum all cube vertices' samples portions
|
// Sum all cube vertices' samples portions
|
||||||
var rj = 0;
|
var rj = 0;
|
||||||
for (var i = 0; i < cubeVertices; i++)
|
for (var i = 0; i < cubeVertices; i++) {
|
||||||
rj += samples[cubeVertex[i] + j] * cubeN[i];
|
rj += samples[cubeVertex[i] + j] * cubeN[i];
|
||||||
|
}
|
||||||
|
|
||||||
// r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
|
// r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
|
||||||
// Decode_2j, Decode_2j+1)
|
// Decode_2j, Decode_2j+1)
|
||||||
|
@ -243,13 +251,15 @@ var PDFFunction = (function PDFFunctionClosure() {
|
||||||
var c1 = dict.get('C1') || [1];
|
var c1 = dict.get('C1') || [1];
|
||||||
var n = dict.get('N');
|
var n = dict.get('N');
|
||||||
|
|
||||||
if (!isArray(c0) || !isArray(c1))
|
if (!isArray(c0) || !isArray(c1)) {
|
||||||
error('Illegal dictionary for interpolated function');
|
error('Illegal dictionary for interpolated function');
|
||||||
|
}
|
||||||
|
|
||||||
var length = c0.length;
|
var length = c0.length;
|
||||||
var diff = [];
|
var diff = [];
|
||||||
for (var i = 0; i < length; ++i)
|
for (var i = 0; i < length; ++i) {
|
||||||
diff.push(c1[i] - c0[i]);
|
diff.push(c1[i] - c0[i]);
|
||||||
|
}
|
||||||
|
|
||||||
return [CONSTRUCT_INTERPOLATED, c0, diff, n];
|
return [CONSTRUCT_INTERPOLATED, c0, diff, n];
|
||||||
},
|
},
|
||||||
|
@ -266,8 +276,9 @@ var PDFFunction = (function PDFFunctionClosure() {
|
||||||
var x = n == 1 ? args[0] : Math.pow(args[0], n);
|
var x = n == 1 ? args[0] : Math.pow(args[0], n);
|
||||||
|
|
||||||
var out = [];
|
var out = [];
|
||||||
for (var j = 0; j < length; ++j)
|
for (var j = 0; j < length; ++j) {
|
||||||
out.push(c0[j] + (x * diff[j]));
|
out.push(c0[j] + (x * diff[j]));
|
||||||
|
}
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
|
|
||||||
|
@ -277,17 +288,20 @@ var PDFFunction = (function PDFFunctionClosure() {
|
||||||
constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
|
constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
|
||||||
var domain = dict.get('Domain');
|
var domain = dict.get('Domain');
|
||||||
|
|
||||||
if (!domain)
|
if (!domain) {
|
||||||
error('No domain');
|
error('No domain');
|
||||||
|
}
|
||||||
|
|
||||||
var inputSize = domain.length / 2;
|
var inputSize = domain.length / 2;
|
||||||
if (inputSize != 1)
|
if (inputSize != 1) {
|
||||||
error('Bad domain for stiched function');
|
error('Bad domain for stiched function');
|
||||||
|
}
|
||||||
|
|
||||||
var fnRefs = dict.get('Functions');
|
var fnRefs = dict.get('Functions');
|
||||||
var fns = [];
|
var fns = [];
|
||||||
for (var i = 0, ii = fnRefs.length; i < ii; ++i)
|
for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
|
||||||
fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
|
fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
|
||||||
|
}
|
||||||
|
|
||||||
var bounds = dict.get('Bounds');
|
var bounds = dict.get('Bounds');
|
||||||
var encode = dict.get('Encode');
|
var encode = dict.get('Encode');
|
||||||
|
@ -308,10 +322,11 @@ var PDFFunction = (function PDFFunctionClosure() {
|
||||||
|
|
||||||
return function constructStichedFromIRResult(args) {
|
return function constructStichedFromIRResult(args) {
|
||||||
var clip = function constructStichedFromIRClip(v, min, max) {
|
var clip = function constructStichedFromIRClip(v, min, max) {
|
||||||
if (v > max)
|
if (v > max) {
|
||||||
v = max;
|
v = max;
|
||||||
else if (v < min)
|
} else if (v < min) {
|
||||||
v = min;
|
v = min;
|
||||||
|
}
|
||||||
return v;
|
return v;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -319,17 +334,20 @@ var PDFFunction = (function PDFFunctionClosure() {
|
||||||
var v = clip(args[0], domain[0], domain[1]);
|
var v = clip(args[0], domain[0], domain[1]);
|
||||||
// calulate which bound the value is in
|
// calulate which bound the value is in
|
||||||
for (var i = 0, ii = bounds.length; i < ii; ++i) {
|
for (var i = 0, ii = bounds.length; i < ii; ++i) {
|
||||||
if (v < bounds[i])
|
if (v < bounds[i]) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// encode value into domain of function
|
// encode value into domain of function
|
||||||
var dmin = domain[0];
|
var dmin = domain[0];
|
||||||
if (i > 0)
|
if (i > 0) {
|
||||||
dmin = bounds[i - 1];
|
dmin = bounds[i - 1];
|
||||||
|
}
|
||||||
var dmax = domain[1];
|
var dmax = domain[1];
|
||||||
if (i < bounds.length)
|
if (i < bounds.length) {
|
||||||
dmax = bounds[i];
|
dmax = bounds[i];
|
||||||
|
}
|
||||||
|
|
||||||
var rmin = encode[2 * i];
|
var rmin = encode[2 * i];
|
||||||
var rmax = encode[2 * i + 1];
|
var rmax = encode[2 * i + 1];
|
||||||
|
@ -346,11 +364,13 @@ var PDFFunction = (function PDFFunctionClosure() {
|
||||||
var domain = dict.get('Domain');
|
var domain = dict.get('Domain');
|
||||||
var range = dict.get('Range');
|
var range = dict.get('Range');
|
||||||
|
|
||||||
if (!domain)
|
if (!domain) {
|
||||||
error('No domain.');
|
error('No domain.');
|
||||||
|
}
|
||||||
|
|
||||||
if (!range)
|
if (!range) {
|
||||||
error('No range.');
|
error('No range.');
|
||||||
|
}
|
||||||
|
|
||||||
var lexer = new PostScriptLexer(fn);
|
var lexer = new PostScriptLexer(fn);
|
||||||
var parser = new PostScriptParser(lexer);
|
var parser = new PostScriptParser(lexer);
|
||||||
|
@ -376,18 +396,20 @@ var PDFFunction = (function PDFFunctionClosure() {
|
||||||
}
|
}
|
||||||
|
|
||||||
var key = initialStack.join('_');
|
var key = initialStack.join('_');
|
||||||
if (cache.has(key))
|
if (cache.has(key)) {
|
||||||
return cache.get(key);
|
return cache.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
var stack = evaluator.execute(initialStack);
|
var stack = evaluator.execute(initialStack);
|
||||||
var transformed = [];
|
var transformed = [];
|
||||||
for (i = numOutputs - 1; i >= 0; --i) {
|
for (i = numOutputs - 1; i >= 0; --i) {
|
||||||
var out = stack.pop();
|
var out = stack.pop();
|
||||||
var rangeIndex = 2 * i;
|
var rangeIndex = 2 * i;
|
||||||
if (out < range[rangeIndex])
|
if (out < range[rangeIndex]) {
|
||||||
out = range[rangeIndex];
|
out = range[rangeIndex];
|
||||||
else if (out > range[rangeIndex + 1])
|
} else if (out > range[rangeIndex + 1]) {
|
||||||
out = range[rangeIndex + 1];
|
out = range[rangeIndex + 1];
|
||||||
|
}
|
||||||
transformed[i] = out;
|
transformed[i] = out;
|
||||||
}
|
}
|
||||||
cache.set(key, transformed);
|
cache.set(key, transformed);
|
||||||
|
@ -430,21 +452,25 @@ var PostScriptStack = (function PostScriptStackClosure() {
|
||||||
|
|
||||||
PostScriptStack.prototype = {
|
PostScriptStack.prototype = {
|
||||||
push: function PostScriptStack_push(value) {
|
push: function PostScriptStack_push(value) {
|
||||||
if (this.stack.length >= MAX_STACK_SIZE)
|
if (this.stack.length >= MAX_STACK_SIZE) {
|
||||||
error('PostScript function stack overflow.');
|
error('PostScript function stack overflow.');
|
||||||
|
}
|
||||||
this.stack.push(value);
|
this.stack.push(value);
|
||||||
},
|
},
|
||||||
pop: function PostScriptStack_pop() {
|
pop: function PostScriptStack_pop() {
|
||||||
if (this.stack.length <= 0)
|
if (this.stack.length <= 0) {
|
||||||
error('PostScript function stack underflow.');
|
error('PostScript function stack underflow.');
|
||||||
|
}
|
||||||
return this.stack.pop();
|
return this.stack.pop();
|
||||||
},
|
},
|
||||||
copy: function PostScriptStack_copy(n) {
|
copy: function PostScriptStack_copy(n) {
|
||||||
if (this.stack.length + n >= MAX_STACK_SIZE)
|
if (this.stack.length + n >= MAX_STACK_SIZE) {
|
||||||
error('PostScript function stack overflow.');
|
error('PostScript function stack overflow.');
|
||||||
|
}
|
||||||
var stack = this.stack;
|
var stack = this.stack;
|
||||||
for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++)
|
for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
|
||||||
stack.push(stack[i]);
|
stack.push(stack[i]);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
index: function PostScriptStack_index(n) {
|
index: function PostScriptStack_index(n) {
|
||||||
this.push(this.stack[this.stack.length - n - 1]);
|
this.push(this.stack[this.stack.length - n - 1]);
|
||||||
|
@ -490,8 +516,9 @@ var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
|
||||||
case 'jz': // jump if false
|
case 'jz': // jump if false
|
||||||
b = stack.pop();
|
b = stack.pop();
|
||||||
a = stack.pop();
|
a = stack.pop();
|
||||||
if (!a)
|
if (!a) {
|
||||||
counter = b;
|
counter = b;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'j': // jump
|
case 'j': // jump
|
||||||
a = stack.pop();
|
a = stack.pop();
|
||||||
|
@ -511,10 +538,11 @@ var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
|
||||||
case 'and':
|
case 'and':
|
||||||
b = stack.pop();
|
b = stack.pop();
|
||||||
a = stack.pop();
|
a = stack.pop();
|
||||||
if (isBool(a) && isBool(b))
|
if (isBool(a) && isBool(b)) {
|
||||||
stack.push(a && b);
|
stack.push(a && b);
|
||||||
else
|
} else {
|
||||||
stack.push(a & b);
|
stack.push(a & b);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'atan':
|
case 'atan':
|
||||||
a = stack.pop();
|
a = stack.pop();
|
||||||
|
@ -523,10 +551,11 @@ var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
|
||||||
case 'bitshift':
|
case 'bitshift':
|
||||||
b = stack.pop();
|
b = stack.pop();
|
||||||
a = stack.pop();
|
a = stack.pop();
|
||||||
if (a > 0)
|
if (a > 0) {
|
||||||
stack.push(a << b);
|
stack.push(a << b);
|
||||||
else
|
} else {
|
||||||
stack.push(a >> b);
|
stack.push(a >> b);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'ceiling':
|
case 'ceiling':
|
||||||
a = stack.pop();
|
a = stack.pop();
|
||||||
|
@ -633,18 +662,20 @@ var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
|
||||||
break;
|
break;
|
||||||
case 'not':
|
case 'not':
|
||||||
a = stack.pop();
|
a = stack.pop();
|
||||||
if (isBool(a) && isBool(b))
|
if (isBool(a) && isBool(b)) {
|
||||||
stack.push(a && b);
|
stack.push(a && b);
|
||||||
else
|
} else {
|
||||||
stack.push(a & b);
|
stack.push(a & b);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'or':
|
case 'or':
|
||||||
b = stack.pop();
|
b = stack.pop();
|
||||||
a = stack.pop();
|
a = stack.pop();
|
||||||
if (isBool(a) && isBool(b))
|
if (isBool(a) && isBool(b)) {
|
||||||
stack.push(a || b);
|
stack.push(a || b);
|
||||||
else
|
} else {
|
||||||
stack.push(a | b);
|
stack.push(a | b);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'pop':
|
case 'pop':
|
||||||
stack.pop();
|
stack.pop();
|
||||||
|
@ -682,10 +713,11 @@ var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
|
||||||
case 'xor':
|
case 'xor':
|
||||||
b = stack.pop();
|
b = stack.pop();
|
||||||
a = stack.pop();
|
a = stack.pop();
|
||||||
if (isBool(a) && isBool(b))
|
if (isBool(a) && isBool(b)) {
|
||||||
stack.push(a != b);
|
stack.push(a != b);
|
||||||
else
|
} else {
|
||||||
stack.push(a ^ b);
|
stack.push(a ^ b);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error('Unknown operator ' + operator);
|
error('Unknown operator ' + operator);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue