Really pass the sanitizer (encoding is broken)

This commit is contained in:
Vivien Nicolas 2011-06-19 11:07:03 +02:00
parent c1fc38725a
commit ca61249db1
2 changed files with 28 additions and 23 deletions

View File

@ -82,6 +82,7 @@ var Fonts = {
*/
var Font = function(aName, aFile, aProperties) {
this.name = aName;
this.encoding = aProperties.encoding;
// If the font has already been decoded simply return
if (Fonts[aName]) {
@ -134,6 +135,7 @@ Font.prototype = {
name: null,
font: null,
mimetype: null,
encoding: null,
bind: function font_bind() {
var data = this.font;
@ -185,10 +187,11 @@ Font.prototype = {
// When debugging use the characters provided by the charsets to visually
// see what's happening
if (debug) {
var encoding = this.encoding;
for (var i = 0; i < charset.length; i++) {
var unicode = GlyphsUnicode[charset[i]];
if (!unicode)
error("Unicode for " + charset[i] + " is has not been found in the glyphs list");
continue;
testString += String.fromCharCode(unicode);
}
}
@ -672,12 +675,18 @@ var TrueType = function(aName, aFile, aProperties) {
"post"
];
var originalCMAP = null;
var tables = [];
for (var i = 0; i < numTables; i++) {
var table = this._readTableEntry(aFile);
var index = requiredTables.indexOf(table.tag);
if (index != -1)
if (index != -1) {
if (table.tag == "cmap")
originalCMAP = table;
requiredTables.splice(index, 1);
}
tables.push(table);
}
@ -726,10 +735,25 @@ var TrueType = function(aName, aFile, aProperties) {
0x00, 0x02 // usMaxContext
];
// If the font is missing a OS/2 table it's could be an old mac font
// without a 3-1-4 Unicode BMP table, so let's rewrite it.
var charset = aProperties.charset;
var glyphs = [];
for (var i = 0; i < charset.length; i++) {
glyphs.push({
unicode: GlyphsUnicode[charset[i]]
});
}
// Replace the old CMAP table
var rewrittedCMAP = this._createCMAPTable(glyphs);
var cmapDelta = rewrittedCMAP.length - originalCMAP.data.length;
originalCMAP.data = rewrittedCMAP;
// Create a new file to hold the new version of our truetype with a new
// header and new offsets
var stream = aFile.stream || aFile;
var ttf = new Uint8Array(stream.length + 16 + OS2.length);
var ttf = new Uint8Array(stream.length + 16 + OS2.length + cmapDelta);
// The new numbers of tables will be the last one plus the num of missing
// tables
@ -753,25 +777,6 @@ var TrueType = function(aName, aFile, aProperties) {
data: OS2
});
// If the font is missing a OS/2 table it's could be an old mac font
// without a 3-1-4 Unicode BMP table, so let's rewrite it.
var charset = aProperties.charset;
var glyphs = [];
for (var i = 0; i < charset.length; i++) {
glyphs.push({
unicode: GlyphsUnicode[aProperties.encoding[charset[i]]]
});
}
// Replace the old CMAP table
var cmap = this._createCMAPTable(glyphs);
for (var i = 0; i < tables.length; i++) {
var table = tables[i];
if (table.tag == "cmap") {
table.data = cmap;
break;
}
}
// Tables needs to be written by ascendant alphabetic order
tables.sort(function(a, b) {

2
pdf.js
View File

@ -1928,7 +1928,7 @@ var CanvasGraphics = (function() {
var index = 0;
for (var j = 0; j < encoding.length; j++) {
encodingMap[firstChar + index++] = GlyphsUnicode[encoding[j]];
encodingMap[index++] = GlyphsUnicode[encoding[j]];
}
var widths = xref.fetchIfRef(fontDict.get("Widths"));