Skip to content

Commit

Permalink
Fallback to the StandardEncoding for Nonsymbolic fonts without `/En…
Browse files Browse the repository at this point in the history
…coding` entry (issue 7580)

Even though this patch passes all tests (unit/font/reference) locally, including the new ones that I added in PR 7621, I'm still a bit nervous about modifying the code that choose the fallback encoding for fonts without an `/Encoding` entry.
Note that over the years this code has been changed on a number of occasions, see a possibly incomplete [list here], to deal with various cases of incorrect font data.

According to the PDF specification, see http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf#G8.1904184, it seems that we should fallback to the `StandardEncoding` for Nonsymbolic fonts.
There's obviously a risk that fixing this particular issue *could* break other PDF files for which we don't have tests. However I've tried to change the logic as little as possible in this patch, to hopefully reduce possible breakage.

Based on debugging numerous font issue, it seems that a lot of fonts actually set the Symbolic flag, even when they are in fact *not* Symbolic. Fonts actually marked as Nonsymbolic seem to be somewhat less common, which I hope should reduce the risk of the patch somewhat.

Fixes 7580.
  • Loading branch information
Snuffleupagus committed Sep 13, 2016
1 parent 4d15928 commit 356b321
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -1738,11 +1738,18 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
if (baseEncodingName) {
properties.defaultEncoding = getEncoding(baseEncodingName).slice();
} else {
encoding = (properties.type === 'TrueType' ?
WinAnsiEncoding : StandardEncoding);
var isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
var isNonsymbolicFont = !!(properties.flags & FontFlags.Nonsymbolic);
// According to "Table 114" in section "9.6.6.1 General" (under
// "9.6.6 Character Encoding") of the PDF specification, a Nonsymbolic
// font should use the `StandardEncoding` if no encoding is specified.
encoding = StandardEncoding;
if (properties.type === 'TrueType' && !isNonsymbolicFont) {
encoding = WinAnsiEncoding;
}
// The Symbolic attribute can be misused for regular fonts
// Heuristic: we have to check if the font is a standard one also
if (!!(properties.flags & FontFlags.Symbolic)) {
if (isSymbolicFont) {
encoding = MacRomanEncoding;
if (!properties.file) {
if (/Symbol/i.test(properties.name)) {
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
!issue7446.pdf
!issue7492.pdf
!issue7544.pdf
!issue7580.pdf
!issue7598.pdf
!filled-background.pdf
!ArabicCIDTrueType.pdf
Expand Down
Binary file added test/pdfs/issue7580.pdf
Binary file not shown.
14 changes: 14 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1615,6 +1615,20 @@
"link": false,
"type": "eq"
},
{ "id": "issue7580-eq",
"file": "pdfs/issue7580.pdf",
"md5": "44dd5a9b4373fcab9890cf567722a766",
"rounds": 1,
"link": false,
"type": "eq"
},
{ "id": "issue7580-text",
"file": "pdfs/issue7580.pdf",
"md5": "44dd5a9b4373fcab9890cf567722a766",
"rounds": 1,
"link": false,
"type": "text"
},
{ "id": "issue6612-text",
"file": "pdfs/issue6612.pdf",
"md5": "657f33236496916597cd70ef1222509a",
Expand Down

0 comments on commit 356b321

Please sign in to comment.