2
0

ElementTextDefault.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. /*
  2. * This source file is part of RmlUi, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://github.com/mikke89/RmlUi
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. * Copyright (c) 2019 The RmlUi Team, and contributors
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. *
  27. */
  28. #include "ElementTextDefault.h"
  29. #include "ElementDefinition.h"
  30. #include "ElementStyle.h"
  31. #include "../../Include/RmlUi/Core/Core.h"
  32. #include "../../Include/RmlUi/Core/Context.h"
  33. #include "../../Include/RmlUi/Core/ElementDocument.h"
  34. #include "../../Include/RmlUi/Core/ElementUtilities.h"
  35. #include "../../Include/RmlUi/Core/Event.h"
  36. #include "../../Include/RmlUi/Core/FontEngineInterface.h"
  37. #include "../../Include/RmlUi/Core/GeometryUtilities.h"
  38. #include "../../Include/RmlUi/Core/Property.h"
  39. #include "../../Include/RmlUi/Core/Profiling.h"
  40. namespace Rml {
  41. 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);
  42. static bool LastToken(const char* token_begin, const char* string_end, bool collapse_white_space, bool break_at_endline);
  43. ElementTextDefault::ElementTextDefault(const String& tag) : ElementText(tag), colour(255, 255, 255), decoration(this)
  44. {
  45. dirty_layout_on_change = true;
  46. generated_decoration = Style::TextDecoration::None;
  47. decoration_property = Style::TextDecoration::None;
  48. geometry_dirty = true;
  49. font_effects_handle = 0;
  50. font_effects_dirty = true;
  51. font_handle_version = 0;
  52. }
  53. ElementTextDefault::~ElementTextDefault()
  54. {
  55. }
  56. void ElementTextDefault::SetText(const String& _text)
  57. {
  58. if (text != _text)
  59. {
  60. text = _text;
  61. if (dirty_layout_on_change)
  62. DirtyLayout();
  63. }
  64. }
  65. const String& ElementTextDefault::GetText() const
  66. {
  67. return text;
  68. }
  69. void ElementTextDefault::OnRender()
  70. {
  71. RMLUI_ZoneScoped;
  72. FontFaceHandle font_face_handle = GetFontFaceHandle();
  73. if (font_face_handle == 0)
  74. return;
  75. // If our font effects have potentially changed, update it and force a geometry generation if necessary.
  76. if (font_effects_dirty && UpdateFontEffects())
  77. geometry_dirty = true;
  78. // Dirty geometry if font version has changed.
  79. int new_version = GetFontEngineInterface()->GetVersion(font_face_handle);
  80. if (new_version != font_handle_version)
  81. {
  82. font_handle_version = new_version;
  83. geometry_dirty = true;
  84. }
  85. // Regenerate the geometry if the colour or font configuration has altered.
  86. if (geometry_dirty)
  87. GenerateGeometry(font_face_handle);
  88. Vector2f translation = GetAbsoluteOffset();
  89. bool render = true;
  90. Vector2i clip_origin;
  91. Vector2i clip_dimensions;
  92. if (GetContext()->GetActiveClipRegion(clip_origin, clip_dimensions))
  93. {
  94. float clip_top = (float)clip_origin.y;
  95. float clip_left = (float)clip_origin.x;
  96. float clip_right = (float)(clip_origin.x + clip_dimensions.x);
  97. float clip_bottom = (float)(clip_origin.y + clip_dimensions.y);
  98. float line_height = (float)GetFontEngineInterface()->GetLineHeight(GetFontFaceHandle());
  99. render = false;
  100. for (size_t i = 0; i < lines.size(); ++i)
  101. {
  102. const Line& line = lines[i];
  103. float x = translation.x + line.position.x;
  104. float y = translation.y + line.position.y;
  105. bool render_line = !(x > clip_right);
  106. render_line = render_line && !(x + line.width < clip_left);
  107. render_line = render_line && !(y - line_height > clip_bottom);
  108. render_line = render_line && !(y < clip_top);
  109. if (render_line)
  110. {
  111. render = true;
  112. break;
  113. }
  114. }
  115. }
  116. translation = translation.Round();
  117. if (render)
  118. {
  119. for (size_t i = 0; i < geometry.size(); ++i)
  120. geometry[i].Render(translation);
  121. }
  122. if (decoration_property != Style::TextDecoration::None)
  123. decoration.Render(translation);
  124. }
  125. // Generates a token of text from this element, returning only the width.
  126. bool ElementTextDefault::GenerateToken(float& token_width, int line_begin)
  127. {
  128. RMLUI_ZoneScoped;
  129. // Bail if we don't have a valid font face.
  130. FontFaceHandle font_face_handle = GetFontFaceHandle();
  131. if (font_face_handle == 0 ||
  132. line_begin >= (int) text.size())
  133. return 0;
  134. // Determine how we are processing white-space while formatting the text.
  135. using namespace Style;
  136. auto& computed = GetComputedValues();
  137. WhiteSpace white_space_property = computed.white_space;
  138. bool collapse_white_space = white_space_property == WhiteSpace::Normal ||
  139. white_space_property == WhiteSpace::Nowrap ||
  140. white_space_property == WhiteSpace::Preline;
  141. bool break_at_endline = white_space_property == WhiteSpace::Pre ||
  142. white_space_property == WhiteSpace::Prewrap ||
  143. white_space_property == WhiteSpace::Preline;
  144. const char* token_begin = text.c_str() + line_begin;
  145. String token;
  146. BuildToken(token, token_begin, text.c_str() + text.size(), true, collapse_white_space, break_at_endline, computed.text_transform, true);
  147. token_width = (float) GetFontEngineInterface()->GetStringWidth(font_face_handle, token);
  148. return LastToken(token_begin, text.c_str() + text.size(), collapse_white_space, break_at_endline);
  149. }
  150. // Generates a line of text rendered from this element
  151. bool ElementTextDefault::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)
  152. {
  153. RMLUI_ZoneScoped;
  154. FontFaceHandle font_face_handle = GetFontFaceHandle();
  155. // Initialise the output variables.
  156. line.clear();
  157. line_length = 0;
  158. line_width = 0;
  159. // Bail if we don't have a valid font face.
  160. if (font_face_handle == 0)
  161. return true;
  162. // Determine how we are processing white-space while formatting the text.
  163. using namespace Style;
  164. auto& computed = GetComputedValues();
  165. WhiteSpace white_space_property = computed.white_space;
  166. bool collapse_white_space = white_space_property == WhiteSpace::Normal ||
  167. white_space_property == WhiteSpace::Nowrap ||
  168. white_space_property == WhiteSpace::Preline;
  169. bool break_at_line = (maximum_line_width >= 0) &&
  170. (white_space_property == WhiteSpace::Normal ||
  171. white_space_property == WhiteSpace::Prewrap ||
  172. white_space_property == WhiteSpace::Preline);
  173. bool break_at_endline = white_space_property == WhiteSpace::Pre ||
  174. white_space_property == WhiteSpace::Prewrap ||
  175. white_space_property == WhiteSpace::Preline;
  176. TextTransform text_transform_property = computed.text_transform;
  177. WordBreak word_break = computed.word_break;
  178. FontEngineInterface* font_engine_interface = GetFontEngineInterface();
  179. // Starting at the line_begin character, we generate sections of the text (we'll call them tokens) depending on the
  180. // white-space parsing parameters. Each section is then appended to the line if it can fit. If not, or if an
  181. // endline is found (and we're processing them), then the line is ended. kthxbai!
  182. const char* token_begin = text.c_str() + line_begin;
  183. const char* string_end = text.c_str() + text.size();
  184. while (token_begin != string_end)
  185. {
  186. String token;
  187. const char* next_token_begin = token_begin;
  188. Character previous_codepoint = Character::Null;
  189. if (!line.empty())
  190. previous_codepoint = StringUtilities::ToCharacter(StringUtilities::SeekBackwardUTF8(&line.back(), line.data()));
  191. // Generate the next token and determine its pixel-length.
  192. 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);
  193. int token_width = font_engine_interface->GetStringWidth(font_face_handle, token, previous_codepoint);
  194. // If we're breaking to fit a line box, check if the token can fit on the line before we add it.
  195. if (break_at_line)
  196. {
  197. const bool is_last_token = LastToken(next_token_begin, string_end, collapse_white_space, break_at_endline);
  198. int max_token_width = int(maximum_line_width - (is_last_token ? line_width + right_spacing_width : line_width));
  199. if (token_width > max_token_width)
  200. {
  201. if (word_break == WordBreak::BreakAll || (word_break == WordBreak::BreakWord && line.empty()))
  202. {
  203. // Try to break up the word
  204. max_token_width = int(maximum_line_width - line_width);
  205. const int token_max_size = int(next_token_begin - token_begin);
  206. bool force_loop_break_after_next = false;
  207. // @performance: Can be made much faster. Use string width heuristics and logarithmic search.
  208. for (int i = token_max_size - 1; i > 0; --i)
  209. {
  210. token.clear();
  211. next_token_begin = token_begin;
  212. const char* partial_string_end = StringUtilities::SeekBackwardUTF8(token_begin + i, token_begin);
  213. break_line = 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);
  214. token_width = font_engine_interface->GetStringWidth(font_face_handle, token, previous_codepoint);
  215. if (force_loop_break_after_next || token_width <= max_token_width)
  216. {
  217. break;
  218. }
  219. else if (next_token_begin == token_begin)
  220. {
  221. // This means the first character of the token doesn't fit. Let it overflow into the next line if we can.
  222. if (!line.empty())
  223. return false;
  224. // Not even the first character of the line fits. Go back to consume the first character even though it will overflow.
  225. i += 2;
  226. force_loop_break_after_next = true;
  227. }
  228. }
  229. break_line = true;
  230. }
  231. else if (!line.empty())
  232. {
  233. // Let the token overflow into the next line.
  234. return false;
  235. }
  236. }
  237. }
  238. // The token can fit on the end of the line, so add it onto the end and increment our width and length counters.
  239. line += token;
  240. line_length += (int)(next_token_begin - token_begin);
  241. line_width += token_width;
  242. // Break out of the loop if an endline was forced.
  243. if (break_line)
  244. return false;
  245. // Set the beginning of the next token.
  246. token_begin = next_token_begin;
  247. }
  248. return true;
  249. }
  250. // Clears all lines of generated text and prepares the element for generating new lines.
  251. void ElementTextDefault::ClearLines()
  252. {
  253. // Clear the rendering information.
  254. for (size_t i = 0; i < geometry.size(); ++i)
  255. geometry[i].Release(true);
  256. lines.clear();
  257. decoration.Release(true);
  258. }
  259. // Adds a new line into the text element.
  260. void ElementTextDefault::AddLine(const Vector2f& line_position, const String& line)
  261. {
  262. FontFaceHandle font_face_handle = GetFontFaceHandle();
  263. if (font_face_handle == 0)
  264. return;
  265. if (font_effects_dirty)
  266. UpdateFontEffects();
  267. Vector2f baseline_position = line_position + Vector2f(0.0f, (float)GetFontEngineInterface()->GetLineHeight(font_face_handle) - GetFontEngineInterface()->GetBaseline(font_face_handle));
  268. lines.push_back(Line(line, baseline_position));
  269. geometry_dirty = true;
  270. }
  271. // Prevents the element from dirtying its document's layout when its text is changed.
  272. void ElementTextDefault::SuppressAutoLayout()
  273. {
  274. dirty_layout_on_change = false;
  275. }
  276. void ElementTextDefault::OnPropertyChange(const PropertyIdSet& changed_properties)
  277. {
  278. RMLUI_ZoneScoped;
  279. Element::OnPropertyChange(changed_properties);
  280. bool colour_changed = false;
  281. bool font_face_changed = false;
  282. auto& computed = GetComputedValues();
  283. if (changed_properties.Contains(PropertyId::Color) ||
  284. changed_properties.Contains(PropertyId::Opacity))
  285. {
  286. // Fetch our (potentially) new colour.
  287. Colourb new_colour = computed.color;
  288. float opacity = computed.opacity;
  289. new_colour.alpha = byte(opacity * float(new_colour.alpha));
  290. colour_changed = colour != new_colour;
  291. if (colour_changed)
  292. colour = new_colour;
  293. }
  294. if (changed_properties.Contains(PropertyId::FontFamily) ||
  295. changed_properties.Contains(PropertyId::FontWeight) ||
  296. changed_properties.Contains(PropertyId::FontStyle) ||
  297. changed_properties.Contains(PropertyId::FontSize))
  298. {
  299. font_face_changed = true;
  300. geometry.clear();
  301. font_effects_dirty = true;
  302. }
  303. if (changed_properties.Contains(PropertyId::FontEffect))
  304. {
  305. font_effects_dirty = true;
  306. }
  307. if (changed_properties.Contains(PropertyId::TextDecoration))
  308. {
  309. decoration_property = computed.text_decoration;
  310. if (decoration_property != Style::TextDecoration::None)
  311. {
  312. if (decoration_property != generated_decoration)
  313. {
  314. decoration.Release(true);
  315. FontFaceHandle font_face_handle = GetFontFaceHandle();
  316. if (font_face_handle != 0)
  317. {
  318. for (size_t i = 0; i < lines.size(); ++i)
  319. GenerateLineDecoration(font_face_handle, lines[i]);
  320. }
  321. generated_decoration = decoration_property;
  322. }
  323. }
  324. }
  325. if (font_face_changed)
  326. {
  327. // We have to let our document know we need to be regenerated.
  328. if (dirty_layout_on_change)
  329. DirtyLayout();
  330. }
  331. else if (colour_changed)
  332. {
  333. // Force the geometry to be regenerated.
  334. geometry_dirty = true;
  335. // Re-colour the decoration geometry.
  336. Vector< Vertex >& vertices = decoration.GetVertices();
  337. for (size_t i = 0; i < vertices.size(); ++i)
  338. vertices[i].colour = colour;
  339. decoration.Release();
  340. }
  341. }
  342. // Returns the RML of this element
  343. void ElementTextDefault::GetRML(String& content)
  344. {
  345. content += text;
  346. }
  347. // Updates the configuration this element uses for its font.
  348. bool ElementTextDefault::UpdateFontEffects()
  349. {
  350. RMLUI_ZoneScoped;
  351. if (GetFontFaceHandle() == 0)
  352. return false;
  353. font_effects_dirty = false;
  354. static const FontEffectList empty_font_effects;
  355. // Fetch the font-effect for this text element
  356. const FontEffectList* font_effects = &empty_font_effects;
  357. if (const FontEffects* effects = GetComputedValues().font_effect.get())
  358. font_effects = &effects->list;
  359. // Request a font layer configuration to match this set of effects. If this is different from
  360. // our old configuration, then return true to indicate we'll need to regenerate geometry.
  361. FontEffectsHandle new_font_effects_handle = GetFontEngineInterface()->PrepareFontEffects(GetFontFaceHandle(), *font_effects);
  362. if (new_font_effects_handle != font_effects_handle)
  363. {
  364. font_effects_handle = new_font_effects_handle;
  365. return true;
  366. }
  367. return false;
  368. }
  369. // Clears and regenerates all of the text's geometry.
  370. void ElementTextDefault::GenerateGeometry(const FontFaceHandle font_face_handle)
  371. {
  372. RMLUI_ZoneScopedC(0xD2691E);
  373. // Release the old geometry ...
  374. for (size_t i = 0; i < geometry.size(); ++i)
  375. geometry[i].Release(true);
  376. // ... and generate it all again!
  377. for (size_t i = 0; i < lines.size(); ++i)
  378. GenerateGeometry(font_face_handle, lines[i]);
  379. geometry_dirty = false;
  380. }
  381. void ElementTextDefault::GenerateGeometry(const FontFaceHandle font_face_handle, Line& line)
  382. {
  383. line.width = GetFontEngineInterface()->GenerateString(font_face_handle, font_effects_handle, line.text, line.position, colour, geometry);
  384. for (size_t i = 0; i < geometry.size(); ++i)
  385. geometry[i].SetHostElement(this);
  386. if (decoration_property != Style::TextDecoration::None)
  387. GenerateLineDecoration(font_face_handle, line);
  388. }
  389. // Generates any geometry necessary for rendering a line decoration (underline, strike-through, etc).
  390. void ElementTextDefault::GenerateLineDecoration(const FontFaceHandle font_face_handle, const Line& line)
  391. {
  392. RMLUI_ZoneScopedC(0xA52A2A);
  393. GeometryUtilities::GenerateLine(font_face_handle, &decoration, line.position, line.width, decoration_property, colour);
  394. }
  395. 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)
  396. {
  397. RMLUI_ASSERT(token_begin != string_end);
  398. token.reserve(string_end - token_begin + token.size());
  399. // Check what the first character of the token is; all we need to know is if it is white-space or not.
  400. bool parsing_white_space = StringUtilities::IsWhitespace(*token_begin);
  401. // Loop through the string from the token's beginning until we find an end to the token. This can occur in various
  402. // places, depending on the white-space processing;
  403. // - at the end of a section of non-white-space characters,
  404. // - at the end of a section of white-space characters, if we're not collapsing white-space,
  405. // - at an endline token, if we're breaking on endlines.
  406. while (token_begin != string_end)
  407. {
  408. bool force_non_whitespace = false;
  409. char character = *token_begin;
  410. const char* escape_begin = token_begin;
  411. // Check for an ampersand; if we find one, we've got an HTML escaped character.
  412. if (decode_escape_characters && character == '&')
  413. {
  414. // Find the terminating ';'.
  415. while (token_begin != string_end &&
  416. *token_begin != ';')
  417. ++token_begin;
  418. // If we couldn't find the ';', print the token like normal text.
  419. if (token_begin == string_end)
  420. {
  421. token_begin = escape_begin;
  422. }
  423. // We could find a ';', parse the escape code. If the escape code is recognised, set the parsed character
  424. // to the appropriate one. If it is a non-breaking space, prevent it being picked up as whitespace. If it
  425. // is not recognised, print the token like normal text.
  426. else
  427. {
  428. String escape_code(escape_begin + 1, token_begin);
  429. if (escape_code == "lt")
  430. character = '<';
  431. else if (escape_code == "gt")
  432. character = '>';
  433. else if (escape_code == "amp")
  434. character = '&';
  435. else if (escape_code == "quot")
  436. character = '"';
  437. else if (escape_code == "nbsp")
  438. {
  439. character = ' ';
  440. force_non_whitespace = true;
  441. }
  442. else
  443. token_begin = escape_begin;
  444. }
  445. }
  446. // Check for an endline token; if we're breaking on endlines and we find one, then return true to indicate a
  447. // forced break.
  448. if (break_at_endline &&
  449. character == '\n')
  450. {
  451. token += '\n';
  452. token_begin++;
  453. return true;
  454. }
  455. // If we've transitioned from white-space characters to non-white-space characters, or vice-versa, then check
  456. // if should terminate the token; if we're not collapsing white-space, then yes (as sections of white-space are
  457. // non-breaking), otherwise only if we've transitioned from characters to white-space.
  458. bool white_space = !force_non_whitespace && StringUtilities::IsWhitespace(character);
  459. if (white_space != parsing_white_space)
  460. {
  461. if (!collapse_white_space)
  462. {
  463. // Restore pointer to the beginning of the escaped token, if we processed an escape code.
  464. token_begin = escape_begin;
  465. return false;
  466. }
  467. // We're collapsing white-space; we only tokenise words, not white-space, so we're only done tokenising
  468. // once we've begun parsing non-white-space and then found white-space.
  469. if (!parsing_white_space)
  470. {
  471. // However, if we are the last non-whitespace character in the string, and there are trailing
  472. // whitespace characters after this token, then we need to append a single space to the end of this
  473. // token.
  474. if (token_begin != string_end &&
  475. LastToken(token_begin, string_end, collapse_white_space, break_at_endline))
  476. token += ' ';
  477. return false;
  478. }
  479. // We've transitioned from white-space to non-white-space, so we append a single white-space character.
  480. if (!first_token)
  481. token += ' ';
  482. parsing_white_space = false;
  483. }
  484. // If the current character is white-space, we'll append a space character to the token if we're not collapsing
  485. // sections of white-space.
  486. if (white_space)
  487. {
  488. if (!collapse_white_space)
  489. token += ' ';
  490. }
  491. else
  492. {
  493. if (text_transformation == Style::TextTransform::Uppercase)
  494. {
  495. if (character >= 'a' && character <= 'z')
  496. character += ('A' - 'a');
  497. }
  498. else if (text_transformation == Style::TextTransform::Lowercase)
  499. {
  500. if (character >= 'A' && character <= 'Z')
  501. character -= ('A' - 'a');
  502. }
  503. token += character;
  504. }
  505. ++token_begin;
  506. }
  507. return false;
  508. }
  509. static bool LastToken(const char* token_begin, const char* string_end, bool collapse_white_space, bool break_at_endline)
  510. {
  511. bool last_token = (token_begin == string_end);
  512. if (collapse_white_space &&
  513. !last_token)
  514. {
  515. last_token = true;
  516. const char* character = token_begin;
  517. while (character != string_end)
  518. {
  519. if (!StringUtilities::IsWhitespace(*character) ||
  520. (break_at_endline && *character == '\n'))
  521. {
  522. last_token = false;
  523. break;
  524. }
  525. character++;
  526. }
  527. }
  528. return last_token;
  529. }
  530. } // namespace Rml