[Pkg-javascript-commits] [pdf.js] 11/210: Guesses Type1C font type based on file content

David Prévot taffit at moszumanska.debian.org
Thu Jun 5 14:20:56 UTC 2014


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

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

commit 98e023e464d21e36b437bd034e5acc69e4e166b7
Author: Yury Delendik <ydelendik at mozilla.com>
Date:   Thu Apr 24 11:48:18 2014 -0500

    Guesses Type1C font type based on file content
---
 src/core/fonts.js       |  14 ++++++++++++--
 test/pdfs/.gitignore    |   1 +
 test/pdfs/issue4668.pdf | Bin 0 -> 32814 bytes
 test/test_manifest.json |   6 ++++++
 4 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/src/core/fonts.js b/src/core/fonts.js
index 5cea7df..8072739 100644
--- a/src/core/fonts.js
+++ b/src/core/fonts.js
@@ -19,7 +19,7 @@
            isNum, ISOAdobeCharset, Stream, stringToArray, stringToBytes,
            string32, TextDecoder, warn, Lexer, Util, FONT_IDENTITY_MATRIX,
            FontRendererFactory, shadow, isString, IdentityCMap, Name,
-           CMapFactory, PDFJS */
+           CMapFactory, PDFJS, readUint32 */
 
 'use strict';
 
@@ -2259,7 +2259,12 @@ var Font = (function FontClosure() {
     // Some fonts might use wrong font types for Type1C or CIDFontType0C
     var subtype = properties.subtype;
     if (subtype == 'Type1C' && (type != 'Type1' && type != 'MMType1')) {
-      type = 'Type1';
+      // Some TrueType fonts by mistake claim Type1C
+      if (isTrueTypeFile(file)) {
+        subtype = 'TrueType';
+      } else {
+        type = 'Type1';
+      }
     }
     if (subtype == 'CIDFontType0C' && type != 'CIDFontType0') {
       type = 'CIDFontType0';
@@ -2407,6 +2412,11 @@ var Font = (function FontClosure() {
     file.virtualOffset += data.length;
   }
 
+  function isTrueTypeFile(file) {
+    var header = file.peekBytes(4);
+    return readUint32(header, 0) === 0x00010000;
+  }
+
   /**
    * 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 8fd46ba..3067af5 100644
--- a/test/pdfs/.gitignore
+++ b/test/pdfs/.gitignore
@@ -50,6 +50,7 @@
 !bug864847.pdf
 !issue1002.pdf
 !issue925.pdf
+!issue4668.pdf
 !gradientfill.pdf
 !bug903856.pdf
 !bug850854.pdf
diff --git a/test/pdfs/issue4668.pdf b/test/pdfs/issue4668.pdf
new file mode 100644
index 0000000..b6ef90a
Binary files /dev/null and b/test/pdfs/issue4668.pdf differ
diff --git a/test/test_manifest.json b/test/test_manifest.json
index 8f7cf3b..de9697b 100644
--- a/test/test_manifest.json
+++ b/test/test_manifest.json
@@ -1583,6 +1583,12 @@
        "lastPage": 1,
        "type": "load"
     },
+    {  "id": "issue4668",
+      "file": "pdfs/issue4668.pdf",
+      "md5": "a749d5ca995ad745411406d29156b04e",
+      "rounds": 1,
+      "type": "eq"
+    },
     {  "id": "issue3666",
        "file": "pdfs/issue3666.pdf",
        "md5": "c2156a34b9634b174556910732ab9df0",

-- 
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