Added ImFontAtlas::GlyphRangesBuilder helper + doc

This commit is contained in:
omar
2017-08-09 22:42:03 +08:00
parent 43e2abbee3
commit 4fd148f4f9
4 changed files with 90 additions and 9 deletions

View File

@ -1694,6 +1694,44 @@ const ImWchar* ImFontAtlas::GetGlyphRangesThai()
return &ranges[0];
}
//-----------------------------------------------------------------------------
// ImFontAtlas::GlyphRangesBuilder
//-----------------------------------------------------------------------------
void ImFontAtlas::GlyphRangesBuilder::AddText(const char* text, const char* text_end)
{
while (text_end ? (text < text_end) : *text)
{
unsigned int c = 0;
int c_len = ImTextCharFromUtf8(&c, text, text_end);
text += c_len;
if (c_len == 0)
break;
if (c < 0x10000)
AddChar((ImWchar)c);
}
}
void ImFontAtlas::GlyphRangesBuilder::AddRanges(const ImWchar* ranges)
{
for (; ranges[0]; ranges += 2)
for (ImWchar c = ranges[0]; c <= ranges[1]; c++)
AddChar(c);
}
void ImFontAtlas::GlyphRangesBuilder::BuildRanges(ImVector<ImWchar>* out_ranges)
{
for (int n = 0; n < 0x10000; n++)
if (GetBit(n))
{
out_ranges->push_back((ImWchar)n);
while (n < 0x10000 && GetBit(n + 1))
n++;
out_ranges->push_back((ImWchar)n);
}
out_ranges->push_back(0);
}
//-----------------------------------------------------------------------------
// ImFont
//-----------------------------------------------------------------------------