mirror of
https://github.com/ocornut/imgui.git
synced 2026-01-09 23:54:20 +00:00
Fonts: remove ImFontHooks in favor of a AddRemapChar() implementation.
This commit is contained in:
parent
89e880dfd1
commit
f6735c223c
3 changed files with 12 additions and 39 deletions
6
imgui.h
6
imgui.h
|
|
@ -177,7 +177,6 @@ struct ImFontBaked; // Baked data for a ImFont at a given size.
|
|||
struct ImFontConfig; // Configuration data when adding a font or merging fonts
|
||||
struct ImFontGlyph; // A single font glyph (code point + coordinates within in ImFontAtlas + offset)
|
||||
struct ImFontGlyphRangesBuilder; // Helper to build glyph ranges from text/string data
|
||||
struct ImFontHooks; // Opaque interface to font hooks
|
||||
struct ImFontLoader; // Opaque interface to a font loading backend (stb_truetype, FreeType etc.).
|
||||
struct ImTextureData; // Specs and pixel storage for a texture used by Dear ImGui.
|
||||
struct ImTextureRect; // Coordinates of a rectangle within a texture.
|
||||
|
|
@ -3683,7 +3682,6 @@ struct ImFontAtlas
|
|||
const ImFontLoader* FontLoader; // Font loader opaque interface (default to stb_truetype, can be changed to use FreeType by defining IMGUI_ENABLE_FREETYPE). Don't set directly!
|
||||
const char* FontLoaderName; // Font loader name (for display e.g. in About box) == FontLoader->Name
|
||||
void* FontLoaderData; // Font backend opaque storage
|
||||
const ImFontHooks* FontHooks; // Shared font hooks for all fonts.
|
||||
unsigned int FontBuilderFlags; // [FIXME: Should be called FontLoaderFlags] Shared flags (for all fonts) for font loader. THIS IS BUILD IMPLEMENTATION DEPENDENT (e.g. . Per-font override is also available in ImFontConfig.
|
||||
int RefCount; // Number of contexts using this atlas
|
||||
|
||||
|
|
@ -3771,7 +3769,7 @@ struct ImFont
|
|||
float Scale; // 4 // in // Base font scale (~1.0f), multiplied by the per-window font scale which you can adjust with SetWindowFontScale()
|
||||
ImU8 Used8kPagesMap[(IM_UNICODE_CODEPOINT_MAX+1)/8192/8]; // 1 bytes if ImWchar=ImWchar16, 16 bytes if ImWchar==ImWchar32. Store 1-bit for each block of 4K codepoints that has one active glyph. This is mainly used to facilitate iterations across all used codepoints.
|
||||
bool EllipsisAutoBake; // 1 // // Mark when the "..." glyph needs to be generated.
|
||||
const ImFontHooks* FontHooks; // 8 // in // Custom font hooks for the font.
|
||||
ImGuiStorage RemapPairs; // 16 // // Remapping pairs when using AddRemapChar(), otherwise empty.
|
||||
|
||||
// Methods
|
||||
IMGUI_API ImFont();
|
||||
|
|
@ -3794,7 +3792,7 @@ struct ImFont
|
|||
|
||||
// [Internal] Don't use!
|
||||
IMGUI_API void ClearOutputData();
|
||||
IMGUI_API void AddRemapChar(ImWchar from_codepoint, ImWchar to_codepoint, bool overwrite_dst);// , bool overwrite_dst = true); // Makes 'dst' character/glyph points to 'src' character/glyph. Currently needs to be called AFTER fonts have been built.
|
||||
IMGUI_API void AddRemapChar(ImWchar from_codepoint, ImWchar to_codepoint); // Makes 'from_codepoint' character points to 'to_codepoint' glyph.
|
||||
IMGUI_API bool IsGlyphRangeUnused(unsigned int c_begin, unsigned int c_last);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -4365,12 +4365,11 @@ static void ImFontBaked_BuildGrowIndex(ImFontBaked* baked, int new_size)
|
|||
baked->IndexLookup.resize(new_size, IM_FONTGLYPH_INDEX_UNUSED);
|
||||
}
|
||||
|
||||
static void ImFont_FontHookRemapCodepoint(ImFontAtlas* atlas, ImFont* font, ImWchar* c)
|
||||
static void ImFontAtlas_FontHookRemapCodepoint(ImFontAtlas* atlas, ImFont* font, ImWchar* c)
|
||||
{
|
||||
if (font->FontHooks && font->FontHooks->FontHookRemapCodepoint != NULL)
|
||||
font->FontHooks->FontHookRemapCodepoint(atlas, font, c);
|
||||
else if (atlas->FontHooks && atlas->FontHooks->FontHookRemapCodepoint != NULL)
|
||||
atlas->FontHooks->FontHookRemapCodepoint(atlas, font, c);
|
||||
IM_UNUSED(atlas);
|
||||
if (font->RemapPairs.Data.Size != 0)
|
||||
*c = (ImWchar)font->RemapPairs.GetInt((ImGuiID)*c, (int)*c);
|
||||
}
|
||||
|
||||
static ImFontGlyph* ImFontBaked_BuildLoadGlyph(ImFontBaked* baked, ImWchar codepoint)
|
||||
|
|
@ -4387,7 +4386,7 @@ static ImFontGlyph* ImFontBaked_BuildLoadGlyph(ImFontBaked* baked, ImWchar codep
|
|||
|
||||
// User remapping hooks
|
||||
ImWchar src_codepoint = codepoint;
|
||||
ImFont_FontHookRemapCodepoint(atlas, font, &codepoint);
|
||||
ImFontAtlas_FontHookRemapCodepoint(atlas, font, &codepoint);
|
||||
|
||||
//char utf8_buf[5];
|
||||
//IMGUI_DEBUG_LOG("[font] BuildLoadGlyph U+%04X (%s)\n", (unsigned int)codepoint, ImTextCharToUtf8(utf8_buf, (unsigned int)codepoint));
|
||||
|
|
@ -5092,25 +5091,9 @@ void ImFontAtlasBakedSetFontGlyphBitmap(ImFontAtlas* atlas, ImFontBaked* baked,
|
|||
ImFontAtlasTextureBlockQueueUpload(atlas, tex, r->x, r->y, r->w, r->h);
|
||||
}
|
||||
|
||||
// FIXME: Use ImFontHooks::FontHookRemapCodepoint() hooks.
|
||||
void ImFont::AddRemapChar(ImWchar from_codepoint, ImWchar to_codepoint, bool overwrite_dst)
|
||||
void ImFont::AddRemapChar(ImWchar from_codepoint, ImWchar to_codepoint)
|
||||
{
|
||||
IM_UNUSED(from_codepoint);
|
||||
IM_UNUSED(to_codepoint);
|
||||
IM_UNUSED(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.
|
||||
unsigned int index_size = (unsigned int)IndexLookup.Size;
|
||||
|
||||
if (from_codepoint < index_size && IndexLookup.Data[from_codepoint] == (ImU16)-1 && !overwrite_dst) // 'from_codepoint' already exists
|
||||
return;
|
||||
if (to_codepoint >= index_size && from_codepoint >= index_size) // both 'from_codepoint' and 'to_codepoint' don't exist -> no-op
|
||||
return;
|
||||
|
||||
BuildGrowIndex(from_codepoint + 1);
|
||||
IndexLookup[from_codepoint] = (to_codepoint < index_size) ? IndexLookup.Data[to_codepoint] : (ImU16)-1;
|
||||
IndexAdvanceX[from_codepoint] = (to_codepoint < index_size) ? IndexAdvanceX.Data[to_codepoint] : 1.0f;
|
||||
*/
|
||||
RemapPairs.SetInt((ImGuiID)from_codepoint, (int)to_codepoint);
|
||||
}
|
||||
|
||||
// Find glyph, load if necessary, return fallback if missing
|
||||
|
|
@ -5162,7 +5145,7 @@ bool ImFontBaked::IsGlyphLoaded(ImWchar c)
|
|||
bool ImFont::IsGlyphInFont(ImWchar c)
|
||||
{
|
||||
ImFontAtlas* atlas = ContainerAtlas;
|
||||
ImFont_FontHookRemapCodepoint(atlas, this, &c);
|
||||
ImFontAtlas_FontHookRemapCodepoint(atlas, this, &c);
|
||||
for (ImFontConfig* src : Sources)
|
||||
{
|
||||
const ImFontLoader* loader = src->FontLoader ? src->FontLoader : atlas->FontLoader;
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ Index of this file:
|
|||
// [SECTION] Tab bar, Tab item support
|
||||
// [SECTION] Table support
|
||||
// [SECTION] ImGui internal API
|
||||
// [SECTION] ImFontLoader, ImFontHooks
|
||||
// [SECTION] ImFontLoader
|
||||
// [SECTION] ImFontAtlas internal API
|
||||
// [SECTION] Test Engine specific hooks (imgui_test_engine)
|
||||
|
||||
|
|
@ -3664,7 +3664,7 @@ namespace ImGui
|
|||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// [SECTION] ImFontLoader, ImFontHooks
|
||||
// [SECTION] ImFontLoader
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Hooks and storage for a given font backend.
|
||||
|
|
@ -3693,14 +3693,6 @@ struct ImFontLoader
|
|||
IMGUI_API const ImFontLoader* ImFontAtlasGetFontLoaderForStbTruetype();
|
||||
#endif
|
||||
|
||||
// User hooks
|
||||
// Conceptually this could be public, but API is still going to be evolve.
|
||||
struct ImFontHooks
|
||||
{
|
||||
// Modify codepoint to map to another value.
|
||||
void (*FontHookRemapCodepoint)(ImFontAtlas* atlas, ImFont* font, ImWchar* io_codepoint);
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// [SECTION] ImFontAtlas internal API
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue