Code coverage report for fontkit/base.coffee

Statements: 96.55% (28 / 29)      Branches: 75% (6 / 8)      Functions: 100% (5 / 5)      Lines: 100% (28 / 28)      Ignored: none     

All files » fontkit/ » base.coffee
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 401 1   1 1 5 5   1 37 37   1 2 2 2   2 2   2 2   1   1   2   1 41 79 39 39 3   36   2  
r = require 'restructure'
fs = require 'fs'
 
formats = []
exports.registerFormat = (format) ->
  formats.push format
  exports[format.name] = format
 
exports.openSync = (filename, postscriptName) ->
  buffer = fs.readFileSync filename
  return exports.create buffer, postscriptName
  
exports.open = (filename, postscriptName, callback) ->
  Eif typeof postscriptName is 'function'
    callback = postscriptName
    postscriptName = null
    
  fs.readFile filename, (err, buffer) ->
    Ireturn callback err if err
    
    try
      font = exports.create buffer, postscriptName
    catch e
      return callback e
      
    callback null, font
    
  return
  
exports.create = (buffer, postscriptName) ->
  for format in formats
    if format.probe buffer
      font = new format(new r.DecodeStream(buffer))
      if postscriptName
        return font.getFont postscriptName
        
      return font
      
  throw new Error 'Unknown font format'