Browse Source

Fixes lint warning W004 in src/shared

Tim van der Meij 11 years ago
parent
commit
10f80bda23
  1. 9
      src/shared/annotation.js
  2. 49
      src/shared/colorspace.js
  3. 21
      src/shared/fonts_utils.js
  4. 16
      src/shared/function.js
  5. 10
      src/shared/util.js
  6. 2
      test/reporter.js

9
src/shared/annotation.js

@ -112,7 +112,8 @@ var Annotation = (function AnnotationClosure() {
var isInvalid = false; var isInvalid = false;
var numPositive = 0; var numPositive = 0;
for (var i = 0; i < dashArrayLength; i++) { for (var i = 0; i < dashArrayLength; i++) {
if (+dashArray[i] < 0) { var validNumber = (+dashArray[i] >= 0);
if (!validNumber) {
isInvalid = true; isInvalid = true;
break; break;
} else if (dashArray[i] > 0) { } else if (dashArray[i] > 0) {
@ -673,10 +674,12 @@ var TextAnnotation = (function TextAnnotationClosure() {
var content = document.createElement('div'); var content = document.createElement('div');
content.className = 'annotTextContent'; content.className = 'annotTextContent';
content.setAttribute('hidden', true); content.setAttribute('hidden', true);
var i, ii;
if (item.hasBgColor) { if (item.hasBgColor) {
var color = item.color; var color = item.color;
var rgb = []; var rgb = [];
for (var i = 0; i < 3; ++i) { for (i = 0; i < 3; ++i) {
// Enlighten the color (70%) // Enlighten the color (70%)
var c = Math.round(color[i] * 255); var c = Math.round(color[i] * 255);
rgb[i] = Math.round((255 - c) * 0.7) + c; rgb[i] = Math.round((255 - c) * 0.7) + c;
@ -693,7 +696,7 @@ var TextAnnotation = (function TextAnnotationClosure() {
} else { } else {
var e = document.createElement('span'); var e = document.createElement('span');
var lines = item.content.split(/(?:\r\n?|\n)/); var lines = item.content.split(/(?:\r\n?|\n)/);
for (var i = 0, ii = lines.length; i < ii; ++i) { for (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)) {

49
src/shared/colorspace.js

@ -85,10 +85,10 @@ var ColorSpace = (function ColorSpaceClosure() {
var rgbBuf = null; var rgbBuf = null;
var numComponentColors = 1 << bpc; var numComponentColors = 1 << bpc;
var needsResizing = originalHeight != height || originalWidth != width; var needsResizing = originalHeight != height || originalWidth != width;
var i, ii;
if (this.isPassthrough(bpc)) { if (this.isPassthrough(bpc)) {
rgbBuf = comps; rgbBuf = comps;
} else if (this.numComps === 1 && count > numComponentColors && } else if (this.numComps === 1 && count > numComponentColors &&
this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') { this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
// Optimization: create a color map when there is just one component and // Optimization: create a color map when there is just one component and
@ -102,18 +102,20 @@ var ColorSpace = (function ColorSpaceClosure() {
// we are reparsing colorspaces too much?). // we are reparsing colorspaces too much?).
var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) : var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
new Uint16Array(numComponentColors); new Uint16Array(numComponentColors);
for (var i = 0; i < numComponentColors; i++) { var key;
for (i = 0; i < numComponentColors; i++) {
allColors[i] = i; allColors[i] = i;
} }
var colorMap = new Uint8Array(numComponentColors * 3); var colorMap = new Uint8Array(numComponentColors * 3);
this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc, this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
/* alpha01 = */ 0); /* alpha01 = */ 0);
var destPos, rgbPos;
if (!needsResizing) { if (!needsResizing) {
// Fill in the RGB values directly into |dest|. // Fill in the RGB values directly into |dest|.
var destPos = 0; destPos = 0;
for (var i = 0; i < count; ++i) { for (i = 0; i < count; ++i) {
var key = comps[i] * 3; key = comps[i] * 3;
dest[destPos++] = colorMap[key]; dest[destPos++] = colorMap[key];
dest[destPos++] = colorMap[key + 1]; dest[destPos++] = colorMap[key + 1];
dest[destPos++] = colorMap[key + 2]; dest[destPos++] = colorMap[key + 2];
@ -121,9 +123,9 @@ var ColorSpace = (function ColorSpaceClosure() {
} }
} else { } else {
rgbBuf = new Uint8Array(count * 3); rgbBuf = new Uint8Array(count * 3);
var rgbPos = 0; rgbPos = 0;
for (var i = 0; i < count; ++i) { for (i = 0; i < count; ++i) {
var key = comps[i] * 3; key = comps[i] * 3;
rgbBuf[rgbPos++] = colorMap[key]; rgbBuf[rgbPos++] = colorMap[key];
rgbBuf[rgbPos++] = colorMap[key + 1]; rgbBuf[rgbPos++] = colorMap[key + 1];
rgbBuf[rgbPos++] = colorMap[key + 2]; rgbBuf[rgbPos++] = colorMap[key + 2];
@ -146,9 +148,9 @@ var ColorSpace = (function ColorSpaceClosure() {
rgbBuf = PDFImage.resize(rgbBuf, bpc, 3, originalWidth, rgbBuf = PDFImage.resize(rgbBuf, bpc, 3, originalWidth,
originalHeight, width, height); originalHeight, width, height);
} }
var rgbPos = 0; rgbPos = 0;
var destPos = 0; destPos = 0;
for (var i = 0, ii = width * actualHeight; i < ii; i++) { for (i = 0, ii = width * actualHeight; i < ii; i++) {
dest[destPos++] = rgbBuf[rgbPos++]; dest[destPos++] = rgbBuf[rgbPos++];
dest[destPos++] = rgbBuf[rgbPos++]; dest[destPos++] = rgbBuf[rgbPos++];
dest[destPos++] = rgbBuf[rgbPos++]; dest[destPos++] = rgbBuf[rgbPos++];
@ -174,6 +176,7 @@ var ColorSpace = (function ColorSpaceClosure() {
ColorSpace.fromIR = function ColorSpace_fromIR(IR) { ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
var name = isArray(IR) ? IR[0] : IR; var name = isArray(IR) ? IR[0] : IR;
var whitePoint, blackPoint;
switch (name) { switch (name) {
case 'DeviceGrayCS': case 'DeviceGrayCS':
@ -183,8 +186,8 @@ var ColorSpace = (function ColorSpaceClosure() {
case 'DeviceCmykCS': case 'DeviceCmykCS':
return this.singletons.cmyk; return this.singletons.cmyk;
case 'CalGrayCS': case 'CalGrayCS':
var whitePoint = IR[1].WhitePoint; whitePoint = IR[1].WhitePoint;
var blackPoint = IR[1].BlackPoint; blackPoint = IR[1].BlackPoint;
var gamma = IR[1].Gamma; var gamma = IR[1].Gamma;
return new CalGrayCS(whitePoint, blackPoint, gamma); return new CalGrayCS(whitePoint, blackPoint, gamma);
case 'PatternCS': case 'PatternCS':
@ -206,8 +209,8 @@ var ColorSpace = (function ColorSpaceClosure() {
return new AlternateCS(numComps, ColorSpace.fromIR(alt), return new AlternateCS(numComps, ColorSpace.fromIR(alt),
PDFFunction.fromIR(tintFnIR)); PDFFunction.fromIR(tintFnIR));
case 'LabCS': case 'LabCS':
var whitePoint = IR[1].WhitePoint; whitePoint = IR[1].WhitePoint;
var blackPoint = IR[1].BlackPoint; blackPoint = IR[1].BlackPoint;
var range = IR[1].Range; var range = IR[1].Range;
return new LabCS(whitePoint, blackPoint, range); return new LabCS(whitePoint, blackPoint, range);
default: default:
@ -252,6 +255,7 @@ var ColorSpace = (function ColorSpaceClosure() {
} else if (isArray(cs)) { } else if (isArray(cs)) {
mode = cs[0].name; mode = cs[0].name;
this.mode = mode; this.mode = mode;
var numComps, params;
switch (mode) { switch (mode) {
case 'DeviceGray': case 'DeviceGray':
@ -264,14 +268,14 @@ var ColorSpace = (function ColorSpaceClosure() {
case 'CMYK': case 'CMYK':
return 'DeviceCmykCS'; return 'DeviceCmykCS';
case 'CalGray': case 'CalGray':
var params = cs[1].getAll(); params = cs[1].getAll();
return ['CalGrayCS', params]; return ['CalGrayCS', params];
case 'CalRGB': case 'CalRGB':
return 'DeviceRgbCS'; return 'DeviceRgbCS';
case 'ICCBased': case 'ICCBased':
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'); numComps = dict.get('N');
if (numComps == 1) { if (numComps == 1) {
return 'DeviceGrayCS'; return 'DeviceGrayCS';
} else if (numComps == 3) { } else if (numComps == 3) {
@ -298,7 +302,7 @@ var ColorSpace = (function ColorSpaceClosure() {
case 'Separation': case 'Separation':
case 'DeviceN': case 'DeviceN':
var name = cs[1]; var name = cs[1];
var numComps = 1; numComps = 1;
if (isName(name)) { if (isName(name)) {
numComps = 1; numComps = 1;
} else if (isArray(name)) { } else if (isArray(name)) {
@ -308,7 +312,7 @@ var ColorSpace = (function ColorSpaceClosure() {
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];
case 'Lab': case 'Lab':
var params = cs[1].getAll(); params = cs[1].getAll();
return ['LabCS', params]; return ['LabCS', params];
default: default:
error('unimplemented color space object "' + mode + '"'); error('unimplemented color space object "' + mode + '"');
@ -403,13 +407,14 @@ var AlternateCS = (function AlternateCSClosure() {
var numComps = this.numComps; var numComps = this.numComps;
var scaled = new Float32Array(numComps); var scaled = new Float32Array(numComps);
for (var i = 0; i < count; i++) { var i, j;
for (var j = 0; j < numComps; j++) { for (i = 0; i < count; i++) {
for (j = 0; j < numComps; j++) {
scaled[j] = src[srcOffset++] * scale; scaled[j] = src[srcOffset++] * scale;
} }
var tinted = tintFn(scaled); var tinted = tintFn(scaled);
if (usesZeroToOneRange) { if (usesZeroToOneRange) {
for (var j = 0; j < baseNumComps; j++) { for (j = 0; j < baseNumComps; j++) {
baseBuf[pos++] = tinted[j] * 255; baseBuf[pos++] = tinted[j] * 255;
} }
} else { } else {

21
src/shared/fonts_utils.js

@ -37,20 +37,21 @@ function readCharset(aStream, aCharstrings) {
var format = aStream.getByte(); var format = aStream.getByte();
var count = aCharstrings.length - 1; var count = aCharstrings.length - 1;
var i, sid;
if (format === 0) { if (format === 0) {
charset['.notdef'] = readCharstringEncoding(aCharstrings[0]); charset['.notdef'] = readCharstringEncoding(aCharstrings[0]);
for (var i = 1; i < count + 1; i++) { for (i = 1; i < count + 1; i++) {
var sid = aStream.getByte() << 8 | aStream.getByte(); sid = aStream.getByte() << 8 | aStream.getByte();
charset[CFFStrings[sid]] = readCharstringEncoding(aCharstrings[i]); charset[CFFStrings[sid]] = readCharstringEncoding(aCharstrings[i]);
} }
} else if (format == 1) { } else if (format == 1) {
for (var i = 1; i < count + 1; i++) { for (i = 1; i < count + 1; i++) {
var first = aStream.getByte(); var first = aStream.getByte();
first = (first << 8) | aStream.getByte(); first = (first << 8) | aStream.getByte();
var numLeft = aStream.getByte(); var numLeft = aStream.getByte();
for (var j = 0; j <= numLeft; j++) { for (var j = 0; j <= numLeft; j++) {
var sid = first++; sid = first++;
charset[CFFStrings[sid]] = readCharstringEncoding(aCharstrings[j]); charset[CFFStrings[sid]] = readCharstringEncoding(aCharstrings[j]);
} }
} }
@ -223,7 +224,8 @@ function readFontIndexData(aStream, aIsByte) {
} }
var offsets = []; var offsets = [];
for (var i = 0; i < count + 1; i++) { var i;
for (i = 0; i < count + 1; i++) {
offsets.push(getNextOffset()); offsets.push(getNextOffset());
} }
@ -233,7 +235,7 @@ function readFontIndexData(aStream, aIsByte) {
// Now extract the objects // Now extract the objects
var relativeOffset = aStream.pos; var relativeOffset = aStream.pos;
var objects = []; var objects = [];
for (var i = 0; i < count; i++) { for (i = 0; i < count; i++) {
var offset = offsets[i]; var offset = offsets[i];
aStream.pos = relativeOffset + offset - 1; aStream.pos = relativeOffset + offset - 1;
@ -332,14 +334,15 @@ 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++) { var i;
for (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 (i = 0; i < count; i++) {
parseAsToken(topDict[i], CFFDictDataMap); parseAsToken(topDict[i], CFFDictDataMap);
} }
@ -356,7 +359,7 @@ 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 (i = 0; i < priv.size; i++) {
privateDict.push(aStream.getByte()); privateDict.push(aStream.getByte());
} }
dump('privateData:' + privateDict); dump('privateData:' + privateDict);

16
src/shared/function.js

@ -27,8 +27,9 @@ var PDFFunction = (function PDFFunctionClosure() {
return { return {
getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps, getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
str) { str) {
var i, ii;
var length = 1; var length = 1;
for (var i = 0, ii = size.length; i < ii; i++) { for (i = 0, ii = size.length; i < ii; i++) {
length *= size[i]; length *= size[i];
} }
length *= outputSize; length *= outputSize;
@ -41,7 +42,7 @@ var PDFFunction = (function PDFFunctionClosure() {
var strBytes = str.getBytes((length * bps + 7) / 8); var strBytes = str.getBytes((length * bps + 7) / 8);
var strIdx = 0; var strIdx = 0;
for (var i = 0; i < length; i++) { for (i = 0; i < length; i++) {
while (codeSize < bps) { while (codeSize < bps) {
codeBuf <<= 8; codeBuf <<= 8;
codeBuf |= strBytes[strIdx++]; codeBuf |= strBytes[strIdx++];
@ -184,13 +185,14 @@ 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++) { var i, j;
for (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.
for (var i = 0; i < m; ++i) { for (i = 0; i < m; ++i) {
// x_i' = min(max(x_i, Domain_2i), Domain_2i+1) // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
var domain_2i = domain[i][0]; var domain_2i = domain[i][0];
var domain_2i_1 = domain[i][1]; var domain_2i_1 = domain[i][1];
@ -211,7 +213,7 @@ var PDFFunction = (function PDFFunctionClosure() {
var n1 = e - e0; // (e - e0) / (e1 - e0); var n1 = e - e0; // (e - e0) / (e1 - e0);
var offset0 = e0 * k; var offset0 = e0 * k;
var offset1 = offset0 + k; // e1 * k var offset1 = offset0 + k; // e1 * k
for (var j = 0; j < cubeVertices; j++) { for (j = 0; j < cubeVertices; j++) {
if (j & pos) { if (j & pos) {
cubeN[j] *= n1; cubeN[j] *= n1;
cubeVertex[j] += offset1; cubeVertex[j] += offset1;
@ -226,10 +228,10 @@ var PDFFunction = (function PDFFunctionClosure() {
} }
var y = new Float64Array(n); var y = new Float64Array(n);
for (var j = 0; j < n; ++j) { for (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 (i = 0; i < cubeVertices; i++) {
rj += samples[cubeVertex[i] + j] * cubeN[i]; rj += samples[cubeVertex[i] + j] * cubeN[i];
} }

10
src/shared/util.js

@ -237,9 +237,10 @@ function combineUrl(baseUrl, url) {
if (/^[a-z][a-z0-9+\-.]*:/i.test(url)) { if (/^[a-z][a-z0-9+\-.]*:/i.test(url)) {
return url; return url;
} }
var i;
if (url.charAt(0) == '/') { if (url.charAt(0) == '/') {
// absolute path // absolute path
var i = baseUrl.indexOf('://'); i = baseUrl.indexOf('://');
if (url.charAt(1) === '/') { if (url.charAt(1) === '/') {
++i; ++i;
} else { } else {
@ -248,7 +249,7 @@ function combineUrl(baseUrl, url) {
return baseUrl.substring(0, i) + url; return baseUrl.substring(0, i) + url;
} else { } else {
// relative path // relative path
var pathLength = baseUrl.length, i; var pathLength = baseUrl.length;
i = baseUrl.lastIndexOf('#'); i = baseUrl.lastIndexOf('#');
pathLength = i >= 0 ? i : pathLength; pathLength = i >= 0 ? i : pathLength;
i = baseUrl.lastIndexOf('?', pathLength); i = baseUrl.lastIndexOf('?', pathLength);
@ -1263,17 +1264,18 @@ var StatTimer = (function StatTimerClosure() {
delete this.started[name]; delete this.started[name];
}, },
toString: function StatTimer_toString() { toString: function StatTimer_toString() {
var i, ii;
var times = this.times; var times = this.times;
var out = ''; var out = '';
// Find the longest name for padding purposes. // Find the longest name for padding purposes.
var longest = 0; var longest = 0;
for (var i = 0, ii = times.length; i < ii; ++i) { for (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 (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;
out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n'; out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';

2
test/reporter.js

@ -28,8 +28,6 @@ module.exports = {
var err = r.error; var err = r.error;
switch (err.code) { switch (err.code) {
case 'W004': // variable is already defined
break;
default: default:
len++; len++;
str += file + ': line ' + err.line + ', col ' + str += file + ': line ' + err.line + ', col ' +

Loading…
Cancel
Save