From 85ceea4d9d9e5e5d2bfa3c7a1f6b0e365f34341b Mon Sep 17 00:00:00 2001 From: Markus Ast Date: Tue, 7 Jan 2020 08:14:44 +0100 Subject: [PATCH] add signature check to Font.isFont It is possible that we end up with multiple versions of the Font object when pdfjs is bundled via e.g. webpack. To still accept such fonts, the `isFont` method is extended by a signature check (tests whether all necessary public methods are available) as a fallback. Refs #182 --- lib/font/base.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/font/base.js b/lib/font/base.js index dcce4727..38e3b855 100644 --- a/lib/font/base.js +++ b/lib/font/base.js @@ -2,7 +2,17 @@ class Font { static isFont(font) { - return font && font instanceof Font + return font && (font instanceof Font || ( + typeof font === 'object' + && typeof font.encode === 'function' + && typeof font.stringWidth === 'function' + && typeof font.lineHeight === 'function' + && typeof font.ascent === 'function' + && typeof font.descent === 'function' + && typeof font.underlinePosition === 'function' + && typeof font.underlineThickness === 'function' + && typeof font.write === 'function' + )) } }