ElementText.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  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-2023 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 "../../Include/RmlUi/Core/ElementText.h"
  29. #include "../../Include/RmlUi/Core/Context.h"
  30. #include "../../Include/RmlUi/Core/Core.h"
  31. #include "../../Include/RmlUi/Core/ElementDocument.h"
  32. #include "../../Include/RmlUi/Core/ElementUtilities.h"
  33. #include "../../Include/RmlUi/Core/Event.h"
  34. #include "../../Include/RmlUi/Core/FontEngineInterface.h"
  35. #include "../../Include/RmlUi/Core/GeometryUtilities.h"
  36. #include "../../Include/RmlUi/Core/Profiling.h"
  37. #include "../../Include/RmlUi/Core/Property.h"
  38. #include "../../Include/RmlUi/Core/TextShapingContext.h"
  39. #include "ComputeProperty.h"
  40. #include "ElementDefinition.h"
  41. #include "ElementStyle.h"
  42. namespace Rml {
  43. static bool BuildToken(String& token, const char*& token_begin, const char* string_end, bool first_token, bool collapse_white_space,
  44. bool break_at_endline, Style::TextTransform text_transformation, bool decode_escape_characters);
  45. static bool LastToken(const char* token_begin, const char* string_end, bool collapse_white_space, bool break_at_endline);
  46. void LogMissingFontFace(Element* element)
  47. {
  48. const String font_family_property = element->GetProperty<String>("font-family");
  49. if (font_family_property.empty())
  50. {
  51. Log::Message(Log::LT_WARNING, "No font face defined. Missing 'font-family' property. On element %s", element->GetAddress().c_str());
  52. }
  53. else
  54. {
  55. const ComputedValues& computed = element->GetComputedValues();
  56. const String font_face_description = GetFontFaceDescription(font_family_property, computed.font_style(), computed.font_weight());
  57. Log::Message(Log::LT_WARNING,
  58. "No font face defined. Ensure (1) that Context::Update is run after new elements are constructed, before Context::Render, "
  59. "and (2) that the specified font face %s has been successfully loaded. "
  60. "Please see previous log messages for all successfully loaded fonts. On element %s",
  61. font_face_description.c_str(), element->GetAddress().c_str());
  62. }
  63. }
  64. ElementText::ElementText(const String& tag) :
  65. Element(tag), colour(255, 255, 255), opacity(1), font_handle_version(0), geometry_dirty(true), dirty_layout_on_change(true),
  66. generated_decoration(Style::TextDecoration::None), decoration_property(Style::TextDecoration::None), font_effects_dirty(true),
  67. font_effects_handle(0)
  68. {}
  69. ElementText::~ElementText() {}
  70. void ElementText::SetText(const String& _text)
  71. {
  72. if (text != _text)
  73. {
  74. text = _text;
  75. if (dirty_layout_on_change)
  76. DirtyLayout();
  77. }
  78. }
  79. const String& ElementText::GetText() const
  80. {
  81. return text;
  82. }
  83. void ElementText::OnRender()
  84. {
  85. RMLUI_ZoneScoped;
  86. FontFaceHandle font_face_handle = GetFontFaceHandle();
  87. if (font_face_handle == 0)
  88. return;
  89. // If our font effects have potentially changed, update it and force a geometry generation if necessary.
  90. if (font_effects_dirty && UpdateFontEffects())
  91. geometry_dirty = true;
  92. // Dirty geometry if font version has changed.
  93. int new_version = GetFontEngineInterface()->GetVersion(font_face_handle);
  94. if (new_version != font_handle_version)
  95. {
  96. font_handle_version = new_version;
  97. geometry_dirty = true;
  98. }
  99. // Regenerate the geometry if the colour or font configuration has altered.
  100. if (geometry_dirty)
  101. GenerateGeometry(font_face_handle);
  102. // Regenerate text decoration if necessary.
  103. if (decoration_property != generated_decoration)
  104. {
  105. if (decoration_property == Style::TextDecoration::None)
  106. {
  107. decoration.reset();
  108. }
  109. else
  110. {
  111. if (decoration)
  112. decoration->Release(true);
  113. else
  114. decoration = MakeUnique<Geometry>();
  115. GenerateDecoration(font_face_handle);
  116. }
  117. generated_decoration = decoration_property;
  118. }
  119. const Vector2f translation = GetAbsoluteOffset();
  120. bool render = true;
  121. Vector2i clip_origin;
  122. Vector2i clip_dimensions;
  123. if (GetContext()->GetActiveClipRegion(clip_origin, clip_dimensions))
  124. {
  125. const FontMetrics& font_metrics = GetFontEngineInterface()->GetFontMetrics(GetFontFaceHandle());
  126. float clip_top = (float)clip_origin.y;
  127. float clip_left = (float)clip_origin.x;
  128. float clip_right = (float)(clip_origin.x + clip_dimensions.x);
  129. float clip_bottom = (float)(clip_origin.y + clip_dimensions.y);
  130. float ascent = font_metrics.ascent;
  131. float descent = font_metrics.descent;
  132. render = false;
  133. for (const Line& line : lines)
  134. {
  135. float x_left = translation.x + line.position.x;
  136. float x_right = x_left + line.width;
  137. float y = translation.y + line.position.y;
  138. float y_top = y - ascent;
  139. float y_bottom = y + descent;
  140. render = !(x_left > clip_right || x_right < clip_left || y_top > clip_bottom || y_bottom < clip_top);
  141. if (render)
  142. break;
  143. }
  144. }
  145. if (render)
  146. {
  147. for (size_t i = 0; i < geometry.size(); ++i)
  148. geometry[i].Render(translation);
  149. }
  150. if (decoration)
  151. decoration->Render(translation);
  152. }
  153. bool ElementText::GenerateLine(String& line, int& line_length, float& line_width, int line_begin, float maximum_line_width, float right_spacing_width,
  154. bool trim_whitespace_prefix, bool decode_escape_characters, bool allow_empty)
  155. {
  156. RMLUI_ZoneScoped;
  157. RMLUI_ASSERT(
  158. maximum_line_width >= 0.f); // TODO: Check all callers for conformance, check break at line condition below. Possibly check for FLT_MAX.
  159. FontFaceHandle font_face_handle = GetFontFaceHandle();
  160. // Initialise the output variables.
  161. line.clear();
  162. line_length = 0;
  163. line_width = 0;
  164. // Bail if we don't have a valid font face.
  165. if (font_face_handle == 0)
  166. {
  167. LogMissingFontFace(GetParentNode() ? GetParentNode() : this);
  168. return true;
  169. }
  170. // Determine how we are processing white-space while formatting the text.
  171. using namespace Style;
  172. const auto& computed = GetComputedValues();
  173. WhiteSpace white_space_property = computed.white_space();
  174. bool collapse_white_space =
  175. white_space_property == WhiteSpace::Normal || white_space_property == WhiteSpace::Nowrap || white_space_property == WhiteSpace::Preline;
  176. bool break_at_line = (maximum_line_width >= 0) &&
  177. (white_space_property == WhiteSpace::Normal || white_space_property == WhiteSpace::Prewrap || white_space_property == WhiteSpace::Preline);
  178. bool break_at_endline =
  179. white_space_property == WhiteSpace::Pre || white_space_property == WhiteSpace::Prewrap || white_space_property == WhiteSpace::Preline;
  180. const TextShapingContext text_shaping_context{ computed.language(), computed.direction(), computed.letter_spacing() };
  181. TextTransform text_transform_property = computed.text_transform();
  182. WordBreak word_break = computed.word_break();
  183. FontEngineInterface* font_engine_interface = GetFontEngineInterface();
  184. // Starting at the line_begin character, we generate sections of the text (we'll call them tokens) depending on the
  185. // white-space parsing parameters. Each section is then appended to the line if it can fit. If not, or if an
  186. // endline is found (and we're processing them), then the line is ended. kthxbai!
  187. const char* token_begin = text.c_str() + line_begin;
  188. const char* string_end = text.c_str() + text.size();
  189. while (token_begin != string_end)
  190. {
  191. String token;
  192. const char* next_token_begin = token_begin;
  193. Character previous_codepoint = Character::Null;
  194. if (!line.empty())
  195. previous_codepoint = StringUtilities::ToCharacter(StringUtilities::SeekBackwardUTF8(&line.back(), line.data()));
  196. // Generate the next token and determine its pixel-length.
  197. bool break_line = BuildToken(token, next_token_begin, string_end, line.empty() && trim_whitespace_prefix, collapse_white_space,
  198. break_at_endline, text_transform_property, decode_escape_characters);
  199. int token_width = font_engine_interface->GetStringWidth(font_face_handle, token, text_shaping_context, previous_codepoint);
  200. // If we're breaking to fit a line box, check if the token can fit on the line before we add it.
  201. if (break_at_line)
  202. {
  203. const bool is_last_token = LastToken(next_token_begin, string_end, collapse_white_space, break_at_endline);
  204. int max_token_width = int(maximum_line_width - (is_last_token ? line_width + right_spacing_width : line_width));
  205. if (token_width > max_token_width)
  206. {
  207. if (word_break == WordBreak::BreakAll || (word_break == WordBreak::BreakWord && line.empty()))
  208. {
  209. // Try to break up the word
  210. max_token_width = int(maximum_line_width - line_width);
  211. const int token_max_size = int(next_token_begin - token_begin);
  212. bool force_loop_break_after_next = false;
  213. // @performance: Can be made much faster. Use string width heuristics and logarithmic search.
  214. for (int i = token_max_size - 1; i > 0; --i)
  215. {
  216. token.clear();
  217. next_token_begin = token_begin;
  218. const char* partial_string_end = StringUtilities::SeekBackwardUTF8(token_begin + i, token_begin);
  219. BuildToken(token, next_token_begin, partial_string_end, line.empty() && trim_whitespace_prefix, collapse_white_space,
  220. break_at_endline, text_transform_property, decode_escape_characters);
  221. token_width = font_engine_interface->GetStringWidth(font_face_handle, token, text_shaping_context, previous_codepoint);
  222. if (force_loop_break_after_next || token_width <= max_token_width)
  223. {
  224. break;
  225. }
  226. else if (next_token_begin == token_begin)
  227. {
  228. // This means the first character of the token doesn't fit. Let it overflow into the next line if we can.
  229. if (allow_empty || !line.empty())
  230. return false;
  231. // Not even the first character of the line fits. Go back to consume the first character even though it will overflow.
  232. i += 2;
  233. force_loop_break_after_next = true;
  234. }
  235. }
  236. break_line = true;
  237. }
  238. else if (allow_empty || !line.empty())
  239. {
  240. // Let the token overflow into the next line.
  241. return false;
  242. }
  243. }
  244. }
  245. // The token can fit on the end of the line, so add it onto the end and increment our width and length counters.
  246. line += token;
  247. line_length += (int)(next_token_begin - token_begin);
  248. line_width += token_width;
  249. // Break out of the loop if an endline was forced.
  250. if (break_line && (allow_empty || !line.empty()))
  251. return false;
  252. // Set the beginning of the next token.
  253. token_begin = next_token_begin;
  254. }
  255. return true;
  256. }
  257. void ElementText::ClearLines()
  258. {
  259. // Clear the rendering information.
  260. for (size_t i = 0; i < geometry.size(); ++i)
  261. geometry[i].Release(true);
  262. lines.clear();
  263. generated_decoration = Style::TextDecoration::None;
  264. }
  265. void ElementText::AddLine(Vector2f line_position, String line)
  266. {
  267. if (font_effects_dirty)
  268. UpdateFontEffects();
  269. lines.emplace_back(std::move(line), line_position);
  270. geometry_dirty = true;
  271. }
  272. void ElementText::SuppressAutoLayout()
  273. {
  274. dirty_layout_on_change = false;
  275. }
  276. void ElementText::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) || changed_properties.Contains(PropertyId::Opacity))
  284. {
  285. const float new_opacity = computed.opacity();
  286. const bool opacity_changed = opacity != new_opacity;
  287. Colourb new_colour = computed.color();
  288. new_colour.alpha = byte(new_opacity * float(new_colour.alpha));
  289. colour_changed = colour != new_colour;
  290. if (colour_changed)
  291. {
  292. colour = new_colour;
  293. }
  294. if (opacity_changed)
  295. {
  296. opacity = new_opacity;
  297. font_effects_dirty = true;
  298. geometry_dirty = true;
  299. }
  300. }
  301. if (changed_properties.Contains(PropertyId::FontFamily) || //
  302. changed_properties.Contains(PropertyId::FontWeight) || //
  303. changed_properties.Contains(PropertyId::FontStyle) || //
  304. changed_properties.Contains(PropertyId::FontSize) || //
  305. changed_properties.Contains(PropertyId::LetterSpacing) || //
  306. changed_properties.Contains(PropertyId::RmlUi_Language) || //
  307. changed_properties.Contains(PropertyId::RmlUi_Direction))
  308. {
  309. font_face_changed = true;
  310. geometry.clear();
  311. geometry_dirty = true;
  312. font_effects_handle = 0;
  313. font_effects_dirty = true;
  314. font_handle_version = 0;
  315. }
  316. if (changed_properties.Contains(PropertyId::FontEffect))
  317. {
  318. font_effects_dirty = true;
  319. }
  320. if (changed_properties.Contains(PropertyId::TextDecoration))
  321. {
  322. decoration_property = computed.text_decoration();
  323. if (decoration && decoration_property == Style::TextDecoration::None)
  324. decoration.reset();
  325. }
  326. if (font_face_changed)
  327. {
  328. // We have to let our document know we need to be regenerated.
  329. if (dirty_layout_on_change)
  330. DirtyLayout();
  331. }
  332. else if (colour_changed)
  333. {
  334. // Force the geometry to be regenerated.
  335. geometry_dirty = true;
  336. // Re-colour the decoration geometry.
  337. if (decoration)
  338. {
  339. Vector<Vertex>& vertices = decoration->GetVertices();
  340. for (size_t i = 0; i < vertices.size(); ++i)
  341. vertices[i].colour = colour;
  342. decoration->Release();
  343. }
  344. }
  345. }
  346. void ElementText::GetRML(String& content)
  347. {
  348. content += StringUtilities::EncodeRml(text);
  349. }
  350. bool ElementText::UpdateFontEffects()
  351. {
  352. RMLUI_ZoneScoped;
  353. if (GetFontFaceHandle() == 0)
  354. return false;
  355. font_effects_dirty = false;
  356. static const FontEffectList empty_font_effects;
  357. // Fetch the font-effect for this text element
  358. const FontEffectList* font_effects = &empty_font_effects;
  359. if (GetComputedValues().has_font_effect())
  360. {
  361. if (const Property* p = GetProperty(PropertyId::FontEffect))
  362. if (FontEffectsPtr effects = p->Get<FontEffectsPtr>())
  363. font_effects = &effects->list;
  364. }
  365. // Request a font layer configuration to match this set of effects. If this is different from
  366. // our old configuration, then return true to indicate we'll need to regenerate geometry.
  367. FontEffectsHandle new_font_effects_handle = GetFontEngineInterface()->PrepareFontEffects(GetFontFaceHandle(), *font_effects);
  368. if (new_font_effects_handle != font_effects_handle)
  369. {
  370. font_effects_handle = new_font_effects_handle;
  371. return true;
  372. }
  373. return false;
  374. }
  375. void ElementText::GenerateGeometry(const FontFaceHandle font_face_handle)
  376. {
  377. RMLUI_ZoneScopedC(0xD2691E);
  378. // Release the old geometry ...
  379. for (size_t i = 0; i < geometry.size(); ++i)
  380. geometry[i].Release(true);
  381. // ... and generate it all again!
  382. for (size_t i = 0; i < lines.size(); ++i)
  383. GenerateGeometry(font_face_handle, lines[i]);
  384. generated_decoration = Style::TextDecoration::None;
  385. geometry_dirty = false;
  386. }
  387. void ElementText::GenerateGeometry(const FontFaceHandle font_face_handle, Line& line)
  388. {
  389. const auto& computed = GetComputedValues();
  390. const TextShapingContext text_shaping_context{ computed.language(), computed.direction(), computed.letter_spacing() };
  391. line.width = GetFontEngineInterface()->GenerateString(font_face_handle, font_effects_handle, line.text, line.position, colour, opacity,
  392. text_shaping_context, geometry);
  393. }
  394. void ElementText::GenerateDecoration(const FontFaceHandle font_face_handle)
  395. {
  396. RMLUI_ZoneScopedC(0xA52A2A);
  397. RMLUI_ASSERT(decoration);
  398. const FontMetrics& metrics = GetFontEngineInterface()->GetFontMetrics(font_face_handle);
  399. float offset = 0.f;
  400. switch (decoration_property)
  401. {
  402. case Style::TextDecoration::Underline: offset = metrics.underline_position; break;
  403. case Style::TextDecoration::Overline: offset = -1.1f * metrics.ascent; break;
  404. case Style::TextDecoration::LineThrough: offset = -0.65f * metrics.x_height; break;
  405. case Style::TextDecoration::None: return;
  406. }
  407. for (const Line& line : lines)
  408. {
  409. const Vector2f position = {line.position.x, line.position.y + offset};
  410. const Vector2f size = {(float)line.width, metrics.underline_thickness};
  411. GeometryUtilities::GenerateLine(decoration.get(), position, size, colour);
  412. }
  413. }
  414. static bool BuildToken(String& token, const char*& token_begin, const char* string_end, bool first_token, bool collapse_white_space,
  415. bool break_at_endline, Style::TextTransform text_transformation, bool decode_escape_characters)
  416. {
  417. RMLUI_ASSERT(token_begin != string_end);
  418. token.reserve(string_end - token_begin + token.size());
  419. // Check what the first character of the token is; all we need to know is if it is white-space or not.
  420. bool parsing_white_space = StringUtilities::IsWhitespace(*token_begin);
  421. // Loop through the string from the token's beginning until we find an end to the token. This can occur in various
  422. // places, depending on the white-space processing;
  423. // - at the end of a section of non-white-space characters,
  424. // - at the end of a section of white-space characters, if we're not collapsing white-space,
  425. // - at an endline token, if we're breaking on endlines.
  426. while (token_begin != string_end)
  427. {
  428. bool force_non_whitespace = false;
  429. char character = *token_begin;
  430. const char* escape_begin = token_begin;
  431. // Check for an ampersand; if we find one, we've got an HTML escaped character.
  432. if (decode_escape_characters && character == '&')
  433. {
  434. // Find the terminating ';'.
  435. while (token_begin != string_end && *token_begin != ';')
  436. ++token_begin;
  437. // If we couldn't find the ';', print the token like normal text.
  438. if (token_begin == string_end)
  439. {
  440. token_begin = escape_begin;
  441. }
  442. // We could find a ';', parse the escape code. If the escape code is recognised, set the parsed character
  443. // to the appropriate one. If it is a non-breaking space, prevent it being picked up as whitespace. If it
  444. // is not recognised, print the token like normal text.
  445. else
  446. {
  447. String escape_code(escape_begin + 1, token_begin);
  448. if (escape_code == "lt")
  449. character = '<';
  450. else if (escape_code == "gt")
  451. character = '>';
  452. else if (escape_code == "amp")
  453. character = '&';
  454. else if (escape_code == "quot")
  455. character = '"';
  456. else if (escape_code == "nbsp")
  457. {
  458. character = ' ';
  459. force_non_whitespace = true;
  460. }
  461. else
  462. token_begin = escape_begin;
  463. }
  464. }
  465. // Check for an endline token; if we're breaking on endlines and we find one, then return true to indicate a
  466. // forced break.
  467. if (break_at_endline && character == '\n')
  468. {
  469. token += '\n';
  470. token_begin++;
  471. return true;
  472. }
  473. // If we've transitioned from white-space characters to non-white-space characters, or vice-versa, then check
  474. // if should terminate the token; if we're not collapsing white-space, then yes (as sections of white-space are
  475. // non-breaking), otherwise only if we've transitioned from characters to white-space.
  476. bool white_space = !force_non_whitespace && StringUtilities::IsWhitespace(character);
  477. if (white_space != parsing_white_space)
  478. {
  479. if (!collapse_white_space)
  480. {
  481. // Restore pointer to the beginning of the escaped token, if we processed an escape code.
  482. token_begin = escape_begin;
  483. return false;
  484. }
  485. // We're collapsing white-space; we only tokenise words, not white-space, so we're only done tokenising
  486. // once we've begun parsing non-white-space and then found white-space.
  487. if (!parsing_white_space)
  488. {
  489. // However, if we are the last non-whitespace character in the string, and there are trailing
  490. // whitespace characters after this token, then we need to append a single space to the end of this
  491. // token.
  492. if (token_begin != string_end && LastToken(token_begin, string_end, collapse_white_space, break_at_endline))
  493. token += ' ';
  494. return false;
  495. }
  496. // We've transitioned from white-space to non-white-space, so we append a single white-space character.
  497. if (!first_token)
  498. token += ' ';
  499. parsing_white_space = false;
  500. }
  501. // If the current character is white-space, we'll append a space character to the token if we're not collapsing
  502. // sections of white-space.
  503. if (white_space)
  504. {
  505. if (!collapse_white_space)
  506. token += ' ';
  507. }
  508. else
  509. {
  510. if (text_transformation == Style::TextTransform::Uppercase)
  511. {
  512. if (character >= 'a' && character <= 'z')
  513. character += ('A' - 'a');
  514. }
  515. else if (text_transformation == Style::TextTransform::Lowercase)
  516. {
  517. if (character >= 'A' && character <= 'Z')
  518. character -= ('A' - 'a');
  519. }
  520. token += character;
  521. }
  522. ++token_begin;
  523. }
  524. return false;
  525. }
  526. static bool LastToken(const char* token_begin, const char* string_end, bool collapse_white_space, bool break_at_endline)
  527. {
  528. bool last_token = (token_begin == string_end);
  529. if (collapse_white_space && !last_token)
  530. {
  531. last_token = true;
  532. const char* character = token_begin;
  533. while (character != string_end)
  534. {
  535. if (!StringUtilities::IsWhitespace(*character) || (break_at_endline && *character == '\n'))
  536. {
  537. last_token = false;
  538. break;
  539. }
  540. character++;
  541. }
  542. }
  543. return last_token;
  544. }
  545. } // namespace Rml