         Supplement: 0
       FontDescriptor: descriptor
       W: [0, @widths]
-      
+
     descendantFont.end()
-          
+
     @dictionary.data =
       Type: 'Font'
       Subtype: 'Type0'

      end
      end
    """
    
    return cmap
  
module.exports = EmbeddedFont

      Encoding: 'Identity-H'
      DescendantFonts: [descendantFont]
      ToUnicode: @toUnicodeCmap()

    @dictionary.end()

  toHex = (codePoints...) ->
    codes = for code in codePoints
      ('0000' + code.toString(16)).slice(-4)

    return codes.join ''

  # Maps the glyph ids encoded in the PDF back to unicode strings
  # Because of ligature substitutions and the like, there may be one or more
  # unicode characters represented by each glyph.
  toUnicodeCmap: ->
    cmap = @document.ref()

    entries = []
    for codePoints in @unicode
      encoded = []

      # encode codePoints to utf16
      for value in codePoints
        if value > 0xffff
          value -= 0x10000
          encoded.push toHex value >>> 10 & 0x3ff | 0xd800
          value = 0xdc00 | value & 0x3ff

        encoded.push toHex value

      entries.push "<#{encoded.join ' '}>"

    cmap.end """
      /CIDInit /ProcSet findresource begin
      12 dict begin
