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.

426 lines
12 KiB

  1. using UnityEngine;
  2. using System;
  3. using System.Collections.Generic;
  4. namespace TMPro
  5. {
  6. /// <summary>
  7. /// Flags to control what vertex data is pushed to the mesh and renderer.
  8. /// </summary>
  9. public enum TMP_VertexDataUpdateFlags
  10. {
  11. None = 0x0,
  12. Vertices = 0x1,
  13. Uv0 = 0x2,
  14. Uv2 = 0x4,
  15. Uv4 = 0x8,
  16. Colors32 = 0x10,
  17. All = 0xFF
  18. };
  19. /// <summary>
  20. /// TMP custom data type to represent 32 bit characters.
  21. /// </summary>
  22. //public struct TMP_Char
  23. //{
  24. // private int m_value;
  25. // private TMP_Char(int value)
  26. // {
  27. // this.m_value = value;
  28. // }
  29. // private TMP_Char(TMP_Char value)
  30. // {
  31. // this.m_value = (int)value;
  32. // }
  33. // public static implicit operator TMP_Char(int value)
  34. // {
  35. // return new TMP_Char(value);
  36. // }
  37. // public static implicit operator TMP_Char(char c)
  38. // {
  39. // return new TMP_Char(c);
  40. // }
  41. // public static explicit operator int(TMP_Char value)
  42. // {
  43. // return value.m_value;
  44. // }
  45. // public override string ToString()
  46. // {
  47. // return m_value.ToString();
  48. // }
  49. //}
  50. /// <summary>
  51. /// Structure containing information about individual text elements (character or sprites).
  52. /// </summary>
  53. //[Serializable]
  54. public struct TMP_CharacterInfo
  55. {
  56. public char character; // Should be changed to an int to handle UTF 32
  57. /// <summary>
  58. /// Index of the character in the raw string.
  59. /// </summary>
  60. public int index; // Index of the character in the input string.
  61. public TMP_TextElementType elementType;
  62. public TMP_TextElement textElement;
  63. public TMP_FontAsset fontAsset;
  64. public TMP_SpriteAsset spriteAsset;
  65. public int spriteIndex;
  66. public Material material;
  67. public int materialReferenceIndex;
  68. public bool isUsingAlternateTypeface;
  69. public float pointSize;
  70. //public short wordNumber;
  71. public int lineNumber;
  72. //public short charNumber;
  73. public int pageNumber;
  74. public int vertexIndex;
  75. public TMP_Vertex vertex_TL;
  76. public TMP_Vertex vertex_BL;
  77. public TMP_Vertex vertex_TR;
  78. public TMP_Vertex vertex_BR;
  79. public Vector3 topLeft;
  80. public Vector3 bottomLeft;
  81. public Vector3 topRight;
  82. public Vector3 bottomRight;
  83. public float origin;
  84. public float ascender;
  85. public float baseLine;
  86. public float descender;
  87. public float xAdvance;
  88. public float aspectRatio;
  89. public float scale;
  90. public Color32 color;
  91. public Color32 underlineColor;
  92. public Color32 strikethroughColor;
  93. public Color32 highlightColor;
  94. public FontStyles style;
  95. public bool isVisible;
  96. //public bool isIgnoringAlignment;
  97. }
  98. public struct TMP_Vertex
  99. {
  100. public Vector3 position;
  101. public Vector2 uv;
  102. public Vector2 uv2;
  103. public Vector2 uv4;
  104. public Color32 color;
  105. //public Vector3 normal;
  106. //public Vector4 tangent;
  107. }
  108. //public struct TMP_VertexInfo
  109. //{
  110. // public TMP_Vertex topLeft;
  111. // public TMP_Vertex bottomLeft;
  112. // public TMP_Vertex topRight;
  113. // public TMP_Vertex bottomRight;
  114. //}
  115. [Serializable]
  116. public struct VertexGradient
  117. {
  118. public Color topLeft;
  119. public Color topRight;
  120. public Color bottomLeft;
  121. public Color bottomRight;
  122. public VertexGradient (Color color)
  123. {
  124. this.topLeft = color;
  125. this.topRight = color;
  126. this.bottomLeft = color;
  127. this.bottomRight = color;
  128. }
  129. /// <summary>
  130. /// The vertex colors at the corners of the characters.
  131. /// </summary>
  132. /// <param name="color0">Top left color.</param>
  133. /// <param name="color1">Top right color.</param>
  134. /// <param name="color2">Bottom left color.</param>
  135. /// <param name="color3">Bottom right color.</param>
  136. public VertexGradient(Color color0, Color color1, Color color2, Color color3)
  137. {
  138. this.topLeft = color0;
  139. this.topRight = color1;
  140. this.bottomLeft = color2;
  141. this.bottomRight = color3;
  142. }
  143. }
  144. public struct TMP_PageInfo
  145. {
  146. public int firstCharacterIndex;
  147. public int lastCharacterIndex;
  148. public float ascender;
  149. public float baseLine;
  150. public float descender;
  151. // public float extents;
  152. }
  153. /// <summary>
  154. /// Structure containing information about individual links contained in the text object.
  155. /// </summary>
  156. public struct TMP_LinkInfo
  157. {
  158. public TMP_Text textComponent;
  159. public int hashCode;
  160. public int linkIdFirstCharacterIndex;
  161. public int linkIdLength;
  162. public int linkTextfirstCharacterIndex;
  163. public int linkTextLength;
  164. internal char[] linkID;
  165. internal void SetLinkID(char[] text, int startIndex, int length)
  166. {
  167. if (linkID == null || linkID.Length < length) linkID = new char[length];
  168. for (int i = 0; i < length; i++)
  169. linkID[i] = text[startIndex + i];
  170. }
  171. /// <summary>
  172. /// Function which returns the text contained in a link.
  173. /// </summary>
  174. /// <param name="textInfo"></param>
  175. /// <returns></returns>
  176. public string GetLinkText()
  177. {
  178. string text = string.Empty;
  179. TMP_TextInfo textInfo = textComponent.textInfo;
  180. for (int i = linkTextfirstCharacterIndex; i < linkTextfirstCharacterIndex + linkTextLength; i++)
  181. text += textInfo.characterInfo[i].character;
  182. return text;
  183. }
  184. /// <summary>
  185. /// Function which returns the link ID as a string.
  186. /// </summary>
  187. /// <param name="text">The source input text.</param>
  188. /// <returns></returns>
  189. public string GetLinkID()
  190. {
  191. if (textComponent == null)
  192. return string.Empty;
  193. return new string(linkID, 0, linkIdLength);
  194. //return textComponent.text.Substring(linkIdFirstCharacterIndex, linkIdLength);
  195. }
  196. }
  197. /// <summary>
  198. /// Structure containing information about the individual words contained in the text object.
  199. /// </summary>
  200. public struct TMP_WordInfo
  201. {
  202. // NOTE: Structure could be simplified by only including the firstCharacterIndex and length.
  203. public TMP_Text textComponent;
  204. public int firstCharacterIndex;
  205. public int lastCharacterIndex;
  206. public int characterCount;
  207. //public float length;
  208. /// <summary>
  209. /// Returns the word as a string.
  210. /// </summary>
  211. /// <returns></returns>
  212. public string GetWord()
  213. {
  214. string word = string.Empty;
  215. TMP_CharacterInfo[] charInfo = textComponent.textInfo.characterInfo;
  216. for (int i = firstCharacterIndex; i < lastCharacterIndex + 1; i++)
  217. {
  218. word += charInfo[i].character;
  219. }
  220. return word;
  221. }
  222. }
  223. public struct TMP_SpriteInfo
  224. {
  225. public int spriteIndex; // Index of the sprite in the sprite atlas.
  226. public int characterIndex; // The characterInfo index which holds the key information about this sprite.
  227. public int vertexIndex;
  228. }
  229. //public struct SpriteInfo
  230. //{
  231. //
  232. //}
  233. public struct Extents
  234. {
  235. public Vector2 min;
  236. public Vector2 max;
  237. public Extents(Vector2 min, Vector2 max)
  238. {
  239. this.min = min;
  240. this.max = max;
  241. }
  242. public override string ToString()
  243. {
  244. string s = "Min (" + min.x.ToString("f2") + ", " + min.y.ToString("f2") + ") Max (" + max.x.ToString("f2") + ", " + max.y.ToString("f2") + ")";
  245. return s;
  246. }
  247. }
  248. [Serializable]
  249. public struct Mesh_Extents
  250. {
  251. public Vector2 min;
  252. public Vector2 max;
  253. public Mesh_Extents(Vector2 min, Vector2 max)
  254. {
  255. this.min = min;
  256. this.max = max;
  257. }
  258. public override string ToString()
  259. {
  260. string s = "Min (" + min.x.ToString("f2") + ", " + min.y.ToString("f2") + ") Max (" + max.x.ToString("f2") + ", " + max.y.ToString("f2") + ")";
  261. //string s = "Center: (" + ")" + " Extents: (" + ((max.x - min.x) / 2).ToString("f2") + "," + ((max.y - min.y) / 2).ToString("f2") + ").";
  262. return s;
  263. }
  264. }
  265. // Structure used for Word Wrapping which tracks the state of execution when the last space or carriage return character was encountered.
  266. public struct WordWrapState
  267. {
  268. public int previous_WordBreak;
  269. public int total_CharacterCount;
  270. public int visible_CharacterCount;
  271. public int visible_SpriteCount;
  272. public int visible_LinkCount;
  273. public int firstCharacterIndex;
  274. public int firstVisibleCharacterIndex;
  275. public int lastCharacterIndex;
  276. public int lastVisibleCharIndex;
  277. public int lineNumber;
  278. public float maxCapHeight;
  279. public float maxAscender;
  280. public float maxDescender;
  281. public float maxLineAscender;
  282. public float maxLineDescender;
  283. public float previousLineAscender;
  284. public float xAdvance;
  285. public float preferredWidth;
  286. public float preferredHeight;
  287. //public float maxFontScale;
  288. public float previousLineScale;
  289. public int wordCount;
  290. public FontStyles fontStyle;
  291. public float fontScale;
  292. public float fontScaleMultiplier;
  293. public float currentFontSize;
  294. public float baselineOffset;
  295. public float lineOffset;
  296. public TMP_TextInfo textInfo;
  297. //public TMPro_CharacterInfo[] characterInfo;
  298. public TMP_LineInfo lineInfo;
  299. public Color32 vertexColor;
  300. public Color32 underlineColor;
  301. public Color32 strikethroughColor;
  302. public Color32 highlightColor;
  303. public TMP_BasicXmlTagStack basicStyleStack;
  304. public TMP_XmlTagStack<Color32> colorStack;
  305. public TMP_XmlTagStack<Color32> underlineColorStack;
  306. public TMP_XmlTagStack<Color32> strikethroughColorStack;
  307. public TMP_XmlTagStack<Color32> highlightColorStack;
  308. public TMP_XmlTagStack<TMP_ColorGradient> colorGradientStack;
  309. public TMP_XmlTagStack<float> sizeStack;
  310. public TMP_XmlTagStack<float> indentStack;
  311. public TMP_XmlTagStack<int> fontWeightStack;
  312. public TMP_XmlTagStack<int> styleStack;
  313. public TMP_XmlTagStack<float> baselineStack;
  314. public TMP_XmlTagStack<int> actionStack;
  315. public TMP_XmlTagStack<MaterialReference> materialReferenceStack;
  316. public TMP_XmlTagStack<TextAlignmentOptions> lineJustificationStack;
  317. //public TMP_XmlTagStack<int> spriteAnimationStack;
  318. public int spriteAnimationID;
  319. public TMP_FontAsset currentFontAsset;
  320. public TMP_SpriteAsset currentSpriteAsset;
  321. public Material currentMaterial;
  322. public int currentMaterialIndex;
  323. public Extents meshExtents;
  324. public bool tagNoParsing;
  325. public bool isNonBreakingSpace;
  326. //public Mesh_Extents lineExtents;
  327. }
  328. /// <summary>
  329. /// Structure used to store retrieve the name and hashcode of the font and material
  330. /// </summary>
  331. public struct TagAttribute
  332. {
  333. public int startIndex;
  334. public int length;
  335. public int hashCode;
  336. }
  337. public struct XML_TagAttribute
  338. {
  339. public int nameHashCode;
  340. public TagType valueType;
  341. public int valueStartIndex;
  342. public int valueLength;
  343. public int valueHashCode;
  344. }
  345. }