Merge pull request #435 from vingtetun/master

Fix for #427 and nit of #422
This commit is contained in:
notmasteryet 2011-09-05 07:37:35 -07:00
commit 89440ebef9
2 changed files with 22 additions and 16 deletions

View File

@ -9,6 +9,10 @@ var isWorker = (typeof window == 'undefined');
*/ */
var kMaxWaitForFontFace = 1000; var kMaxWaitForFontFace = 1000;
// Unicode Private Use Area
var kCmapGlyphOffset = 0xE000;
/** /**
* Hold a map of decoded fonts and of the standard fourteen Type1 * Hold a map of decoded fonts and of the standard fourteen Type1
* fonts and their acronyms. * fonts and their acronyms.
@ -797,9 +801,6 @@ var Font = (function Font() {
encoding: null, encoding: null,
checkAndRepair: function font_checkAndRepair(name, font, properties) { checkAndRepair: function font_checkAndRepair(name, font, properties) {
// offset glyphs to the Unicode Private Use Area
var kCmapGlyphOffset = 0xE000;
function readTableEntry(file) { function readTableEntry(file) {
var tag = file.getBytes(4); var tag = file.getBytes(4);
tag = String.fromCharCode(tag[0]) + tag = String.fromCharCode(tag[0]) +
@ -879,16 +880,23 @@ var Font = (function Font() {
var index = font.getByte(); var index = font.getByte();
if (index) { if (index) {
deltas.push(index); deltas.push(index);
glyphs.push({ unicode: j });
var code = encoding[index];
for (var glyph in properties.glyphs) {
if (properties.glyphs[glyph] == code)
break;
}
glyphs.push({ glyph: glyph, unicode: j });
} }
} }
if (properties.firstChar < 0x20) { if (properties.firstChar < 0x20) {
var code = 0;
for (var j = 0; j < glyphs.length; j++) { for (var j = 0; j < glyphs.length; j++) {
var glyph = glyphs[j]; var glyph = glyphs[j];
glyphs[j].unicode += 0x1F; var code = glyph.unicode + kCmapGlyphOffset;
properties.glyphs[glyph.glyph] = encoding[++code] = glyph.unicode; properties.glyphs[glyph.glyph] = encoding[glyph.unicode] = code;
glyph.unicode = code;
} }
} }
@ -1406,7 +1414,7 @@ var Type1Parser = function() {
// Type1 only command with command not (yet) built-in ,throw an error // Type1 only command with command not (yet) built-in ,throw an error
'6': -1, // seac '6': -1, // seac
'7': -1, //sbw '7': -1, // sbw
'11': 'sub', '11': 'sub',
'12': 'div', '12': 'div',
@ -1422,8 +1430,8 @@ var Type1Parser = function() {
// moveto (this is a one shot positionning command). This is used only // moveto (this is a one shot positionning command). This is used only
// with the return of an OtherSubrs call. // with the return of an OtherSubrs call.
// TODO Implement the OtherSubrs charstring embedding and replace this // TODO Implement the OtherSubrs charstring embedding and replace this
// call by a no-op, like 2 'pop' commands for example. // call by a no-op, like 2 'pop' commands for example.
'33': null //setcurrentpoint '33': null // setcurrentpoint
}, },
'13': 'hsbw', '13': 'hsbw',
'14': 'endchar', '14': 'endchar',
@ -1458,7 +1466,7 @@ var Type1Parser = function() {
charstring.push('drop'); charstring.push('drop');
// If the flex mechanism is not used in a font program, Adobe // If the flex mechanism is not used in a font program, Adobe
// state that that entries 0, 1 and 2 can simply be replace by // states that entries 0, 1 and 2 can simply be replaced by
// {}, which means that we can simply ignore them. // {}, which means that we can simply ignore them.
if (index < 3) { if (index < 3) {
continue; continue;
@ -1477,7 +1485,7 @@ var Type1Parser = function() {
command = charStringDictionary['12'][escape]; command = charStringDictionary['12'][escape];
} else { } else {
// TODO Clean this code // TODO Clean this code
if (value == 13) { //hsbw if (value == 13) { // hsbw
if (charstring.length == 2) { if (charstring.length == 2) {
lsb = charstring[0]; lsb = charstring[0];
width = charstring[1]; width = charstring[1];
@ -1646,9 +1654,9 @@ var Type1Parser = function() {
var encoded = decrypt(data, kCharStringsEncryptionKey, lenIV); var encoded = decrypt(data, kCharStringsEncryptionKey, lenIV);
var str = decodeCharString(encoded); var str = decodeCharString(encoded);
i = i + 1 + length; i = i + 1 + length;
t = getToken(); //read in 'NP' t = getToken(); // read in 'NP'
if (t == 'noaccess') if (t == 'noaccess')
getToken(); //read in 'put' getToken(); // read in 'put'
program.subrs[index] = str.charstring; program.subrs[index] = str.charstring;
} }
break; break;
@ -2235,7 +2243,6 @@ var Type2CFF = (function() {
var nominalWidth = privDict['nominalWidthX']; var nominalWidth = privDict['nominalWidthX'];
var charstrings = []; var charstrings = [];
var kCmapGlyphOffset = 0xE000;
var differences = properties.differences; var differences = properties.differences;
var index = 0; var index = 0;
for (var i = 1; i < charsets.length; i++) { for (var i = 1; i < charsets.length; i++) {

1
pdf.js
View File

@ -4304,7 +4304,6 @@ var PartialEvaluator = (function() {
var index = GlyphsUnicode[glyph] || i; var index = GlyphsUnicode[glyph] || i;
glyphsMap[glyph] = encodingMap[i] = index; glyphsMap[glyph] = encodingMap[i] = index;
var kCmapGlyphOffset = 0xE000;
if (index <= 0x1f || (index >= 127 && index <= 255)) if (index <= 0x1f || (index >= 127 && index <= 255))
glyphsMap[glyph] = encodingMap[i] += kCmapGlyphOffset; glyphsMap[glyph] = encodingMap[i] += kCmapGlyphOffset;
} }