Fix priority of which font encoding is used.

This commit is contained in:
Brendan Dahl 2013-04-10 09:51:06 -07:00
parent a017e105cc
commit 0f41b2db44
5 changed files with 36 additions and 9 deletions

View File

@ -939,27 +939,41 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
}
// Based on 9.6.6 of the spec the encoding can come from multiple places
// but should be prioritized in the following order:
// 1. Encoding dictionary
// 2. Encoding within font file (Type1 or Type1C)
// 3. Default (depends on font type)
// Differences applied to the above.
// Note: we don't fill in the encoding from the font file(2) here but use
// the flag overridableEncoding to signal that the font can override the
// encoding if it has one built in.
var overridableEncoding = true;
var hasEncoding = false;
var flags = properties.flags;
var differences = [];
var baseEncoding = Encodings.StandardEncoding;
var baseEncoding = properties.type === 'TrueType' ?
Encodings.WinAnsiEncoding :
Encodings.StandardEncoding;
// The Symbolic attribute can be misused for regular fonts
// Heuristic: we have to check if the font is a standard one also
if (!!(flags & FontFlags.Symbolic)) {
baseEncoding = !properties.file ? Encodings.symbolsEncoding :
Encodings.MacRomanEncoding;
}
var hasEncoding = dict.has('Encoding');
if (hasEncoding) {
if (dict.has('Encoding')) {
var encoding = dict.get('Encoding');
if (isDict(encoding)) {
var baseName = encoding.get('BaseEncoding');
if (baseName)
if (baseName) {
overridableEncoding = false;
hasEncoding = true;
baseEncoding = Encodings[baseName.name];
else
hasEncoding = false; // base encoding was not provided
}
// Load the differences between the base and original
if (encoding.has('Differences')) {
hasEncoding = true;
var diffEncoding = encoding.get('Differences');
var index = 0;
for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
@ -971,6 +985,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
}
}
} else if (isName(encoding)) {
overridableEncoding = false;
hasEncoding = true;
baseEncoding = Encodings[encoding.name];
} else {
error('Encoding is not a Name nor a Dict');
@ -980,6 +996,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
properties.differences = differences;
properties.baseEncoding = baseEncoding;
properties.hasEncoding = hasEncoding;
properties.overridableEncoding = overridableEncoding;
},
readToUnicode: function PartialEvaluator_readToUnicode(toUnicode, xref,

View File

@ -3104,7 +3104,7 @@ var Font = (function FontClosure() {
encoding[code] = glyphName;
}
properties.glyphNameMap = glyphNameMap;
if (!properties.hasEncoding)
if (properties.overridableEncoding)
properties.baseEncoding = encoding;
}
@ -5345,7 +5345,7 @@ var Type1Parser = (function Type1ParserClosure() {
}
}
}
if (!properties.hasEncoding && encoding) {
if (properties.overridableEncoding && encoding) {
properties.baseEncoding = encoding;
break;
}

View File

@ -0,0 +1,2 @@
https://bugzilla.mozilla.org/attachment.cgi?id=733257

View File

@ -1013,6 +1013,14 @@
"type": "eq",
"about": "Has a 4 bit per component image with mask and decode."
},
{ "id": "issue3064",
"file": "pdfs/issue3064.pdf",
"md5": "0307415b7d69b13acaf8bd4285d9544b",
"rounds": 1,
"link": true,
"type": "eq",
"about": "True type font with encoding dict with no base encoding but with differences."
},
{ "id": "p020121130574743273239",
"file": "pdfs/P020121130574743273239.pdf",
"md5": "271b65885d42d174cbc597ca89becb1a",

View File

@ -383,7 +383,7 @@ describe('font', function() {
'dup 33 /arrowright put\n' +
'readonly def\n');
var parser = new Type1Parser(stream);
var props = {};
var props = { overridableEncoding: true };
var program = parser.extractFontHeader(props);
expect(props.baseEncoding[33]).toEqual('arrowright');
});