Skip to content

Commit ea63330

Browse files
committed
Merge pull request mozilla#3187 from brendandahl/cid-glyph-selection
Fix glyph selection for CID fonts that don't actually have CID font files.
2 parents f87de63 + e128f8b commit ea63330

File tree

3 files changed

+38
-15
lines changed

3 files changed

+38
-15
lines changed

src/fonts.js

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5712,9 +5712,9 @@ var CFFFont = (function CFFFontClosure() {
57125712
this.properties = properties;
57135713

57145714
var parser = new CFFParser(file, properties);
5715-
var cff = parser.parse();
5716-
var compiler = new CFFCompiler(cff);
5717-
this.readExtra(cff);
5715+
this.cff = parser.parse();
5716+
var compiler = new CFFCompiler(this.cff);
5717+
this.readExtra();
57185718
try {
57195719
this.data = compiler.compile();
57205720
} catch (e) {
@@ -5726,12 +5726,10 @@ var CFFFont = (function CFFFontClosure() {
57265726
}
57275727

57285728
CFFFont.prototype = {
5729-
readExtra: function CFFFont_readExtra(cff) {
5729+
readExtra: function CFFFont_readExtra() {
57305730
// charstrings contains info about glyphs (one element per glyph
57315731
// containing mappings for {unicode, width})
5732-
var charset = cff.charset.charset;
5733-
var encoding = cff.encoding ? cff.encoding.encoding : null;
5734-
var charstrings = this.getCharStrings(charset, encoding);
5732+
var charstrings = this.getCharStrings();
57355733

57365734
// create the mapping between charstring and glyph id
57375735
var glyphIds = [];
@@ -5740,21 +5738,39 @@ var CFFFont = (function CFFFontClosure() {
57405738

57415739
this.charstrings = charstrings;
57425740
this.glyphIds = glyphIds;
5743-
this.seacs = cff.seacs;
5741+
this.seacs = this.cff.seacs;
57445742
},
5745-
getCharStrings: function CFFFont_getCharStrings(charsets, encoding) {
5743+
getCharStrings: function CFFFont_getCharStrings() {
5744+
var cff = this.cff;
5745+
var charsets = cff.charset.charset;
5746+
var encoding = cff.encoding ? cff.encoding.encoding : null;
57465747
var charstrings = [];
57475748
var unicodeUsed = [];
57485749
var unassignedUnicodeItems = [];
57495750
var inverseEncoding = [];
5750-
// CID fonts don't have an encoding.
5751-
if (encoding !== null)
5751+
var gidStart = 0;
5752+
// Even though the CFF font may not actually be a CID font is could have
5753+
// CID information in the font descriptor.
5754+
if (this.properties.cidSystemInfo) {
5755+
// According to section 9.7.4.2 if the font is actually a CID font then
5756+
// we should use the charset to map CIDs to GIDs. If it is not actually
5757+
// a CID font then CIDs can be mapped directly to GIDs.
5758+
if (this.cff.isCIDFont) {
5759+
inverseEncoding = charsets;
5760+
} else {
5761+
for (var i = 0, ii = charsets.length; i < charsets.length; i++) {
5762+
inverseEncoding.push(i);
5763+
}
5764+
}
5765+
} else {
57525766
for (var charcode in encoding)
57535767
inverseEncoding[encoding[charcode]] = charcode | 0;
5754-
else
5755-
inverseEncoding = charsets;
5756-
var i = charsets[0] == '.notdef' ? 1 : 0;
5757-
for (var ii = charsets.length; i < ii; i++) {
5768+
if (charsets[0] === '.notedef') {
5769+
gidStart = 1;
5770+
}
5771+
}
5772+
5773+
for (var i = gidStart, ii = charsets.length; i < ii; i++) {
57585774
var glyph = charsets[i];
57595775

57605776
var code = inverseEncoding[i];

test/pdfs/bug816075.pdf

20.6 KB
Binary file not shown.

test/test_manifest.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,13 @@
10191019
"rounds": 1,
10201020
"type": "eq"
10211021
},
1022+
{ "id": "bug816075",
1023+
"file": "pdfs/bug816075.pdf",
1024+
"md5": "7ec87c115c1f9ec41234cc7002555e82",
1025+
"rounds": 1,
1026+
"type": "eq",
1027+
"about": "A CIDFontType0 font with a CFF font that isn't actually CID."
1028+
},
10221029
{ "id": "noembed-identity-2",
10231030
"file": "pdfs/noembed-identity-2.pdf",
10241031
"md5": "13b7d9ab9579d45c10bc8d499d087f21",

0 commit comments

Comments
 (0)