PageRenderTime 55ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/Rendering/BasicTests/FontTests.cs

#
C# | 737 lines | 522 code | 78 blank | 137 comment | 37 complexity | 4e55233fee16df54ded4851700d36296 MD5 | raw file
Possible License(s): Apache-2.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Text;
  5. using Delta.ContentSystem.Rendering;
  6. using Delta.Engine;
  7. using Delta.InputSystem;
  8. using Delta.InputSystem.Devices;
  9. using Delta.Rendering.Basics.Drawing;
  10. using Delta.Rendering.Basics.Fonts;
  11. using Delta.Rendering.Basics.Materials;
  12. using Delta.Rendering.Enums;
  13. using Delta.Utilities;
  14. using Delta.Utilities.Datatypes;
  15. using Delta.Utilities.Datatypes.Advanced;
  16. using Delta.Utilities.Graphics;
  17. using Delta.Utilities.Helpers;
  18. using NUnit.Framework;
  19. namespace Delta.Rendering.BasicTests
  20. {
  21. /// <summary>
  22. /// All unit tests for the Delta.Rendering.Fonts module.
  23. /// <para />
  24. /// Reference of "famous" test sentences for bitmap fonts:
  25. /// http://forums.appleinsider.com/archive/index.php/t-57707.html
  26. /// </summary>
  27. public class FontTests
  28. {
  29. #region DrawSimpleText (Static)
  30. /// <summary>
  31. /// Draw simple text in the center of the screen. Also used as a font
  32. /// rendering performance test. In both debug and release mode and even
  33. /// with attached profiler we can reach the max. fps here (10k on my
  34. /// system in OpenTK, Sandy Bridge 4Ghz, GeForce 480). It gets interesting
  35. /// when disabling swap buffer, clear and geometry rendering, then the fps
  36. /// goes up to 1.5 million in release mode and 600 000 fps in debug mode :)
  37. /// </summary>
  38. [Test]
  39. public static void DrawSimpleText()
  40. {
  41. Application.Start(delegate
  42. {
  43. Font.Default.Draw("Hi there",
  44. Rectangle.FromCenter(Point.Half, Size.Half));
  45. });
  46. }
  47. #endregion
  48. #region TestTextAlignment (Static)
  49. /// <summary>
  50. /// TestTextAlignment with some helper lines, boxes and font map to see
  51. /// if everything is pixel aligned correctly.
  52. /// </summary>
  53. [Test]
  54. public static void TestTextAlignment()
  55. {
  56. Material2D fontMaterial = new Material2D("Verdana_9_16");
  57. Application.Start(delegate
  58. {
  59. Line.Draw(Point.Zero, Point.One, Color.Green);
  60. Material2D.Default.Draw(ScreenSpace.ToQuadraticSpace(
  61. new Rectangle(0, 0, 10, 10)));
  62. Font.Default.Draw(
  63. Application.Window.ViewportPixelWidth + "," +
  64. Application.Window.ViewportPixelHeight, ScreenSpace.DrawArea);
  65. fontMaterial.Draw(ScreenSpace.ToQuadraticSpace(
  66. new Rectangle(10, 70, 128, 128)));//test: 113 0 7 12
  67. });
  68. }
  69. #endregion
  70. #region DrawSingleLineTextCentered (Static)
  71. /// <summary>
  72. /// Draw single line text centered
  73. /// </summary>
  74. [Test]
  75. public static void DrawSingleLineTextCentered()
  76. {
  77. Application.Start(delegate
  78. {
  79. Font.Default.Draw("Jackdaws love my big sphinx of quartz.",
  80. Rectangle.FromCenter(0.5f, 0.5f, 0.2f, 0.2f));
  81. });
  82. }
  83. #endregion
  84. #region DrawSingleLineTextTopLeft (Static)
  85. /// <summary>
  86. /// Draw single line text in the top left corner
  87. /// </summary>
  88. [Test]
  89. public static void DrawSingleLineTextTopLeft()
  90. {
  91. Application.Start(delegate
  92. {
  93. Font.DrawTopLeftInformation("Jackdaws love my big sphinx of quartz.");
  94. });
  95. }
  96. #endregion
  97. #region DrawMultiLineText (Static)
  98. /// <summary>
  99. /// Draw multi line text
  100. /// </summary>
  101. [Test]
  102. public static void DrawMultiLineText()
  103. {
  104. Font infoFont = new Font(Font.Default,
  105. HorizontalAlignment.Left, VerticalAlignment.Top);
  106. Application.Start(delegate
  107. {
  108. infoFont.Draw(
  109. "Jackdaws love my big sphinx of quartz.\n" +
  110. "But another idiom is:\r\n" +
  111. "Six big juicy steaks sizzled in a pan as five workmen left the" +
  112. " quarry.\r" +
  113. ":)",
  114. new Rectangle(0.5f, 0.5f, 0.2f, infoFont.LineHeight));
  115. });
  116. }
  117. #endregion
  118. #region MeasureSingleLineText (Static)
  119. /// <summary>
  120. /// Measure single line text
  121. /// </summary>
  122. [Test]
  123. public static void MeasureSingleLineText()
  124. {
  125. const string Text = "Jackdaws love my big sphinx of quartz.";
  126. Font infoFont = new Font(Font.Default,
  127. HorizontalAlignment.Left, VerticalAlignment.Top);
  128. Point textStartPosition = Point.Half;
  129. Application.Start(delegate
  130. {
  131. // Measure the text
  132. Size textSize = infoFont.Measure(Text);
  133. // and draw the measured text size
  134. Rect.DrawOutline(new Rectangle(textStartPosition, textSize),
  135. Color.Red);
  136. // and additionally the original text to check if the computed text
  137. // fits with the drawn text too
  138. infoFont.Draw(Text, new Rectangle(textStartPosition,
  139. new Size(0.2f, infoFont.LineHeight)));
  140. });
  141. }
  142. #endregion
  143. #region MeasureMultiLineText (Static)
  144. /// <summary>
  145. /// Measure multi line text
  146. /// </summary>
  147. [Test]
  148. public static void MeasureMultiLineText()
  149. {
  150. string text =
  151. "Jackdaws love my big sphinx of quartz.\n" +
  152. "But another idiom is:\r\n" +
  153. "Six big juicy steaks sizzled in a pan as five workmen left the" +
  154. " quarry.\r" +
  155. ":)";
  156. Font infoFont = new Font(Font.Default,
  157. HorizontalAlignment.Left, VerticalAlignment.Top);
  158. Point textStartPos = new Point(0.2f, 0.4f);
  159. Application.Start(delegate
  160. {
  161. // Measure the text
  162. Size textSize = infoFont.Measure(text);
  163. // and draw the measured text size
  164. Rect.DrawOutline(new Rectangle(textStartPos, textSize), Color.Red);
  165. // and additionally the original text to prove if the computed text
  166. // fits with the drawn text too
  167. Size availableTextSize = textSize * 1.25f;
  168. infoFont.Draw(text, new Rectangle(textStartPos, availableTextSize));
  169. // and draw also the available text size
  170. Rect.DrawOutline(new Rectangle(textStartPos, availableTextSize),
  171. Color.Green);
  172. });
  173. }
  174. #endregion
  175. #region MeasureTab (Static)
  176. /// <summary>
  177. /// Measure tab
  178. /// </summary>
  179. [Test]
  180. public static void MeasureTab()
  181. {
  182. Font infoFont = new Font(Font.Default,
  183. HorizontalAlignment.Left, VerticalAlignment.Top);
  184. Point textStartPosition = Point.Half;
  185. Application.Start(delegate
  186. {
  187. // Measure the tab
  188. Size numberSize = infoFont.Measure("0");
  189. Size tabSize = infoFont.Measure("\t");
  190. // and draw the measured text size
  191. Rectangle tabRectangle = new Rectangle(textStartPosition, tabSize);
  192. tabRectangle.X += numberSize.Width;
  193. Rect.DrawOutline(tabRectangle, Color.Red);
  194. // and addionally the tab + some text for better visualization and
  195. // comparing it
  196. infoFont.Draw("0\t123456789", new Rectangle(textStartPosition,
  197. new Size(0.2f, infoFont.LineHeight)));
  198. // wit normal spaces
  199. infoFont.Draw("0 1 2 3 456789", new Rectangle(textStartPosition.X,
  200. textStartPosition.Y + infoFont.LineHeight,
  201. 0.2f, infoFont.LineHeight));
  202. });
  203. }
  204. #endregion
  205. #region DrawSingleLineTextAligned (Static)
  206. /// <summary>
  207. /// Draw single line text aligned
  208. /// </summary>
  209. [Test]
  210. public static void DrawSingleLineTextAligned()
  211. {
  212. // Get the number of available horizontal
  213. int horizontalAlignmentModes =
  214. EnumHelper.GetCount<HorizontalAlignment>();
  215. // and vertical alignment modes
  216. int verticalAlignmentModes =
  217. EnumHelper.GetCount<VerticalAlignment>();
  218. // Create fonts with every horizontal and vertical alignment mode
  219. Font[,] fonts =
  220. new Font[horizontalAlignmentModes, verticalAlignmentModes];
  221. for (int hModeId = 0; hModeId < horizontalAlignmentModes; hModeId++)
  222. {
  223. for (int vModeId = 0; vModeId < verticalAlignmentModes; vModeId++)
  224. {
  225. fonts[hModeId, vModeId] = new Font(Font.Default,
  226. (HorizontalAlignment)hModeId, (VerticalAlignment)vModeId);
  227. }
  228. }
  229. Application.Start(delegate
  230. {
  231. // Show a text with every possible horizontal and vertical alignment
  232. for (int hModeId = 0; hModeId < horizontalAlignmentModes; hModeId++)
  233. {
  234. for (int vModeId = 0; vModeId < verticalAlignmentModes; vModeId++)
  235. {
  236. // While the code for all fonts is the same, the actual rendering
  237. // will appear at different locations on the screen depending on
  238. // the current alignment combination.
  239. Font font = fonts[hModeId, vModeId];
  240. font.Draw(
  241. "Text at '" + font.HorizontalAlignment + " " +
  242. font.VerticalAlignment + "'", ScreenSpace.DrawArea);
  243. }
  244. }
  245. });
  246. }
  247. #endregion
  248. #region DrawMultiLineTextAligned (Static)
  249. /// <summary>
  250. /// Draw multi line text aligned
  251. /// </summary>
  252. [Test]
  253. public static void DrawMultiLineTextAligned()
  254. {
  255. // Get the number of available horizontal
  256. int horizontalAlignmentModes =
  257. EnumHelper.GetCount<HorizontalAlignment>();
  258. // and vertical alignment modes
  259. int verticalAlignmentModes =
  260. EnumHelper.GetCount<VerticalAlignment>();
  261. // Create fonts with every horizontal and vertical alignment mode
  262. Font[,] fonts =
  263. new Font[horizontalAlignmentModes,verticalAlignmentModes];
  264. for (int hModeId = 0; hModeId < horizontalAlignmentModes; hModeId++)
  265. {
  266. for (int vModeId = 0; vModeId < verticalAlignmentModes; vModeId++)
  267. {
  268. fonts[hModeId, vModeId] = new Font(Font.Default,
  269. (HorizontalAlignment)hModeId, (VerticalAlignment)vModeId);
  270. }
  271. }
  272. Application.Start(delegate
  273. {
  274. // Draw outline of the area we use to draw all fonts
  275. Rectangle drawArea = ScreenSpace.DrawArea.ScaleCentered(0.99f);
  276. Rect.DrawOutline(ScreenSpace.DrawArea, Color.Blue);
  277. // Show a text with every possible horizontal and vertical alignment
  278. for (int hModeId = 0; hModeId < horizontalAlignmentModes; hModeId++)
  279. {
  280. for (int vModeId = 0; vModeId < verticalAlignmentModes; vModeId++)
  281. {
  282. // While the code for all fonts is the same, the actual rendering
  283. // will appear at different locations on the screen depending on
  284. // the current alignment combination.
  285. Font font = fonts[hModeId, vModeId];
  286. string text =
  287. "This text is in the" + Environment.NewLine +
  288. font.VerticalAlignment + " " + font.HorizontalAlignment +
  289. Environment.NewLine + "alignment mode.";
  290. font.Draw(text, drawArea);
  291. } // for
  292. } // for
  293. });
  294. }
  295. #endregion
  296. #region DrawTextClipped (Static)
  297. /// <summary>
  298. /// Draw text clipped
  299. /// </summary>
  300. [Test]
  301. public static void DrawTextClipped()
  302. {
  303. const string Text = "That text should be only inside red box.";
  304. Point textAreaPos = new Point(0.2f, 0.45f);
  305. Application.Start(delegate
  306. {
  307. Size maxTextSize = Font.Default.Measure(Text);
  308. Font.Default.Draw(
  309. Text + "If you are still seeing text outside of the" +
  310. " shown box,\nthen you know the clipping doesn't work :(",
  311. new Rectangle(textAreaPos, maxTextSize));
  312. Rect.DrawOutline(new Rectangle(textAreaPos, maxTextSize), Color.Red);
  313. });
  314. }
  315. #endregion
  316. #region DrawTextWordWrapped (Static)
  317. /// <summary>
  318. /// Draw text word wrapped
  319. /// </summary>
  320. [Test]
  321. public static void DrawTextWordWrapped()
  322. {
  323. string text = "long loong looong loooong text";
  324. text += Environment.NewLine + "Newline";
  325. Font infoFont = new Font(Font.Default, Color.White,
  326. HorizontalAlignment.Left, VerticalAlignment.Top, true);
  327. Rectangle textArea = new Rectangle(0.2f, 0.45f, 0.135f, 0.05f);
  328. Application.Start(delegate
  329. {
  330. infoFont.Draw(text, textArea);
  331. Rect.DrawOutline(textArea, Color.Red);
  332. BaseMouse mouse = Input.Mouse;
  333. if (Input.Gestures.IsDrag)
  334. {
  335. // Compute the drag movement per tick
  336. textArea.Size += (Size)(mouse.Movement);
  337. } // if
  338. });
  339. }
  340. #endregion
  341. #region DrawTextResolutionBased (Static)
  342. /// <summary>
  343. /// Draw text resolution based
  344. /// </summary>
  345. [Test]
  346. public static void DrawTextResolutionBased()
  347. {
  348. Application.Start(delegate
  349. {
  350. string fontInfoText =
  351. "Current resolution: '" + Settings.Resolution + "'\n" +
  352. "Current font size: '" + Font.Default.CurrentFontSize + "'";
  353. Font.Default.Draw(fontInfoText, ScreenSpace.DrawArea);
  354. // Switch the 4 supported font scaling-steps by pressing the numbers
  355. // 1-4 on the keyboard
  356. if (Input.Keyboard.IsReleased(InputButton.D1))
  357. {
  358. Application.Window.Resize(480, 320);
  359. } // if
  360. else if (Input.Keyboard.IsReleased(InputButton.D2))
  361. {
  362. Application.Window.Resize(800, 480);
  363. } // if
  364. else if (Input.Keyboard.IsReleased(InputButton.D3))
  365. {
  366. Application.Window.Resize(1024, 768);
  367. } // if
  368. else if (Input.Keyboard.IsReleased(InputButton.D4))
  369. {
  370. Application.Window.Resize(1920, 1080);
  371. } // if
  372. });
  373. }
  374. #endregion
  375. #region RotationResearchTest (Static)
  376. /// <summary>
  377. /// Rotation research test
  378. /// </summary>
  379. [Test]
  380. private static void RotationResearchTest()
  381. {
  382. Rectangle textArea = new Rectangle(0.5f, 0.5f, 0.2f,
  383. 0.025f);
  384. Rectangle glyphArea = new Rectangle(0.0f, 0.0f, 0.015f,
  385. 0.02f);
  386. float rotation = 0.0f;
  387. //rotation = 1.0f;
  388. Application.Start(delegate
  389. {
  390. // Rotate 10 degree per second
  391. rotation += 22.5f * Time.Delta;
  392. Rect.DrawOutline(textArea, Color.Red, rotation);
  393. Point startPos = new Point(textArea.Left, textArea.Center.Y);
  394. Point rotationOffset =
  395. (startPos + new Point(glyphArea.Width / 2.0f, 0.0f)) -
  396. textArea.Center;
  397. rotationOffset.Rotate(rotation);
  398. Point nextGlyphCenterPoint = textArea.Center + rotationOffset;
  399. Line.Draw(textArea.Center, nextGlyphCenterPoint, Color.Orange);
  400. //Line.Draw(textArea.Center, textArea.BottomRight, Color.Orange);
  401. Rect.DrawOutline(
  402. Rectangle.FromCenter(nextGlyphCenterPoint, glyphArea.Size),
  403. Color.Green,
  404. rotation);
  405. });
  406. }
  407. #endregion
  408. #region DrawSingleLineRotatedText (Static)
  409. /// <summary>
  410. /// Draw single line rotated text
  411. /// </summary>
  412. [Test]
  413. public static void DrawSingleLineRotatedText()
  414. {
  415. string text = "Jackdaws love my big sphinx of quartz.";
  416. Rectangle textArea = new Rectangle(0.5f, 0.5f,
  417. // We don't care about the size, do not clip!
  418. 0.0f, 0.0f);//0.2f, infoFont.LineHeight);
  419. float rotation = 0.0f;
  420. Application.Start(delegate
  421. {
  422. // Draw reference how the unrotated text should look like
  423. Font.Default.Draw(text,
  424. Rectangle.FromCenter(0.5f, 0.25f, 0.25f, 0.25f));
  425. // Rotate 90 degree per second (4 seconds for a full rotation)
  426. if (Input.Keyboard.IsPressed(InputButton.Shift) == false)
  427. {
  428. // Only rotate if Shift is not pressed
  429. rotation += 90.0f * Time.Delta;
  430. }
  431. // Helper to see the circle we are rotating around in
  432. if (Input.Keyboard.IsPressed(InputButton.Space))
  433. {
  434. Circle.DrawOutline(new Point(0.5f, 0.5f), 0.2f, Color.Red);
  435. }
  436. // Helpers to see if text is still sharp at 0, 90, 180 and 270 degrees
  437. if (Input.Keyboard.IsPressed(InputButton.A))
  438. {
  439. rotation = 0;
  440. }
  441. else if (Input.Keyboard.IsPressed(InputButton.B))
  442. {
  443. rotation = 90;
  444. }
  445. else if (Input.Keyboard.IsPressed(InputButton.C))
  446. {
  447. rotation = 180;
  448. }
  449. else if (Input.Keyboard.IsPressed(InputButton.D))
  450. {
  451. rotation = 270;
  452. }
  453. Font.Default.Draw(text, textArea, rotation, Point.Zero);
  454. });
  455. }
  456. #endregion
  457. #region CompareFontKerning (LongRunning)
  458. /// <summary>
  459. /// Compare font kerning
  460. /// </summary>
  461. [Test, Category("LongRunning")]
  462. public static void CompareFontKerning()
  463. {
  464. // First define the fonts
  465. Font noKerningFont = new Font(
  466. FontData.Get("VerdanaNoKerning", 28, FontStyle.AddOutline),
  467. HorizontalAlignment.Left);
  468. Font kerningFont = new Font(
  469. FontData.Get("Verdana", 28, FontStyle.AddOutline),
  470. HorizontalAlignment.Left);
  471. // As next the text we want to see with and without kerning
  472. const string Text = "P. and V.";
  473. // also the text area (reference) for the text drawing
  474. Rectangle textArea = new Rectangle(0.5f, 0.4f, 0.3f,
  475. kerningFont.LineHeight);
  476. Application.Start(delegate
  477. {
  478. // Now just show the text without kerning
  479. noKerningFont.Draw("Without kerning: ", textArea.Move(-0.3f, 0.0f));
  480. noKerningFont.Draw(Text, textArea);
  481. // And once with kerning to see the difference
  482. noKerningFont.Draw("With kerning: ", textArea.Move(-0.3f,
  483. kerningFont.LineHeight));
  484. kerningFont.Draw(Text, textArea.Move(0.0f,
  485. kerningFont.LineHeight));
  486. });
  487. }
  488. #endregion
  489. #region DrawMultiLineRotatedText (LongRunning)
  490. /// <summary>
  491. /// Draw multi line rotated text
  492. /// </summary>
  493. [Test, Category("LongRunning")]
  494. public static void DrawMultiLineRotatedText()
  495. {
  496. string text =
  497. "Jackdaws love my big sphinx of quartz.\n" +
  498. "But another idiom is:\r\n" +
  499. "Six big juicy steaks sizzled.";
  500. Rectangle textArea =
  501. new Rectangle(0.35f, 0.25f, 0.3f, Font.Default.LineHeight * 3.0f);
  502. float rotation = 0.0f;
  503. Application.Start(delegate
  504. {
  505. // Draw reference how the unrotated text should look like
  506. Font.Default.Draw(text, textArea, 0.0f, Point.Zero);
  507. // Rotate 90 degree per second
  508. rotation += 90.0f * Time.Delta;
  509. Font.Default.Draw(text, textArea.Move(0.0f, 0.25f), rotation,
  510. Point.Zero);
  511. });
  512. }
  513. #endregion
  514. #region DrawPerformanceTest
  515. /// <summary>
  516. /// Draw performance test
  517. /// </summary>
  518. [Test, Category("Visual")]
  519. public static void DrawPerformanceTest()
  520. {
  521. string[] texts = new[]
  522. {
  523. "Hello World",
  524. " !\"#$%&'()*+,-./0123456789:;<=>?@",
  525. "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`",
  526. "abcdefghijklmnopqrstuvwxyz{|}~",
  527. "That kind of drawing text is interresting.",
  528. "Hello World"
  529. };
  530. Font infoFont = new Font(Font.Default,
  531. HorizontalAlignment.Left, VerticalAlignment.Top);
  532. Size textSize = new Size(1.0f, infoFont.LineHeight * 3);
  533. Application.Start(delegate
  534. {
  535. for (int index = 0; index < texts.Length; index++)
  536. {
  537. Rectangle textArea = new Rectangle(
  538. new Point(0.1f, 0.2f + index * infoFont.LineHeight * 2.5f),
  539. textSize);
  540. // old: Judge: Win 7, Core i7 920, 6 GB Ram, Ati 5750 HD
  541. // - Draw with GlyphInfo[] -> ~2540 FPS
  542. // - Draw with Geometry -> ~3170 FPS
  543. // Optimized to ~10000 FPS on Sandy Bridge 4Ghz, GeForce 480.
  544. // without swapbuffer/clear/render this is ~250000 FPS (in debug
  545. // mode, in release mode we can reach 3 times that)
  546. // Drawing by cached glyph info's
  547. infoFont.Draw(texts[index], textArea, 0.0f, Point.Zero);
  548. // on the mobile devices
  549. //// Drawing by cached geomtry
  550. //infoFont.Draw(texts[index], textArea, 0.0f, Point.Zero);
  551. }
  552. //no thanks to auto quit
  553. //if (Time.Seconds >= 3)
  554. //{
  555. // Application.Quit();
  556. //} // if
  557. });
  558. }
  559. #endregion
  560. #region TestCharCollectingPerformance (Static)
  561. /// <summary>
  562. /// Test char collecting
  563. /// </summary>
  564. [Test]
  565. private static void TestCharCollectingPerformance()
  566. {
  567. string text = "ehoiwrhaenf ierfh ioei hEWOIHoeirjnlsdnflsdn osdjfsdfö " +
  568. "ashnfdeir aweho nklidfhwioerhoewir knskdfla jrfweimwaemfijefe ids " +
  569. "löginjaqw ioiai wrjnuiu na ua safooiuroiwrpewr jioa djijwrweruqwer" +
  570. "iodjpjanvlxic9prtgopüaj opdu 39483 rawü ß asd 0po asd ak lkjdfau80" +
  571. "ok09i2jqaw 9 9a du opjo34eqwrjfaj oas parörpo3ir0 wakasj ööas foMF" +
  572. "esifjhaierf idsfj lijef iodsfjinnhdf dfhhidsio idinqäppa osao oad";
  573. int Loops = 100000;
  574. char[] textChars = text.ToCharArray();
  575. Stopwatch time = new Stopwatch();
  576. List<char> charList = new List<char>();
  577. time.Start();
  578. for (int i = 0; i < Loops; i++)
  579. {
  580. for (int charId = 0; charId < textChars.Length; charId++)
  581. {
  582. charList.Add(textChars[charId]);
  583. }
  584. charList.Clear();
  585. }
  586. time.Stop();
  587. Log.Info("'" + time.ElapsedMilliseconds + "' ms elapsed.");
  588. string charString = "";
  589. time.Restart();
  590. for (int i = 0; i < Loops; i++)
  591. {
  592. for (int charId = 0; charId < textChars.Length; charId++)
  593. {
  594. charString += textChars[charId];
  595. }
  596. charString = "";
  597. }
  598. time.Stop();
  599. Log.Info("'" + time.ElapsedMilliseconds + "' ms elapsed.");
  600. StringBuilder charBuilder = new StringBuilder();
  601. time.Restart();
  602. for (int i = 0; i < Loops; i++)
  603. {
  604. for (int charId = 0; charId < textChars.Length; charId++)
  605. {
  606. charBuilder.Append(textChars[charId]);
  607. }
  608. charBuilder.Clear();
  609. }
  610. time.Stop();
  611. Log.Info("'" + time.ElapsedMilliseconds + "' ms elapsed.");
  612. List<char> list = new List<char>();
  613. time.Restart();
  614. for (int i = 0; i < Loops; i++)
  615. {
  616. char[] chars = text.ToCharArray();
  617. for (int charId = 0; charId < chars.Length; charId++)
  618. {
  619. list.Add(chars[charId]);
  620. }
  621. charString = "";
  622. }
  623. time.Stop();
  624. Log.Info("'" + time.ElapsedMilliseconds + "' ms elapsed.");
  625. list = new List<char>();
  626. time.Restart();
  627. for (int i = 0; i < Loops; i++)
  628. {
  629. for (int charId = 0; charId < text.Length; charId++)
  630. {
  631. list.Add(text[charId]);
  632. }
  633. charString = "";
  634. }
  635. time.Stop();
  636. Log.Info("'" + time.ElapsedMilliseconds + "' ms elapsed.");
  637. }
  638. #endregion
  639. #region TestFontRamBug (Static)
  640. /// <summary>
  641. /// Test the bug #4015 with massively increasing ram as posted here:
  642. /// http://forum.deltaengine.net/yaf_postsm851_-Bug--Or-WTF-RAM-Faill.aspx#post851
  643. /// </summary>
  644. [Test]
  645. public static void TestFontRamBug()
  646. {
  647. int tmp = 0;
  648. string inputText;
  649. Application.Start(delegate
  650. {
  651. // Constantly change the text to be rendered.
  652. tmp++;
  653. inputText = "Level1 \n" + tmp;
  654. Font.Default.Draw(inputText, new Rectangle(0.025f, 0.45f, 0.3f, 0.3f));
  655. });
  656. }
  657. #endregion
  658. }
  659. }