parseCFFCharset function

dynamic parseCFFCharset(
  1. dynamic data,
  2. dynamic start,
  3. dynamic nGlyphs,
  4. dynamic strings,
)

Implementation

parseCFFCharset(data, start, nGlyphs, strings) {
  var sid;
  var count;
  var parser = Parser(data, start);

  // The .notdef glyph is not included, so subtract 1.
  nGlyphs -= 1;
  List<String?> charset = ['.notdef'];

  var format = parser.parseCard8();
  if (format == 0) {
    for (var i = 0; i < nGlyphs; i += 1) {
      sid = parser.parseSID();
      charset.add(getCFFString(strings, sid));
    }
  } else if (format == 1) {
    while (charset.length <= nGlyphs) {
      sid = parser.parseSID();
      count = parser.parseCard8();
      for (var i = 0; i <= count; i += 1) {
        charset.add(getCFFString(strings, sid));
        sid += 1;
      }
    }
  } else if (format == 2) {
    while (charset.length <= nGlyphs) {
      sid = parser.parseSID();
      count = parser.parseCard16();

      for (var i = 0; i <= count; i += 1) {
        charset.add(getCFFString(strings, sid));
        sid += 1;
      }
    }
  } else {
    throw ('Unknown charset format ' + format);
  }

  return charset;
}