1
0
mirror of https://github.com/ocornut/imgui.git synced 2024-11-12 02:00:58 +01:00

ImFont: Allowing to use up to 0xFFFE glyphs in same font (increased from previous 0x8000)

This commit is contained in:
ocornut 2016-06-07 09:14:54 +02:00
parent 4fddfa4b5e
commit 65a525550e
2 changed files with 9 additions and 9 deletions

View File

@ -1357,7 +1357,7 @@ struct ImFont
ImVec2 DisplayOffset; // = (0.f,1.f) // Offset font rendering by xx pixels ImVec2 DisplayOffset; // = (0.f,1.f) // Offset font rendering by xx pixels
ImVector<Glyph> Glyphs; // // All glyphs. 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<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) const Glyph* FallbackGlyph; // == FindGlyph(FontFallbackChar)
float FallbackXAdvance; // == FallbackGlyph->XAdvance float FallbackXAdvance; // == FallbackGlyph->XAdvance
ImWchar FallbackChar; // = '?' // Replacement glyph if one isn't found. Only set via SetFallbackChar() ImWchar FallbackChar; // = '?' // Replacement glyph if one isn't found. Only set via SetFallbackChar()

View File

@ -1695,7 +1695,7 @@ void ImFont::BuildLookupTable()
for (int i = 0; i != Glyphs.Size; i++) for (int i = 0; i != Glyphs.Size; i++)
max_codepoint = ImMax(max_codepoint, (int)Glyphs[i].Codepoint); 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(); IndexXAdvance.clear();
IndexLookup.clear(); IndexLookup.clear();
GrowIndex(max_codepoint + 1); GrowIndex(max_codepoint + 1);
@ -1703,7 +1703,7 @@ void ImFont::BuildLookupTable()
{ {
int codepoint = (int)Glyphs[i].Codepoint; int codepoint = (int)Glyphs[i].Codepoint;
IndexXAdvance[codepoint] = Glyphs[i].XAdvance; IndexXAdvance[codepoint] = Glyphs[i].XAdvance;
IndexLookup[codepoint] = (short)i; IndexLookup[codepoint] = (unsigned short)i;
} }
// Create a glyph to handle TAB // Create a glyph to handle TAB
@ -1717,7 +1717,7 @@ void ImFont::BuildLookupTable()
tab_glyph.Codepoint = '\t'; tab_glyph.Codepoint = '\t';
tab_glyph.XAdvance *= 4; tab_glyph.XAdvance *= 4;
IndexXAdvance[(int)tab_glyph.Codepoint] = (float)tab_glyph.XAdvance; 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; FallbackGlyph = NULL;
@ -1745,7 +1745,7 @@ void ImFont::GrowIndex(int new_size)
for (int i = old_size; i < new_size; i++) for (int i = old_size; i < new_size; i++)
{ {
IndexXAdvance[i] = -1.0f; 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. 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; 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; return;
if (src >= index_size && dst >= index_size) // both 'dst' and 'src' don't exist -> no-op if (src >= index_size && dst >= index_size) // both 'dst' and 'src' don't exist -> no-op
return; return;
GrowIndex(dst + 1); 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; 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) if (c < IndexLookup.Size)
{ {
const short i = IndexLookup[c]; const unsigned short i = IndexLookup[c];
if (i != -1) if (i != (unsigned short)-1)
return &Glyphs.Data[i]; return &Glyphs.Data[i];
} }
return FallbackGlyph; return FallbackGlyph;