TtfParser constructor

TtfParser(
  1. ByteData bytes
)

Implementation

TtfParser(this.bytes) {
  final numTables = bytes.getUint16(4);

  for (var i = 0; i < numTables; i++) {
    final name = utf8.decode(bytes.buffer.asUint8List(i * 16 + 12, 4));
    final offset = bytes.getUint32(i * 16 + 20);
    final size = bytes.getUint32(i * 16 + 24);
    tableOffsets[name] = offset;
    tableSize[name] = size;
  }

  assert(tableOffsets.containsKey(head_table),
      'Unable to find the `head` table. This file is not a supported TTF font');
  assert(tableOffsets.containsKey(name_table),
      'Unable to find the `name` table. This file is not a supported TTF font');
  assert(tableOffsets.containsKey(hmtx_table),
      'Unable to find the `hmtx` table. This file is not a supported TTF font');
  assert(tableOffsets.containsKey(hhea_table),
      'Unable to find the `hhea` table. This file is not a supported TTF font');
  assert(tableOffsets.containsKey(cmap_table),
      'Unable to find the `cmap` table. This file is not a supported TTF font');
  assert(tableOffsets.containsKey(maxp_table),
      'Unable to find the `maxp` table. This file is not a supported TTF font');

  _parseCMap();
  if (tableOffsets.containsKey(loca_table) &&
      tableOffsets.containsKey(glyf_table)) {
    _parseIndexes();
    _parseGlyphs();
  }
  if (tableOffsets.containsKey(cblc_table) &&
      tableOffsets.containsKey(cbdt_table)) {
    _parseBitmaps();
  }
}