|
|
@@ -41,7 +41,8 @@
|
|
|
|
|
|
namespace Rml {
|
|
|
|
|
|
-static bool BuildToken(String& token, const char*& token_begin, const char* string_end, bool first_token, bool collapse_white_space, bool break_at_endline, Style::TextTransform text_transformation, bool decode_escape_characters);
|
|
|
+static bool BuildToken(String& token, const char*& token_begin, const char* string_end, bool first_token, bool skip_trailing_whitespace,
|
|
|
+ bool collapse_white_space, bool break_at_endline, Style::TextTransform text_transformation, bool decode_escape_characters);
|
|
|
static bool LastToken(const char* token_begin, const char* string_end, bool collapse_white_space, bool break_at_endline);
|
|
|
|
|
|
ElementText::ElementText(const String& tag) :
|
|
|
@@ -180,14 +181,15 @@ bool ElementText::GenerateToken(float& token_width, int line_begin)
|
|
|
const char* token_begin = text.c_str() + line_begin;
|
|
|
String token;
|
|
|
|
|
|
- BuildToken(token, token_begin, text.c_str() + text.size(), true, collapse_white_space, break_at_endline, computed.text_transform(), true);
|
|
|
+ BuildToken(token, token_begin, text.c_str() + text.size(), true, true, collapse_white_space, break_at_endline, computed.text_transform(), true);
|
|
|
token_width = (float) GetFontEngineInterface()->GetStringWidth(font_face_handle, token);
|
|
|
|
|
|
return LastToken(token_begin, text.c_str() + text.size(), collapse_white_space, break_at_endline);
|
|
|
}
|
|
|
|
|
|
// Generates a line of text rendered from this element
|
|
|
-bool ElementText::GenerateLine(String& line, int& line_length, float& line_width, int line_begin, float maximum_line_width, float right_spacing_width, bool trim_whitespace_prefix, bool decode_escape_characters)
|
|
|
+bool ElementText::GenerateLine(String& line, int& line_length, float& line_width, int line_begin, float maximum_line_width, float right_spacing_width,
|
|
|
+ bool trim_whitespace_prefix, bool trim_whitespace_suffix, bool decode_escape_characters)
|
|
|
{
|
|
|
RMLUI_ZoneScoped;
|
|
|
|
|
|
@@ -236,7 +238,8 @@ bool ElementText::GenerateLine(String& line, int& line_length, float& line_width
|
|
|
previous_codepoint = StringUtilities::ToCharacter(StringUtilities::SeekBackwardUTF8(&line.back(), line.data()));
|
|
|
|
|
|
// Generate the next token and determine its pixel-length.
|
|
|
- bool break_line = BuildToken(token, next_token_begin, string_end, line.empty() && trim_whitespace_prefix, collapse_white_space, break_at_endline, text_transform_property, decode_escape_characters);
|
|
|
+ bool break_line = BuildToken(token, next_token_begin, string_end, line.empty() && trim_whitespace_prefix, trim_whitespace_suffix,
|
|
|
+ collapse_white_space, break_at_endline, text_transform_property, decode_escape_characters);
|
|
|
int token_width = font_engine_interface->GetStringWidth(font_face_handle, token, previous_codepoint);
|
|
|
|
|
|
// If we're breaking to fit a line box, check if the token can fit on the line before we add it.
|
|
|
@@ -260,7 +263,8 @@ bool ElementText::GenerateLine(String& line, int& line_length, float& line_width
|
|
|
token.clear();
|
|
|
next_token_begin = token_begin;
|
|
|
const char* partial_string_end = StringUtilities::SeekBackwardUTF8(token_begin + i, token_begin);
|
|
|
- BuildToken(token, next_token_begin, partial_string_end, line.empty() && trim_whitespace_prefix, collapse_white_space, break_at_endline, text_transform_property, decode_escape_characters);
|
|
|
+ BuildToken(token, next_token_begin, partial_string_end, line.empty() && trim_whitespace_prefix, trim_whitespace_suffix,
|
|
|
+ collapse_white_space, break_at_endline, text_transform_property, decode_escape_characters);
|
|
|
token_width = font_engine_interface->GetStringWidth(font_face_handle, token, previous_codepoint);
|
|
|
|
|
|
if (force_loop_break_after_next || token_width <= max_token_width)
|
|
|
@@ -495,7 +499,8 @@ void ElementText::GenerateDecoration(const FontFaceHandle font_face_handle)
|
|
|
GeometryUtilities::GenerateLine(font_face_handle, decoration.get(), line.position, line.width, decoration_property, colour);
|
|
|
}
|
|
|
|
|
|
-static bool BuildToken(String& token, const char*& token_begin, const char* string_end, bool first_token, bool collapse_white_space, bool break_at_endline, Style::TextTransform text_transformation, bool decode_escape_characters)
|
|
|
+static bool BuildToken(String& token, const char*& token_begin, const char* string_end, bool first_token, bool skip_trailing_whitespace,
|
|
|
+ bool collapse_white_space, bool break_at_endline, Style::TextTransform text_transformation, bool decode_escape_characters)
|
|
|
{
|
|
|
RMLUI_ASSERT(token_begin != string_end);
|
|
|
|
|
|
@@ -583,8 +588,8 @@ static bool BuildToken(String& token, const char*& token_begin, const char* stri
|
|
|
{
|
|
|
// However, if we are the last non-whitespace character in the string, and there are trailing
|
|
|
// whitespace characters after this token, then we need to append a single space to the end of this
|
|
|
- // token.
|
|
|
- if (token_begin != string_end &&
|
|
|
+ // token. Exception: Skip trailing whitespace if we are at the end of a layout line.
|
|
|
+ if (token_begin != string_end && !skip_trailing_whitespace &&
|
|
|
LastToken(token_begin, string_end, collapse_white_space, break_at_endline))
|
|
|
token += ' ';
|
|
|
|