Add braces to single line statements in src/shared/function.js

This commit is contained in:
Jonas Jenwald 2014-03-03 13:34:12 +01:00
parent 635466fcd2
commit e8a68f12df

View File

@ -28,8 +28,9 @@ var PDFFunction = (function PDFFunctionClosure() {
getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
str) {
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 *= outputSize;
var array = [];
@ -55,8 +56,9 @@ var PDFFunction = (function PDFFunctionClosure() {
getIR: function PDFFunction_getIR(xref, fn) {
var dict = fn.dict;
if (!dict)
if (!dict) {
dict = fn;
}
var types = [this.constructSampled,
null,
@ -66,8 +68,9 @@ var PDFFunction = (function PDFFunctionClosure() {
var typeNum = dict.get('FunctionType');
var typeFn = types[typeNum];
if (!typeFn)
if (!typeFn) {
error('Unknown type of function');
}
return typeFn.call(this, fn, dict, xref);
},
@ -107,8 +110,9 @@ var PDFFunction = (function PDFFunctionClosure() {
var domain = dict.get('Domain');
var range = dict.get('Range');
if (!domain || !range)
if (!domain || !range) {
error('No domain or range');
}
var inputSize = domain.length / 2;
var outputSize = range.length / 2;
@ -136,10 +140,11 @@ var PDFFunction = (function PDFFunctionClosure() {
encode = toMultiArray(encode);
var decode = dict.get('Decode');
if (!decode)
if (!decode) {
decode = range;
else
} else {
decode = toMultiArray(decode);
}
var samples = this.getSampleArray(size, outputSize, bps, str);
@ -167,9 +172,10 @@ var PDFFunction = (function PDFFunctionClosure() {
var mask = IR[8];
var range = IR[9];
if (m != args.length)
if (m != args.length) {
error('Incorrect number of arguments: ' + m + ' != ' +
args.length);
}
var x = args;
@ -178,8 +184,9 @@ var PDFFunction = (function PDFFunctionClosure() {
var cubeVertices = 1 << m;
var cubeN = new Float64Array(cubeVertices);
var cubeVertex = new Uint32Array(cubeVertices);
for (var j = 0; j < cubeVertices; j++)
for (var j = 0; j < cubeVertices; j++) {
cubeN[j] = 1;
}
var k = n, pos = 1;
// 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) {
// Sum all cube vertices' samples portions
var rj = 0;
for (var i = 0; i < cubeVertices; i++)
for (var i = 0; i < cubeVertices; i++) {
rj += samples[cubeVertex[i] + j] * cubeN[i];
}
// r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
// Decode_2j, Decode_2j+1)
@ -243,13 +251,15 @@ var PDFFunction = (function PDFFunctionClosure() {
var c1 = dict.get('C1') || [1];
var n = dict.get('N');
if (!isArray(c0) || !isArray(c1))
if (!isArray(c0) || !isArray(c1)) {
error('Illegal dictionary for interpolated function');
}
var length = c0.length;
var diff = [];
for (var i = 0; i < length; ++i)
for (var i = 0; i < length; ++i) {
diff.push(c1[i] - c0[i]);
}
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 out = [];
for (var j = 0; j < length; ++j)
for (var j = 0; j < length; ++j) {
out.push(c0[j] + (x * diff[j]));
}
return out;
@ -277,17 +288,20 @@ var PDFFunction = (function PDFFunctionClosure() {
constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
var domain = dict.get('Domain');
if (!domain)
if (!domain) {
error('No domain');
}
var inputSize = domain.length / 2;
if (inputSize != 1)
if (inputSize != 1) {
error('Bad domain for stiched function');
}
var fnRefs = dict.get('Functions');
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])));
}
var bounds = dict.get('Bounds');
var encode = dict.get('Encode');
@ -308,10 +322,11 @@ var PDFFunction = (function PDFFunctionClosure() {
return function constructStichedFromIRResult(args) {
var clip = function constructStichedFromIRClip(v, min, max) {
if (v > max)
if (v > max) {
v = max;
else if (v < min)
} else if (v < min) {
v = min;
}
return v;
};
@ -319,17 +334,20 @@ var PDFFunction = (function PDFFunctionClosure() {
var v = clip(args[0], domain[0], domain[1]);
// calulate which bound the value is in
for (var i = 0, ii = bounds.length; i < ii; ++i) {
if (v < bounds[i])
if (v < bounds[i]) {
break;
}
}
// encode value into domain of function
var dmin = domain[0];
if (i > 0)
if (i > 0) {
dmin = bounds[i - 1];
}
var dmax = domain[1];
if (i < bounds.length)
if (i < bounds.length) {
dmax = bounds[i];
}
var rmin = encode[2 * i];
var rmax = encode[2 * i + 1];
@ -346,11 +364,13 @@ var PDFFunction = (function PDFFunctionClosure() {
var domain = dict.get('Domain');
var range = dict.get('Range');
if (!domain)
if (!domain) {
error('No domain.');
}
if (!range)
if (!range) {
error('No range.');
}
var lexer = new PostScriptLexer(fn);
var parser = new PostScriptParser(lexer);
@ -376,18 +396,20 @@ var PDFFunction = (function PDFFunctionClosure() {
}
var key = initialStack.join('_');
if (cache.has(key))
if (cache.has(key)) {
return cache.get(key);
}
var stack = evaluator.execute(initialStack);
var transformed = [];
for (i = numOutputs - 1; i >= 0; --i) {
var out = stack.pop();
var rangeIndex = 2 * i;
if (out < range[rangeIndex])
if (out < range[rangeIndex]) {
out = range[rangeIndex];
else if (out > range[rangeIndex + 1])
} else if (out > range[rangeIndex + 1]) {
out = range[rangeIndex + 1];
}
transformed[i] = out;
}
cache.set(key, transformed);
@ -430,21 +452,25 @@ var PostScriptStack = (function PostScriptStackClosure() {
PostScriptStack.prototype = {
push: function PostScriptStack_push(value) {
if (this.stack.length >= MAX_STACK_SIZE)
if (this.stack.length >= MAX_STACK_SIZE) {
error('PostScript function stack overflow.');
}
this.stack.push(value);
},
pop: function PostScriptStack_pop() {
if (this.stack.length <= 0)
if (this.stack.length <= 0) {
error('PostScript function stack underflow.');
}
return this.stack.pop();
},
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.');
}
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]);
}
},
index: function PostScriptStack_index(n) {
this.push(this.stack[this.stack.length - n - 1]);
@ -490,8 +516,9 @@ var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
case 'jz': // jump if false
b = stack.pop();
a = stack.pop();
if (!a)
if (!a) {
counter = b;
}
break;
case 'j': // jump
a = stack.pop();
@ -511,10 +538,11 @@ var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
case 'and':
b = stack.pop();
a = stack.pop();
if (isBool(a) && isBool(b))
if (isBool(a) && isBool(b)) {
stack.push(a && b);
else
} else {
stack.push(a & b);
}
break;
case 'atan':
a = stack.pop();
@ -523,10 +551,11 @@ var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
case 'bitshift':
b = stack.pop();
a = stack.pop();
if (a > 0)
if (a > 0) {
stack.push(a << b);
else
} else {
stack.push(a >> b);
}
break;
case 'ceiling':
a = stack.pop();
@ -633,18 +662,20 @@ var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
break;
case 'not':
a = stack.pop();
if (isBool(a) && isBool(b))
if (isBool(a) && isBool(b)) {
stack.push(a && b);
else
} else {
stack.push(a & b);
}
break;
case 'or':
b = stack.pop();
a = stack.pop();
if (isBool(a) && isBool(b))
if (isBool(a) && isBool(b)) {
stack.push(a || b);
else
} else {
stack.push(a | b);
}
break;
case 'pop':
stack.pop();
@ -682,10 +713,11 @@ var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
case 'xor':
b = stack.pop();
a = stack.pop();
if (isBool(a) && isBool(b))
if (isBool(a) && isBool(b)) {
stack.push(a != b);
else
} else {
stack.push(a ^ b);
}
break;
default:
error('Unknown operator ' + operator);