Rebuilding invalid OS/2 table
This commit is contained in:
parent
d8235925ac
commit
be6ccdca34
52
src/fonts.js
52
src/fonts.js
@ -1727,6 +1727,16 @@ var Font = (function FontClosure() {
|
||||
properties.glyphNames = glyphNames;
|
||||
}
|
||||
|
||||
function isOS2Valid(os2Table) {
|
||||
var data = os2Table.data;
|
||||
// usWinAscent == 0 makes font unreadable by windows
|
||||
var usWinAscent = (data[74] << 8) | data[75];
|
||||
if (usWinAscent == 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check that required tables are present
|
||||
var requiredTables = ['OS/2', 'cmap', 'head', 'hhea',
|
||||
'hmtx', 'maxp', 'name', 'post'];
|
||||
@ -1734,7 +1744,7 @@ var Font = (function FontClosure() {
|
||||
var header = readOpenTypeHeader(font);
|
||||
var numTables = header.numTables;
|
||||
|
||||
var cmap, post, maxp, hhea, hmtx, vhea, vmtx, head, loca, glyf;
|
||||
var cmap, post, maxp, hhea, hmtx, vhea, vmtx, head, loca, glyf, os2;
|
||||
var tables = [];
|
||||
for (var i = 0; i < numTables; i++) {
|
||||
var table = readTableEntry(font);
|
||||
@ -1752,6 +1762,8 @@ var Font = (function FontClosure() {
|
||||
hmtx = table;
|
||||
else if (table.tag == 'head')
|
||||
head = table;
|
||||
else if (table.tag == 'OS/2')
|
||||
os2 = table;
|
||||
|
||||
requiredTables.splice(index, 1);
|
||||
} else {
|
||||
@ -1767,7 +1779,7 @@ var Font = (function FontClosure() {
|
||||
tables.push(table);
|
||||
}
|
||||
|
||||
var numTables = header.numTables + requiredTables.length;
|
||||
var numTables = tables.length + requiredTables.length;
|
||||
|
||||
// header and new offsets. Table entry information is appended to the
|
||||
// end of file. The virtualOffset represents where to put the actual
|
||||
@ -1781,21 +1793,10 @@ var Font = (function FontClosure() {
|
||||
// of missing tables
|
||||
createOpenTypeHeader(header.version, ttf, numTables);
|
||||
|
||||
if (requiredTables.indexOf('OS/2') != -1) {
|
||||
// extract some more font properties from the OpenType head and
|
||||
// hhea tables; yMin and descent value are always negative
|
||||
var override = {
|
||||
unitsPerEm: int16([head.data[18], head.data[19]]),
|
||||
yMax: int16([head.data[42], head.data[43]]),
|
||||
yMin: int16([head.data[38], head.data[39]]) - 0x10000,
|
||||
ascent: int16([hhea.data[4], hhea.data[5]]),
|
||||
descent: int16([hhea.data[6], hhea.data[7]]) - 0x10000
|
||||
};
|
||||
|
||||
tables.push({
|
||||
tag: 'OS/2',
|
||||
data: stringToArray(createOS2Table(properties, null, override))
|
||||
});
|
||||
// Invalid OS/2 can break the font for the Windows
|
||||
if (os2 && !isOS2Valid(os2)) {
|
||||
tables.splice(tables.indexOf(os2), 1);
|
||||
os2 = null;
|
||||
}
|
||||
|
||||
// Ensure the [h/v]mtx tables contains the advance width and
|
||||
@ -2076,6 +2077,23 @@ var Font = (function FontClosure() {
|
||||
}
|
||||
this.unicodeIsEnabled = unicodeIsEnabled;
|
||||
|
||||
if (!os2) {
|
||||
// extract some more font properties from the OpenType head and
|
||||
// hhea tables; yMin and descent value are always negative
|
||||
var override = {
|
||||
unitsPerEm: int16([head.data[18], head.data[19]]),
|
||||
yMax: int16([head.data[42], head.data[43]]),
|
||||
yMin: int16([head.data[38], head.data[39]]) - 0x10000,
|
||||
ascent: int16([hhea.data[4], hhea.data[5]]),
|
||||
descent: int16([hhea.data[6], hhea.data[7]]) - 0x10000
|
||||
};
|
||||
|
||||
tables.push({
|
||||
tag: 'OS/2',
|
||||
data: stringToArray(createOS2Table(properties, glyphs, override))
|
||||
});
|
||||
}
|
||||
|
||||
// Rewrite the 'post' table if needed
|
||||
if (requiredTables.indexOf('post') != -1) {
|
||||
tables.push({
|
||||
|
1
test/pdfs/issue1502.pdf.link
Normal file
1
test/pdfs/issue1502.pdf.link
Normal file
@ -0,0 +1 @@
|
||||
http://register.consilium.europa.eu/pdf/en/11/st12/st12196.en11.pdf
|
@ -559,6 +559,14 @@
|
||||
"link": true,
|
||||
"type": "eq"
|
||||
},
|
||||
{ "id": "issue1502",
|
||||
"file": "pdfs/issue1502.pdf",
|
||||
"md5": "6f0569b7e85561ea784cb0403de89d84",
|
||||
"rounds": 1,
|
||||
"pageLimit": 5,
|
||||
"link": true,
|
||||
"type": "eq"
|
||||
},
|
||||
{ "id": "issue1317",
|
||||
"file": "pdfs/issue1317.pdf",
|
||||
"md5": "6fb46275b30c48c8985617d4f86199e3",
|
||||
|
Loading…
x
Reference in New Issue
Block a user