Skip to content

Displaying Glyphs' Codepoints as Characters [SOLVED] #494

@tingspain

Description

@tingspain

Hello,

I am trying to create a simple window to list all the glyphs and theirs Unicode of a font. But I dont manage to use properly the Codepoint to render the character.

Does anyone know how I can achieve that?

Thanks in advance!

static void ShowGlyphWindow()
{
    unsafe {

        ImGui.Begin("Glyphs List");

        var io = ImGui.GetIO();
        var font = io.Fonts.Fonts[0]; // Access the default font (usually the first one)
        
        ImGui.Text(Regex.Unescape(font.GetDebugName().ToString()));

        // Iterate through all the glyphs in the default font
        for (int i = 0; i < font.Glyphs.Size; i++)
        {
            var glyph = font.Glyphs[i];
            if( glyph.Codepoint == 0)
                continue;

            // Create a string to display the glyph character and its Unicode codepoint
            var glyphString = new StringBuilder(); 
            string text = $"\\u{glyph.Codepoint:X4}";

            string text2 = $"{glyph.Codepoint:X4}";
            byte[] bytes = Encoding.Default.GetBytes(text2);
            text2 = Encoding.UTF8.GetString(bytes);
            
            glyphString.Append($"Char: {text}  Unicode: U+{glyph.Codepoint:X4}");

            // Display the glyph string
            ImGui.Text(Regex.Unescape(glyphString.ToString()));

        }

        ImGui.End();
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions