Browse Source

Merge pull request #909 from notmasteryet/tree-45

Fixing TrueType code-glyph assigmnent to pass sanitizer
Brendan Dahl 14 years ago
parent
commit
853f16085f
  1. 17
      src/fonts.js
  2. 5
      test/driver.js
  3. 1
      test/pdfs/lista_preliminar.pdf.link
  4. 8
      test/test_manifest.json

17
src/fonts.js

@ -1765,7 +1765,7 @@ var Font = (function FontClosure() {
var hasShortCmap = !!cmapTable.hasShortCmap; var hasShortCmap = !!cmapTable.hasShortCmap;
var toUnicode = this.toUnicode; var toUnicode = this.toUnicode;
if (toUnicode) { if (toUnicode && toUnicode.length > 0) {
// checking if cmap is just identity map // checking if cmap is just identity map
var isIdentity = true; var isIdentity = true;
for (var i = 0, ii = glyphs.length; i < ii; i++) { for (var i = 0, ii = glyphs.length; i < ii; i++) {
@ -1776,9 +1776,22 @@ var Font = (function FontClosure() {
} }
// if it is, replacing with meaningful toUnicode values // if it is, replacing with meaningful toUnicode values
if (isIdentity) { if (isIdentity) {
var usedUnicodes = [], unassignedUnicodeItems = [];
for (var i = 0, ii = glyphs.length; i < ii; i++) { for (var i = 0, ii = glyphs.length; i < ii; i++) {
var unicode = toUnicode[i + 1] || i + 1; var unicode = toUnicode[i + 1];
if (!unicode || unicode in usedUnicodes) {
unassignedUnicodeItems.push(i);
continue;
}
glyphs[i].unicode = unicode; glyphs[i].unicode = unicode;
usedUnicodes[unicode] = true;
}
var unusedUnicode = kCmapGlyphOffset;
for (var j = 0, jj = unassignedUnicodeItems.length; j < jj; j++) {
var i = unassignedUnicodeItems[j];
while (unusedUnicode in usedUnicodes)
unusedUnicode++;
glyphs[i].unicode = unusedUnicode++;
} }
this.useToUnicode = true; this.useToUnicode = true;
} }

5
test/driver.js

@ -139,6 +139,11 @@ function nextPage(task, loadError) {
if (task.skipPages && task.skipPages.indexOf(task.pageNum) >= 0) { if (task.skipPages && task.skipPages.indexOf(task.pageNum) >= 0) {
log(' skipping page ' + task.pageNum + '/' + task.pdfDoc.numPages + log(' skipping page ' + task.pageNum + '/' + task.pdfDoc.numPages +
'... '); '... ');
// empty the canvas
canvas.width = 1;
canvas.height = 1;
clear(canvas.getContext('2d'));
snapshotCurrentPage(task, ''); snapshotCurrentPage(task, '');
return; return;
} }

1
test/pdfs/lista_preliminar.pdf.link

@ -0,0 +1 @@
http://www.lfg.com.br/concursodebolsas/lista_preliminar_classificao.pdf

8
test/test_manifest.json

@ -332,5 +332,13 @@
"pageLimit": 5, "pageLimit": 5,
"skipPages": [1], "skipPages": [1],
"type": "eq" "type": "eq"
},
{ "id": "lista_preliminar",
"file": "pdfs/lista_preliminar.pdf",
"md5": "4eff251319eeb660ba8a7a5cfac7787d",
"rounds": 1,
"link": true,
"pageLimit": 3,
"type": "eq"
} }
] ]

Loading…
Cancel
Save