Skip to content

Commit

Permalink
add signature check to Font.isFont
Browse files Browse the repository at this point in the history
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 rkusa#182
  • Loading branch information
rkusa committed Jan 7, 2020
1 parent 09f7f72 commit 85ceea4
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/font/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
))
}
}

Expand Down

0 comments on commit 85ceea4

Please sign in to comment.