private void AddGlyphToTree(GlyphNode node, Glyph glyph)
    {
        foreach (var letter in glyph.sequence)
        {
            node = GetNextNode(node, letter);
        }

        node.glyph = glyph;
    }
    private GlyphNode GetNextNode(GlyphNode currentNode, char key)
    {
        currentNode.next = currentNode.next ?? new Dictionary <char, GlyphNode>();

        if (!currentNode.next.ContainsKey(key))
        {
            currentNode.next.Add(key, new GlyphNode());
        }

        return(currentNode.next[key]);
    }
    private GlyphNode BuildTree()
    {
        var fontData = JsonUtility.FromJson <FontData>(glyphData.text);
        var result   = new GlyphNode();

        LineHeight = fontData.lineHeight;

        foreach (var glyph in fontData.glyphs)
        {
            AddGlyphToTree(result, glyph);
        }

        return(result);
    }
    public Glyph GetNextGlyph(string input, int offset)
    {
        root = root ?? BuildTree();

        var node = root;

        for (int index = offset, length = input.Length; index < length; index++)
        {
            if (node.next == null)
            {
                break;
            }

            var letter = input[index];
            if (node.next.ContainsKey(letter))
            {
                node = node.next[letter];
            }
        }

        return(node.glyph);
    }