parseCFFIndex function

dynamic parseCFFIndex(
  1. dynamic data,
  2. dynamic start,
  3. Function? conversionFn
)

Implementation

parseCFFIndex(data, start, Function? conversionFn) {
  var offsets = [];
  var objects = [];
  var count = getCard16(data, start);
  var objectOffset;
  var endOffset;
  if (count != 0) {
    var offsetSize = getByte(data, start + 2);
    objectOffset = start + ((count + 1) * offsetSize) + 2;
    var pos = start + 3;
    for (var i = 0; i < count + 1; i += 1) {
      offsets.add(getOffset(data, pos, offsetSize));
      pos += offsetSize;
    }

    // The total size of the index array is 4 header bytes + the value of the last offset.
    endOffset = objectOffset + offsets[count];
  } else {
    endOffset = start + 2;
  }

  for (var i = 0; i < offsets.length - 1; i += 1) {
    var value = getBytes(
        data, objectOffset + offsets[i], objectOffset + offsets[i + 1]);
    if (conversionFn != null) {
      value = conversionFn(value);
    }

    objects.add(value);
  }

  return {"objects": objects, "startOffset": start, "endOffset": endOffset};
}