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
This commit is contained in:
Megamouse 2022-07-26 21:43:11 +02:00
parent 87e628a9e9
commit 228844c017
2 changed files with 16 additions and 4 deletions

View File

@ -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);

View File

@ -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;
}
}
}