-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
NGUIText.cs
1892 lines (1815 loc) · 43.4 KB
/
NGUIText.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System.Diagnostics;
using System.Text;
using UnityEngine;
public static class NGUIText
{
public enum Alignment
{
Automatic,
Left,
Center,
Right,
Justified
}
public enum SymbolStyle
{
None,
Normal,
Colored
}
public class GlyphInfo
{
public Vector2 v0;
public Vector2 v1;
public Vector2 u0;
public Vector2 u1;
public float advance;
public int channel;
public bool rotatedUVs;
}
public static UIFont bitmapFont;
public static Font dynamicFont;
public static GlyphInfo glyph = new GlyphInfo();
public static int fontSize = 16;
public static float fontScale = 1f;
public static float pixelDensity = 1f;
public static FontStyle fontStyle = FontStyle.Normal;
public static Alignment alignment = Alignment.Left;
public static Color tint = Color.white;
public static int rectWidth = 1000000;
public static int rectHeight = 1000000;
public static int regionWidth = 1000000;
public static int regionHeight = 1000000;
public static int maxLines = 0;
public static bool gradient = false;
public static Color gradientBottom = Color.white;
public static Color gradientTop = Color.white;
public static bool encoding = false;
public static float spacingX = 0f;
public static float spacingY = 0f;
public static bool premultiply = false;
public static SymbolStyle symbolStyle;
public static int finalSize = 0;
public static float finalSpacingX = 0f;
public static float finalLineHeight = 0f;
public static float baseline = 0f;
public static bool useSymbols = false;
private static Color mInvisible = new Color(0f, 0f, 0f, 0f);
private static BetterList<Color> mColors = new BetterList<Color>();
private static float mAlpha = 1f;
private static CharacterInfo mTempChar;
private static BetterList<float> mSizes = new BetterList<float>();
private static Color32 s_c0;
private static Color32 s_c1;
private static float[] mBoldOffset = new float[8]
{
-0.25f,
0f,
0.25f,
0f,
0f,
-0.25f,
0f,
0.25f
};
public static void Update()
{
Update(request: true);
}
public static void Update(bool request)
{
finalSize = Mathf.RoundToInt((float)fontSize / pixelDensity);
finalSpacingX = spacingX * fontScale;
finalLineHeight = ((float)fontSize + spacingY) * fontScale;
useSymbols = (bitmapFont != null && bitmapFont.hasSymbols && encoding && symbolStyle != SymbolStyle.None);
if (dynamicFont != null && request)
{
dynamicFont.RequestCharactersInTexture(")_-", finalSize, fontStyle);
if (!dynamicFont.GetCharacterInfo(')', out mTempChar, finalSize, fontStyle) || mTempChar.vert.height == 0f)
{
dynamicFont.RequestCharactersInTexture("A", finalSize, fontStyle);
if (!dynamicFont.GetCharacterInfo('A', out mTempChar, finalSize, fontStyle))
{
baseline = 0f;
return;
}
}
float yMax = mTempChar.vert.yMax;
float yMin = mTempChar.vert.yMin;
baseline = Mathf.Round(yMax + ((float)finalSize - yMax + yMin) * 0.5f);
}
}
public static void Prepare(string text)
{
if (dynamicFont != null)
{
dynamicFont.RequestCharactersInTexture(text, finalSize, fontStyle);
}
}
public static BMSymbol GetSymbol(string text, int index, int textLength)
{
return (!(bitmapFont != null)) ? null : bitmapFont.MatchSymbol(text, index, textLength);
}
public static float GetGlyphWidth(int ch, int prev)
{
if (bitmapFont != null)
{
bool flag = false;
if (ch == 8201)
{
flag = true;
ch = 32;
}
BMGlyph bMGlyph = bitmapFont.bmFont.GetGlyph(ch);
if (bMGlyph != null)
{
int num = bMGlyph.advance;
if (flag)
{
num >>= 1;
}
return fontScale * (float)((prev == 0) ? bMGlyph.advance : (num + bMGlyph.GetKerning(prev)));
}
}
else if (dynamicFont != null && dynamicFont.GetCharacterInfo((char)ch, out mTempChar, finalSize, fontStyle))
{
return mTempChar.width * fontScale * pixelDensity;
}
return 0f;
}
public static GlyphInfo GetGlyph(int ch, int prev)
{
if (bitmapFont != null)
{
bool flag = false;
if (ch == 8201)
{
flag = true;
ch = 32;
}
BMGlyph bMGlyph = bitmapFont.bmFont.GetGlyph(ch);
if (bMGlyph != null)
{
int num = (prev != 0) ? bMGlyph.GetKerning(prev) : 0;
glyph.v0.x = (float)((prev == 0) ? bMGlyph.offsetX : (bMGlyph.offsetX + num));
glyph.v1.y = (float)(-bMGlyph.offsetY);
glyph.v1.x = glyph.v0.x + (float)bMGlyph.width;
glyph.v0.y = glyph.v1.y - (float)bMGlyph.height;
glyph.u0.x = (float)bMGlyph.x;
glyph.u0.y = (float)(bMGlyph.y + bMGlyph.height);
glyph.u1.x = (float)(bMGlyph.x + bMGlyph.width);
glyph.u1.y = (float)bMGlyph.y;
int num2 = bMGlyph.advance;
if (flag)
{
num2 >>= 1;
}
glyph.advance = (float)(num2 + num);
glyph.channel = bMGlyph.channel;
glyph.rotatedUVs = false;
if (fontScale != 1f)
{
glyph.v0 *= fontScale;
glyph.v1 *= fontScale;
glyph.advance *= fontScale;
}
return glyph;
}
}
else if (dynamicFont != null && dynamicFont.GetCharacterInfo((char)ch, out mTempChar, finalSize, fontStyle))
{
glyph.v0.x = mTempChar.vert.xMin;
glyph.v1.x = glyph.v0.x + mTempChar.vert.width;
glyph.v0.y = mTempChar.vert.yMax - baseline;
glyph.v1.y = glyph.v0.y - mTempChar.vert.height;
glyph.u0.x = mTempChar.uv.xMin;
glyph.u0.y = mTempChar.uv.yMin;
glyph.u1.x = mTempChar.uv.xMax;
glyph.u1.y = mTempChar.uv.yMax;
glyph.advance = mTempChar.width;
glyph.channel = 0;
glyph.rotatedUVs = mTempChar.flipped;
glyph.v0.x = Mathf.Round(glyph.v0.x);
glyph.v0.y = Mathf.Round(glyph.v0.y);
glyph.v1.x = Mathf.Round(glyph.v1.x);
glyph.v1.y = Mathf.Round(glyph.v1.y);
float num3 = fontScale * pixelDensity;
if (num3 != 1f)
{
glyph.v0 *= num3;
glyph.v1 *= num3;
glyph.advance *= num3;
}
return glyph;
}
return null;
}
[DebuggerHidden]
[DebuggerStepThrough]
public static float ParseAlpha(string text, int index)
{
int num = (NGUIMath.HexToDecimal(text[index + 1]) << 4) | NGUIMath.HexToDecimal(text[index + 2]);
return Mathf.Clamp01((float)num / 255f);
}
[DebuggerHidden]
[DebuggerStepThrough]
public static Color ParseColor(string text, int offset)
{
return ParseColor24(text, offset);
}
[DebuggerHidden]
[DebuggerStepThrough]
public static Color ParseColor24(string text, int offset)
{
int num = (NGUIMath.HexToDecimal(text[offset]) << 4) | NGUIMath.HexToDecimal(text[offset + 1]);
int num2 = (NGUIMath.HexToDecimal(text[offset + 2]) << 4) | NGUIMath.HexToDecimal(text[offset + 3]);
int num3 = (NGUIMath.HexToDecimal(text[offset + 4]) << 4) | NGUIMath.HexToDecimal(text[offset + 5]);
float num4 = 0.003921569f;
return new Color(num4 * (float)num, num4 * (float)num2, num4 * (float)num3);
}
[DebuggerHidden]
[DebuggerStepThrough]
public static Color ParseColor32(string text, int offset)
{
int num = (NGUIMath.HexToDecimal(text[offset]) << 4) | NGUIMath.HexToDecimal(text[offset + 1]);
int num2 = (NGUIMath.HexToDecimal(text[offset + 2]) << 4) | NGUIMath.HexToDecimal(text[offset + 3]);
int num3 = (NGUIMath.HexToDecimal(text[offset + 4]) << 4) | NGUIMath.HexToDecimal(text[offset + 5]);
int num4 = (NGUIMath.HexToDecimal(text[offset + 6]) << 4) | NGUIMath.HexToDecimal(text[offset + 7]);
float num5 = 0.003921569f;
return new Color(num5 * (float)num, num5 * (float)num2, num5 * (float)num3, num5 * (float)num4);
}
[DebuggerHidden]
[DebuggerStepThrough]
public static string EncodeColor(Color c)
{
return EncodeColor24(c);
}
[DebuggerHidden]
[DebuggerStepThrough]
public static string EncodeAlpha(float a)
{
int num = Mathf.Clamp(Mathf.RoundToInt(a * 255f), 0, 255);
return NGUIMath.DecimalToHex8(num);
}
[DebuggerHidden]
[DebuggerStepThrough]
public static string EncodeColor24(Color c)
{
int num = 0xFFFFFF & (NGUIMath.ColorToInt(c) >> 8);
return NGUIMath.DecimalToHex24(num);
}
[DebuggerHidden]
[DebuggerStepThrough]
public static string EncodeColor32(Color c)
{
int num = NGUIMath.ColorToInt(c);
return NGUIMath.DecimalToHex32(num);
}
public static bool ParseSymbol(string text, ref int index)
{
int sub = 1;
bool bold = false;
bool italic = false;
bool underline = false;
bool strike = false;
bool ignoreColor = false;
return ParseSymbol(text, ref index, null, /*premultiply:*/ false, ref sub, ref bold, ref italic, ref underline, ref strike, ref ignoreColor);
}
[DebuggerHidden]
[DebuggerStepThrough]
public static bool IsHex(char ch)
{
return (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F');
}
public static bool ParseSymbol(string text, ref int index, BetterList<Color> colors, bool premultiply, ref int sub, ref bool bold, ref bool italic, ref bool underline, ref bool strike, ref bool ignoreColor)
{
int length = text.Length;
if (index + 3 > length || text[index] != '[')
{
return false;
}
if (text[index + 2] == ']')
{
if (text[index + 1] == '-')
{
if (colors != null && colors.size > 1)
{
colors.RemoveAt(colors.size - 1);
}
index += 3;
return true;
}
string text2 = text.Substring(index, 3);
switch (text2)
{
case "[b]":
bold = true;
index += 3;
return true;
case "[i]":
italic = true;
index += 3;
return true;
case "[u]":
underline = true;
index += 3;
return true;
case "[s]":
strike = true;
index += 3;
return true;
case "[c]":
ignoreColor = true;
index += 3;
return true;
}
}
if (index + 4 > length)
{
return false;
}
if (text[index + 3] == ']')
{
string text3 = text.Substring(index, 4);
switch (text3)
{
case "[/b]":
bold = false;
index += 4;
return true;
case "[/i]":
italic = false;
index += 4;
return true;
case "[/u]":
underline = false;
index += 4;
return true;
case "[/s]":
strike = false;
index += 4;
return true;
case "[/c]":
ignoreColor = false;
index += 4;
return true;
}
char ch = text[index + 1];
char ch2 = text[index + 2];
if (IsHex(ch) && IsHex(ch2))
{
int num = (NGUIMath.HexToDecimal(ch) << 4) | NGUIMath.HexToDecimal(ch2);
mAlpha = (float)num / 255f;
index += 4;
return true;
}
}
if (index + 5 > length)
{
return false;
}
if (text[index + 4] == ']')
{
string text4 = text.Substring(index, 5);
switch (text4)
{
case "[sub]":
sub = 1;
index += 5;
return true;
case "[sup]":
sub = 2;
index += 5;
return true;
}
}
if (index + 6 > length)
{
return false;
}
if (text[index + 5] == ']')
{
string text5 = text.Substring(index, 6);
switch (text5)
{
case "[/sub]":
sub = 0;
index += 6;
return true;
case "[/sup]":
sub = 0;
index += 6;
return true;
case "[/url]":
index += 6;
return true;
}
}
if (text[index + 1] == 'u' && text[index + 2] == 'r' && text[index + 3] == 'l' && text[index + 4] == '=')
{
int num2 = text.IndexOf(']', index + 4);
if (num2 != -1)
{
index = num2 + 1;
return true;
}
index = text.Length;
return true;
}
if (index + 8 > length)
{
return false;
}
if (text[index + 7] == ']')
{
Color color = ParseColor24(text, index + 1);
if (EncodeColor24(color) != text.Substring(index + 1, 6).ToUpper())
{
return false;
}
if (colors != null)
{
Color color2 = colors[colors.size - 1];
color.a = color2.a;
if (premultiply && color.a != 1f)
{
color = Color.Lerp(mInvisible, color, color.a);
}
colors.Add(color);
}
index += 8;
return true;
}
if (index + 10 > length)
{
return false;
}
if (text[index + 9] == ']')
{
Color color3 = ParseColor32(text, index + 1);
if (EncodeColor32(color3) != text.Substring(index + 1, 8).ToUpper())
{
return false;
}
if (colors != null)
{
if (premultiply && color3.a != 1f)
{
color3 = Color.Lerp(mInvisible, color3, color3.a);
}
colors.Add(color3);
}
index += 10;
return true;
}
return false;
}
public static string StripSymbols(string text)
{
if (text != null)
{
int num = 0;
int length = text.Length;
while (num < length)
{
char c = text[num];
if (c == '[')
{
int sub = 0;
bool bold = false;
bool italic = false;
bool underline = false;
bool strike = false;
bool ignoreColor = false;
int index = num;
if (ParseSymbol(text, ref index, null, /*premultiply:*/ false, ref sub, ref bold, ref italic, ref underline, ref strike, ref ignoreColor))
{
text = text.Remove(num, index - num);
length = text.Length;
continue;
}
}
num++;
}
}
return text;
}
public static void Align(BetterList<Vector3> verts, int indexOffset, float printedWidth)
{
switch (alignment)
{
case Alignment.Right:
{
float num17 = (float)rectWidth - printedWidth;
if (!(num17 < 0f))
{
for (int j = indexOffset; j < verts.size; j++)
{
verts.buffer[j].x += num17;
}
}
break;
}
case Alignment.Center:
{
float num14 = ((float)rectWidth - printedWidth) * 0.5f;
if (!(num14 < 0f))
{
int num15 = Mathf.RoundToInt((float)rectWidth - printedWidth);
int num16 = Mathf.RoundToInt((float)rectWidth);
bool flag = (num15 & 1) == 1;
bool flag2 = (num16 & 1) == 1;
if ((flag && !flag2) || (!flag && flag2))
{
num14 += 0.5f * fontScale;
}
for (int i = indexOffset; i < verts.size; i++)
{
verts.buffer[i].x += num14;
}
}
break;
}
case Alignment.Justified:
if (!(printedWidth < (float)rectWidth * 0.65f))
{
float num = ((float)rectWidth - printedWidth) * 0.5f;
if (!(num < 1f))
{
int num2 = (verts.size - indexOffset) / 4;
if (num2 >= 1)
{
float num3 = 1f / (float)(num2 - 1);
float num4 = (float)rectWidth / printedWidth;
int num5 = indexOffset + 4;
int num6 = 1;
while (num5 < verts.size)
{
float x = verts.buffer[num5].x;
float x2 = verts.buffer[num5 + 2].x;
float num7 = x2 - x;
float num8 = x * num4;
float a = num8 + num7;
float num9 = x2 * num4;
float b = num9 - num7;
float t = (float)num6 * num3;
x = Mathf.Lerp(num8, b, t);
x2 = Mathf.Lerp(a, num9, t);
x = Mathf.Round(x);
x2 = Mathf.Round(x2);
verts.buffer[num5++].x = x;
verts.buffer[num5++].x = x;
verts.buffer[num5++].x = x2;
verts.buffer[num5++].x = x2;
num6++;
}
}
}
}
break;
}
}
public static int GetExactCharacterIndex(BetterList<Vector3> verts, BetterList<int> indices, Vector2 pos)
{
for (int i = 0; i < indices.size; i++)
{
int num = i << 1;
int i2 = num + 1;
Vector3 vector = verts[num];
float x = vector.x;
if (!(pos.x < x))
{
Vector3 vector2 = verts[i2];
float x2 = vector2.x;
if (!(pos.x > x2))
{
Vector3 vector3 = verts[num];
float y = vector3.y;
if (!(pos.y < y))
{
Vector3 vector4 = verts[i2];
float y2 = vector4.y;
if (!(pos.y > y2))
{
return indices[i];
}
}
}
}
}
return 0;
}
public static int GetApproximateCharacterIndex(BetterList<Vector3> verts, BetterList<int> indices, Vector2 pos)
{
float num = 3.40282347E+38f;
float num2 = 3.40282347E+38f;
int i = 0;
for (int j = 0; j < verts.size; j++)
{
float y = pos.y;
Vector3 vector = verts[j];
float num3 = Mathf.Abs(y - vector.y);
if (!(num3 > num2))
{
float x = pos.x;
Vector3 vector2 = verts[j];
float num4 = Mathf.Abs(x - vector2.x);
if (num3 < num2)
{
num2 = num3;
num = num4;
i = j;
}
else if (num4 < num)
{
num = num4;
i = j;
}
}
}
return indices[i];
}
[DebuggerHidden]
[DebuggerStepThrough]
private static bool IsSpace(int ch)
{
return ch == 32 || ch == 8202 || ch == 8203 || ch == 8201;
}
[DebuggerHidden]
[DebuggerStepThrough]
public static void EndLine(ref StringBuilder s)
{
int num = s.Length - 1;
if (num > 0 && IsSpace(s[num]))
{
s[num] = '\n';
}
else
{
s.Append('\n');
}
}
[DebuggerHidden]
[DebuggerStepThrough]
private static void ReplaceSpaceWithNewline(ref StringBuilder s)
{
int num = s.Length - 1;
if (num > 0 && IsSpace(s[num]))
{
s[num] = '\n';
}
}
public static Vector2 CalculatePrintedSize(string text)
{
Vector2 zero = Vector2.zero;
if (!string.IsNullOrEmpty(text))
{
if (encoding)
{
text = StripSymbols(text);
}
Prepare(text);
float num = 0f;
float num2 = 0f;
float num3 = 0f;
int length = text.Length;
int num4 = 0;
int prev = 0;
for (int i = 0; i < length; i++)
{
num4 = text[i];
if (num4 == 10)
{
if (num > num3)
{
num3 = num;
}
num = 0f;
num2 += finalLineHeight;
}
else if (num4 >= 32)
{
BMSymbol bMSymbol = (!useSymbols) ? null : GetSymbol(text, i, length);
if (bMSymbol == null)
{
float glyphWidth = GetGlyphWidth(num4, prev);
if (glyphWidth != 0f)
{
glyphWidth += finalSpacingX;
if (Mathf.RoundToInt(num + glyphWidth) > regionWidth)
{
if (num > num3)
{
num3 = num - finalSpacingX;
}
num = glyphWidth;
num2 += finalLineHeight;
}
else
{
num += glyphWidth;
}
prev = num4;
}
}
else
{
float num5 = finalSpacingX + (float)bMSymbol.advance * fontScale;
if (Mathf.RoundToInt(num + num5) > regionWidth)
{
if (num > num3)
{
num3 = num - finalSpacingX;
}
num = num5;
num2 += finalLineHeight;
}
else
{
num += num5;
}
i += bMSymbol.sequence.Length - 1;
prev = 0;
}
}
}
zero.x = ((!(num > num3)) ? num3 : (num - finalSpacingX));
zero.y = num2 + finalLineHeight;
}
return zero;
}
public static int CalculateOffsetToFit(string text)
{
if (string.IsNullOrEmpty(text) || regionWidth < 1)
{
return 0;
}
Prepare(text);
int length = text.Length;
int num = 0;
int prev = 0;
int i = 0;
for (int length2 = text.Length; i < length2; i++)
{
BMSymbol bMSymbol = (!useSymbols) ? null : GetSymbol(text, i, length);
if (bMSymbol == null)
{
num = text[i];
float glyphWidth = GetGlyphWidth(num, prev);
if (glyphWidth != 0f)
{
mSizes.Add(finalSpacingX + glyphWidth);
}
prev = num;
}
else
{
mSizes.Add(finalSpacingX + (float)bMSymbol.advance * fontScale);
int j = 0;
for (int num2 = bMSymbol.sequence.Length - 1; j < num2; j++)
{
mSizes.Add(0f);
}
i += bMSymbol.sequence.Length - 1;
prev = 0;
}
}
float num3 = (float)regionWidth;
int num4 = mSizes.size;
while (num4 > 0 && num3 > 0f)
{
num3 -= mSizes[--num4];
}
mSizes.Clear();
if (num3 < 0f)
{
num4++;
}
return num4;
}
public static string GetEndOfLineThatFits(string text)
{
int length = text.Length;
int num = CalculateOffsetToFit(text);
return text.Substring(num, length - num);
}
public static bool WrapText(string text, out string finalText)
{
return WrapText(text, out finalText, keepCharCount: false);
}
public static bool WrapText(string text, out string finalText, bool keepCharCount)
{
if (regionWidth < 1 || regionHeight < 1 || finalLineHeight < 1f)
{
finalText = string.Empty;
return false;
}
float num = (maxLines <= 0) ? ((float)regionHeight) : Mathf.Min((float)regionHeight, finalLineHeight * (float)maxLines);
int num2 = (maxLines <= 0) ? 1000000 : maxLines;
num2 = Mathf.FloorToInt(Mathf.Min((float)num2, num / finalLineHeight) + 0.01f);
if (num2 == 0)
{
finalText = string.Empty;
return false;
}
if (string.IsNullOrEmpty(text))
{
text = " ";
}
Prepare(text);
StringBuilder s = new StringBuilder();
int length = text.Length;
float num3 = (float)regionWidth;
int num4 = 0;
int i = 0;
int num5 = 1;
int prev = 0;
bool flag = true;
bool flag2 = true;
bool flag3 = false;
for (; i < length; i++)
{
char c = text[i];
if (c > '\u2fff')
{
flag3 = true;
}
if (c == '\n')
{
if (num5 == num2)
{
break;
}
num3 = (float)regionWidth;
if (num4 < i)
{
s.Append(text.Substring(num4, i - num4 + 1));
}
else
{
s.Append(c);
}
flag = true;
num5++;
num4 = i + 1;
prev = 0;
}
else if (encoding && ParseSymbol(text, ref i))
{
i--;
}
else
{
BMSymbol bMSymbol = (!useSymbols) ? null : GetSymbol(text, i, length);
float num6;
if (bMSymbol == null)
{
float glyphWidth = GetGlyphWidth(c, prev);
if (glyphWidth == 0f)
{
continue;
}
num6 = finalSpacingX + glyphWidth;
}
else
{
num6 = finalSpacingX + (float)bMSymbol.advance * fontScale;
}
num3 -= num6;
if (IsSpace(c) && !flag3 && num4 < i)
{
int num7 = i - num4 + 1;
if (num5 == num2 && num3 <= 0f && i < length)
{
char c2 = text[i];
if (c2 < ' ' || IsSpace(c2))
{
num7--;
}
}
s.Append(text.Substring(num4, num7));
flag = false;
num4 = i + 1;
prev = c;
}
if (Mathf.RoundToInt(num3) < 0)
{
if (!flag && num5 != num2)
{
flag = true;
num3 = (float)regionWidth;
i = num4 - 1;
prev = 0;
if (num5++ == num2)
{
break;
}
if (keepCharCount)
{
ReplaceSpaceWithNewline(ref s);
}
else
{
EndLine(ref s);
}
continue;
}
s.Append(text.Substring(num4, Mathf.Max(0, i - num4)));
bool flag4 = IsSpace(c);
if (!flag4 && !flag3)
{
flag2 = false;
}
if (num5++ == num2)
{
num4 = i;
break;
}