mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-04 03:58:47 +02:00
ImFontConfig: Added GlyphOffset to explicitely offset glyphs at font build time, useful for merged fonts. May remove MergeGlyphCenterV soon.
This commit is contained in:
@ -1043,6 +1043,7 @@ ImFontConfig::ImFontConfig()
|
||||
OversampleV = 1;
|
||||
PixelSnapH = false;
|
||||
GlyphExtraSpacing = ImVec2(0.0f, 0.0f);
|
||||
GlyphOffset = ImVec2(0.0f, 0.0f);
|
||||
GlyphRanges = NULL;
|
||||
MergeMode = false;
|
||||
MergeGlyphCenterV = false;
|
||||
@ -1426,7 +1427,8 @@ bool ImFontAtlas::Build()
|
||||
dst_font->MetricsTotalSurface = 0;
|
||||
}
|
||||
dst_font->ConfigDataCount++;
|
||||
float off_y = (cfg.MergeMode && cfg.MergeGlyphCenterV) ? (ascent - dst_font->Ascent) * 0.5f : 0.0f;
|
||||
float off_x = cfg.GlyphOffset.x, off_y = cfg.GlyphOffset.y;
|
||||
float merge_off_y = (cfg.MergeMode && cfg.MergeGlyphCenterV) ? (ascent - dst_font->Ascent) * 0.5f : 0.0f;
|
||||
|
||||
dst_font->FallbackGlyph = NULL; // Always clear fallback so FindGlyph can return NULL. It will be set again in BuildLookupTable()
|
||||
for (int i = 0; i < tmp.RangesCount; i++)
|
||||
@ -1449,10 +1451,10 @@ bool ImFontAtlas::Build()
|
||||
dst_font->Glyphs.resize(dst_font->Glyphs.Size + 1);
|
||||
ImFont::Glyph& glyph = dst_font->Glyphs.back();
|
||||
glyph.Codepoint = (ImWchar)codepoint;
|
||||
glyph.X0 = q.x0; glyph.Y0 = q.y0; glyph.X1 = q.x1; glyph.Y1 = q.y1;
|
||||
glyph.X0 = q.x0 + off_x; glyph.Y0 = q.y0 + off_y; glyph.X1 = q.x1 + off_x; glyph.Y1 = q.y1 + off_y;
|
||||
glyph.U0 = q.s0; glyph.V0 = q.t0; glyph.U1 = q.s1; glyph.V1 = q.t1;
|
||||
glyph.Y0 += (float)(int)(dst_font->Ascent + off_y + 0.5f);
|
||||
glyph.Y1 += (float)(int)(dst_font->Ascent + off_y + 0.5f);
|
||||
glyph.Y0 += (float)(int)(dst_font->Ascent + merge_off_y + 0.5f);
|
||||
glyph.Y1 += (float)(int)(dst_font->Ascent + merge_off_y + 0.5f);
|
||||
glyph.XAdvance = (pc.xadvance + cfg.GlyphExtraSpacing.x); // Bake spacing into XAdvance
|
||||
if (cfg.PixelSnapH)
|
||||
glyph.XAdvance = (float)(int)(glyph.XAdvance + 0.5f);
|
||||
|
Reference in New Issue
Block a user