暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FontEngineTests.cs 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. using UnityEngine;
  2. using UnityEditor;
  3. using NUnit.Framework;
  4. using UnityEngine.TextCore.LowLevel;
  5. namespace TMPro
  6. {
  7. [Category("Text Parsing & Layout")]
  8. class FontEngineTests
  9. {
  10. [OneTimeSetUp]
  11. public void Setup()
  12. {
  13. // Check if "TextMesh Pro" folder is present in project
  14. string folderPath = AssetDatabase.GUIDToAssetPath("f54d1bd14bd3ca042bd867b519fee8cc");
  15. if (string.IsNullOrEmpty(folderPath))
  16. {
  17. // Import TMP Essential Resources and TMP Examples & Extras
  18. TMP_PackageResourceImporter.ImportResources(true, true, false);
  19. }
  20. }
  21. [TestCase("e3265ab4bf004d28a9537516768c1c75", "Liberation Sans", "Regular")]
  22. [TestCase("4beb055f07aaff244873dec698d0363e", "Roboto", "Bold")]
  23. [TestCase("997a43b767814dd0a7642ec9b78cba41", "Anton", "Regular")]
  24. public void CreateFontAsset_from_FilePath(string fontFileGUID, string familyName, string styleName)
  25. {
  26. string filePath = AssetDatabase.GUIDToAssetPath(fontFileGUID);
  27. TMP_FontAsset fontAsset = TMP_FontAsset.CreateFontAsset(filePath, 0, 90, 9, GlyphRenderMode.SDFAA, 512, 512);
  28. Assert.NotNull(fontAsset);
  29. Assert.AreEqual(fontAsset.faceInfo.familyName, familyName);
  30. Assert.AreEqual(fontAsset.faceInfo.styleName, styleName);
  31. }
  32. [TestCase("e3265ab4bf004d28a9537516768c1c75", "Liberation Sans", "Regular")]
  33. [TestCase("4beb055f07aaff244873dec698d0363e", "Roboto", "Bold")]
  34. [TestCase("997a43b767814dd0a7642ec9b78cba41", "Anton", "Regular")]
  35. public void CreateFontAsset_from_FontObject(string fontFileGUID, string familyName, string styleName)
  36. {
  37. string filePath = AssetDatabase.GUIDToAssetPath(fontFileGUID);
  38. Font font = AssetDatabase.LoadAssetAtPath<Font>(filePath);
  39. TMP_FontAsset fontAsset = TMP_FontAsset.CreateFontAsset(font, 90, 9, GlyphRenderMode.SDFAA, 512, 512);
  40. Assert.NotNull(fontAsset);
  41. Assert.AreEqual(fontAsset.faceInfo.familyName, familyName);
  42. Assert.AreEqual(fontAsset.faceInfo.styleName, styleName);
  43. }
  44. [TestCase("e3265ab4bf004d28a9537516768c1c75", "Liberation Sans", "Regular")]
  45. public void TryAddCharacters_SanityCheck(string fontFileGUID, string familyName, string styleName)
  46. {
  47. string filePath = AssetDatabase.GUIDToAssetPath(fontFileGUID);
  48. TMP_FontAsset fontAsset = TMP_FontAsset.CreateFontAsset(filePath, 0, 90, 9, GlyphRenderMode.SDFAA, 512, 512);
  49. Assert.NotNull(fontAsset);
  50. fontAsset.TryAddCharacters("abc");
  51. Assert.IsTrue(fontAsset.HasCharacters("abc"));
  52. }
  53. // =============================================
  54. // FONT ENGINE - OPENTYPE TESTS
  55. // =============================================
  56. #if TEXTCORE_FONT_ENGINE_1_5_OR_NEWER
  57. [TestCase("e3265ab4bf004d28a9537516768c1c75", 1)]
  58. [TestCase("4beb055f07aaff244873dec698d0363e", 623)]
  59. [TestCase("24007ea0bd4d6b2418f4caf1b06e2cb4", 43)]
  60. public void GetSingleSubstitutionRecords(string fontFileGUID, int recordCount)
  61. {
  62. string filePath = AssetDatabase.GUIDToAssetPath(fontFileGUID);
  63. if (FontEngine.LoadFontFace(filePath) != FontEngineError.Success)
  64. return;
  65. UnityEngine.TextCore.LowLevel.SingleSubstitutionRecord[] records = FontEngine.GetAllSingleSubstitutionRecords();
  66. if (records == null)
  67. return;
  68. Assert.AreEqual(recordCount, records.Length);
  69. }
  70. [TestCase("47a9b34e6f77bbd4d94f512d266bcd0c", 77)] // Inter - Regular
  71. public void GetAlternateSubstitutionRecords(string fontFileGUID, int recordCount)
  72. {
  73. string filePath = AssetDatabase.GUIDToAssetPath(fontFileGUID);
  74. if (FontEngine.LoadFontFace(filePath) != FontEngineError.Success)
  75. return;
  76. UnityEngine.TextCore.LowLevel.AlternateSubstitutionRecord[] records = FontEngine.GetAllAlternateSubstitutionRecords();
  77. if (records == null)
  78. return;
  79. Assert.AreEqual(recordCount, records.Length);
  80. }
  81. [TestCase("e3265ab4bf004d28a9537516768c1c75", 184)]
  82. [TestCase("4beb055f07aaff244873dec698d0363e", 177)]
  83. [TestCase("c9f6d0e7bc8541498c9a4799ba184ede", 5)]
  84. public void GetLigatures(string fontFileGUID, int recordCount)
  85. {
  86. string filePath = AssetDatabase.GUIDToAssetPath(fontFileGUID);
  87. if (FontEngine.LoadFontFace(filePath) != FontEngineError.Success)
  88. return;
  89. UnityEngine.TextCore.LowLevel.LigatureSubstitutionRecord[] records = FontEngine.GetAllLigatureSubstitutionRecords();
  90. if (records == null)
  91. return;
  92. Assert.AreEqual(recordCount, records.Length);
  93. }
  94. [TestCase("e3265ab4bf004d28a9537516768c1c75", 2016)]
  95. [TestCase("4beb055f07aaff244873dec698d0363e", 70027)]
  96. [TestCase("c9f6d0e7bc8541498c9a4799ba184ede", 1940)]
  97. public void GetPairAdjustmentRecords(string fontFileGUID, int recordCount)
  98. {
  99. string filePath = AssetDatabase.GUIDToAssetPath(fontFileGUID);
  100. if (FontEngine.LoadFontFace(filePath) != FontEngineError.Success)
  101. return;
  102. GlyphPairAdjustmentRecord[] records = FontEngine.GetAllPairAdjustmentRecords();
  103. if (records == null)
  104. return;
  105. Assert.AreEqual(recordCount, records.Length);
  106. }
  107. [TestCase("e3265ab4bf004d28a9537516768c1c75", 8911)]
  108. [TestCase("4beb055f07aaff244873dec698d0363e", 0)]
  109. [TestCase("24007ea0bd4d6b2418f4caf1b06e2cb4", 432)]
  110. public void GetMarkToBaseAdjustmentRecords(string fontFileGUID, int recordCount)
  111. {
  112. string filePath = AssetDatabase.GUIDToAssetPath(fontFileGUID);
  113. if (FontEngine.LoadFontFace(filePath) != FontEngineError.Success)
  114. return;
  115. UnityEngine.TextCore.LowLevel.MarkToBaseAdjustmentRecord[] records = FontEngine.GetAllMarkToBaseAdjustmentRecords();
  116. if (records == null)
  117. return;
  118. Assert.AreEqual(recordCount, records.Length);
  119. }
  120. [TestCase("e3265ab4bf004d28a9537516768c1c75", 0)]
  121. [TestCase("4beb055f07aaff244873dec698d0363e", 0)]
  122. [TestCase("24007ea0bd4d6b2418f4caf1b06e2cb4", 324)]
  123. public void GetMarkToMarkAdjustmentRecords(string fontFileGUID, int recordCount)
  124. {
  125. string filePath = AssetDatabase.GUIDToAssetPath(fontFileGUID);
  126. if (FontEngine.LoadFontFace(filePath) != FontEngineError.Success)
  127. return;
  128. UnityEngine.TextCore.LowLevel.MarkToMarkAdjustmentRecord[] records = FontEngine.GetAllMarkToMarkAdjustmentRecords();
  129. if (records == null)
  130. return;
  131. Assert.AreEqual(recordCount, records.Length);
  132. }
  133. // GetOpenTypeFontFeatureList throws NotImplementedException with new FontEngine changes to support FontFeature (TEXTCORE_FONT_ENGINE_1_5_OR_NEWER)
  134. /*
  135. [TestCase("e3265ab4bf004d28a9537516768c1c75", 0)]
  136. [TestCase("4beb055f07aaff244873dec698d0363e", 0)]
  137. [TestCase("24007ea0bd4d6b2418f4caf1b06e2cb4", 324)]
  138. [TestCase("47a9b34e6f77bbd4d94f512d266bcd0c", 324)]
  139. [TestCase("d01f31227e1b4cd49bc293f44aab2253", 324)]
  140. public void GetFontFeatureList(string fontFileGUID, int recordCount)
  141. {
  142. string filePath = AssetDatabase.GUIDToAssetPath(fontFileGUID);
  143. if (FontEngine.LoadFontFace(filePath) != FontEngineError.Success)
  144. return;
  145. OpenTypeFeature[] fontFeatureList = FontEngine.GetOpenTypeFontFeatureList();
  146. if (fontFeatureList == null)
  147. return;
  148. Assert.AreEqual(recordCount, fontFeatureList.Length);
  149. } */
  150. #endif
  151. }
  152. }