[Pkg-javascript-commits] [pdf.js] 06/119: Guess CIDFontType0 subtype based on font file contents (issue 5751)

David Prévot taffit at moszumanska.debian.org
Wed May 13 21:27:35 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository pdf.js.

commit e894a0a4c670585261f60b184372828cdac4e608
Author: Jonas Jenwald <jonas.jenwald at gmail.com>
Date:   Mon Feb 23 16:01:08 2015 +0100

    Guess CIDFontType0 subtype based on font file contents (issue 5751)
---
 src/core/fonts.js       |  18 ++++++++++++++++++
 test/pdfs/.gitignore    |   1 +
 test/pdfs/issue5751.pdf | Bin 0 -> 67017 bytes
 test/test_manifest.json |   7 +++++++
 4 files changed, 26 insertions(+)

diff --git a/src/core/fonts.js b/src/core/fonts.js
index 0541292..74609b1 100644
--- a/src/core/fonts.js
+++ b/src/core/fonts.js
@@ -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) {
@@ -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
diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore
index 4e727c4..83df9ba 100644
--- a/test/pdfs/.gitignore
+++ b/test/pdfs/.gitignore
@@ -62,6 +62,7 @@
 !bug868745.pdf
 !mmtype1.pdf
 !issue5704.pdf
+!issue5751.pdf
 !bug893730.pdf
 !bug864847.pdf
 !issue1002.pdf
diff --git a/test/pdfs/issue5751.pdf b/test/pdfs/issue5751.pdf
new file mode 100644
index 0000000..763de9d
Binary files /dev/null and b/test/pdfs/issue5751.pdf differ
diff --git a/test/test_manifest.json b/test/test_manifest.json
index ae42e4a..577b149 100644
--- a/test/test_manifest.json
+++ b/test/test_manifest.json
@@ -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",

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git



More information about the Pkg-javascript-commits mailing list