Merge pull request #2581 from brendandahl/fix-cid
Fix normalized CID fonts for direct write 6.1.
This commit is contained in:
commit
9a58bc9aba
55
src/fonts.js
55
src/fonts.js
@ -5366,7 +5366,7 @@ var CFFFont = (function CFFFontClosure() {
|
|||||||
this.properties = properties;
|
this.properties = properties;
|
||||||
|
|
||||||
var parser = new CFFParser(file, properties);
|
var parser = new CFFParser(file, properties);
|
||||||
var cff = parser.parse(true);
|
var cff = parser.parse();
|
||||||
var compiler = new CFFCompiler(cff);
|
var compiler = new CFFCompiler(cff);
|
||||||
this.readExtra(cff);
|
this.readExtra(cff);
|
||||||
try {
|
try {
|
||||||
@ -5531,7 +5531,7 @@ var CFFParser = (function CFFParserClosure() {
|
|||||||
this.properties = properties;
|
this.properties = properties;
|
||||||
}
|
}
|
||||||
CFFParser.prototype = {
|
CFFParser.prototype = {
|
||||||
parse: function CFFParser_parse(normalizeCIDData) {
|
parse: function CFFParser_parse() {
|
||||||
var properties = this.properties;
|
var properties = this.properties;
|
||||||
var cff = new CFF();
|
var cff = new CFF();
|
||||||
this.cff = cff;
|
this.cff = cff;
|
||||||
@ -5599,30 +5599,6 @@ var CFFParser = (function CFFParserClosure() {
|
|||||||
cff.charset = charset;
|
cff.charset = charset;
|
||||||
cff.encoding = encoding;
|
cff.encoding = encoding;
|
||||||
|
|
||||||
if (!cff.isCIDFont || !normalizeCIDData)
|
|
||||||
return cff;
|
|
||||||
|
|
||||||
// DirectWrite does not like CID fonts data. Trying to convert/flatten
|
|
||||||
// the font data and remove CID properties.
|
|
||||||
if (cff.fdArray.length !== 1) {
|
|
||||||
warn('Unable to normalize CID font in CFF data -- using font as is');
|
|
||||||
return cff;
|
|
||||||
}
|
|
||||||
|
|
||||||
var fontDict = cff.fdArray[0];
|
|
||||||
// Make the sanitizer happy and remove anything that is only for CID
|
|
||||||
// fonts.
|
|
||||||
fontDict.setByKey(17, topDict.getByName('CharStrings'));
|
|
||||||
fontDict.removeByName('CIDFontVersion');
|
|
||||||
fontDict.removeByName('CIDFontRevision');
|
|
||||||
fontDict.removeByName('CIDFontType');
|
|
||||||
fontDict.removeByName('CIDCount');
|
|
||||||
fontDict.removeByName('UIDBase');
|
|
||||||
cff.topDict = fontDict;
|
|
||||||
cff.isCIDFont = false;
|
|
||||||
delete cff.fdArray;
|
|
||||||
delete cff.fdSelect;
|
|
||||||
|
|
||||||
return cff;
|
return cff;
|
||||||
},
|
},
|
||||||
parseHeader: function CFFParser_parseHeader() {
|
parseHeader: function CFFParser_parseHeader() {
|
||||||
@ -6253,9 +6229,12 @@ var CFFTopDict = (function CFFTopDictClosure() {
|
|||||||
[[12, 33], 'CIDFontType', 'num', 0],
|
[[12, 33], 'CIDFontType', 'num', 0],
|
||||||
[[12, 34], 'CIDCount', 'num', 8720],
|
[[12, 34], 'CIDCount', 'num', 8720],
|
||||||
[[12, 35], 'UIDBase', 'num', null],
|
[[12, 35], 'UIDBase', 'num', null],
|
||||||
[[12, 36], 'FDArray', 'offset', null],
|
// XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
|
||||||
|
// before FDArray.
|
||||||
[[12, 37], 'FDSelect', 'offset', null],
|
[[12, 37], 'FDSelect', 'offset', null],
|
||||||
[[12, 38], 'FontName', 'sid', null]];
|
[[12, 36], 'FDArray', 'offset', null],
|
||||||
|
[[12, 38], 'FontName', 'sid', null]
|
||||||
|
];
|
||||||
var tables = null;
|
var tables = null;
|
||||||
function CFFTopDict(strings) {
|
function CFFTopDict(strings) {
|
||||||
if (tables === null)
|
if (tables === null)
|
||||||
@ -6426,7 +6405,9 @@ var CFFCompiler = (function CFFCompilerClosure() {
|
|||||||
var nameIndex = this.compileNameIndex(cff.names);
|
var nameIndex = this.compileNameIndex(cff.names);
|
||||||
output.add(nameIndex);
|
output.add(nameIndex);
|
||||||
|
|
||||||
var compiled = this.compileTopDicts([cff.topDict], output.length);
|
var compiled = this.compileTopDicts([cff.topDict],
|
||||||
|
output.length,
|
||||||
|
cff.isCIDFont);
|
||||||
output.add(compiled.output);
|
output.add(compiled.output);
|
||||||
var topDictTracker = compiled.trackers[0];
|
var topDictTracker = compiled.trackers[0];
|
||||||
|
|
||||||
@ -6469,8 +6450,9 @@ var CFFCompiler = (function CFFCompilerClosure() {
|
|||||||
topDictTracker.setEntryLocation('FDSelect', [output.length], output);
|
topDictTracker.setEntryLocation('FDSelect', [output.length], output);
|
||||||
var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
|
var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
|
||||||
output.add(fdSelect);
|
output.add(fdSelect);
|
||||||
|
// It is unclear if the sub font dictionary can have CID related
|
||||||
var compiled = this.compileTopDicts(cff.fdArray, output.length);
|
// dictionary keys, but the sanitizer doesn't like them so remove them.
|
||||||
|
var compiled = this.compileTopDicts(cff.fdArray, output.length, true);
|
||||||
topDictTracker.setEntryLocation('FDArray', [output.length], output);
|
topDictTracker.setEntryLocation('FDArray', [output.length], output);
|
||||||
output.add(compiled.output);
|
output.add(compiled.output);
|
||||||
var fontDictTrackers = compiled.trackers;
|
var fontDictTrackers = compiled.trackers;
|
||||||
@ -6545,11 +6527,20 @@ var CFFCompiler = (function CFFCompilerClosure() {
|
|||||||
nameIndex.add(stringToArray(names[i]));
|
nameIndex.add(stringToArray(names[i]));
|
||||||
return this.compileIndex(nameIndex);
|
return this.compileIndex(nameIndex);
|
||||||
},
|
},
|
||||||
compileTopDicts: function CFFCompiler_compileTopDicts(dicts, length) {
|
compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
|
||||||
|
length,
|
||||||
|
removeCidKeys) {
|
||||||
var fontDictTrackers = [];
|
var fontDictTrackers = [];
|
||||||
var fdArrayIndex = new CFFIndex();
|
var fdArrayIndex = new CFFIndex();
|
||||||
for (var i = 0, ii = dicts.length; i < ii; ++i) {
|
for (var i = 0, ii = dicts.length; i < ii; ++i) {
|
||||||
var fontDict = dicts[i];
|
var fontDict = dicts[i];
|
||||||
|
if (removeCidKeys) {
|
||||||
|
fontDict.removeByName('CIDFontVersion');
|
||||||
|
fontDict.removeByName('CIDFontRevision');
|
||||||
|
fontDict.removeByName('CIDFontType');
|
||||||
|
fontDict.removeByName('CIDCount');
|
||||||
|
fontDict.removeByName('UIDBase');
|
||||||
|
}
|
||||||
var fontDictTracker = new CFFOffsetTracker();
|
var fontDictTracker = new CFFOffsetTracker();
|
||||||
var fontDictData = this.compileDict(fontDict, fontDictTracker);
|
var fontDictData = this.compileDict(fontDict, fontDictTracker);
|
||||||
fontDictTrackers.push(fontDictTracker);
|
fontDictTrackers.push(fontDictTracker);
|
||||||
|
Loading…
Reference in New Issue
Block a user