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.
| 3254 | // 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). |
| 3255 | // 'cfg' is not necessarily == 'this->ConfigData' because multiple source fonts+configs can be used to build one target font. |
| 3256 | void 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) |
| 3257 | { |
| 3258 | if (cfg != NULL) |
| 3259 | { |
| 3260 | // Clamp & recenter if needed |
| 3261 | const float advance_x_original = advance_x; |
| 3262 | advance_x = ImClamp(advance_x, cfg->GlyphMinAdvanceX, cfg->GlyphMaxAdvanceX); |
| 3263 | if (advance_x != advance_x_original) |
| 3264 | { |
| 3265 | float char_off_x = cfg->PixelSnapH ? ImFloor((advance_x - advance_x_original) * 0.5f) : (advance_x - advance_x_original) * 0.5f; |
| 3266 | x0 += char_off_x; |
| 3267 | x1 += char_off_x; |
| 3268 | } |
| 3269 | |
| 3270 | // Snap to pixel |
| 3271 | if (cfg->PixelSnapH) |
| 3272 | advance_x = IM_ROUND(advance_x); |
| 3273 | |
| 3274 | // Bake spacing |
| 3275 | advance_x += cfg->GlyphExtraSpacing.x; |
| 3276 | } |
| 3277 | |
| 3278 | Glyphs.resize(Glyphs.Size + 1); |
| 3279 | ImFontGlyph& glyph = Glyphs.back(); |
| 3280 | glyph.Codepoint = (unsigned int)codepoint; |
| 3281 | glyph.Visible = (x0 != x1) && (y0 != y1); |
| 3282 | glyph.Colored = false; |
| 3283 | glyph.X0 = x0; |
| 3284 | glyph.Y0 = y0; |
| 3285 | glyph.X1 = x1; |
| 3286 | glyph.Y1 = y1; |
| 3287 | glyph.U0 = u0; |
| 3288 | glyph.V0 = v0; |
| 3289 | glyph.U1 = u1; |
| 3290 | glyph.V1 = v1; |
| 3291 | glyph.AdvanceX = advance_x; |
| 3292 | |
| 3293 | // Compute rough surface usage metrics (+1 to account for average padding, +0.99 to round) |
| 3294 | // We use (U1-U0)*TexWidth instead of X1-X0 to account for oversampling. |
| 3295 | float pad = ContainerAtlas->TexGlyphPadding + 0.99f; |
| 3296 | DirtyLookupTables = true; |
| 3297 | MetricsTotalSurface += (int)((glyph.U1 - glyph.U0) * ContainerAtlas->TexWidth + pad) * (int)((glyph.V1 - glyph.V0) * ContainerAtlas->TexHeight + pad); |
| 3298 | } |
| 3299 | |
| 3300 | void ImFont::AddRemapChar(ImWchar dst, ImWchar src, bool overwrite_dst) |
| 3301 | { |
no test coverage detected