From d52495a9c83c266a34d0aad77a7bb699ea47720f Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 9 Jan 2016 11:50:48 +0100 Subject: [PATCH] [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(-) create mode 100644 test/pdfs/issue4684.pdf diff --git a/src/core/fonts.js b/src/core/fonts.js index cdb08c74b..e20dad92c 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 fe8e207ee..d1d8cf0bc 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 0000000000000000000000000000000000000000..b2c15f09bda9ae2bf89ee612bbdcd2e206ff8a46 GIT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