1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Guess CIDFontType0 subtype based on font file contents (issue 5751)

This commit is contained in:
Jonas Jenwald 2015-02-23 16:01:08 +01:00
parent 72cfa36b06
commit e894a0a4c6
4 changed files with 26 additions and 0 deletions

View file

@ -2575,6 +2575,10 @@ var Font = (function FontClosure() {
if (subtype === 'OpenType') {
type = 'OpenType';
}
// Some CIDFontType0C fonts by mistake claim CIDFontType0.
if (type === 'CIDFontType0') {
subtype = isType1File(file) ? 'CIDFontType0' : 'CIDFontType0C';
}
var data;
switch (type) {
@ -2655,6 +2659,20 @@ var Font = (function FontClosure() {
return readUint32(header, 0) === 0x00010000;
}
function isType1File(file) {
var header = file.peekBytes(2);
// All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
if (header[0] === 0x25 && header[1] === 0x21) {
return true;
}
// ... obviously some fonts violate that part of the specification,
// please refer to the comment in |Type1Font| below.
if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
return true;
}
return false;
}
/**
* Rebuilds the char code to glyph ID map by trying to replace the char codes
* with their unicode value. It also moves char codes that are in known