mirror of
https://github.com/foliojs/pdfkit.git
synced 2025-12-08 20:15:54 +00:00
Refactor font loading code and add support for ArrayBuffers
This commit is contained in:
parent
314e9d28ae
commit
1241997715
@ -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'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user