mirror of
https://github.com/ocornut/imgui.git
synced 2025-11-03 17:24:24 +00:00
Fonts: ImFontConfig::GlyphExcludeRanges is owner and copied.
This commit is contained in:
@@ -2011,6 +2011,12 @@ char* ImStrdup(const char* str)
|
|||||||
return (char*)memcpy(buf, (const void*)str, len + 1);
|
return (char*)memcpy(buf, (const void*)str, len + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void* ImMemdup(const void* src, size_t size)
|
||||||
|
{
|
||||||
|
void* dst = IM_ALLOC(size);
|
||||||
|
return memcpy(dst, src, size);
|
||||||
|
}
|
||||||
|
|
||||||
char* ImStrdupcpy(char* dst, size_t* p_dst_size, const char* src)
|
char* ImStrdupcpy(char* dst, size_t* p_dst_size, const char* src)
|
||||||
{
|
{
|
||||||
size_t dst_buf_size = p_dst_size ? *p_dst_size : ImStrlen(dst) + 1;
|
size_t dst_buf_size = p_dst_size ? *p_dst_size : ImStrlen(dst) + 1;
|
||||||
|
|||||||
2
imgui.h
2
imgui.h
@@ -3434,7 +3434,7 @@ struct ImFontConfig
|
|||||||
//ImVec2 GlyphExtraSpacing; // 0, 0 // (REMOVED AT IT SEEMS LARGELY OBSOLETE. PLEASE REPORT IF YOU WERE USING THIS). Extra spacing (in pixels) between glyphs when rendered: essentially add to glyph->AdvanceX. Only X axis is supported for now.
|
//ImVec2 GlyphExtraSpacing; // 0, 0 // (REMOVED AT IT SEEMS LARGELY OBSOLETE. PLEASE REPORT IF YOU WERE USING THIS). Extra spacing (in pixels) between glyphs when rendered: essentially add to glyph->AdvanceX. Only X axis is supported for now.
|
||||||
ImVec2 GlyphOffset; // 0, 0 // Offset (in pixels) all glyphs from this font input. Absolute value for default size, other sizes will scale this value.
|
ImVec2 GlyphOffset; // 0, 0 // Offset (in pixels) all glyphs from this font input. Absolute value for default size, other sizes will scale this value.
|
||||||
const ImWchar* GlyphRanges; // NULL // THE ARRAY DATA NEEDS TO PERSIST AS LONG AS THE FONT IS ALIVE. Pointer to a user-provided list of Unicode range (2 value per range, values are inclusive, zero-terminated list).
|
const ImWchar* GlyphRanges; // NULL // THE ARRAY DATA NEEDS TO PERSIST AS LONG AS THE FONT IS ALIVE. Pointer to a user-provided list of Unicode range (2 value per range, values are inclusive, zero-terminated list).
|
||||||
const ImWchar* GlyphExcludeRanges; // NULL // THE ARRAY DATA NEEDS TO PERSIST AS LONG AS THE FONT IS ALIVE. Pointer to a VERY SHORT user-provided list of Unicode range (2 value per range, values are inclusive, zero-terminated list). This is very close to GlyphRanges[] but designed to exclude ranges from a font source, when merging fonts with overlapping glyphs.
|
const ImWchar* GlyphExcludeRanges; // NULL // Pointer to a VERY SHORT user-provided list of Unicode range (2 value per range, values are inclusive, zero-terminated list). This is very close to GlyphRanges[] but designed to exclude ranges from a font source, when merging fonts with overlapping glyphs.
|
||||||
float GlyphMinAdvanceX; // 0 // Minimum AdvanceX for glyphs, set Min to align font icons, set both Min/Max to enforce mono-space font. Absolute value for default size, other sizes will scale this value.
|
float GlyphMinAdvanceX; // 0 // Minimum AdvanceX for glyphs, set Min to align font icons, set both Min/Max to enforce mono-space font. Absolute value for default size, other sizes will scale this value.
|
||||||
float GlyphMaxAdvanceX; // FLT_MAX // Maximum AdvanceX for glyphs
|
float GlyphMaxAdvanceX; // FLT_MAX // Maximum AdvanceX for glyphs
|
||||||
float GlyphExtraAdvanceX; // 0 // Extra spacing (in pixels) between glyphs. Please contact us if you are using this.
|
float GlyphExtraAdvanceX; // 0 // Extra spacing (in pixels) between glyphs. Please contact us if you are using this.
|
||||||
|
|||||||
@@ -2644,11 +2644,7 @@ void ImFontAtlas::ClearInputData()
|
|||||||
const ImFontLoader* loader = font_cfg.FontLoader ? font_cfg.FontLoader : FontLoader;
|
const ImFontLoader* loader = font_cfg.FontLoader ? font_cfg.FontLoader : FontLoader;
|
||||||
if (loader && loader->FontSrcDestroy != NULL)
|
if (loader && loader->FontSrcDestroy != NULL)
|
||||||
loader->FontSrcDestroy(this, &font_cfg);
|
loader->FontSrcDestroy(this, &font_cfg);
|
||||||
if (font_cfg.FontData && font_cfg.FontDataOwnedByAtlas)
|
ImFontAtlasBuildDiscardFontSource(this, &font_cfg);
|
||||||
{
|
|
||||||
IM_FREE(font_cfg.FontData);
|
|
||||||
font_cfg.FontData = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// When clearing this we lose access to the font name and other information used to build the font.
|
// When clearing this we lose access to the font name and other information used to build the font.
|
||||||
@@ -2969,6 +2965,17 @@ bool ImFontAtlas::Build()
|
|||||||
}
|
}
|
||||||
#endif // #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
#endif // #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||||
|
|
||||||
|
void ImFontAtlasBuildDiscardFontSource(ImFontAtlas* atlas, ImFontConfig* src)
|
||||||
|
{
|
||||||
|
IM_UNUSED(atlas);
|
||||||
|
if (src->FontDataOwnedByAtlas)
|
||||||
|
IM_FREE(src->FontData);
|
||||||
|
if (src->GlyphExcludeRanges)
|
||||||
|
IM_FREE((void*)src->GlyphExcludeRanges);
|
||||||
|
src->FontData = NULL;
|
||||||
|
src->GlyphExcludeRanges = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
ImFont* ImFontAtlas::AddFont(const ImFontConfig* font_cfg)
|
ImFont* ImFontAtlas::AddFont(const ImFontConfig* font_cfg)
|
||||||
{
|
{
|
||||||
IM_ASSERT(!Locked && "Cannot modify a locked ImFontAtlas!");
|
IM_ASSERT(!Locked && "Cannot modify a locked ImFontAtlas!");
|
||||||
@@ -3001,9 +3008,8 @@ ImFont* ImFontAtlas::AddFont(const ImFontConfig* font_cfg)
|
|||||||
new_font_cfg.DstFont = font;
|
new_font_cfg.DstFont = font;
|
||||||
if (!new_font_cfg.FontDataOwnedByAtlas)
|
if (!new_font_cfg.FontDataOwnedByAtlas)
|
||||||
{
|
{
|
||||||
new_font_cfg.FontData = IM_ALLOC(new_font_cfg.FontDataSize);
|
|
||||||
new_font_cfg.FontDataOwnedByAtlas = true;
|
new_font_cfg.FontDataOwnedByAtlas = true;
|
||||||
memcpy(new_font_cfg.FontData, font_cfg->FontData, (size_t)new_font_cfg.FontDataSize);
|
new_font_cfg.FontData = ImMemdup(font_cfg->FontData, (size_t)new_font_cfg.FontDataSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sanity check
|
// Sanity check
|
||||||
@@ -3013,6 +3019,7 @@ ImFont* ImFontAtlas::AddFont(const ImFontConfig* font_cfg)
|
|||||||
for (const ImWchar* p = font_cfg->GlyphExcludeRanges; p[0] != 0; p++, size++) {}
|
for (const ImWchar* p = font_cfg->GlyphExcludeRanges; p[0] != 0; p++, size++) {}
|
||||||
IM_ASSERT((size & 1) == 0 && "GlyphExcludeRanges[] size must be multiple of two!");
|
IM_ASSERT((size & 1) == 0 && "GlyphExcludeRanges[] size must be multiple of two!");
|
||||||
IM_ASSERT((size <= 64) && "GlyphExcludeRanges[] size must be small!");
|
IM_ASSERT((size <= 64) && "GlyphExcludeRanges[] size must be small!");
|
||||||
|
new_font_cfg.GlyphExcludeRanges = (ImWchar*)ImMemdup(font_cfg->GlyphExcludeRanges, sizeof(font_cfg->GlyphExcludeRanges[0]) * (size + 1));
|
||||||
}
|
}
|
||||||
if (font_cfg->FontLoader != NULL)
|
if (font_cfg->FontLoader != NULL)
|
||||||
IM_ASSERT(font_cfg->FontLoader->FontBakedLoadGlyph != NULL);
|
IM_ASSERT(font_cfg->FontLoader->FontBakedLoadGlyph != NULL);
|
||||||
@@ -3029,8 +3036,7 @@ ImFont* ImFontAtlas::AddFont(const ImFontConfig* font_cfg)
|
|||||||
if (!ImFontAtlasBuildAddFont(this, &new_font_cfg))
|
if (!ImFontAtlasBuildAddFont(this, &new_font_cfg))
|
||||||
{
|
{
|
||||||
// Rollback (this is a fragile/rarely exercised code-path. TestSuite's "misc_atlas_add_invalid_font" aim to test this)
|
// Rollback (this is a fragile/rarely exercised code-path. TestSuite's "misc_atlas_add_invalid_font" aim to test this)
|
||||||
if (new_font_cfg.FontDataOwnedByAtlas)
|
ImFontAtlasBuildDiscardFontSource(this, &new_font_cfg);
|
||||||
IM_FREE(new_font_cfg.FontData);
|
|
||||||
Sources.pop_back();
|
Sources.pop_back();
|
||||||
if (!font_cfg->MergeMode)
|
if (!font_cfg->MergeMode)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -389,6 +389,7 @@ IMGUI_API int ImStricmp(const char* str1, const char* str2);
|
|||||||
IMGUI_API int ImStrnicmp(const char* str1, const char* str2, size_t count); // Case insensitive compare to a certain count.
|
IMGUI_API int ImStrnicmp(const char* str1, const char* str2, size_t count); // Case insensitive compare to a certain count.
|
||||||
IMGUI_API void ImStrncpy(char* dst, const char* src, size_t count); // Copy to a certain count and always zero terminate (strncpy doesn't).
|
IMGUI_API void ImStrncpy(char* dst, const char* src, size_t count); // Copy to a certain count and always zero terminate (strncpy doesn't).
|
||||||
IMGUI_API char* ImStrdup(const char* str); // Duplicate a string.
|
IMGUI_API char* ImStrdup(const char* str); // Duplicate a string.
|
||||||
|
IMGUI_API void* ImMemdup(const void* src, size_t size); // Duplicate a chunk of memory.
|
||||||
IMGUI_API char* ImStrdupcpy(char* dst, size_t* p_dst_size, const char* str); // Copy in provided buffer, recreate buffer if needed.
|
IMGUI_API char* ImStrdupcpy(char* dst, size_t* p_dst_size, const char* str); // Copy in provided buffer, recreate buffer if needed.
|
||||||
IMGUI_API const char* ImStrchrRange(const char* str_begin, const char* str_end, char c); // Find first occurrence of 'c' in string range.
|
IMGUI_API const char* ImStrchrRange(const char* str_begin, const char* str_end, char c); // Find first occurrence of 'c' in string range.
|
||||||
IMGUI_API const char* ImStreolRange(const char* str, const char* str_end); // End end-of-line
|
IMGUI_API const char* ImStreolRange(const char* str, const char* str_end); // End end-of-line
|
||||||
@@ -3778,6 +3779,7 @@ IMGUI_API bool ImFontAtlasBuildAddFont(ImFontAtlas* atlas, ImFontCo
|
|||||||
IMGUI_API void ImFontAtlasBuildSetupFontSpecialGlyphs(ImFontAtlas* atlas, ImFont* font, ImFontConfig* src);
|
IMGUI_API void ImFontAtlasBuildSetupFontSpecialGlyphs(ImFontAtlas* atlas, ImFont* font, ImFontConfig* src);
|
||||||
IMGUI_API void ImFontAtlasBuildDiscardBakes(ImFontAtlas* atlas, int unused_frames);
|
IMGUI_API void ImFontAtlasBuildDiscardBakes(ImFontAtlas* atlas, int unused_frames);
|
||||||
IMGUI_API void ImFontAtlasBuildDiscardFont(ImFontAtlas* atlas, ImFont* font);
|
IMGUI_API void ImFontAtlasBuildDiscardFont(ImFontAtlas* atlas, ImFont* font);
|
||||||
|
IMGUI_API void ImFontAtlasBuildDiscardFontSource(ImFontAtlas* atlas, ImFontConfig* src);
|
||||||
IMGUI_API ImFontBaked* ImFontAtlasBuildAddFontBaked(ImFontAtlas* atlas, ImFont* font, float font_size, ImGuiID baked_id);
|
IMGUI_API ImFontBaked* ImFontAtlasBuildAddFontBaked(ImFontAtlas* atlas, ImFont* font, float font_size, ImGuiID baked_id);
|
||||||
IMGUI_API ImFontBaked* ImFontAtlasBuildGetClosestFontBakedMatch(ImFontAtlas* atlas, ImFont* font, float font_size);
|
IMGUI_API ImFontBaked* ImFontAtlasBuildGetClosestFontBakedMatch(ImFontAtlas* atlas, ImFont* font, float font_size);
|
||||||
IMGUI_API void ImFontAtlasBuildDiscardFontBaked(ImFontAtlas* atlas, ImFont* font, ImFontBaked* baked);
|
IMGUI_API void ImFontAtlasBuildDiscardFontBaked(ImFontAtlas* atlas, ImFont* font, ImFontBaked* baked);
|
||||||
|
|||||||
Reference in New Issue
Block a user