Browse Source

Merge pull request #4414 from Snuffleupagus/src-shared-braces

Add braces to single line statements in src/shared
Tim van der Meij 11 years ago
parent
commit
df2248d5b9
  1. 6
      src/shared/annotation.js
  2. 45
      src/shared/colorspace.js
  3. 27
      src/shared/fonts_utils.js
  4. 112
      src/shared/function.js
  5. 48
      src/shared/util.js

6
src/shared/annotation.js

@ -401,9 +401,10 @@ var WidgetAnnotation = (function WidgetAnnotationClosure() {
var j, jj; var j, jj;
for (j = 0, jj = kids.length; j < jj; j++) { for (j = 0, jj = kids.length; j < jj; j++) {
var kidRef = kids[j]; var kidRef = kids[j];
if (kidRef.num == ref.num && kidRef.gen == ref.gen) if (kidRef.num == ref.num && kidRef.gen == ref.gen) {
break; break;
} }
}
fieldName.unshift('`' + j); fieldName.unshift('`' + j);
} }
namedItem = parent; namedItem = parent;
@ -695,9 +696,10 @@ var TextAnnotation = (function TextAnnotationClosure() {
for (var i = 0, ii = lines.length; i < ii; ++i) { for (var i = 0, ii = lines.length; i < ii; ++i) {
var line = lines[i]; var line = lines[i];
e.appendChild(document.createTextNode(line)); e.appendChild(document.createTextNode(line));
if (i < (ii - 1)) if (i < (ii - 1)) {
e.appendChild(document.createElement('br')); e.appendChild(document.createElement('br'));
} }
}
text.appendChild(e); text.appendChild(e);
var pinned = false; var pinned = false;

45
src/shared/colorspace.js

@ -166,9 +166,9 @@ var ColorSpace = (function ColorSpaceClosure() {
ColorSpace.parse = function ColorSpace_parse(cs, xref, res) { ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
var IR = ColorSpace.parseToIR(cs, xref, res); var IR = ColorSpace.parseToIR(cs, xref, res);
if (IR instanceof AlternateCS) if (IR instanceof AlternateCS) {
return IR; return IR;
}
return ColorSpace.fromIR(IR); return ColorSpace.fromIR(IR);
}; };
@ -189,8 +189,9 @@ var ColorSpace = (function ColorSpaceClosure() {
return new CalGrayCS(whitePoint, blackPoint, gamma); return new CalGrayCS(whitePoint, blackPoint, gamma);
case 'PatternCS': case 'PatternCS':
var basePatternCS = IR[1]; var basePatternCS = IR[1];
if (basePatternCS) if (basePatternCS) {
basePatternCS = ColorSpace.fromIR(basePatternCS); basePatternCS = ColorSpace.fromIR(basePatternCS);
}
return new PatternCS(basePatternCS); return new PatternCS(basePatternCS);
case 'IndexedCS': case 'IndexedCS':
var baseIndexedCS = IR[1]; var baseIndexedCS = IR[1];
@ -220,10 +221,11 @@ var ColorSpace = (function ColorSpaceClosure() {
var colorSpaces = res.get('ColorSpace'); var colorSpaces = res.get('ColorSpace');
if (isDict(colorSpaces)) { if (isDict(colorSpaces)) {
var refcs = colorSpaces.get(cs.name); var refcs = colorSpaces.get(cs.name);
if (refcs) if (refcs) {
cs = refcs; cs = refcs;
} }
} }
}
cs = xref.fetchIfRef(cs); cs = xref.fetchIfRef(cs);
var mode; var mode;
@ -270,17 +272,19 @@ var ColorSpace = (function ColorSpaceClosure() {
var stream = xref.fetchIfRef(cs[1]); var stream = xref.fetchIfRef(cs[1]);
var dict = stream.dict; var dict = stream.dict;
var numComps = dict.get('N'); var numComps = dict.get('N');
if (numComps == 1) if (numComps == 1) {
return 'DeviceGrayCS'; return 'DeviceGrayCS';
if (numComps == 3) } else if (numComps == 3) {
return 'DeviceRgbCS'; return 'DeviceRgbCS';
if (numComps == 4) } else if (numComps == 4) {
return 'DeviceCmykCS'; return 'DeviceCmykCS';
}
break; break;
case 'Pattern': case 'Pattern':
var basePatternCS = cs[1]; var basePatternCS = cs[1];
if (basePatternCS) if (basePatternCS) {
basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res); basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
}
return ['PatternCS', basePatternCS]; return ['PatternCS', basePatternCS];
case 'Indexed': case 'Indexed':
case 'I': case 'I':
@ -295,10 +299,11 @@ var ColorSpace = (function ColorSpaceClosure() {
case 'DeviceN': case 'DeviceN':
var name = cs[1]; var name = cs[1];
var numComps = 1; var numComps = 1;
if (isName(name)) if (isName(name)) {
numComps = 1; numComps = 1;
else if (isArray(name)) } else if (isArray(name)) {
numComps = name.length; numComps = name.length;
}
var alt = ColorSpace.parseToIR(cs[2], xref, res); var alt = ColorSpace.parseToIR(cs[2], xref, res);
var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3])); var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
return ['AlternateCS', numComps, alt, tintFnIR]; return ['AlternateCS', numComps, alt, tintFnIR];
@ -323,17 +328,19 @@ var ColorSpace = (function ColorSpaceClosure() {
* @param {Number} n Number of components the color space has. * @param {Number} n Number of components the color space has.
*/ */
ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) { ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
if (!decode) if (!decode) {
return true; return true;
}
if (n * 2 !== decode.length) { if (n * 2 !== decode.length) {
warn('The decode map is not the correct length'); warn('The decode map is not the correct length');
return true; return true;
} }
for (var i = 0, ii = decode.length; i < ii; i += 2) { for (var i = 0, ii = decode.length; i < ii; i += 2) {
if (decode[i] !== 0 || decode[i + 1] != 1) if (decode[i] !== 0 || decode[i + 1] != 1) {
return false; return false;
} }
}
return true; return true;
}; };
@ -459,8 +466,9 @@ var IndexedCS = (function IndexedCSClosure() {
lookupArray.set(bytes); lookupArray.set(bytes);
} else if (isString(lookup)) { } else if (isString(lookup)) {
lookupArray = new Uint8Array(length); lookupArray = new Uint8Array(length);
for (var i = 0; i < length; ++i) for (var i = 0; i < length; ++i) {
lookupArray[i] = lookup.charCodeAt(i); lookupArray[i] = lookup.charCodeAt(i);
}
} else if (lookup instanceof Uint8Array || lookup instanceof Array) { } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
lookupArray = lookup; lookupArray = lookup;
} else { } else {
@ -793,8 +801,9 @@ var LabCS = (function LabCSClosure() {
this.numComps = 3; this.numComps = 3;
this.defaultColor = new Float32Array([0, 0, 0]); this.defaultColor = new Float32Array([0, 0, 0]);
if (!whitePoint) if (!whitePoint) {
error('WhitePoint missing - required for color space Lab'); error('WhitePoint missing - required for color space Lab');
}
blackPoint = blackPoint || [0, 0, 0]; blackPoint = blackPoint || [0, 0, 0];
range = range || [-100, 100, -100, 100]; range = range || [-100, 100, -100, 100];
@ -814,8 +823,9 @@ var LabCS = (function LabCSClosure() {
this.ZB = blackPoint[2]; this.ZB = blackPoint[2];
// Validate vars as per spec // Validate vars as per spec
if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
error('Invalid WhitePoint components, no fallback available'); error('Invalid WhitePoint components, no fallback available');
}
if (this.XB < 0 || this.YB < 0 || this.ZB < 0) { if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
info('Invalid BlackPoint, falling back to default'); info('Invalid BlackPoint, falling back to default');
@ -833,11 +843,12 @@ var LabCS = (function LabCSClosure() {
// Function g(x) from spec // Function g(x) from spec
function fn_g(x) { function fn_g(x) {
if (x >= 6 / 29) if (x >= 6 / 29) {
return x * x * x; return x * x * x;
else } else {
return (108 / 841) * (x - 4 / 29); return (108 / 841) * (x - 4 / 29);
} }
}
function decode(value, high1, low2, high2) { function decode(value, high1, low2, high2) {
return low2 + (value) * (high2 - low2) / (high1); return low2 + (value) * (high2 - low2) / (high1);

27
src/shared/fonts_utils.js

@ -67,8 +67,9 @@ function readCharset(aStream, aCharstrings) {
* chapter 3.1. * chapter 3.1.
*/ */
function readCharstringEncoding(aString) { function readCharstringEncoding(aString) {
if (!aString) if (!aString) {
return ''; return '';
}
var charstringTokens = []; var charstringTokens = [];
@ -222,8 +223,9 @@ function readFontIndexData(aStream, aIsByte) {
} }
var offsets = []; var offsets = [];
for (var i = 0; i < count + 1; i++) for (var i = 0; i < count + 1; i++) {
offsets.push(getNextOffset()); offsets.push(getNextOffset());
}
dump('Found ' + count + ' objects at offsets :' + dump('Found ' + count + ' objects at offsets :' +
offsets + ' (offsize: ' + offsize + ')'); offsets + ' (offsize: ' + offsize + ')');
@ -237,8 +239,9 @@ function readFontIndexData(aStream, aIsByte) {
var data = []; var data = [];
var length = offsets[i + 1] - 1; var length = offsets[i + 1] - 1;
for (var j = offset - 1; j < length; j++) for (var j = offset - 1; j < length; j++) {
data.push(aIsByte ? aStream.getByte() : aStream.getChar()); data.push(aIsByte ? aStream.getByte() : aStream.getChar());
}
objects.push(data); objects.push(data);
} }
@ -294,8 +297,9 @@ var Type2Parser = function type2Parser(aFilePath) {
default: default:
if (token.operand && token.operand.length) { if (token.operand && token.operand.length) {
var array = []; var array = [];
for (var j = 0; j < token.operand.length; j++) for (var j = 0; j < token.operand.length; j++) {
array.push(stack.pop()); array.push(stack.pop());
}
font.set(token.name, array); font.set(token.name, array);
} else { } else {
font.set(token.name, stack.pop()); font.set(token.name, stack.pop());
@ -328,14 +332,16 @@ var Type2Parser = function type2Parser(aFilePath) {
dump('strings: ' + strings); dump('strings: ' + strings);
// Fill up the Strings dictionary with the new unique strings // Fill up the Strings dictionary with the new unique strings
for (var i = 0; i < strings.length; i++) for (var i = 0; i < strings.length; i++) {
CFFStrings.push(strings[i].join('')); CFFStrings.push(strings[i].join(''));
}
// Parse the TopDict operator // Parse the TopDict operator
var objects = []; var objects = [];
var count = topDict.length; var count = topDict.length;
for (var i = 0; i < count; i++) for (var i = 0; i < count; i++) {
parseAsToken(topDict[i], CFFDictDataMap); parseAsToken(topDict[i], CFFDictDataMap);
}
// Read the Global Subr Index that comes just after the Strings Index // Read the Global Subr Index that comes just after the Strings Index
// (cf. "The Compact Font Format Specification" Chapter 16) // (cf. "The Compact Font Format Specification" Chapter 16)
@ -350,13 +356,15 @@ var Type2Parser = function type2Parser(aFilePath) {
aStream.pos = priv.offset; aStream.pos = priv.offset;
var privateDict = []; var privateDict = [];
for (var i = 0; i < priv.size; i++) for (var i = 0; i < priv.size; i++) {
privateDict.push(aStream.getByte()); privateDict.push(aStream.getByte());
}
dump('privateData:' + privateDict); dump('privateData:' + privateDict);
parseAsToken(privateDict, CFFDictPrivateDataMap); parseAsToken(privateDict, CFFDictPrivateDataMap);
for (var p in font.map) for (var p in font.map) {
dump(p + '::' + font.get(p)); dump(p + '::' + font.get(p));
}
// Read CharStrings Index // Read CharStrings Index
var charStringsOffset = font.get('CharStrings'); var charStringsOffset = font.get('CharStrings');
@ -402,8 +410,9 @@ var Type2Parser = function type2Parser(aFilePath) {
* writeToFile(fontData, "/tmp/pdf.js." + fontCount + ".cff"); * writeToFile(fontData, "/tmp/pdf.js." + fontCount + ".cff");
*/ */
function writeToFile(aBytes, aFilePath) { function writeToFile(aBytes, aFilePath) {
if (!('netscape' in window)) if (!('netscape' in window)) {
return; return;
}
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var Cc = Components.classes, var Cc = Components.classes,

112
src/shared/function.js

@ -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);

48
src/shared/util.js

@ -195,8 +195,9 @@ function backtrace() {
} }
function assert(cond, msg) { function assert(cond, msg) {
if (!cond) if (!cond) {
error(msg); error(msg);
}
} }
var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = { var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = {
@ -227,10 +228,12 @@ var UnsupportedManager = PDFJS.UnsupportedManager =
// Combines two URLs. The baseUrl shall be absolute URL. If the url is an // Combines two URLs. The baseUrl shall be absolute URL. If the url is an
// absolute URL, it will be returned as is. // absolute URL, it will be returned as is.
function combineUrl(baseUrl, url) { function combineUrl(baseUrl, url) {
if (!url) if (!url) {
return baseUrl; return baseUrl;
if (/^[a-z][a-z0-9+\-.]*:/i.test(url)) }
if (/^[a-z][a-z0-9+\-.]*:/i.test(url)) {
return url; return url;
}
if (url.charAt(0) == '/') { if (url.charAt(0) == '/') {
// absolute path // absolute path
var i = baseUrl.indexOf('://'); var i = baseUrl.indexOf('://');
@ -279,8 +282,9 @@ PDFJS.isValidUrl = isValidUrl;
// In a well-formed PDF, |cond| holds. If it doesn't, subsequent // In a well-formed PDF, |cond| holds. If it doesn't, subsequent
// behavior is undefined. // behavior is undefined.
function assertWellFormed(cond, msg) { function assertWellFormed(cond, msg) {
if (!cond) if (!cond) {
error(msg); error(msg);
}
} }
function shadow(obj, prop, value) { function shadow(obj, prop, value) {
@ -397,8 +401,9 @@ function bytesToString(bytes) {
function stringToBytes(str) { function stringToBytes(str) {
var length = str.length; var length = str.length;
var bytes = new Uint8Array(length); var bytes = new Uint8Array(length);
for (var n = 0; n < length; ++n) for (var n = 0; n < length; ++n) {
bytes[n] = str.charCodeAt(n) & 0xFF; bytes[n] = str.charCodeAt(n) & 0xFF;
}
return bytes; return bytes;
} }
@ -802,14 +807,15 @@ function isRef(v) {
function isPDFFunction(v) { function isPDFFunction(v) {
var fnDict; var fnDict;
if (typeof v != 'object') if (typeof v != 'object') {
return false; return false;
else if (isDict(v)) } else if (isDict(v)) {
fnDict = v; fnDict = v;
else if (isStream(v)) } else if (isStream(v)) {
fnDict = v.dict; fnDict = v.dict;
else } else {
return false; return false;
}
return fnDict.has('FunctionType'); return fnDict.has('FunctionType');
} }
@ -1030,8 +1036,9 @@ var LegacyPromise = PDFJS.LegacyPromise = (function LegacyPromiseClosure() {
} }
results[i] = value; results[i] = value;
unresolved--; unresolved--;
if (unresolved === 0) if (unresolved === 0) {
resolveAll(results); resolveAll(results);
}
}; };
})(i); })(i);
if (Promise.isPromise(promise)) { if (Promise.isPromise(promise)) {
@ -1121,8 +1128,9 @@ var LegacyPromise = PDFJS.LegacyPromise = (function LegacyPromiseClosure() {
var StatTimer = (function StatTimerClosure() { var StatTimer = (function StatTimerClosure() {
function rpad(str, pad, length) { function rpad(str, pad, length) {
while (str.length < length) while (str.length < length) {
str += pad; str += pad;
}
return str; return str;
} }
function StatTimer() { function StatTimer() {
@ -1132,17 +1140,21 @@ var StatTimer = (function StatTimerClosure() {
} }
StatTimer.prototype = { StatTimer.prototype = {
time: function StatTimer_time(name) { time: function StatTimer_time(name) {
if (!this.enabled) if (!this.enabled) {
return; return;
if (name in this.started) }
if (name in this.started) {
warn('Timer is already running for ' + name); warn('Timer is already running for ' + name);
}
this.started[name] = Date.now(); this.started[name] = Date.now();
}, },
timeEnd: function StatTimer_timeEnd(name) { timeEnd: function StatTimer_timeEnd(name) {
if (!this.enabled) if (!this.enabled) {
return; return;
if (!(name in this.started)) }
if (!(name in this.started)) {
warn('Timer has not been started for ' + name); warn('Timer has not been started for ' + name);
}
this.times.push({ this.times.push({
'name': name, 'name': name,
'start': this.started[name], 'start': this.started[name],
@ -1158,9 +1170,10 @@ var StatTimer = (function StatTimerClosure() {
var longest = 0; var longest = 0;
for (var i = 0, ii = times.length; i < ii; ++i) { for (var i = 0, ii = times.length; i < ii; ++i) {
var name = times[i]['name']; var name = times[i]['name'];
if (name.length > longest) if (name.length > longest) {
longest = name.length; longest = name.length;
} }
}
for (var i = 0, ii = times.length; i < ii; ++i) { for (var i = 0, ii = times.length; i < ii; ++i) {
var span = times[i]; var span = times[i];
var duration = span.end - span.start; var duration = span.end - span.start;
@ -1173,8 +1186,9 @@ var StatTimer = (function StatTimerClosure() {
})(); })();
PDFJS.createBlob = function createBlob(data, contentType) { PDFJS.createBlob = function createBlob(data, contentType) {
if (typeof Blob !== 'undefined') if (typeof Blob !== 'undefined') {
return new Blob([data], { type: contentType }); return new Blob([data], { type: contentType });
}
// Blob builder is deprecated in FF14 and removed in FF18. // Blob builder is deprecated in FF14 and removed in FF18.
var bb = new MozBlobBuilder(); var bb = new MozBlobBuilder();
bb.append(data); bb.append(data);

Loading…
Cancel
Save