From 228844c017cb062f08d12903253f1245ce75bb4f Mon Sep 17 00:00:00 2001 From: Megamouse Date: Tue, 26 Jul 2022 21:43:11 +0200 Subject: [PATCH] overlays: fix line wrapping and position of lines - Fix off by one issue when we wrapping a line caused by unnecessary zeroed whitespaces. - Fix centering of lines that end with carriage return caused by overzealous reset of counters. - Remove fabs where there shouldn't be any --- rpcs3/Emu/RSX/Overlays/overlay_controls.cpp | 3 +-- rpcs3/Emu/RSX/Overlays/overlay_fonts.cpp | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/rpcs3/Emu/RSX/Overlays/overlay_controls.cpp b/rpcs3/Emu/RSX/Overlays/overlay_controls.cpp index bd837f94c4..b3ecc6b639 100644 --- a/rpcs3/Emu/RSX/Overlays/overlay_controls.cpp +++ b/rpcs3/Emu/RSX/Overlays/overlay_controls.cpp @@ -398,7 +398,6 @@ namespace rsx { case '\r': { - word_end = line_end = line_begin = ctr; continue; } case '\n': @@ -481,7 +480,7 @@ namespace rsx const bool is_last_glyph = i_next >= end; // The line may be wrapped, so we need to check if the next glyph's position is below the current position. - if (is_last_glyph || (std::fabs(result[i_next - 1].y() - result[i_begin + 3].y()) >= size_px)) + if (is_last_glyph || (result[i_next - 1].y() - result[i_begin + 3].y() >= size_px)) { // Whenever we reached the end of a visual line we need to move its glyphs accordingly. const u32 i_end = i_next - (is_last_glyph ? 0 : 4); diff --git a/rpcs3/Emu/RSX/Overlays/overlay_fonts.cpp b/rpcs3/Emu/RSX/Overlays/overlay_fonts.cpp index c0c8a9ed80..80151fcc6e 100644 --- a/rpcs3/Emu/RSX/Overlays/overlay_fonts.cpp +++ b/rpcs3/Emu/RSX/Overlays/overlay_fonts.cpp @@ -327,15 +327,28 @@ namespace rsx if (is_whitespace) { // Skip whitespace if we are at the start of a line. - if (x_advance > 0.f) + if (x_advance <= 0.f) { + // Set the glyph to the current position. + // This is necessary for downstream linewidth calculations. + quad.x0 = quad.x1 = x_advance; + quad.y0 = quad.y1 = y_advance; + } + else + { + const f32 x_advance_old = x_advance; + const f32 y_advance_old = y_advance; + // Get the glyph size. quad = get_char(c, x_advance, y_advance); // Reset the result if the glyph would protrude out of the given space anyway. if (x_advance > max_width) { - quad = {}; + // Set the glyph to the previous position. + // This is necessary for downstream linewidth calculations. + quad.x0 = quad.x1 = x_advance_old; + quad.y0 = quad.y1 = y_advance_old; } } }