Merge pull request #1244 from notmasteryet/issue-1243
Sets proper unicode range for symbols; sanitize no-glyphs fonts
This commit is contained in:
commit
884ea5f028
28
src/fonts.js
28
src/fonts.js
@ -11,6 +11,7 @@ var kMaxWaitForFontFace = 1000;
|
|||||||
// Unicode Private Use Area
|
// Unicode Private Use Area
|
||||||
var kCmapGlyphOffset = 0xE000;
|
var kCmapGlyphOffset = 0xE000;
|
||||||
var kSizeOfGlyphArea = 0x1900;
|
var kSizeOfGlyphArea = 0x1900;
|
||||||
|
var kSymbolicFontGlyphOffset = 0xF000;
|
||||||
|
|
||||||
// PDF Glyph Space Units are one Thousandth of a TextSpace Unit
|
// PDF Glyph Space Units are one Thousandth of a TextSpace Unit
|
||||||
// except for Type 3 fonts
|
// except for Type 3 fonts
|
||||||
@ -1648,6 +1649,18 @@ var Font = (function FontClosure() {
|
|||||||
itemEncode(locaData, j, writeOffset);
|
itemEncode(locaData, j, writeOffset);
|
||||||
startOffset = endOffset;
|
startOffset = endOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (writeOffset == 0) {
|
||||||
|
// glyf table cannot be empty -- redoing the glyf and loca tables
|
||||||
|
// to have single glyph with one point
|
||||||
|
var simpleGlyph = new Uint8Array(
|
||||||
|
[0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
|
||||||
|
for (var i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize)
|
||||||
|
itemEncode(locaData, j, simpleGlyph.length);
|
||||||
|
glyf.data = simpleGlyph;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
glyf.data = newGlyfData.subarray(0, writeOffset);
|
glyf.data = newGlyfData.subarray(0, writeOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1876,7 +1889,7 @@ var Font = (function FontClosure() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if it is, replacing with meaningful toUnicode values
|
// if it is, replacing with meaningful toUnicode values
|
||||||
if (isIdentity) {
|
if (isIdentity && !this.isSymbolicFont) {
|
||||||
var usedUnicodes = [], unassignedUnicodeItems = [];
|
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];
|
var unicode = toUnicode[i + 1];
|
||||||
@ -1928,6 +1941,16 @@ var Font = (function FontClosure() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Moving all symbolic font glyphs into 0xF000 - 0xF0FF range.
|
||||||
|
this.symbolicGlyphsOffset = 0;
|
||||||
|
if (this.isSymbolicFont) {
|
||||||
|
for (var i = 0, ii = glyphs.length; i < ii; i++) {
|
||||||
|
var code = glyphs[i].unicode;
|
||||||
|
glyphs[i].unicode = kSymbolicFontGlyphOffset | (code & 0xFF);
|
||||||
|
}
|
||||||
|
this.symbolicGlyphsOffset = kSymbolicFontGlyphOffset;
|
||||||
|
}
|
||||||
|
|
||||||
// remove glyph references outside range of avaialable glyphs
|
// remove glyph references outside range of avaialable glyphs
|
||||||
for (var i = 0, ii = ids.length; i < ii; i++) {
|
for (var i = 0, ii = ids.length; i < ii; i++) {
|
||||||
if (ids[i] >= numGlyphs)
|
if (ids[i] >= numGlyphs)
|
||||||
@ -2315,7 +2338,8 @@ var Font = (function FontClosure() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!this.hasEncoding || this.isSymbolicFont) {
|
if (!this.hasEncoding || this.isSymbolicFont) {
|
||||||
unicode = this.useToUnicode ? this.toUnicode[charcode] : charcode;
|
unicode = this.useToUnicode ? this.toUnicode[charcode] :
|
||||||
|
(this.symbolicGlyphsOffset + charcode);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1
test/pdfs/issue1243.pdf.link
Normal file
1
test/pdfs/issue1243.pdf.link
Normal file
@ -0,0 +1 @@
|
|||||||
|
http://www.nsa.gov/public_info/_files/nash_letters/nash_letters1.pdf
|
1
test/pdfs/issue1257.pdf.link
Normal file
1
test/pdfs/issue1257.pdf.link
Normal file
@ -0,0 +1 @@
|
|||||||
|
http://hse-econ.fi/tervio/MediocritiesAndSuperstars.pdf
|
@ -487,5 +487,21 @@
|
|||||||
"rounds": 1,
|
"rounds": 1,
|
||||||
"link": true,
|
"link": true,
|
||||||
"type": "eq"
|
"type": "eq"
|
||||||
|
},
|
||||||
|
{ "id": "issue1243",
|
||||||
|
"file": "pdfs/issue1243.pdf",
|
||||||
|
"md5": "130c849b83513d5ac5e03c6421fc7489",
|
||||||
|
"rounds": 1,
|
||||||
|
"pageLimit": 2,
|
||||||
|
"link": true,
|
||||||
|
"type": "eq"
|
||||||
|
},
|
||||||
|
{ "id": "issue1257",
|
||||||
|
"file": "pdfs/issue1257.pdf",
|
||||||
|
"md5": "9111533826bc21ed774e8e01603a2f54",
|
||||||
|
"rounds": 1,
|
||||||
|
"pageLimit": 2,
|
||||||
|
"link": true,
|
||||||
|
"type": "eq"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user