Convert the Linearization
class in src/core/parser.js
to ES6 syntax
Moreover, disable `var` usage for this file.
This commit is contained in:
parent
8d4d7dbf58
commit
7d3cb19571
@ -12,6 +12,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
/* eslint no-var: error */
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Ascii85Stream, AsciiHexStream, FlateStream, LZWStream, NullStream,
|
Ascii85Stream, AsciiHexStream, FlateStream, LZWStream, NullStream,
|
||||||
@ -1172,55 +1173,61 @@ class Lexer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var Linearization = {
|
class Linearization {
|
||||||
create: function LinearizationCreate(stream) {
|
static create(stream) {
|
||||||
function getInt(name, allowZeroValue) {
|
function getInt(linDict, name, allowZeroValue = false) {
|
||||||
var obj = linDict.get(name);
|
const obj = linDict.get(name);
|
||||||
if (Number.isInteger(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
|
if (Number.isInteger(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
throw new Error('The "' + name + '" parameter in the linearization ' +
|
throw new Error(`The "${name}" parameter in the linearization ` +
|
||||||
'dictionary is invalid.');
|
'dictionary is invalid.');
|
||||||
}
|
}
|
||||||
function getHints() {
|
|
||||||
var hints = linDict.get('H'), hintsLength, item;
|
function getHints(linDict) {
|
||||||
|
const hints = linDict.get('H');
|
||||||
|
let hintsLength;
|
||||||
|
|
||||||
if (Array.isArray(hints) &&
|
if (Array.isArray(hints) &&
|
||||||
((hintsLength = hints.length) === 2 || hintsLength === 4)) {
|
((hintsLength = hints.length) === 2 || hintsLength === 4)) {
|
||||||
for (var index = 0; index < hintsLength; index++) {
|
for (let index = 0; index < hintsLength; index++) {
|
||||||
if (!(Number.isInteger(item = hints[index]) && item > 0)) {
|
const hint = hints[index];
|
||||||
throw new Error('Hint (' + index +
|
if (!(Number.isInteger(hint) && hint > 0)) {
|
||||||
') in the linearization dictionary is invalid.');
|
throw new Error(`Hint (${index}) in the linearization dictionary ` +
|
||||||
|
'is invalid.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return hints;
|
return hints;
|
||||||
}
|
}
|
||||||
throw new Error('Hint array in the linearization dictionary is invalid.');
|
throw new Error('Hint array in the linearization dictionary is invalid.');
|
||||||
}
|
}
|
||||||
var parser = new Parser(new Lexer(stream), false, null);
|
|
||||||
var obj1 = parser.getObj();
|
const parser = new Parser(new Lexer(stream), false, null);
|
||||||
var obj2 = parser.getObj();
|
const obj1 = parser.getObj();
|
||||||
var obj3 = parser.getObj();
|
const obj2 = parser.getObj();
|
||||||
var linDict = parser.getObj();
|
const obj3 = parser.getObj();
|
||||||
var obj, length;
|
const linDict = parser.getObj();
|
||||||
|
let obj, length;
|
||||||
if (!(Number.isInteger(obj1) && Number.isInteger(obj2) &&
|
if (!(Number.isInteger(obj1) && Number.isInteger(obj2) &&
|
||||||
isCmd(obj3, 'obj') && isDict(linDict) &&
|
isCmd(obj3, 'obj') && isDict(linDict) &&
|
||||||
isNum(obj = linDict.get('Linearized')) && obj > 0)) {
|
isNum(obj = linDict.get('Linearized')) && obj > 0)) {
|
||||||
return null; // No valid linearization dictionary found.
|
return null; // No valid linearization dictionary found.
|
||||||
} else if ((length = getInt('L')) !== stream.length) {
|
} else if ((length = getInt(linDict, 'L')) !== stream.length) {
|
||||||
throw new Error('The "L" parameter in the linearization dictionary ' +
|
throw new Error('The "L" parameter in the linearization dictionary ' +
|
||||||
'does not equal the stream length.');
|
'does not equal the stream length.');
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
length,
|
length,
|
||||||
hints: getHints(),
|
hints: getHints(linDict),
|
||||||
objectNumberFirst: getInt('O'),
|
objectNumberFirst: getInt(linDict, 'O'),
|
||||||
endFirst: getInt('E'),
|
endFirst: getInt(linDict, 'E'),
|
||||||
numPages: getInt('N'),
|
numPages: getInt(linDict, 'N'),
|
||||||
mainXRefEntriesOffset: getInt('T'),
|
mainXRefEntriesOffset: getInt(linDict, 'T'),
|
||||||
pageFirst: (linDict.has('P') ? getInt('P', true) : 0),
|
pageFirst: (linDict.has('P') ?
|
||||||
};
|
getInt(linDict, 'P', /* allowZeroValue = */ true) : 0),
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
Lexer,
|
Lexer,
|
||||||
|
Loading…
Reference in New Issue
Block a user