MCPcopy Create free account
hub / github.com/DISTRHO/Cardinal / BuildLookupTable

Method BuildLookupTable

plugins/Cardinal/src/DearImGui/imgui_draw.cpp:3150–3220  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3148}
3149
3150void ImFont::BuildLookupTable()
3151{
3152 int max_codepoint = 0;
3153 for (int i = 0; i != Glyphs.Size; i++)
3154 max_codepoint = ImMax(max_codepoint, (int)Glyphs[i].Codepoint);
3155
3156 // Build lookup table
3157 IM_ASSERT(Glyphs.Size < 0xFFFF); // -1 is reserved
3158 IndexAdvanceX.clear();
3159 IndexLookup.clear();
3160 DirtyLookupTables = false;
3161 memset(Used4kPagesMap, 0, sizeof(Used4kPagesMap));
3162 GrowIndex(max_codepoint + 1);
3163 for (int i = 0; i < Glyphs.Size; i++)
3164 {
3165 int codepoint = (int)Glyphs[i].Codepoint;
3166 IndexAdvanceX[codepoint] = Glyphs[i].AdvanceX;
3167 IndexLookup[codepoint] = (ImWchar)i;
3168
3169 // Mark 4K page as used
3170 const int page_n = codepoint / 4096;
3171 Used4kPagesMap[page_n >> 3] |= 1 << (page_n & 7);
3172 }
3173
3174 // Create a glyph to handle TAB
3175 // FIXME: Needs proper TAB handling but it needs to be contextualized (or we could arbitrary say that each string starts at "column 0" ?)
3176 if (FindGlyph((ImWchar)' '))
3177 {
3178 if (Glyphs.back().Codepoint != '\t') // So we can call this function multiple times (FIXME: Flaky)
3179 Glyphs.resize(Glyphs.Size + 1);
3180 ImFontGlyph& tab_glyph = Glyphs.back();
3181 tab_glyph = *FindGlyph((ImWchar)' ');
3182 tab_glyph.Codepoint = '\t';
3183 tab_glyph.AdvanceX *= IM_TABSIZE;
3184 IndexAdvanceX[(int)tab_glyph.Codepoint] = (float)tab_glyph.AdvanceX;
3185 IndexLookup[(int)tab_glyph.Codepoint] = (ImWchar)(Glyphs.Size - 1);
3186 }
3187
3188 // Mark special glyphs as not visible (note that AddGlyph already mark as non-visible glyphs with zero-size polygons)
3189 SetGlyphVisible((ImWchar)' ', false);
3190 SetGlyphVisible((ImWchar)'\t', false);
3191
3192 // Ellipsis character is required for rendering elided text. We prefer using U+2026 (horizontal ellipsis).
3193 // However some old fonts may contain ellipsis at U+0085. Here we auto-detect most suitable ellipsis character.
3194 // FIXME: Note that 0x2026 is rarely included in our font ranges. Because of this we are more likely to use three individual dots.
3195 const ImWchar ellipsis_chars[] = { (ImWchar)0x2026, (ImWchar)0x0085 };
3196 const ImWchar dots_chars[] = { (ImWchar)'.', (ImWchar)0xFF0E };
3197 if (EllipsisChar == (ImWchar)-1)
3198 EllipsisChar = FindFirstExistingGlyph(this, ellipsis_chars, IM_ARRAYSIZE(ellipsis_chars));
3199 if (DotChar == (ImWchar)-1)
3200 DotChar = FindFirstExistingGlyph(this, dots_chars, IM_ARRAYSIZE(dots_chars));
3201
3202 // Setup fallback character
3203 const ImWchar fallback_chars[] = { (ImWchar)IM_UNICODE_CODEPOINT_INVALID, (ImWchar)'?', (ImWchar)' ' };
3204 FallbackGlyph = FindGlyphNoFallback(FallbackChar);
3205 if (FallbackGlyph == NULL)
3206 {
3207 FallbackChar = FindFirstExistingGlyph(this, fallback_chars, IM_ARRAYSIZE(fallback_chars));

Callers 1

ImFontAtlasBuildFinishFunction · 0.80

Calls 5

ImMaxFunction · 0.85
FindFirstExistingGlyphFunction · 0.85
backMethod · 0.80
clearMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected