From 1241997715b5cdee32c681f9e42d47f3c26cd552 Mon Sep 17 00:00:00 2001 From: Devon Govett Date: Tue, 29 Jul 2014 09:42:48 -0700 Subject: [PATCH] Refactor font loading code and add support for ArrayBuffers --- lib/font.coffee | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/font.coffee b/lib/font.coffee index 027b408..faadf67 100644 --- a/lib/font.coffee +++ b/lib/font.coffee @@ -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'