diff --git a/src/evaluator.js b/src/evaluator.js index 3da4322c0..276d59543 100644 --- a/src/evaluator.js +++ b/src/evaluator.js @@ -1089,9 +1089,30 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { properties.widths = glyphsWidths; }, + isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) { + + // Simulating descriptor flags attribute + var fontNameWoStyle = baseFontName.split('-')[0]; + return (fontNameWoStyle in serifFonts) || + (fontNameWoStyle.search(/serif/gi) !== -1); + }, + getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) { var defaultWidth = 0, widths = [], monospace = false; - var glyphWidths = Metrics[stdFontMap[name] || name]; + + var lookupName = stdFontMap[name] || name; + + if (!(lookupName in Metrics)) { + // Use default fonts for looking up font metrics if the passed + // font is not a base font + if (this.isSerifFont(name)) { + lookupName = 'Times-Roman'; + } else { + lookupName = 'Helvetica'; + } + } + var glyphWidths = Metrics[lookupName]; + if (isNum(glyphWidths)) { defaultWidth = glyphWidths; monospace = true; @@ -1153,8 +1174,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { // Simulating descriptor flags attribute var fontNameWoStyle = baseFontName.split('-')[0]; - var flags = (serifFonts[fontNameWoStyle] || - (fontNameWoStyle.search(/serif/gi) != -1) ? FontFlags.Serif : 0) | + var flags = ( + this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) | (metrics.monospace ? FontFlags.FixedPitch : 0) | (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic : FontFlags.Nonsymbolic); diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 050b533fe..ef210099d 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -2,6 +2,7 @@ !tracemonkey.pdf !issue2391-1.pdf +!issue2391-2.pdf !ArabicCIDTrueType.pdf !ThuluthFeatures.pdf !arial_unicode_ab_cidfont.pdf diff --git a/test/pdfs/issue2391-2.pdf b/test/pdfs/issue2391-2.pdf new file mode 100644 index 000000000..e3683e5fd --- /dev/null +++ b/test/pdfs/issue2391-2.pdf @@ -0,0 +1,130 @@ +%PDF-1.4 +%âãÏÓ +1 0 obj +<< +/Pages 2 0 R +/Metadata 3 0 R +/Type /Catalog +>> +endobj +2 0 obj +<< +/Kids [4 0 R] +/Count 1 +/Type /Pages +>> +endobj +4 0 obj +<< +/Rotate 0 +/Parent 2 0 R +/Resources +<< +/ExtGState 5 0 R +/Font 6 0 R +/ProcSet [/PDF /Text] +>> +/MediaBox [0 0 595 842] +/Contents 7 0 R +/Type /Page +>> +endobj +7 0 obj +<< +/Length 121 +>> +stream +q 0.1 0 0 0.1 0 0 cm +/R7 gs +0 g +q +10 0 0 10 0 0 cm BT +/R8 10 Tf +1 0 0 1 29 805 Tm +(test non-existant base font)Tj +ET +Q +Q + +endstream +endobj +8 0 obj +<< +/Type /ExtGState +/OPM 1 +>> +endobj +9 0 obj +<< +/BaseFont /Monaco +/Subtype /Type1 +/Type /Font +>> +endobj +5 0 obj +<< +/R7 8 0 R +>> +endobj +6 0 obj +<< +/R8 9 0 R +>> +endobj +3 0 obj +<< +/Subtype /XML +/Length 1421 +/Type /Metadata +>> +stream + + + + + +2013-01-11T10:57:59-08:00 +2013-01-11T10:57:59-08:00 +GNU Enscript 1.6.6 + +Enscript OutputMack Duan + + + + + +endstream +endobj +10 0 obj +<< +/Creator (GNU Enscript 1.6.6) +/Title (Enscript Output) +/Producer (GPL Ghostscript 9.05) +/Author (Mack Duan) +/ModDate (D:20130111105759-08'00') +/CreationDate (D:20130111105759-08'00') +>> +endobj xref +0 11 +0000000000 65535 f +0000000015 00000 n +0000000082 00000 n +0000000666 00000 n +0000000141 00000 n +0000000600 00000 n +0000000633 00000 n +0000000309 00000 n +0000000484 00000 n +0000000531 00000 n +0000002172 00000 n +trailer + +<< +/Info 10 0 R +/Root 1 0 R +/Size 11 +/ID [<2eee0bd94f14c7014ff602c9df19ad9a> <2eee0bd94f14c7014ff602c9df19ad9a>] +>> +startxref +2378 +%%EOF diff --git a/test/test_manifest.json b/test/test_manifest.json index 14026c9e2..da4821a48 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -24,6 +24,12 @@ "pageLimit": 1, "type": "load" }, + { "id": "issue2391-2", + "file": "pdfs/issue2391-2.pdf", + "md5": "7e68756d11021a087383eaac95ba45dd", + "rounds": 1, + "type": "eq" + }, { "id": "html5-canvas-cheat-sheet-load", "file": "pdfs/canvas.pdf", "md5": "59510028561daf62e00bf9f6f066b033",