1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08:06 +02:00

Merge pull request #3424 from yurydelendik/lookChar

lookChar refactoring
This commit is contained in:
Brendan Dahl 2013-07-11 09:08:59 -07:00
commit 5dcc4cd1b4
8 changed files with 251 additions and 272 deletions

View file

@ -3562,8 +3562,9 @@ var Font = (function FontClosure() {
while (font.pos < end) {
var stringLength = font.getByte();
var string = '';
for (var i = 0; i < stringLength; ++i)
string += font.getChar();
for (var i = 0; i < stringLength; ++i) {
string += String.fromCharCode(font.getByte());
}
customNames.push(string);
}
glyphNames = [];
@ -5170,10 +5171,10 @@ var Type1Parser = (function Type1ParserClosure() {
}
function isSpecial(c) {
return c === '/' ||
c === '[' || c === ']' ||
c === '{' || c === '}' ||
c === '(' || c === ')';
return c === 0x2F || // '/'
c === 0x5B || c === 0x5D || // '[', ']'
c === 0x7B || c === 0x7D || // '{', '}'
c === 0x28 || c === 0x29; // '(', ')'
}
function Type1Parser(stream, encrypted) {
@ -5181,6 +5182,7 @@ var Type1Parser = (function Type1ParserClosure() {
stream = new Stream(decrypt(stream.getBytes(), EEXEC_ENCRYPT_KEY, 4));
}
this.stream = stream;
this.nextChar();
}
Type1Parser.prototype = {
@ -5216,36 +5218,39 @@ var Type1Parser = (function Type1ParserClosure() {
return token === 'true' ? 1 : 0;
},
nextChar : function Type1_nextChar() {
return (this.currentChar = this.stream.getByte());
},
getToken: function Type1Parser_getToken() {
// Eat whitespace and comments.
var comment = false;
var ch;
var stream = this.stream;
var ch = this.currentChar;
while (true) {
if ((ch = stream.lookChar()) === null)
if (ch === -1) {
return null;
}
if (comment) {
if (ch === '\x0a' || ch === '\x0d') {
if (ch === 0x0A || ch === 0x0D) {
comment = false;
}
} else if (ch === '%') {
} else if (ch === 0x25) { // '%'
comment = true;
} else if (!Lexer.isSpace(ch)) {
break;
}
stream.skip();
ch = this.nextChar();
}
if (isSpecial(ch)) {
stream.skip();
return ch;
this.nextChar();
return String.fromCharCode(ch);
}
var token = '';
do {
token += ch;
stream.skip();
ch = stream.lookChar();
} while (ch !== null && !Lexer.isSpace(ch) && !isSpecial(ch));
token += String.fromCharCode(ch);
ch = this.nextChar();
} while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
return token;
},
@ -5292,12 +5297,13 @@ var Type1Parser = (function Type1ParserClosure() {
var glyph = this.getToken();
var length = this.readInt();
this.getToken(); // read in 'RD' or '-|'
var data = stream.makeSubStream(stream.pos + 1, length);
var data = stream.makeSubStream(stream.pos, length);
var lenIV = program.properties.privateData['lenIV'];
var encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY,
lenIV);
// Skip past the required space and binary data.
stream.skip(1 + length);
stream.skip(length);
this.nextChar();
token = this.getToken(); // read in 'ND' or '|-'
if (token === 'noaccess') {
this.getToken(); // read in 'def'
@ -5315,12 +5321,13 @@ var Type1Parser = (function Type1ParserClosure() {
var index = this.readInt();
var length = this.readInt();
this.getToken(); // read in 'RD' or '-|'
var data = stream.makeSubStream(stream.pos + 1, length);
var data = stream.makeSubStream(stream.pos, length);
var lenIV = program.properties.privateData['lenIV'];
var encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY,
lenIV);
// Skip past the required space and binary data.
stream.skip(1 + length);
stream.skip(length);
this.nextChar();
token = this.getToken(); // read in 'NP' or '|'
if (token === 'noaccess') {
this.getToken(); // read in 'put'