MCPcopy Create free account
hub / github.com/danoon2/Boxedwine / BuildLookupTable

Method BuildLookupTable

lib/imgui/imgui_draw.cpp:2619–2662  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2617}
2618
2619void ImFont::BuildLookupTable()
2620{
2621 int max_codepoint = 0;
2622 for (int i = 0; i != Glyphs.Size; i++)
2623 max_codepoint = ImMax(max_codepoint, (int)Glyphs[i].Codepoint);
2624
2625 // Build lookup table
2626 IM_ASSERT(Glyphs.Size < 0xFFFF); // -1 is reserved
2627 IndexAdvanceX.clear();
2628 IndexLookup.clear();
2629 DirtyLookupTables = false;
2630 GrowIndex(max_codepoint + 1);
2631 for (int i = 0; i < Glyphs.Size; i++)
2632 {
2633 int codepoint = (int)Glyphs[i].Codepoint;
2634 IndexAdvanceX[codepoint] = Glyphs[i].AdvanceX;
2635 IndexLookup[codepoint] = (ImWchar)i;
2636 }
2637
2638 // Create a glyph to handle TAB
2639 // FIXME: Needs proper TAB handling but it needs to be contextualized (or we could arbitrary say that each string starts at "column 0" ?)
2640 if (FindGlyph((ImWchar)' '))
2641 {
2642 if (Glyphs.back().Codepoint != '\t') // So we can call this function multiple times (FIXME: Flaky)
2643 Glyphs.resize(Glyphs.Size + 1);
2644 ImFontGlyph& tab_glyph = Glyphs.back();
2645 tab_glyph = *FindGlyph((ImWchar)' ');
2646 tab_glyph.Codepoint = '\t';
2647 tab_glyph.AdvanceX *= IM_TABSIZE;
2648 IndexAdvanceX[(int)tab_glyph.Codepoint] = (float)tab_glyph.AdvanceX;
2649 IndexLookup[(int)tab_glyph.Codepoint] = (ImWchar)(Glyphs.Size-1);
2650 }
2651
2652 // Mark special glyphs as not visible (note that AddGlyph already mark as non-visible glyphs with zero-size polygons)
2653 SetGlyphVisible((ImWchar)' ', false);
2654 SetGlyphVisible((ImWchar)'\t', false);
2655
2656 // Setup fall-backs
2657 FallbackGlyph = FindGlyphNoFallback(FallbackChar);
2658 FallbackAdvanceX = FallbackGlyph ? FallbackGlyph->AdvanceX : 0.0f;
2659 for (int i = 0; i < max_codepoint + 1; i++)
2660 if (IndexAdvanceX[i] < 0.0f)
2661 IndexAdvanceX[i] = FallbackAdvanceX;
2662}
2663
2664void ImFont::SetGlyphVisible(ImWchar c, bool visible)
2665{

Callers 1

ImFontAtlasBuildFinishFunction · 0.80

Calls 4

ImMaxFunction · 0.85
clearMethod · 0.45
backMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected