From e8aa2f922b41864f45749950ab75a86a5d91dc6e Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Fri, 14 Apr 2023 15:00:50 -0500 Subject: [PATCH 1/2] Allow word wrapping to wrap on capital letters and underscores. --- Source/Engine/Render2D/Font.cpp | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/Source/Engine/Render2D/Font.cpp b/Source/Engine/Render2D/Font.cpp index 0cbc30701..d80f7d19c 100644 --- a/Source/Engine/Render2D/Font.cpp +++ b/Source/Engine/Render2D/Font.cpp @@ -122,6 +122,12 @@ void Font::ProcessText(const StringView& text, Array& outputLines float lastWhitespaceX = 0; bool lastMoveLine = false; + int32 lastUpperIndex = INVALID_INDEX; + float lastUpperX = 0; + + int32 lastUnderscoreIndex = INVALID_INDEX; + float lastUnderscoreX = 0; + // Process each character to split text into single lines for (int32 currentIndex = 0; currentIndex < textLength;) { @@ -141,6 +147,21 @@ void Font::ProcessText(const StringView& text, Array& outputLines lastWhitespaceX = cursorX; } + // Check if character is an upper case letter + const bool isUpper = StringUtils::IsUpper(currentChar); + if (isUpper && currentIndex != 0) + { + lastUpperIndex = currentIndex; + lastUpperX = cursorX; + } + + const bool isUnderscore = currentChar == '_'; + if (isUnderscore) + { + lastUnderscoreIndex = currentIndex; + lastUnderscoreX = cursorX; + } + // Check if it's a newline character if (currentChar == '\n') { @@ -185,6 +206,20 @@ void Font::ProcessText(const StringView& text, Array& outputLines currentIndex = lastWhitespaceIndex + 1; nextCharIndex = currentIndex; } + else if (lastUpperIndex != INVALID_INDEX) + { + cursorX = lastUpperX; + tmpLine.LastCharIndex = lastUpperIndex - 1; + currentIndex = lastUpperIndex; + nextCharIndex = currentIndex; + } + else if (lastUnderscoreIndex != INVALID_INDEX) + { + cursorX = lastUnderscoreX; + tmpLine.LastCharIndex = lastUnderscoreIndex; + currentIndex = lastUnderscoreIndex + 1; + nextCharIndex = currentIndex; + } else { nextCharIndex = currentIndex; @@ -224,6 +259,12 @@ void Font::ProcessText(const StringView& text, Array& outputLines lastWhitespaceIndex = INVALID_INDEX; lastWhitespaceX = 0; + lastUpperIndex = INVALID_INDEX; + lastUpperX = 0; + + lastUnderscoreIndex = INVALID_INDEX; + lastUnderscoreX = 0; + previous.IsValid = false; } From da857714729d6f2a7606c3fe1f9f28dcf15ebbbb Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Fri, 14 Apr 2023 15:07:06 -0500 Subject: [PATCH 2/2] Small fixes --- Source/Engine/Render2D/Font.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/Engine/Render2D/Font.cpp b/Source/Engine/Render2D/Font.cpp index d80f7d19c..5881c2322 100644 --- a/Source/Engine/Render2D/Font.cpp +++ b/Source/Engine/Render2D/Font.cpp @@ -124,7 +124,7 @@ void Font::ProcessText(const StringView& text, Array& outputLines int32 lastUpperIndex = INVALID_INDEX; float lastUpperX = 0; - + int32 lastUnderscoreIndex = INVALID_INDEX; float lastUnderscoreX = 0; @@ -155,6 +155,7 @@ void Font::ProcessText(const StringView& text, Array& outputLines lastUpperX = cursorX; } + // Check if character is an underscore const bool isUnderscore = currentChar == '_'; if (isUnderscore) {