1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | PDFDocument = require 'pdfkit' concat = require 'concat-stream' r = require 'restructure' fontkit = require '../' fs = require 'fs' font = fontkit.openSync '/System/Library/Fonts/Apple Color Emoji.ttf' family = font.layout('👨👩👧👦👨👩👧👨👩👦👦'); console.log(family) doc = new PDFDocument doc.pipe require('fs').createWriteStream 'out.pdf' size = 45 scale = size / font.head.unitsPerEm doc.translate 40, 80 + size # doc.scale 1, -1, {} for glyph, i in family.glyphs glyph.render(doc, size) # doc.rect glyph.cbox.minX * scale, glyph.cbox.minY * scale, glyph.cbox.width * scale, glyph.cbox.height * scale # doc.stroke() doc.translate family.positions[i].xAdvance * scale, 0 doc.end() return variations = -> font = fontkit.openSync '/Library/Fonts/Skia.ttf' # font = fontkit.openSync '/Users/devongovett/Downloads/fonttools-master/Skia2.ttf' # console.log font.directory console.log require('util').inspect font.avar, false, 10 console.log font.variationAxes console.log font.namedVariations a = font.variationAxes.wght fonts = for i in [a.min..a.max] by (a.max - a.min) / 15 font.getVariation wght: i glyphs = for f in fonts f.glyphForCodePoint 'Q'.charCodeAt() doc = new PDFDocument doc.pipe require('fs').createWriteStream 'out.pdf' size = 45 scale = size / font.head.unitsPerEm doc.translate 40, 80 + size doc.scale 1, -1, {} for glyph in glyphs glyph.render(doc, size) # doc.rect glyph.cbox.minX * scale, glyph.cbox.minY * scale, glyph.cbox.width * scale, glyph.cbox.height * scale # doc.stroke() doc.translate glyph.advanceWidth * scale, 0 doc.end() # return variations() ltag = -> font = fontkit.openSync '/Library/Fonts/BigCaslon.ttf' console.log font.directory console.log require('util').inspect font.ltag, false, 10 console.log font.ltag.tags[1].string # return ltag() # font = fontkit.openSync '/Users/devongovett/Downloads/SF-UI/SF-UI-Text-Regular.otf' # console.log font.directory # console.log require('util').inspect font.name, false, 10 # return DEFAULT_FEATURES = ['ccmp', 'liga', 'dlig', 'frac'] # font = fontkit.openSync __dirname + '/../test/data/Helvetica.dfont', 'Helvetica-LightOblique' # console.log font.name#font.fonts.map (f) -> f.postscriptName # LucidaGrande.ttc, Palatino.ttc, Hoefler Text.ttc read = (dir, table, filter) -> for file in fs.readdirSync dir if fs.lstatSync(dir + '/' + file).isDirectory() read dir + '/' + file, table, filter else if /\.(ttf|otf|ttc|dfont)/.test file font = fontkit.openSync dir + '/' + file if /\.(ttc|dfont)/.test(file) for font in font.fonts if font.directory.tables[table] and filter(font) console.log dir + '/' + file, font.postscriptName else if font.directory.tables[table] and filter(font) console.log dir + '/' + file find = (table, filter = -> true) -> # read '/System/Library/Fonts', table, filter # read '/Library/Fonts', table, filter # read '/Users/devongovett/Library/Fonts', table, filter read '/Users/devongovett/Downloads/fonts-master', table, filter # read '/Users/devongovett/Downloads/Noto-unhinted', table, filter # return find 'GPOS', (f) -> f.GPOS.featureList.some (x) -> x.tag is 'curs' layout = -> # font = fontkit.openSync '/Library/Fonts/BigCaslon.ttf' # console.log require('util').inspect font.ltag, depth: 50 # console.log require('util').inspect font.morx, depth: 50 # font = fontkit.openSync '/Library/Fonts/AppleSDGothicNeo-Medium.otf' # console.log require('util').inspect font.BASE, depth: 50 # font = fontkit.openSync '/Users/devongovett/Downloads/Palatino_Linotype.ttf' # console.log require('util').inspect font.JSTF, depth: 50 # font = fontkit.openSync '/Library/Fonts/Hoefler Text.ttc', 'HoeflerText-Regular' # font = fontkit.openSync '/Library/Fonts/Al Nile.ttc', 'AlNile' # just state table # font = fontkit.openSync '/Library/Fonts/Skia.ttf' # font = fontkit.openSync '/System/Library/Fonts/GeezaPro.ttc', 'GeezaPro' # kern state table # console.log font.directory # font = fontkit.openSync '/Library/Fonts/Arial.ttf' # font = fontkit.openSync '/Users/devongovett/Downloads/source-serif-pro-1.014R/OTF/SourceSerifPro-Regular.otf' # font = fontkit.openSync __dirname + '/ACaslonPro-Regular.otf' # console.log require('util').inspect font.GDEF, depth: 50 # glyphs = font.glyphsForString 'Z͓̥͙̮̆AͣL͇̮̤̗̠͈̱̈ͤͦ̓ͬG͍̭͇̪̠͕͐̆̈́O̹̺̥ͧͯ̏͌ͫ͆͗' # {glyphs,positions} = font.layout 'Z͓̥͙̮̆AͣL͇̮̤̗̠͈̱̈ͤͦ̓ͬG͍̭͇̪̠͕͐̆̈́O̹̺̥ͧͯ̏͌ͫ͆͗' font = null devanagari = -> font = fontkit.openSync '/Library/Fonts/DevanagariMT.ttc', 'DevanagariMT' # AAT font = fontkit.openSync '/System/Library/Fonts/Kohinoor.ttc', 'KohinoorDevanagari-Book' # OT font.layout 'हालाँकि सूर के प्रचलित' arabic = -> # /Users/devongovett/Downloads/fonts-master/apache/notonastaliqurdudraft/NotoNastaliqUrduDraft.ttf # /Users/devongovett/Downloads/fonts-master/ofl/amiri/Amiri-Bold.ttf # /Users/devongovett/Downloads/fonts-master/ofl/amiri/Amiri-BoldSlanted.ttf # /Users/devongovett/Downloads/fonts-master/ofl/amiri/Amiri-Regular.ttf # /Users/devongovett/Downloads/fonts-master/ofl/amiri/Amiri-Slanted.ttf # /Users/devongovett/Downloads/fonts-master/ofl/lateef/LateefRegOT.ttf # /Users/devongovett/Downloads/fonts-master/ofl/scheherazade/Scheherazade-R.ttf font = fontkit.openSync '/Users/devongovett/Downloads/fonts-master/apache/notonastaliqurdudraft/NotoNastaliqUrduDraft.ttf' #'/Users/devongovett/Downloads/Noto-unhinted/NotoKufiArabic-Regular.ttf' #'/Users/devongovett/Downloads/ARABTYPE.TTF' # font.layout 'يعامل بعضهم بعضًا بروح الإخاء.' #'\u0633\u064F\u0644\u0651\u064E\u0627\u0651\u0650\u0645\u062A\u06CC'#'سُلَّاِّمتی' r = 'ححححححب' font.layout r #124+342|484+512|709+343|749+708|532@60,-20+0|1183+699|490+284|3+413|497+855|519+606|754@-100,0+566|714+204|3+413|709+343|522@319,-5+0|769+962|779+484|712+237|3+413|809+566|822+416|769@0,17+962|779@0,17+484|712@0,17+237|3+413|803+903|810+469|709+343|779+484|827+283 mongolian = -> font = fontkit.openSync '/Users/devongovett/Downloads/Noto-unhinted/NotoSansMongolian-Regular.ttf' #'/Users/devongovett/Downloads/monbaiti.ttf' font.layout '\u183A\u1823\u182E\u182B\u1822\u1826\u180B\u1832\u180B\u1827\u1837\u0020\u182D\u182D\u180B\u0020\u182D\u180C\u0020\u182D\u180D\u200D\u0020\u182D\u200D\u182D\u180B\u200D\u0020\u182D\u180C\u200D\u0020\u182D\u180D\u200D\u0020\u200D\u182D\u200D\u200D\u182D\u180B\u200D\u0020\u200D\u182D\u180C\u200D\u0020\u200D\u182D\u180D\u200D\u0020\u200D\u182D\u200D\u182D\u180B\u0020\u200D\u182D\u180C\u0020\u1820\u200C\u182D\u1820\u1837\u0020\u1830\u1824\u1837\u200D\u200D\u182D\u1820\u200D\u0020\u200D\u182D\u1824\u182F\u1822\u0020\u182A\u1820\u1822\u182D\u180E\u1820\u202F\u1836\u1822\u1828' #'\u1826\u180B\u1826'#'ᠬᠦᠮᠦᠨ ᠪᠦᠷ ᠲᠥᠷᠥᠵᠦ ᠮᠡᠨᠳᠡᠯᠡᠬᠦ ᠡᠷᠬᠡ' syriac = -> font = fontkit.openSync '/Users/devongovett/Downloads/Noto-unhinted/NotoSansSyriacEstrangela-Regular.ttf' #'/Users/devongovett/Downloads/estre.ttf' font.layout 'ܚܐܪܐ ܘܒܪܒܪ ܓܘ ܐܝܩܪܐ ܘܙܕܩܐ.' nko = -> # not a good test font... shaping doesn't change font = fontkit.openSync '/Users/devongovett/Downloads/Noto-unhinted/NotoSansNKo-Regular.ttf' #'/Users/devongovett/Downloads/ebrima.ttf' font.layout 'ߞߊ߬ ߞߐߕߐ߮ ߞߎߘߊ ߘߏ߫ ߘߊߦߟߍ߬ ߸ ߏ߬' phagspa = -> font = fontkit.openSync '/Users/devongovett/Downloads/Noto-unhinted/NotoSansPhagsPa-Regular.ttf' #'/Users/devongovett/Downloads/phagspa.ttf' font.layout 'ꡀꡁꡂꡃ ꡄꡅꡆꡇ ꡈꡉꡊꡋ ꡌꡍꡎꡏ' # /Users/devongovett/Downloads/Noto-unhinted/NotoSansMandaic-Regular.ttf {glyphs,positions} = arabic() res = [] for glyph, i in glyphs pos = positions[i] x = "#{glyph.id}" if pos.xOffset or pos.yOffset x += "@#{pos.xOffset},#{pos.yOffset}" x += "+#{pos.xAdvance}" res.push x console.log res.join('|') # font = fontkit.openSync '/Library/Fonts/PCmyoungjo.ttf' # AAT # font = fontkit.openSync '/Users/devongovett/Downloads/BATANG.TTC', 'Batang' # font = fontkit.openSync '/Users/devongovett/Downloads/fonts-master/ofl/khmer/Khmer.ttf' # console.log font.directory, font.availableFeatures # {glyphs,positions} = font.layout 'ខ្ញុំអាចញ៉ាំកញ្ចក់បាន ដោយគ្មានបញ្ហា' # {glyphs,positions} = font.layout 'abc 휴가 가-- (오--)'#'휴가 가-- (오--)' # {glyphs,positions} = font.layout '\u302f'#'휴가 가-- (오--)' # console.log font.GSUB # No fonts for Mandaic, Manichaean, Psalter Pahlavi # {glyphs,positions} = font.layout 'Twitter 1⁄8' # glyphs = font.glyphsForString 'ff\u0301\u0300x\u0301yz' # positions = font.positionsForGlyphs glyphs # console.log 'glyphs', glyphs.map (g) -> g.id # console.log 'positions', positions # console.log font._GPOSProcessor.features # glyphs.reverse() # positions.reverse() # console.log font.GPOS.scriptList # glyphs.reverse() # positions.reverse() console.log glyphs.map (g) -> g.id doc = new PDFDocument doc.pipe require('fs').createWriteStream 'out.pdf' size = 64 doc.translate 50, 200 + size doc.moveTo 0, 0 doc.lineTo 200, 0 doc.stroke() doc.scale 1, -1, {} scale = size / font.head.unitsPerEm x = y = 0 for glyph, i in glyphs position = positions[i] gx = (position.xOffset + x) * scale gy = (position.yOffset + y) * scale doc.save() doc.translate gx, gy glyph.render(doc, size) # doc.rect glyph.bbox.minX * scale, glyph.bbox.minY * scale, glyph.bbox.width * scale, glyph.bbox.height * scale # doc.stroke() doc.restore() x += position.xAdvance y += position.yAdvance # glyphs[0].render(doc, size) # # doc.scale size / 128 # bbox = glyphs[0].bbox # doc.rect bbox[0], bbox[1], bbox[2] - bbox[0], bbox[3] - bbox[1] # doc.stroke() # font.getGlyph(4).render(doc, size) # doc.path 'M101 -747C95 -747 91 -745 91 -738L91 162C91 169 94 173 102 173L313 173C319 173 322 171 322 165L322 144C322 138 320 135 314 135L166 135C160 135 159 132 159 121L159 -698C159 -707 162 -709 169 -709L304 -709C310 -709 312 -712 312 -717L312 -741C312 -744 310 -747 306 -747Z' doc.fill() doc.end() return layout() # font = TTFFont.open '/Users/devongovett/Downloads/fk.otf' # console.log require('util').inspect(font['CFF '], false, 50) # return font = TTFFont.open 'ACaslonPro-Regular.otf' # console.log font['CFF '] # cff = CFFFont.open 'out.cff' # cff = TTFFont.open('/Users/devongovett/Downloads/font.otf')['CFF '] # console.log require('util').inspect(cff, false, 50) # return # font = TTFFont.open 'wts55.ttf' # font = TTFFont.open '/Library/Fonts/Hoefler Text.ttc', 'HoeflerText-Regular' # font = TTFFont.open '/Users/devongovett/Downloads/source-serif-pro-1.014R/OTF/SourceSerifPro-Regular.otf' # font = TTFFont.open '/Users/devongovett/Downloads/source-serif-pro-1.014R/TTF/SourceSerifPro-Regular.ttf' # font = TTFFont.open '/Users/devongovett/Downloads/SourceSansPro_FontsOnly-1.050/OTF/SourceSansPro-Regular.otf' # font = TTFFont.open '/Users/devongovett/Downloads/source-serif-pro-1.014R/WOFF/OTF/SourceSerifPro-Regular.otf.woff' # font = TTFFont.open '/Users/devongovett/Downloads/Archive/Cambria Bold.ttf' # /System/Library/Fonts/Apple Color Emoji.ttf # /Users/devongovett/Downloads/ss-emoji-beta-master/ss-emoji-microsoft.ttf # font = TTFFont.open '/Users/devongovett/Downloads/ss-emoji-beta-master/ss-emoji-microsoft.ttf' # console.log font.directory # console.log require('util').inspect font.CBLC, false, 50 glyphs = font.glyphsForString '⅔' # glyphs = font.glyphsForString '😜🇬💵💸🍃🍻💰💩👍🏀🍺' # console.log glyphs # console.log font['CFF '].topDict.charset, font['CFF '].charStrings.length # glyphs = font.glyphsForString 'stffi', ['ccmp', 'liga', 'dlig', 'frac'] # console.log glyphs # glyph = glyphs[0] # fn = glyph.path.toFunction() # console.log fn.toString() # console.log glyph.layers # # doc = new PDFDocument # doc.pipe require('fs').createWriteStream 'out.pdf' # # size = 64 # doc.translate 300, 300 # # glyph.render(doc, size) # # doc.fill() # doc.end() # console.log require('util').inspect font['CFF '], false, 50 # --------- subset = new CFFSubset font subset.includeGlyph glyph.id for glyph in glyphs # subset.includeGlyph g for g in [0, 1, 5, 7, 8, 10, 14, 16, 18, 19, 22, 27, 28, 29, 30, 31, 32, 33, 34, 35, 37, 38, 39, 40, 41, 42, 44, 45, 46, 48, 49, 50, 53, 56, 57, 60] stream = new r.EncodeStream stream.pipe require('fs').createWriteStream 'out.cff' stream.pipe concat (buffer) -> s = new r.DecodeStream buffer fp = new CFFFont s console.log require('util').inspect(fp, false, 50), fp.fullName # CFFGlyph = require '../src/cff/CFFGlyph' # g = new CFFGlyph 8, [], { 'CFF ': fp, stream: s } # # fn = g.path.toFunction() # console.log fn.toString() # # doc = new PDFDocument # doc.pipe require('fs').createWriteStream 'out.pdf' # # doc.translate 300, 300 # doc.scale 1 / font.head.unitsPerEm * 200 # # bbox = g.bbox # console.log bbox, g.cbox # doc.rect bbox[0], bbox[1], bbox[2] - bbox[0], bbox[3] - bbox[1] # doc.stroke() # # fn(doc) # # doc.fill() # doc.end() subset.encode stream stream.end() # subset = new TTFSubset font # subset.includeGlyph glyph.id for glyph in glyphs # # stream = new r.EncodeStream # stream.pipe concat (buffer) -> # console.log buffer.length, buffer # fp = new TTFFont buffer # console.log require('util').inspect(fp.loca, false, 50) # # TTFGlyph = require '../src/TTFGlyph' # g = new TTFGlyph 1, [], fp # # fn = g.path.toFunction() # console.log fn.toString() # # doc = new PDFDocument # doc.pipe require('fs').createWriteStream 'out.pdf' # # doc.translate 300, 300 # doc.scale 1 / font.head.unitsPerEm * 200 # # bbox = g.bbox # console.log bbox, g.cbox # doc.rect bbox[0], bbox[1], bbox[2] - bbox[0], bbox[3] - bbox[1] # doc.stroke() # # fn(doc) # # doc.fill() # doc.end() # # subset.encode stream # stream.end() |