mirror of
https://github.com/Drezil/imgui.git
synced 2024-12-24 00:26:36 +00:00
ImFont: Allowing to use up to 0xFFFE glyphs in same font (increased from previous 0x8000)
This commit is contained in:
parent
4fddfa4b5e
commit
65a525550e
2
imgui.h
2
imgui.h
@ -1357,7 +1357,7 @@ struct ImFont
|
||||
ImVec2 DisplayOffset; // = (0.f,1.f) // Offset font rendering by xx pixels
|
||||
ImVector<Glyph> Glyphs; // // All glyphs.
|
||||
ImVector<float> IndexXAdvance; // // Sparse. Glyphs->XAdvance in a directly indexable way (more cache-friendly, for CalcTextSize functions which are often bottleneck in large UI).
|
||||
ImVector<short> IndexLookup; // // Sparse. Index glyphs by Unicode code-point.
|
||||
ImVector<unsigned short> IndexLookup; // // Sparse. Index glyphs by Unicode code-point.
|
||||
const Glyph* FallbackGlyph; // == FindGlyph(FontFallbackChar)
|
||||
float FallbackXAdvance; // == FallbackGlyph->XAdvance
|
||||
ImWchar FallbackChar; // = '?' // Replacement glyph if one isn't found. Only set via SetFallbackChar()
|
||||
|
@ -1695,7 +1695,7 @@ void ImFont::BuildLookupTable()
|
||||
for (int i = 0; i != Glyphs.Size; i++)
|
||||
max_codepoint = ImMax(max_codepoint, (int)Glyphs[i].Codepoint);
|
||||
|
||||
IM_ASSERT(Glyphs.Size < 32*1024);
|
||||
IM_ASSERT(Glyphs.Size < 0xFFFF); // -1 is reserved
|
||||
IndexXAdvance.clear();
|
||||
IndexLookup.clear();
|
||||
GrowIndex(max_codepoint + 1);
|
||||
@ -1703,7 +1703,7 @@ void ImFont::BuildLookupTable()
|
||||
{
|
||||
int codepoint = (int)Glyphs[i].Codepoint;
|
||||
IndexXAdvance[codepoint] = Glyphs[i].XAdvance;
|
||||
IndexLookup[codepoint] = (short)i;
|
||||
IndexLookup[codepoint] = (unsigned short)i;
|
||||
}
|
||||
|
||||
// Create a glyph to handle TAB
|
||||
@ -1717,7 +1717,7 @@ void ImFont::BuildLookupTable()
|
||||
tab_glyph.Codepoint = '\t';
|
||||
tab_glyph.XAdvance *= 4;
|
||||
IndexXAdvance[(int)tab_glyph.Codepoint] = (float)tab_glyph.XAdvance;
|
||||
IndexLookup[(int)tab_glyph.Codepoint] = (short)(Glyphs.Size-1);
|
||||
IndexLookup[(int)tab_glyph.Codepoint] = (unsigned short)(Glyphs.Size-1);
|
||||
}
|
||||
|
||||
FallbackGlyph = NULL;
|
||||
@ -1745,7 +1745,7 @@ void ImFont::GrowIndex(int new_size)
|
||||
for (int i = old_size; i < new_size; i++)
|
||||
{
|
||||
IndexXAdvance[i] = -1.0f;
|
||||
IndexLookup[i] = (short)-1;
|
||||
IndexLookup[i] = (unsigned short)-1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1754,13 +1754,13 @@ void ImFont::AddRemapChar(ImWchar dst, ImWchar src, bool overwrite_dst)
|
||||
IM_ASSERT(IndexLookup.Size > 0); // Currently this can only be called AFTER the font has been built, aka after calling ImFontAtlas::GetTexDataAs*() function.
|
||||
int index_size = IndexLookup.Size;
|
||||
|
||||
if (dst < index_size && IndexLookup.Data[dst] == -1 && !overwrite_dst) // 'dst' already exists
|
||||
if (dst < index_size && IndexLookup.Data[dst] == (unsigned short)-1 && !overwrite_dst) // 'dst' already exists
|
||||
return;
|
||||
if (src >= index_size && dst >= index_size) // both 'dst' and 'src' don't exist -> no-op
|
||||
return;
|
||||
|
||||
GrowIndex(dst + 1);
|
||||
IndexLookup[dst] = (src < index_size) ? IndexLookup.Data[src] : -1;
|
||||
IndexLookup[dst] = (src < index_size) ? IndexLookup.Data[src] : (unsigned short)-1;
|
||||
IndexXAdvance[dst] = (src < index_size) ? IndexXAdvance.Data[src] : 1.0f;
|
||||
}
|
||||
|
||||
@ -1768,8 +1768,8 @@ const ImFont::Glyph* ImFont::FindGlyph(unsigned short c) const
|
||||
{
|
||||
if (c < IndexLookup.Size)
|
||||
{
|
||||
const short i = IndexLookup[c];
|
||||
if (i != -1)
|
||||
const unsigned short i = IndexLookup[c];
|
||||
if (i != (unsigned short)-1)
|
||||
return &Glyphs.Data[i];
|
||||
}
|
||||
return FallbackGlyph;
|
||||
|
Loading…
Reference in New Issue
Block a user