[src/core/fonts.js] Improve the validateOS2Table function

Rather than creating a new `Stream` just to validate the OS/2 TrueType table, it's simpler/better to just pass in a reference to the font data and use that instead (similar to other TrueType helper functions).
This commit is contained in:
Jonas Jenwald 2020-04-19 11:17:36 +02:00
parent 033d27fc25
commit 695140728a

View File

@ -1063,23 +1063,23 @@ var Font = (function FontClosure() {
); );
} }
function validateOS2Table(os2) { function validateOS2Table(os2, file) {
var stream = new Stream(os2.data); file.pos = (file.start || 0) + os2.offset;
var version = stream.getUint16(); var version = file.getUint16();
// TODO verify all OS/2 tables fields, but currently we validate only those // TODO verify all OS/2 tables fields, but currently we validate only those
// that give us issues // that give us issues
stream.skip(60); // skipping type, misc sizes, panose, unicode ranges file.skip(60); // skipping type, misc sizes, panose, unicode ranges
var selection = stream.getUint16(); var selection = file.getUint16();
if (version < 4 && selection & 0x0300) { if (version < 4 && selection & 0x0300) {
return false; return false;
} }
var firstChar = stream.getUint16(); var firstChar = file.getUint16();
var lastChar = stream.getUint16(); var lastChar = file.getUint16();
if (firstChar > lastChar) { if (firstChar > lastChar) {
return false; return false;
} }
stream.skip(6); // skipping sTypoAscender/Descender/LineGap file.skip(6); // skipping sTypoAscender/Descender/LineGap
var usWinAscent = stream.getUint16(); var usWinAscent = file.getUint16();
if (usWinAscent === 0) { if (usWinAscent === 0) {
// makes font unreadable by windows // makes font unreadable by windows
return false; return false;
@ -2916,7 +2916,7 @@ var Font = (function FontClosure() {
data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphsOut), data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphsOut),
}; };
if (!tables["OS/2"] || !validateOS2Table(tables["OS/2"])) { if (!tables["OS/2"] || !validateOS2Table(tables["OS/2"], font)) {
tables["OS/2"] = { tables["OS/2"] = {
tag: "OS/2", tag: "OS/2",
data: createOS2Table( data: createOS2Table(