From 4654aea175b364745642566cb153d8930217ce5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Wed, 28 Jan 2026 22:40:59 -0300 Subject: [PATCH] Fix issue with kerning when using tab characters (i do not want to apply kerning in tab characters). --- src/eepp/graphics/linewrap.cpp | 6 +++--- src/eepp/graphics/text.cpp | 1 + src/eepp/graphics/textlayout.cpp | 2 +- src/tests/unit_tests/fontrendering.cpp | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/eepp/graphics/linewrap.cpp b/src/eepp/graphics/linewrap.cpp index 797659332..0f7622a21 100644 --- a/src/eepp/graphics/linewrap.cpp +++ b/src/eepp/graphics/linewrap.cpp @@ -165,10 +165,10 @@ LineWrap::computeLineBreaksInternal( const String::View& string, Font* font, Uin ? font->getGlyph( curChar, characterSize, bold, italic, outlineThickness ).advance : hspace; - if ( curChar == '\t' ) + if ( curChar == '\t' ) { w = Text::tabAdvance( hspace, tabWidth, tabStops ? xoffset : std::optional{} ); - - if ( !isMonospace && curChar != '\r' ) { + prevChar = 0; + } else if ( !isMonospace && curChar != '\r' ) { if ( !( textDrawHints & TextHints::NoKerning ) ) { w += font->getKerning( prevChar, curChar, characterSize, bold, italic, outlineThickness ); diff --git a/src/eepp/graphics/text.cpp b/src/eepp/graphics/text.cpp index 4b750c150..cf0eba473 100644 --- a/src/eepp/graphics/text.cpp +++ b/src/eepp/graphics/text.cpp @@ -1290,6 +1290,7 @@ void Text::updateWidthCache() { width += glyph.advance; } else if ( codepoint == '\t' ) { width += tabAdvance( hspace, mTabWidth, mTabStops ? width : std::optional{} ); + codepoint = 0; } else if ( codepoint == '\r' ) { prevChar = 0; continue; diff --git a/src/eepp/graphics/textlayout.cpp b/src/eepp/graphics/textlayout.cpp index 93903b6fa..3d5161254 100644 --- a/src/eepp/graphics/textlayout.cpp +++ b/src/eepp/graphics/textlayout.cpp @@ -464,7 +464,6 @@ TextLayout::Cache TextLayout::layout( const String::View& string, Font* font, prevChar = curChar; if ( curChar == '\t' ) { - ShapedGlyph sg; sg.stringIndex = i; sg.advance = { Text::tabAdvance( hspace, tabWidth, @@ -477,6 +476,7 @@ TextLayout::Cache TextLayout::layout( const String::View& string, Font* font, sg.position = pen; pen.x += sg.advance.x; curParagraph->shapedGlyphs.emplace_back( std::move( sg ) ); + prevChar = 0; continue; } diff --git a/src/tests/unit_tests/fontrendering.cpp b/src/tests/unit_tests/fontrendering.cpp index 75cb68f07..7cd768b52 100644 --- a/src/tests/unit_tests/fontrendering.cpp +++ b/src/tests/unit_tests/fontrendering.cpp @@ -1038,7 +1038,7 @@ UTEST( FontRendering, LineWrapInfo ) { runTest( "assets/textfiles/test-hard-wrap.uext" ); runTest( "assets/textfiles/lorem-ipsum.uext" ); - // runTest( "assets/textfiles/test-tabs.txt" ); + runTest( "assets/textfiles/test-tabs.txt" ); } UTEST( FontRendering, TextHardWrap ) {