mirror of
https://github.com/ocornut/imgui.git
synced 2025-09-06 11:28:31 +00:00
Fonts: Reduced reliance on ImFontConfig::DstFont.
This commit is contained in:
@@ -2966,9 +2966,6 @@ ImFont* ImFontAtlas::AddFont(const ImFontConfig* font_cfg)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Invalidate texture
|
|
||||||
//TexReady = false;
|
|
||||||
//ClearTexData();
|
|
||||||
return new_font_cfg.DstFont;
|
return new_font_cfg.DstFont;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3276,15 +3273,16 @@ void ImFontAtlasBuildSetupFontLoader(ImFontAtlas* atlas, const ImFontLoader* fon
|
|||||||
void ImFontAtlasBuildPreloadAllGlyphRanges(ImFontAtlas* atlas)
|
void ImFontAtlasBuildPreloadAllGlyphRanges(ImFontAtlas* atlas)
|
||||||
{
|
{
|
||||||
atlas->Builder->PreloadedAllGlyphsRanges = true;
|
atlas->Builder->PreloadedAllGlyphsRanges = true;
|
||||||
for (int src_n = 0; src_n < atlas->Sources.Size; src_n++)
|
for (ImFont* font : atlas->Fonts)
|
||||||
{
|
for (int src_n = 0; src_n < font->SourcesCount; src_n++)
|
||||||
ImFontConfig* src = &atlas->Sources[src_n];
|
{
|
||||||
const ImWchar* ranges = src->GlyphRanges ? src->GlyphRanges : atlas->GetGlyphRangesDefault();
|
ImFontConfig* src = &font->Sources[src_n];
|
||||||
IM_ASSERT(ranges != NULL);
|
const ImWchar* ranges = src->GlyphRanges ? src->GlyphRanges : atlas->GetGlyphRangesDefault();
|
||||||
for (; ranges[0]; ranges += 2)
|
IM_ASSERT(ranges != NULL);
|
||||||
for (unsigned int c = ranges[0]; c <= ranges[1] && c <= IM_UNICODE_CODEPOINT_MAX; c++) //-V560
|
for (; ranges[0]; ranges += 2)
|
||||||
src->DstFont->FindGlyphNoFallback((ImWchar)c);
|
for (unsigned int c = ranges[0]; c <= ranges[1] && c <= IM_UNICODE_CODEPOINT_MAX; c++) //-V560
|
||||||
}
|
font->FindGlyphNoFallback((ImWchar)c);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImFontAtlasBuildUpdatePointers(ImFontAtlas* atlas)
|
void ImFontAtlasBuildUpdatePointers(ImFontAtlas* atlas)
|
||||||
@@ -3462,17 +3460,15 @@ bool ImFontAtlasBuildAddFont(ImFontAtlas* atlas, ImFontConfig* src)
|
|||||||
if (!font_loader->FontSrcInit(atlas, src))
|
if (!font_loader->FontSrcInit(atlas, src))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ImFontAtlasBuildSetupFontSpecialGlyphs(atlas, src);
|
ImFontAtlasBuildSetupFontSpecialGlyphs(atlas, font, src);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rasterize our own ellipsis character from a dot.
|
// Rasterize our own ellipsis character from a dot.
|
||||||
// This may seem overly complicated right now but the point is to exercise and improve a technique which should be increasingly used.
|
// This may seem overly complicated right now but the point is to exercise and improve a technique which should be increasingly used.
|
||||||
// FIXME-NEWATLAS: This borrows too much from FontLoader's FontAddGlyph() and suggest that we should add further helpers.
|
// FIXME-NEWATLAS: This borrows too much from FontLoader's FontAddGlyph() and suggest that we should add further helpers.
|
||||||
static void ImFontAtlasBuildSetupFontCreateEllipsisFromDot(ImFontAtlas* atlas, ImFontConfig* src, const ImFontGlyph* dot_glyph)
|
static void ImFontAtlasBuildSetupFontCreateEllipsisFromDot(ImFontAtlas* atlas, ImFont* font, const ImFontGlyph* dot_glyph)
|
||||||
{
|
{
|
||||||
ImFont* font = src->DstFont;
|
|
||||||
|
|
||||||
ImFontAtlasRect* dot_r = ImFontAtlasPackGetRect(atlas, dot_glyph->PackId);
|
ImFontAtlasRect* dot_r = ImFontAtlasPackGetRect(atlas, dot_glyph->PackId);
|
||||||
const int dot_spacing = 1;
|
const int dot_spacing = 1;
|
||||||
const float dot_step = (dot_glyph->X1 - dot_glyph->X0) + dot_spacing;
|
const float dot_step = (dot_glyph->X1 - dot_glyph->X0) + dot_spacing;
|
||||||
@@ -3502,15 +3498,14 @@ static void ImFontAtlasBuildSetupFontCreateEllipsisFromDot(ImFontAtlas* atlas, I
|
|||||||
|
|
||||||
// Load/identify special glyphs
|
// Load/identify special glyphs
|
||||||
// (note that this is called again for fonts with MergeMode)
|
// (note that this is called again for fonts with MergeMode)
|
||||||
void ImFontAtlasBuildSetupFontSpecialGlyphs(ImFontAtlas* atlas, ImFontConfig* src)
|
void ImFontAtlasBuildSetupFontSpecialGlyphs(ImFontAtlas* atlas, ImFont* font, ImFontConfig* src)
|
||||||
{
|
{
|
||||||
ImFont* font = src->DstFont;
|
const int src_idx_in_font = (int)(src - font->Sources);
|
||||||
const int cfg_idx_in_font = (int)(src - font->Sources);
|
IM_ASSERT(src_idx_in_font >= 0 && src_idx_in_font < font->SourcesCount);
|
||||||
IM_ASSERT(cfg_idx_in_font >= 0 && cfg_idx_in_font < font->SourcesCount);
|
|
||||||
IM_UNUSED(atlas);
|
IM_UNUSED(atlas);
|
||||||
|
|
||||||
// While manipulating glyphs during init we want to restrict all searches for one source font.
|
// While manipulating glyphs during init we want to restrict all searches for one source font.
|
||||||
font->LockSingleSrcConfigIdx = (short)cfg_idx_in_font;
|
font->LockSingleSrcConfigIdx = (short)src_idx_in_font;
|
||||||
|
|
||||||
// Setup Fallback character
|
// Setup Fallback character
|
||||||
// FIXME-NEWATLAS: could we use a scheme where this is lazily loaded?
|
// FIXME-NEWATLAS: could we use a scheme where this is lazily loaded?
|
||||||
@@ -3553,7 +3548,7 @@ void ImFontAtlasBuildSetupFontSpecialGlyphs(ImFontAtlas* atlas, ImFontConfig* sr
|
|||||||
{
|
{
|
||||||
const ImWchar dots_chars[] = { (ImWchar)'.', (ImWchar)0xFF0E };
|
const ImWchar dots_chars[] = { (ImWchar)'.', (ImWchar)0xFF0E };
|
||||||
if (const ImFontGlyph* dot_glyph = LoadFirstExistingGlyph(font, dots_chars, IM_ARRAYSIZE(dots_chars)))
|
if (const ImFontGlyph* dot_glyph = LoadFirstExistingGlyph(font, dots_chars, IM_ARRAYSIZE(dots_chars)))
|
||||||
ImFontAtlasBuildSetupFontCreateEllipsisFromDot(atlas, src, dot_glyph);
|
ImFontAtlasBuildSetupFontCreateEllipsisFromDot(atlas, font, dot_glyph);
|
||||||
else
|
else
|
||||||
font->EllipsisChar = (ImWchar)' ';
|
font->EllipsisChar = (ImWchar)' ';
|
||||||
}
|
}
|
||||||
@@ -3598,7 +3593,7 @@ void ImFontAtlasBuildReloadFont(ImFontAtlas* atlas, ImFont* font)
|
|||||||
if (atlas->FontLoader && atlas->FontLoader->FontSrcInit != NULL)
|
if (atlas->FontLoader && atlas->FontLoader->FontSrcInit != NULL)
|
||||||
atlas->FontLoader->FontSrcInit(atlas, src);
|
atlas->FontLoader->FontSrcInit(atlas, src);
|
||||||
|
|
||||||
ImFontAtlasBuildSetupFontSpecialGlyphs(atlas, src); // Technically this is called for each source sub-font, tho 99.9% of the time the first one fills everything.
|
ImFontAtlasBuildSetupFontSpecialGlyphs(atlas, font, src); // Technically this is called for each source sub-font, tho 99.9% of the time the first one fills everything.
|
||||||
atlas->TexIsBuilt = false;
|
atlas->TexIsBuilt = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3717,7 +3717,7 @@ IMGUI_API ImVec2i ImFontAtlasBuildGetTextureSizeEstimate(ImFontAtlas*
|
|||||||
|
|
||||||
IMGUI_API bool ImFontAtlasBuildAddFont(ImFontAtlas* atlas, ImFontConfig* src);
|
IMGUI_API bool ImFontAtlasBuildAddFont(ImFontAtlas* atlas, ImFontConfig* src);
|
||||||
IMGUI_API ImFontGlyph* ImFontAtlasBuildAddFontGlyph(ImFontAtlas* atlas, ImFont* font, ImFontConfig* src, const ImFontGlyph* in_glyph);
|
IMGUI_API ImFontGlyph* ImFontAtlasBuildAddFontGlyph(ImFontAtlas* atlas, ImFont* font, ImFontConfig* src, const ImFontGlyph* in_glyph);
|
||||||
IMGUI_API void ImFontAtlasBuildSetupFontSpecialGlyphs(ImFontAtlas* atlas, ImFontConfig* src);
|
IMGUI_API void ImFontAtlasBuildSetupFontSpecialGlyphs(ImFontAtlas* atlas, ImFont* font, ImFontConfig* src);
|
||||||
IMGUI_API void ImFontAtlasBuildDiscardFontGlyph(ImFontAtlas* atlas, ImFont* font, ImFontGlyph* glyph);
|
IMGUI_API void ImFontAtlasBuildDiscardFontGlyph(ImFontAtlas* atlas, ImFont* font, ImFontGlyph* glyph);
|
||||||
IMGUI_API void ImFontAtlasBuildDiscardFontGlyphs(ImFontAtlas* atlas, ImFont* font);
|
IMGUI_API void ImFontAtlasBuildDiscardFontGlyphs(ImFontAtlas* atlas, ImFont* font);
|
||||||
IMGUI_API void ImFontAtlasBuildReloadFont(ImFontAtlas* atlas, ImFont* font); // <--- Your future new best friend!
|
IMGUI_API void ImFontAtlasBuildReloadFont(ImFontAtlas* atlas, ImFont* font); // <--- Your future new best friend!
|
||||||
|
Reference in New Issue
Block a user