初始化

@param {ArrayBuffer} buffer buffer对象
@return {Object} ttf对象
774866
function read(buffer) {

            var reader = new Reader(buffer, 0, buffer.byteLength, false);

            var ttf = {};

            // version
            ttf.version = reader.readFixed(0);

            if (ttf.version !== 0x1) {
                error.raise(10101);
            }

            // num tables
            ttf.numTables = reader.readUint16();

            if (ttf.numTables <= 0 || ttf.numTables > 100) {
                error.raise(10101);
            }

            // searchRenge
            ttf.searchRenge = reader.readUint16();

            // entrySelector
            ttf.entrySelector = reader.readUint16();

            // rengeShift
            ttf.rengeShift = reader.readUint16();

            ttf.tables = new Directory(reader.offset).read(reader, ttf);

            if (!ttf.tables.glyf || !ttf.tables.head || !ttf.tables.cmap || !ttf.tables.hmtx) {
                error.raise(10204);
            }

            ttf.readOptions = this.options;

            // 读取支持的表数据
            Object.keys(supportTables).forEach(function (tableName) {

                if (ttf.tables[tableName]) {
                    var offset = ttf.tables[tableName].offset;
                    ttf[tableName] = new supportTables[tableName](offset).read(reader, ttf);
                }
            });

            if (!ttf.glyf) {
                error.raise(10201);
            }

            reader.dispose();

            return ttf;
        }
653501
function() {
      var result = new StringBuffer();
      var array = this._input.split('');
      // var prev = null;

      for (var i = 0; i < array.length; i++) {
        var cur = array[i];
        var next = array[i + 1];

        if (typeof next !== 'undefined') {
          var curToken = cur + next;

          if (this._mode.tokens.ia[curToken]) {
            var nextNext = array[i + 2];
            if (typeof nextNext === 'undefined' || /^[-\s]$/.test(nextNext)) {
              result.append(this._mode.tokens.ia[curToken]);
              i++;
              continue;
            }
          }
        }

        if (this._mode.cyr2lat[cur]) {
          result.append(this._mode.cyr2lat[cur]);
        } else {
          result.append(cur);
        }

        // prev = cur;
      }

      return result.toString();
    }
596191
function BufferSegment(buf, offset, count) {
  if (!Buffer.isBuffer(buf)) throw new TypeError('buf must be a buffer');

  this.buffer = buf;
  this.offset = offset || 0;
  this.count = count || buf.length;
}
270745
function bnToBuffer(trimOrSize) {
    var res = new Buffer(this.toByteArray());
    if (trimOrSize === true && res[0] === 0) {
        res = res.slice(1);
    } else if (_.isNumber(trimOrSize)) {
        if (res.length > trimOrSize) {
            for (var i = 0; i < res.length - trimOrSize; i++) {
                if (res[i] !== 0) {
                    return null;
                }
            }
            return res.slice(res.length - trimOrSize);
        } else if (res.length < trimOrSize) {
            var padded = new Buffer(trimOrSize);
            padded.fill(0, 0, trimOrSize - res.length);
            res.copy(padded, trimOrSize - res.length);
            return padded;
        }
    }
    return res;
}
1183219
function (buffer) {
        var str = '',
            uArrayVal = new Uint8Array(buffer),

            i,
            ii;

        for (i = 0, ii = uArrayVal.length; i < ii; i++) {
            str += String.fromCharCode(uArrayVal[i]);
        }

        return str;
    }
516349
function fill(buffer, value) {
    $.checkArgumentType(buffer, 'Buffer', 'buffer');
    $.checkArgumentType(value, 'number', 'value');
    var length = buffer.length;
    for (var i = 0; i < length; i++) {
      buffer[i] = value;
    }
    return buffer;
  }
469628
function write(ttf) {

            // 用来做写入缓存的对象，用完后删掉
            ttf.support = {};

            // head + directory
            var ttfSize = 12 + ttf.numTables * 16;
            var ttfHeadOffset = 0; // 记录head的偏移

            // 构造tables
            ttf.support.tables = [];
            ttf.writeOptions.tables.forEach(function (tableName) {
                var offset = ttfSize;
                var tableSize = new supportTables[tableName]().size(ttf); // 原始的表大小
                var size = tableSize; // 对齐后的表大小

                if (tableName === 'head') {
                    ttfHeadOffset = offset;
                }

                // 4字节对齐
                if (size % 4) {
                    size += 4 - size % 4;
                }

                ttf.support.tables.push({
                    name: tableName,
                    checkSum: 0,
                    offset: offset,
                    length: tableSize,
                    size: size
                });

                ttfSize += size;
            });

            var writer = new Writer(new ArrayBuffer(ttfSize));

            // 写头部
            writer.writeFixed(ttf.version);
            writer.writeUint16(ttf.numTables);
            writer.writeUint16(ttf.searchRange);
            writer.writeUint16(ttf.entrySelector);
            writer.writeUint16(ttf.rangeShift);

            // 写表偏移
            !new Directory().write(writer, ttf);

            // 写支持的表数据
            ttf.support.tables.forEach(function (table) {

                var tableStart = writer.offset;
                !new supportTables[table.name]().write(writer, ttf);

                if (table.length % 4) {
                    // 对齐字节
                    writer.writeEmpty(4 - table.length % 4);
                }

                // 计算校验和
                table.checkSum = checkSum(writer.getBuffer(), tableStart, table.size);

            });

            // 重新写入每个表校验和
            ttf.support.tables.forEach(function (table, index) {
                var offset = 12 + index * 16 + 4;
                writer.writeUint32(table.checkSum, offset);
            });

            // 写入总校验和
            var ttfCheckSum = (0xB1B0AFBA - checkSum(writer.getBuffer()) + 0x100000000) % 0x100000000;
            writer.writeUint32(ttfCheckSum, ttfHeadOffset + 8);

            delete ttf.writeOptions;
            delete ttf.support;

            var buffer = writer.getBuffer();
            writer.dispose();

            return buffer;
        }
1008479
function ttf2eot(arr) {
  var buf = new ByteBuffer(arr);
  var out = new ByteBuffer(SIZEOF.EOT_PREFIX),
      i, j;

  out.fill(0);
  out.setUint32(EOT_OFFSET.FONT_LENGTH, buf.length, true);
  out.setUint32(EOT_OFFSET.VERSION, MAGIC.EOT_VERSION, true);
  out.setUint8(EOT_OFFSET.CHARSET, MAGIC.EOT_CHARSET);
  out.setUint16(EOT_OFFSET.MAGIC, MAGIC.EOT_MAGIC, true);

  var familyName = [],
      subfamilyName = [],
      fullName = [],
      versionString = [];

  var haveOS2 = false,
      haveName = false,
      haveHead = false;

  var numTables = buf.getUint16 (SFNT_OFFSET.NUMTABLES);

  for (i = 0; i < numTables; ++i) {
    var data = new ByteBuffer(buf, SIZEOF.SFNT_HEADER + i * SIZEOF.SFNT_TABLE_ENTRY);
    var tableEntry = {
      tag: data.toString (SFNT_OFFSET.TABLE_TAG, 4),
      offset: data.getUint32 (SFNT_OFFSET.TABLE_OFFSET),
      length: data.getUint32 (SFNT_OFFSET.TABLE_LENGTH)
    };

    var table = new ByteBuffer(buf, tableEntry.offset, tableEntry.length);

    if (tableEntry.tag === 'OS/2') {
      haveOS2 = true;

      for (j = 0; j < 10; ++j) {
        out.setUint8 (EOT_OFFSET.FONT_PANOSE + j, table.getUint8 (SFNT_OFFSET.OS2_FONT_PANOSE + j));
      }

      /*jshint bitwise:false */
      out.setUint8 (EOT_OFFSET.ITALIC, table.getUint16 (SFNT_OFFSET.OS2_FS_SELECTION) & 0x01);
      out.setUint32 (EOT_OFFSET.WEIGHT, table.getUint16 (SFNT_OFFSET.OS2_WEIGHT), true);

      for (j = 0; j < 4; ++j) {
        out.setUint32 (EOT_OFFSET.UNICODE_RANGE + j * 4, table.getUint32 (SFNT_OFFSET.OS2_UNICODE_RANGE + j * 4), true);
      }

      for (j = 0; j < 2; ++j) {
        out.setUint32 (EOT_OFFSET.CODEPAGE_RANGE + j * 4, table.getUint32 (SFNT_OFFSET.OS2_CODEPAGE_RANGE + j * 4), true);
      }

    } else if (tableEntry.tag === 'head') {

      haveHead = true;
      out.setUint32 (EOT_OFFSET.CHECKSUM_ADJUSTMENT, table.getUint32 (SFNT_OFFSET.HEAD_CHECKSUM_ADJUSTMENT), true);

    } else if (tableEntry.tag === 'name') {

      haveName = true;

      var nameTable = {
        format: table.getUint16 (SFNT_OFFSET.NAMETABLE_FORMAT),
        count: table.getUint16 (SFNT_OFFSET.NAMETABLE_COUNT),
        stringOffset: table.getUint16 (SFNT_OFFSET.NAMETABLE_STRING_OFFSET)
      };

      for (j = 0; j < nameTable.count; ++j) {
        var nameRecord = new ByteBuffer(table, SIZEOF.SFNT_NAMETABLE + j * SIZEOF.SFNT_NAMETABLE_ENTRY);
        var name = {
          platformID: nameRecord.getUint16 (SFNT_OFFSET.NAME_PLATFORM_ID),
          encodingID: nameRecord.getUint16 (SFNT_OFFSET.NAME_ENCODING_ID),
          languageID: nameRecord.getUint16 (SFNT_OFFSET.NAME_LANGUAGE_ID),
          nameID: nameRecord.getUint16 (SFNT_OFFSET.NAME_NAME_ID),
          length: nameRecord.getUint16 (SFNT_OFFSET.NAME_LENGTH),
          offset: nameRecord.getUint16 (SFNT_OFFSET.NAME_OFFSET)
        };

        if (name.platformID === 3 && name.encodingID === 1 && name.languageID === MAGIC.LANGUAGE_ENGLISH) {
          var s = strbuf (new ByteBuffer(table, nameTable.stringOffset + name.offset, name.length));

          switch (name.nameID) {
            case 1:
              familyName = s;
              break;
            case 2:
              subfamilyName = s;
              break;
            case 4:
              fullName = s;
              break;
            case 5:
              versionString = s;
              break;
          }
        }
      }
    }
    if (haveOS2 && haveName && haveHead) { break; }
  }

  if (!(haveOS2 && haveName && haveHead)) {
    throw new Error ('Required section not found');
  }

  // Calculate final length
  var len =
   out.length +
   familyName.length +
   subfamilyName.length +
   versionString.length +
   fullName.length +
   2 +
   buf.length;

  // Create final buffer with the the same array type as input one.
  var eot = new ByteBuffer(len);

  eot.writeBytes(out.buffer);
  eot.writeBytes(familyName.buffer);
  eot.writeBytes(subfamilyName.buffer);
  eot.writeBytes(versionString.buffer);
  eot.writeBytes(fullName.buffer);
  eot.writeBytes([ 0, 0 ]);
  eot.writeBytes(buf.buffer);

  eot.setUint32(EOT_OFFSET.LENGTH, len, true); // Calculate overall length

  return eot;
}
753738
function stringToArrayBuffer(str) {
    var buf=new Uint8Array(str.length);
    for (var i=0; i<str.length; i++) {
      var ch = str.charCodeAt(i);
      if (ch>=256) {
        console.warn("stringToArrayBuffer got non-8 bit character - code "+ch);
        ch = "?".charCodeAt(0);
      }
      buf[i] = ch;
    }
    return buf.buffer;
  }
712911
function toBuffer (typed) {
        var ab = typed.buffer;
        var buffer = new Buffer(ab.byteLength);
        var view = new Uint8Array(ab);
        for (var i = 0; i < buffer.length; ++i) {
            buffer[i] = view[i];
        }
        return buffer;
    }
488889
function( buffer, offset ) {

    if( !Buffer.isBuffer( buffer ) )
      throw new TypeError( 'Value must be a buffer' )

    offset = offset || 0

    return this.fromNumber( buffer.readUIntLE( offset, 3 ) )

  }
69246
function (buffers) {
            var length = 0,
                offset = 0,
                buffer = null, i;

            for (i = 0; i < buffers.length; i++) {
                length += buffers[i].length;
            }

            buffer = new TableStore.util.Buffer(length);

            for (i = 0; i < buffers.length; i++) {
                buffers[i].copy(buffer, offset);
                offset += buffers[i].length;
            }

            return buffer;
        }
805971
function ttf2woff2Transform() {
  // Return a callback function handling the buffered content
  return function ttf2woff2TransformCb(err, buf, cb) {

    // Handle any error
    if(err) {
      return cb(new PluginError(PLUGIN_NAME, err, { showStack: true }));
    }

    // Use the buffered content
    try {
      buf = ttf2woff2(buf);
      return cb(null, buf);
    } catch(err2) {
      return cb(new PluginError(PLUGIN_NAME, err2, { showStack: true }));
    }

  };
}
134819
public static char[] bytesToCharArrayUTFNIO(byte[] buffer) {
        ByteBuffer byteBuffer = ByteBuffer.wrap(buffer);
        CharBuffer charBuffer = Charset.forName(ENCODING).decode(byteBuffer);
        try {
            return charBufferToChars(charBuffer);
        } finally {
            eraseCharBuffer(charBuffer);
        }
    }
1085081
function (str) {
         var buffer = JSZip.utils.transformTo("arraybuffer", str);
         return JSZip.utils.arrayBuffer2Blob(buffer);
      }
83918
function toBuffer(buf) {
  if (buf instanceof ArrayBuffer) {
    return arrayBufferToBuffer(buf);
  } else if (Buffer.isBuffer(buf)) {
    return buf;
  } else if (buf instanceof Uint8Array) {
    return new Buffer(buf);
  } else {
    return buf; // type unknown, trust the user
  }
}
1000619
function toBuffer(arrayBuffer) {
    if (Array.isArray(arrayBuffer)) {
        return new Buffer(arrayBuffer);
    }
    else {
        var length = arrayBuffer.byteLength;
        var view = new DataView(arrayBuffer, 0, length);
        var buffer = new Buffer(length);
        for (var i = 0, l = length; i < l; i++) {
            buffer[i] = view.getUint8(i, false);
        }
    }

    return buffer;
}