Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
ImFont Struct Reference

#include <src/imgui/imgui.h>

+ Collaboration diagram for ImFont:

Public Member Functions

IMGUI_API ImFont ()
 
IMGUI_API ~ImFont ()
 
IMGUI_API const ImFontGlyphFindGlyph (ImWchar c) const
 
IMGUI_API const ImFontGlyphFindGlyphNoFallback (ImWchar c) const
 
float GetCharAdvance (ImWchar c) const
 
bool IsLoaded () const
 
const char * GetDebugName () const
 
IMGUI_API ImVec2 CalcTextSizeA (float size, float max_width, float wrap_width, const char *text_begin, const char *text_end=NULL, const char **remaining=NULL) const
 
IMGUI_API const char * CalcWordWrapPositionA (float scale, const char *text, const char *text_end, float wrap_width) const
 
IMGUI_API void RenderChar (ImDrawList *draw_list, float size, ImVec2 pos, ImU32 col, ImWchar c) const
 
IMGUI_API void RenderText (ImDrawList *draw_list, float size, ImVec2 pos, ImU32 col, const ImVec4 &clip_rect, const char *text_begin, const char *text_end, float wrap_width=0.0f, bool cpu_fine_clip=false) const
 
IMGUI_API void BuildLookupTable ()
 
IMGUI_API void ClearOutputData ()
 
IMGUI_API void GrowIndex (int new_size)
 
IMGUI_API void AddGlyph (const ImFontConfig *src_cfg, ImWchar c, float x0, float y0, float x1, float y1, float u0, float v0, float u1, float v1, float advance_x)
 
IMGUI_API void AddRemapChar (ImWchar dst, ImWchar src, bool overwrite_dst=true)
 
IMGUI_API void SetGlyphVisible (ImWchar c, bool visible)
 
IMGUI_API void SetFallbackChar (ImWchar c)
 
IMGUI_API bool IsGlyphRangeUnused (unsigned int c_begin, unsigned int c_last)
 

Public Attributes

ImVector< float > IndexAdvanceX
 
float FallbackAdvanceX
 
float FontSize
 
ImVector< ImWcharIndexLookup
 
ImVector< ImFontGlyphGlyphs
 
const ImFontGlyphFallbackGlyph
 
ImFontAtlasContainerAtlas
 
const ImFontConfigConfigData
 
short ConfigDataCount
 
ImWchar FallbackChar
 
ImWchar EllipsisChar
 
bool DirtyLookupTables
 
float Scale
 
float Ascent
 
float Descent
 
int MetricsTotalSurface
 
ImU8 Used4kPagesMap [(IM_UNICODE_CODEPOINT_MAX+1)/4096/8]
 

Detailed Description

Constructor & Destructor Documentation

◆ ImFont()

ImFont::ImFont ( )
3102{
3103 FontSize = 0.0f;
3104 FallbackAdvanceX = 0.0f;
3105 FallbackChar = (ImWchar)'?';
3106 EllipsisChar = (ImWchar)-1;
3107 FallbackGlyph = NULL;
3108 ContainerAtlas = NULL;
3109 ConfigData = NULL;
3110 ConfigDataCount = 0;
3111 DirtyLookupTables = false;
3112 Scale = 1.0f;
3113 Ascent = Descent = 0.0f;
3115 memset(Used4kPagesMap, 0, sizeof(Used4kPagesMap));
3116}
ImWchar16 ImWchar
Definition imgui.h:220
const ImFontGlyph * FallbackGlyph
Definition imgui.h:2699
bool DirtyLookupTables
Definition imgui.h:2707
float FontSize
Definition imgui.h:2694
short ConfigDataCount
Definition imgui.h:2704
ImWchar EllipsisChar
Definition imgui.h:2706
float Ascent
Definition imgui.h:2709
int MetricsTotalSurface
Definition imgui.h:2710
ImFontAtlas * ContainerAtlas
Definition imgui.h:2702
ImU8 Used4kPagesMap[(IM_UNICODE_CODEPOINT_MAX+1)/4096/8]
Definition imgui.h:2711
float Descent
Definition imgui.h:2709
float FallbackAdvanceX
Definition imgui.h:2693
ImWchar FallbackChar
Definition imgui.h:2705
float Scale
Definition imgui.h:2708
const ImFontConfig * ConfigData
Definition imgui.h:2703

References Ascent, ConfigData, ConfigDataCount, ContainerAtlas, Descent, DirtyLookupTables, EllipsisChar, FallbackAdvanceX, FallbackChar, FallbackGlyph, FontSize, MetricsTotalSurface, Scale, and Used4kPagesMap.

◆ ~ImFont()

ImFont::~ImFont ( )
3119{
3121}
IMGUI_API void ClearOutputData()
Definition imgui_draw.cpp:3123

References ClearOutputData().

+ Here is the call graph for this function:

Member Function Documentation

◆ AddGlyph()

void ImFont::AddGlyph ( const ImFontConfig src_cfg,
ImWchar  c,
float  x0,
float  y0,
float  x1,
float  y1,
float  u0,
float  v0,
float  u1,
float  v1,
float  advance_x 
)
3225{
3226 if (cfg != NULL)
3227 {
3228 // Clamp & recenter if needed
3229 const float advance_x_original = advance_x;
3230 advance_x = ImClamp(advance_x, cfg->GlyphMinAdvanceX, cfg->GlyphMaxAdvanceX);
3231 if (advance_x != advance_x_original)
3232 {
3233 float char_off_x = cfg->PixelSnapH ? ImFloor((advance_x - advance_x_original) * 0.5f) : (advance_x - advance_x_original) * 0.5f;
3234 x0 += char_off_x;
3235 x1 += char_off_x;
3236 }
3237
3238 // Snap to pixel
3239 if (cfg->PixelSnapH)
3240 advance_x = IM_ROUND(advance_x);
3241
3242 // Bake spacing
3243 advance_x += cfg->GlyphExtraSpacing.x;
3244 }
3245
3246 Glyphs.resize(Glyphs.Size + 1);
3247 ImFontGlyph& glyph = Glyphs.back();
3248 glyph.Codepoint = (unsigned int)codepoint;
3249 glyph.Visible = (x0 != x1) && (y0 != y1);
3250 glyph.Colored = false;
3251 glyph.X0 = x0;
3252 glyph.Y0 = y0;
3253 glyph.X1 = x1;
3254 glyph.Y1 = y1;
3255 glyph.U0 = u0;
3256 glyph.V0 = v0;
3257 glyph.U1 = u1;
3258 glyph.V1 = v1;
3259 glyph.AdvanceX = advance_x;
3260
3261 // Compute rough surface usage metrics (+1 to account for average padding, +0.99 to round)
3262 // We use (U1-U0)*TexWidth instead of X1-X0 to account for oversampling.
3263 float pad = ContainerAtlas->TexGlyphPadding + 0.99f;
3264 DirtyLookupTables = true;
3265 MetricsTotalSurface += (int)((glyph.U1 - glyph.U0) * ContainerAtlas->TexWidth + pad) * (int)((glyph.V1 - glyph.V0) * ContainerAtlas->TexHeight + pad);
3266}
float AdvanceX
Definition imgui.h:2528
float X1
Definition imgui.h:2529
float X0
Definition imgui.h:2529
unsigned int Codepoint
Definition imgui.h:2527
float V0
Definition imgui.h:2530
float U0
Definition imgui.h:2530
float V1
Definition imgui.h:2530
unsigned int Visible
Definition imgui.h:2526
unsigned int Colored
Definition imgui.h:2525
float Y1
Definition imgui.h:2529
float U1
Definition imgui.h:2530
float Y0
Definition imgui.h:2529
Definition imgui.h:2524
static float ImFloor(float f)
Definition imgui_internal.h:427
static T ImClamp(T v, T mn, T mx)
Definition imgui_internal.h:411
#define IM_ROUND(_VAL)
Definition imgui_internal.h:233
int TexWidth
Definition imgui.h:2664
int TexGlyphPadding
Definition imgui.h:2656
int TexHeight
Definition imgui.h:2665
ImVector< ImFontGlyph > Glyphs
Definition imgui.h:2698
T & back()
Definition imgui.h:1685
int Size
Definition imgui.h:1655
void resize(int new_size)
Definition imgui.h:1690

References ImFontGlyph::AdvanceX, ImVector< T >::back(), ImFontGlyph::Codepoint, ImFontGlyph::Colored, ContainerAtlas, DirtyLookupTables, ImFontConfig::GlyphExtraSpacing, ImFontConfig::GlyphMaxAdvanceX, ImFontConfig::GlyphMinAdvanceX, Glyphs, IM_ROUND, ImClamp(), ImFloor(), MetricsTotalSurface, ImFontConfig::PixelSnapH, ImVector< T >::resize(), ImVector< T >::Size, ImFontAtlas::TexGlyphPadding, ImFontAtlas::TexHeight, ImFontAtlas::TexWidth, ImFontGlyph::U0, ImFontGlyph::U1, ImFontGlyph::V0, ImFontGlyph::V1, ImFontGlyph::Visible, ImVec2::x, ImFontGlyph::X0, ImFontGlyph::X1, ImFontGlyph::Y0, and ImFontGlyph::Y1.

Referenced by ImFontAtlasBuildFinish(), and ImFontAtlasBuildWithStbTruetype().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AddRemapChar()

void ImFont::AddRemapChar ( ImWchar  dst,
ImWchar  src,
bool  overwrite_dst = true 
)
3269{
3270 IM_ASSERT(IndexLookup.Size > 0); // Currently this can only be called AFTER the font has been built, aka after calling ImFontAtlas::GetTexDataAs*() function.
3271 unsigned int index_size = (unsigned int)IndexLookup.Size;
3272
3273 if (dst < index_size && IndexLookup.Data[dst] == (ImWchar)-1 && !overwrite_dst) // 'dst' already exists
3274 return;
3275 if (src >= index_size && dst >= index_size) // both 'dst' and 'src' don't exist -> no-op
3276 return;
3277
3278 GrowIndex(dst + 1);
3279 IndexLookup[dst] = (src < index_size) ? IndexLookup.Data[src] : (ImWchar)-1;
3280 IndexAdvanceX[dst] = (src < index_size) ? IndexAdvanceX.Data[src] : 1.0f;
3281}
#define IM_ASSERT(_EXPR)
Definition imgui.h:81
ImVector< ImWchar > IndexLookup
Definition imgui.h:2697
IMGUI_API void GrowIndex(int new_size)
Definition imgui_draw.cpp:3212
ImVector< float > IndexAdvanceX
Definition imgui.h:2692
T * Data
Definition imgui.h:1657

References ImVector< T >::Data, GrowIndex(), IM_ASSERT, IndexAdvanceX, IndexLookup, and ImVector< T >::Size.

+ Here is the call graph for this function:

◆ BuildLookupTable()

void ImFont::BuildLookupTable ( )
3138{
3139 int max_codepoint = 0;
3140 for (int i = 0; i != Glyphs.Size; i++)
3141 max_codepoint = ImMax(max_codepoint, (int)Glyphs[i].Codepoint);
3142
3143 // Build lookup table
3144 IM_ASSERT(Glyphs.Size < 0xFFFF); // -1 is reserved
3147 DirtyLookupTables = false;
3148 memset(Used4kPagesMap, 0, sizeof(Used4kPagesMap));
3149 GrowIndex(max_codepoint + 1);
3150 for (int i = 0; i < Glyphs.Size; i++)
3151 {
3152 int codepoint = (int)Glyphs[i].Codepoint;
3153 IndexAdvanceX[codepoint] = Glyphs[i].AdvanceX;
3154 IndexLookup[codepoint] = (ImWchar)i;
3155
3156 // Mark 4K page as used
3157 const int page_n = codepoint / 4096;
3158 Used4kPagesMap[page_n >> 3] |= 1 << (page_n & 7);
3159 }
3160
3161 // Create a glyph to handle TAB
3162 // FIXME: Needs proper TAB handling but it needs to be contextualized (or we could arbitrary say that each string starts at "column 0" ?)
3163 if (FindGlyph((ImWchar)' '))
3164 {
3165 if (Glyphs.back().Codepoint != '\t') // So we can call this function multiple times (FIXME: Flaky)
3166 Glyphs.resize(Glyphs.Size + 1);
3167 ImFontGlyph& tab_glyph = Glyphs.back();
3168 tab_glyph = *FindGlyph((ImWchar)' ');
3169 tab_glyph.Codepoint = '\t';
3170 tab_glyph.AdvanceX *= IM_TABSIZE;
3171 IndexAdvanceX[(int)tab_glyph.Codepoint] = (float)tab_glyph.AdvanceX;
3172 IndexLookup[(int)tab_glyph.Codepoint] = (ImWchar)(Glyphs.Size - 1);
3173 }
3174
3175 // Mark special glyphs as not visible (note that AddGlyph already mark as non-visible glyphs with zero-size polygons)
3176 SetGlyphVisible((ImWchar)' ', false);
3177 SetGlyphVisible((ImWchar)'\t', false);
3178
3179 // Setup fall-backs
3182 for (int i = 0; i < max_codepoint + 1; i++)
3183 if (IndexAdvanceX[i] < 0.0f)
3185}
static T ImMax(T lhs, T rhs)
Definition imgui_internal.h:410
#define IM_TABSIZE
Definition imgui_internal.h:228
IMGUI_API void SetGlyphVisible(ImWchar c, bool visible)
Definition imgui_draw.cpp:3200
IMGUI_API const ImFontGlyph * FindGlyphNoFallback(ImWchar c) const
Definition imgui_draw.cpp:3293
IMGUI_API const ImFontGlyph * FindGlyph(ImWchar c) const
Definition imgui_draw.cpp:3283
void clear()
Definition imgui.h:1678

References ImFontGlyph::AdvanceX, ImVector< T >::back(), ImVector< T >::clear(), ImFontGlyph::Codepoint, DirtyLookupTables, FallbackAdvanceX, FallbackChar, FallbackGlyph, FindGlyph(), FindGlyphNoFallback(), Glyphs, GrowIndex(), IM_ASSERT, IM_TABSIZE, ImMax(), IndexAdvanceX, IndexLookup, ImVector< T >::resize(), SetGlyphVisible(), ImVector< T >::Size, and Used4kPagesMap.

Referenced by SetFallbackChar().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CalcTextSizeA()

ImVec2 ImFont::CalcTextSizeA ( float  size,
float  max_width,
float  wrap_width,
const char *  text_begin,
const char *  text_end = NULL,
const char **  remaining = NULL 
) const
3403{
3404 if (!text_end)
3405 text_end = text_begin + strlen(text_begin); // FIXME-OPT: Need to avoid this.
3406
3407 const float line_height = size;
3408 const float scale = size / FontSize;
3409
3410 ImVec2 text_size = ImVec2(0, 0);
3411 float line_width = 0.0f;
3412
3413 const bool word_wrap_enabled = (wrap_width > 0.0f);
3414 const char* word_wrap_eol = NULL;
3415
3416 const char* s = text_begin;
3417 while (s < text_end)
3418 {
3419 if (word_wrap_enabled)
3420 {
3421 // Calculate how far we can render. Requires two passes on the string data but keeps the code simple and not intrusive for what's essentially an uncommon feature.
3422 if (!word_wrap_eol)
3423 {
3424 word_wrap_eol = CalcWordWrapPositionA(scale, s, text_end, wrap_width - line_width);
3425 if (word_wrap_eol == s) // Wrap_width is too small to fit anything. Force displaying 1 character to minimize the height discontinuity.
3426 word_wrap_eol++; // +1 may not be a character start point in UTF-8 but it's ok because we use s >= word_wrap_eol below
3427 }
3428
3429 if (s >= word_wrap_eol)
3430 {
3431 if (text_size.x < line_width)
3432 text_size.x = line_width;
3433 text_size.y += line_height;
3434 line_width = 0.0f;
3435 word_wrap_eol = NULL;
3436
3437 // Wrapping skips upcoming blanks
3438 while (s < text_end)
3439 {
3440 const char c = *s;
3441 if (ImCharIsBlankA(c)) { s++; } else if (c == '\n') { s++; break; } else { break; }
3442 }
3443 continue;
3444 }
3445 }
3446
3447 // Decode and advance source
3448 const char* prev_s = s;
3449 unsigned int c = (unsigned int)*s;
3450 if (c < 0x80)
3451 {
3452 s += 1;
3453 }
3454 else
3455 {
3456 s += ImTextCharFromUtf8(&c, s, text_end);
3457 if (c == 0) // Malformed UTF-8?
3458 break;
3459 }
3460
3461 if (c < 32)
3462 {
3463 if (c == '\n')
3464 {
3465 text_size.x = ImMax(text_size.x, line_width);
3466 text_size.y += line_height;
3467 line_width = 0.0f;
3468 continue;
3469 }
3470 if (c == '\r')
3471 continue;
3472 }
3473
3474 const float char_width = ((int)c < IndexAdvanceX.Size ? IndexAdvanceX.Data[c] : FallbackAdvanceX) * scale;
3475 if (line_width + char_width >= max_width)
3476 {
3477 s = prev_s;
3478 break;
3479 }
3480
3481 line_width += char_width;
3482 }
3483
3484 if (text_size.x < line_width)
3485 text_size.x = line_width;
3486
3487 if (line_width > 0 || text_size.y == 0.0f)
3488 text_size.y += line_height;
3489
3490 if (remaining)
3491 *remaining = s;
3492
3493 return text_size;
3494}
int scale(const int val)
Definition WipeTowerDialog.cpp:14
int ImTextCharFromUtf8(unsigned int *out_char, const char *in_text, const char *in_text_end)
Definition imgui.cpp:1619
static bool ImCharIsBlankA(char c)
Definition imgui_internal.h:321
constexpr auto size(const C &c) -> decltype(c.size())
Definition span.hpp:183
IMGUI_API const char * CalcWordWrapPositionA(float scale, const char *text, const char *text_end, float wrap_width) const
Definition imgui_draw.cpp:3303
Definition imgui.h:245
float y
Definition imgui.h:246
float x
Definition imgui.h:246

References CalcWordWrapPositionA(), ImVector< T >::Data, FallbackAdvanceX, FontSize, ImCharIsBlankA(), ImMax(), ImTextCharFromUtf8(), IndexAdvanceX, scale(), ImVector< T >::Size, ImVec2::x, and ImVec2::y.

Referenced by ImGui::CalcTextSize(), and ImGui::RenderTextEllipsis().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CalcWordWrapPositionA()

const char * ImFont::CalcWordWrapPositionA ( float  scale,
const char *  text,
const char *  text_end,
float  wrap_width 
) const
3304{
3305 // Simple word-wrapping for English, not full-featured. Please submit failing cases!
3306 // FIXME: Much possible improvements (don't cut things like "word !", "word!!!" but cut within "word,,,,", more sensible support for punctuations, support for Unicode punctuations, etc.)
3307
3308 // For references, possible wrap point marked with ^
3309 // "aaa bbb, ccc,ddd. eee fff. ggg!"
3310 // ^ ^ ^ ^ ^__ ^ ^
3311
3312 // List of hardcoded separators: .,;!?'"
3313
3314 // Skip extra blanks after a line returns (that includes not counting them in width computation)
3315 // e.g. "Hello world" --> "Hello" "World"
3316
3317 // Cut words that cannot possibly fit within one line.
3318 // e.g.: "The tropical fish" with ~5 characters worth of width --> "The tr" "opical" "fish"
3319
3320 float line_width = 0.0f;
3321 float word_width = 0.0f;
3322 float blank_width = 0.0f;
3323 wrap_width /= scale; // We work with unscaled widths to avoid scaling every characters
3324
3325 const char* word_end = text;
3326 const char* prev_word_end = NULL;
3327 bool inside_word = true;
3328
3329 const char* s = text;
3330 while (s < text_end)
3331 {
3332 unsigned int c = (unsigned int)*s;
3333 const char* next_s;
3334 if (c < 0x80)
3335 next_s = s + 1;
3336 else
3337 next_s = s + ImTextCharFromUtf8(&c, s, text_end);
3338 if (c == 0)
3339 break;
3340
3341 if (c < 32)
3342 {
3343 if (c == '\n')
3344 {
3345 line_width = word_width = blank_width = 0.0f;
3346 inside_word = true;
3347 s = next_s;
3348 continue;
3349 }
3350 if (c == '\r')
3351 {
3352 s = next_s;
3353 continue;
3354 }
3355 }
3356
3357 const float char_width = ((int)c < IndexAdvanceX.Size ? IndexAdvanceX.Data[c] : FallbackAdvanceX);
3358 if (ImCharIsBlankW(c))
3359 {
3360 if (inside_word)
3361 {
3362 line_width += blank_width;
3363 blank_width = 0.0f;
3364 word_end = s;
3365 }
3366 blank_width += char_width;
3367 inside_word = false;
3368 }
3369 else
3370 {
3371 word_width += char_width;
3372 if (inside_word)
3373 {
3374 word_end = next_s;
3375 }
3376 else
3377 {
3378 prev_word_end = word_end;
3379 line_width += word_width + blank_width;
3380 word_width = blank_width = 0.0f;
3381 }
3382
3383 // Allow wrapping after punctuation.
3384 inside_word = (c != '.' && c != ',' && c != ';' && c != '!' && c != '?' && c != '\"');
3385 }
3386
3387 // We ignore blank width at the end of the line (they can be skipped)
3388 if (line_width + word_width > wrap_width)
3389 {
3390 // Words that cannot possibly fit within an entire line will be cut anywhere.
3391 if (word_width < wrap_width)
3392 s = prev_word_end ? prev_word_end : word_end;
3393 break;
3394 }
3395
3396 s = next_s;
3397 }
3398
3399 return s;
3400}
static bool ImCharIsBlankW(unsigned int c)
Definition imgui_internal.h:322

References ImVector< T >::Data, FallbackAdvanceX, ImCharIsBlankW(), ImTextCharFromUtf8(), IndexAdvanceX, scale(), and ImVector< T >::Size.

Referenced by CalcTextSizeA(), and RenderText().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ClearOutputData()

void ImFont::ClearOutputData ( )
3124{
3125 FontSize = 0.0f;
3126 FallbackAdvanceX = 0.0f;
3127 Glyphs.clear();
3130 FallbackGlyph = NULL;
3131 ContainerAtlas = NULL;
3132 DirtyLookupTables = true;
3133 Ascent = Descent = 0.0f;
3135}

References Ascent, ImVector< T >::clear(), ContainerAtlas, Descent, DirtyLookupTables, FallbackAdvanceX, FallbackGlyph, FontSize, Glyphs, IndexAdvanceX, IndexLookup, and MetricsTotalSurface.

Referenced by ~ImFont(), and ImFontAtlasBuildSetupFont().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FindGlyph()

const ImFontGlyph * ImFont::FindGlyph ( ImWchar  c) const
3284{
3285 if (c >= (size_t)IndexLookup.Size)
3286 return FallbackGlyph;
3287 const ImWchar i = IndexLookup.Data[c];
3288 if (i == (ImWchar)-1)
3289 return FallbackGlyph;
3290 return &Glyphs.Data[i];
3291}

References ImVector< T >::Data, FallbackGlyph, Glyphs, IndexLookup, and ImVector< T >::Size.

Referenced by BuildLookupTable(), ImGui::InputTextEx(), RenderChar(), RenderText(), ImGui::RenderTextEllipsis(), and SetGlyphVisible().

+ Here is the caller graph for this function:

◆ FindGlyphNoFallback()

const ImFontGlyph * ImFont::FindGlyphNoFallback ( ImWchar  c) const
3294{
3295 if (c >= (size_t)IndexLookup.Size)
3296 return NULL;
3297 const ImWchar i = IndexLookup.Data[c];
3298 if (i == (ImWchar)-1)
3299 return NULL;
3300 return &Glyphs.Data[i];
3301}

References ImVector< T >::Data, Glyphs, IndexLookup, and ImVector< T >::Size.

Referenced by BuildLookupTable(), ImFontAtlasBuildFinish(), and ShowFont().

+ Here is the caller graph for this function:

◆ GetCharAdvance()

float ImFont::GetCharAdvance ( ImWchar  c) const
inline
2718{ return ((int)c < IndexAdvanceX.Size) ? IndexAdvanceX[(int)c] : FallbackAdvanceX; }

References ImVector< T >::Size.

Referenced by InputTextCalcTextSizeW(), ImGui::InputTextEx(), and ImStb::STB_TEXTEDIT_GETWIDTH().

+ Here is the caller graph for this function:

◆ GetDebugName()

const char * ImFont::GetDebugName ( ) const
inline
2720{ return ConfigData ? ConfigData->Name : "<unknown>"; }
char Name[40]
Definition imgui.h:2515

References ImFontConfig::Name.

Referenced by ImGui::ShowFontSelector().

+ Here is the caller graph for this function:

◆ GrowIndex()

void ImFont::GrowIndex ( int  new_size)
3213{
3215 if (new_size <= IndexLookup.Size)
3216 return;
3217 IndexAdvanceX.resize(new_size, -1.0f);
3218 IndexLookup.resize(new_size, (ImWchar)-1);
3219}

References IM_ASSERT, IndexAdvanceX, IndexLookup, ImVector< T >::resize(), and ImVector< T >::Size.

Referenced by AddRemapChar(), and BuildLookupTable().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IsGlyphRangeUnused()

bool ImFont::IsGlyphRangeUnused ( unsigned int  c_begin,
unsigned int  c_last 
)
3190{
3191 unsigned int page_begin = (c_begin / 4096);
3192 unsigned int page_last = (c_last / 4096);
3193 for (unsigned int page_n = page_begin; page_n <= page_last; page_n++)
3194 if ((page_n >> 3) < sizeof(Used4kPagesMap))
3195 if (Used4kPagesMap[page_n >> 3] & (1 << (page_n & 7)))
3196 return false;
3197 return true;
3198}

References Used4kPagesMap.

Referenced by ShowFont().

+ Here is the caller graph for this function:

◆ IsLoaded()

bool ImFont::IsLoaded ( ) const
inline
2719{ return ContainerAtlas != NULL; }

Referenced by Slic3r::GUI::ImGuiWrapper::contain_all_glyphs(), Slic3r::GUI::Emboss::StyleManager::create_imgui_font(), Slic3r::GUI::GLGizmoEmboss::draw_text_input(), ImFontAtlasBuildWithStbTruetype(), ImGui::NewFrame(), and ImGui::SetCurrentFont().

+ Here is the caller graph for this function:

◆ RenderChar()

void ImFont::RenderChar ( ImDrawList draw_list,
float  size,
ImVec2  pos,
ImU32  col,
ImWchar  c 
) const
3498{
3499 const ImFontGlyph* glyph = FindGlyph(c);
3500 if (!glyph || !glyph->Visible)
3501 return;
3502 if (glyph->Colored)
3503 col |= ~IM_COL32_A_MASK;
3504 float scale = (size >= 0.0f) ? (size / FontSize) : 1.0f;
3505 pos.x = IM_FLOOR(pos.x);
3506 pos.y = IM_FLOOR(pos.y);
3507 draw_list->PrimReserve(6, 4);
3508 draw_list->PrimRectUV(ImVec2(pos.x + glyph->X0 * scale, pos.y + glyph->Y0 * scale), ImVec2(pos.x + glyph->X1 * scale, pos.y + glyph->Y1 * scale), ImVec2(glyph->U0, glyph->V0), ImVec2(glyph->U1, glyph->V1), col);
3509}
EIGEN_DEVICE_FUNC ColXpr col(Index i)
This is the const version of col().
Definition BlockMethods.h:838
#define IM_FLOOR(_VAL)
Definition imgui_internal.h:232
Vec3d pos(const Pt &p)
Definition ReprojectPointsOnMesh.hpp:14
IMGUI_API void PrimRectUV(const ImVec2 &a, const ImVec2 &b, const ImVec2 &uv_a, const ImVec2 &uv_b, ImU32 col)
Definition imgui_draw.cpp:668
IMGUI_API void PrimReserve(int idx_count, int vtx_count)
Definition imgui_draw.cpp:616

References col(), ImFontGlyph::Colored, FindGlyph(), FontSize, IM_FLOOR, ImDrawList::PrimRectUV(), ImDrawList::PrimReserve(), scale(), ImFontGlyph::U0, ImFontGlyph::U1, ImFontGlyph::V0, ImFontGlyph::V1, ImFontGlyph::Visible, ImFontGlyph::X0, ImFontGlyph::X1, ImFontGlyph::Y0, and ImFontGlyph::Y1.

Referenced by ImGui::RenderTextEllipsis(), and ShowFont().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RenderText()

void ImFont::RenderText ( ImDrawList draw_list,
float  size,
ImVec2  pos,
ImU32  col,
const ImVec4 clip_rect,
const char *  text_begin,
const char *  text_end,
float  wrap_width = 0.0f,
bool  cpu_fine_clip = false 
) const
3513{
3514 if (!text_end)
3515 text_end = text_begin + strlen(text_begin); // ImGui:: functions generally already provides a valid text_end, so this is merely to handle direct calls.
3516
3517 // Align to be pixel perfect
3518 pos.x = IM_FLOOR(pos.x);
3519 pos.y = IM_FLOOR(pos.y);
3520 float x = pos.x;
3521 float y = pos.y;
3522 if (y > clip_rect.w)
3523 return;
3524
3525 const float scale = size / FontSize;
3526 const float line_height = FontSize * scale;
3527 const bool word_wrap_enabled = (wrap_width > 0.0f);
3528 const char* word_wrap_eol = NULL;
3529
3530 // Fast-forward to first visible line
3531 const char* s = text_begin;
3532 if (y + line_height < clip_rect.y && !word_wrap_enabled)
3533 while (y + line_height < clip_rect.y && s < text_end)
3534 {
3535 s = (const char*)memchr(s, '\n', text_end - s);
3536 s = s ? s + 1 : text_end;
3537 y += line_height;
3538 }
3539
3540 // For large text, scan for the last visible line in order to avoid over-reserving in the call to PrimReserve()
3541 // Note that very large horizontal line will still be affected by the issue (e.g. a one megabyte string buffer without a newline will likely crash atm)
3542 if (text_end - s > 10000 && !word_wrap_enabled)
3543 {
3544 const char* s_end = s;
3545 float y_end = y;
3546 while (y_end < clip_rect.w && s_end < text_end)
3547 {
3548 s_end = (const char*)memchr(s_end, '\n', text_end - s_end);
3549 s_end = s_end ? s_end + 1 : text_end;
3550 y_end += line_height;
3551 }
3552 text_end = s_end;
3553 }
3554 if (s == text_end)
3555 return;
3556
3557 // Reserve vertices for remaining worse case (over-reserving is useful and easily amortized)
3558 const int vtx_count_max = (int)(text_end - s) * 4;
3559 const int idx_count_max = (int)(text_end - s) * 6;
3560 const int idx_expected_size = draw_list->IdxBuffer.Size + idx_count_max;
3561 draw_list->PrimReserve(idx_count_max, vtx_count_max);
3562
3563 ImDrawVert* vtx_write = draw_list->_VtxWritePtr;
3564 ImDrawIdx* idx_write = draw_list->_IdxWritePtr;
3565 unsigned int vtx_current_idx = draw_list->_VtxCurrentIdx;
3566
3567 const ImU32 col_untinted = col | ~IM_COL32_A_MASK;
3568
3569 ImU32 defaultCol = col;
3571 // if text is started with ColorMarkerHovered symbol, we should use another color for a highlighting
3572 if (*s == ImGui::ColorMarkerHovered) {
3573 highlighCol = ImGui::GetColorU32(ImGuiCol_FrameBg);
3574 s += 1;
3575 }
3576
3577 while (s < text_end)
3578 {
3579 if (word_wrap_enabled)
3580 {
3581 // Calculate how far we can render. Requires two passes on the string data but keeps the code simple and not intrusive for what's essentially an uncommon feature.
3582 if (!word_wrap_eol)
3583 {
3584 word_wrap_eol = CalcWordWrapPositionA(scale, s, text_end, wrap_width - (x - pos.x));
3585 if (word_wrap_eol == s) // Wrap_width is too small to fit anything. Force displaying 1 character to minimize the height discontinuity.
3586 word_wrap_eol++; // +1 may not be a character start point in UTF-8 but it's ok because we use s >= word_wrap_eol below
3587 }
3588
3589 if (s >= word_wrap_eol)
3590 {
3591 x = pos.x;
3592 y += line_height;
3593 word_wrap_eol = NULL;
3594
3595 // Wrapping skips upcoming blanks
3596 while (s < text_end)
3597 {
3598 const char c = *s;
3599 if (ImCharIsBlankA(c)) { s++; } else if (c == '\n') { s++; break; } else { break; }
3600 }
3601 continue;
3602 }
3603 }
3604
3605 if (*s == ImGui::ColorMarkerStart) {
3606 col = highlighCol;
3607 s += 1;
3608 }
3609 else if (*s == ImGui::ColorMarkerEnd) {
3610 col = defaultCol;
3611 s += 1;
3612 if (s == text_end)
3613 break;
3614 }
3615
3616 // Decode and advance source
3617 unsigned int c = (unsigned int)*s;
3618 if (c < 0x80)
3619 {
3620 s += 1;
3621 }
3622 else
3623 {
3624 s += ImTextCharFromUtf8(&c, s, text_end);
3625 if (c == 0) // Malformed UTF-8?
3626 break;
3627 }
3628
3629 if (c < 32)
3630 {
3631 if (c == '\n')
3632 {
3633 x = pos.x;
3634 y += line_height;
3635 if (y > clip_rect.w)
3636 break; // break out of main loop
3637 continue;
3638 }
3639 if (c == '\r')
3640 continue;
3641 }
3642
3643 const ImFontGlyph* glyph = FindGlyph((ImWchar)c);
3644 if (glyph == NULL)
3645 continue;
3646
3647 float char_width = glyph->AdvanceX * scale;
3648 if (glyph->Visible)
3649 {
3650 // We don't do a second finer clipping test on the Y axis as we've already skipped anything before clip_rect.y and exit once we pass clip_rect.w
3651 float x1 = x + glyph->X0 * scale;
3652 float x2 = x + glyph->X1 * scale;
3653 float y1 = y + glyph->Y0 * scale;
3654 float y2 = y + glyph->Y1 * scale;
3655 if (x1 <= clip_rect.z && x2 >= clip_rect.x)
3656 {
3657 // Render a character
3658 float u1 = glyph->U0;
3659 float v1 = glyph->V0;
3660 float u2 = glyph->U1;
3661 float v2 = glyph->V1;
3662
3663 // CPU side clipping used to fit text in their frame when the frame is too small. Only does clipping for axis aligned quads.
3664 if (cpu_fine_clip)
3665 {
3666 if (x1 < clip_rect.x)
3667 {
3668 u1 = u1 + (1.0f - (x2 - clip_rect.x) / (x2 - x1)) * (u2 - u1);
3669 x1 = clip_rect.x;
3670 }
3671 if (y1 < clip_rect.y)
3672 {
3673 v1 = v1 + (1.0f - (y2 - clip_rect.y) / (y2 - y1)) * (v2 - v1);
3674 y1 = clip_rect.y;
3675 }
3676 if (x2 > clip_rect.z)
3677 {
3678 u2 = u1 + ((clip_rect.z - x1) / (x2 - x1)) * (u2 - u1);
3679 x2 = clip_rect.z;
3680 }
3681 if (y2 > clip_rect.w)
3682 {
3683 v2 = v1 + ((clip_rect.w - y1) / (y2 - y1)) * (v2 - v1);
3684 y2 = clip_rect.w;
3685 }
3686 if (y1 >= y2)
3687 {
3688 x += char_width;
3689 continue;
3690 }
3691 }
3692
3693 // Support for untinted glyphs
3694 ImU32 glyph_col = glyph->Colored ? col_untinted : col;
3695
3696 // We are NOT calling PrimRectUV() here because non-inlined causes too much overhead in a debug builds. Inlined here:
3697 {
3698 idx_write[0] = (ImDrawIdx)(vtx_current_idx); idx_write[1] = (ImDrawIdx)(vtx_current_idx+1); idx_write[2] = (ImDrawIdx)(vtx_current_idx+2);
3699 idx_write[3] = (ImDrawIdx)(vtx_current_idx); idx_write[4] = (ImDrawIdx)(vtx_current_idx+2); idx_write[5] = (ImDrawIdx)(vtx_current_idx+3);
3700 vtx_write[0].pos.x = x1; vtx_write[0].pos.y = y1; vtx_write[0].col = glyph_col; vtx_write[0].uv.x = u1; vtx_write[0].uv.y = v1;
3701 vtx_write[1].pos.x = x2; vtx_write[1].pos.y = y1; vtx_write[1].col = glyph_col; vtx_write[1].uv.x = u2; vtx_write[1].uv.y = v1;
3702 vtx_write[2].pos.x = x2; vtx_write[2].pos.y = y2; vtx_write[2].col = glyph_col; vtx_write[2].uv.x = u2; vtx_write[2].uv.y = v2;
3703 vtx_write[3].pos.x = x1; vtx_write[3].pos.y = y2; vtx_write[3].col = glyph_col; vtx_write[3].uv.x = u1; vtx_write[3].uv.y = v2;
3704 vtx_write += 4;
3705 vtx_current_idx += 4;
3706 idx_write += 6;
3707 }
3708 }
3709 }
3710 x += char_width;
3711 }
3712
3713 // Give back unused vertices (clipped ones, blanks) ~ this is essentially a PrimUnreserve() action.
3714 draw_list->VtxBuffer.Size = (int)(vtx_write - draw_list->VtxBuffer.Data); // Same as calling shrink()
3715 draw_list->IdxBuffer.Size = (int)(idx_write - draw_list->IdxBuffer.Data);
3716 draw_list->CmdBuffer[draw_list->CmdBuffer.Size - 1].ElemCount -= (idx_expected_size - draw_list->IdxBuffer.Size);
3717 draw_list->_VtxWritePtr = vtx_write;
3718 draw_list->_IdxWritePtr = idx_write;
3719 draw_list->_VtxCurrentIdx = vtx_current_idx;
3720}
unsigned int ImU32
Definition imgui.h:229
@ ImGuiCol_FrameBg
Definition imgui.h:1420
@ ImGuiCol_ButtonHovered
Definition imgui.h:1435
ImU32 col
Definition imgui.h:2264
ImVec2 uv
Definition imgui.h:2263
ImVec2 pos
Definition imgui.h:2262
unsigned short ImDrawIdx
Definition imgui.h:2255
Definition imgui.h:2261
const Scalar & y
Definition MathFunctions.h:552
IMGUI_API ImU32 GetColorU32(ImGuiCol idx, float alpha_mul=1.0f)
Definition imgui.cpp:2429
const char ColorMarkerStart
Definition imconfig.h:123
const char ColorMarkerHovered
Definition imconfig.h:120
const char ColorMarkerEnd
Definition imconfig.h:124
TCoord< P > x(const P &p)
Definition geometry_traits.hpp:297
unsigned int _VtxCurrentIdx
Definition imgui.h:2356
ImVector< ImDrawCmd > CmdBuffer
Definition imgui.h:2350
ImDrawVert * _VtxWritePtr
Definition imgui.h:2359
ImDrawIdx * _IdxWritePtr
Definition imgui.h:2360
ImVector< ImDrawVert > VtxBuffer
Definition imgui.h:2352
ImVector< ImDrawIdx > IdxBuffer
Definition imgui.h:2351
float x
Definition imgui.h:259
float y
Definition imgui.h:259
float z
Definition imgui.h:259
float w
Definition imgui.h:259

References ImDrawList::_IdxWritePtr, ImDrawList::_VtxCurrentIdx, ImDrawList::_VtxWritePtr, ImFontGlyph::AdvanceX, CalcWordWrapPositionA(), ImDrawList::CmdBuffer, col(), ImDrawVert::col, ImFontGlyph::Colored, ImGui::ColorMarkerEnd, ImGui::ColorMarkerHovered, ImGui::ColorMarkerStart, ImVector< T >::Data, FindGlyph(), FontSize, ImGui::GetColorU32(), ImDrawList::IdxBuffer, IM_FLOOR, ImCharIsBlankA(), ImGuiCol_ButtonHovered, ImGuiCol_FrameBg, ImTextCharFromUtf8(), ImDrawVert::pos, ImDrawList::PrimReserve(), scale(), ImVector< T >::Size, ImFontGlyph::U0, ImFontGlyph::U1, ImDrawVert::uv, ImFontGlyph::V0, ImFontGlyph::V1, ImFontGlyph::Visible, ImDrawList::VtxBuffer, ImVec4::w, ImVec2::x, ImVec4::x, ImFontGlyph::X0, ImFontGlyph::X1, ImVec2::y, ImVec4::y, ImFontGlyph::Y0, ImFontGlyph::Y1, and ImVec4::z.

Referenced by ImDrawList::AddText().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetFallbackChar()

void ImFont::SetFallbackChar ( ImWchar  c)
3207{
3208 FallbackChar = c;
3210}
IMGUI_API void BuildLookupTable()
Definition imgui_draw.cpp:3137

References BuildLookupTable(), and FallbackChar.

+ Here is the call graph for this function:

◆ SetGlyphVisible()

void ImFont::SetGlyphVisible ( ImWchar  c,
bool  visible 
)
3201{
3202 if (ImFontGlyph* glyph = (ImFontGlyph*)(void*)FindGlyph((ImWchar)c))
3203 glyph->Visible = visible ? 1 : 0;
3204}

References FindGlyph().

Referenced by BuildLookupTable().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ Ascent

◆ ConfigData

◆ ConfigDataCount

short ImFont::ConfigDataCount

◆ ContainerAtlas

◆ Descent

◆ DirtyLookupTables

bool ImFont::DirtyLookupTables

◆ EllipsisChar

◆ FallbackAdvanceX

◆ FallbackChar

ImWchar ImFont::FallbackChar

◆ FallbackGlyph

◆ FontSize

◆ Glyphs

◆ IndexAdvanceX

◆ IndexLookup

◆ MetricsTotalSurface

int ImFont::MetricsTotalSurface

◆ Scale

◆ Used4kPagesMap

ImU8 ImFont::Used4kPagesMap[(IM_UNICODE_CODEPOINT_MAX+1)/4096/8]

The documentation for this struct was generated from the following files: