mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-10-31 13:11:05 +01:00 
			
		
		
		
	Internals: Replace unsigned short with ImWchar when dealing with character storage. (#2078)
This commit is contained in:
		| @@ -1894,7 +1894,7 @@ bool    ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas) | ||||
|                     continue; | ||||
|  | ||||
|                 const int codepoint = range.first_unicode_codepoint_in_range + char_idx; | ||||
|                 if (cfg.MergeMode && dst_font->FindGlyphNoFallback((unsigned short)codepoint)) | ||||
|                 if (cfg.MergeMode && dst_font->FindGlyphNoFallback((ImWchar)codepoint)) | ||||
|                     continue; | ||||
|  | ||||
|                 float char_advance_x_org = pc.xadvance; | ||||
| @@ -2316,21 +2316,21 @@ void ImFont::BuildLookupTable() | ||||
|     { | ||||
|         int codepoint = (int)Glyphs[i].Codepoint; | ||||
|         IndexAdvanceX[codepoint] = Glyphs[i].AdvanceX; | ||||
|         IndexLookup[codepoint] = (unsigned short)i; | ||||
|         IndexLookup[codepoint] = (ImWchar)i; | ||||
|     } | ||||
|  | ||||
|     // Create a glyph to handle TAB | ||||
|     // FIXME: Needs proper TAB handling but it needs to be contextualized (or we could arbitrary say that each string starts at "column 0" ?) | ||||
|     if (FindGlyph((unsigned short)' ')) | ||||
|     if (FindGlyph((ImWchar)' ')) | ||||
|     { | ||||
|         if (Glyphs.back().Codepoint != '\t')   // So we can call this function multiple times | ||||
|             Glyphs.resize(Glyphs.Size + 1); | ||||
|         ImFontGlyph& tab_glyph = Glyphs.back(); | ||||
|         tab_glyph = *FindGlyph((unsigned short)' '); | ||||
|         tab_glyph = *FindGlyph((ImWchar)' '); | ||||
|         tab_glyph.Codepoint = '\t'; | ||||
|         tab_glyph.AdvanceX *= 4; | ||||
|         IndexAdvanceX[(int)tab_glyph.Codepoint] = (float)tab_glyph.AdvanceX; | ||||
|         IndexLookup[(int)tab_glyph.Codepoint] = (unsigned short)(Glyphs.Size-1); | ||||
|         IndexLookup[(int)tab_glyph.Codepoint] = (ImWchar)(Glyphs.Size-1); | ||||
|     } | ||||
|  | ||||
|     FallbackGlyph = FindGlyphNoFallback(FallbackChar); | ||||
| @@ -2352,7 +2352,7 @@ void ImFont::GrowIndex(int new_size) | ||||
|     if (new_size <= IndexLookup.Size) | ||||
|         return; | ||||
|     IndexAdvanceX.resize(new_size, -1.0f); | ||||
|     IndexLookup.resize(new_size, (unsigned short)-1); | ||||
|     IndexLookup.resize(new_size, (ImWchar)-1); | ||||
| } | ||||
|  | ||||
| // x0/y0/x1/y1 are offset from the character upper-left layout position, in pixels. Therefore x0/y0 are often fairly close to zero. | ||||
| @@ -2385,13 +2385,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] == (unsigned short)-1 && !overwrite_dst) // 'dst' already exists | ||||
|     if (dst < index_size && IndexLookup.Data[dst] == (ImWchar)-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] : (unsigned short)-1; | ||||
|     IndexLookup[dst] = (src < index_size) ? IndexLookup.Data[src] : (ImWchar)-1; | ||||
|     IndexAdvanceX[dst] = (src < index_size) ? IndexAdvanceX.Data[src] : 1.0f; | ||||
| } | ||||
|  | ||||
| @@ -2399,8 +2399,8 @@ const ImFontGlyph* ImFont::FindGlyph(ImWchar c) const | ||||
| { | ||||
|     if (c >= IndexLookup.Size) | ||||
|         return FallbackGlyph; | ||||
|     const unsigned short i = IndexLookup[c]; | ||||
|     if (i == (unsigned short)-1) | ||||
|     const ImWchar i = IndexLookup[c]; | ||||
|     if (i == (ImWchar)-1) | ||||
|         return FallbackGlyph; | ||||
|     return &Glyphs.Data[i]; | ||||
| } | ||||
| @@ -2409,8 +2409,8 @@ const ImFontGlyph* ImFont::FindGlyphNoFallback(ImWchar c) const | ||||
| { | ||||
|     if (c >= IndexLookup.Size) | ||||
|         return NULL; | ||||
|     const unsigned short i = IndexLookup[c]; | ||||
|     if (i == (unsigned short)-1) | ||||
|     const ImWchar i = IndexLookup[c]; | ||||
|     if (i == (ImWchar)-1) | ||||
|         return NULL; | ||||
|     return &Glyphs.Data[i]; | ||||
| } | ||||
| @@ -2608,7 +2608,7 @@ ImVec2 ImFont::CalcTextSizeA(float size, float max_width, float wrap_width, cons | ||||
|     return text_size; | ||||
| } | ||||
|  | ||||
| void ImFont::RenderChar(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col, unsigned short c) const | ||||
| void ImFont::RenderChar(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col, ImWchar c) const | ||||
| { | ||||
|     if (c == ' ' || c == '\t' || c == '\n' || c == '\r') // Match behavior of RenderText(), those 4 codepoints are hard-coded. | ||||
|         return; | ||||
| @@ -2733,7 +2733,7 @@ void ImFont::RenderText(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col | ||||
|         } | ||||
|  | ||||
|         float char_width = 0.0f; | ||||
|         if (const ImFontGlyph* glyph = FindGlyph((unsigned short)c)) | ||||
|         if (const ImFontGlyph* glyph = FindGlyph((ImWchar)c)) | ||||
|         { | ||||
|             char_width = glyph->AdvanceX * scale; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user