1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-25 01:28:06 +02:00

Merge pull request #220 from saebekassebil/master

ASCIIHexDecode Filter implementation
This commit is contained in:
sbarman 2011-07-08 15:41:25 -07:00
commit c16f594465
2 changed files with 126 additions and 1 deletions

72
pdf.js
View file

@ -904,6 +904,74 @@ var Ascii85Stream = (function() {
return constructor;
})();
var AsciiHexStream = (function() {
function constructor(str) {
this.str = str;
this.dict = str.dict;
DecodeStream.call(this);
}
var hexvalueMap = {
9: -1, // \t
32: -1, // space
48: 0,
49: 1,
50: 2,
51: 3,
52: 4,
53: 5,
54: 6,
55: 7,
56: 8,
57: 9,
65: 10,
66: 11,
67: 12,
68: 13,
69: 14,
70: 15,
97: 10,
98: 11,
99: 12,
100: 13,
101: 14,
102: 15
};
constructor.prototype = Object.create(DecodeStream.prototype);
constructor.prototype.readBlock = function() {
var gtCode = '>'.charCodeAt(0), bytes = this.str.getBytes(), c, n,
decodeLength, buffer, bufferLength, i, length;
decodeLength = (bytes.length + 1) >> 1;
buffer = this.ensureBuffer(this.bufferLength + decodeLength);
bufferLength = this.bufferLength;
for(i = 0, length = bytes.length; i < length; i++) {
c = hexvalueMap[bytes[i]];
while (c == -1 && (i+1) < length) {
c = hexvalueMap[bytes[++i]];
}
if((i+1) < length && (bytes[i+1] !== gtCode)) {
n = hexvalueMap[bytes[++i]];
buffer[bufferLength++] = c*16+n;
} else {
if(bytes[i] !== gtCode) { // EOD marker at an odd number, behave as if a 0 followed the last digit.
buffer[bufferLength++] = c*16;
}
}
}
this.bufferLength = bufferLength;
this.eof = true;
};
return constructor;
})();
var CCITTFaxStream = (function() {
var ccittEOL = -2;
@ -1943,7 +2011,7 @@ var Dict = (function() {
forEach: function(callback) {
for (var key in this.map) {
callback.call(null, key, this.map[key]);
callback(key, this.map[key]);
}
}
};
@ -2496,6 +2564,8 @@ var Parser = (function() {
return new JpegStream(bytes, stream.dict);
} else if (name == 'ASCII85Decode') {
return new Ascii85Stream(stream);
} else if (name == 'ASCIIHexDecode') {
return new AsciiHexStream(stream);
} else if (name == 'CCITTFaxDecode') {
TODO('implement fax stream');
return new CCITTFaxStream(stream, params);