Skip to content

Commit

Permalink
Refactor font loading code and add support for ArrayBuffers
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett committed Jul 29, 2014
1 parent 314e9d2 commit 1241997
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/font.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,33 @@ class PDFFont
@isAFM = true
@font = new AFMFont STANDARD_FONTS[src]()
@registerAFM src
return

else if /\.(ttf|ttc)$/i.test src
@font = TTFFont.open src, family
@subset = new Subset @font
@registerTTF()

else if /\.dfont$/i.test src
@font = TTFFont.fromDFont src, family
@subset = new Subset @font
@registerTTF()

else
throw new Error 'Not a supported font format or standard PDF font.'

else if Buffer.isBuffer(src)
@font = TTFFont.fromBuffer src, family
@subset = new Subset @font
@registerTTF()

else if src instanceof Uint8Array
@font = TTFFont.fromBuffer (new Buffer src), family
@subset = new Subset @font
@registerTTF()
@font = TTFFont.fromBuffer new Buffer(src), family

else if src instanceof ArrayBuffer
@font = TTFFont.fromBuffer new Buffer(new Uint8Array(src)), family

else
throw new Error 'Not a supported font format or standard PDF font.'

# create a subset for the font and register
@subset = new Subset @font
@registerTTF()

# This insanity is so browserify can inline the font files
STANDARD_FONTS =
"Courier": -> fs.readFileSync __dirname + "/font/data/Courier.afm", 'utf8'
Expand Down

0 comments on commit 1241997

Please sign in to comment.