getNameID method

String? getNameID(
  1. TtfParserName fontNameID
)

Implementation

String? getNameID(TtfParserName fontNameID) {
  final basePosition = tableOffsets[name_table];
  if (basePosition == null) {
    return null;
  }
  // final format = bytes.getUint16(basePosition);
  final count = bytes.getUint16(basePosition + 2);
  final stringOffset = bytes.getUint16(basePosition + 4);
  var pos = basePosition + 6;
  String? _fontName;

  for (var i = 0; i < count; i++) {
    final platformID = bytes.getUint16(pos);
    final nameID = bytes.getUint16(pos + 6);
    final length = bytes.getUint16(pos + 8);
    final offset = bytes.getUint16(pos + 10);
    pos += 12;

    if (platformID == 1 && nameID == fontNameID.index) {
      try {
        _fontName = utf8.decode(bytes.buffer
            .asUint8List(basePosition + stringOffset + offset, length));
      } catch (a) {
        print('Error: $platformID $nameID $a');
      }
    }

    if (platformID == 3 && nameID == fontNameID.index) {
      try {
        return _decodeUtf16(bytes.buffer
            .asUint8List(basePosition + stringOffset + offset, length));
      } catch (a) {
        print('Error: $platformID $nameID $a');
      }
    }
  }
  return _fontName;
}