BsTextData.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "BsTextData.h"
  4. #include "BsFont.h"
  5. #include "BsVector2.h"
  6. #include "BsDebug.h"
  7. namespace BansheeEngine
  8. {
  9. const int SPACE_CHAR = 32;
  10. const int TAB_CHAR = 9;
  11. void TextDataBase::TextWord::init(bool spacer)
  12. {
  13. mWidth = mHeight = 0;
  14. mSpacer = spacer;
  15. mSpaceWidth = 0;
  16. mCharsStart = 0;
  17. mCharsEnd = 0;
  18. mLastChar = nullptr;
  19. }
  20. // Assumes charIdx is an index right after last char in the list (if any). All chars need to be sequential.
  21. UINT32 TextDataBase::TextWord::addChar(UINT32 charIdx, const CHAR_DESC& desc)
  22. {
  23. UINT32 charWidth = calcCharWidth(mLastChar, desc);
  24. mWidth += charWidth;
  25. mHeight = std::max(mHeight, desc.height);
  26. if(mLastChar == nullptr) // First char
  27. mCharsStart = mCharsEnd = charIdx;
  28. else
  29. mCharsEnd = charIdx;
  30. mLastChar = &desc;
  31. return charWidth;
  32. }
  33. UINT32 TextDataBase::TextWord::calcWidthWithChar(const CHAR_DESC& desc)
  34. {
  35. return mWidth + calcCharWidth(mLastChar, desc);
  36. }
  37. UINT32 TextDataBase::TextWord::calcCharWidth(const CHAR_DESC* prevDesc, const CHAR_DESC& desc)
  38. {
  39. UINT32 charWidth = desc.xAdvance;
  40. if (prevDesc != nullptr)
  41. {
  42. UINT32 kerning = 0;
  43. for (size_t j = 0; j < prevDesc->kerningPairs.size(); j++)
  44. {
  45. if (prevDesc->kerningPairs[j].otherCharId == desc.charId)
  46. {
  47. kerning = prevDesc->kerningPairs[j].amount;
  48. break;
  49. }
  50. }
  51. charWidth += kerning;
  52. }
  53. return charWidth;
  54. }
  55. void TextDataBase::TextWord::addSpace(UINT32 spaceWidth)
  56. {
  57. mSpaceWidth += spaceWidth;
  58. mWidth = mSpaceWidth;
  59. mHeight = 0;
  60. }
  61. void TextDataBase::TextLine::init(TextDataBase* textData)
  62. {
  63. mWidth = 0;
  64. mHeight = 0;
  65. mIsEmpty = true;
  66. mTextData = textData;
  67. mWordsStart = mWordsEnd = 0;
  68. }
  69. void TextDataBase::TextLine::finalize(bool hasNewlineChar)
  70. {
  71. mHasNewline = hasNewlineChar;
  72. }
  73. void TextDataBase::TextLine::add(UINT32 charIdx, const CHAR_DESC& charDesc)
  74. {
  75. UINT32 charWidth = 0;
  76. if(mIsEmpty)
  77. {
  78. mWordsStart = mWordsEnd = MemBuffer->allocWord(false);
  79. mIsEmpty = false;
  80. }
  81. else
  82. {
  83. if(MemBuffer->WordBuffer[mWordsEnd].isSpacer())
  84. mWordsEnd = MemBuffer->allocWord(false);
  85. }
  86. TextWord& lastWord = MemBuffer->WordBuffer[mWordsEnd];
  87. charWidth = lastWord.addChar(charIdx, charDesc);
  88. mWidth += charWidth;
  89. mHeight = std::max(mHeight, lastWord.getHeight());
  90. }
  91. void TextDataBase::TextLine::addSpace(UINT32 spaceWidth)
  92. {
  93. if(mIsEmpty)
  94. {
  95. mWordsStart = mWordsEnd = MemBuffer->allocWord(true);
  96. mIsEmpty = false;
  97. }
  98. else
  99. mWordsEnd = MemBuffer->allocWord(true); // Each space is counted as its own word, to make certain operations easier
  100. TextWord& lastWord = MemBuffer->WordBuffer[mWordsEnd];
  101. lastWord.addSpace(spaceWidth);
  102. mWidth += spaceWidth;
  103. }
  104. // Assumes wordIdx is an index right after last word in the list (if any). All words need to be sequential.
  105. void TextDataBase::TextLine::addWord(UINT32 wordIdx, const TextWord& word)
  106. {
  107. if(mIsEmpty)
  108. {
  109. mWordsStart = mWordsEnd = wordIdx;
  110. mIsEmpty = false;
  111. }
  112. else
  113. mWordsEnd = wordIdx;
  114. mWidth += word.getWidth();
  115. mHeight = std::max(mHeight, word.getHeight());
  116. }
  117. UINT32 TextDataBase::TextLine::removeLastWord()
  118. {
  119. if(mIsEmpty)
  120. {
  121. assert(false);
  122. return 0;
  123. }
  124. UINT32 lastWord = mWordsEnd--;
  125. if(mWordsStart == lastWord)
  126. {
  127. mIsEmpty = true;
  128. mWordsStart = mWordsEnd = 0;
  129. }
  130. calculateBounds();
  131. return lastWord;
  132. }
  133. UINT32 TextDataBase::TextLine::calcWidthWithChar(const CHAR_DESC& desc)
  134. {
  135. UINT32 charWidth = 0;
  136. if (!mIsEmpty)
  137. {
  138. TextWord& lastWord = MemBuffer->WordBuffer[mWordsEnd];
  139. if (lastWord.isSpacer())
  140. charWidth = TextWord::calcCharWidth(nullptr, desc);
  141. else
  142. charWidth = lastWord.calcWidthWithChar(desc) - lastWord.getWidth();
  143. }
  144. else
  145. {
  146. charWidth = TextWord::calcCharWidth(nullptr, desc);
  147. }
  148. return mWidth + charWidth;
  149. }
  150. bool TextDataBase::TextLine::isAtWordBoundary() const
  151. {
  152. return mIsEmpty || MemBuffer->WordBuffer[mWordsEnd].isSpacer();
  153. }
  154. UINT32 TextDataBase::TextLine::fillBuffer(UINT32 page, Vector2* vertices, Vector2* uvs, UINT32* indexes, UINT32 offset, UINT32 size) const
  155. {
  156. UINT32 numQuads = 0;
  157. if(mIsEmpty)
  158. return numQuads;
  159. UINT32 penX = 0;
  160. for(UINT32 i = mWordsStart; i <= mWordsEnd; i++)
  161. {
  162. const TextWord& word = mTextData->getWord(i);
  163. if(word.isSpacer())
  164. {
  165. // We store invisible space quads in the first page. Even though they aren't needed
  166. // for rendering and we could just leave an empty space, they are needed for intersection tests
  167. // for things like determining caret placement and selection areas
  168. if(page == 0)
  169. {
  170. INT32 curX = penX;
  171. INT32 curY = 0;
  172. UINT32 curVert = offset * 4;
  173. UINT32 curIndex = offset * 6;
  174. vertices[curVert + 0] = Vector2((float)curX, (float)curY);
  175. vertices[curVert + 1] = Vector2((float)(curX + word.getWidth()), (float)curY);
  176. vertices[curVert + 2] = Vector2((float)curX, (float)curY + (float)mTextData->getLineHeight());
  177. vertices[curVert + 3] = Vector2((float)(curX + word.getWidth()), (float)curY + (float)mTextData->getLineHeight());
  178. if(uvs != nullptr)
  179. {
  180. uvs[curVert + 0] = Vector2(0.0f, 0.0f);
  181. uvs[curVert + 1] = Vector2(0.0f, 0.0f);
  182. uvs[curVert + 2] = Vector2(0.0f, 0.0f);
  183. uvs[curVert + 3] = Vector2(0.0f, 0.0f);
  184. }
  185. // Triangles are back-facing which makes them invisible
  186. if(indexes != nullptr)
  187. {
  188. indexes[curIndex + 0] = curVert + 0;
  189. indexes[curIndex + 1] = curVert + 2;
  190. indexes[curIndex + 2] = curVert + 1;
  191. indexes[curIndex + 3] = curVert + 1;
  192. indexes[curIndex + 4] = curVert + 2;
  193. indexes[curIndex + 5] = curVert + 3;
  194. }
  195. offset++;
  196. numQuads++;
  197. if(offset > size)
  198. BS_EXCEPT(InternalErrorException, "Out of buffer bounds. Buffer size: " + toString(size));
  199. }
  200. penX += word.getWidth();
  201. }
  202. else
  203. {
  204. UINT32 kerning = 0;
  205. for(UINT32 j = word.getCharsStart(); j <= word.getCharsEnd(); j++)
  206. {
  207. const CHAR_DESC& curChar = mTextData->getChar(j);
  208. INT32 curX = penX + curChar.xOffset;
  209. INT32 curY = ((INT32) mTextData->getBaselineOffset() - curChar.yOffset);
  210. penX += curChar.xAdvance + kerning;
  211. kerning = 0;
  212. if((j + 1) <= word.getCharsEnd())
  213. {
  214. const CHAR_DESC& nextChar = mTextData->getChar(j + 1);
  215. for(size_t j = 0; j < curChar.kerningPairs.size(); j++)
  216. {
  217. if(curChar.kerningPairs[j].otherCharId == nextChar.charId)
  218. {
  219. kerning = curChar.kerningPairs[j].amount;
  220. break;
  221. }
  222. }
  223. }
  224. if(curChar.page != page)
  225. continue;
  226. UINT32 curVert = offset * 4;
  227. UINT32 curIndex = offset * 6;
  228. vertices[curVert + 0] = Vector2((float)curX, (float)curY);
  229. vertices[curVert + 1] = Vector2((float)(curX + curChar.width), (float)curY);
  230. vertices[curVert + 2] = Vector2((float)curX, (float)curY + (float)curChar.height);
  231. vertices[curVert + 3] = Vector2((float)(curX + curChar.width), (float)curY + (float)curChar.height);
  232. if(uvs != nullptr)
  233. {
  234. uvs[curVert + 0] = Vector2(curChar.uvX, curChar.uvY);
  235. uvs[curVert + 1] = Vector2(curChar.uvX + curChar.uvWidth, curChar.uvY);
  236. uvs[curVert + 2] = Vector2(curChar.uvX, curChar.uvY + curChar.uvHeight);
  237. uvs[curVert + 3] = Vector2(curChar.uvX + curChar.uvWidth, curChar.uvY + curChar.uvHeight);
  238. }
  239. if(indexes != nullptr)
  240. {
  241. indexes[curIndex + 0] = curVert + 0;
  242. indexes[curIndex + 1] = curVert + 1;
  243. indexes[curIndex + 2] = curVert + 2;
  244. indexes[curIndex + 3] = curVert + 1;
  245. indexes[curIndex + 4] = curVert + 3;
  246. indexes[curIndex + 5] = curVert + 2;
  247. }
  248. offset++;
  249. numQuads++;
  250. if(offset > size)
  251. BS_EXCEPT(InternalErrorException, "Out of buffer bounds. Buffer size: " + toString(size));
  252. }
  253. }
  254. }
  255. return numQuads;
  256. }
  257. UINT32 TextDataBase::TextLine::getNumChars() const
  258. {
  259. if(mIsEmpty)
  260. return 0;
  261. UINT32 numChars = 0;
  262. for(UINT32 i = mWordsStart; i <= mWordsEnd; i++)
  263. {
  264. TextWord& word = MemBuffer->WordBuffer[i];
  265. if(word.isSpacer())
  266. numChars++;
  267. else
  268. numChars += (UINT32)word.getNumChars();
  269. }
  270. return numChars;
  271. }
  272. void TextDataBase::TextLine::calculateBounds()
  273. {
  274. mWidth = 0;
  275. mHeight = 0;
  276. if(mIsEmpty)
  277. return;
  278. for(UINT32 i = mWordsStart; i <= mWordsEnd; i++)
  279. {
  280. TextWord& word = MemBuffer->WordBuffer[i];
  281. mWidth += word.getWidth();
  282. mHeight = std::max(mHeight, word.getHeight());
  283. }
  284. }
  285. TextDataBase::TextDataBase(const WString& text, const HFont& font, UINT32 fontSize, UINT32 width, UINT32 height, bool wordWrap, bool wordBreak)
  286. : mChars(nullptr), mNumChars(0), mWords(nullptr), mNumWords(0), mLines(nullptr), mNumLines(0), mPageInfos(nullptr)
  287. , mNumPageInfos(0), mFont(font), mFontData(nullptr)
  288. {
  289. // In order to reduce number of memory allocations algorithm first calculates data into temporary buffers and then copies the results
  290. initAlloc();
  291. if(font != nullptr)
  292. {
  293. UINT32 nearestSize = font->getClosestSize(fontSize);
  294. mFontData = font->getBitmap(nearestSize);
  295. }
  296. if(mFontData == nullptr || mFontData->texturePages.size() == 0)
  297. return;
  298. if(mFontData->size != fontSize)
  299. {
  300. LOGWRN("Unable to find font with specified size (" + toString(fontSize) + "). Using nearest available size: " + toString(mFontData->size));
  301. }
  302. bool widthIsLimited = width > 0;
  303. mFont = font;
  304. UINT32 curLineIdx = MemBuffer->allocLine(this);
  305. UINT32 curHeight = mFontData->fontDesc.lineHeight;
  306. UINT32 charIdx = 0;
  307. while(true)
  308. {
  309. if(charIdx >= text.size())
  310. break;
  311. UINT32 charId = text[charIdx];
  312. const CHAR_DESC& charDesc = mFontData->getCharDesc(charId);
  313. TextLine* curLine = &MemBuffer->LineBuffer[curLineIdx];
  314. if(text[charIdx] == '\n' || text[charIdx] == '\r')
  315. {
  316. curLine->finalize(true);
  317. curLineIdx = MemBuffer->allocLine(this);
  318. curLine = &MemBuffer->LineBuffer[curLineIdx];
  319. curHeight += mFontData->fontDesc.lineHeight;
  320. charIdx++;
  321. // Check for \r\n
  322. if (charIdx < text.size())
  323. {
  324. if (text[charIdx] == '\n')
  325. charIdx++;
  326. }
  327. continue;
  328. }
  329. if (widthIsLimited && wordWrap)
  330. {
  331. UINT32 widthWithChar = 0;
  332. if (charIdx == SPACE_CHAR)
  333. widthWithChar = curLine->getWidth() + getSpaceWidth();
  334. else if (charIdx == TAB_CHAR)
  335. widthWithChar = curLine->getWidth() + getSpaceWidth() * 4;
  336. else
  337. widthWithChar = curLine->calcWidthWithChar(charDesc);
  338. if (widthWithChar > width && !curLine->isEmpty())
  339. {
  340. bool atWordBoundary = charId == SPACE_CHAR || charId == TAB_CHAR || curLine->isAtWordBoundary();
  341. if (!atWordBoundary) // Need to break word into multiple pieces, or move it to next line
  342. {
  343. UINT32 lastWordIdx = curLine->removeLastWord();
  344. TextWord& lastWord = MemBuffer->WordBuffer[lastWordIdx];
  345. bool wordFits = lastWord.calcWidthWithChar(charDesc) <= width;
  346. if (wordFits && !curLine->isEmpty())
  347. {
  348. curLine->finalize(false);
  349. curLineIdx = MemBuffer->allocLine(this);
  350. curLine = &MemBuffer->LineBuffer[curLineIdx];
  351. curHeight += mFontData->fontDesc.lineHeight;
  352. curLine->addWord(lastWordIdx, lastWord);
  353. }
  354. else
  355. {
  356. if (wordBreak)
  357. {
  358. curLine->addWord(lastWordIdx, lastWord);
  359. curLine->finalize(false);
  360. curLineIdx = MemBuffer->allocLine(this);
  361. curLine = &MemBuffer->LineBuffer[curLineIdx];
  362. curHeight += mFontData->fontDesc.lineHeight;
  363. }
  364. else
  365. {
  366. if (!curLine->isEmpty()) // Add new line unless current line is empty (to avoid constantly moving the word to new lines)
  367. {
  368. curLine->finalize(false);
  369. curLineIdx = MemBuffer->allocLine(this);
  370. curLine = &MemBuffer->LineBuffer[curLineIdx];
  371. curHeight += mFontData->fontDesc.lineHeight;
  372. }
  373. curLine->addWord(lastWordIdx, lastWord);
  374. }
  375. }
  376. }
  377. else if (charId != SPACE_CHAR && charId != TAB_CHAR) // If current char is whitespace add it to the existing line even if it doesn't fit
  378. {
  379. curLine->finalize(false);
  380. curLineIdx = MemBuffer->allocLine(this);
  381. curLine = &MemBuffer->LineBuffer[curLineIdx];
  382. curHeight += mFontData->fontDesc.lineHeight;
  383. }
  384. }
  385. }
  386. if(charId == SPACE_CHAR)
  387. {
  388. curLine->addSpace(getSpaceWidth());
  389. MemBuffer->addCharToPage(0, *mFontData);
  390. }
  391. else if (charId == TAB_CHAR)
  392. {
  393. curLine->addSpace(getSpaceWidth() * 4);
  394. MemBuffer->addCharToPage(0, *mFontData);
  395. }
  396. else
  397. {
  398. curLine->add(charIdx, charDesc);
  399. MemBuffer->addCharToPage(charDesc.page, *mFontData);
  400. }
  401. charIdx++;
  402. }
  403. MemBuffer->LineBuffer[curLineIdx].finalize(true);
  404. // Now that we have all the data we need, allocate the permanent buffers and copy the data
  405. mNumChars = (UINT32)text.size();
  406. mNumWords = MemBuffer->NextFreeWord;
  407. mNumLines = MemBuffer->NextFreeLine;
  408. mNumPageInfos = MemBuffer->NextFreePageInfo;
  409. }
  410. void TextDataBase::generatePersistentData(const WString& text, UINT8* buffer, UINT32& size, bool freeTemporary)
  411. {
  412. UINT32 charArraySize = mNumChars * sizeof(const CHAR_DESC*);
  413. UINT32 wordArraySize = mNumWords * sizeof(TextWord);
  414. UINT32 lineArraySize = mNumLines * sizeof(TextLine);
  415. UINT32 pageInfoArraySize = mNumPageInfos * sizeof(PageInfo);
  416. if (buffer == nullptr)
  417. {
  418. size = charArraySize + wordArraySize + lineArraySize + pageInfoArraySize;;
  419. return;
  420. }
  421. UINT8* dataPtr = (UINT8*)buffer;
  422. mChars = (const CHAR_DESC**)dataPtr;
  423. for (UINT32 i = 0; i < mNumChars; i++)
  424. {
  425. UINT32 charId = text[i];
  426. const CHAR_DESC& charDesc = mFontData->getCharDesc(charId);
  427. mChars[i] = &charDesc;
  428. }
  429. dataPtr += charArraySize;
  430. mWords = (TextWord*)dataPtr;
  431. memcpy(mWords, &MemBuffer->WordBuffer[0], wordArraySize);
  432. dataPtr += wordArraySize;
  433. mLines = (TextLine*)dataPtr;
  434. memcpy(mLines, &MemBuffer->LineBuffer[0], lineArraySize);
  435. dataPtr += lineArraySize;
  436. mPageInfos = (PageInfo*)dataPtr;
  437. memcpy((void*)mPageInfos, (void*)&MemBuffer->PageBuffer[0], pageInfoArraySize);
  438. if (freeTemporary)
  439. MemBuffer->deallocAll();
  440. }
  441. const HTexture& TextDataBase::getTextureForPage(UINT32 page) const
  442. {
  443. return mFontData->texturePages[page];
  444. }
  445. INT32 TextDataBase::getBaselineOffset() const
  446. {
  447. return mFontData->fontDesc.baselineOffset;
  448. }
  449. UINT32 TextDataBase::getLineHeight() const
  450. {
  451. return mFontData->fontDesc.lineHeight;
  452. }
  453. UINT32 TextDataBase::getSpaceWidth() const
  454. {
  455. return mFontData->fontDesc.spaceWidth;
  456. }
  457. void TextDataBase::initAlloc()
  458. {
  459. if (MemBuffer == nullptr)
  460. MemBuffer = bs_new<BufferData>();
  461. }
  462. BS_THREADLOCAL TextDataBase::BufferData* TextDataBase::MemBuffer = nullptr;
  463. TextDataBase::BufferData::BufferData()
  464. {
  465. WordBufferSize = 2000;
  466. LineBufferSize = 500;
  467. PageBufferSize = 20;
  468. NextFreeWord = 0;
  469. NextFreeLine = 0;
  470. NextFreePageInfo = 0;
  471. WordBuffer = bs_newN<TextWord>(WordBufferSize);
  472. LineBuffer = bs_newN<TextLine>(LineBufferSize);
  473. PageBuffer = bs_newN<PageInfo>(PageBufferSize);
  474. }
  475. TextDataBase::BufferData::~BufferData()
  476. {
  477. bs_deleteN(WordBuffer, WordBufferSize);
  478. bs_deleteN(LineBuffer, LineBufferSize);
  479. bs_deleteN(PageBuffer, PageBufferSize);
  480. }
  481. UINT32 TextDataBase::BufferData::allocWord(bool spacer)
  482. {
  483. if(NextFreeWord >= WordBufferSize)
  484. {
  485. UINT32 newBufferSize = WordBufferSize * 2;
  486. TextWord* newBuffer = bs_newN<TextWord>(newBufferSize);
  487. memcpy(WordBuffer, newBuffer, WordBufferSize);
  488. bs_deleteN(WordBuffer, WordBufferSize);
  489. WordBuffer = newBuffer;
  490. WordBufferSize = newBufferSize;
  491. }
  492. WordBuffer[NextFreeWord].init(spacer);
  493. return NextFreeWord++;
  494. }
  495. UINT32 TextDataBase::BufferData::allocLine(TextDataBase* textData)
  496. {
  497. if(NextFreeLine >= LineBufferSize)
  498. {
  499. UINT32 newBufferSize = LineBufferSize * 2;
  500. TextLine* newBuffer = bs_newN<TextLine>(newBufferSize);
  501. memcpy(LineBuffer, newBuffer, LineBufferSize);
  502. bs_deleteN(LineBuffer, LineBufferSize);
  503. LineBuffer = newBuffer;
  504. LineBufferSize = newBufferSize;
  505. }
  506. LineBuffer[NextFreeLine].init(textData);
  507. return NextFreeLine++;
  508. }
  509. void TextDataBase::BufferData::deallocAll()
  510. {
  511. NextFreeWord = 0;
  512. NextFreeLine = 0;
  513. NextFreePageInfo = 0;
  514. }
  515. void TextDataBase::BufferData::addCharToPage(UINT32 page, const FontBitmap& fontData)
  516. {
  517. if(NextFreePageInfo >= PageBufferSize)
  518. {
  519. UINT32 newBufferSize = PageBufferSize * 2;
  520. PageInfo* newBuffer = bs_newN<PageInfo>(newBufferSize);
  521. memcpy((void*)PageBuffer, (void*)newBuffer, PageBufferSize);
  522. bs_deleteN(PageBuffer, PageBufferSize);
  523. PageBuffer = newBuffer;
  524. PageBufferSize = newBufferSize;
  525. }
  526. while(page >= NextFreePageInfo)
  527. {
  528. PageBuffer[NextFreePageInfo].numQuads = 0;
  529. NextFreePageInfo++;
  530. }
  531. PageBuffer[page].numQuads++;
  532. }
  533. UINT32 TextDataBase::getWidth() const
  534. {
  535. UINT32 width = 0;
  536. for(UINT32 i = 0; i < mNumLines; i++)
  537. width = std::max(width, mLines[i].getWidth());
  538. return width;
  539. }
  540. UINT32 TextDataBase::getHeight() const
  541. {
  542. UINT32 height = 0;
  543. for(UINT32 i = 0; i < mNumLines; i++)
  544. height += mLines[i].getHeight();
  545. return height;
  546. }
  547. }