Lie to the sanitizer about the real nature of Type1C font
This commit is contained in:
parent
76f6398e47
commit
3fd2f42a50
68
fonts.js
68
fonts.js
@ -415,11 +415,10 @@ var Font = (function Font() {
|
|||||||
this.mimetype = 'font/opentype';
|
this.mimetype = 'font/opentype';
|
||||||
|
|
||||||
var subtype = properties.subtype;
|
var subtype = properties.subtype;
|
||||||
if (subtype === 'Type1C') {
|
if (subtype === 'Type1C')
|
||||||
var cff = new Type2CFF(file, properties);
|
var cff = new Type2CFF(file, properties);
|
||||||
} else {
|
else
|
||||||
var cff = new CFF(name, file, properties);
|
var cff = new CFF(name, file, properties);
|
||||||
}
|
|
||||||
|
|
||||||
// Wrap the CFF data inside an OTF font file
|
// Wrap the CFF data inside an OTF font file
|
||||||
data = this.convert(name, cff, properties);
|
data = this.convert(name, cff, properties);
|
||||||
@ -2140,23 +2139,18 @@ var Type2CFF = (function() {
|
|||||||
this.bytes = bytes;
|
this.bytes = bytes;
|
||||||
this.properties = properties;
|
this.properties = properties;
|
||||||
|
|
||||||
// Other classes expect this.data to be a Javascript array
|
this.data = this.parse();
|
||||||
var data = [];
|
|
||||||
for (var i = 0, ii = bytes.length; i < ii; ++i)
|
|
||||||
data.push(bytes[i]);
|
|
||||||
this.data = data;
|
|
||||||
|
|
||||||
this.parse(properties);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor.prototype = {
|
constructor.prototype = {
|
||||||
parse: function cff_parse(properties) {
|
parse: function cff_parse() {
|
||||||
var header = this.parseHeader();
|
var header = this.parseHeader();
|
||||||
|
var properties = this.properties;
|
||||||
var nameIndex = this.parseIndex(header.endPos);
|
var nameIndex = this.parseIndex(header.endPos);
|
||||||
|
|
||||||
var dictIndex = this.parseIndex(nameIndex.endPos);
|
var dictIndex = this.parseIndex(nameIndex.endPos);
|
||||||
if (dictIndex.length != 1)
|
if (dictIndex.length != 1)
|
||||||
error('More than 1 font');
|
error('CFF contains more than 1 font');
|
||||||
|
|
||||||
var stringIndex = this.parseIndex(dictIndex.endPos);
|
var stringIndex = this.parseIndex(dictIndex.endPos);
|
||||||
var gsubrIndex = this.parseIndex(stringIndex.endPos);
|
var gsubrIndex = this.parseIndex(stringIndex.endPos);
|
||||||
@ -2168,20 +2162,30 @@ var Type2CFF = (function() {
|
|||||||
|
|
||||||
var bytes = this.bytes;
|
var bytes = this.bytes;
|
||||||
|
|
||||||
var privInfo = topDict['Private'];
|
var privateInfo = topDict['Private'];
|
||||||
var privOffset = privInfo[1], privLength = privInfo[0];
|
var privOffset = privateInfo[1], privLength = privateInfo[0];
|
||||||
var privBytes = bytes.subarray(privOffset, privOffset + privLength);
|
var privBytes = bytes.subarray(privOffset, privOffset + privLength);
|
||||||
baseDict = this.parseDict(privBytes);
|
baseDict = this.parseDict(privBytes);
|
||||||
var privDict = this.getPrivDict(baseDict, strings);
|
var privDict = this.getPrivDict(baseDict, strings);
|
||||||
|
|
||||||
var charStrings = this.parseIndex(topDict['CharStrings']);
|
var charStrings = this.parseIndex(topDict['CharStrings']);
|
||||||
var charset = this.parseCharsets(topDict['charset'], charStrings.length, strings);
|
var charset = this.parseCharsets(topDict['charset'],
|
||||||
var encoding = this.parseEncoding(topDict['Encoding'], properties, strings, charset);
|
charStrings.length, strings);
|
||||||
|
var hasSupplement = this.parseEncoding(topDict['Encoding'], properties,
|
||||||
|
strings, charset);
|
||||||
|
|
||||||
|
// The font sanitizer does not support CFF encoding with a
|
||||||
|
// supplement, since the encoding is not really use to map
|
||||||
|
// between gid to glyph, let's overwrite what is declared in
|
||||||
|
// the top dictionary to let the sanitizer think the font use
|
||||||
|
// StandardEncoding, that's a lie but that's ok.
|
||||||
|
if (hasSupplement)
|
||||||
|
bytes[topDict['Encoding']] = 0;
|
||||||
|
|
||||||
// charstrings contains info about glyphs (one element per glyph
|
// charstrings contains info about glyphs (one element per glyph
|
||||||
// containing mappings for {unicode, width})
|
// containing mappings for {unicode, width})
|
||||||
var charstrings = this.getCharStrings(charset, charStrings, encoding,
|
var charstrings = this.getCharStrings(charset, charStrings,
|
||||||
privDict, this.properties);
|
privDict, this.properties);
|
||||||
|
|
||||||
// create the mapping between charstring and glyph id
|
// create the mapping between charstring and glyph id
|
||||||
var glyphIds = [];
|
var glyphIds = [];
|
||||||
@ -2190,9 +2194,14 @@ var Type2CFF = (function() {
|
|||||||
|
|
||||||
this.charstrings = charstrings;
|
this.charstrings = charstrings;
|
||||||
this.glyphIds = glyphIds;
|
this.glyphIds = glyphIds;
|
||||||
|
|
||||||
|
var data = [];
|
||||||
|
for (var i = 0, ii = bytes.length; i < ii; ++i)
|
||||||
|
data.push(bytes[i]);
|
||||||
|
return data;
|
||||||
},
|
},
|
||||||
|
|
||||||
getCharStrings: function cff_charstrings(charsets, charStrings, encoding,
|
getCharStrings: function cff_charstrings(charsets, charStrings,
|
||||||
privDict, properties) {
|
privDict, properties) {
|
||||||
var widths = properties.widths;
|
var widths = properties.widths;
|
||||||
|
|
||||||
@ -2203,13 +2212,10 @@ var Type2CFF = (function() {
|
|||||||
var differences = properties.differences;
|
var differences = properties.differences;
|
||||||
for (var i = 1; i < charsets.length; i++) {
|
for (var i = 1; i < charsets.length; i++) {
|
||||||
var glyph = charsets[i];
|
var glyph = charsets[i];
|
||||||
var charCode = properties.glyphs[glyph];
|
var code = differences.indexOf(glyph);
|
||||||
if (charCode) {
|
var width = widths[code] || defaultWidth;
|
||||||
var width = widths[charCode] || defaultWidth;
|
properties.encoding[i] = i + 0x1F;
|
||||||
charstrings.push({unicode: charCode, width: width, gid: i});
|
charstrings.push({unicode: code + 0x1F, width: width, gid: i});
|
||||||
} else if (glyph !== '.notdef') {
|
|
||||||
warn('Cannot find unicode for glyph ' + charName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// sort the array by the unicode value
|
// sort the array by the unicode value
|
||||||
@ -2248,8 +2254,10 @@ var Type2CFF = (function() {
|
|||||||
for (var i = 1; i <= glyphsCount; i++)
|
for (var i = 1; i <= glyphsCount; i++)
|
||||||
encoding[bytes[pos++]] = i;
|
encoding[bytes[pos++]] = i;
|
||||||
|
|
||||||
if (format & 0x80)
|
if (format & 0x80) {
|
||||||
readSupplement();
|
readSupplement();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
@ -2262,8 +2270,10 @@ var Type2CFF = (function() {
|
|||||||
encoding[j] = gid++;
|
encoding[j] = gid++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (format & 0x80)
|
if (format & 0x80) {
|
||||||
readSupplement();
|
readSupplement();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -2271,7 +2281,7 @@ var Type2CFF = (function() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return encoding;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
parseCharsets: function cff_parsecharsets(pos, length, strings) {
|
parseCharsets: function cff_parsecharsets(pos, length, strings) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user