MCPcopy Create free account
hub / github.com/KebsCS/KBotExt / AddGlyph

Method AddGlyph

KBotExt/imgui/imgui_draw.cpp:3328–3370  ·  view source on GitHub ↗

x0/y0/x1/y1 are offset from the character upper-left layout position, in pixels. Therefore x0/y0 are often fairly close to zero. Not to be mistaken with texture coordinates, which are held by u0/v0/u1/v1 in normalized format (0.0..1.0 on each texture axis). 'cfg' is not necessarily == 'this->ConfigData' because multiple source fonts+configs can be used to build one target font.

Source from the content-addressed store, hash-verified

3326// Not to be mistaken with texture coordinates, which are held by u0/v0/u1/v1 in normalized format (0.0..1.0 on each texture axis).
3327// 'cfg' is not necessarily == 'this->ConfigData' because multiple source fonts+configs can be used to build one target font.
3328void ImFont::AddGlyph(const ImFontConfig* cfg, ImWchar codepoint, float x0, float y0, float x1, float y1, float u0, float v0, float u1, float v1, float advance_x)
3329{
3330 if (cfg != NULL)
3331 {
3332 // Clamp & recenter if needed
3333 const float advance_x_original = advance_x;
3334 advance_x = ImClamp(advance_x, cfg->GlyphMinAdvanceX, cfg->GlyphMaxAdvanceX);
3335 if (advance_x != advance_x_original)
3336 {
3337 float char_off_x = cfg->PixelSnapH ? ImFloor((advance_x - advance_x_original) * 0.5f) : (advance_x - advance_x_original) * 0.5f;
3338 x0 += char_off_x;
3339 x1 += char_off_x;
3340 }
3341
3342 // Snap to pixel
3343 if (cfg->PixelSnapH)
3344 advance_x = IM_ROUND(advance_x);
3345
3346 // Bake spacing
3347 advance_x += cfg->GlyphExtraSpacing.x;
3348 }
3349
3350 Glyphs.resize(Glyphs.Size + 1);
3351 ImFontGlyph& glyph = Glyphs.back();
3352 glyph.Codepoint = (unsigned int)codepoint;
3353 glyph.Visible = (x0 != x1) && (y0 != y1);
3354 glyph.Colored = false;
3355 glyph.X0 = x0;
3356 glyph.Y0 = y0;
3357 glyph.X1 = x1;
3358 glyph.Y1 = y1;
3359 glyph.U0 = u0;
3360 glyph.V0 = v0;
3361 glyph.U1 = u1;
3362 glyph.V1 = v1;
3363 glyph.AdvanceX = advance_x;
3364
3365 // Compute rough surface usage metrics (+1 to account for average padding, +0.99 to round)
3366 // We use (U1-U0)*TexWidth instead of X1-X0 to account for oversampling.
3367 float pad = ContainerAtlas->TexGlyphPadding + 0.99f;
3368 DirtyLookupTables = true;
3369 MetricsTotalSurface += (int)((glyph.U1 - glyph.U0) * ContainerAtlas->TexWidth + pad) * (int)((glyph.V1 - glyph.V0) * ContainerAtlas->TexHeight + pad);
3370}
3371
3372void ImFont::AddRemapChar(ImWchar dst, ImWchar src, bool overwrite_dst)
3373{

Callers 3

ImFontAtlasBuildFinishFunction · 0.80

Calls 2

ImClampFunction · 0.85
ImFloorFunction · 0.85

Tested by

no test coverage detected