mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-07 13:35:49 +02:00
Merge branch 'features/backends_context' into docking
# Conflicts: # backends/imgui_impl_dx10.cpp # backends/imgui_impl_dx11.cpp # backends/imgui_impl_dx12.cpp # backends/imgui_impl_dx9.cpp # backends/imgui_impl_glfw.cpp # backends/imgui_impl_opengl2.cpp # backends/imgui_impl_opengl3.cpp # backends/imgui_impl_sdl.cpp # backends/imgui_impl_vulkan.cpp # backends/imgui_impl_win32.cpp # examples/example_apple_opengl2/main.mm
This commit is contained in:
@ -2039,11 +2039,7 @@ void ImFontAtlas::GetTexDataAsAlpha8(unsigned char** out_pixels, int* out_wid
|
||||
{
|
||||
// Build atlas on demand
|
||||
if (TexPixelsAlpha8 == NULL)
|
||||
{
|
||||
if (ConfigData.empty())
|
||||
AddFontDefault();
|
||||
Build();
|
||||
}
|
||||
|
||||
*out_pixels = TexPixelsAlpha8;
|
||||
if (out_width) *out_width = TexWidth;
|
||||
@ -2264,6 +2260,10 @@ bool ImFontAtlas::Build()
|
||||
{
|
||||
IM_ASSERT(!Locked && "Cannot modify a locked ImFontAtlas between NewFrame() and EndFrame/Render()!");
|
||||
|
||||
// Default font is none are specified
|
||||
if (ConfigData.Size == 0)
|
||||
AddFontDefault();
|
||||
|
||||
// Select builder
|
||||
// - Note that we do not reassign to atlas->FontBuilderIO, since it is likely to point to static data which
|
||||
// may mess with some hot-reloading schemes. If you need to assign to this (for dynamic selection) AND are
|
||||
@ -2801,23 +2801,6 @@ void ImFontAtlasBuildFinish(ImFontAtlas* atlas)
|
||||
for (int i = 0; i < atlas->Fonts.Size; i++)
|
||||
if (atlas->Fonts[i]->DirtyLookupTables)
|
||||
atlas->Fonts[i]->BuildLookupTable();
|
||||
|
||||
// Ellipsis character is required for rendering elided text. We prefer using U+2026 (horizontal ellipsis).
|
||||
// However some old fonts may contain ellipsis at U+0085. Here we auto-detect most suitable ellipsis character.
|
||||
// FIXME: Also note that 0x2026 is currently seldom included in our font ranges. Because of this we are more likely to use three individual dots.
|
||||
for (int i = 0; i < atlas->Fonts.size(); i++)
|
||||
{
|
||||
ImFont* font = atlas->Fonts[i];
|
||||
if (font->EllipsisChar != (ImWchar)-1)
|
||||
continue;
|
||||
const ImWchar ellipsis_variants[] = { (ImWchar)0x2026, (ImWchar)0x0085 };
|
||||
for (int j = 0; j < IM_ARRAYSIZE(ellipsis_variants); j++)
|
||||
if (font->FindGlyphNoFallback(ellipsis_variants[j]) != NULL) // Verify glyph exists
|
||||
{
|
||||
font->EllipsisChar = ellipsis_variants[j];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Retrieve list of range (2 int per range, values are inclusive)
|
||||
@ -2838,6 +2821,7 @@ const ImWchar* ImFontAtlas::GetGlyphRangesKorean()
|
||||
0x0020, 0x00FF, // Basic Latin + Latin Supplement
|
||||
0x3131, 0x3163, // Korean alphabets
|
||||
0xAC00, 0xD7A3, // Korean characters
|
||||
0xFFFD, 0xFFFD, // Invalid
|
||||
0,
|
||||
};
|
||||
return &ranges[0];
|
||||
@ -2852,6 +2836,7 @@ const ImWchar* ImFontAtlas::GetGlyphRangesChineseFull()
|
||||
0x3000, 0x30FF, // CJK Symbols and Punctuations, Hiragana, Katakana
|
||||
0x31F0, 0x31FF, // Katakana Phonetic Extensions
|
||||
0xFF00, 0xFFEF, // Half-width characters
|
||||
0xFFFD, 0xFFFD, // Invalid
|
||||
0x4e00, 0x9FAF, // CJK Ideograms
|
||||
0,
|
||||
};
|
||||
@ -2928,7 +2913,8 @@ const ImWchar* ImFontAtlas::GetGlyphRangesChineseSimplifiedCommon()
|
||||
0x2000, 0x206F, // General Punctuation
|
||||
0x3000, 0x30FF, // CJK Symbols and Punctuations, Hiragana, Katakana
|
||||
0x31F0, 0x31FF, // Katakana Phonetic Extensions
|
||||
0xFF00, 0xFFEF // Half-width characters
|
||||
0xFF00, 0xFFEF, // Half-width characters
|
||||
0xFFFD, 0xFFFD // Invalid
|
||||
};
|
||||
static ImWchar full_ranges[IM_ARRAYSIZE(base_ranges) + IM_ARRAYSIZE(accumulative_offsets_from_0x4E00) * 2 + 1] = { 0 };
|
||||
if (!full_ranges[0])
|
||||
@ -3017,7 +3003,8 @@ const ImWchar* ImFontAtlas::GetGlyphRangesJapanese()
|
||||
0x0020, 0x00FF, // Basic Latin + Latin Supplement
|
||||
0x3000, 0x30FF, // CJK Symbols and Punctuations, Hiragana, Katakana
|
||||
0x31F0, 0x31FF, // Katakana Phonetic Extensions
|
||||
0xFF00, 0xFFEF // Half-width characters
|
||||
0xFF00, 0xFFEF, // Half-width characters
|
||||
0xFFFD, 0xFFFD // Invalid
|
||||
};
|
||||
static ImWchar full_ranges[IM_ARRAYSIZE(base_ranges) + IM_ARRAYSIZE(accumulative_offsets_from_0x4E00)*2 + 1] = { 0 };
|
||||
if (!full_ranges[0])
|
||||
@ -3116,8 +3103,9 @@ ImFont::ImFont()
|
||||
{
|
||||
FontSize = 0.0f;
|
||||
FallbackAdvanceX = 0.0f;
|
||||
FallbackChar = (ImWchar)'?';
|
||||
FallbackChar = (ImWchar)-1;
|
||||
EllipsisChar = (ImWchar)-1;
|
||||
DotChar = (ImWchar)-1;
|
||||
FallbackGlyph = NULL;
|
||||
ContainerAtlas = NULL;
|
||||
ConfigData = NULL;
|
||||
@ -3148,6 +3136,14 @@ void ImFont::ClearOutputData()
|
||||
MetricsTotalSurface = 0;
|
||||
}
|
||||
|
||||
static ImWchar FindFirstExistingGlyph(ImFont* font, const ImWchar* candidate_chars, int candidate_chars_count)
|
||||
{
|
||||
for (int n = 0; n < candidate_chars_count; n++)
|
||||
if (font->FindGlyphNoFallback(candidate_chars[n]) != NULL)
|
||||
return candidate_chars[n];
|
||||
return (ImWchar)-1;
|
||||
}
|
||||
|
||||
void ImFont::BuildLookupTable()
|
||||
{
|
||||
int max_codepoint = 0;
|
||||
@ -3190,9 +3186,31 @@ void ImFont::BuildLookupTable()
|
||||
SetGlyphVisible((ImWchar)' ', false);
|
||||
SetGlyphVisible((ImWchar)'\t', false);
|
||||
|
||||
// Setup fall-backs
|
||||
// Ellipsis character is required for rendering elided text. We prefer using U+2026 (horizontal ellipsis).
|
||||
// However some old fonts may contain ellipsis at U+0085. Here we auto-detect most suitable ellipsis character.
|
||||
// FIXME: Note that 0x2026 is rarely included in our font ranges. Because of this we are more likely to use three individual dots.
|
||||
const ImWchar ellipsis_chars[] = { (ImWchar)0x2026, (ImWchar)0x0085 };
|
||||
const ImWchar dots_chars[] = { (ImWchar)'.', (ImWchar)0xFF0E };
|
||||
if (EllipsisChar == (ImWchar)-1)
|
||||
EllipsisChar = FindFirstExistingGlyph(this, ellipsis_chars, IM_ARRAYSIZE(ellipsis_chars));
|
||||
if (DotChar == (ImWchar)-1)
|
||||
DotChar = FindFirstExistingGlyph(this, dots_chars, IM_ARRAYSIZE(dots_chars));
|
||||
|
||||
// Setup fallback character
|
||||
const ImWchar fallback_chars[] = { (ImWchar)IM_UNICODE_CODEPOINT_INVALID, (ImWchar)'?', (ImWchar)' ' };
|
||||
FallbackGlyph = FindGlyphNoFallback(FallbackChar);
|
||||
FallbackAdvanceX = FallbackGlyph ? FallbackGlyph->AdvanceX : 0.0f;
|
||||
if (FallbackGlyph == NULL)
|
||||
{
|
||||
FallbackChar = FindFirstExistingGlyph(this, fallback_chars, IM_ARRAYSIZE(fallback_chars));
|
||||
FallbackGlyph = FindGlyphNoFallback(FallbackChar);
|
||||
if (FallbackGlyph == NULL)
|
||||
{
|
||||
FallbackGlyph = &Glyphs.back();
|
||||
FallbackChar = FallbackGlyph->Codepoint;
|
||||
}
|
||||
}
|
||||
|
||||
FallbackAdvanceX = FallbackGlyph->AdvanceX;
|
||||
for (int i = 0; i < max_codepoint + 1; i++)
|
||||
if (IndexAdvanceX[i] < 0.0f)
|
||||
IndexAdvanceX[i] = FallbackAdvanceX;
|
||||
@ -3217,12 +3235,6 @@ void ImFont::SetGlyphVisible(ImWchar c, bool visible)
|
||||
glyph->Visible = visible ? 1 : 0;
|
||||
}
|
||||
|
||||
void ImFont::SetFallbackChar(ImWchar c)
|
||||
{
|
||||
FallbackChar = c;
|
||||
BuildLookupTable();
|
||||
}
|
||||
|
||||
void ImFont::GrowIndex(int new_size)
|
||||
{
|
||||
IM_ASSERT(IndexAdvanceX.Size == IndexLookup.Size);
|
||||
|
Reference in New Issue
Block a user