all files / fontkit/src/cff/ CFFPointer.coffee

100% Statements 21/21
100% Branches 2/2
100% Functions 10/10
100% Lines 21/21
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         72× 72×   72×     101×     14×     101×   87× 87×   87× 87×   14× 14×   14×   14× 14×    
r = require 'restructure'
 
class CFFPointer extends r.Pointer
  constructor: (type, options = {}) ->
    options.type ?= 'global'
    super null, type, options
  
  decode: (stream, parent, operands) ->
    @offsetType = 
      decode: -> operands[0]
  
    super
    
  class Ptr
    constructor: (@val) ->
      @forceLarge = true
      
    valueOf: ->
      @val
  
  encode: (stream, value, ctx) ->
    unless stream
      # compute the size (so ctx.pointerSize is correct)
      @offsetType =
        size: -> 0
        
      @size(value, ctx)
      return [new Ptr 0]
    
    ptr = null
    @offsetType =
      encode: (stream, val) ->
        ptr = val
      
    super    
    return [new Ptr ptr]
 
module.exports = CFFPointer