A game about forced loneliness, made by TACStudios
1using System.Diagnostics;
2using UnityEngine;
3
4
5namespace TMPro
6{
7 internal enum TextProcessingElementType
8 {
9 Undefined = 0x0,
10 TextCharacterElement = 0x1,
11 TextMarkupElement = 0x2
12 }
13
14 internal struct CharacterElement
15 {
16 public uint Unicode
17 {
18 get { return m_Unicode; }
19 set { m_Unicode = value; }
20 }
21
22 public CharacterElement(TMP_TextElement textElement)
23 {
24 m_Unicode = textElement.unicode;
25 m_TextElement = textElement;
26 }
27
28 // =============================================
29 // Private backing fields for public properties.
30 // =============================================
31
32 uint m_Unicode;
33 TMP_TextElement m_TextElement;
34 }
35
36 internal struct MarkupAttribute
37 {
38 /// <summary>
39 /// The hash code of the name of the Markup attribute.
40 /// </summary>
41 public int NameHashCode
42 {
43 get { return m_NameHashCode; }
44 set { m_NameHashCode = value; }
45 }
46
47 /// <summary>
48 /// The hash code of the value of the Markup attribute.
49 /// </summary>
50 public int ValueHashCode
51 {
52 get { return m_ValueHashCode; }
53 set { m_ValueHashCode = value; }
54 }
55
56 /// <summary>
57 /// The index of the value of the Markup attribute in the text backing buffer.
58 /// </summary>
59 public int ValueStartIndex
60 {
61 get { return m_ValueStartIndex; }
62 set { m_ValueStartIndex = value; }
63 }
64
65 /// <summary>
66 /// The length of the value of the Markup attribute in the text backing buffer.
67 /// </summary>
68 public int ValueLength
69 {
70 get { return m_ValueLength; }
71 set { m_ValueLength = value; }
72 }
73
74 // =============================================
75 // Private backing fields for public properties.
76 // =============================================
77
78 int m_NameHashCode;
79 int m_ValueHashCode;
80 int m_ValueStartIndex;
81 int m_ValueLength;
82 }
83
84 internal struct MarkupElement
85 {
86 /// <summary>
87 /// The hash code of the name of the markup element.
88 /// </summary>
89 public int NameHashCode
90 {
91 get
92 {
93 return m_Attributes == null ? 0 : m_Attributes[0].NameHashCode;
94 }
95 set
96 {
97 if (m_Attributes == null)
98 m_Attributes = new MarkupAttribute[8];
99
100 m_Attributes[0].NameHashCode = value;
101 }
102 }
103
104 /// <summary>
105 /// The hash code of the value of the markup element.
106 /// </summary>
107 public int ValueHashCode
108 {
109 get { return m_Attributes == null ? 0 : m_Attributes[0].ValueHashCode; }
110 set { m_Attributes[0].ValueHashCode = value; }
111 }
112
113 /// <summary>
114 /// The index of the value of the markup element in the text backing buffer.
115 /// </summary>
116 public int ValueStartIndex
117 {
118 get { return m_Attributes == null ? 0 : m_Attributes[0].ValueStartIndex; }
119 set { m_Attributes[0].ValueStartIndex = value; }
120 }
121
122 /// <summary>
123 /// The length of the value of the markup element in the text backing buffer.
124 /// </summary>
125 public int ValueLength
126 {
127 get { return m_Attributes == null ? 0 : m_Attributes[0].ValueLength; }
128 set { m_Attributes[0].ValueLength = value; }
129 }
130
131 /// <summary>
132 ///
133 /// </summary>
134 public MarkupAttribute[] Attributes
135 {
136 get { return m_Attributes; }
137 set { m_Attributes = value; }
138 }
139
140 /// <summary>
141 /// Constructor for a new Markup Element
142 /// </summary>
143 /// <param name="nameHashCode"></param>
144 public MarkupElement(int nameHashCode, int startIndex, int length)
145 {
146 m_Attributes = new MarkupAttribute[8];
147
148 m_Attributes[0].NameHashCode = nameHashCode;
149 m_Attributes[0].ValueStartIndex = startIndex;
150 m_Attributes[0].ValueLength = length;
151 }
152
153 // =============================================
154 // Private backing fields for public properties.
155 // =============================================
156
157 private MarkupAttribute[] m_Attributes;
158 }
159
160 [DebuggerDisplay("{DebuggerDisplay()}")]
161 internal struct TextProcessingElement
162 {
163 public TextProcessingElementType ElementType
164 {
165 get { return m_ElementType; }
166 set { m_ElementType = value; }
167 }
168
169 public int StartIndex
170 {
171 get { return m_StartIndex; }
172 set { m_StartIndex = value; }
173 }
174
175 public int Length
176 {
177 get { return m_Length; }
178 set { m_Length = value; }
179 }
180
181 public CharacterElement CharacterElement
182 {
183 get { return m_CharacterElement; }
184 }
185
186 public MarkupElement MarkupElement
187 {
188 get { return m_MarkupElement; }
189 set { m_MarkupElement = value; }
190 }
191
192 public TextProcessingElement(TextProcessingElementType elementType, int startIndex, int length)
193 {
194 m_ElementType = elementType;
195 m_StartIndex = startIndex;
196 m_Length = length;
197
198 m_CharacterElement = new CharacterElement();
199 m_MarkupElement = new MarkupElement();
200 }
201
202 public TextProcessingElement(TMP_TextElement textElement, int startIndex, int length)
203 {
204 m_ElementType = TextProcessingElementType.TextCharacterElement;
205 m_StartIndex = startIndex;
206 m_Length = length;
207
208 m_CharacterElement = new CharacterElement(textElement);
209 m_MarkupElement = new MarkupElement();
210 }
211
212 public TextProcessingElement(CharacterElement characterElement, int startIndex, int length)
213 {
214 m_ElementType = TextProcessingElementType.TextCharacterElement;
215 m_StartIndex = startIndex;
216 m_Length = length;
217
218 m_CharacterElement = characterElement;
219 m_MarkupElement = new MarkupElement();
220 }
221
222 public TextProcessingElement(MarkupElement markupElement)
223 {
224 m_ElementType = TextProcessingElementType.TextMarkupElement;
225 m_StartIndex = markupElement.ValueStartIndex;
226 m_Length = markupElement.ValueLength;
227
228 m_CharacterElement = new CharacterElement();
229 m_MarkupElement = markupElement;
230 }
231
232 public static TextProcessingElement Undefined => new TextProcessingElement() { ElementType = TextProcessingElementType.Undefined };
233
234
235 private string DebuggerDisplay()
236 {
237 return m_ElementType == TextProcessingElementType.TextCharacterElement ? $"Unicode ({m_CharacterElement.Unicode}) '{(char)m_CharacterElement.Unicode}' " : $"Markup = {(MarkupTag)m_MarkupElement.NameHashCode}";
238 }
239
240 // =============================================
241 // Private backing fields for public properties.
242 // =============================================
243
244 TextProcessingElementType m_ElementType;
245 int m_StartIndex;
246 int m_Length;
247
248 CharacterElement m_CharacterElement;
249 MarkupElement m_MarkupElement;
250 }
251
252
253}