Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guess CIDFontType0 subtype based on font file contents (issue 5751) #5756

Merged
merged 1 commit into from
Apr 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/core/fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2575,6 +2575,10 @@ var Font = (function FontClosure() {
if (subtype === 'OpenType') {
type = 'OpenType';
}
// Some CIDFontType0C fonts by mistake claim CIDFontType0.
if (type === 'CIDFontType0') {
subtype = isType1File(file) ? 'CIDFontType0' : 'CIDFontType0C';
}

var data;
switch (type) {
Expand Down Expand Up @@ -2655,6 +2659,20 @@ var Font = (function FontClosure() {
return readUint32(header, 0) === 0x00010000;
}

function isType1File(file) {
var header = file.peekBytes(2);
// All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
if (header[0] === 0x25 && header[1] === 0x21) {
return true;
}
// ... obviously some fonts violate that part of the specification,
// please refer to the comment in |Type1Font| below.
if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
return true;
}
return false;
}

/**
* Rebuilds the char code to glyph ID map by trying to replace the char codes
* with their unicode value. It also moves char codes that are in known
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
!bug868745.pdf
!mmtype1.pdf
!issue5704.pdf
!issue5751.pdf
!bug893730.pdf
!bug864847.pdf
!issue1002.pdf
Expand Down
Binary file added test/pdfs/issue5751.pdf
Binary file not shown.
7 changes: 7 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,13 @@
"link": true,
"type": "eq"
},
{ "id": "issue5751",
"file": "pdfs/issue5751.pdf",
"md5": "9334a52dc85747f1e3422767e0cd3ee9",
"rounds": 1,
"link": false,
"type": "eq"
},
{ "id": "bug867484",
"file": "pdfs/bug867484.pdf",
"md5": "347af7b0ef7279b1a7f43b03bfda4548",
Expand Down