From b1a85c62295e0b35fa284a41ef6761d59074a8d5 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas <21@vingtetun.org> Date: Tue, 6 Sep 2011 15:12:33 +0200 Subject: [PATCH] Fix cmap encoding records to pass the sanitizer in the case of a duplicate platform: 1, encoding: 0 --- fonts.js | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/fonts.js b/fonts.js index 50eafc566..f53a2098b 100755 --- a/fonts.js +++ b/fonts.js @@ -857,9 +857,42 @@ var Font = (function Font() { }); } + // Check that table are sorted by platformID then encodingID, + var tables = [records[0]]; + for (var i = 1; i < numRecords; i++) { + // The sanitizer will drop the font if 2 tables have the same + // platformID and the same encodingID, this will be correct for + // most cases but if the font has been made for Mac it could + // exist a few platformID: 1, encodingID: 0 but with a different + // language field and that's correct. But the sanitizer does not + // seem to support this case. + var current = records[i]; + var previous = records[i - 1]; + if (((current.platformID << 16) + current.encodingID) <= + ((previous.platformID << 16) + previous.encodingID)) + continue; + tables.push(current); + } + + var missing = numRecords - tables.length; + if (numRecords - tables.length) { + numRecords = tables.length; + var data = string16(version) + string16(numRecords); + + for (var i = 0; i < numRecords; i++) { + var table = tables[i]; + data += string16(table.platformID) + + string16(table.encodingID) + + string32(table.offset); + } + + for (var i = 0; i < data.length; i++) + cmap.data[i] = data.charCodeAt(i); + } + var encoding = properties.encoding; for (var i = 0; i < numRecords; i++) { - var table = records[i]; + var table = tables[i]; font.pos = start + table.offset; var format = int16(font.getBytes(2));