From ac32a9316dee2aad3090cdc91262e71f2092dbe2 Mon Sep 17 00:00:00 2001 From: Devon Govett Date: Thu, 3 Jul 2014 18:58:27 -0700 Subject: [PATCH] Add support for OpenType/CFF embedding and subsetting --- lib/font.coffee | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/font.coffee b/lib/font.coffee index 8699c67..7f666c4 100644 --- a/lib/font.coffee +++ b/lib/font.coffee @@ -18,7 +18,7 @@ class PDFFont @font = new AFMFont STANDARD_FONTS[src]() @registerAFM src - else if /\.(ttf|ttc)$/i.test src + else if /\.(ttf|otf|ttc)$/i.test src @font = TTFFont.open src, family @subset = @font.createSubset() @unicode = [[0]] @@ -96,7 +96,12 @@ class PDFFont @bbox = @font.bbox embedTTF: -> + isCFF = @subset.cff? fontFile = @document.ref() + + if isCFF + fontFile.data.Subtype = 'CIDFontType0C' + @subset.encodeStream(fontFile) familyClass = (@font['OS/2']?.sFamilyClass or 0) >> 8 @@ -122,13 +127,17 @@ class PDFFont CapHeight: @font.capHeight or @font.ascent XHeight: @font.xHeight or 0 StemV: 0 # not sure how to calculate this - FontFile2: fontFile + + if isCFF + descriptor.data.FontFile3 = fontFile + else + descriptor.data.FontFile2 = fontFile descriptor.end() descendantFont = @document.ref Type: 'Font' - Subtype: 'CIDFontType2' + Subtype: if isCFF then 'CIDFontType0' else 'CIDFontType2' BaseFont: name CIDSystemInfo: Registry: PDFObject.s 'Adobe'