BsTextData.cpp 17 KB

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