BsTextData.cpp 18 KB

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