[Pkg-javascript-commits] [pdf.js] 117/414: [TrueType] Recover from a missing "glyf" table by replacing it with dummy data, utilizing the existing code in `sanitizeGlyphLocations`

David Prévot taffit at moszumanska.debian.org
Tue Jun 28 17:12:12 UTC 2016


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

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

commit d52495a9c83c266a34d0aad77a7bb699ea47720f
Author: Jonas Jenwald <jonas.jenwald at gmail.com>
Date:   Sat Jan 9 11:50:48 2016 +0100

    [TrueType] Recover from a missing "glyf" table by replacing it with dummy data, utilizing the existing code in `sanitizeGlyphLocations`
    
    It seems to be fairly common for OCR software to include incomplete TrueType fonts, notable missing the "glyf" table, in PDF files. Since we currently reject such fonts, the result is that text-selection/copying is broken.
    
    This patch contains a suggested approach to try and use these kind of broken fonts, by using existing code in `sanitizeGlyphLocations` to replace a missing "glyf" table with dummy data.
    
    Fixes 4684.
    Fixes 6007.
    Fixes 6829.
---
 src/core/fonts.js       |  12 ++++++++++--
 test/pdfs/.gitignore    |   1 +
 test/pdfs/issue4684.pdf | Bin 0 -> 3714 bytes
 test/test_manifest.json |   8 ++++++++
 4 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/src/core/fonts.js b/src/core/fonts.js
index cdb08c7..e20dad9 100644
--- a/src/core/fonts.js
+++ b/src/core/fonts.js
@@ -4154,8 +4154,16 @@ var Font = (function FontClosure() {
         delete tables['cvt '];
         this.isOpenType = true;
       } else {
-        if (!tables.glyf || !tables.loca) {
-          error('Required "glyf" or "loca" tables are not found');
+        if (!tables.loca) {
+          error('Required "loca" table is not found');
+        }
+        if (!tables.glyf) {
+          warn('Required "glyf" table is not found -- trying to recover.');
+          // Note: We use `sanitizeGlyphLocations` to add dummy glyf data below.
+          tables.glyf = {
+            tag: 'glyf',
+            data: new Uint8Array(0),
+          };
         }
         this.isOpenType = false;
       }
diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore
index fe8e207..d1d8cf0 100644
--- a/test/pdfs/.gitignore
+++ b/test/pdfs/.gitignore
@@ -10,6 +10,7 @@
 !issue2391-1.pdf
 !issue2391-2.pdf
 !issue4665.pdf
+!issue4684.pdf
 !issue5801.pdf
 !issue5946.pdf
 !issue5972.pdf
diff --git a/test/pdfs/issue4684.pdf b/test/pdfs/issue4684.pdf
new file mode 100644
index 0000000..b2c15f0
Binary files /dev/null and b/test/pdfs/issue4684.pdf differ
diff --git a/test/test_manifest.json b/test/test_manifest.json
index c62dda6..00460e3 100644
--- a/test/test_manifest.json
+++ b/test/test_manifest.json
@@ -1789,6 +1789,14 @@
       "type": "eq",
       "about": "Has a multi-byte char codes."
     },
+    {  "id": "issue4684-text",
+       "file": "pdfs/issue4684.pdf",
+       "md5": "af5056fcdfb08bd7adc1710d36e4b5b5",
+       "link": false,
+       "rounds": 1,
+       "type": "text",
+       "about": "Invisible (and broken) TrueType font used for text-selection."
+    },
     {  "id": "issue1912",
       "file": "pdfs/issue1912.pdf",
       "md5": "15305b7c2cba971e7423de3f6ad38fef",

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