47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
public static class CharWidth
|
|
{
|
|
private static readonly Dictionary<char, float> CharWidths = new Dictionary<char, float>();
|
|
|
|
static CharWidth()
|
|
{
|
|
// Default for all ASCII
|
|
for (char c = (char)32; c <= (char)126; c++)
|
|
CharWidths[c] = 5.0f;
|
|
|
|
// Override exceptions
|
|
CharWidths[' '] = 3.0f;
|
|
CharWidths['!'] = 1.0f;
|
|
CharWidths['"'] = 3.0f;
|
|
CharWidths['\''] = 1.0f;
|
|
CharWidths['('] = 3.0f;
|
|
CharWidths[')'] = 3.0f;
|
|
CharWidths['*'] = 3.0f;
|
|
CharWidths[','] = 1.0f;
|
|
CharWidths['.'] = 1.0f;
|
|
CharWidths[':'] = 1.0f;
|
|
CharWidths[';'] = 1.0f;
|
|
CharWidths['<'] = 4.0f;
|
|
CharWidths['>'] = 4.0f;
|
|
CharWidths['@'] = 6.0f;
|
|
CharWidths['I'] = 3.0f;
|
|
CharWidths['['] = 3.0f;
|
|
CharWidths[']'] = 3.0f;
|
|
CharWidths['`'] = 2.0f;
|
|
CharWidths['f'] = 4.0f;
|
|
CharWidths['i'] = 1.0f;
|
|
CharWidths['k'] = 4.0f;
|
|
CharWidths['l'] = 2.0f;
|
|
CharWidths['t'] = 3.0f;
|
|
CharWidths['{'] = 3.0f;
|
|
CharWidths['|'] = 1.0f;
|
|
CharWidths['}'] = 3.0f;
|
|
CharWidths['~'] = 6.0f;
|
|
}
|
|
|
|
public static float GetWidth(char c)
|
|
{
|
|
if (CharWidths.TryGetValue(c, out float width))
|
|
return width;
|
|
return 5.0f;
|
|
}
|
|
} |