|
|
@@ -1527,6 +1527,7 @@ ImFont* ImFontAtlas::AddFontDefault(const ImFontConfig* font_cfg_template)
|
|
|
|
|
|
const char* ttf_compressed_base85 = GetDefaultCompressedFontDataTTFBase85();
|
|
|
ImFont* font = AddFontFromMemoryCompressedBase85TTF(ttf_compressed_base85, font_cfg.SizePixels, &font_cfg, GetGlyphRangesDefault());
|
|
|
+ font->DisplayOffset.y = 1.0f;
|
|
|
return font;
|
|
|
}
|
|
|
|
|
|
@@ -1545,7 +1546,7 @@ ImFont* ImFontAtlas::AddFontFromFileTTF(const char* filename, float size_pixels,
|
|
|
// Store a short copy of filename into into the font name for convenience
|
|
|
const char* p;
|
|
|
for (p = filename + strlen(filename); p > filename && p[-1] != '/' && p[-1] != '\\'; p--) {}
|
|
|
- snprintf(font_cfg.Name, IM_ARRAYSIZE(font_cfg.Name), "%s, %.0fpx", p, size_pixels);
|
|
|
+ ImFormatString(font_cfg.Name, IM_ARRAYSIZE(font_cfg.Name), "%s, %.0fpx", p, size_pixels);
|
|
|
}
|
|
|
return AddFontFromMemoryTTF(data, data_size, size_pixels, &font_cfg, glyph_ranges);
|
|
|
}
|
|
|
@@ -1819,13 +1820,15 @@ bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
|
|
|
ImFontConfig& cfg = atlas->ConfigData[input_i];
|
|
|
ImFontTempBuildData& tmp = tmp_array[input_i];
|
|
|
ImFont* dst_font = cfg.DstFont; // We can have multiple input fonts writing into a same destination font (when using MergeMode=true)
|
|
|
+ if (cfg.MergeMode)
|
|
|
+ dst_font->BuildLookupTable();
|
|
|
|
|
|
const float font_scale = stbtt_ScaleForPixelHeight(&tmp.FontInfo, cfg.SizePixels);
|
|
|
int unscaled_ascent, unscaled_descent, unscaled_line_gap;
|
|
|
stbtt_GetFontVMetrics(&tmp.FontInfo, &unscaled_ascent, &unscaled_descent, &unscaled_line_gap);
|
|
|
|
|
|
- const float ascent = unscaled_ascent * font_scale;
|
|
|
- const float descent = unscaled_descent * font_scale;
|
|
|
+ const float ascent = ImFloor(unscaled_ascent * font_scale + ((unscaled_ascent > 0.0f) ? +1 : -1));
|
|
|
+ const float descent = ImFloor(unscaled_descent * font_scale + ((unscaled_descent > 0.0f) ? +1 : -1));
|
|
|
ImFontAtlasBuildSetupFont(atlas, dst_font, &cfg, ascent, descent);
|
|
|
const float off_x = cfg.GlyphOffset.x;
|
|
|
const float off_y = cfg.GlyphOffset.y + (float)(int)(dst_font->Ascent + 0.5f);
|
|
|
@@ -1962,7 +1965,8 @@ void ImFontAtlasBuildFinish(ImFontAtlas* atlas)
|
|
|
|
|
|
// Build all fonts lookup tables
|
|
|
for (int i = 0; i < atlas->Fonts.Size; i++)
|
|
|
- atlas->Fonts[i]->BuildLookupTable();
|
|
|
+ if (atlas->Fonts[i]->DirtyLookupTables)
|
|
|
+ atlas->Fonts[i]->BuildLookupTable();
|
|
|
}
|
|
|
|
|
|
// Retrieve list of range (2 int per range, values are inclusive)
|
|
|
@@ -2138,7 +2142,7 @@ ImFont::ImFont()
|
|
|
{
|
|
|
Scale = 1.0f;
|
|
|
FallbackChar = (ImWchar)'?';
|
|
|
- DisplayOffset = ImVec2(0.0f, 1.0f);
|
|
|
+ DisplayOffset = ImVec2(0.0f, 0.0f);
|
|
|
ClearOutputData();
|
|
|
}
|
|
|
|
|
|
@@ -2167,6 +2171,7 @@ void ImFont::ClearOutputData()
|
|
|
ConfigData = NULL;
|
|
|
ContainerAtlas = NULL;
|
|
|
Ascent = Descent = 0.0f;
|
|
|
+ DirtyLookupTables = true;
|
|
|
MetricsTotalSurface = 0;
|
|
|
}
|
|
|
|
|
|
@@ -2179,6 +2184,7 @@ void ImFont::BuildLookupTable()
|
|
|
IM_ASSERT(Glyphs.Size < 0xFFFF); // -1 is reserved
|
|
|
IndexAdvanceX.clear();
|
|
|
IndexLookup.clear();
|
|
|
+ DirtyLookupTables = false;
|
|
|
GrowIndex(max_codepoint + 1);
|
|
|
for (int i = 0; i < Glyphs.Size; i++)
|
|
|
{
|
|
|
@@ -2243,6 +2249,7 @@ void ImFont::AddGlyph(ImWchar codepoint, float x0, float y0, float x1, float y1,
|
|
|
glyph.AdvanceX = (float)(int)(glyph.AdvanceX + 0.5f);
|
|
|
|
|
|
// Compute rough surface usage metrics (+1 to account for average padding, +0.99 to round)
|
|
|
+ DirtyLookupTables = true;
|
|
|
MetricsTotalSurface += (int)((glyph.U1 - glyph.U0) * ContainerAtlas->TexWidth + 1.99f) * (int)((glyph.V1 - glyph.V0) * ContainerAtlas->TexHeight + 1.99f);
|
|
|
}
|
|
|
|