BsTextData.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "Text/BsTextData.h"
  4. #include "Text/BsFont.h"
  5. #include "Math/BsVector2.h"
  6. #include "Debug/BsDebug.h"
  7. namespace bs
  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 CharDesc& 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 CharDesc& desc)
  34. {
  35. return mWidth + calcCharWidth(mLastChar, desc);
  36. }
  37. UINT32 TextDataBase::TextWord::calcCharWidth(const CharDesc* prevDesc, const CharDesc& 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 CharDesc& 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 CharDesc& 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. UINT32 penNegativeXOffset = 0;
  161. for(UINT32 i = mWordsStart; i <= mWordsEnd; i++)
  162. {
  163. const TextWord& word = mTextData->getWord(i);
  164. if(word.isSpacer())
  165. {
  166. // We store invisible space quads in the first page. Even though they aren't needed
  167. // for rendering and we could just leave an empty space, they are needed for intersection tests
  168. // for things like determining caret placement and selection areas
  169. if(page == 0)
  170. {
  171. INT32 curX = penX;
  172. INT32 curY = 0;
  173. UINT32 curVert = offset * 4;
  174. UINT32 curIndex = offset * 6;
  175. vertices[curVert + 0] = Vector2((float)curX, (float)curY);
  176. vertices[curVert + 1] = Vector2((float)(curX + word.getWidth()), (float)curY);
  177. vertices[curVert + 2] = Vector2((float)curX, (float)curY + (float)mTextData->getLineHeight());
  178. vertices[curVert + 3] = Vector2((float)(curX + word.getWidth()), (float)curY + (float)mTextData->getLineHeight());
  179. if(uvs != nullptr)
  180. {
  181. uvs[curVert + 0] = Vector2(0.0f, 0.0f);
  182. uvs[curVert + 1] = Vector2(0.0f, 0.0f);
  183. uvs[curVert + 2] = Vector2(0.0f, 0.0f);
  184. uvs[curVert + 3] = Vector2(0.0f, 0.0f);
  185. }
  186. // Triangles are back-facing which makes them invisible
  187. if(indexes != nullptr)
  188. {
  189. indexes[curIndex + 0] = curVert + 0;
  190. indexes[curIndex + 1] = curVert + 2;
  191. indexes[curIndex + 2] = curVert + 1;
  192. indexes[curIndex + 3] = curVert + 1;
  193. indexes[curIndex + 4] = curVert + 2;
  194. indexes[curIndex + 5] = curVert + 3;
  195. }
  196. offset++;
  197. numQuads++;
  198. if(offset > size)
  199. BS_EXCEPT(InternalErrorException, "Out of buffer bounds. Buffer size: " + toString(size));
  200. }
  201. penX += word.getWidth();
  202. }
  203. else
  204. {
  205. UINT32 kerning = 0;
  206. for(UINT32 j = word.getCharsStart(); j <= word.getCharsEnd(); j++)
  207. {
  208. const CharDesc& curChar = mTextData->getChar(j);
  209. INT32 curX = penX + curChar.xOffset;
  210. INT32 curY = ((INT32) mTextData->getBaselineOffset() - curChar.yOffset);
  211. // If index is negative, offset it so the text always begins at X=0. This works under the assumption
  212. // that only the first character on a line can have a negative offset.
  213. if (curX < 0)
  214. penNegativeXOffset = penX - curChar.xOffset;
  215. curX += penNegativeXOffset;
  216. penX += curChar.xAdvance + kerning;
  217. kerning = 0;
  218. if((j + 1) <= word.getCharsEnd())
  219. {
  220. const CharDesc& nextChar = mTextData->getChar(j + 1);
  221. for(size_t j = 0; j < curChar.kerningPairs.size(); j++)
  222. {
  223. if(curChar.kerningPairs[j].otherCharId == nextChar.charId)
  224. {
  225. kerning = curChar.kerningPairs[j].amount;
  226. break;
  227. }
  228. }
  229. }
  230. if(curChar.page != page)
  231. continue;
  232. UINT32 curVert = offset * 4;
  233. UINT32 curIndex = offset * 6;
  234. vertices[curVert + 0] = Vector2((float)curX, (float)curY);
  235. vertices[curVert + 1] = Vector2((float)(curX + curChar.width), (float)curY);
  236. vertices[curVert + 2] = Vector2((float)curX, (float)curY + (float)curChar.height);
  237. vertices[curVert + 3] = Vector2((float)(curX + curChar.width), (float)curY + (float)curChar.height);
  238. if(uvs != nullptr)
  239. {
  240. uvs[curVert + 0] = Vector2(curChar.uvX, curChar.uvY);
  241. uvs[curVert + 1] = Vector2(curChar.uvX + curChar.uvWidth, curChar.uvY);
  242. uvs[curVert + 2] = Vector2(curChar.uvX, curChar.uvY + curChar.uvHeight);
  243. uvs[curVert + 3] = Vector2(curChar.uvX + curChar.uvWidth, curChar.uvY + curChar.uvHeight);
  244. }
  245. if(indexes != nullptr)
  246. {
  247. indexes[curIndex + 0] = curVert + 0;
  248. indexes[curIndex + 1] = curVert + 1;
  249. indexes[curIndex + 2] = curVert + 2;
  250. indexes[curIndex + 3] = curVert + 1;
  251. indexes[curIndex + 4] = curVert + 3;
  252. indexes[curIndex + 5] = curVert + 2;
  253. }
  254. offset++;
  255. numQuads++;
  256. if(offset > size)
  257. BS_EXCEPT(InternalErrorException, "Out of buffer bounds. Buffer size: " + toString(size));
  258. }
  259. }
  260. }
  261. return numQuads;
  262. }
  263. UINT32 TextDataBase::TextLine::getNumChars() const
  264. {
  265. if(mIsEmpty)
  266. return 0;
  267. UINT32 numChars = 0;
  268. for(UINT32 i = mWordsStart; i <= mWordsEnd; i++)
  269. {
  270. TextWord& word = MemBuffer->WordBuffer[i];
  271. if(word.isSpacer())
  272. numChars++;
  273. else
  274. numChars += (UINT32)word.getNumChars();
  275. }
  276. return numChars;
  277. }
  278. void TextDataBase::TextLine::calculateBounds()
  279. {
  280. mWidth = 0;
  281. mHeight = 0;
  282. if(mIsEmpty)
  283. return;
  284. for(UINT32 i = mWordsStart; i <= mWordsEnd; i++)
  285. {
  286. TextWord& word = MemBuffer->WordBuffer[i];
  287. mWidth += word.getWidth();
  288. mHeight = std::max(mHeight, word.getHeight());
  289. }
  290. }
  291. TextDataBase::TextDataBase(const WString& text, const HFont& font, UINT32 fontSize, UINT32 width, UINT32 height, bool wordWrap, bool wordBreak)
  292. : mChars(nullptr), mNumChars(0), mWords(nullptr), mNumWords(0), mLines(nullptr), mNumLines(0), mPageInfos(nullptr)
  293. , mNumPageInfos(0), mFont(font), mFontData(nullptr)
  294. {
  295. // In order to reduce number of memory allocations algorithm first calculates data into temporary buffers and then copies the results
  296. initAlloc();
  297. if(font != nullptr)
  298. {
  299. UINT32 nearestSize = font->getClosestSize(fontSize);
  300. mFontData = font->getBitmap(nearestSize);
  301. }
  302. if(mFontData == nullptr || mFontData->texturePages.size() == 0)
  303. return;
  304. if(mFontData->size != fontSize)
  305. {
  306. LOGWRN("Unable to find font with specified size (" + toString(fontSize) + "). Using nearest available size: " + toString(mFontData->size));
  307. }
  308. bool widthIsLimited = width > 0;
  309. mFont = font;
  310. UINT32 curLineIdx = MemBuffer->allocLine(this);
  311. UINT32 curHeight = mFontData->lineHeight;
  312. UINT32 charIdx = 0;
  313. while(true)
  314. {
  315. if(charIdx >= text.size())
  316. break;
  317. UINT32 charId = text[charIdx];
  318. const CharDesc& charDesc = mFontData->getCharDesc(charId);
  319. TextLine* curLine = &MemBuffer->LineBuffer[curLineIdx];
  320. if(text[charIdx] == '\n' || text[charIdx] == '\r')
  321. {
  322. curLine->finalize(true);
  323. curLineIdx = MemBuffer->allocLine(this);
  324. curLine = &MemBuffer->LineBuffer[curLineIdx];
  325. curHeight += mFontData->lineHeight;
  326. charIdx++;
  327. // Check for \r\n
  328. if (charIdx < text.size())
  329. {
  330. if (text[charIdx] == '\n')
  331. charIdx++;
  332. }
  333. continue;
  334. }
  335. if (widthIsLimited && wordWrap)
  336. {
  337. UINT32 widthWithChar = 0;
  338. if (charIdx == SPACE_CHAR)
  339. widthWithChar = curLine->getWidth() + getSpaceWidth();
  340. else if (charIdx == TAB_CHAR)
  341. widthWithChar = curLine->getWidth() + getSpaceWidth() * 4;
  342. else
  343. widthWithChar = curLine->calcWidthWithChar(charDesc);
  344. if (widthWithChar > width && !curLine->isEmpty())
  345. {
  346. bool atWordBoundary = charId == SPACE_CHAR || charId == TAB_CHAR || curLine->isAtWordBoundary();
  347. if (!atWordBoundary) // Need to break word into multiple pieces, or move it to next line
  348. {
  349. UINT32 lastWordIdx = curLine->removeLastWord();
  350. TextWord& lastWord = MemBuffer->WordBuffer[lastWordIdx];
  351. bool wordFits = lastWord.calcWidthWithChar(charDesc) <= width;
  352. if (wordFits && !curLine->isEmpty())
  353. {
  354. curLine->finalize(false);
  355. curLineIdx = MemBuffer->allocLine(this);
  356. curLine = &MemBuffer->LineBuffer[curLineIdx];
  357. curHeight += mFontData->lineHeight;
  358. curLine->addWord(lastWordIdx, lastWord);
  359. }
  360. else
  361. {
  362. if (wordBreak)
  363. {
  364. curLine->addWord(lastWordIdx, lastWord);
  365. curLine->finalize(false);
  366. curLineIdx = MemBuffer->allocLine(this);
  367. curLine = &MemBuffer->LineBuffer[curLineIdx];
  368. curHeight += mFontData->lineHeight;
  369. }
  370. else
  371. {
  372. if (!curLine->isEmpty()) // Add new line unless current line is empty (to avoid constantly moving the word to new lines)
  373. {
  374. curLine->finalize(false);
  375. curLineIdx = MemBuffer->allocLine(this);
  376. curLine = &MemBuffer->LineBuffer[curLineIdx];
  377. curHeight += mFontData->lineHeight;
  378. }
  379. curLine->addWord(lastWordIdx, lastWord);
  380. }
  381. }
  382. }
  383. 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
  384. {
  385. curLine->finalize(false);
  386. curLineIdx = MemBuffer->allocLine(this);
  387. curLine = &MemBuffer->LineBuffer[curLineIdx];
  388. curHeight += mFontData->lineHeight;
  389. }
  390. }
  391. }
  392. if(charId == SPACE_CHAR)
  393. {
  394. curLine->addSpace(getSpaceWidth());
  395. MemBuffer->addCharToPage(0, *mFontData);
  396. }
  397. else if (charId == TAB_CHAR)
  398. {
  399. curLine->addSpace(getSpaceWidth() * 4);
  400. MemBuffer->addCharToPage(0, *mFontData);
  401. }
  402. else
  403. {
  404. curLine->add(charIdx, charDesc);
  405. MemBuffer->addCharToPage(charDesc.page, *mFontData);
  406. }
  407. charIdx++;
  408. }
  409. MemBuffer->LineBuffer[curLineIdx].finalize(true);
  410. // Now that we have all the data we need, allocate the permanent buffers and copy the data
  411. mNumChars = (UINT32)text.size();
  412. mNumWords = MemBuffer->NextFreeWord;
  413. mNumLines = MemBuffer->NextFreeLine;
  414. mNumPageInfos = MemBuffer->NextFreePageInfo;
  415. }
  416. void TextDataBase::generatePersistentData(const WString& text, UINT8* buffer, UINT32& size, bool freeTemporary)
  417. {
  418. UINT32 charArraySize = mNumChars * sizeof(const CharDesc*);
  419. UINT32 wordArraySize = mNumWords * sizeof(TextWord);
  420. UINT32 lineArraySize = mNumLines * sizeof(TextLine);
  421. UINT32 pageInfoArraySize = mNumPageInfos * sizeof(PageInfo);
  422. if (buffer == nullptr)
  423. {
  424. size = charArraySize + wordArraySize + lineArraySize + pageInfoArraySize;;
  425. return;
  426. }
  427. UINT8* dataPtr = (UINT8*)buffer;
  428. mChars = (const CharDesc**)dataPtr;
  429. for (UINT32 i = 0; i < mNumChars; i++)
  430. {
  431. UINT32 charId = text[i];
  432. const CharDesc& charDesc = mFontData->getCharDesc(charId);
  433. mChars[i] = &charDesc;
  434. }
  435. dataPtr += charArraySize;
  436. mWords = (TextWord*)dataPtr;
  437. memcpy(mWords, &MemBuffer->WordBuffer[0], wordArraySize);
  438. dataPtr += wordArraySize;
  439. mLines = (TextLine*)dataPtr;
  440. memcpy(mLines, &MemBuffer->LineBuffer[0], lineArraySize);
  441. dataPtr += lineArraySize;
  442. mPageInfos = (PageInfo*)dataPtr;
  443. memcpy((void*)mPageInfos, (void*)&MemBuffer->PageBuffer[0], pageInfoArraySize);
  444. if (freeTemporary)
  445. MemBuffer->deallocAll();
  446. }
  447. const HTexture& TextDataBase::getTextureForPage(UINT32 page) const
  448. {
  449. return mFontData->texturePages[page];
  450. }
  451. INT32 TextDataBase::getBaselineOffset() const
  452. {
  453. return mFontData->baselineOffset;
  454. }
  455. UINT32 TextDataBase::getLineHeight() const
  456. {
  457. return mFontData->lineHeight;
  458. }
  459. UINT32 TextDataBase::getSpaceWidth() const
  460. {
  461. return mFontData->spaceWidth;
  462. }
  463. void TextDataBase::initAlloc()
  464. {
  465. if (MemBuffer == nullptr)
  466. MemBuffer = bs_new<BufferData>();
  467. }
  468. BS_THREADLOCAL TextDataBase::BufferData* TextDataBase::MemBuffer = nullptr;
  469. TextDataBase::BufferData::BufferData()
  470. {
  471. WordBufferSize = 2000;
  472. LineBufferSize = 500;
  473. PageBufferSize = 20;
  474. NextFreeWord = 0;
  475. NextFreeLine = 0;
  476. NextFreePageInfo = 0;
  477. WordBuffer = bs_newN<TextWord>(WordBufferSize);
  478. LineBuffer = bs_newN<TextLine>(LineBufferSize);
  479. PageBuffer = bs_newN<PageInfo>(PageBufferSize);
  480. }
  481. TextDataBase::BufferData::~BufferData()
  482. {
  483. bs_deleteN(WordBuffer, WordBufferSize);
  484. bs_deleteN(LineBuffer, LineBufferSize);
  485. bs_deleteN(PageBuffer, PageBufferSize);
  486. }
  487. UINT32 TextDataBase::BufferData::allocWord(bool spacer)
  488. {
  489. if(NextFreeWord >= WordBufferSize)
  490. {
  491. UINT32 newBufferSize = WordBufferSize * 2;
  492. TextWord* newBuffer = bs_newN<TextWord>(newBufferSize);
  493. memcpy(WordBuffer, newBuffer, WordBufferSize);
  494. bs_deleteN(WordBuffer, WordBufferSize);
  495. WordBuffer = newBuffer;
  496. WordBufferSize = newBufferSize;
  497. }
  498. WordBuffer[NextFreeWord].init(spacer);
  499. return NextFreeWord++;
  500. }
  501. UINT32 TextDataBase::BufferData::allocLine(TextDataBase* textData)
  502. {
  503. if(NextFreeLine >= LineBufferSize)
  504. {
  505. UINT32 newBufferSize = LineBufferSize * 2;
  506. TextLine* newBuffer = bs_newN<TextLine>(newBufferSize);
  507. memcpy(LineBuffer, newBuffer, LineBufferSize);
  508. bs_deleteN(LineBuffer, LineBufferSize);
  509. LineBuffer = newBuffer;
  510. LineBufferSize = newBufferSize;
  511. }
  512. LineBuffer[NextFreeLine].init(textData);
  513. return NextFreeLine++;
  514. }
  515. void TextDataBase::BufferData::deallocAll()
  516. {
  517. NextFreeWord = 0;
  518. NextFreeLine = 0;
  519. NextFreePageInfo = 0;
  520. }
  521. void TextDataBase::BufferData::addCharToPage(UINT32 page, const FontBitmap& fontData)
  522. {
  523. if(NextFreePageInfo >= PageBufferSize)
  524. {
  525. UINT32 newBufferSize = PageBufferSize * 2;
  526. PageInfo* newBuffer = bs_newN<PageInfo>(newBufferSize);
  527. memcpy((void*)PageBuffer, (void*)newBuffer, PageBufferSize);
  528. bs_deleteN(PageBuffer, PageBufferSize);
  529. PageBuffer = newBuffer;
  530. PageBufferSize = newBufferSize;
  531. }
  532. while(page >= NextFreePageInfo)
  533. {
  534. PageBuffer[NextFreePageInfo].numQuads = 0;
  535. NextFreePageInfo++;
  536. }
  537. PageBuffer[page].numQuads++;
  538. }
  539. UINT32 TextDataBase::getWidth() const
  540. {
  541. UINT32 width = 0;
  542. for(UINT32 i = 0; i < mNumLines; i++)
  543. width = std::max(width, mLines[i].getWidth());
  544. return width;
  545. }
  546. UINT32 TextDataBase::getHeight() const
  547. {
  548. UINT32 height = 0;
  549. for(UINT32 i = 0; i < mNumLines; i++)
  550. height += mLines[i].getHeight();
  551. return height;
  552. }
  553. }