factory method

dynamic factory(
  1. dynamic coverageTable
)

Implementation

factory(coverageTable) {
  if (coverageTable.format == 1) {
    final _fields = [{"name": 'coverageFormat', "type": 'USHORT', "value": 1}];
    _fields.addAll(ushortList('glyph', coverageTable.glyphs, null));

    return Coverage('coverageTable', _fields, null);
  } else if (coverageTable.format == 2) {
    final _fields = [{"name": 'coverageFormat', "type": 'USHORT', "value": 1}];
    _fields.addAll(
      recordList('rangeRecord', coverageTable.ranges, (RangeRecord) {
        return [
          {"name": 'startGlyphID', "type": 'USHORT', "value": RangeRecord.start},
          {"name": 'endGlyphID', "type": 'USHORT', "value": RangeRecord.end},
          {"name": 'startCoverageIndex', "type": 'USHORT', "value": RangeRecord.index},
        ];
      })
    );

    return Coverage('coverageTable', _fields, null);
  } else {
    assertfn(false, 'Coverage format must be 1 or 2.');
  }
}