starting position of a stream is relative to the file, not the current stream

This commit is contained in:
Andreas Gal 2011-06-02 10:57:06 -07:00
parent d66fc27bad
commit 9b9a258a57

21
pdf.js
View File

@ -47,26 +47,24 @@ function shadow(obj, prop, value) {
} }
var Stream = (function() { var Stream = (function() {
function constructor(arrayBuffer, dict) { function constructor(arrayBuffer, start, length, dict) {
this.bytes = new Uint8Array(arrayBuffer); this.bytes = new Uint8Array(arrayBuffer);
this.pos = 0; this.start = start || 0;
this.start = 0; this.pos = this.start;
this.length = (start + length) || arrayBuffer.byteLength;
this.dict = dict; this.dict = dict;
} }
constructor.prototype = { constructor.prototype = {
get length() {
return this.bytes.length;
},
getByte: function() { getByte: function() {
var bytes = this.bytes; var bytes = this.bytes;
if (this.pos >= bytes.length) if (this.pos >= this.length)
return -1; return -1;
return bytes[this.pos++]; return bytes[this.pos++];
}, },
lookChar: function() { lookChar: function() {
var bytes = this.bytes; var bytes = this.bytes;
if (this.pos >= bytes.length) if (this.pos >= this.length)
return; return;
return String.fromCharCode(bytes[this.pos]); return String.fromCharCode(bytes[this.pos]);
}, },
@ -88,11 +86,8 @@ var Stream = (function() {
moveStart: function() { moveStart: function() {
this.start = this.pos; this.start = this.pos;
}, },
makeSubStream: function(pos, length, dict) { makeSubStream: function(start, length, dict) {
var buffer = this.bytes.buffer; return new Stream(this.bytes.buffer, start, length, dict);
if (length)
return new Stream(new Uint8Array(buffer, pos, length), dict);
return new Stream(new Uint8Array(buffer, pos), dict);
} }
}; };