Hue Preserving Color Blending
TMPro_MeshUtilities.cs
1 using UnityEngine;
2 using System;
3 using System.Collections.Generic;
4 
5 
6 namespace TMPro
7 {
12  {
13  None = 0x0,
14  Vertices = 0x1,
15  Uv0 = 0x2,
16  Uv2 = 0x4,
17  Uv4 = 0x8,
18  Colors32 = 0x10,
19  All = 0xFF
20  };
21 
22 
26  //public struct TMP_Char
27  //{
28  // private int m_value;
29 
30  // private TMP_Char(int value)
31  // {
32  // this.m_value = value;
33  // }
34 
35  // private TMP_Char(TMP_Char value)
36  // {
37  // this.m_value = (int)value;
38  // }
39 
40  // public static implicit operator TMP_Char(int value)
41  // {
42  // return new TMP_Char(value);
43  // }
44 
45  // public static implicit operator TMP_Char(char c)
46  // {
47  // return new TMP_Char(c);
48  // }
49 
50  // public static explicit operator int(TMP_Char value)
51  // {
52  // return value.m_value;
53  // }
54 
55  // public override string ToString()
56  // {
57  // return m_value.ToString();
58  // }
59  //}
60 
61 
65  //[Serializable]
66  public struct TMP_CharacterInfo
67  {
68  public char character; // Should be changed to an int to handle UTF 32
72  public int index; // Index of the character in the input string.
73  public TMP_TextElementType elementType;
74 
75  public TMP_TextElement textElement;
76  public TMP_FontAsset fontAsset;
77  public TMP_SpriteAsset spriteAsset;
78  public int spriteIndex;
79  public Material material;
80  public int materialReferenceIndex;
81  public bool isUsingAlternateTypeface;
82 
83  public float pointSize;
84 
85  //public short wordNumber;
86  public int lineNumber;
87  //public short charNumber;
88  public int pageNumber;
89 
90 
91  public int vertexIndex;
92  public TMP_Vertex vertex_TL;
93  public TMP_Vertex vertex_BL;
94  public TMP_Vertex vertex_TR;
95  public TMP_Vertex vertex_BR;
96 
97  public Vector3 topLeft;
98  public Vector3 bottomLeft;
99  public Vector3 topRight;
100  public Vector3 bottomRight;
101  public float origin;
102  public float ascender;
103  public float baseLine;
104  public float descender;
105 
106  public float xAdvance;
107  public float aspectRatio;
108  public float scale;
109  public Color32 color;
110  public Color32 underlineColor;
111  public Color32 strikethroughColor;
112  public Color32 highlightColor;
113  public FontStyles style;
114  public bool isVisible;
115  //public bool isIgnoringAlignment;
116  }
117 
118 
119  public struct TMP_Vertex
120  {
121  public Vector3 position;
122  public Vector2 uv;
123  public Vector2 uv2;
124  public Vector2 uv4;
125  public Color32 color;
126 
127  //public Vector3 normal;
128  //public Vector4 tangent;
129  }
130 
131 
132  //public struct TMP_VertexInfo
133  //{
134  // public TMP_Vertex topLeft;
135  // public TMP_Vertex bottomLeft;
136  // public TMP_Vertex topRight;
137  // public TMP_Vertex bottomRight;
138  //}
139 
140 
141  [Serializable]
142  public struct VertexGradient
143  {
144  public Color topLeft;
145  public Color topRight;
146  public Color bottomLeft;
147  public Color bottomRight;
148 
149  public VertexGradient (Color color)
150  {
151  this.topLeft = color;
152  this.topRight = color;
153  this.bottomLeft = color;
154  this.bottomRight = color;
155  }
156 
164  public VertexGradient(Color color0, Color color1, Color color2, Color color3)
165  {
166  this.topLeft = color0;
167  this.topRight = color1;
168  this.bottomLeft = color2;
169  this.bottomRight = color3;
170  }
171  }
172 
173 
174  public struct TMP_PageInfo
175  {
176  public int firstCharacterIndex;
177  public int lastCharacterIndex;
178  public float ascender;
179  public float baseLine;
180  public float descender;
181  // public float extents;
182  }
183 
184 
188  public struct TMP_LinkInfo
189  {
190  public TMP_Text textComponent;
191 
192  public int hashCode;
193 
194  public int linkIdFirstCharacterIndex;
195  public int linkIdLength;
196  public int linkTextfirstCharacterIndex;
197  public int linkTextLength;
198 
199  internal char[] linkID;
200 
201 
202  internal void SetLinkID(char[] text, int startIndex, int length)
203  {
204  if (linkID == null || linkID.Length < length) linkID = new char[length];
205 
206  for (int i = 0; i < length; i++)
207  linkID[i] = text[startIndex + i];
208  }
209 
215  public string GetLinkText()
216  {
217  string text = string.Empty;
218  TMP_TextInfo textInfo = textComponent.textInfo;
219 
220  for (int i = linkTextfirstCharacterIndex; i < linkTextfirstCharacterIndex + linkTextLength; i++)
221  text += textInfo.characterInfo[i].character;
222 
223  return text;
224  }
225 
226 
232  public string GetLinkID()
233  {
234  if (textComponent == null)
235  return string.Empty;
236 
237  return new string(linkID, 0, linkIdLength);
238  //return textComponent.text.Substring(linkIdFirstCharacterIndex, linkIdLength);
239 
240  }
241  }
242 
243 
247  public struct TMP_WordInfo
248  {
249  // NOTE: Structure could be simplified by only including the firstCharacterIndex and length.
250 
251  public TMP_Text textComponent;
252 
253  public int firstCharacterIndex;
254  public int lastCharacterIndex;
255  public int characterCount;
256  //public float length;
257 
262  public string GetWord()
263  {
264  string word = string.Empty;
265  TMP_CharacterInfo[] charInfo = textComponent.textInfo.characterInfo;
266 
267  for (int i = firstCharacterIndex; i < lastCharacterIndex + 1; i++)
268  {
269  word += charInfo[i].character;
270  }
271 
272  return word;
273  }
274  }
275 
276 
277  public struct TMP_SpriteInfo
278  {
279  public int spriteIndex; // Index of the sprite in the sprite atlas.
280  public int characterIndex; // The characterInfo index which holds the key information about this sprite.
281  public int vertexIndex;
282  }
283 
284 
285  //public struct SpriteInfo
286  //{
287  //
288  //}
289 
290 
291  public struct Extents
292  {
293  public Vector2 min;
294  public Vector2 max;
295 
296  public Extents(Vector2 min, Vector2 max)
297  {
298  this.min = min;
299  this.max = max;
300  }
301 
302  public override string ToString()
303  {
304  string s = "Min (" + min.x.ToString("f2") + ", " + min.y.ToString("f2") + ") Max (" + max.x.ToString("f2") + ", " + max.y.ToString("f2") + ")";
305  return s;
306  }
307  }
308 
309 
310  [Serializable]
311  public struct Mesh_Extents
312  {
313  public Vector2 min;
314  public Vector2 max;
315 
316 
317  public Mesh_Extents(Vector2 min, Vector2 max)
318  {
319  this.min = min;
320  this.max = max;
321  }
322 
323  public override string ToString()
324  {
325  string s = "Min (" + min.x.ToString("f2") + ", " + min.y.ToString("f2") + ") Max (" + max.x.ToString("f2") + ", " + max.y.ToString("f2") + ")";
326  //string s = "Center: (" + ")" + " Extents: (" + ((max.x - min.x) / 2).ToString("f2") + "," + ((max.y - min.y) / 2).ToString("f2") + ").";
327  return s;
328  }
329  }
330 
331 
332  // Structure used for Word Wrapping which tracks the state of execution when the last space or carriage return character was encountered.
333  public struct WordWrapState
334  {
335  public int previous_WordBreak;
336  public int total_CharacterCount;
337  public int visible_CharacterCount;
338  public int visible_SpriteCount;
339  public int visible_LinkCount;
340  public int firstCharacterIndex;
341  public int firstVisibleCharacterIndex;
342  public int lastCharacterIndex;
343  public int lastVisibleCharIndex;
344  public int lineNumber;
345 
346  public float maxCapHeight;
347  public float maxAscender;
348  public float maxDescender;
349  public float maxLineAscender;
350  public float maxLineDescender;
351  public float previousLineAscender;
352 
353  public float xAdvance;
354  public float preferredWidth;
355  public float preferredHeight;
356  //public float maxFontScale;
357  public float previousLineScale;
358 
359  public int wordCount;
360  public FontStyles fontStyle;
361  public float fontScale;
362  public float fontScaleMultiplier;
363 
364  public float currentFontSize;
365  public float baselineOffset;
366  public float lineOffset;
367 
368  public TMP_TextInfo textInfo;
369  //public TMPro_CharacterInfo[] characterInfo;
370  public TMP_LineInfo lineInfo;
371 
372  public Color32 vertexColor;
373  public Color32 underlineColor;
374  public Color32 strikethroughColor;
375  public Color32 highlightColor;
376  public TMP_BasicXmlTagStack basicStyleStack;
377  public TMP_XmlTagStack<Color32> colorStack;
378  public TMP_XmlTagStack<Color32> underlineColorStack;
379  public TMP_XmlTagStack<Color32> strikethroughColorStack;
380  public TMP_XmlTagStack<Color32> highlightColorStack;
381  public TMP_XmlTagStack<TMP_ColorGradient> colorGradientStack;
382  public TMP_XmlTagStack<float> sizeStack;
383  public TMP_XmlTagStack<float> indentStack;
384  public TMP_XmlTagStack<int> fontWeightStack;
385  public TMP_XmlTagStack<int> styleStack;
386  public TMP_XmlTagStack<float> baselineStack;
387  public TMP_XmlTagStack<int> actionStack;
388  public TMP_XmlTagStack<MaterialReference> materialReferenceStack;
389  public TMP_XmlTagStack<TextAlignmentOptions> lineJustificationStack;
390  //public TMP_XmlTagStack<int> spriteAnimationStack;
391  public int spriteAnimationID;
392 
393  public TMP_FontAsset currentFontAsset;
394  public TMP_SpriteAsset currentSpriteAsset;
395  public Material currentMaterial;
396  public int currentMaterialIndex;
397 
398  public Extents meshExtents;
399 
400  public bool tagNoParsing;
401  public bool isNonBreakingSpace;
402  //public Mesh_Extents lineExtents;
403  }
404 
405 
409  public struct TagAttribute
410  {
411  public int startIndex;
412  public int length;
413  public int hashCode;
414  }
415 
416 
417  public struct XML_TagAttribute
418  {
419  public int nameHashCode;
420  public TagType valueType;
421  public int valueStartIndex;
422  public int valueLength;
423  public int valueHashCode;
424  }
425 
426 }
Structure used to store retrieve the name and hashcode of the font and material
int index
Index of the character in the raw string.
Structure which contains information about the individual lines of text.
Definition: TMP_LineInfo.cs:7
Class which contains information about every element contained within the text object.
Definition: TMP_TextInfo.cs:13
Base class which contains common properties and functions shared between the TextMeshPro and TextMesh...
Definition: TMP_Text.cs:110
TMP_VertexDataUpdateFlags
Flags to control what vertex data is pushed to the mesh and renderer.
Structure containing information about the individual words contained in the text object.
Base class for all text elements like characters (glyphs) and sprites.
VertexGradient(Color color0, Color color1, Color color2, Color color3)
The vertex colors at the corners of the characters.
TMP custom data type to represent 32 bit characters.
string GetWord()
Returns the word as a string.
Structure used to track basic XML tags which are binary (on / off)
TMP_TextInfo textInfo
Returns data about the text object which includes information about each character,...
Definition: TMP_Text.cs:1014