Merge pull request #402 from notmasteryet/cmap

cmap fixes: hex/dec numbers, arrays, ranges
This commit is contained in:
vingtetun 2011-08-29 19:24:39 -07:00
commit 3e8d956bcc

65
pdf.js
View File

@ -4311,53 +4311,78 @@ var PartialEvaluator = (function() {
var tokens = [];
var token = '';
var beginArrayToken = {};
var cmap = cmapObj.getBytes(cmapObj.length);
for (var i = 0; i < cmap.length; i++) {
var byte = cmap[i];
if (byte == 0x20 || byte == 0x0A || byte == 0x3C ||
byte == 0x3E) {
if (byte == 0x20 || byte == 0x0D || byte == 0x0A ||
byte == 0x3C || byte == 0x5B || byte == 0x5D) {
switch (token) {
case 'useCMap':
error('useCMap is not implemented');
case 'usecmap':
error('usecmap is not implemented');
break;
case 'beginbfchar':
case 'beginbfrange':
case 'begincodespacerange':
case 'begincidchar':
case 'begincidrange':
token = '';
tokens = [];
break;
case 'endcodespacerange':
TODO('Support CMap ranges');
break;
case 'endcidrange':
case 'endbfrange':
for (var j = 0; j < tokens.length; j += 3) {
var startRange = parseInt('0x' + tokens[j]);
var endRange = parseInt('0x' + tokens[j + 1]);
var code = parseInt('0x' + tokens[j + 2]);
var startRange = tokens[j];
var endRange = tokens[j + 1];
var code = tokens[j + 2];
while(startRange < endRange) {
encodingMap[startRange] = code++;
++startRange;
}
}
break;
case 'endcidchar':
case 'endbfchar':
for (var j = 0; j < tokens.length; j += 2) {
var index = parseInt('0x' + tokens[j]);
var code = parseInt('0x' + tokens[j + 1]);
var index = tokens[j];
var code = tokens[j + 1];
encodingMap[index] = code;
}
break;
case '':
break;
default:
if (token.length) {
tokens.push(token);
token = '';
}
if (token[0] >= '0' && token[0] <= '9')
token = parseInt(token, 10); // a number
tokens.push(token);
token = '';
break;
}
} else if (byte == 0x5B || byte == 0x5D) {
error('CMAP list parsing is not implemented');
switch (byte) {
case 0x5B:
// begin list parsing
tokens.push(beginArrayToken);
break;
case 0x5D:
// collect array items
var items = [], item;
while (tokens.length && (item = tokens.pop()) != beginArrayToken) {
items.unshift(item);
}
tokens.push(items);
break;
}
} else if (byte == 0x3E) {
if (token.length) {
// parsing hex number
tokens.push(parseInt(token, 16));
token = '';
}
} else {
token += String.fromCharCode(byte);
}