glyphNameToText static method

String? glyphNameToText(
  1. String name
)

Translates a glyph name into text.

Covers uniXXXX, uXXXX with four or more hex digits, and the names of the standard Latin set. Names outside that return null, and the caller falls back to the base encoding.

Implementation

static String? glyphNameToText(String name) {
  final clean = name.startsWith('/') ? name.substring(1) : name;
  if (clean.isEmpty) return null;

  final standard = _standardGlyphNames[clean];
  if (standard != null) return standard;

  if (clean.length >= 7 && clean.startsWith('uni')) {
    final value = int.tryParse(clean.substring(3, 7), radix: 16);
    if (value != null) return String.fromCharCode(value);
  }
  if (clean.length >= 5 && clean.startsWith('u')) {
    final value = int.tryParse(clean.substring(1), radix: 16);
    if (value != null && value >= 0 && value <= 0x10FFFF) {
      return String.fromCharCode(value);
    }
  }
  // `gNN` / `cidNN` / `indexNN` are glyph indices: undecipherable here.
  return null;
}