getChar: function() {
var ch = this.lookChar();
this.pos++;
- return String.fromCharCode(ch);
+ return ch;
},
putBack: function() {
this.pos--;
this.pos += n;
},
moveStart: function() {
- this.bytes = Uint8Array(bytes, pos);
+ this.bytes = Uint8Array(this.bytes, this.pos);
this.pos = 0;
},
- find: function(str, limit, backwards) {
+ find: function(needle, limit, backwards) {
var length = this.bytes.length;
var pos = this.pos;
var str = "";
limit = length - pos;
for (var n = 0; n < limit; ++n)
str += this.getChar();
- var index = backwards ? str.lastIndexOf(str) : str.indexOf(str);
+ this.pos = pos;
+ var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
if (index == -1)
return false; /* not found */
this.pos += index;
};
return constructor;
-});
+})();
var Obj = (function() {
function constructor(type, value) {
break;
}
} while (true);
- var value = parseNumber(str);
+ var value = parseFloat(str);
if (isNaN(value))
return Obj.errorObj;
if (floating) {
getName: function(ch) {
var str = "";
var stream = this.stream;
- while (!!(ch = stream.lookChar()) && !specialChars[ch.toCharCode()]) {
+ while (!!(ch = stream.lookChar()) && !specialChars[ch.charCodeAt(0)]) {
stream.getChar();
if (ch == "#") {
ch = stream.lookChar();
// skip whitespace and comments
var comment = false;
var stream = this.stream;
+ var ch;
while (true) {
- var ch;
if (!(ch = stream.getChar()))
return new Obj(Object.EOF);
if (comment) {
comment = false;
} else if (ch == '%') {
comment = true;
- } else if (specialChars[ch.chatCodeAt(0)] != 1) {
+ } else if (specialChars[ch.charCodeAt(0)] != 1) {
break;
}
}
// start reading token
- switch (c) {
+ switch (ch) {
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
case '+': case '-': case '.':
// command
var str = ch;
- while (!!(ch = stream.lookChar()) && !specialChars[ch.toCharCode()]) {
+ while (!!(ch = stream.lookChar()) && !specialChars[ch.charCodeAt(0)]) {
stream.getChar();
if (str.length == 128) {
error("Command token too long");
constructor.prototype = {
refill: function() {
- this.buf1 = lexer.getObj();
- this.buf2 = lexer.getObj();
+ this.buf1 = this.lexer.getObj();
+ this.buf2 = this.lexer.getObj();
},
shift: function() {
if (this.inlineImg > 0) {
var obj2 = this.parser.getObj();
var obj3 = this.parser.getObj();
this.linDict = this.parser.getObj();
- if (obj1.isInt() && obj2.isInt() && obj3.isCmd("obj") && linDict.isDict()) {
- var obj = linDict.lookup("Linearized");
+ if (obj1.isInt() && obj2.isInt() && obj3.isCmd("obj") && this.linDict.isDict()) {
+ var obj = this.linDict.lookup("Linearized");
if (!(obj.isNum() && obj.value > 0))
this.linDict = Obj.nullObj;
}
getInt: function(name) {
var linDict = this.linDict;
var obj;
- if (!linDict.isDict() &&
+ if (linDict.isDict() &&
(obj = linDict.lookup(name)).isInt() &&
obj.value > 0) {
return length;
return 0;
},
get length() {
+ if (!this.linDict.isDict())
+ return 0;
return this.getInt("L");
},
get hintsOffset() {
return this.getInt("P");
}
};
+
+ return constructor;
})();
var PDFDoc = (function () {
function constructor(stream) {
- this.setup(stream);
+ this.stream = stream;
+ this.setup();
}
constructor.prototype = {
return this.linearization = linearization;
},
get startXRef() {
+ var stream = this.stream;
var startXRef = 0;
var linearization = this.linearization;
if (linearization) {
str += ch;
ch = stream.getChar();
}
- startXRef = parseNumber(str);
+ startXRef = parseInt(str);
if (isNaN(startXRef))
startXRef = 0;
}
},
// Find the header, remove leading garbage and setup the stream
// starting from the header.
- checkHeader: function(stream) {
+ checkHeader: function() {
+ var stream = this.stream;
stream.reset();
if (stream.find("%PDF-", 1024)) {
// Found the header, trim off any garbage before it.
}
// May not be a PDF file, continue anyway.
- this.stream = stream;
},
setup: function(arrayBuffer, ownerPassword, userPassword) {
this.checkHeader(arrayBuffer);
+ print(this.startXRef);
}
};
+
+ return constructor;
})();
var Interpreter = (function() {
}
function runParseTests() {
+ var data = snarf("simple_graphics.pdf", "binary");
+ var pdf = new PDFDoc(new Stream(data));
}
if ("arguments" in this) {