Skip to content

Commit

Permalink
Don't justify last line of paragraph or whole text
Browse files Browse the repository at this point in the history
  • Loading branch information
nieznanysprawiciel committed Nov 13, 2024
1 parent 0dabc83 commit 5b5ec5e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions swGraphicAPI/Assets/TextAsset/Text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ void TextArranger::ApplyAlignement( const FontLayout& layout, std

case TextAlignment::Justify:
{
// The last line in paragraph is not justified. Should be aligned left.
// Assumption: text contains not only one line, but whole text starting from this line.
// The second condition checks cases when text doesn't end with newline and it last character
// in whole text.
if( IsNewline( text[ lastCharIdx ] ) || letters.size() == text.length() )
return;

// Find all spaces which will be extended.
auto numSpaces = std::count_if( text.begin(), text.begin() + lastCharIdx, [](wchar_t c) { return IsWhitespace(c); });
auto trailingSpaces = CountTrailingWhitespaces( std::wstring_view( text.data(), lastCharIdx ) );
Expand Down

0 comments on commit 5b5ec5e

Please sign in to comment.