Text.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. //
  2. // Copyright (c) 2008-2014 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include "Precompiled.h"
  23. #include "Context.h"
  24. #include "Font.h"
  25. #include "Log.h"
  26. #include "Profiler.h"
  27. #include "ResourceCache.h"
  28. #include "Text.h"
  29. #include "Texture2D.h"
  30. #include "DebugNew.h"
  31. namespace Urho3D
  32. {
  33. const char* textEffects[] =
  34. {
  35. "None",
  36. "Shadow",
  37. "Stroke",
  38. 0
  39. };
  40. static const float MIN_ROW_SPACING = 0.5f;
  41. extern const char* horizontalAlignments[];
  42. extern const char* UI_CATEGORY;
  43. Text::Text(Context* context) :
  44. UIElement(context),
  45. fontSize_(DEFAULT_FONT_SIZE),
  46. textAlignment_(HA_LEFT),
  47. rowSpacing_(1.0f),
  48. wordWrap_(false),
  49. charPositionsDirty_(true),
  50. selectionStart_(0),
  51. selectionLength_(0),
  52. selectionColor_(Color::TRANSPARENT),
  53. hoverColor_(Color::TRANSPARENT),
  54. textEffect_(TE_NONE),
  55. effectColor_(Color::BLACK),
  56. effectDepthBias_(0.0f),
  57. rowHeight_(0)
  58. {
  59. // By default Text does not derive opacity from parent elements
  60. useDerivedOpacity_ = false;
  61. }
  62. Text::~Text()
  63. {
  64. }
  65. void Text::RegisterObject(Context* context)
  66. {
  67. context->RegisterFactory<Text>(UI_CATEGORY);
  68. COPY_BASE_ATTRIBUTES(Text, UIElement);
  69. UPDATE_ATTRIBUTE_DEFAULT_VALUE(Text, "Use Derived Opacity", false);
  70. ACCESSOR_ATTRIBUTE(Text, VAR_RESOURCEREF, "Font", GetFontAttr, SetFontAttr, ResourceRef, ResourceRef(Font::GetTypeStatic()), AM_FILE);
  71. ATTRIBUTE(Text, VAR_INT, "Font Size", fontSize_, DEFAULT_FONT_SIZE, AM_FILE);
  72. ATTRIBUTE(Text, VAR_STRING, "Text", text_, String::EMPTY, AM_FILE);
  73. ENUM_ATTRIBUTE(Text, "Text Alignment", textAlignment_, horizontalAlignments, HA_LEFT, AM_FILE);
  74. ATTRIBUTE(Text, VAR_FLOAT, "Row Spacing", rowSpacing_, 1.0f, AM_FILE);
  75. ATTRIBUTE(Text, VAR_BOOL, "Word Wrap", wordWrap_, false, AM_FILE);
  76. REF_ACCESSOR_ATTRIBUTE(Text, VAR_COLOR, "Selection Color", GetSelectionColor, SetSelectionColor, Color, Color::TRANSPARENT, AM_FILE);
  77. REF_ACCESSOR_ATTRIBUTE(Text, VAR_COLOR, "Hover Color", GetHoverColor, SetHoverColor, Color, Color::TRANSPARENT, AM_FILE);
  78. ENUM_ATTRIBUTE(Text, "Text Effect", textEffect_, textEffects, TE_NONE, AM_FILE);
  79. REF_ACCESSOR_ATTRIBUTE(Text, VAR_COLOR, "Effect Color", GetEffectColor, SetEffectColor, Color, Color::BLACK, AM_FILE);
  80. // Change the default value for UseDerivedOpacity
  81. context->GetAttribute<Text>("Use Derived Opacity")->defaultValue_ = false;
  82. }
  83. void Text::ApplyAttributes()
  84. {
  85. UIElement::ApplyAttributes();
  86. // Decode to Unicode now
  87. unicodeText_.Clear();
  88. for (unsigned i = 0; i < text_.Length();)
  89. unicodeText_.Push(text_.NextUTF8Char(i));
  90. fontSize_ = Max(fontSize_, 1);
  91. ValidateSelection();
  92. UpdateText();
  93. }
  94. void Text::GetBatches(PODVector<UIBatch>& batches, PODVector<float>& vertexData, const IntRect& currentScissor)
  95. {
  96. // Hovering and/or whole selection batch
  97. if ((hovering_ && hoverColor_.a_ > 0.0) || (selected_ && selectionColor_.a_ > 0.0f))
  98. {
  99. bool both = hovering_ && selected_ && hoverColor_.a_ > 0.0 && selectionColor_.a_ > 0.0f;
  100. UIBatch batch(this, BLEND_ALPHA, currentScissor, 0, &vertexData);
  101. batch.SetColor(both ? selectionColor_.Lerp(hoverColor_, 0.5f) : (selected_ && selectionColor_.a_ > 0.0f ?
  102. selectionColor_: hoverColor_));
  103. batch.AddQuad(0, 0, GetWidth(), GetHeight(), 0, 0);
  104. UIBatch::AddOrMerge(batch, batches);
  105. }
  106. // Partial selection batch
  107. if (!selected_ && selectionLength_ && charSizes_.Size() >= selectionStart_ + selectionLength_ && selectionColor_.a_ > 0.0f)
  108. {
  109. UIBatch batch(this, BLEND_ALPHA, currentScissor, 0, &vertexData);
  110. batch.SetColor(selectionColor_);
  111. IntVector2 currentStart = charPositions_[selectionStart_];
  112. IntVector2 currentEnd = currentStart;
  113. for (unsigned i = selectionStart_; i < selectionStart_ + selectionLength_; ++i)
  114. {
  115. // Check if row changes, and start a new quad in that case
  116. if (charSizes_[i].x_ && charSizes_[i].y_)
  117. {
  118. if (charPositions_[i].y_ != currentStart.y_)
  119. {
  120. batch.AddQuad(currentStart.x_, currentStart.y_, currentEnd.x_ - currentStart.x_, currentEnd.y_ - currentStart.y_,
  121. 0, 0);
  122. currentStart = charPositions_[i];
  123. currentEnd = currentStart + charSizes_[i];
  124. }
  125. else
  126. {
  127. currentEnd.x_ += charSizes_[i].x_;
  128. currentEnd.y_ = Max(currentStart.y_ + charSizes_[i].y_, currentEnd.y_);
  129. }
  130. }
  131. }
  132. if (currentEnd != currentStart)
  133. {
  134. batch.AddQuad(currentStart.x_, currentStart.y_, currentEnd.x_ - currentStart.x_, currentEnd.y_ - currentStart.y_,
  135. 0, 0);
  136. }
  137. UIBatch::AddOrMerge(batch, batches);
  138. }
  139. // Text batch
  140. if (font_)
  141. {
  142. FontFace* face = font_->GetFace(fontSize_);
  143. if (!face)
  144. return;
  145. if (charPositionsDirty_ || !fontFace_ || face != fontFace_)
  146. UpdateCharPositions();
  147. const Vector<SharedPtr<Texture2D> >& textures = face->GetTextures();
  148. for (unsigned n = 0; n < textures.Size() && n < pageGlyphLocations_.Size(); ++n)
  149. {
  150. // One batch per texture/page
  151. UIBatch pageBatch(this, BLEND_ALPHA, currentScissor, textures[n], &vertexData);
  152. const PODVector<GlyphLocation>& pageGlyphLocation = pageGlyphLocations_[n];
  153. switch (textEffect_)
  154. {
  155. case TE_NONE:
  156. ConstructBatch(pageBatch, pageGlyphLocation, 0, 0);
  157. break;
  158. case TE_SHADOW:
  159. ConstructBatch(pageBatch, pageGlyphLocation, 1, 1, &effectColor_, effectDepthBias_);
  160. ConstructBatch(pageBatch, pageGlyphLocation, 0, 0);
  161. break;
  162. case TE_STROKE:
  163. ConstructBatch(pageBatch, pageGlyphLocation, -1, -1, &effectColor_, effectDepthBias_);
  164. ConstructBatch(pageBatch, pageGlyphLocation, 0, -1, &effectColor_, effectDepthBias_);
  165. ConstructBatch(pageBatch, pageGlyphLocation, 1, -1, &effectColor_, effectDepthBias_);
  166. ConstructBatch(pageBatch, pageGlyphLocation, -1, 0, &effectColor_, effectDepthBias_);
  167. ConstructBatch(pageBatch, pageGlyphLocation, 1, 0, &effectColor_, effectDepthBias_);
  168. ConstructBatch(pageBatch, pageGlyphLocation, -1, 1, &effectColor_, effectDepthBias_);
  169. ConstructBatch(pageBatch, pageGlyphLocation, 0, 1, &effectColor_, effectDepthBias_);
  170. ConstructBatch(pageBatch, pageGlyphLocation, 1, 1, &effectColor_, effectDepthBias_);
  171. ConstructBatch(pageBatch, pageGlyphLocation, 0, 0);
  172. break;
  173. }
  174. UIBatch::AddOrMerge(pageBatch, batches);
  175. }
  176. }
  177. // Reset hovering for next frame
  178. hovering_ = false;
  179. }
  180. void Text::OnResize()
  181. {
  182. if (wordWrap_)
  183. UpdateText();
  184. else
  185. charPositionsDirty_ = true;
  186. }
  187. void Text::OnIndentSet()
  188. {
  189. charPositionsDirty_ = true;
  190. }
  191. bool Text::SetFont(const String& fontName, int size)
  192. {
  193. ResourceCache* cache = GetSubsystem<ResourceCache>();
  194. return SetFont(cache->GetResource<Font>(fontName), size);
  195. }
  196. bool Text::SetFont(Font* font, int size)
  197. {
  198. if (!font)
  199. {
  200. LOGERROR("Null font for Text");
  201. return false;
  202. }
  203. if (font != font_ || size != fontSize_)
  204. {
  205. font_ = font;
  206. fontSize_ = Max(size, 1);
  207. UpdateText();
  208. }
  209. return true;
  210. }
  211. void Text::SetText(const String& text)
  212. {
  213. text_ = text;
  214. // Decode to Unicode now
  215. unicodeText_.Clear();
  216. for (unsigned i = 0; i < text_.Length();)
  217. unicodeText_.Push(text_.NextUTF8Char(i));
  218. ValidateSelection();
  219. UpdateText();
  220. }
  221. void Text::SetTextAlignment(HorizontalAlignment align)
  222. {
  223. if (align != textAlignment_)
  224. {
  225. textAlignment_ = align;
  226. charPositionsDirty_ = true;
  227. }
  228. }
  229. void Text::SetRowSpacing(float spacing)
  230. {
  231. if (spacing != rowSpacing_)
  232. {
  233. rowSpacing_ = Max(spacing, MIN_ROW_SPACING);
  234. UpdateText();
  235. }
  236. }
  237. void Text::SetWordwrap(bool enable)
  238. {
  239. if (enable != wordWrap_)
  240. {
  241. wordWrap_ = enable;
  242. UpdateText();
  243. }
  244. }
  245. void Text::SetSelection(unsigned start, unsigned length)
  246. {
  247. selectionStart_ = start;
  248. selectionLength_ = length;
  249. ValidateSelection();
  250. }
  251. void Text::ClearSelection()
  252. {
  253. selectionStart_ = 0;
  254. selectionLength_ = 0;
  255. }
  256. void Text::SetSelectionColor(const Color& color)
  257. {
  258. selectionColor_ = color;
  259. }
  260. void Text::SetHoverColor(const Color& color)
  261. {
  262. hoverColor_ = color;
  263. }
  264. void Text::SetTextEffect(TextEffect textEffect)
  265. {
  266. textEffect_ = textEffect;
  267. }
  268. void Text::SetEffectColor(const Color& effectColor)
  269. {
  270. effectColor_ = effectColor;
  271. }
  272. void Text::SetEffectDepthBias(float bias)
  273. {
  274. effectDepthBias_ = bias;
  275. }
  276. const PODVector<IntVector2>& Text::GetCharPositions()
  277. {
  278. if (charPositionsDirty_)
  279. UpdateCharPositions();
  280. return charPositions_;
  281. }
  282. const PODVector<IntVector2>& Text::GetCharSizes()
  283. {
  284. if (charPositionsDirty_)
  285. UpdateCharPositions();
  286. return charSizes_;
  287. }
  288. void Text::SetFontAttr(ResourceRef value)
  289. {
  290. ResourceCache* cache = GetSubsystem<ResourceCache>();
  291. font_ = cache->GetResource<Font>(value.name_);
  292. }
  293. ResourceRef Text::GetFontAttr() const
  294. {
  295. return GetResourceRef(font_, Font::GetTypeStatic());
  296. }
  297. bool Text::FilterImplicitAttributes(XMLElement& dest) const
  298. {
  299. if (!UIElement::FilterImplicitAttributes(dest))
  300. return false;
  301. if (!IsFixedWidth())
  302. {
  303. if (!RemoveChildXML(dest, "Size"))
  304. return false;
  305. if (!RemoveChildXML(dest, "Min Size"))
  306. return false;
  307. if (!RemoveChildXML(dest, "Max Size"))
  308. return false;
  309. }
  310. return true;
  311. }
  312. void Text::UpdateText()
  313. {
  314. rowWidths_.Clear();
  315. printText_.Clear();
  316. if (font_)
  317. {
  318. FontFace* face = font_->GetFace(fontSize_);
  319. if (!face)
  320. return;
  321. rowHeight_ = face->GetRowHeight();
  322. int width = 0;
  323. int height = 0;
  324. int rowWidth = 0;
  325. int rowHeight = (int)(rowSpacing_ * rowHeight_);
  326. // First see if the text must be split up
  327. if (!wordWrap_)
  328. {
  329. printText_ = unicodeText_;
  330. printToText_.Resize(printText_.Size());
  331. for (unsigned i = 0; i < printText_.Size(); ++i)
  332. printToText_[i] = i;
  333. }
  334. else
  335. {
  336. int maxWidth = GetWidth();
  337. unsigned nextBreak = 0;
  338. unsigned lineStart = 0;
  339. printToText_.Clear();
  340. for (unsigned i = 0; i < unicodeText_.Size(); ++i)
  341. {
  342. unsigned j;
  343. unsigned c = unicodeText_[i];
  344. if (c != '\n')
  345. {
  346. bool ok = true;
  347. if (nextBreak <= i)
  348. {
  349. int futureRowWidth = rowWidth;
  350. for (j = i; j < unicodeText_.Size(); ++j)
  351. {
  352. unsigned d = unicodeText_[j];
  353. if (d == ' ' || d == '\n')
  354. {
  355. nextBreak = j;
  356. break;
  357. }
  358. const FontGlyph* glyph = face->GetGlyph(d);
  359. if (glyph)
  360. {
  361. futureRowWidth += glyph->advanceX_;
  362. if (j < unicodeText_.Size() - 1)
  363. futureRowWidth += face->GetKerning(d, unicodeText_[j + 1]);
  364. }
  365. if (d == '-' && futureRowWidth <= maxWidth)
  366. {
  367. nextBreak = j + 1;
  368. break;
  369. }
  370. if (futureRowWidth > maxWidth)
  371. {
  372. ok = false;
  373. break;
  374. }
  375. }
  376. }
  377. if (!ok)
  378. {
  379. // If did not find any breaks on the line, copy until j, or at least 1 char, to prevent infinite loop
  380. if (nextBreak == lineStart)
  381. {
  382. while (i < j)
  383. {
  384. printText_.Push(unicodeText_[i]);
  385. printToText_.Push(i);
  386. ++i;
  387. }
  388. }
  389. // Eliminate spaces that have been copied before the forced break
  390. while (printText_.Size() && printText_.Back() == ' ')
  391. {
  392. printText_.Pop();
  393. printToText_.Pop();
  394. }
  395. printText_.Push('\n');
  396. printToText_.Push(Min((int)i, (int)unicodeText_.Size() - 1));
  397. rowWidth = 0;
  398. nextBreak = lineStart = i;
  399. }
  400. if (i < unicodeText_.Size())
  401. {
  402. // When copying a space, position is allowed to be over row width
  403. c = unicodeText_[i];
  404. const FontGlyph* glyph = face->GetGlyph(c);
  405. if (glyph)
  406. {
  407. rowWidth += glyph->advanceX_;
  408. if (i < text_.Length() - 1)
  409. rowWidth += face->GetKerning(c, unicodeText_[i + 1]);
  410. }
  411. if (rowWidth <= maxWidth)
  412. {
  413. printText_.Push(c);
  414. printToText_.Push(i);
  415. }
  416. }
  417. }
  418. else
  419. {
  420. printText_.Push('\n');
  421. printToText_.Push(Min((int)i, (int)unicodeText_.Size() - 1));
  422. rowWidth = 0;
  423. nextBreak = lineStart = i;
  424. }
  425. }
  426. }
  427. rowWidth = 0;
  428. for (unsigned i = 0; i < printText_.Size(); ++i)
  429. {
  430. unsigned c = printText_[i];
  431. if (c != '\n')
  432. {
  433. const FontGlyph* glyph = face->GetGlyph(c);
  434. if (glyph)
  435. {
  436. rowWidth += glyph->advanceX_;
  437. if (i < printText_.Size() - 1)
  438. rowWidth += face->GetKerning(c, printText_[i + 1]);
  439. }
  440. }
  441. else
  442. {
  443. width = Max(width, rowWidth);
  444. height += rowHeight;
  445. rowWidths_.Push(rowWidth);
  446. rowWidth = 0;
  447. }
  448. }
  449. if (rowWidth)
  450. {
  451. width = Max(width, rowWidth);
  452. height += rowHeight;
  453. rowWidths_.Push(rowWidth);
  454. }
  455. // Set at least one row height even if text is empty
  456. if (!height)
  457. height = rowHeight;
  458. // Set minimum and current size according to the text size, but respect fixed width if set
  459. if (!IsFixedWidth())
  460. {
  461. SetMinWidth(wordWrap_ ? 0 : width);
  462. SetWidth(width);
  463. }
  464. SetFixedHeight(height);
  465. charPositionsDirty_ = true;
  466. }
  467. else
  468. {
  469. // No font, nothing to render
  470. pageGlyphLocations_.Clear();
  471. }
  472. }
  473. void Text::UpdateCharPositions()
  474. {
  475. if (font_)
  476. {
  477. // Remember the font face to see if it's still valid when it's time to render
  478. FontFace* face = font_->GetFace(fontSize_);
  479. if (!face)
  480. return;
  481. fontFace_ = face;
  482. int rowHeight = (int)(rowSpacing_ * rowHeight_);
  483. // Store position & size of each character, and locations per texture page
  484. charPositions_.Resize(unicodeText_.Size() + 1);
  485. charSizes_.Resize(unicodeText_.Size());
  486. pageGlyphLocations_.Resize(face->GetTextures().Size());
  487. for (unsigned i = 0; i < pageGlyphLocations_.Size(); ++i)
  488. pageGlyphLocations_[i].Clear();
  489. unsigned rowIndex = 0;
  490. unsigned lastFilled = 0;
  491. int x = GetRowStartPosition(rowIndex);
  492. int y = 0;
  493. for (unsigned i = 0; i < printText_.Size(); ++i)
  494. {
  495. IntVector2 pos(x, y);
  496. // Fill gaps in case characters were skipped from printing
  497. for (unsigned j = lastFilled; j <= printToText_[i]; ++j)
  498. charPositions_[j] = pos;
  499. unsigned c = printText_[i];
  500. if (c != '\n')
  501. {
  502. const FontGlyph* glyph = face->GetGlyph(c);
  503. IntVector2 size(glyph ? glyph->advanceX_ : 0, rowHeight_);
  504. for (unsigned j = lastFilled; j <= printToText_[i]; ++j)
  505. charSizes_[j] = size;
  506. if (glyph)
  507. {
  508. // Store glyph's location for rendering. Verify that glyph page is valid
  509. if (glyph->page_ < pageGlyphLocations_.Size())
  510. pageGlyphLocations_[glyph->page_].Push(GlyphLocation(x, y, glyph));
  511. x += glyph->advanceX_;
  512. if (i < printText_.Size() - 1)
  513. x += face->GetKerning(c, printText_[i + 1]);
  514. }
  515. }
  516. else
  517. {
  518. for (unsigned j = lastFilled; j <= printToText_[i]; ++j)
  519. charSizes_[j] = IntVector2::ZERO;
  520. x = GetRowStartPosition(++rowIndex);
  521. y += rowHeight;
  522. }
  523. lastFilled = printToText_[i] + 1;
  524. }
  525. // Store the ending position
  526. charPositions_[unicodeText_.Size()] = IntVector2(x, y);
  527. charPositionsDirty_ = false;
  528. }
  529. }
  530. void Text::ValidateSelection()
  531. {
  532. unsigned textLength = unicodeText_.Size();
  533. if (textLength)
  534. {
  535. if (selectionStart_ >= textLength)
  536. selectionStart_ = textLength - 1;
  537. if (selectionStart_ + selectionLength_ > textLength)
  538. selectionLength_ = textLength - selectionStart_;
  539. }
  540. else
  541. {
  542. selectionStart_ = 0;
  543. selectionLength_ = 0;
  544. }
  545. }
  546. int Text::GetRowStartPosition(unsigned rowIndex) const
  547. {
  548. int rowWidth = 0;
  549. if (rowIndex < rowWidths_.Size())
  550. rowWidth = rowWidths_[rowIndex];
  551. int ret = GetIndentWidth();
  552. switch (textAlignment_)
  553. {
  554. case HA_LEFT:
  555. break;
  556. case HA_CENTER:
  557. ret += (GetSize().x_ - rowWidth) / 2;
  558. break;
  559. case HA_RIGHT:
  560. ret += GetSize().x_ - rowWidth;
  561. break;
  562. }
  563. return ret;
  564. }
  565. void Text::ConstructBatch(UIBatch& pageBatch, const PODVector<GlyphLocation>& pageGlyphLocation, int dx, int dy, Color* color,
  566. float depthBias)
  567. {
  568. unsigned startDataSize = pageBatch.vertexData_->Size();
  569. if (!color)
  570. pageBatch.SetDefaultColor();
  571. else
  572. pageBatch.SetColor(*color);
  573. for (unsigned i = 0; i < pageGlyphLocation.Size(); ++i)
  574. {
  575. const GlyphLocation& glyphLocation = pageGlyphLocation[i];
  576. const FontGlyph& glyph = *glyphLocation.glyph_;
  577. pageBatch.AddQuad(dx + glyphLocation.x_ + glyph.offsetX_, dy + glyphLocation.y_ + glyph.offsetY_, glyph.width_,
  578. glyph.height_, glyph.x_, glyph.y_);
  579. }
  580. if (depthBias != 0.0f)
  581. {
  582. unsigned dataSize = pageBatch.vertexData_->Size();
  583. for (unsigned i = startDataSize; i < dataSize; i += UI_VERTEX_SIZE)
  584. pageBatch.vertexData_->At(i + 2) += depthBias;
  585. }
  586. }
  587. }