From 6782533ad24cf49485d2bb81f44ca2f7825db4a9 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Sun, 7 Mar 2021 17:30:11 +0100 Subject: [PATCH] Fix heuristic to find font atlas optimal width --- lib/font_renderer/font_renderer.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/font_renderer/font_renderer.cpp b/lib/font_renderer/font_renderer.cpp index d060839f..c30c8f57 100644 --- a/lib/font_renderer/font_renderer.cpp +++ b/lib/font_renderer/font_renderer.cpp @@ -244,7 +244,8 @@ FR_Bitmap *FR_Bake_Font_Bitmap(FR_Renderer *font_renderer, int font_height, i = i + 1; } - const int pixels_width = glyph_count > 0 ? (x_size_sum / glyph_count) * 16 : 12; + const int glyph_avg_width = glyph_count > 0 ? x_size_sum / (glyph_count * subpixel_scale) : font_height; + const int pixels_width = glyph_avg_width * 20; // dry run simulating pixel position to estimate required image's height int x = x_start, y = 0, y_bottom = y;