woff格式转换成ttf字体格式

@param {ArrayBuffer} woffBuffer woff缓冲数组
@param {Object} options 选项
@param {Object} options.inflate 解压相关函数

@return {ArrayBuffer} ttf格式byte流
499005
function woff2ttf(woffBuffer, options) {
    options = options || {};

    var reader = new Reader(woffBuffer);
    var signature = reader.readUint32(0);
    var flavor = reader.readUint32(4);

    if (signature !== 0x774F4646 || flavor !== 0x10000) {
        reader.dispose();
        error.raise(10102);
    }

    var numTables = reader.readUint16(12);
    var ttfSize =  reader.readUint32(16);
    var tableEntries = [];
    var tableEntry;
    var i;
    var l;

    // 读取woff表索引信息
    for (i = 0; i < numTables; ++i) {
        reader.seek(44 + i * 20);
        tableEntry = {
            tag: reader.readString(reader.offset, 4),
            offset: reader.readUint32(),
            compLength: reader.readUint32(),
            length: reader.readUint32(),
            checkSum: reader.readUint32()
        };

        // ttf 表数据
        var deflateData = reader.readBytes(tableEntry.offset, tableEntry.compLength);
        // 需要解压
        if (deflateData.length < tableEntry.length) {

            if (!options.inflate) {
                reader.dispose();
                error.raise(10105);
            }

            tableEntry.data = options.inflate(deflateData);
        }
        else {
            tableEntry.data = deflateData;
        }

        tableEntry.length = tableEntry.data.length;
        tableEntries.push(tableEntry);
    }


    var writer = new Writer(new ArrayBuffer(ttfSize));
    // 写头部
    var entrySelector = Math.floor(Math.log(numTables) / Math.LN2);
    var searchRange = Math.pow(2, entrySelector) * 16;
    var rangeShift = numTables * 16 - searchRange;

    writer.writeFixed(1);
    writer.writeUint16(numTables);
    writer.writeUint16(searchRange);
    writer.writeUint16(entrySelector);
    writer.writeUint16(rangeShift);

    // 写ttf表索引
    var tblOffset = 12 + 16 * tableEntries.length;
    for (i = 0, l = tableEntries.length; i < l; ++i) {
        tableEntry = tableEntries[i];
        writer.writeString(tableEntry.tag);
        writer.writeUint32(tableEntry.checkSum);
        writer.writeUint32(tblOffset);
        writer.writeUint32(tableEntry.length);
        tblOffset += tableEntry.length
            + (tableEntry.length % 4 ? 4 - tableEntry.length % 4 : 0);
    }

    // 写ttf表数据
    for (i = 0, l = tableEntries.length; i < l; ++i) {
        tableEntry = tableEntries[i];
        writer.writeBytes(tableEntry.data);
        if (tableEntry.length % 4) {
            writer.writeEmpty(4 - tableEntry.length % 4);
        }
    }

    return writer.getBuffer();
}
355373
function toVFile(options) {
  if (typeof options === 'string' || buffer(options)) {
    options = {path: String(options)}
  }

  return vfile(options)
}
436343
function IconvHtmlStream(options) {
    this.buff = new Buffer([]);
    this.isBuffering = true;
    this.conv = null;
    options = options || {};
    this.rewrite = (options.rewrite !== false);
    this.inputEncoding = 'utf8';
    this.encoding = options.encoding = 'utf8'; // this is the *output* encoding
    this.conv = iconv.getEncoder(this.inputEncoding);
    Transform.call(this, options);
}
67167
function decodeBuffer(buf, options, cb) {
  if (typeof options === 'function') {
    cb = options;
    options = {};
  }

  try {
    buf = bufferUtils.toUint8Array(buf);

    if (_hasWorker.hasWorker) {
      const wr = require('webworkify')(_decodeWorker2.default);

      wr.onmessage = ({ data: msg }) => {
        const err = msg.err ? new Error(msg.err) : undefined;
        cb(err, msg.result);
      };

      const msg = {
        buf: buf,
        options: options
      };

      if (options.transferable) {
        wr.postMessage(msg, [buf]);
      } else {
        wr.postMessage(msg);
      }
    } else {
      (0, _decode2.default)(buf, options, cb);
    }
  } catch (err) {
    cb(err);
  }
}
1112530
function parse_PtgFunc(blob, length, opts) {
	var ptg = blob[blob.l] & 0x1F;
	var type = (blob[blob.l] & 0x60)>>5;
	blob.l += 1;
	var iftab = blob.read_shift(opts && opts.biff <= 3 ? 1 : 2);
	return [FtabArgc[iftab], Ftab[iftab], type];
}
550858
private void deflateData(boolean force) throws IOException {
        //we don't need to flush here, as this should have been called already by the time we get to
        //this point
        boolean nextCreated = false;
        try (PooledByteBuffer arrayPooled = this.exchange.getConnection().getByteBufferPool().getArrayBackedPool().allocate()) {
            PooledByteBuffer pooled = this.currentBuffer;
            final ByteBuffer outputBuffer = pooled.getBuffer();

            final boolean shutdown = anyAreSet(state, SHUTDOWN);
            ByteBuffer buf = arrayPooled.getBuffer();
            while (force || !deflater.needsInput() || (shutdown && !deflater.finished())) {
                int count = deflater.deflate(buf.array(), buf.arrayOffset(), buf.remaining(), force ? Deflater.SYNC_FLUSH: Deflater.NO_FLUSH);
                Connectors.updateResponseBytesSent(exchange, count);
                if (count != 0) {
                    int remaining = outputBuffer.remaining();
                    if (remaining > count) {
                        outputBuffer.put(buf.array(), buf.arrayOffset(), count);
                    } else {
                        if (remaining == count) {
                            outputBuffer.put(buf.array(), buf.arrayOffset(), count);
                        } else {
                            outputBuffer.put(buf.array(), buf.arrayOffset(), remaining);
                            additionalBuffer = ByteBuffer.allocate(count - remaining);
                            additionalBuffer.put(buf.array(), buf.arrayOffset() + remaining, count - remaining);
                            additionalBuffer.flip();
                        }
                        outputBuffer.flip();
                        this.state |= FLUSHING_BUFFER;
                        if (next == null) {
                            nextCreated = true;
                            this.next = createNextChannel();
                        }
                        if (!performFlushIfRequired()) {
                            return;
                        }
                    }
                } else {
                    force = false;
                }
            }
        } finally {
            if (nextCreated) {
                if (anyAreSet(state, WRITES_RESUMED)) {
                    next.resumeWrites();
                }
            }
        }
    }
125572
function ifft2DArray(ft, ftRows, ftCols) {
    var tempTransform = new Array(ftRows * ftCols);
    var nRows = ftRows / 2;
    var nCols = (ftCols - 1) * 2;
    // reverse transform columns
    FFT.init(nRows);
    var tmpCols = {re: new Array(nRows), im: new Array(nRows)};
    var iRow, iCol;
    for (iCol = 0; iCol < ftCols; iCol++) {
        for (iRow = nRows - 1; iRow >= 0; iRow--) {
            tmpCols.re[iRow] = ft[(iRow * 2) * ftCols + iCol];
            tmpCols.im[iRow] = ft[(iRow * 2 + 1) * ftCols + iCol];
        }
        //Unnormalized inverse transform
        FFT.bt(tmpCols.re, tmpCols.im);
        for (iRow = nRows - 1; iRow >= 0; iRow--) {
            tempTransform[(iRow * 2) * ftCols + iCol] = tmpCols.re[iRow];
            tempTransform[(iRow * 2 + 1) * ftCols + iCol] = tmpCols.im[iRow];
        }
    }

    // reverse row transform
    var finalTransform = new Array(nRows * nCols);
    FFT.init(nCols);
    var tmpRows = {re: new Array(nCols), im: new Array(nCols)};
    var scale = nCols * nRows;
    for (iRow = 0; iRow < ftRows; iRow += 2) {
        tmpRows.re[0] = tempTransform[iRow * ftCols];
        tmpRows.im[0] = tempTransform[(iRow + 1) * ftCols];
        for (iCol = 1; iCol < ftCols; iCol++) {
            tmpRows.re[iCol] = tempTransform[iRow * ftCols + iCol];
            tmpRows.im[iCol] = tempTransform[(iRow + 1) * ftCols + iCol];
            tmpRows.re[nCols - iCol] = tempTransform[iRow * ftCols + iCol];
            tmpRows.im[nCols - iCol] = -tempTransform[(iRow + 1) * ftCols + iCol];
        }
        //Unnormalized inverse transform
        FFT.bt(tmpRows.re, tmpRows.im);

        var indexB = (iRow / 2) * nCols;
        for (iCol = nCols - 1; iCol >= 0; iCol--) {
            finalTransform[indexB + iCol] = tmpRows.re[iCol] / scale;
        }
    }
    return finalTransform;
}
1174352
function encodeBuffer(buf, options, cb) {
  if (typeof options === 'function') {
    cb = options;
    options = {};
  }

  try {
    buf = bufferUtils.toArrayLike(buf);

    if (!options.hasOwnProperty('width') || !options.hasOwnProperty('height')) {
      return cb(new Error('Provide width & height of the buffer'));
    }

    if (_hasWorker.hasWorker) {
      const wr = require('webworkify')(_encodeWorker2.default);

      wr.onmessage = ({ data: msg }) => {
        const err = msg.err ? new Error(msg.err) : undefined;
        cb(err, msg.result);
      };

      const msg = {
        buf: buf,
        options: options
      };

      if (options.transferable) {
        wr.postMessage(msg, [buf]);
      } else {
        wr.postMessage(msg);
      }
    } else {
      (0, _encode2.default)(buf, options, cb);
    }
  } catch (err) {
    cb(err);
  }
}
245209
function ttf2icon(ttfBuffer, options) {

            options = options || {};

            // 读取ttf二进制流
            if (ttfBuffer instanceof ArrayBuffer) {
                var reader = new TTFReader();
                var ttfObject = reader.read(ttfBuffer);
                reader.dispose();

                return ttfobject2icon(ttfObject, options);
            }
            // 读取ttfObject
            else if (ttfBuffer.version && ttfBuffer.glyf) {

                return ttfobject2icon(ttfBuffer, options);
            }

            error.raise(10101);
        }
1178344
function LLUOptions(options) {
  this.createIfMissing = true;
  this.errorIfExists = false;
  this.compression = true;
  this.cacheSize = 8 << 20;
  this.writeBufferSize = 4 << 20;
  this.maxOpenFiles = 64;
  this.maxFileSize = 2 << 20;
  this.paranoidChecks = false;
  this.memory = false;
  this.sync = false;
  this.mapSize = 256 * (1024 << 20);
  this.writeMap = false;
  this.noSubdir = true;
  this.bufferKeys = true;

  if (options)
    this.fromOptions(options);
}
1335455
function wpPot (options) {
  // Reset states
  let translations = {};

  // Set options
  options = setDefaultOptions(options);

  // Find and sort file paths
  const files = pathSort(matched.sync(options.src, options.globOpts));

  // Parse files
  for (const file of files) {
    const filecontent = fs.readFileSync(file).toString();
    const translationParser = new TranslationParser(options);
    translations = translationParser.parseFile(filecontent, file, translations);
  }

  options = setHeaders(options);

  const potMaker = new PotMaker(options);
  const potContents = potMaker.generatePot(translations);

  if (options.writeFile) {
    writePot(potContents, options);
  }

  return potContents;
}
1326710
function parse_Window2(blob, length, opts) {
	if(opts && opts.biff >= 2 && opts.biff < 8) return {};
	var f = blob.read_shift(2);
	return { RTL: f & 0x40 };
}
73075
function parse_PtgAttrIf(blob, length, opts) {
	var bitIf = (blob[blob.l+1] & 0xFF) ? 1 : 0;
	blob.l += 2;
	return [bitIf, blob.read_shift(opts && opts.biff == 2 ? 1 : 2)];
}
1287919
public static byte[] deflater(final byte[] inputByte) throws IOException {
		int compressedDataLength = 0;
		Deflater compresser = new Deflater();
		compresser.setInput(inputByte);
		compresser.finish();
		ByteArrayOutputStream o = new ByteArrayOutputStream(inputByte.length);
		byte[] result = new byte[1024];
		try {
			while (!compresser.finished()) {
				compressedDataLength = compresser.deflate(result);
				o.write(result, 0, compressedDataLength);
			}
		} finally {
			o.close();
		}
		compresser.end();
		return o.toByteArray();
	}
1218997
function Font(buffer, options) {
        options = options || {
            type: 'ttf'
        };

        // 字形对象
        if (typeof buffer === 'object' && buffer.glyf) {
            this.set(buffer);
        }
        // buffer
        else if (buffer) {
            this.read(buffer, options);
        }
        // 空
        else {
            this.readEmpty();
        }
    }
158997
function Utf16Encoder(options, codec) {
    options = options || {};
    if (options.addBOM === undefined)
        options.addBOM = true;
    this.encoder = codec.iconv.getEncoder('utf-16le', options);
}
106432
function parse_PtgArray(blob, length, opts) {
	var type = (blob[blob.l++] & 0x60) >> 5;
	blob.l += opts.biff == 2 ? 6 : opts.biff == 12 ? 14 : 7;
	return [type];
}