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