pdf.js/src/core
Jonas Jenwald b6d090cc14 Fallback to the built-in font renderer when font loading fails
After PR 9340 all glyphs are now re-mapped to a Private Use Area (PUA) which means that if a font fails to load, for whatever reason[1], all glyphs in the font will now render as Unicode glyph outlines.
This obviously doesn't look good, to say the least, and might be seen as a "regression" since previously many glyphs were left in their original positions which provided a slightly better fallback[2].

Hence this patch, which implements a *general* fallback to the PDF.js built-in font renderer for fonts that fail to load (i.e. are rejected by the sanitizer). One caveat here is that this only works for the Font Loading API, since it's easy to handle errors in that case[3].

The solution implemented in this patch does *not* in any way delay the loading of valid fonts, which was the problem with my previous attempt at a solution, and will only require a bit of extra work/waiting for those fonts that actually fail to load.

*Please note:* This patch doesn't fix any of the underlying PDF.js font conversion bugs that's responsible for creating corrupt font files, however it does *improve* rendering in a number of cases; refer to this possibly incomplete list:

[Bug 1524888](https://bugzilla.mozilla.org/show_bug.cgi?id=1524888)
Issue 10175
Issue 10232

---
[1] Usually because the PDF.js font conversion code wasn't able to parse the font file correctly.

[2] Glyphs fell back to some default font, which while not accurate was more useful than the current state.

[3] Furthermore I'm not sure how to implement this generally, assuming that's even possible, and don't really have time/interest to look into it either.
2019-02-11 10:27:08 +01:00
..
annotation.js Convert src/core/charsets.js and src/core/standard_fonts.js to ES6 syntax 2019-01-06 15:04:01 +01:00
arithmetic_decoder.js Convert src/core/arithmetic_decoder.js to ES6 syntax 2019-01-06 15:04:01 +01:00
bidi.js Fix inconsistent spacing and trailing commas in objects in src/core/ files, so we can enable the comma-dangle and object-curly-spacing ESLint rules later on 2017-06-02 11:20:19 +02:00
ccitt_stream.js Extract the actual decoding in CCITTFaxStream into a new CCITTFaxDecoder "class", which the new CCITTFaxStream depends on 2017-10-24 16:03:08 +02:00
ccitt.js Fix abbreviation. 2018-09-13 13:10:38 -07:00
cff_parser.js Repair CFF fonts if stem hints are in wrong order 2018-11-20 18:50:37 +02:00
charsets.js Convert src/core/charsets.js and src/core/standard_fonts.js to ES6 syntax 2019-01-06 15:04:01 +01:00
chunked_stream.js Convert the PDFDocument class in src/core/document.js to ES6 syntax 2018-12-30 13:54:43 +01:00
cmap.js Replace String.prototype.substr() occurrences with String.prototype.substring() 2018-09-28 11:41:07 +02:00
colorspace.js Reduce unnecessary duplication of the isDefaultDecode methods on ColorSpace instances 2019-01-25 08:53:08 +01:00
crypto.js Implement the AESBaseCipher class and let the AES128Cipher and AES256Cipher classes extend it 2018-02-03 20:16:33 +01:00
document.js Fallback to the built-in font renderer when font loading fails 2019-02-11 10:27:08 +01:00
encodings.js Implement unit tests for the encodings and fix missing items 2017-12-24 18:14:40 +01:00
evaluator.js Fallback to the built-in font renderer when font loading fails 2019-02-11 10:27:08 +01:00
font_renderer.js Map all glyphs to the private use area and duplicate the first glyph. 2018-09-05 14:04:54 -07:00
fonts.js Fallback to the built-in font renderer when font loading fails 2019-02-11 10:27:08 +01:00
function.js Use Dict.getArray, instead of Dict.get, when getting the 'Size' in constructSampled in src/core/function.js (PR 7295 follow-up) 2018-06-02 11:16:05 -04:00
glyphlist.js Convert the files in the /src/core folder to ES6 modules 2017-05-30 22:06:21 +02:00
image.js Reduce unnecessary duplication of the isDefaultDecode methods on ColorSpace instances 2019-01-25 08:53:08 +01:00
jbig2_stream.js Fix the interface of JpegStream/JpxStream/Jbig2Stream to agree with the other DecodeStreams 2017-11-11 11:22:16 +01:00
jbig2.js Expose a Jbig2Image.parse method, by re-instating the parseJbig2 function 2018-06-16 17:56:54 +02:00
jpeg_stream.js Add a new parameter to JpegImage.getData to indicate the source of the image data (issue 9513) 2018-09-02 14:15:22 +02:00
jpg.js Slightly improve the isSourcePDF parameter handling in JpegImage (PR 10031 follow-up) 2018-09-12 11:30:59 +02:00
jpx_stream.js Fix the interface of JpegStream/JpxStream/Jbig2Stream to agree with the other DecodeStreams 2017-11-11 11:22:16 +01:00
jpx.js Add more validation of the /Filter entry, in image dictionaries, to the PDFImage constructor 2018-08-01 16:41:15 +02:00
metrics.js Convert the files in the /src/core folder to ES6 modules 2017-05-30 22:06:21 +02:00
murmurhash3.js [api-major] Remove the TypedArray polyfills 2017-11-01 10:31:28 +01:00
obj.js Fallback to the built-in font renderer when font loading fails 2019-02-11 10:27:08 +01:00
operator_list.js Ensure that Uint8ClampedArray is used for image data transfered by getTransfers (PR 9802 follow-up) 2018-08-16 10:29:44 +02:00
parser.js Avoid truncating inline images, where the data and the "EI" marker is glued together (issue 10388) (#10436) 2019-01-12 20:31:23 +01:00
pattern.js Fix typos 2018-04-01 23:20:41 +02:00
pdf_manager.js Fallback to the built-in font renderer when font loading fails 2019-02-11 10:27:08 +01:00
primitives.js Optimize the Ref class in src/core/primitives.js 2018-12-29 17:48:41 +01:00
ps_parser.js Convert src/core/charsets.js and src/core/standard_fonts.js to ES6 syntax 2019-01-06 15:04:01 +01:00
standard_fonts.js Convert src/core/charsets.js and src/core/standard_fonts.js to ES6 syntax 2019-01-06 15:04:01 +01:00
stream.js Add Glyph & Cog's XPDF copyright/license information. 2018-09-12 13:59:56 -07:00
type1_parser.js Remove usage of makeSubStream from Type1Parser.extractFontProgram in src/core/type1_parser.js (issue 9735) 2018-05-28 14:32:20 +02:00
unicode.js Replace String.prototype.substr() occurrences with String.prototype.substring() 2018-09-28 11:41:07 +02:00
worker.js Fallback to the built-in font renderer when font loading fails 2019-02-11 10:27:08 +01:00