TMPro_Private.cs
209 KB
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
//#define TMP_PROFILE_ON
//#define TMP_PROFILE_PHASES_ON
using UnityEngine;
using UnityEngine.TextCore;
using System;
using System.Collections;
using System.Collections.Generic;
#pragma warning disable 0414 // Disabled a few warnings related to serialized variables not used in this script but used in the editor.
namespace TMPro
{
public partial class TextMeshPro
{
[SerializeField]
private bool m_hasFontAssetChanged = false; // Used to track when font properties have changed.
float m_previousLossyScaleY = -1; // Used for Tracking lossy scale changes in the transform;
[SerializeField]
private Renderer m_renderer;
private MeshFilter m_meshFilter;
private bool m_isFirstAllocation; // Flag to determine if this is the first allocation of the buffers.
private int m_max_characters = 8; // Determines the initial allocation and size of the character array / buffer.
private int m_max_numberOfLines = 4; // Determines the initial allocation and maximum number of lines of text.
[SerializeField]
protected TMP_SubMesh[] m_subTextObjects = new TMP_SubMesh[8];
// MASKING RELATED PROPERTIES
//MaterialPropertyBlock m_maskingPropertyBlock;
//[SerializeField]
private bool m_isMaskingEnabled;
private bool isMaskUpdateRequired;
//private bool m_isMaterialBlockSet;
[SerializeField]
private MaskingTypes m_maskType;
// Matrix used to animated Env Map
private Matrix4x4 m_EnvMapMatrix = new Matrix4x4();
// Text Container / RectTransform Component
private Vector3[] m_RectTransformCorners = new Vector3[4];
[NonSerialized]
private bool m_isRegisteredForEvents;
// DEBUG Variables
//private System.Diagnostics.Stopwatch m_StopWatch;
//private bool isDebugOutputDone;
//private int m_recursiveCount = 0;
private int loopCountA;
//private int loopCountB;
//private int loopCountC;
//private int loopCountD;
//private int loopCountE;
protected override void Awake()
{
//Debug.Log("***** Awake() called on object ID " + GetInstanceID() + ". *****");
#if UNITY_EDITOR
// Special handling for TMP Settings and importing Essential Resources
if (TMP_Settings.instance == null)
{
if (m_isWaitingOnResourceLoad == false)
TMPro_EventManager.RESOURCE_LOAD_EVENT.Add(ON_RESOURCES_LOADED);
m_isWaitingOnResourceLoad = true;
return;
}
#endif
// Cache Reference to the Mesh Renderer.
m_renderer = GetComponent<Renderer>();
if (m_renderer == null)
m_renderer = gameObject.AddComponent<Renderer>();
// Make sure we have a CanvasRenderer for compatibility reasons and hide it
if (this.canvasRenderer != null)
this.canvasRenderer.hideFlags = HideFlags.HideInInspector;
else
{
CanvasRenderer canvasRenderer = gameObject.AddComponent<CanvasRenderer>();
canvasRenderer.hideFlags = HideFlags.HideInInspector;
}
// Cache Reference to RectTransform
m_rectTransform = this.rectTransform;
// Cache Reference to the transform;
m_transform = this.transform;
// Cache a reference to the Mesh Filter.
m_meshFilter = GetComponent<MeshFilter>();
if (m_meshFilter == null)
m_meshFilter = gameObject.AddComponent<MeshFilter>();
// Create new Mesh if necessary and cache reference to it.
if (m_mesh == null)
{
m_mesh = new Mesh();
m_mesh.hideFlags = HideFlags.HideAndDontSave;
m_meshFilter.mesh = m_mesh;
// Create new TextInfo for the text object.
m_textInfo = new TMP_TextInfo(this);
}
m_meshFilter.hideFlags = HideFlags.HideInInspector;
// Load TMP Settings for new text object instances.
LoadDefaultSettings();
// Load the font asset and assign material to renderer.
LoadFontAsset();
// Load Default TMP StyleSheet
TMP_StyleSheet.LoadDefaultStyleSheet();
// Allocate our initial buffers.
if (m_TextParsingBuffer == null)
m_TextParsingBuffer = new UnicodeChar[m_max_characters];
m_cached_TextElement = new TMP_Character();
m_isFirstAllocation = true;
// Check if we have a font asset assigned. Return if we don't because no one likes to see purple squares on screen.
if (m_fontAsset == null)
{
Debug.LogWarning("Please assign a Font Asset to this " + transform.name + " gameobject.", this);
return;
}
// Check to make sure Sub Text Objects are tracked correctly in the event a Prefab is used.
TMP_SubMesh[] subTextObjects = GetComponentsInChildren<TMP_SubMesh>();
if (subTextObjects.Length > 0)
{
for (int i = 0; i < subTextObjects.Length; i++)
m_subTextObjects[i + 1] = subTextObjects[i];
}
// Set flags to ensure our text is parsed and redrawn.
m_isInputParsingRequired = true;
m_havePropertiesChanged = true;
m_isCalculateSizeRequired = true;
m_isAwake = true;
}
protected override void OnEnable()
{
//Debug.Log("***** OnEnable() called on object ID " + GetInstanceID() + ". *****");
// Return if Awake() has not been called on the text object.
if (m_isAwake == false)
return;
// Register Callbacks for various events.
if (!m_isRegisteredForEvents)
{
#if UNITY_EDITOR
TMPro_EventManager.MATERIAL_PROPERTY_EVENT.Add(ON_MATERIAL_PROPERTY_CHANGED);
TMPro_EventManager.FONT_PROPERTY_EVENT.Add(ON_FONT_PROPERTY_CHANGED);
TMPro_EventManager.TEXTMESHPRO_PROPERTY_EVENT.Add(ON_TEXTMESHPRO_PROPERTY_CHANGED);
TMPro_EventManager.DRAG_AND_DROP_MATERIAL_EVENT.Add(ON_DRAG_AND_DROP_MATERIAL);
TMPro_EventManager.TEXT_STYLE_PROPERTY_EVENT.Add(ON_TEXT_STYLE_CHANGED);
TMPro_EventManager.COLOR_GRADIENT_PROPERTY_EVENT.Add(ON_COLOR_GRADIENT_CHANGED);
TMPro_EventManager.TMP_SETTINGS_PROPERTY_EVENT.Add(ON_TMP_SETTINGS_CHANGED);
#endif
m_isRegisteredForEvents = true;
}
TMP_UpdateManager.RegisterTextObjectForUpdate(this);
meshFilter.sharedMesh = mesh;
SetActiveSubMeshes(true);
// Schedule potential text object update (if any of the properties have changed.
ComputeMarginSize();
m_isInputParsingRequired = true;
m_havePropertiesChanged = true;
m_verticesAlreadyDirty = false;
SetVerticesDirty();
}
protected override void OnDisable()
{
//Debug.Log("***** OnDisable() called on object ID " + GetInstanceID() + ". *****");
// Return if Awake() has not been called on the text object.
if (m_isAwake == false)
return;
TMP_UpdateManager.UnRegisterTextElementForRebuild(this);
TMP_UpdateManager.UnRegisterTextObjectForUpdate(this);
m_meshFilter.sharedMesh = null;
SetActiveSubMeshes(false);
}
protected override void OnDestroy()
{
//Debug.Log("***** OnDestroy() called on object ID " + GetInstanceID() + ". *****");
// Destroy the mesh if we have one.
if (m_mesh != null)
{
DestroyImmediate(m_mesh);
}
// Unregister the event this object was listening to
#if UNITY_EDITOR
TMPro_EventManager.MATERIAL_PROPERTY_EVENT.Remove(ON_MATERIAL_PROPERTY_CHANGED);
TMPro_EventManager.FONT_PROPERTY_EVENT.Remove(ON_FONT_PROPERTY_CHANGED);
TMPro_EventManager.TEXTMESHPRO_PROPERTY_EVENT.Remove(ON_TEXTMESHPRO_PROPERTY_CHANGED);
TMPro_EventManager.DRAG_AND_DROP_MATERIAL_EVENT.Remove(ON_DRAG_AND_DROP_MATERIAL);
TMPro_EventManager.TEXT_STYLE_PROPERTY_EVENT.Remove(ON_TEXT_STYLE_CHANGED);
TMPro_EventManager.COLOR_GRADIENT_PROPERTY_EVENT.Remove(ON_COLOR_GRADIENT_CHANGED);
TMPro_EventManager.TMP_SETTINGS_PROPERTY_EVENT.Remove(ON_TMP_SETTINGS_CHANGED);
TMPro_EventManager.RESOURCE_LOAD_EVENT.Remove(ON_RESOURCES_LOADED);
#endif
m_isRegisteredForEvents = false;
TMP_UpdateManager.UnRegisterTextElementForRebuild(this);
TMP_UpdateManager.UnRegisterTextObjectForUpdate(this);
}
#if UNITY_EDITOR
protected override void Reset()
{
//Debug.Log("Reset() has been called." + m_subTextObjects);
// Return if Awake() has not been called on the text object.
if (m_isAwake == false)
return;
if (m_mesh != null)
DestroyImmediate(m_mesh);
Awake();
}
protected override void OnValidate()
{
//Debug.Log("*** TextMeshPro OnValidate() has been called on Object ID:" + gameObject.GetInstanceID());
// Return if Awake() has not been called on the text object.
if (m_isAwake == false)
return;
// Additional Properties could be added to sync up Serialized Properties & Properties.
// Handle Font Asset changes in the inspector
if (m_fontAsset == null || m_hasFontAssetChanged)
{
LoadFontAsset();
m_isCalculateSizeRequired = true;
m_hasFontAssetChanged = false;
}
m_padding = GetPaddingForMaterial();
ComputeMarginSize();
m_isInputParsingRequired = true;
m_inputSource = TextInputSources.Text;
m_havePropertiesChanged = true;
m_isCalculateSizeRequired = true;
m_isPreferredWidthDirty = true;
m_isPreferredHeightDirty = true;
SetAllDirty();
}
// Event received when TMP resources have been loaded.
void ON_RESOURCES_LOADED()
{
TMPro_EventManager.RESOURCE_LOAD_EVENT.Remove(ON_RESOURCES_LOADED);
if (this == null)
return;
Awake();
OnEnable();
}
// Event received when custom material editor properties are changed.
void ON_MATERIAL_PROPERTY_CHANGED(bool isChanged, Material mat)
{
//Debug.Log("ON_MATERIAL_PROPERTY_CHANGED event received. Targeted Material is: " + mat.name + " m_sharedMaterial: " + m_sharedMaterial.name + " m_renderer.sharedMaterial: " + m_renderer.sharedMaterial);
if (m_renderer.sharedMaterial == null)
{
if (m_fontAsset != null)
{
m_renderer.sharedMaterial = m_fontAsset.material;
Debug.LogWarning("No Material was assigned to " + name + ". " + m_fontAsset.material.name + " was assigned.", this);
}
else
Debug.LogWarning("No Font Asset assigned to " + name + ". Please assign a Font Asset.", this);
}
if (m_fontAsset.atlasTexture != null && m_fontAsset.atlasTexture.GetInstanceID() != m_renderer.sharedMaterial.GetTexture(ShaderUtilities.ID_MainTex).GetInstanceID())
{
m_renderer.sharedMaterial = m_sharedMaterial;
//m_renderer.sharedMaterial = m_fontAsset.material;
Debug.LogWarning("Font Asset Atlas doesn't match the Atlas in the newly assigned material. Select a matching material or a different font asset.", this);
}
if (m_renderer.sharedMaterial != m_sharedMaterial) // || m_renderer.sharedMaterials.Contains(mat))
{
//Debug.Log("ON_MATERIAL_PROPERTY_CHANGED Called on Target ID: " + GetInstanceID() + ". Previous Material:" + m_sharedMaterial + " New Material:" + m_renderer.sharedMaterial); // on Object ID:" + GetInstanceID() + ". m_sharedMaterial: " + m_sharedMaterial.name + " m_renderer.sharedMaterial: " + m_renderer.sharedMaterial.name);
m_sharedMaterial = m_renderer.sharedMaterial;
}
m_padding = GetPaddingForMaterial();
//m_sharedMaterialHashCode = TMP_TextUtilities.GetSimpleHashCode(m_sharedMaterial.name);
UpdateMask();
UpdateEnvMapMatrix();
m_havePropertiesChanged = true;
SetVerticesDirty();
}
// Event received when font asset properties are changed in Font Inspector
void ON_FONT_PROPERTY_CHANGED(bool isChanged, TMP_FontAsset font)
{
if (MaterialReference.Contains(m_materialReferences, font))
{
//Debug.Log("ON_FONT_PROPERTY_CHANGED event received.");
m_isInputParsingRequired = true;
m_havePropertiesChanged = true;
UpdateMeshPadding();
SetMaterialDirty();
SetVerticesDirty();
}
}
// Event received when UNDO / REDO Event alters the properties of the object.
void ON_TEXTMESHPRO_PROPERTY_CHANGED(bool isChanged, TextMeshPro obj)
{
if (obj == this)
{
//Debug.Log("Undo / Redo Event Received by Object ID:" + GetInstanceID());
m_havePropertiesChanged = true;
m_isInputParsingRequired = true;
m_padding = GetPaddingForMaterial();
ComputeMarginSize(); // Verify this change
SetVerticesDirty();
}
}
// Event to Track Material Changed resulting from Drag-n-drop.
void ON_DRAG_AND_DROP_MATERIAL(GameObject obj, Material currentMaterial, Material newMaterial)
{
//Debug.Log("Drag-n-Drop Event - Receiving Object ID " + GetInstanceID()); // + ". Target Object ID " + obj.GetInstanceID() + ". New Material is " + mat.name + " with ID " + mat.GetInstanceID() + ". Base Material is " + m_baseMaterial.name + " with ID " + m_baseMaterial.GetInstanceID());
// Check if event applies to this current object
#if UNITY_2018_2_OR_NEWER
if (obj == gameObject || UnityEditor.PrefabUtility.GetCorrespondingObjectFromSource(gameObject) == obj)
#else
if (obj == gameObject || UnityEditor.PrefabUtility.GetPrefabParent(gameObject) == obj)
#endif
{
UnityEditor.Undo.RecordObject(this, "Material Assignment");
UnityEditor.Undo.RecordObject(m_renderer, "Material Assignment");
m_sharedMaterial = newMaterial;
m_padding = GetPaddingForMaterial();
m_havePropertiesChanged = true;
SetVerticesDirty();
SetMaterialDirty();
}
}
// Event received when Text Styles are changed.
void ON_TEXT_STYLE_CHANGED(bool isChanged)
{
m_havePropertiesChanged = true;
m_isInputParsingRequired = true;
SetVerticesDirty();
}
/// <summary>
/// Event received when a Color Gradient Preset is modified.
/// </summary>
/// <param name="textObject"></param>
void ON_COLOR_GRADIENT_CHANGED(TMP_ColorGradient gradient)
{
if (m_fontColorGradientPreset != null && gradient.GetInstanceID() == m_fontColorGradientPreset.GetInstanceID())
{
m_havePropertiesChanged = true;
SetVerticesDirty();
}
}
/// <summary>
/// Event received when the TMP Settings are changed.
/// </summary>
void ON_TMP_SETTINGS_CHANGED()
{
m_defaultSpriteAsset = null;
m_havePropertiesChanged = true;
m_isInputParsingRequired = true;
SetAllDirty();
}
#endif
// Function which loads either the default font or a newly assigned font asset. This function also assigned the appropriate material to the renderer.
protected override void LoadFontAsset()
{
//Debug.Log("TextMeshPro LoadFontAsset() has been called."); // Current Font Asset is " + (font != null ? font.name: "Null") );
ShaderUtilities.GetShaderPropertyIDs(); // Initialize & Get shader property IDs.
if (m_fontAsset == null)
{
if (TMP_Settings.defaultFontAsset != null)
m_fontAsset =TMP_Settings.defaultFontAsset;
else
m_fontAsset = Resources.Load<TMP_FontAsset>("Fonts & Materials/LiberationSans SDF");
if (m_fontAsset == null)
{
Debug.LogWarning("The LiberationSans SDF Font Asset was not found. There is no Font Asset assigned to " + gameObject.name + ".", this);
return;
}
if (m_fontAsset.characterLookupTable == null)
{
Debug.Log("Dictionary is Null!");
}
m_renderer.sharedMaterial = m_fontAsset.material;
m_sharedMaterial = m_fontAsset.material;
m_sharedMaterial.SetFloat("_CullMode", 0);
m_sharedMaterial.SetFloat(ShaderUtilities.ShaderTag_ZTestMode, 4);
m_renderer.receiveShadows = false;
m_renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; // true;
// Get a Reference to the Shader
}
else
{
if (m_fontAsset.characterLookupTable == null)
{
//Debug.Log("Reading Font Definition and Creating Character Dictionary.");
m_fontAsset.ReadFontAssetDefinition();
}
//Debug.Log("Font Asset name:" + font.material.name);
// If font atlas texture doesn't match the assigned material font atlas, switch back to default material specified in the Font Asset.
if (m_renderer.sharedMaterial == null || m_renderer.sharedMaterial.GetTexture(ShaderUtilities.ID_MainTex) == null || m_fontAsset.atlasTexture.GetInstanceID() != m_renderer.sharedMaterial.GetTexture(ShaderUtilities.ID_MainTex).GetInstanceID())
{
m_renderer.sharedMaterial = m_fontAsset.material;
m_sharedMaterial = m_fontAsset.material;
}
else
{
m_sharedMaterial = m_renderer.sharedMaterial;
}
//m_sharedMaterial.SetFloat("_CullMode", 0);
m_sharedMaterial.SetFloat(ShaderUtilities.ShaderTag_ZTestMode, 4);
// Check if we are using the SDF Surface Shader
if (m_sharedMaterial.passCount == 1)
{
m_renderer.receiveShadows = false;
m_renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
}
}
m_padding = GetPaddingForMaterial();
//m_alignmentPadding = ShaderUtilities.GetFontExtent(m_sharedMaterial);
m_isMaskingEnabled = ShaderUtilities.IsMaskingEnabled(m_sharedMaterial);
// Find and cache Underline & Ellipsis characters.
GetSpecialCharacters(m_fontAsset);
//m_sharedMaterials.Add(m_sharedMaterial);
//m_sharedMaterialHashCode = TMP_TextUtilities.GetSimpleHashCode(m_sharedMaterial.name);
// Hide Material Editor Component
//m_renderer.sharedMaterial.hideFlags = HideFlags.None;
}
void UpdateEnvMapMatrix()
{
if (!m_sharedMaterial.HasProperty(ShaderUtilities.ID_EnvMap) || m_sharedMaterial.GetTexture(ShaderUtilities.ID_EnvMap) == null)
return;
//Debug.Log("Updating Env Matrix...");
Vector3 rotation = m_sharedMaterial.GetVector(ShaderUtilities.ID_EnvMatrixRotation);
m_EnvMapMatrix = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(rotation), Vector3.one);
m_sharedMaterial.SetMatrix(ShaderUtilities.ID_EnvMatrix, m_EnvMapMatrix);
}
//
void SetMask(MaskingTypes maskType)
{
switch(maskType)
{
case MaskingTypes.MaskOff:
m_sharedMaterial.DisableKeyword(ShaderUtilities.Keyword_MASK_SOFT);
m_sharedMaterial.DisableKeyword(ShaderUtilities.Keyword_MASK_HARD);
m_sharedMaterial.DisableKeyword(ShaderUtilities.Keyword_MASK_TEX);
break;
case MaskingTypes.MaskSoft:
m_sharedMaterial.EnableKeyword(ShaderUtilities.Keyword_MASK_SOFT);
m_sharedMaterial.DisableKeyword(ShaderUtilities.Keyword_MASK_HARD);
m_sharedMaterial.DisableKeyword(ShaderUtilities.Keyword_MASK_TEX);
break;
case MaskingTypes.MaskHard:
m_sharedMaterial.EnableKeyword(ShaderUtilities.Keyword_MASK_HARD);
m_sharedMaterial.DisableKeyword(ShaderUtilities.Keyword_MASK_SOFT);
m_sharedMaterial.DisableKeyword(ShaderUtilities.Keyword_MASK_TEX);
break;
//case MaskingTypes.MaskTex:
// m_sharedMaterial.EnableKeyword(ShaderUtilities.Keyword_MASK_TEX);
// m_sharedMaterial.DisableKeyword(ShaderUtilities.Keyword_MASK_HARD);
// m_sharedMaterial.DisableKeyword(ShaderUtilities.Keyword_MASK_SOFT);
// break;
}
}
// Method used to set the masking coordinates
void SetMaskCoordinates(Vector4 coords)
{
m_sharedMaterial.SetVector(ShaderUtilities.ID_ClipRect, coords);
}
// Method used to set the masking coordinates
void SetMaskCoordinates(Vector4 coords, float softX, float softY)
{
m_sharedMaterial.SetVector(ShaderUtilities.ID_ClipRect, coords);
m_sharedMaterial.SetFloat(ShaderUtilities.ID_MaskSoftnessX, softX);
m_sharedMaterial.SetFloat(ShaderUtilities.ID_MaskSoftnessY, softY);
}
// Enable Masking in the Shader
void EnableMasking()
{
if (m_sharedMaterial.HasProperty(ShaderUtilities.ID_ClipRect))
{
m_sharedMaterial.EnableKeyword(ShaderUtilities.Keyword_MASK_SOFT);
m_sharedMaterial.DisableKeyword(ShaderUtilities.Keyword_MASK_HARD);
m_sharedMaterial.DisableKeyword(ShaderUtilities.Keyword_MASK_TEX);
m_isMaskingEnabled = true;
UpdateMask();
}
}
// Enable Masking in the Shader
void DisableMasking()
{
if (m_sharedMaterial.HasProperty(ShaderUtilities.ID_ClipRect))
{
m_sharedMaterial.DisableKeyword(ShaderUtilities.Keyword_MASK_SOFT);
m_sharedMaterial.DisableKeyword(ShaderUtilities.Keyword_MASK_HARD);
m_sharedMaterial.DisableKeyword(ShaderUtilities.Keyword_MASK_TEX);
m_isMaskingEnabled = false;
UpdateMask();
}
}
void UpdateMask()
{
//Debug.Log("UpdateMask() called.");
if (!m_isMaskingEnabled)
{
// Release Masking Material
// Re-assign Base Material
return;
}
if (m_isMaskingEnabled && m_fontMaterial == null)
{
CreateMaterialInstance();
}
/*
if (!m_isMaskingEnabled)
{
//Debug.Log("Masking is not enabled.");
if (m_maskingPropertyBlock != null)
{
m_renderer.SetPropertyBlock(null);
//havePropertiesChanged = true;
}
return;
}
//else
// Debug.Log("Updating Masking...");
*/
// Compute Masking Coordinates & Softness
//float softnessX = Mathf.Min(Mathf.Min(m_textContainer.margins.x, m_textContainer.margins.z), m_sharedMaterial.GetFloat(ShaderUtilities.ID_MaskSoftnessX));
//float softnessY = Mathf.Min(Mathf.Min(m_textContainer.margins.y, m_textContainer.margins.w), m_sharedMaterial.GetFloat(ShaderUtilities.ID_MaskSoftnessY));
//softnessX = softnessX > 0 ? softnessX : 0;
//softnessY = softnessY > 0 ? softnessY : 0;
//float width = (m_textContainer.width - Mathf.Max(m_textContainer.margins.x, 0) - Mathf.Max(m_textContainer.margins.z, 0)) / 2 + softnessX;
//float height = (m_textContainer.height - Mathf.Max(m_textContainer.margins.y, 0) - Mathf.Max(m_textContainer.margins.w, 0)) / 2 + softnessY;
//Vector2 center = new Vector2((0.5f - m_textContainer.pivot.x) * m_textContainer.width + (Mathf.Max(m_textContainer.margins.x, 0) - Mathf.Max(m_textContainer.margins.z, 0)) / 2, (0.5f - m_textContainer.pivot.y) * m_textContainer.height + (- Mathf.Max(m_textContainer.margins.y, 0) + Mathf.Max(m_textContainer.margins.w, 0)) / 2);
//Vector4 mask = new Vector4(center.x, center.y, width, height);
//m_fontMaterial.SetVector(ShaderUtilities.ID_ClipRect, mask);
//m_fontMaterial.SetFloat(ShaderUtilities.ID_MaskSoftnessX, softnessX);
//m_fontMaterial.SetFloat(ShaderUtilities.ID_MaskSoftnessY, softnessY);
/*
if(m_maskingPropertyBlock == null)
{
m_maskingPropertyBlock = new MaterialPropertyBlock();
//m_maskingPropertyBlock.AddFloat(ShaderUtilities.ID_VertexOffsetX, m_sharedMaterial.GetFloat(ShaderUtilities.ID_VertexOffsetX));
//m_maskingPropertyBlock.AddFloat(ShaderUtilities.ID_VertexOffsetY, m_sharedMaterial.GetFloat(ShaderUtilities.ID_VertexOffsetY));
//Debug.Log("Creating new MaterialPropertyBlock.");
}
//Debug.Log("Updating Material Property Block.");
//m_maskingPropertyBlock.Clear();
m_maskingPropertyBlock.AddFloat(ShaderUtilities.ID_MaskID, m_renderer.GetInstanceID());
m_maskingPropertyBlock.AddVector(ShaderUtilities.ID_MaskCoord, mask);
m_maskingPropertyBlock.AddFloat(ShaderUtilities.ID_MaskSoftnessX, softnessX);
m_maskingPropertyBlock.AddFloat(ShaderUtilities.ID_MaskSoftnessY, softnessY);
m_renderer.SetPropertyBlock(m_maskingPropertyBlock);
*/
}
// Function called internally when a new material is assigned via the fontMaterial property.
protected override Material GetMaterial(Material mat)
{
// Check in case Object is disabled. If so, we don't have a valid reference to the Renderer.
// This can occur when the Duplicate Material Context menu is used on an inactive object.
//if (m_renderer == null)
// m_renderer = GetComponent<Renderer>();
// Create Instance Material only if the new material is not the same instance previously used.
if (m_fontMaterial == null || m_fontMaterial.GetInstanceID() != mat.GetInstanceID())
m_fontMaterial = CreateMaterialInstance(mat);
m_sharedMaterial = m_fontMaterial;
m_padding = GetPaddingForMaterial();
SetVerticesDirty();
SetMaterialDirty();
return m_sharedMaterial;
}
/// <summary>
/// Method returning instances of the materials used by the text object.
/// </summary>
/// <returns></returns>
protected override Material[] GetMaterials(Material[] mats)
{
int materialCount = m_textInfo.materialCount;
if (m_fontMaterials == null)
m_fontMaterials = new Material[materialCount];
else if (m_fontMaterials.Length != materialCount)
TMP_TextInfo.Resize(ref m_fontMaterials, materialCount, false);
// Get instances of the materials
for (int i = 0; i < materialCount; i++)
{
if (i == 0)
m_fontMaterials[i] = fontMaterial;
else
m_fontMaterials[i] = m_subTextObjects[i].material;
}
m_fontSharedMaterials = m_fontMaterials;
return m_fontMaterials;
}
// Function called internally when a new shared material is assigned via the fontSharedMaterial property.
protected override void SetSharedMaterial(Material mat)
{
// Check in case Object is disabled. If so, we don't have a valid reference to the Renderer.
// This can occur when the Duplicate Material Context menu is used on an inactive object.
//if (m_renderer == null)
// m_renderer = GetComponent<Renderer>();
m_sharedMaterial = mat;
m_padding = GetPaddingForMaterial();
SetMaterialDirty();
}
/// <summary>
/// Method returning an array containing the materials used by the text object.
/// </summary>
/// <returns></returns>
protected override Material[] GetSharedMaterials()
{
int materialCount = m_textInfo.materialCount;
if (m_fontSharedMaterials == null)
m_fontSharedMaterials = new Material[materialCount];
else if (m_fontSharedMaterials.Length != materialCount)
TMP_TextInfo.Resize(ref m_fontSharedMaterials, materialCount, false);
for (int i = 0; i < materialCount; i++)
{
if (i == 0)
m_fontSharedMaterials[i] = m_sharedMaterial;
else
m_fontSharedMaterials[i] = m_subTextObjects[i].sharedMaterial;
}
return m_fontSharedMaterials;
}
/// <summary>
/// Method used to assign new materials to the text and sub text objects.
/// </summary>
protected override void SetSharedMaterials(Material[] materials)
{
int materialCount = m_textInfo.materialCount;
// Check allocation of the fontSharedMaterials array.
if (m_fontSharedMaterials == null)
m_fontSharedMaterials = new Material[materialCount];
else if (m_fontSharedMaterials.Length != materialCount)
TMP_TextInfo.Resize(ref m_fontSharedMaterials, materialCount, false);
// Only assign as many materials as the text object contains.
for (int i = 0; i < materialCount; i++)
{
Texture mat_MainTex = materials[i].GetTexture(ShaderUtilities.ID_MainTex);
if (i == 0)
{
// Only assign new material if the font atlas textures match.
if ( mat_MainTex == null || mat_MainTex.GetInstanceID() != m_sharedMaterial.GetTexture(ShaderUtilities.ID_MainTex).GetInstanceID())
continue;
m_sharedMaterial = m_fontSharedMaterials[i] = materials[i];
m_padding = GetPaddingForMaterial(m_sharedMaterial);
}
else
{
// Only assign new material if the font atlas textures match.
if (mat_MainTex == null || mat_MainTex.GetInstanceID() != m_subTextObjects[i].sharedMaterial.GetTexture(ShaderUtilities.ID_MainTex).GetInstanceID())
continue;
// Only assign a new material if none were specified in the text input.
if (m_subTextObjects[i].isDefaultMaterial)
m_subTextObjects[i].sharedMaterial = m_fontSharedMaterials[i] = materials[i];
}
}
}
// This function will create an instance of the Font Material.
protected override void SetOutlineThickness(float thickness)
{
thickness = Mathf.Clamp01(thickness);
m_renderer.material.SetFloat(ShaderUtilities.ID_OutlineWidth, thickness);
if (m_fontMaterial == null)
m_fontMaterial = m_renderer.material;
m_fontMaterial = m_renderer.material;
m_sharedMaterial = m_fontMaterial;
m_padding = GetPaddingForMaterial();
}
// This function will create an instance of the Font Material.
protected override void SetFaceColor(Color32 color)
{
m_renderer.material.SetColor(ShaderUtilities.ID_FaceColor, color);
if (m_fontMaterial == null)
m_fontMaterial = m_renderer.material;
m_sharedMaterial = m_fontMaterial;
}
// This function will create an instance of the Font Material.
protected override void SetOutlineColor(Color32 color)
{
m_renderer.material.SetColor(ShaderUtilities.ID_OutlineColor, color);
if (m_fontMaterial == null)
m_fontMaterial = m_renderer.material;
//Debug.Log("Material ID:" + m_fontMaterial.GetInstanceID());
m_sharedMaterial = m_fontMaterial;
}
// Function used to create an instance of the material
void CreateMaterialInstance()
{
Material mat = new Material(m_sharedMaterial);
mat.shaderKeywords = m_sharedMaterial.shaderKeywords;
//mat.hideFlags = HideFlags.DontSave;
mat.name += " Instance";
m_fontMaterial = mat;
}
// Sets the Render Queue and Ztest mode
protected override void SetShaderDepth()
{
if (m_isOverlay)
{
// Changing these properties results in an instance of the material
m_sharedMaterial.SetFloat(ShaderUtilities.ShaderTag_ZTestMode, 0);
//m_renderer.material.SetFloat("_ZTestMode", 8);
m_renderer.material.renderQueue = 4000;
m_sharedMaterial = m_renderer.material;
//Debug.Log("Text set to Overlay mode.");
}
else
{
// Should this use an instanced material?
m_sharedMaterial.SetFloat(ShaderUtilities.ShaderTag_ZTestMode, 4);
m_renderer.material.renderQueue = -1;
m_sharedMaterial = m_renderer.material;
//Debug.Log("Text set to Normal mode.");
}
}
// Sets the Culling mode of the material
protected override void SetCulling()
{
if (m_isCullingEnabled)
{
m_renderer.material.SetFloat("_CullMode", 2);
for (int i = 1; i < m_subTextObjects.Length && m_subTextObjects[i] != null; i++)
{
Renderer renderer = m_subTextObjects[i].renderer;
if (renderer != null)
{
renderer.material.SetFloat(ShaderUtilities.ShaderTag_CullMode, 2);
}
}
}
else
{
m_renderer.material.SetFloat("_CullMode", 0);
for (int i = 1; i < m_subTextObjects.Length && m_subTextObjects[i] != null; i++)
{
Renderer renderer = m_subTextObjects[i].renderer;
if (renderer != null)
{
renderer.material.SetFloat(ShaderUtilities.ShaderTag_CullMode, 0);
}
}
}
}
// Set Perspective Correction Mode based on whether Camera is Orthographic or Perspective
void SetPerspectiveCorrection()
{
if (m_isOrthographic)
m_sharedMaterial.SetFloat(ShaderUtilities.ID_PerspectiveFilter, 0.0f);
else
m_sharedMaterial.SetFloat(ShaderUtilities.ID_PerspectiveFilter, 0.875f);
}
/// <summary>
/// Get the padding value for the currently assigned material.
/// </summary>
/// <returns></returns>
protected override float GetPaddingForMaterial(Material mat)
{
m_padding = ShaderUtilities.GetPadding(mat, m_enableExtraPadding, m_isUsingBold);
m_isMaskingEnabled = ShaderUtilities.IsMaskingEnabled(m_sharedMaterial);
m_isSDFShader = mat.HasProperty(ShaderUtilities.ID_WeightNormal);
return m_padding;
}
/// <summary>
/// Get the padding value for the currently assigned material.
/// </summary>
/// <returns></returns>
protected override float GetPaddingForMaterial()
{
ShaderUtilities.GetShaderPropertyIDs();
if (m_sharedMaterial == null) return 0;
m_padding = ShaderUtilities.GetPadding(m_sharedMaterial, m_enableExtraPadding, m_isUsingBold);
m_isMaskingEnabled = ShaderUtilities.IsMaskingEnabled(m_sharedMaterial);
m_isSDFShader = m_sharedMaterial.HasProperty(ShaderUtilities.ID_WeightNormal);
return m_padding;
}
// This function parses through the Char[] to determine how many characters will be visible. It then makes sure the arrays are large enough for all those characters.
protected override int SetArraySizes(UnicodeChar[] chars)
{
//Debug.Log("*** SetArraySizes() ***");
int spriteCount = 0;
m_totalCharacterCount = 0;
m_isUsingBold = false;
m_isParsingText = false;
tag_NoParsing = false;
m_FontStyleInternal = m_fontStyle;
m_FontWeightInternal = (m_FontStyleInternal & FontStyles.Bold) == FontStyles.Bold ? FontWeight.Bold : m_fontWeight;
m_FontWeightStack.SetDefault(m_FontWeightInternal);
m_currentFontAsset = m_fontAsset;
m_currentMaterial = m_sharedMaterial;
m_currentMaterialIndex = 0;
m_materialReferenceStack.SetDefault(new MaterialReference(m_currentMaterialIndex, m_currentFontAsset, null, m_currentMaterial, m_padding));
m_materialReferenceIndexLookup.Clear();
MaterialReference.AddMaterialReference(m_currentMaterial, m_currentFontAsset, m_materialReferences, m_materialReferenceIndexLookup);
if (m_textInfo == null) m_textInfo = new TMP_TextInfo();
m_textElementType = TMP_TextElementType.Character;
// Clear Linked Text object if we have one.
if (m_linkedTextComponent != null)
{
m_linkedTextComponent.text = string.Empty;
m_linkedTextComponent.ForceMeshUpdate();
}
// Parsing XML tags in the text
for (int i = 0; i < chars.Length && chars[i].unicode != 0; i++)
{
//Make sure the characterInfo array can hold the next text element.
if (m_textInfo.characterInfo == null || m_totalCharacterCount >= m_textInfo.characterInfo.Length)
TMP_TextInfo.Resize(ref m_textInfo.characterInfo, m_totalCharacterCount + 1, true);
int unicode = (int)chars[i].unicode;
// PARSE XML TAGS
#region PARSE XML TAGS
if (m_isRichText && unicode == 60) // if Char '<'
{
int prev_MaterialIndex = m_currentMaterialIndex;
// Check if Tag is Valid
if (ValidateHtmlTag(chars, i + 1, out int tagEnd))
{
int tagStartIndex = chars[i].stringIndex;
i = tagEnd;
if ((m_FontStyleInternal & FontStyles.Bold) == FontStyles.Bold) m_isUsingBold = true;
if (m_textElementType == TMP_TextElementType.Sprite)
{
m_materialReferences[m_currentMaterialIndex].referenceCount += 1;
m_textInfo.characterInfo[m_totalCharacterCount].character = (char)(57344 + m_spriteIndex);
m_textInfo.characterInfo[m_totalCharacterCount].spriteIndex = m_spriteIndex;
m_textInfo.characterInfo[m_totalCharacterCount].fontAsset = m_currentFontAsset;
m_textInfo.characterInfo[m_totalCharacterCount].spriteAsset = m_currentSpriteAsset;
m_textInfo.characterInfo[m_totalCharacterCount].materialReferenceIndex = m_currentMaterialIndex;
m_textInfo.characterInfo[m_totalCharacterCount].textElement = m_currentSpriteAsset.spriteCharacterTable[m_spriteIndex];
m_textInfo.characterInfo[m_totalCharacterCount].elementType = m_textElementType;
m_textInfo.characterInfo[m_totalCharacterCount].index = tagStartIndex;
m_textInfo.characterInfo[m_totalCharacterCount].stringLength = chars[i].stringIndex - tagStartIndex + 1;
// Restore element type and material index to previous values.
m_textElementType = TMP_TextElementType.Character;
m_currentMaterialIndex = prev_MaterialIndex;
spriteCount += 1;
m_totalCharacterCount += 1;
}
continue;
}
}
#endregion
bool isUsingAlternativeTypeface = false;
bool isUsingFallbackOrAlternativeTypeface = false;
TMP_Character character;
TMP_FontAsset tempFontAsset;
TMP_FontAsset prev_fontAsset = m_currentFontAsset;
Material prev_material = m_currentMaterial;
int prev_materialIndex = m_currentMaterialIndex;
// Handle Font Styles like LowerCase, UpperCase and SmallCaps.
#region Handling of LowerCase, UpperCase and SmallCaps Font Styles
if (m_textElementType == TMP_TextElementType.Character)
{
if ((m_FontStyleInternal & FontStyles.UpperCase) == FontStyles.UpperCase)
{
// If this character is lowercase, switch to uppercase.
if (char.IsLower((char)unicode))
unicode = char.ToUpper((char)unicode);
}
else if ((m_FontStyleInternal & FontStyles.LowerCase) == FontStyles.LowerCase)
{
// If this character is uppercase, switch to lowercase.
if (char.IsUpper((char)unicode))
unicode = char.ToLower((char)unicode);
}
else if ((m_FontStyleInternal & FontStyles.SmallCaps) == FontStyles.SmallCaps)
{
// Only convert lowercase characters to uppercase.
if (char.IsLower((char)unicode))
unicode = char.ToUpper((char)unicode);
}
}
#endregion
// Lookup the Glyph data for each character and cache it.
#region LOOKUP GLYPH
character = TMP_FontAssetUtilities.GetCharacterFromFontAsset((uint)unicode, m_currentFontAsset, false, m_FontStyleInternal, m_FontWeightInternal, out isUsingAlternativeTypeface, out tempFontAsset);
// Search for the glyph in the list of fallback assigned to the primary font asset.
if (character == null)
{
if (m_currentFontAsset.fallbackFontAssetTable != null && m_currentFontAsset.fallbackFontAssetTable.Count > 0)
character = TMP_FontAssetUtilities.GetCharacterFromFontAssets((uint)unicode, m_currentFontAsset.fallbackFontAssetTable, true, m_FontStyleInternal, m_FontWeightInternal, out isUsingAlternativeTypeface, out tempFontAsset);
}
// Search for the glyph in the Sprite Asset assigned to the text object.
if (character == null)
{
TMP_SpriteAsset spriteAsset = this.spriteAsset;
if (spriteAsset != null)
{
int spriteIndex = -1;
// Check Default Sprite Asset and its Fallbacks
spriteAsset = TMP_SpriteAsset.SearchForSpriteByUnicode(spriteAsset, (uint)unicode, true, out spriteIndex);
if (spriteIndex != -1)
{
m_textElementType = TMP_TextElementType.Sprite;
m_textInfo.characterInfo[m_totalCharacterCount].elementType = m_textElementType;
m_currentMaterialIndex = MaterialReference.AddMaterialReference(spriteAsset.material, spriteAsset, m_materialReferences, m_materialReferenceIndexLookup);
m_materialReferences[m_currentMaterialIndex].referenceCount += 1;
m_textInfo.characterInfo[m_totalCharacterCount].character = (char)unicode;
m_textInfo.characterInfo[m_totalCharacterCount].spriteIndex = spriteIndex;
m_textInfo.characterInfo[m_totalCharacterCount].fontAsset = m_currentFontAsset;
m_textInfo.characterInfo[m_totalCharacterCount].spriteAsset = spriteAsset;
m_textInfo.characterInfo[m_totalCharacterCount].textElement = spriteAsset.spriteCharacterTable[m_spriteIndex];
m_textInfo.characterInfo[m_totalCharacterCount].materialReferenceIndex = m_currentMaterialIndex;
m_textInfo.characterInfo[m_totalCharacterCount].index = chars[i].stringIndex;
m_textInfo.characterInfo[m_totalCharacterCount].stringLength = chars[i].length;
// Restore element type and material index to previous values.
m_textElementType = TMP_TextElementType.Character;
m_currentMaterialIndex = prev_materialIndex;
spriteCount += 1;
m_totalCharacterCount += 1;
continue;
}
}
}
// Search for the glyph in the list of fallback assigned in the TMP Settings (General Fallbacks).
if (character == null)
{
if (TMP_Settings.fallbackFontAssets != null && TMP_Settings.fallbackFontAssets.Count > 0)
character = TMP_FontAssetUtilities.GetCharacterFromFontAssets((uint)unicode, TMP_Settings.fallbackFontAssets, true, m_FontStyleInternal, m_FontWeightInternal, out isUsingAlternativeTypeface, out tempFontAsset);
}
// Search for the glyph in the Default Font Asset assigned in the TMP Settings file.
if (character == null)
{
if (TMP_Settings.defaultFontAsset != null)
character = TMP_FontAssetUtilities.GetCharacterFromFontAsset((uint)unicode, TMP_Settings.defaultFontAsset, true, m_FontStyleInternal, m_FontWeightInternal, out isUsingAlternativeTypeface, out tempFontAsset);
}
// TODO: Add support for using Sprite Assets like a special Emoji only Sprite Asset when UTF16 or UTF32 glyphs are requested.
// This would kind of mirror native Emoji support.
if (character == null)
{
TMP_SpriteAsset spriteAsset = TMP_Settings.defaultSpriteAsset;
if (spriteAsset != null)
{
int spriteIndex = -1;
// Check Default Sprite Asset and its Fallbacks
spriteAsset = TMP_SpriteAsset.SearchForSpriteByUnicode(spriteAsset, (uint)unicode, true, out spriteIndex);
if (spriteIndex != -1)
{
m_textElementType = TMP_TextElementType.Sprite;
m_textInfo.characterInfo[m_totalCharacterCount].elementType = m_textElementType;
m_currentMaterialIndex = MaterialReference.AddMaterialReference(spriteAsset.material, spriteAsset, m_materialReferences, m_materialReferenceIndexLookup);
m_materialReferences[m_currentMaterialIndex].referenceCount += 1;
m_textInfo.characterInfo[m_totalCharacterCount].character = (char)unicode;
m_textInfo.characterInfo[m_totalCharacterCount].spriteIndex = spriteIndex;
m_textInfo.characterInfo[m_totalCharacterCount].fontAsset = m_currentFontAsset;
m_textInfo.characterInfo[m_totalCharacterCount].spriteAsset = spriteAsset;
m_textInfo.characterInfo[m_totalCharacterCount].textElement = spriteAsset.spriteCharacterTable[m_spriteIndex];
m_textInfo.characterInfo[m_totalCharacterCount].materialReferenceIndex = m_currentMaterialIndex;
m_textInfo.characterInfo[m_totalCharacterCount].index = chars[i].stringIndex;
m_textInfo.characterInfo[m_totalCharacterCount].stringLength = chars[i].length;
// Restore element type and material index to previous values.
m_textElementType = TMP_TextElementType.Character;
m_currentMaterialIndex = prev_materialIndex;
spriteCount += 1;
m_totalCharacterCount += 1;
continue;
}
}
}
//Check if Lowercase or Uppercase variant of the character is available.
// Not sure this is necessary anyone as it is very unlikely with recursive search through fallback fonts.
//if (glyph == null)
//{
// if (char.IsLower((char)c))
// {
// if (m_currentFontAsset.characterDictionary.TryGetValue(char.ToUpper((char)c), out glyph))
// c = chars[i] = char.ToUpper((char)c);
// }
// else if (char.IsUpper((char)c))
// {
// if (m_currentFontAsset.characterDictionary.TryGetValue(char.ToLower((char)c), out glyph))
// c = chars[i] = char.ToLower((char)c);
// }
//}
// Replace missing glyph by the Square (9633) glyph or possibly the Space (32) glyph.
if (character == null)
{
// Save the original unicode character
int srcGlyph = unicode;
// Try replacing the missing glyph character by TMP Settings Missing Glyph or Square (9633) character.
unicode = chars[i].unicode = TMP_Settings.missingGlyphCharacter == 0 ? 9633 : TMP_Settings.missingGlyphCharacter;
// Check for the missing glyph character in the currently assigned font asset and its fallbacks
character = TMP_FontAssetUtilities.GetCharacterFromFontAsset((uint)unicode, m_currentFontAsset, true, m_FontStyleInternal, m_FontWeightInternal, out isUsingAlternativeTypeface, out tempFontAsset);
if (character == null)
{
// Search for the missing glyph character in the TMP Settings Fallback list.
if (TMP_Settings.fallbackFontAssets != null && TMP_Settings.fallbackFontAssets.Count > 0)
character = TMP_FontAssetUtilities.GetCharacterFromFontAssets((uint)unicode, TMP_Settings.fallbackFontAssets, true, m_FontStyleInternal, m_FontWeightInternal, out isUsingAlternativeTypeface, out tempFontAsset);
}
if (character == null)
{
// Search for the missing glyph in the TMP Settings Default Font Asset.
if (TMP_Settings.defaultFontAsset != null)
character = TMP_FontAssetUtilities.GetCharacterFromFontAsset((uint)unicode, TMP_Settings.defaultFontAsset, true, m_FontStyleInternal, m_FontWeightInternal, out isUsingAlternativeTypeface, out tempFontAsset);
}
if (character == null)
{
// Use Space (32) Glyph from the currently assigned font asset.
unicode = chars[i].unicode = 32;
character = TMP_FontAssetUtilities.GetCharacterFromFontAsset((uint)unicode, m_currentFontAsset, true, m_FontStyleInternal, m_FontWeightInternal, out isUsingAlternativeTypeface, out tempFontAsset);
if (!TMP_Settings.warningsDisabled)
Debug.LogWarning("Character with ASCII value of " + srcGlyph + " was not found in the Font Asset Glyph Table. It was replaced by a space.", this);
}
}
// Determine if the font asset is still the current font asset or a fallback.
if (tempFontAsset != null)
{
if (tempFontAsset.GetInstanceID() != m_currentFontAsset.GetInstanceID())
{
isUsingFallbackOrAlternativeTypeface = true;
m_currentFontAsset = tempFontAsset;
}
}
#endregion
m_textInfo.characterInfo[m_totalCharacterCount].elementType = TMP_TextElementType.Character;
m_textInfo.characterInfo[m_totalCharacterCount].textElement = character;
m_textInfo.characterInfo[m_totalCharacterCount].isUsingAlternateTypeface = isUsingAlternativeTypeface;
m_textInfo.characterInfo[m_totalCharacterCount].character = (char)unicode;
m_textInfo.characterInfo[m_totalCharacterCount].fontAsset = m_currentFontAsset;
m_textInfo.characterInfo[m_totalCharacterCount].index = chars[i].stringIndex;
m_textInfo.characterInfo[m_totalCharacterCount].stringLength = chars[i].length;
if (isUsingFallbackOrAlternativeTypeface)
{
// Create Fallback material instance matching current material preset if necessary
if (TMP_Settings.matchMaterialPreset)
m_currentMaterial = TMP_MaterialManager.GetFallbackMaterial(m_currentMaterial, m_currentFontAsset.material);
else
m_currentMaterial = m_currentFontAsset.material;
m_currentMaterialIndex = MaterialReference.AddMaterialReference(m_currentMaterial, m_currentFontAsset, m_materialReferences, m_materialReferenceIndexLookup);
}
if (!char.IsWhiteSpace((char)unicode) && unicode != 0x200B)
{
// Limit the mesh of the main text object to 65535 vertices and use sub objects for the overflow.
if (m_materialReferences[m_currentMaterialIndex].referenceCount < 16383)
m_materialReferences[m_currentMaterialIndex].referenceCount += 1;
else
{
m_currentMaterialIndex = MaterialReference.AddMaterialReference(new Material(m_currentMaterial), m_currentFontAsset, m_materialReferences, m_materialReferenceIndexLookup);
m_materialReferences[m_currentMaterialIndex].referenceCount += 1;
}
}
m_textInfo.characterInfo[m_totalCharacterCount].material = m_currentMaterial;
m_textInfo.characterInfo[m_totalCharacterCount].materialReferenceIndex = m_currentMaterialIndex;
m_materialReferences[m_currentMaterialIndex].isFallbackMaterial = isUsingFallbackOrAlternativeTypeface;
// Restore previous font asset and material if fallback font was used.
if (isUsingFallbackOrAlternativeTypeface)
{
m_materialReferences[m_currentMaterialIndex].fallbackMaterial = prev_material;
m_currentFontAsset = prev_fontAsset;
m_currentMaterial = prev_material;
m_currentMaterialIndex = prev_materialIndex;
}
m_totalCharacterCount += 1;
}
// Early return if we are calculating the preferred values.
if (m_isCalculatingPreferredValues)
{
m_isCalculatingPreferredValues = false;
m_isInputParsingRequired = true;
return m_totalCharacterCount;
}
// Save material and sprite count.
m_textInfo.spriteCount = spriteCount;
int materialCount = m_textInfo.materialCount = m_materialReferenceIndexLookup.Count;
// Check if we need to resize the MeshInfo array for handling different materials.
if (materialCount > m_textInfo.meshInfo.Length)
TMP_TextInfo.Resize(ref m_textInfo.meshInfo, materialCount, false);
// Resize SubTextObject array if necessary
if (materialCount > m_subTextObjects.Length)
TMP_TextInfo.Resize(ref m_subTextObjects, Mathf.NextPowerOfTwo(materialCount + 1));
// Resize CharacterInfo[] if allocations are excessive
if (m_textInfo.characterInfo.Length - m_totalCharacterCount > 256)
TMP_TextInfo.Resize(ref m_textInfo.characterInfo, Mathf.Max(m_totalCharacterCount + 1, 256), true);
// Iterate through the material references to set the mesh buffer allocations
for (int i = 0; i < materialCount; i++)
{
// Add new sub text object for each material reference
if (i > 0)
{
if (m_subTextObjects[i] == null)
{
m_subTextObjects[i] = TMP_SubMesh.AddSubTextObject(this, m_materialReferences[i]);
// Not sure this is necessary
m_textInfo.meshInfo[i].vertices = null;
}
//else if (m_subTextObjects[i].gameObject.activeInHierarchy == false)
// m_subTextObjects[i].gameObject.SetActive(true);
// Check if the material has changed.
if (m_subTextObjects[i].sharedMaterial == null || m_subTextObjects[i].sharedMaterial.GetInstanceID() != m_materialReferences[i].material.GetInstanceID())
{
bool isDefaultMaterial = m_materialReferences[i].isDefaultMaterial;
m_subTextObjects[i].isDefaultMaterial = isDefaultMaterial;
// Assign new material if we are not using the default material or if the font asset has changed.
if (!isDefaultMaterial || m_subTextObjects[i].sharedMaterial == null || m_subTextObjects[i].sharedMaterial.GetTexture(ShaderUtilities.ID_MainTex).GetInstanceID() != m_materialReferences[i].material.GetTexture(ShaderUtilities.ID_MainTex).GetInstanceID())
{
m_subTextObjects[i].sharedMaterial = m_materialReferences[i].material;
m_subTextObjects[i].fontAsset = m_materialReferences[i].fontAsset;
m_subTextObjects[i].spriteAsset = m_materialReferences[i].spriteAsset;
}
}
// Check if we need to use a Fallback Material
if (m_materialReferences[i].isFallbackMaterial)
{
m_subTextObjects[i].fallbackMaterial = m_materialReferences[i].material;
m_subTextObjects[i].fallbackSourceMaterial = m_materialReferences[i].fallbackMaterial;
}
}
int referenceCount = m_materialReferences[i].referenceCount;
// Check to make sure our buffers allocations can accommodate the required text elements.
if (m_textInfo.meshInfo[i].vertices == null || m_textInfo.meshInfo[i].vertices.Length < referenceCount * (!m_isVolumetricText ? 4 : 8))
{
if (m_textInfo.meshInfo[i].vertices == null)
{
if (i == 0)
m_textInfo.meshInfo[i] = new TMP_MeshInfo(m_mesh, referenceCount + 1, m_isVolumetricText);
else
m_textInfo.meshInfo[i] = new TMP_MeshInfo(m_subTextObjects[i].mesh, referenceCount + 1, m_isVolumetricText);
}
else
m_textInfo.meshInfo[i].ResizeMeshInfo(referenceCount > 1024 ? referenceCount + 256 : Mathf.NextPowerOfTwo(referenceCount + 1), m_isVolumetricText);
}
else if (m_VertexBufferAutoSizeReduction && referenceCount > 0 && m_textInfo.meshInfo[i].vertices.Length - referenceCount * (!m_isVolumetricText ? 4 : 8) > 1024)
{
// Resize vertex buffers if allocations are excessive.
//Debug.Log("Reducing the size of the vertex buffers.");
m_textInfo.meshInfo[i].ResizeMeshInfo(referenceCount > 1024 ? referenceCount + 256 : Mathf.NextPowerOfTwo(referenceCount + 1), m_isVolumetricText);
}
}
//TMP_MaterialManager.CleanupFallbackMaterials();
// Clean up unused SubMeshes
for (int i = materialCount; i < m_subTextObjects.Length && m_subTextObjects[i] != null; i++)
{
if (i < m_textInfo.meshInfo.Length)
m_textInfo.meshInfo[i].ClearUnusedVertices(0, true);
//m_subTextObjects[i].gameObject.SetActive(false);
}
return m_totalCharacterCount;
}
// Added to sort handle the potential issue with OnWillRenderObject() not getting called when objects are not visible by camera.
//void OnBecameInvisible()
//{
// if (m_mesh != null)
// m_mesh.bounds = new Bounds(transform.position, new Vector3(1000, 1000, 0));
//}
/// <summary>
/// Update the margin width and height
/// </summary>
public override void ComputeMarginSize()
{
if (this.rectTransform != null)
{
//Debug.Log("*** ComputeMarginSize() *** Current RectTransform's Width is " + m_rectTransform.rect.width + " and Height is " + m_rectTransform.rect.height); // + " and size delta is " + m_rectTransform.sizeDelta);
m_marginWidth = m_rectTransform.rect.width - m_margin.x - m_margin.z;
m_marginHeight = m_rectTransform.rect.height - m_margin.y - m_margin.w;
// Update the corners of the RectTransform
m_RectTransformCorners = GetTextContainerLocalCorners();
}
}
protected override void OnDidApplyAnimationProperties()
{
//Debug.Log("*** OnDidApplyAnimationProperties() ***");
m_havePropertiesChanged = true;
isMaskUpdateRequired = true;
SetVerticesDirty();
}
protected override void OnTransformParentChanged()
{
//Debug.Log("*** OnTransformParentChanged() ***");
//ComputeMarginSize();
SetVerticesDirty();
SetLayoutDirty();
}
protected override void OnRectTransformDimensionsChange()
{
//Debug.Log("*** OnRectTransformDimensionsChange() ***");
ComputeMarginSize();
SetVerticesDirty();
SetLayoutDirty();
}
/// <summary>
/// Function used as a replacement for LateUpdate to check if the transform or scale of the text object has changed.
/// </summary>
internal override void InternalUpdate()
{
// We need to update the SDF scale or possibly regenerate the text object if lossy scale has changed.
if (m_havePropertiesChanged == false)
{
float lossyScaleY = m_rectTransform.lossyScale.y;
if (lossyScaleY != m_previousLossyScaleY && m_text != string.Empty && m_text != null)
{
float scaleDelta = lossyScaleY / m_previousLossyScaleY;
UpdateSDFScale(scaleDelta);
m_previousLossyScaleY = lossyScaleY;
}
}
// Added to handle legacy animation mode.
if (m_isUsingLegacyAnimationComponent)
{
//if (m_havePropertiesChanged)
m_havePropertiesChanged = true;
OnPreRenderObject();
}
}
/// <summary>
/// Function called when the text needs to be updated.
/// </summary>
void OnPreRenderObject()
{
//Debug.Log("*** OnPreRenderObject() ***");
if (!m_isAwake || (this.IsActive() == false && m_ignoreActiveState == false)) return;
// Debug Variables
loopCountA = 0;
//loopCountB = 0;
//loopCountC = 0;
//loopCountD = 0;
//loopCountE = 0;
if (m_havePropertiesChanged || m_isLayoutDirty)
{
//Debug.Log("Properties have changed!"); // Assigned Material is:" + m_sharedMaterial); // New Text is: " + m_text + ".");
if (isMaskUpdateRequired)
{
UpdateMask();
isMaskUpdateRequired = false;
}
// Update mesh padding if necessary.
if (checkPaddingRequired)
UpdateMeshPadding();
// Reparse the text if the input has changed or text was truncated.
if (m_isInputParsingRequired || m_isTextTruncated)
ParseInputText();
// Reset Font min / max used with Auto-sizing
if (m_enableAutoSizing)
m_fontSize = Mathf.Clamp(m_fontSizeBase, m_fontSizeMin, m_fontSizeMax);
m_maxFontSize = m_fontSizeMax;
m_minFontSize = m_fontSizeMin;
m_lineSpacingDelta = 0;
m_charWidthAdjDelta = 0;
//m_recursiveCount = 0;
m_isCharacterWrappingEnabled = false;
m_isTextTruncated = false;
m_havePropertiesChanged = false;
m_isLayoutDirty = false;
m_ignoreActiveState = false;
GenerateTextMesh();
}
}
/// <summary>
/// This is the main function that is responsible for creating / displaying the text.
/// </summary>
protected override void GenerateTextMesh()
{
//Debug.Log("***** GenerateTextMesh() *****"); // ***** Frame: " + Time.frameCount); // + ". Point Size: " + m_fontSize + ". Margins are (W) " + m_marginWidth + " (H) " + m_marginHeight); // ". Iteration Count: " + loopCountA + ". Min: " + m_minFontSize + " Max: " + m_maxFontSize + " Delta: " + (m_maxFontSize - m_minFontSize) + " Font size is " + m_fontSize); //called for Object with ID " + GetInstanceID()); // Assigned Material is " + m_uiRenderer.GetMaterial().name); // IncludeForMasking " + this.m_IncludeForMasking); // and text is " + m_text);
// Early exit if no font asset was assigned. This should not be needed since LiberationSans SDF will be assigned by default.
if (m_fontAsset == null || m_fontAsset.characterLookupTable == null)
{
Debug.LogWarning("Can't Generate Mesh! No Font Asset has been assigned to Object ID: " + this.GetInstanceID());
return;
}
// Clear TextInfo
if (m_textInfo != null)
m_textInfo.Clear();
// Early exit if we don't have any Text to generate.
if (m_TextParsingBuffer == null || m_TextParsingBuffer.Length == 0 || m_TextParsingBuffer[0].unicode == (char)0)
{
// Clear mesh and upload changes to the mesh.
ClearMesh(true);
m_preferredWidth = 0;
m_preferredHeight = 0;
// Event indicating the text has been regenerated.
TMPro_EventManager.ON_TEXT_CHANGED(this);
return;
}
m_currentFontAsset = m_fontAsset;
m_currentMaterial = m_sharedMaterial;
m_currentMaterialIndex = 0;
m_materialReferenceStack.SetDefault(new MaterialReference(m_currentMaterialIndex, m_currentFontAsset, null, m_currentMaterial, m_padding));
m_currentSpriteAsset = m_spriteAsset;
// Stop all Sprite Animations
if (m_spriteAnimator != null)
m_spriteAnimator.StopAllAnimations();
// Total character count is computed when the text is parsed.
int totalCharacterCount = m_totalCharacterCount;
// Calculate the scale of the font based on selected font size and sampling point size.
// baseScale is calculated using the font asset assigned to the text object.
float baseScale = m_fontScale = (m_fontSize / m_fontAsset.faceInfo.pointSize * m_fontAsset.faceInfo.scale * (m_isOrthographic ? 1 : 0.1f));
float currentElementScale = baseScale;
m_fontScaleMultiplier = 1;
m_currentFontSize = m_fontSize;
m_sizeStack.SetDefault(m_currentFontSize);
float fontSizeDelta = 0;
int charCode = 0; // Holds the character code of the currently being processed character.
m_FontStyleInternal = m_fontStyle; // Set the default style.
m_FontWeightInternal = (m_FontStyleInternal & FontStyles.Bold) == FontStyles.Bold ? FontWeight.Bold : m_fontWeight;
m_FontWeightStack.SetDefault(m_FontWeightInternal);
m_fontStyleStack.Clear();
m_lineJustification = m_textAlignment; // Sets the line justification mode to match editor alignment.
m_lineJustificationStack.SetDefault(m_lineJustification);
float padding = 0;
float style_padding = 0; // Extra padding required to accommodate Bold style.
float bold_xAdvance_multiplier = 1; // Used to increase spacing between character when style is bold.
m_baselineOffset = 0; // Used by subscript characters.
m_baselineOffsetStack.Clear();
// Underline
bool beginUnderline = false;
Vector3 underline_start = Vector3.zero; // Used to track where underline starts & ends.
Vector3 underline_end = Vector3.zero;
// Strike-through
bool beginStrikethrough = false;
Vector3 strikethrough_start = Vector3.zero;
Vector3 strikethrough_end = Vector3.zero;
// Text Highlight
bool beginHighlight = false;
Vector3 highlight_start = Vector3.zero;
Vector3 highlight_end = Vector3.zero;
m_fontColor32 = m_fontColor;
Color32 vertexColor;
m_htmlColor = m_fontColor32;
m_underlineColor = m_htmlColor;
m_strikethroughColor = m_htmlColor;
m_colorStack.SetDefault(m_htmlColor);
m_underlineColorStack.SetDefault(m_htmlColor);
m_strikethroughColorStack.SetDefault(m_htmlColor);
m_highlightColorStack.SetDefault(m_htmlColor);
m_colorGradientPreset = null;
m_colorGradientStack.SetDefault(null);
// Clear the Style stack.
//m_styleStack.Clear();
// Clear the Action stack.
m_actionStack.Clear();
m_isFXMatrixSet = false;
m_lineOffset = 0; // Amount of space between lines (font line spacing + m_linespacing).
m_lineHeight = TMP_Math.FLOAT_UNSET;
float lineGap = m_currentFontAsset.faceInfo.lineHeight - (m_currentFontAsset.faceInfo.ascentLine - m_currentFontAsset.faceInfo.descentLine);
m_cSpacing = 0; // Amount of space added between characters as a result of the use of the <cspace> tag.
m_monoSpacing = 0;
float lineOffsetDelta = 0;
m_xAdvance = 0; // Used to track the position of each character.
tag_LineIndent = 0; // Used for indentation of text.
tag_Indent = 0;
m_indentStack.SetDefault(0);
tag_NoParsing = false;
//m_isIgnoringAlignment = false;
m_characterCount = 0; // Total characters in the char[]
// Tracking of line information
m_firstCharacterOfLine = 0;
m_lastCharacterOfLine = 0;
m_firstVisibleCharacterOfLine = 0;
m_lastVisibleCharacterOfLine = 0;
m_maxLineAscender = k_LargeNegativeFloat;
m_maxLineDescender = k_LargePositiveFloat;
m_lineNumber = 0;
m_lineVisibleCharacterCount = 0;
bool isStartOfNewLine = true;
m_firstOverflowCharacterIndex = -1;
m_pageNumber = 0;
int pageToDisplay = Mathf.Clamp(m_pageToDisplay - 1, 0, m_textInfo.pageInfo.Length - 1);
int previousPageOverflowChar = 0;
int ellipsisIndex = 0;
Vector4 margins = m_margin;
float marginWidth = m_marginWidth;
float marginHeight = m_marginHeight;
m_marginLeft = 0;
m_marginRight = 0;
m_width = -1;
float width = marginWidth + 0.0001f - m_marginLeft - m_marginRight;
// Need to initialize these Extents structures
m_meshExtents.min = k_LargePositiveVector2;
m_meshExtents.max = k_LargeNegativeVector2;
// Initialize lineInfo
m_textInfo.ClearLineInfo();
// Tracking of the highest Ascender
m_maxCapHeight = 0;
m_maxAscender = 0;
m_maxDescender = 0;
float pageAscender = 0;
float maxVisibleDescender = 0;
bool isMaxVisibleDescenderSet = false;
m_isNewPage = false;
// Initialize struct to track states of word wrapping
bool isFirstWord = true;
m_isNonBreakingSpace = false;
bool ignoreNonBreakingSpace = false;
bool isLastBreakingChar = false;
float linebreakingWidth = 0;
int wrappingIndex = 0;
// Save character and line state before we begin layout.
SaveWordWrappingState(ref m_SavedWordWrapState, -1, -1);
SaveWordWrappingState(ref m_SavedLineState, -1, -1);
loopCountA += 1;
// Parse through Character buffer to read HTML tags and begin creating mesh.
for (int i = 0; i < m_TextParsingBuffer.Length && m_TextParsingBuffer[i].unicode != 0; i++)
{
charCode = m_TextParsingBuffer[i].unicode;
// Parse Rich Text Tag
#region Parse Rich Text Tag
if (m_isRichText && charCode == 60) // '<'
{
m_isParsingText = true;
m_textElementType = TMP_TextElementType.Character;
// Check if Tag is valid. If valid, skip to the end of the validated tag.
if (ValidateHtmlTag(m_TextParsingBuffer, i + 1, out int endTagIndex))
{
i = endTagIndex;
// Continue to next character or handle the sprite element
if (m_textElementType == TMP_TextElementType.Character)
continue;
}
}
else
{
m_textElementType = m_textInfo.characterInfo[m_characterCount].elementType;
m_currentMaterialIndex = m_textInfo.characterInfo[m_characterCount].materialReferenceIndex;
m_currentFontAsset = m_textInfo.characterInfo[m_characterCount].fontAsset;
}
#endregion End Parse Rich Text Tag
int prev_MaterialIndex = m_currentMaterialIndex;
bool isUsingAltTypeface = m_textInfo.characterInfo[m_characterCount].isUsingAlternateTypeface;
m_isParsingText = false;
// When using Linked text, mark character as ignored and skip to next character.
if (m_characterCount < m_firstVisibleCharacter)
{
m_textInfo.characterInfo[m_characterCount].isVisible = false;
m_textInfo.characterInfo[m_characterCount].character = (char)0x200B;
m_characterCount += 1;
continue;
}
// Handle Font Styles like LowerCase, UpperCase and SmallCaps.
#region Handling of LowerCase, UpperCase and SmallCaps Font Styles
float smallCapsMultiplier = 1.0f;
if (m_textElementType == TMP_TextElementType.Character)
{
if ((m_FontStyleInternal & FontStyles.UpperCase) == FontStyles.UpperCase)
{
// If this character is lowercase, switch to uppercase.
if (char.IsLower((char)charCode))
charCode = char.ToUpper((char)charCode);
}
else if ((m_FontStyleInternal & FontStyles.LowerCase) == FontStyles.LowerCase)
{
// If this character is uppercase, switch to lowercase.
if (char.IsUpper((char)charCode))
charCode = char.ToLower((char)charCode);
}
else if ((m_FontStyleInternal & FontStyles.SmallCaps) == FontStyles.SmallCaps)
{
if (char.IsLower((char)charCode))
{
smallCapsMultiplier = 0.8f;
charCode = char.ToUpper((char)charCode);
}
}
}
#endregion
// Look up Character Data from Dictionary and cache it.
#region Look up Character Data
if (m_textElementType == TMP_TextElementType.Sprite)
{
// If a sprite is used as a fallback then get a reference to it and set the color to white.
m_currentSpriteAsset = m_textInfo.characterInfo[m_characterCount].spriteAsset;
m_spriteIndex = m_textInfo.characterInfo[m_characterCount].spriteIndex;
TMP_SpriteCharacter sprite = m_currentSpriteAsset.spriteCharacterTable[m_spriteIndex];
if (sprite == null) continue;
// Sprites are assigned in the E000 Private Area + sprite Index
if (charCode == 60)
charCode = 57344 + m_spriteIndex;
else
m_spriteColor = s_colorWhite;
// The sprite scale calculations are based on the font asset assigned to the text object.
float spriteScale = (m_currentFontSize / m_currentFontAsset.faceInfo.pointSize * m_currentFontAsset.faceInfo.scale * (m_isOrthographic ? 1 : 0.1f));
currentElementScale = m_currentFontAsset.faceInfo.ascentLine / sprite.glyph.metrics.height * sprite.scale * sprite.glyph.scale * spriteScale;
m_cached_TextElement = sprite;
m_textInfo.characterInfo[m_characterCount].elementType = TMP_TextElementType.Sprite;
m_textInfo.characterInfo[m_characterCount].scale = spriteScale;
m_textInfo.characterInfo[m_characterCount].spriteAsset = m_currentSpriteAsset;
m_textInfo.characterInfo[m_characterCount].fontAsset = m_currentFontAsset;
m_textInfo.characterInfo[m_characterCount].materialReferenceIndex = m_currentMaterialIndex;
m_currentMaterialIndex = prev_MaterialIndex;
padding = 0;
}
else if (m_textElementType == TMP_TextElementType.Character)
{
m_cached_TextElement = m_textInfo.characterInfo[m_characterCount].textElement;
if (m_cached_TextElement == null) continue;
m_currentFontAsset = m_textInfo.characterInfo[m_characterCount].fontAsset;
m_currentMaterial = m_textInfo.characterInfo[m_characterCount].material;
m_currentMaterialIndex = m_textInfo.characterInfo[m_characterCount].materialReferenceIndex;
// Re-calculate font scale as the font asset may have changed.
m_fontScale = m_currentFontSize * smallCapsMultiplier / m_currentFontAsset.faceInfo.pointSize * m_currentFontAsset.faceInfo.scale * (m_isOrthographic ? 1 : 0.1f);
currentElementScale = m_fontScale * m_fontScaleMultiplier * m_cached_TextElement.scale * m_cached_TextElement.glyph.scale;
m_textInfo.characterInfo[m_characterCount].elementType = TMP_TextElementType.Character;
m_textInfo.characterInfo[m_characterCount].scale = currentElementScale;
padding = m_currentMaterialIndex == 0 ? m_padding : m_subTextObjects[m_currentMaterialIndex].padding;
}
#endregion
// Handle Soft Hyphen
#region Handle Soft Hyphen
float old_scale = currentElementScale;
if (charCode == 0xAD)
{
currentElementScale = 0;
}
#endregion
// Store some of the text object's information
m_textInfo.characterInfo[m_characterCount].character = (char)charCode;
m_textInfo.characterInfo[m_characterCount].pointSize = m_currentFontSize;
m_textInfo.characterInfo[m_characterCount].color = m_htmlColor;
m_textInfo.characterInfo[m_characterCount].underlineColor = m_underlineColor;
m_textInfo.characterInfo[m_characterCount].strikethroughColor = m_strikethroughColor;
m_textInfo.characterInfo[m_characterCount].highlightColor = m_highlightColor;
m_textInfo.characterInfo[m_characterCount].style = m_FontStyleInternal;
//m_textInfo.characterInfo[m_characterCount].index = m_TextParsingBuffer[i].stringIndex;
//m_textInfo.characterInfo[m_characterCount].isIgnoringAlignment = m_isIgnoringAlignment;
// Handle Kerning if Enabled.
#region Handle Kerning
TMP_GlyphValueRecord glyphAdjustments = new TMP_GlyphValueRecord();
float characterSpacingAdjustment = m_characterSpacing;
if (m_enableKerning)
{
if (m_characterCount < totalCharacterCount - 1)
{
uint firstGlyphIndex = m_cached_TextElement.glyphIndex;
uint secondGlyphIndex = m_textInfo.characterInfo[m_characterCount + 1].textElement.glyphIndex;
long key = new GlyphPairKey(firstGlyphIndex, secondGlyphIndex).key;
if (m_currentFontAsset.fontFeatureTable.m_GlyphPairAdjustmentRecordLookupDictionary.TryGetValue(key, out TMP_GlyphPairAdjustmentRecord adjustmentPair))
{
glyphAdjustments = adjustmentPair.firstAdjustmentRecord.glyphValueRecord;
characterSpacingAdjustment = (adjustmentPair.featureLookupFlags & FontFeatureLookupFlags.IgnoreSpacingAdjustments) == FontFeatureLookupFlags.IgnoreSpacingAdjustments ? 0 : characterSpacingAdjustment;
}
}
if (m_characterCount >= 1)
{
uint firstGlyphIndex = m_textInfo.characterInfo[m_characterCount - 1].textElement.glyphIndex;
uint secondGlyphIndex = m_cached_TextElement.glyphIndex;
long key = new GlyphPairKey(firstGlyphIndex, secondGlyphIndex).key;
if (m_currentFontAsset.fontFeatureTable.m_GlyphPairAdjustmentRecordLookupDictionary.TryGetValue(key, out TMP_GlyphPairAdjustmentRecord adjustmentPair))
{
glyphAdjustments += adjustmentPair.secondAdjustmentRecord.glyphValueRecord;
characterSpacingAdjustment = (adjustmentPair.featureLookupFlags & FontFeatureLookupFlags.IgnoreSpacingAdjustments) == FontFeatureLookupFlags.IgnoreSpacingAdjustments ? 0 : characterSpacingAdjustment;
}
}
}
#endregion
// Initial Implementation for RTL support.
#region Handle Right-to-Left
if (m_isRightToLeft)
{
m_xAdvance -= ((m_cached_TextElement.glyph.metrics.horizontalAdvance * bold_xAdvance_multiplier + characterSpacingAdjustment + m_wordSpacing + m_currentFontAsset.normalSpacingOffset) * currentElementScale + m_cSpacing) * (1 - m_charWidthAdjDelta);
if (char.IsWhiteSpace((char)charCode) || charCode == 0x200B)
m_xAdvance -= m_wordSpacing * currentElementScale;
}
#endregion
// Handle Mono Spacing
#region Handle Mono Spacing
float monoAdvance = 0;
if (m_monoSpacing != 0)
{
monoAdvance = (m_monoSpacing / 2 - (m_cached_TextElement.glyph.metrics.width / 2 + m_cached_TextElement.glyph.metrics.horizontalBearingX) * currentElementScale) * (1 - m_charWidthAdjDelta);
m_xAdvance += monoAdvance;
}
#endregion
// Set Padding based on selected font style
#region Handle Style Padding
if (m_textElementType == TMP_TextElementType.Character && !isUsingAltTypeface && (/*(m_fontStyle & FontStyles.Bold) == FontStyles.Bold ||*/ (m_FontStyleInternal & FontStyles.Bold) == FontStyles.Bold)) // Checks for any combination of Bold Style.
{
if (m_currentMaterial.HasProperty(ShaderUtilities.ID_GradientScale))
{
float gradientScale = m_currentMaterial.GetFloat(ShaderUtilities.ID_GradientScale);
style_padding = m_currentFontAsset.boldStyle / 4.0f * gradientScale * m_currentMaterial.GetFloat(ShaderUtilities.ID_ScaleRatio_A);
// Clamp overall padding to Gradient Scale size.
if (style_padding + padding > gradientScale)
padding = gradientScale - style_padding;
}
else
style_padding = 0;
bold_xAdvance_multiplier = 1 + m_currentFontAsset.boldSpacing * 0.01f;
}
else
{
if (m_currentMaterial.HasProperty(ShaderUtilities.ID_GradientScale))
{
float gradientScale = m_currentMaterial.GetFloat(ShaderUtilities.ID_GradientScale);
style_padding = m_currentFontAsset.normalStyle / 4.0f * gradientScale * m_currentMaterial.GetFloat(ShaderUtilities.ID_ScaleRatio_A);
// Clamp overall padding to Gradient Scale size.
if (style_padding + padding > gradientScale)
padding = gradientScale - style_padding;
}
else
style_padding = 0;
bold_xAdvance_multiplier = 1.0f;
}
#endregion Handle Style Padding
// Determine the position of the vertices of the Character or Sprite.
#region Calculate Vertices Position
float fontBaseLineOffset = m_currentFontAsset.faceInfo.baseline * m_fontScale * m_fontScaleMultiplier * m_currentFontAsset.faceInfo.scale;
Vector3 top_left;
top_left.x = m_xAdvance + ((m_cached_TextElement.glyph.metrics.horizontalBearingX - padding - style_padding + glyphAdjustments.xPlacement) * currentElementScale * (1 - m_charWidthAdjDelta));
top_left.y = fontBaseLineOffset + (m_cached_TextElement.glyph.metrics.horizontalBearingY + padding + glyphAdjustments.yPlacement) * currentElementScale - m_lineOffset + m_baselineOffset;
top_left.z = 0;
Vector3 bottom_left;
bottom_left.x = top_left.x;
bottom_left.y = top_left.y - ((m_cached_TextElement.glyph.metrics.height + padding * 2) * currentElementScale);
bottom_left.z = 0;
Vector3 top_right;
top_right.x = bottom_left.x + ((m_cached_TextElement.glyph.metrics.width + padding * 2 + style_padding * 2) * currentElementScale * (1 - m_charWidthAdjDelta));
top_right.y = top_left.y;
top_right.z = 0;
Vector3 bottom_right;
bottom_right.x = top_right.x;
bottom_right.y = bottom_left.y;
bottom_right.z = 0;
#endregion
// Check if we need to Shear the rectangles for Italic styles
#region Handle Italic & Shearing
if (m_textElementType == TMP_TextElementType.Character && !isUsingAltTypeface && (/*(m_fontStyle & FontStyles.Italic) == FontStyles.Italic ||*/ (m_FontStyleInternal & FontStyles.Italic) == FontStyles.Italic))
{
// Shift Top vertices forward by half (Shear Value * height of character) and Bottom vertices back by same amount.
float shear_value = m_currentFontAsset.italicStyle * 0.01f;
Vector3 topShear = new Vector3(shear_value * ((m_cached_TextElement.glyph.metrics.horizontalBearingY + padding + style_padding) * currentElementScale), 0, 0);
Vector3 bottomShear = new Vector3(shear_value * (((m_cached_TextElement.glyph.metrics.horizontalBearingY - m_cached_TextElement.glyph.metrics.height - padding - style_padding)) * currentElementScale), 0, 0);
top_left = top_left + topShear;
bottom_left = bottom_left + bottomShear;
top_right = top_right + topShear;
bottom_right = bottom_right + bottomShear;
}
#endregion Handle Italics & Shearing
// Handle Character Rotation
#region Handle Character Rotation
if (m_isFXMatrixSet)
{
// Apply scale matrix when simulating Condensed text.
if (m_FXMatrix.lossyScale.x != 1)
{
//top_left = m_FXMatrix.MultiplyPoint3x4(top_left);
//bottom_left = m_FXMatrix.MultiplyPoint3x4(bottom_left);
//top_right = m_FXMatrix.MultiplyPoint3x4(top_right);
//bottom_right = m_FXMatrix.MultiplyPoint3x4(bottom_right);
}
Vector3 positionOffset = (top_right + bottom_left) / 2;
top_left = m_FXMatrix.MultiplyPoint3x4(top_left - positionOffset) + positionOffset;
bottom_left = m_FXMatrix.MultiplyPoint3x4(bottom_left - positionOffset) + positionOffset;
top_right = m_FXMatrix.MultiplyPoint3x4(top_right - positionOffset) + positionOffset;
bottom_right = m_FXMatrix.MultiplyPoint3x4(bottom_right - positionOffset) + positionOffset;
}
#endregion
// Store vertex information for the character or sprite.
m_textInfo.characterInfo[m_characterCount].bottomLeft = bottom_left;
m_textInfo.characterInfo[m_characterCount].topLeft = top_left;
m_textInfo.characterInfo[m_characterCount].topRight = top_right;
m_textInfo.characterInfo[m_characterCount].bottomRight = bottom_right;
m_textInfo.characterInfo[m_characterCount].origin = m_xAdvance;
m_textInfo.characterInfo[m_characterCount].baseLine = fontBaseLineOffset - m_lineOffset + m_baselineOffset;
m_textInfo.characterInfo[m_characterCount].aspectRatio = (top_right.x - bottom_left.x) / (top_left.y - bottom_left.y);
// Compute and save text element Ascender and maximum line Ascender.
float elementAscender = m_currentFontAsset.faceInfo.ascentLine * (m_textElementType == TMP_TextElementType.Character ? currentElementScale / smallCapsMultiplier : m_textInfo.characterInfo[m_characterCount].scale) + m_baselineOffset;
m_textInfo.characterInfo[m_characterCount].ascender = elementAscender - m_lineOffset;
m_maxLineAscender = elementAscender > m_maxLineAscender ? elementAscender : m_maxLineAscender;
// Compute and save text element Descender and maximum line Descender.
float elementDescender = m_currentFontAsset.faceInfo.descentLine * (m_textElementType == TMP_TextElementType.Character ? currentElementScale / smallCapsMultiplier : m_textInfo.characterInfo[m_characterCount].scale) + m_baselineOffset;
float elementDescenderII = m_textInfo.characterInfo[m_characterCount].descender = elementDescender - m_lineOffset;
m_maxLineDescender = elementDescender < m_maxLineDescender ? elementDescender : m_maxLineDescender;
// Adjust maxLineAscender and maxLineDescender if style is superscript or subscript
if ((m_FontStyleInternal & FontStyles.Subscript) == FontStyles.Subscript || (m_FontStyleInternal & FontStyles.Superscript) == FontStyles.Superscript)
{
float baseAscender = (elementAscender - m_baselineOffset) / m_currentFontAsset.faceInfo.subscriptSize;
elementAscender = m_maxLineAscender;
m_maxLineAscender = baseAscender > m_maxLineAscender ? baseAscender : m_maxLineAscender;
float baseDescender = (elementDescender - m_baselineOffset) / m_currentFontAsset.faceInfo.subscriptSize;
elementDescender = m_maxLineDescender;
m_maxLineDescender = baseDescender < m_maxLineDescender ? baseDescender : m_maxLineDescender;
}
if (m_lineNumber == 0 || m_isNewPage)
{
m_maxAscender = m_maxAscender > elementAscender ? m_maxAscender : elementAscender;
m_maxCapHeight = Mathf.Max(m_maxCapHeight, m_currentFontAsset.faceInfo.capLine * currentElementScale / smallCapsMultiplier);
}
if (m_lineOffset == 0) pageAscender = pageAscender > elementAscender ? pageAscender : elementAscender;
// Set Characters to not visible by default.
m_textInfo.characterInfo[m_characterCount].isVisible = false;
// Setup Mesh for visible text elements. ie. not a SPACE / LINEFEED / CARRIAGE RETURN.
#region Handle Visible Characters
if (charCode == 9 || charCode == 0xA0 || charCode == 0x2007 || (!char.IsWhiteSpace((char)charCode) && charCode != 0x200B) || m_textElementType == TMP_TextElementType.Sprite)
{
m_textInfo.characterInfo[m_characterCount].isVisible = true;
#region Experimental Margin Shaper
//Vector2 shapedMargins;
//if (marginShaper)
//{
// shapedMargins = m_marginShaper.GetShapedMargins(m_textInfo.characterInfo[m_characterCount].baseLine);
// if (shapedMargins.x < margins.x)
// {
// shapedMargins.x = m_marginLeft;
// }
// else
// {
// shapedMargins.x += m_marginLeft - margins.x;
// }
// if (shapedMargins.y < margins.z)
// {
// shapedMargins.y = m_marginRight;
// }
// else
// {
// shapedMargins.y += m_marginRight - margins.z;
// }
//}
//else
//{
// shapedMargins.x = m_marginLeft;
// shapedMargins.y = m_marginRight;
//}
//width = marginWidth + 0.0001f - shapedMargins.x - shapedMargins.y;
//if (m_width != -1 && m_width < width)
//{
// width = m_width;
//}
//m_textInfo.lineInfo[m_lineNumber].marginLeft = shapedMargins.x;
#endregion
width = m_width != -1 ? Mathf.Min(marginWidth + 0.0001f - m_marginLeft - m_marginRight, m_width) : marginWidth + 0.0001f - m_marginLeft - m_marginRight;
m_textInfo.lineInfo[m_lineNumber].marginLeft = m_marginLeft;
bool isJustifiedOrFlush = ((_HorizontalAlignmentOptions)m_lineJustification & _HorizontalAlignmentOptions.Flush) == _HorizontalAlignmentOptions.Flush || ((_HorizontalAlignmentOptions)m_lineJustification & _HorizontalAlignmentOptions.Justified) == _HorizontalAlignmentOptions.Justified;
// Calculate the line breaking width of the text.
linebreakingWidth = Mathf.Abs(m_xAdvance) + (!m_isRightToLeft ? m_cached_TextElement.glyph.metrics.horizontalAdvance : 0) * (1 - m_charWidthAdjDelta) * (charCode != 0xAD ? currentElementScale : old_scale);
// Check if Character exceeds the width of the Text Container
#region Handle Line Breaking, Text Auto-Sizing and Horizontal Overflow
if (linebreakingWidth > width * (isJustifiedOrFlush ? 1.05f : 1.0f))
{
ellipsisIndex = m_characterCount - 1; // Last safely rendered character
// Word Wrapping
#region Handle Word Wrapping
if (enableWordWrapping && m_characterCount != m_firstCharacterOfLine)
{
// Check if word wrapping is still possible
#region Line Breaking Check
if (wrappingIndex == m_SavedWordWrapState.previous_WordBreak || isFirstWord)
{
// Word wrapping is no longer possible. Shrink size of text if auto-sizing is enabled.
if (m_enableAutoSizing && m_fontSize > m_fontSizeMin)
{
// Handle Character Width Adjustments
#region Character Width Adjustments
if (m_charWidthAdjDelta < m_charWidthMaxAdj / 100)
{
loopCountA = 0;
m_charWidthAdjDelta += 0.01f;
GenerateTextMesh();
return;
}
#endregion
// Adjust Point Size
m_maxFontSize = m_fontSize;
m_fontSize -= Mathf.Max((m_fontSize - m_minFontSize) / 2, 0.05f);
m_fontSize = (int)(Mathf.Max(m_fontSize, m_fontSizeMin) * 20 + 0.5f) / 20f;
if (loopCountA > 20) return; // Added to debug
GenerateTextMesh();
return;
}
// Word wrapping is no longer possible, now breaking up individual words.
if (m_isCharacterWrappingEnabled == false)
{
if (ignoreNonBreakingSpace == false)
ignoreNonBreakingSpace = true;
else
m_isCharacterWrappingEnabled = true;
}
else
isLastBreakingChar = true;
//m_recursiveCount += 1;
//if (m_recursiveCount > 20)
//{
// Debug.Log("Recursive count exceeded!");
// continue;
//}
}
#endregion
// Restore to previously stored state of last valid (space character or linefeed)
i = RestoreWordWrappingState(ref m_SavedWordWrapState);
wrappingIndex = i; // Used to detect when line length can no longer be reduced.
// Handling for Soft Hyphen
if (m_TextParsingBuffer[i].unicode == 0xAD) // && !m_isCharacterWrappingEnabled) // && ellipsisIndex != i && !m_isCharacterWrappingEnabled)
{
m_isTextTruncated = true;
m_TextParsingBuffer[i].unicode = 0x2D;
GenerateTextMesh();
return;
}
//Debug.Log("Last Visible Character of line # " + m_lineNumber + " is [" + m_textInfo.characterInfo[m_lastVisibleCharacterOfLine].character + " Character Count: " + m_characterCount + " Last visible: " + m_lastVisibleCharacterOfLine);
// Check if Line Spacing of previous line needs to be adjusted.
if (m_lineNumber > 0 && !TMP_Math.Approximately(m_maxLineAscender, m_startOfLineAscender) && m_lineHeight == TMP_Math.FLOAT_UNSET && !m_isNewPage)
{
//Debug.Log("(Line Break - Adjusting Line Spacing on line #" + m_lineNumber);
float offsetDelta = m_maxLineAscender - m_startOfLineAscender;
AdjustLineOffset(m_firstCharacterOfLine, m_characterCount, offsetDelta);
m_lineOffset += offsetDelta;
m_SavedWordWrapState.lineOffset = m_lineOffset;
m_SavedWordWrapState.previousLineAscender = m_maxLineAscender;
// TODO - Add check for character exceeding vertical bounds
}
m_isNewPage = false;
// Calculate lineAscender & make sure if last character is superscript or subscript that we check that as well.
float lineAscender = m_maxLineAscender - m_lineOffset;
float lineDescender = m_maxLineDescender - m_lineOffset;
// Update maxDescender and maxVisibleDescender
m_maxDescender = m_maxDescender < lineDescender ? m_maxDescender : lineDescender;
if (!isMaxVisibleDescenderSet)
maxVisibleDescender = m_maxDescender;
if (m_useMaxVisibleDescender && (m_characterCount >= m_maxVisibleCharacters || m_lineNumber >= m_maxVisibleLines))
isMaxVisibleDescenderSet = true;
// Track & Store lineInfo for the new line
m_textInfo.lineInfo[m_lineNumber].firstCharacterIndex = m_firstCharacterOfLine;
m_textInfo.lineInfo[m_lineNumber].firstVisibleCharacterIndex = m_firstVisibleCharacterOfLine = m_firstCharacterOfLine > m_firstVisibleCharacterOfLine ? m_firstCharacterOfLine : m_firstVisibleCharacterOfLine;
m_textInfo.lineInfo[m_lineNumber].lastCharacterIndex = m_lastCharacterOfLine = m_characterCount - 1 > 0 ? m_characterCount - 1 : 0;
m_textInfo.lineInfo[m_lineNumber].lastVisibleCharacterIndex = m_lastVisibleCharacterOfLine = m_lastVisibleCharacterOfLine < m_firstVisibleCharacterOfLine ? m_firstVisibleCharacterOfLine : m_lastVisibleCharacterOfLine;
m_textInfo.lineInfo[m_lineNumber].characterCount = m_textInfo.lineInfo[m_lineNumber].lastCharacterIndex - m_textInfo.lineInfo[m_lineNumber].firstCharacterIndex + 1;
m_textInfo.lineInfo[m_lineNumber].visibleCharacterCount = m_lineVisibleCharacterCount;
m_textInfo.lineInfo[m_lineNumber].lineExtents.min = new Vector2(m_textInfo.characterInfo[m_firstVisibleCharacterOfLine].bottomLeft.x, lineDescender);
m_textInfo.lineInfo[m_lineNumber].lineExtents.max = new Vector2(m_textInfo.characterInfo[m_lastVisibleCharacterOfLine].topRight.x, lineAscender);
m_textInfo.lineInfo[m_lineNumber].length = m_textInfo.lineInfo[m_lineNumber].lineExtents.max.x;
m_textInfo.lineInfo[m_lineNumber].width = width;
//m_textInfo.lineInfo[m_lineNumber].alignment = m_lineJustification;
m_textInfo.lineInfo[m_lineNumber].maxAdvance = m_textInfo.characterInfo[m_lastVisibleCharacterOfLine].xAdvance - (characterSpacingAdjustment + m_currentFontAsset.normalSpacingOffset) * currentElementScale - m_cSpacing;
m_textInfo.lineInfo[m_lineNumber].baseline = 0 - m_lineOffset;
m_textInfo.lineInfo[m_lineNumber].ascender = lineAscender;
m_textInfo.lineInfo[m_lineNumber].descender = lineDescender;
m_textInfo.lineInfo[m_lineNumber].lineHeight = lineAscender - lineDescender + lineGap * baseScale;
m_firstCharacterOfLine = m_characterCount; // Store first character of the next line.
m_lineVisibleCharacterCount = 0;
// Store the state of the line before starting on the new line.
SaveWordWrappingState(ref m_SavedLineState, i, m_characterCount - 1);
m_lineNumber += 1;
isStartOfNewLine = true;
isFirstWord = true;
// Check to make sure Array is large enough to hold a new line.
if (m_lineNumber >= m_textInfo.lineInfo.Length)
ResizeLineExtents(m_lineNumber);
// Apply Line Spacing based on scale of the last character of the line.
if (m_lineHeight == TMP_Math.FLOAT_UNSET)
{
float ascender = m_textInfo.characterInfo[m_characterCount].ascender - m_textInfo.characterInfo[m_characterCount].baseLine;
lineOffsetDelta = 0 - m_maxLineDescender + ascender + (lineGap + m_lineSpacing + m_lineSpacingDelta) * baseScale;
m_lineOffset += lineOffsetDelta;
m_startOfLineAscender = ascender;
}
else
m_lineOffset += m_lineHeight + m_lineSpacing * baseScale;
m_maxLineAscender = k_LargeNegativeFloat;
m_maxLineDescender = k_LargePositiveFloat;
m_xAdvance = 0 + tag_Indent;
continue;
}
#endregion End Word Wrapping
// Text Auto-Sizing (text exceeding Width of container.
#region Handle Text Auto-Sizing
if (m_enableAutoSizing && m_fontSize > m_fontSizeMin)
{
// Handle Character Width Adjustments
#region Character Width Adjustments
if (m_charWidthAdjDelta < m_charWidthMaxAdj / 100)
{
loopCountA = 0;
m_charWidthAdjDelta += 0.01f;
GenerateTextMesh();
return;
}
#endregion
// Adjust Point Size
m_maxFontSize = m_fontSize;
m_fontSize -= Mathf.Max((m_fontSize - m_minFontSize) / 2, 0.05f);
m_fontSize = (int)(Mathf.Max(m_fontSize, m_fontSizeMin) * 20 + 0.5f) / 20f;
//m_recursiveCount = 0;
if (loopCountA > 20) return; // Added to debug
GenerateTextMesh();
return;
}
#endregion End Text Auto-Sizing
// Handle Text Overflow
#region Handle Text Overflow
switch (m_overflowMode)
{
case TextOverflowModes.Overflow:
if (m_isMaskingEnabled)
DisableMasking();
break;
case TextOverflowModes.Ellipsis:
if (m_isMaskingEnabled)
DisableMasking();
m_isTextTruncated = true;
if (m_characterCount < 1)
{
m_textInfo.characterInfo[m_characterCount].isVisible = false;
//m_visibleCharacterCount = 0;
break;
}
m_TextParsingBuffer[i - 1].unicode = 8230;
m_TextParsingBuffer[i].unicode = (char)0;
if (m_cached_Ellipsis_Character != null)
{
m_textInfo.characterInfo[ellipsisIndex].character = (char)8230;
m_textInfo.characterInfo[ellipsisIndex].textElement = m_cached_Ellipsis_Character;
m_textInfo.characterInfo[ellipsisIndex].fontAsset = m_materialReferences[0].fontAsset;
m_textInfo.characterInfo[ellipsisIndex].material = m_materialReferences[0].material;
m_textInfo.characterInfo[ellipsisIndex].materialReferenceIndex = 0;
}
else
{
Debug.LogWarning("Unable to use Ellipsis character since it wasn't found in the current Font Asset [" + m_fontAsset.name + "]. Consider regenerating this font asset to include the Ellipsis character (u+2026).\nNote: Warnings can be disabled in the TMP Settings file.", this);
}
m_totalCharacterCount = ellipsisIndex + 1;
GenerateTextMesh();
return;
//case TextOverflowModes.Masking:
// if (!m_isMaskingEnabled)
// EnableMasking();
// break;
//case TextOverflowModes.ScrollRect:
// if (!m_isMaskingEnabled)
// EnableMasking();
// break;
case TextOverflowModes.Truncate:
if (m_isMaskingEnabled)
DisableMasking();
m_textInfo.characterInfo[m_characterCount].isVisible = false;
break;
case TextOverflowModes.Linked:
//m_textInfo.characterInfo[m_characterCount].isVisible = false;
//if (m_linkedTextComponent != null)
//{
// m_linkedTextComponent.text = text;
// m_linkedTextComponent.firstVisibleCharacter = m_characterCount;
// m_linkedTextComponent.ForceMeshUpdate();
//}
break;
}
#endregion End Text Overflow
}
#endregion End Check for Characters Exceeding Width of Text Container
// Special handling of characters that are not ignored at the end of a line.
if (charCode == 9 || charCode == 0xA0 || charCode == 0x2007)
{
m_textInfo.characterInfo[m_characterCount].isVisible = false;
m_lastVisibleCharacterOfLine = m_characterCount;
m_textInfo.lineInfo[m_lineNumber].spaceCount += 1;
m_textInfo.spaceCount += 1;
if (charCode == 0xA0)
m_textInfo.lineInfo[m_lineNumber].controlCharacterCount += 1;
}
else
{
// Determine Vertex Color
if (m_overrideHtmlColors)
vertexColor = m_fontColor32;
else
vertexColor = m_htmlColor;
// Store Character & Sprite Vertex Information
if (m_textElementType == TMP_TextElementType.Character)
{
// Save Character Vertex Data
SaveGlyphVertexInfo(padding, style_padding, vertexColor);
}
else if (m_textElementType == TMP_TextElementType.Sprite)
{
SaveSpriteVertexInfo(vertexColor);
}
}
// Increase visible count for Characters.
if (m_textInfo.characterInfo[m_characterCount].isVisible && charCode != 0xAD)
{
if (isStartOfNewLine) { isStartOfNewLine = false; m_firstVisibleCharacterOfLine = m_characterCount; }
m_lineVisibleCharacterCount += 1;
m_lastVisibleCharacterOfLine = m_characterCount;
}
}
else
{ // This is a Space, Tab, LineFeed or Carriage Return
// Track # of spaces per line which is used for line justification.
if ((charCode == 10 || char.IsSeparator((char)charCode)) && charCode != 0xAD && charCode != 0x200B && charCode != 0x2060)
{
m_textInfo.lineInfo[m_lineNumber].spaceCount += 1;
m_textInfo.spaceCount += 1;
}
}
#endregion Handle Visible Characters
// Check if Line Spacing of previous line needs to be adjusted.
#region Adjust Line Spacing
if (m_lineNumber > 0 && !TMP_Math.Approximately(m_maxLineAscender, m_startOfLineAscender) && m_lineHeight == TMP_Math.FLOAT_UNSET && !m_isNewPage)
{
//Debug.Log("Inline - Adjusting Line Spacing on line #" + m_lineNumber);
//float gap = 0; // Compute gap.
float offsetDelta = m_maxLineAscender - m_startOfLineAscender;
AdjustLineOffset(m_firstCharacterOfLine, m_characterCount, offsetDelta);
elementDescenderII -= offsetDelta;
m_lineOffset += offsetDelta;
m_startOfLineAscender += offsetDelta;
m_SavedWordWrapState.lineOffset = m_lineOffset;
m_SavedWordWrapState.previousLineAscender = m_startOfLineAscender;
}
#endregion
// Store Rectangle positions for each Character.
#region Store Character Data
m_textInfo.characterInfo[m_characterCount].lineNumber = m_lineNumber;
m_textInfo.characterInfo[m_characterCount].pageNumber = m_pageNumber;
if (charCode != 10 && charCode != 13 && charCode != 8230 || m_textInfo.lineInfo[m_lineNumber].characterCount == 1)
m_textInfo.lineInfo[m_lineNumber].alignment = m_lineJustification;
#endregion Store Character Data
// Check if text Exceeds the vertical bounds of the margin area.
#region Check Vertical Bounds & Auto-Sizing
if (m_maxAscender - elementDescenderII > marginHeight + 0.0001f)
{
// Handle Line spacing adjustments
#region Line Spacing Adjustments
if (m_enableAutoSizing && m_lineSpacingDelta > m_lineSpacingMax && m_lineNumber > 0)
{
loopCountA = 0;
m_lineSpacingDelta -= 1;
GenerateTextMesh();
return;
}
#endregion
// Handle Text Auto-sizing resulting from text exceeding vertical bounds.
#region Text Auto-Sizing (Text greater than vertical bounds)
if (m_enableAutoSizing && m_fontSize > m_fontSizeMin)
{
m_maxFontSize = m_fontSize;
m_fontSize -= Mathf.Max((m_fontSize - m_minFontSize) / 2, 0.05f);
m_fontSize = (int)(Mathf.Max(m_fontSize, m_fontSizeMin) * 20 + 0.5f) / 20f;
//m_recursiveCount = 0;
if (loopCountA > 20) return; // Added to debug
GenerateTextMesh();
return;
}
#endregion Text Auto-Sizing
// Set isTextOverflowing and firstOverflowCharacterIndex
if (m_firstOverflowCharacterIndex == -1)
m_firstOverflowCharacterIndex = m_characterCount;
// Handle Text Overflow
#region Text Overflow
switch (m_overflowMode)
{
case TextOverflowModes.Overflow:
if (m_isMaskingEnabled)
DisableMasking();
break;
case TextOverflowModes.Ellipsis:
if (m_isMaskingEnabled)
DisableMasking();
if (m_lineNumber > 0)
{
m_TextParsingBuffer[m_textInfo.characterInfo[ellipsisIndex].index].unicode = 8230;
m_TextParsingBuffer[m_textInfo.characterInfo[ellipsisIndex].index + 1].unicode = (char)0;
if (m_cached_Ellipsis_Character != null)
{
m_textInfo.characterInfo[ellipsisIndex].character = (char)8230;
m_textInfo.characterInfo[ellipsisIndex].textElement = m_cached_Ellipsis_Character;
m_textInfo.characterInfo[ellipsisIndex].fontAsset = m_materialReferences[0].fontAsset;
m_textInfo.characterInfo[ellipsisIndex].material = m_materialReferences[0].material;
m_textInfo.characterInfo[ellipsisIndex].materialReferenceIndex = 0;
}
else
{
Debug.LogWarning("Unable to use Ellipsis character since it wasn't found in the current Font Asset [" + m_fontAsset.name + "]. Consider regenerating this font asset to include the Ellipsis character (u+2026).\nNote: Warnings can be disabled in the TMP Settings file.", this);
}
m_totalCharacterCount = ellipsisIndex + 1;
GenerateTextMesh();
m_isTextTruncated = true;
return;
}
else
{
ClearMesh(false);
return;
}
//case TextOverflowModes.Masking:
// if (!m_isMaskingEnabled)
// EnableMasking();
// break;
//case TextOverflowModes.ScrollRect:
// if (!m_isMaskingEnabled)
// EnableMasking();
// break;
case TextOverflowModes.Truncate:
if (m_isMaskingEnabled)
DisableMasking();
// TODO : Optimize
if (m_lineNumber > 0)
{
m_TextParsingBuffer[m_textInfo.characterInfo[ellipsisIndex].index + 1].unicode = (char)0;
m_totalCharacterCount = ellipsisIndex + 1;
GenerateTextMesh();
m_isTextTruncated = true;
return;
}
else
{
ClearMesh(false);
return;
}
case TextOverflowModes.Page:
if (m_isMaskingEnabled)
DisableMasking();
// Ignore Page Break, Linefeed or carriage return
if (charCode == 13 || charCode == 10)
break;
// Return if the first character doesn't fit.
if (i == 0)
{
ClearMesh();
return;
}
else if (previousPageOverflowChar == i)
{
m_TextParsingBuffer[i].unicode = 0;
m_isTextTruncated = true;
}
previousPageOverflowChar = i;
// Go back to previous line and re-layout
i = RestoreWordWrappingState(ref m_SavedLineState);
m_isNewPage = true;
m_xAdvance = 0 + tag_Indent;
m_lineOffset = 0;
m_maxAscender = 0;
pageAscender = 0;
m_lineNumber += 1;
m_pageNumber += 1;
continue;
case TextOverflowModes.Linked:
if (m_linkedTextComponent != null)
{
m_linkedTextComponent.text = text;
m_linkedTextComponent.firstVisibleCharacter = m_characterCount;
m_linkedTextComponent.ForceMeshUpdate();
}
// Truncate remaining text
if (m_lineNumber > 0)
{
m_TextParsingBuffer[i].unicode = (char)0;
m_totalCharacterCount = m_characterCount;
// TODO : Optimize as we should be able to end the layout phase here without having to do another pass.
GenerateTextMesh();
m_isTextTruncated = true;
return;
}
else
{
ClearMesh(true);
return;
}
}
#endregion End Text Overflow
}
#endregion Check Vertical Bounds
// Handle xAdvance & Tabulation Stops. Tab stops at every 25% of Font Size.
#region XAdvance, Tabulation & Stops
if (charCode == 9)
{
float tabSize = m_currentFontAsset.faceInfo.tabWidth * m_currentFontAsset.tabSize * currentElementScale;
float tabs = Mathf.Ceil(m_xAdvance / tabSize) * tabSize;
m_xAdvance = tabs > m_xAdvance ? tabs : m_xAdvance + tabSize;
}
else if (m_monoSpacing != 0)
{
m_xAdvance += (m_monoSpacing - monoAdvance + ((characterSpacingAdjustment + m_currentFontAsset.normalSpacingOffset) * currentElementScale) + m_cSpacing) * (1 - m_charWidthAdjDelta);
if (char.IsWhiteSpace((char)charCode) || charCode == 0x200B)
m_xAdvance += m_wordSpacing * currentElementScale;
}
else if (!m_isRightToLeft)
{
float scaleFXMultiplier = 1;
if (m_isFXMatrixSet) scaleFXMultiplier = m_FXMatrix.lossyScale.x;
m_xAdvance += ((m_cached_TextElement.glyph.metrics.horizontalAdvance * scaleFXMultiplier * bold_xAdvance_multiplier + characterSpacingAdjustment + m_currentFontAsset.normalSpacingOffset + glyphAdjustments.xAdvance) * currentElementScale + m_cSpacing) * (1 - m_charWidthAdjDelta);
if (char.IsWhiteSpace((char)charCode) || charCode == 0x200B)
m_xAdvance += m_wordSpacing * currentElementScale;
}
else
{
m_xAdvance -= glyphAdjustments.xAdvance * currentElementScale;
}
// Store xAdvance information
m_textInfo.characterInfo[m_characterCount].xAdvance = m_xAdvance;
#endregion Tabulation & Stops
// Handle Carriage Return
#region Carriage Return
if (charCode == 13)
{
m_xAdvance = 0 + tag_Indent;
}
#endregion Carriage Return
// Handle Line Spacing Adjustments + Word Wrapping & special case for last line.
#region Check for Line Feed and Last Character
if (charCode == 10 || m_characterCount == totalCharacterCount - 1)
{
// Check if Line Spacing of previous line needs to be adjusted.
if (m_lineNumber > 0 && !TMP_Math.Approximately(m_maxLineAscender, m_startOfLineAscender) && m_lineHeight == TMP_Math.FLOAT_UNSET && !m_isNewPage)
{
//Debug.Log("Line Feed - Adjusting Line Spacing on line #" + m_lineNumber);
float offsetDelta = m_maxLineAscender - m_startOfLineAscender;
AdjustLineOffset(m_firstCharacterOfLine, m_characterCount, offsetDelta);
elementDescenderII -= offsetDelta;
m_lineOffset += offsetDelta;
}
m_isNewPage = false;
// Calculate lineAscender & make sure if last character is superscript or subscript that we check that as well.
float lineAscender = m_maxLineAscender - m_lineOffset;
float lineDescender = m_maxLineDescender - m_lineOffset;
// Update maxDescender and maxVisibleDescender
m_maxDescender = m_maxDescender < lineDescender ? m_maxDescender : lineDescender;
if (!isMaxVisibleDescenderSet)
maxVisibleDescender = m_maxDescender;
if (m_useMaxVisibleDescender && (m_characterCount >= m_maxVisibleCharacters || m_lineNumber >= m_maxVisibleLines))
isMaxVisibleDescenderSet = true;
// Save Line Information
m_textInfo.lineInfo[m_lineNumber].firstCharacterIndex = m_firstCharacterOfLine;
m_textInfo.lineInfo[m_lineNumber].firstVisibleCharacterIndex = m_firstVisibleCharacterOfLine = m_firstCharacterOfLine > m_firstVisibleCharacterOfLine ? m_firstCharacterOfLine : m_firstVisibleCharacterOfLine;
m_textInfo.lineInfo[m_lineNumber].lastCharacterIndex = m_lastCharacterOfLine = m_characterCount;
m_textInfo.lineInfo[m_lineNumber].lastVisibleCharacterIndex = m_lastVisibleCharacterOfLine = m_lastVisibleCharacterOfLine < m_firstVisibleCharacterOfLine ? m_firstVisibleCharacterOfLine : m_lastVisibleCharacterOfLine;
m_textInfo.lineInfo[m_lineNumber].characterCount = m_textInfo.lineInfo[m_lineNumber].lastCharacterIndex - m_textInfo.lineInfo[m_lineNumber].firstCharacterIndex + 1;
m_textInfo.lineInfo[m_lineNumber].visibleCharacterCount = m_lineVisibleCharacterCount;
m_textInfo.lineInfo[m_lineNumber].lineExtents.min = new Vector2(m_textInfo.characterInfo[m_firstVisibleCharacterOfLine].bottomLeft.x, lineDescender);
m_textInfo.lineInfo[m_lineNumber].lineExtents.max = new Vector2(m_textInfo.characterInfo[m_lastVisibleCharacterOfLine].topRight.x, lineAscender);
m_textInfo.lineInfo[m_lineNumber].length = m_textInfo.lineInfo[m_lineNumber].lineExtents.max.x - (padding * currentElementScale);
m_textInfo.lineInfo[m_lineNumber].width = width;
if (m_textInfo.lineInfo[m_lineNumber].characterCount == 1)
m_textInfo.lineInfo[m_lineNumber].alignment = m_lineJustification;
if (m_textInfo.characterInfo[m_lastVisibleCharacterOfLine].isVisible)
m_textInfo.lineInfo[m_lineNumber].maxAdvance = m_textInfo.characterInfo[m_lastVisibleCharacterOfLine].xAdvance - (characterSpacingAdjustment + m_currentFontAsset.normalSpacingOffset) * currentElementScale - m_cSpacing;
else
m_textInfo.lineInfo[m_lineNumber].maxAdvance = m_textInfo.characterInfo[m_lastCharacterOfLine].xAdvance - (characterSpacingAdjustment + m_currentFontAsset.normalSpacingOffset) * currentElementScale - m_cSpacing;
m_textInfo.lineInfo[m_lineNumber].baseline = 0 - m_lineOffset;
m_textInfo.lineInfo[m_lineNumber].ascender = lineAscender;
m_textInfo.lineInfo[m_lineNumber].descender = lineDescender;
m_textInfo.lineInfo[m_lineNumber].lineHeight = lineAscender - lineDescender + lineGap * baseScale;
m_firstCharacterOfLine = m_characterCount + 1;
m_lineVisibleCharacterCount = 0;
// Add new line if not last line or character.
if (charCode == 10)
{
// Store the state of the line before starting on the new line.
SaveWordWrappingState(ref m_SavedLineState, i, m_characterCount);
// Store the state of the last Character before the new line.
SaveWordWrappingState(ref m_SavedWordWrapState, i, m_characterCount);
m_lineNumber += 1;
isStartOfNewLine = true;
ignoreNonBreakingSpace = false;
isFirstWord = true;
// Check to make sure Array is large enough to hold a new line.
if (m_lineNumber >= m_textInfo.lineInfo.Length)
ResizeLineExtents(m_lineNumber);
// Apply Line Spacing
if (m_lineHeight == TMP_Math.FLOAT_UNSET)
{
lineOffsetDelta = 0 - m_maxLineDescender + elementAscender + (lineGap + m_lineSpacing + m_paragraphSpacing + m_lineSpacingDelta) * baseScale;
m_lineOffset += lineOffsetDelta;
}
else
m_lineOffset += m_lineHeight + (m_lineSpacing + m_paragraphSpacing) * baseScale;
m_maxLineAscender = k_LargeNegativeFloat;
m_maxLineDescender = k_LargePositiveFloat;
m_startOfLineAscender = elementAscender;
m_xAdvance = 0 + tag_LineIndent + tag_Indent;
ellipsisIndex = m_characterCount - 1;
m_characterCount += 1;
continue;
}
}
#endregion Check for Linefeed or Last Character
// Store Rectangle positions for each Character.
#region Save CharacterInfo for the current character.
// Determine the bounds of the Mesh.
if (m_textInfo.characterInfo[m_characterCount].isVisible)
{
m_meshExtents.min.x = Mathf.Min(m_meshExtents.min.x, m_textInfo.characterInfo[m_characterCount].bottomLeft.x);
m_meshExtents.min.y = Mathf.Min(m_meshExtents.min.y, m_textInfo.characterInfo[m_characterCount].bottomLeft.y);
m_meshExtents.max.x = Mathf.Max(m_meshExtents.max.x, m_textInfo.characterInfo[m_characterCount].topRight.x);
m_meshExtents.max.y = Mathf.Max(m_meshExtents.max.y, m_textInfo.characterInfo[m_characterCount].topRight.y);
//m_meshExtents.min = new Vector2(Mathf.Min(m_meshExtents.min.x, m_textInfo.characterInfo[m_characterCount].bottomLeft.x), Mathf.Min(m_meshExtents.min.y, m_textInfo.characterInfo[m_characterCount].bottomLeft.y));
//m_meshExtents.max = new Vector2(Mathf.Max(m_meshExtents.max.x, m_textInfo.characterInfo[m_characterCount].topRight.x), Mathf.Max(m_meshExtents.max.y, m_textInfo.characterInfo[m_characterCount].topRight.y));
}
// Save pageInfo Data
if (m_overflowMode == TextOverflowModes.Page && charCode != 13 && charCode != 10) // && m_pageNumber < 16)
{
// Check if we need to increase allocations for the pageInfo array.
if (m_pageNumber + 1 > m_textInfo.pageInfo.Length)
TMP_TextInfo.Resize(ref m_textInfo.pageInfo, m_pageNumber + 1, true);
m_textInfo.pageInfo[m_pageNumber].ascender = pageAscender;
m_textInfo.pageInfo[m_pageNumber].descender = elementDescender < m_textInfo.pageInfo[m_pageNumber].descender ? elementDescender : m_textInfo.pageInfo[m_pageNumber].descender;
if (m_pageNumber == 0 && m_characterCount == 0)
m_textInfo.pageInfo[m_pageNumber].firstCharacterIndex = m_characterCount;
else if (m_characterCount > 0 && m_pageNumber != m_textInfo.characterInfo[m_characterCount - 1].pageNumber)
{
m_textInfo.pageInfo[m_pageNumber - 1].lastCharacterIndex = m_characterCount - 1;
m_textInfo.pageInfo[m_pageNumber].firstCharacterIndex = m_characterCount;
}
else if (m_characterCount == totalCharacterCount - 1)
m_textInfo.pageInfo[m_pageNumber].lastCharacterIndex = m_characterCount;
}
#endregion Saving CharacterInfo
// Save State of Mesh Creation for handling of Word Wrapping
#region Save Word Wrapping State
if (m_enableWordWrapping || m_overflowMode == TextOverflowModes.Truncate || m_overflowMode == TextOverflowModes.Ellipsis)
{
if ((char.IsWhiteSpace((char)charCode) || charCode == 0x200B || charCode == 0x2D || charCode == 0xAD) && (!m_isNonBreakingSpace || ignoreNonBreakingSpace) && charCode != 0xA0 && charCode != 0x2007 && charCode != 0x2011 && charCode != 0x202F && charCode != 0x2060)
{
// We store the state of numerous variables for the most recent Space, LineFeed or Carriage Return to enable them to be restored
// for Word Wrapping.
SaveWordWrappingState(ref m_SavedWordWrapState, i, m_characterCount);
m_isCharacterWrappingEnabled = false;
isFirstWord = false;
}
// Handling for East Asian languages
else if (( charCode > 0x1100 && charCode < 0x11ff || /* Hangul Jamo */
charCode > 0x2E80 && charCode < 0x9FFF || /* CJK */
charCode > 0xA960 && charCode < 0xA97F || /* Hangul Jame Extended-A */
charCode > 0xAC00 && charCode < 0xD7FF || /* Hangul Syllables */
charCode > 0xF900 && charCode < 0xFAFF || /* CJK Compatibility Ideographs */
charCode > 0xFE30 && charCode < 0xFE4F || /* CJK Compatibility Forms */
charCode > 0xFF00 && charCode < 0xFFEF) /* CJK Halfwidth */
&& !m_isNonBreakingSpace)
{
if (isFirstWord || isLastBreakingChar || TMP_Settings.linebreakingRules.leadingCharacters.ContainsKey(charCode) == false &&
(m_characterCount < totalCharacterCount - 1 &&
TMP_Settings.linebreakingRules.followingCharacters.ContainsKey(m_textInfo.characterInfo[m_characterCount + 1].character) == false))
{
SaveWordWrappingState(ref m_SavedWordWrapState, i, m_characterCount);
m_isCharacterWrappingEnabled = false;
isFirstWord = false;
}
}
else if ((isFirstWord || m_isCharacterWrappingEnabled == true || isLastBreakingChar))
SaveWordWrappingState(ref m_SavedWordWrapState, i, m_characterCount);
}
#endregion Save Word Wrapping State
m_characterCount += 1;
}
// Check Auto Sizing and increase font size to fill text container.
#region Check Auto-Sizing (Upper Font Size Bounds)
fontSizeDelta = m_maxFontSize - m_minFontSize;
if (!m_isCharacterWrappingEnabled && m_enableAutoSizing && fontSizeDelta > 0.051f && m_fontSize < m_fontSizeMax)
{
m_minFontSize = m_fontSize;
m_fontSize += Mathf.Max((m_maxFontSize - m_fontSize) / 2, 0.05f);
m_fontSize = (int)(Mathf.Min(m_fontSize, m_fontSizeMax) * 20 + 0.5f) / 20f;
//Debug.Log(m_fontSize);
if (loopCountA > 20) return; // Added to debug
GenerateTextMesh();
return;
}
#endregion End Auto-sizing Check
m_isCharacterWrappingEnabled = false;
//Debug.Log("Iteration Count: " + loopCountA + ". Final Point Size: " + m_fontSize); // + " B: " + loopCountB + " C: " + loopCountC + " D: " + loopCountD);
// If there are no visible characters... no need to continue
if (m_characterCount == 0) // && m_visibleSpriteCount == 0)
{
ClearMesh(true);
// Event indicating the text has been regenerated.
TMPro_EventManager.ON_TEXT_CHANGED(this);
return;
}
// *** PHASE II of Text Generation ***
int last_vert_index = m_materialReferences[0].referenceCount * (!m_isVolumetricText ? 4 : 8);
// Partial clear of the vertices array to mark unused vertices as degenerate.
m_textInfo.meshInfo[0].Clear(false);
// Handle Text Alignment
#region Text Vertical Alignment
Vector3 anchorOffset = Vector3.zero;
Vector3[] corners = m_RectTransformCorners; // GetTextContainerLocalCorners();
// Handle Vertical Text Alignment
switch (m_textAlignment)
{
// Top Vertically
case TextAlignmentOptions.Top:
case TextAlignmentOptions.TopLeft:
case TextAlignmentOptions.TopRight:
case TextAlignmentOptions.TopJustified:
case TextAlignmentOptions.TopFlush:
case TextAlignmentOptions.TopGeoAligned:
if (m_overflowMode != TextOverflowModes.Page)
anchorOffset = corners[1] + new Vector3(0 + margins.x, 0 - m_maxAscender - margins.y, 0);
else
anchorOffset = corners[1] + new Vector3(0 + margins.x, 0 - m_textInfo.pageInfo[pageToDisplay].ascender - margins.y, 0);
break;
// Middle Vertically
case TextAlignmentOptions.Left:
case TextAlignmentOptions.Right:
case TextAlignmentOptions.Center:
case TextAlignmentOptions.Justified:
case TextAlignmentOptions.Flush:
case TextAlignmentOptions.CenterGeoAligned:
if (m_overflowMode != TextOverflowModes.Page)
anchorOffset = (corners[0] + corners[1]) / 2 + new Vector3(0 + margins.x, 0 - (m_maxAscender + margins.y + maxVisibleDescender - margins.w) / 2, 0);
else
anchorOffset = (corners[0] + corners[1]) / 2 + new Vector3(0 + margins.x, 0 - (m_textInfo.pageInfo[pageToDisplay].ascender + margins.y + m_textInfo.pageInfo[pageToDisplay].descender - margins.w) / 2, 0);
break;
// Bottom Vertically
case TextAlignmentOptions.Bottom:
case TextAlignmentOptions.BottomLeft:
case TextAlignmentOptions.BottomRight:
case TextAlignmentOptions.BottomJustified:
case TextAlignmentOptions.BottomFlush:
case TextAlignmentOptions.BottomGeoAligned:
if (m_overflowMode != TextOverflowModes.Page)
anchorOffset = corners[0] + new Vector3(0 + margins.x, 0 - maxVisibleDescender + margins.w, 0);
else
anchorOffset = corners[0] + new Vector3(0 + margins.x, 0 - m_textInfo.pageInfo[pageToDisplay].descender + margins.w, 0);
break;
// Baseline Vertically
case TextAlignmentOptions.Baseline:
case TextAlignmentOptions.BaselineLeft:
case TextAlignmentOptions.BaselineRight:
case TextAlignmentOptions.BaselineJustified:
case TextAlignmentOptions.BaselineFlush:
case TextAlignmentOptions.BaselineGeoAligned:
anchorOffset = (corners[0] + corners[1]) / 2 + new Vector3(0 + margins.x, 0, 0);
break;
// Midline Vertically
case TextAlignmentOptions.MidlineLeft:
case TextAlignmentOptions.Midline:
case TextAlignmentOptions.MidlineRight:
case TextAlignmentOptions.MidlineJustified:
case TextAlignmentOptions.MidlineFlush:
case TextAlignmentOptions.MidlineGeoAligned:
anchorOffset = (corners[0] + corners[1]) / 2 + new Vector3(0 + margins.x, 0 - (m_meshExtents.max.y + margins.y + m_meshExtents.min.y - margins.w) / 2, 0);
break;
// Capline Vertically
case TextAlignmentOptions.CaplineLeft:
case TextAlignmentOptions.Capline:
case TextAlignmentOptions.CaplineRight:
case TextAlignmentOptions.CaplineJustified:
case TextAlignmentOptions.CaplineFlush:
case TextAlignmentOptions.CaplineGeoAligned:
anchorOffset = (corners[0] + corners[1]) / 2 + new Vector3(0 + margins.x, 0 - (m_maxCapHeight - margins.y - margins.w) / 2, 0);
break;
}
#endregion
// Initialization for Second Pass
Vector3 justificationOffset = Vector3.zero;
Vector3 offset = Vector3.zero;
int vert_index_X4 = 0;
int sprite_index_X4 = 0;
int wordCount = 0;
int lineCount = 0;
int lastLine = 0;
bool isFirstSeperator = false;
bool isStartOfWord = false;
int wordFirstChar = 0;
int wordLastChar = 0;
// Second Pass : Line Justification, UV Mapping, Character & Line Visibility & more.
float lossyScale = m_previousLossyScaleY = this.transform.lossyScale.y;
Color32 underlineColor = Color.white;
Color32 strikethroughColor = Color.white;
Color32 highlightColor = new Color32(255, 255, 0, 64);
float xScale = 0;
float xScaleMax = 0;
float underlineStartScale = 0;
float underlineEndScale = 0;
float underlineMaxScale = 0;
float underlineBaseLine = k_LargePositiveFloat;
int lastPage = 0;
float strikethroughPointSize = 0;
float strikethroughScale = 0;
float strikethroughBaseline = 0;
TMP_CharacterInfo[] characterInfos = m_textInfo.characterInfo;
#region Handle Line Justification & UV Mapping & Character Visibility & More
for (int i = 0; i < m_characterCount; i++)
{
TMP_FontAsset currentFontAsset = characterInfos[i].fontAsset;
char currentCharacter = characterInfos[i].character;
int currentLine = characterInfos[i].lineNumber;
TMP_LineInfo lineInfo = m_textInfo.lineInfo[currentLine];
lineCount = currentLine + 1;
TextAlignmentOptions lineAlignment = lineInfo.alignment;
// Process Line Justification
#region Handle Line Justification
switch (lineAlignment)
{
case TextAlignmentOptions.TopLeft:
case TextAlignmentOptions.Left:
case TextAlignmentOptions.BottomLeft:
case TextAlignmentOptions.BaselineLeft:
case TextAlignmentOptions.MidlineLeft:
case TextAlignmentOptions.CaplineLeft:
if (!m_isRightToLeft)
justificationOffset = new Vector3(0 + lineInfo.marginLeft, 0, 0);
else
justificationOffset = new Vector3(0 - lineInfo.maxAdvance, 0, 0);
break;
case TextAlignmentOptions.Top:
case TextAlignmentOptions.Center:
case TextAlignmentOptions.Bottom:
case TextAlignmentOptions.Baseline:
case TextAlignmentOptions.Midline:
case TextAlignmentOptions.Capline:
justificationOffset = new Vector3(lineInfo.marginLeft + lineInfo.width / 2 - lineInfo.maxAdvance / 2, 0, 0);
break;
case TextAlignmentOptions.TopGeoAligned:
case TextAlignmentOptions.CenterGeoAligned:
case TextAlignmentOptions.BottomGeoAligned:
case TextAlignmentOptions.BaselineGeoAligned:
case TextAlignmentOptions.MidlineGeoAligned:
case TextAlignmentOptions.CaplineGeoAligned:
justificationOffset = new Vector3(lineInfo.marginLeft + lineInfo.width / 2 - (lineInfo.lineExtents.min.x + lineInfo.lineExtents.max.x) / 2, 0, 0);
break;
case TextAlignmentOptions.TopRight:
case TextAlignmentOptions.Right:
case TextAlignmentOptions.BottomRight:
case TextAlignmentOptions.BaselineRight:
case TextAlignmentOptions.MidlineRight:
case TextAlignmentOptions.CaplineRight:
if (!m_isRightToLeft)
justificationOffset = new Vector3(lineInfo.marginLeft + lineInfo.width - lineInfo.maxAdvance, 0, 0);
else
justificationOffset = new Vector3(lineInfo.marginLeft + lineInfo.width, 0, 0);
break;
case TextAlignmentOptions.TopJustified:
case TextAlignmentOptions.Justified:
case TextAlignmentOptions.BottomJustified:
case TextAlignmentOptions.BaselineJustified:
case TextAlignmentOptions.MidlineJustified:
case TextAlignmentOptions.CaplineJustified:
case TextAlignmentOptions.TopFlush:
case TextAlignmentOptions.Flush:
case TextAlignmentOptions.BottomFlush:
case TextAlignmentOptions.BaselineFlush:
case TextAlignmentOptions.MidlineFlush:
case TextAlignmentOptions.CaplineFlush:
// Skip Zero Width Characters
if (currentCharacter == 0xAD || currentCharacter == 0x200B || currentCharacter == 0x2060) break;
char lastCharOfCurrentLine = characterInfos[lineInfo.lastCharacterIndex].character;
bool isFlush = ((_HorizontalAlignmentOptions)lineAlignment & _HorizontalAlignmentOptions.Flush) == _HorizontalAlignmentOptions.Flush;
// In Justified mode, all lines are justified except the last one.
// In Flush mode, all lines are justified.
if (char.IsControl(lastCharOfCurrentLine) == false && currentLine < m_lineNumber || isFlush || lineInfo.maxAdvance > lineInfo.width)
{
// First character of each line.
if (currentLine != lastLine || i == 0 || i == m_firstVisibleCharacter)
{
if (!m_isRightToLeft)
justificationOffset = new Vector3(lineInfo.marginLeft, 0, 0);
else
justificationOffset = new Vector3(lineInfo.marginLeft + lineInfo.width, 0, 0);
if (char.IsSeparator(currentCharacter))
isFirstSeperator = true;
else
isFirstSeperator = false;
}
else
{
float gap = !m_isRightToLeft ? lineInfo.width - lineInfo.maxAdvance : lineInfo.width + lineInfo.maxAdvance;
int visibleCount = lineInfo.visibleCharacterCount - 1 + lineInfo.controlCharacterCount;
// Get the number of spaces for each line ignoring the last character if it is not visible (ie. a space or linefeed).
int spaces = (characterInfos[lineInfo.lastCharacterIndex].isVisible ? lineInfo.spaceCount : lineInfo.spaceCount - 1) - lineInfo.controlCharacterCount;
if (isFirstSeperator) { spaces -= 1; visibleCount += 1; }
float ratio = spaces > 0 ? m_wordWrappingRatios : 1;
if (spaces < 1) spaces = 1;
if (currentCharacter != 0xA0 && (currentCharacter == 9 || char.IsSeparator((char)currentCharacter)))
{
if (!m_isRightToLeft)
justificationOffset += new Vector3(gap * (1 - ratio) / spaces, 0, 0);
else
justificationOffset -= new Vector3(gap * (1 - ratio) / spaces, 0, 0);
}
else
{
if (!m_isRightToLeft)
justificationOffset += new Vector3(gap * ratio / visibleCount, 0, 0);
else
justificationOffset -= new Vector3(gap * ratio / visibleCount, 0, 0);
}
}
}
else
{
if (!m_isRightToLeft)
justificationOffset = new Vector3(lineInfo.marginLeft, 0, 0); // Keep last line left justified.
else
justificationOffset = new Vector3(lineInfo.marginLeft + lineInfo.width, 0, 0); // Keep last line right justified.
}
//Debug.Log("Char [" + (char)charCode + "] Code:" + charCode + " Line # " + currentLine + " Offset:" + justificationOffset + " # Spaces:" + lineInfo.spaceCount + " # Characters:" + lineInfo.characterCount);
break;
}
#endregion End Text Justification
offset = anchorOffset + justificationOffset;
// Handle UV2 mapping options and packing of scale information into UV2.
#region Handling of UV2 mapping & Scale packing
bool isCharacterVisible = characterInfos[i].isVisible;
if (isCharacterVisible)
{
TMP_TextElementType elementType = characterInfos[i].elementType;
switch (elementType)
{
// CHARACTERS
case TMP_TextElementType.Character:
Extents lineExtents = lineInfo.lineExtents;
float uvOffset = (m_uvLineOffset * currentLine) % 1; // + m_uvOffset.x;
// Setup UV2 based on Character Mapping Options Selected
#region Handle UV Mapping Options
switch (m_horizontalMapping)
{
case TextureMappingOptions.Character:
characterInfos[i].vertex_BL.uv2.x = 0; //+ m_uvOffset.x;
characterInfos[i].vertex_TL.uv2.x = 0; //+ m_uvOffset.x;
characterInfos[i].vertex_TR.uv2.x = 1; //+ m_uvOffset.x;
characterInfos[i].vertex_BR.uv2.x = 1; //+ m_uvOffset.x;
break;
case TextureMappingOptions.Line:
if (m_textAlignment != TextAlignmentOptions.Justified)
{
characterInfos[i].vertex_BL.uv2.x = (characterInfos[i].vertex_BL.position.x - lineExtents.min.x) / (lineExtents.max.x - lineExtents.min.x) + uvOffset;
characterInfos[i].vertex_TL.uv2.x = (characterInfos[i].vertex_TL.position.x - lineExtents.min.x) / (lineExtents.max.x - lineExtents.min.x) + uvOffset;
characterInfos[i].vertex_TR.uv2.x = (characterInfos[i].vertex_TR.position.x - lineExtents.min.x) / (lineExtents.max.x - lineExtents.min.x) + uvOffset;
characterInfos[i].vertex_BR.uv2.x = (characterInfos[i].vertex_BR.position.x - lineExtents.min.x) / (lineExtents.max.x - lineExtents.min.x) + uvOffset;
break;
}
else // Special Case if Justified is used in Line Mode.
{
characterInfos[i].vertex_BL.uv2.x = (characterInfos[i].vertex_BL.position.x + justificationOffset.x - m_meshExtents.min.x) / (m_meshExtents.max.x - m_meshExtents.min.x) + uvOffset;
characterInfos[i].vertex_TL.uv2.x = (characterInfos[i].vertex_TL.position.x + justificationOffset.x - m_meshExtents.min.x) / (m_meshExtents.max.x - m_meshExtents.min.x) + uvOffset;
characterInfos[i].vertex_TR.uv2.x = (characterInfos[i].vertex_TR.position.x + justificationOffset.x - m_meshExtents.min.x) / (m_meshExtents.max.x - m_meshExtents.min.x) + uvOffset;
characterInfos[i].vertex_BR.uv2.x = (characterInfos[i].vertex_BR.position.x + justificationOffset.x - m_meshExtents.min.x) / (m_meshExtents.max.x - m_meshExtents.min.x) + uvOffset;
break;
}
case TextureMappingOptions.Paragraph:
characterInfos[i].vertex_BL.uv2.x = (characterInfos[i].vertex_BL.position.x + justificationOffset.x - m_meshExtents.min.x) / (m_meshExtents.max.x - m_meshExtents.min.x) + uvOffset;
characterInfos[i].vertex_TL.uv2.x = (characterInfos[i].vertex_TL.position.x + justificationOffset.x - m_meshExtents.min.x) / (m_meshExtents.max.x - m_meshExtents.min.x) + uvOffset;
characterInfos[i].vertex_TR.uv2.x = (characterInfos[i].vertex_TR.position.x + justificationOffset.x - m_meshExtents.min.x) / (m_meshExtents.max.x - m_meshExtents.min.x) + uvOffset;
characterInfos[i].vertex_BR.uv2.x = (characterInfos[i].vertex_BR.position.x + justificationOffset.x - m_meshExtents.min.x) / (m_meshExtents.max.x - m_meshExtents.min.x) + uvOffset;
break;
case TextureMappingOptions.MatchAspect:
switch (m_verticalMapping)
{
case TextureMappingOptions.Character:
characterInfos[i].vertex_BL.uv2.y = 0; //+ m_uvOffset.y;
characterInfos[i].vertex_TL.uv2.y = 1; //+ m_uvOffset.y;
characterInfos[i].vertex_TR.uv2.y = 0; //+ m_uvOffset.y;
characterInfos[i].vertex_BR.uv2.y = 1; //+ m_uvOffset.y;
break;
case TextureMappingOptions.Line:
characterInfos[i].vertex_BL.uv2.y = (characterInfos[i].vertex_BL.position.y - lineExtents.min.y) / (lineExtents.max.y - lineExtents.min.y) + uvOffset;
characterInfos[i].vertex_TL.uv2.y = (characterInfos[i].vertex_TL.position.y - lineExtents.min.y) / (lineExtents.max.y - lineExtents.min.y) + uvOffset;
characterInfos[i].vertex_TR.uv2.y = characterInfos[i].vertex_BL.uv2.y;
characterInfos[i].vertex_BR.uv2.y = characterInfos[i].vertex_TL.uv2.y;
break;
case TextureMappingOptions.Paragraph:
characterInfos[i].vertex_BL.uv2.y = (characterInfos[i].vertex_BL.position.y - m_meshExtents.min.y) / (m_meshExtents.max.y - m_meshExtents.min.y) + uvOffset;
characterInfos[i].vertex_TL.uv2.y = (characterInfos[i].vertex_TL.position.y - m_meshExtents.min.y) / (m_meshExtents.max.y - m_meshExtents.min.y) + uvOffset;
characterInfos[i].vertex_TR.uv2.y = characterInfos[i].vertex_BL.uv2.y;
characterInfos[i].vertex_BR.uv2.y = characterInfos[i].vertex_TL.uv2.y;
break;
case TextureMappingOptions.MatchAspect:
Debug.Log("ERROR: Cannot Match both Vertical & Horizontal.");
break;
}
//float xDelta = 1 - (_uv2s[vert_index + 0].y * textMeshCharacterInfo[i].AspectRatio); // Left aligned
float xDelta = (1 - ((characterInfos[i].vertex_BL.uv2.y + characterInfos[i].vertex_TL.uv2.y) * characterInfos[i].aspectRatio)) / 2; // Center of Rectangle
characterInfos[i].vertex_BL.uv2.x = (characterInfos[i].vertex_BL.uv2.y * characterInfos[i].aspectRatio) + xDelta + uvOffset;
characterInfos[i].vertex_TL.uv2.x = characterInfos[i].vertex_BL.uv2.x;
characterInfos[i].vertex_TR.uv2.x = (characterInfos[i].vertex_TL.uv2.y * characterInfos[i].aspectRatio) + xDelta + uvOffset;
characterInfos[i].vertex_BR.uv2.x = characterInfos[i].vertex_TR.uv2.x;
break;
}
switch (m_verticalMapping)
{
case TextureMappingOptions.Character:
characterInfos[i].vertex_BL.uv2.y = 0; //+ m_uvOffset.y;
characterInfos[i].vertex_TL.uv2.y = 1; //+ m_uvOffset.y;
characterInfos[i].vertex_TR.uv2.y = 1; //+ m_uvOffset.y;
characterInfos[i].vertex_BR.uv2.y = 0; //+ m_uvOffset.y;
break;
case TextureMappingOptions.Line:
characterInfos[i].vertex_BL.uv2.y = (characterInfos[i].vertex_BL.position.y - lineInfo.descender) / (lineInfo.ascender - lineInfo.descender); // + m_uvOffset.y;
characterInfos[i].vertex_TL.uv2.y = (characterInfos[i].vertex_TL.position.y - lineInfo.descender) / (lineInfo.ascender - lineInfo.descender); // + m_uvOffset.y;
characterInfos[i].vertex_TR.uv2.y = characterInfos[i].vertex_TL.uv2.y;
characterInfos[i].vertex_BR.uv2.y = characterInfos[i].vertex_BL.uv2.y;
break;
case TextureMappingOptions.Paragraph:
characterInfos[i].vertex_BL.uv2.y = (characterInfos[i].vertex_BL.position.y - m_meshExtents.min.y) / (m_meshExtents.max.y - m_meshExtents.min.y); // + m_uvOffset.y;
characterInfos[i].vertex_TL.uv2.y = (characterInfos[i].vertex_TL.position.y - m_meshExtents.min.y) / (m_meshExtents.max.y - m_meshExtents.min.y); // + m_uvOffset.y;
characterInfos[i].vertex_TR.uv2.y = characterInfos[i].vertex_TL.uv2.y;
characterInfos[i].vertex_BR.uv2.y = characterInfos[i].vertex_BL.uv2.y;
break;
case TextureMappingOptions.MatchAspect:
float yDelta = (1 - ((characterInfos[i].vertex_BL.uv2.x + characterInfos[i].vertex_TR.uv2.x) / characterInfos[i].aspectRatio)) / 2; // Center of Rectangle
characterInfos[i].vertex_BL.uv2.y = yDelta + (characterInfos[i].vertex_BL.uv2.x / characterInfos[i].aspectRatio); // + m_uvOffset.y;
characterInfos[i].vertex_TL.uv2.y = yDelta + (characterInfos[i].vertex_TR.uv2.x / characterInfos[i].aspectRatio); // + m_uvOffset.y;
characterInfos[i].vertex_BR.uv2.y = characterInfos[i].vertex_BL.uv2.y;
characterInfos[i].vertex_TR.uv2.y = characterInfos[i].vertex_TL.uv2.y;
break;
}
#endregion
// Pack UV's so that we can pass Xscale needed for Shader to maintain 1:1 ratio.
#region Pack Scale into UV2
xScale = characterInfos[i].scale * Mathf.Abs(lossyScale) * (1 - m_charWidthAdjDelta);
if (!characterInfos[i].isUsingAlternateTypeface && (characterInfos[i].style & FontStyles.Bold) == FontStyles.Bold) xScale *= -1;
//int isBold = (m_textInfo.characterInfo[i].style & FontStyles.Bold) == FontStyles.Bold ? 1 : 0;
//Vector2 vertexData = new Vector2(isBold, xScale);
//characterInfos[i].vertex_BL.uv4 = vertexData;
//characterInfos[i].vertex_TL.uv4 = vertexData;
//characterInfos[i].vertex_TR.uv4 = vertexData;
//characterInfos[i].vertex_BR.uv4 = vertexData;
float x0 = characterInfos[i].vertex_BL.uv2.x;
float y0 = characterInfos[i].vertex_BL.uv2.y;
float x1 = characterInfos[i].vertex_TR.uv2.x;
float y1 = characterInfos[i].vertex_TR.uv2.y;
float dx = (int)x0;
float dy = (int)y0;
x0 = x0 - dx;
x1 = x1 - dx;
y0 = y0 - dy;
y1 = y1 - dy;
// Optimization to avoid having a vector2 returned from the Pack UV function.
characterInfos[i].vertex_BL.uv2.x = PackUV(x0, y0); characterInfos[i].vertex_BL.uv2.y = xScale;
characterInfos[i].vertex_TL.uv2.x = PackUV(x0, y1); characterInfos[i].vertex_TL.uv2.y = xScale;
characterInfos[i].vertex_TR.uv2.x = PackUV(x1, y1); characterInfos[i].vertex_TR.uv2.y = xScale;
characterInfos[i].vertex_BR.uv2.x = PackUV(x1, y0); characterInfos[i].vertex_BR.uv2.y = xScale;
#endregion
break;
// SPRITES
case TMP_TextElementType.Sprite:
// Nothing right now
break;
}
// Handle maxVisibleCharacters, maxVisibleLines and Overflow Page Mode.
#region Handle maxVisibleCharacters / maxVisibleLines / Page Mode
if (i < m_maxVisibleCharacters && wordCount < m_maxVisibleWords && currentLine < m_maxVisibleLines && m_overflowMode != TextOverflowModes.Page)
{
characterInfos[i].vertex_BL.position += offset;
characterInfos[i].vertex_TL.position += offset;
characterInfos[i].vertex_TR.position += offset;
characterInfos[i].vertex_BR.position += offset;
}
else if (i < m_maxVisibleCharacters && wordCount < m_maxVisibleWords && currentLine < m_maxVisibleLines && m_overflowMode == TextOverflowModes.Page && characterInfos[i].pageNumber == pageToDisplay)
{
characterInfos[i].vertex_BL.position += offset;
characterInfos[i].vertex_TL.position += offset;
characterInfos[i].vertex_TR.position += offset;
characterInfos[i].vertex_BR.position += offset;
}
else
{
characterInfos[i].vertex_BL.position = Vector3.zero;
characterInfos[i].vertex_TL.position = Vector3.zero;
characterInfos[i].vertex_TR.position = Vector3.zero;
characterInfos[i].vertex_BR.position = Vector3.zero;
characterInfos[i].isVisible = false;
}
#endregion
// Fill Vertex Buffers for the various types of element
if (elementType == TMP_TextElementType.Character)
{
FillCharacterVertexBuffers(i, vert_index_X4, m_isVolumetricText);
}
else if (elementType == TMP_TextElementType.Sprite)
{
FillSpriteVertexBuffers(i, sprite_index_X4);
}
}
#endregion
// Apply Alignment and Justification Offset
m_textInfo.characterInfo[i].bottomLeft += offset;
m_textInfo.characterInfo[i].topLeft += offset;
m_textInfo.characterInfo[i].topRight += offset;
m_textInfo.characterInfo[i].bottomRight += offset;
m_textInfo.characterInfo[i].origin += offset.x;
m_textInfo.characterInfo[i].xAdvance += offset.x;
m_textInfo.characterInfo[i].ascender += offset.y;
m_textInfo.characterInfo[i].descender += offset.y;
m_textInfo.characterInfo[i].baseLine += offset.y;
// Update MeshExtents
if (isCharacterVisible)
{
//m_meshExtents.min = new Vector2(Mathf.Min(m_meshExtents.min.x, m_textInfo.characterInfo[i].bottomLeft.x), Mathf.Min(m_meshExtents.min.y, m_textInfo.characterInfo[i].bottomLeft.y));
//m_meshExtents.max = new Vector2(Mathf.Max(m_meshExtents.max.x, m_textInfo.characterInfo[i].topRight.x), Mathf.Max(m_meshExtents.max.y, m_textInfo.characterInfo[i].topLeft.y));
}
// Need to recompute lineExtent to account for the offset from justification.
#region Adjust lineExtents resulting from alignment offset
if (currentLine != lastLine || i == m_characterCount - 1)
{
// Update the previous line's extents
if (currentLine != lastLine)
{
m_textInfo.lineInfo[lastLine].baseline += offset.y;
m_textInfo.lineInfo[lastLine].ascender += offset.y;
m_textInfo.lineInfo[lastLine].descender += offset.y;
m_textInfo.lineInfo[lastLine].lineExtents.min = new Vector2(m_textInfo.characterInfo[m_textInfo.lineInfo[lastLine].firstCharacterIndex].bottomLeft.x, m_textInfo.lineInfo[lastLine].descender);
m_textInfo.lineInfo[lastLine].lineExtents.max = new Vector2(m_textInfo.characterInfo[m_textInfo.lineInfo[lastLine].lastVisibleCharacterIndex].topRight.x, m_textInfo.lineInfo[lastLine].ascender);
}
// Update the current line's extents
if (i == m_characterCount - 1)
{
m_textInfo.lineInfo[currentLine].baseline += offset.y;
m_textInfo.lineInfo[currentLine].ascender += offset.y;
m_textInfo.lineInfo[currentLine].descender += offset.y;
m_textInfo.lineInfo[currentLine].lineExtents.min = new Vector2(m_textInfo.characterInfo[m_textInfo.lineInfo[currentLine].firstCharacterIndex].bottomLeft.x, m_textInfo.lineInfo[currentLine].descender);
m_textInfo.lineInfo[currentLine].lineExtents.max = new Vector2(m_textInfo.characterInfo[m_textInfo.lineInfo[currentLine].lastVisibleCharacterIndex].topRight.x, m_textInfo.lineInfo[currentLine].ascender);
}
}
#endregion
// Track Word Count per line and for the object
#region Track Word Count
if (char.IsLetterOrDigit(currentCharacter) || currentCharacter == 0x2D || currentCharacter == 0xAD || currentCharacter == 0x2010 || currentCharacter == 0x2011)
{
if (isStartOfWord == false)
{
isStartOfWord = true;
wordFirstChar = i;
}
// If last character is a word
if (isStartOfWord && i == m_characterCount - 1)
{
int size = m_textInfo.wordInfo.Length;
int index = m_textInfo.wordCount;
if (m_textInfo.wordCount + 1 > size)
TMP_TextInfo.Resize(ref m_textInfo.wordInfo, size + 1);
wordLastChar = i;
m_textInfo.wordInfo[index].firstCharacterIndex = wordFirstChar;
m_textInfo.wordInfo[index].lastCharacterIndex = wordLastChar;
m_textInfo.wordInfo[index].characterCount = wordLastChar - wordFirstChar + 1;
m_textInfo.wordInfo[index].textComponent = this;
wordCount += 1;
m_textInfo.wordCount += 1;
m_textInfo.lineInfo[currentLine].wordCount += 1;
}
}
else if (isStartOfWord || i == 0 && (!char.IsPunctuation(currentCharacter) || char.IsWhiteSpace(currentCharacter) || currentCharacter == 0x200B || i == m_characterCount - 1))
{
if (i > 0 && i < characterInfos.Length - 1 && i < m_characterCount && (currentCharacter == 39 || currentCharacter == 8217) && char.IsLetterOrDigit(characterInfos[i - 1].character) && char.IsLetterOrDigit(characterInfos[i + 1].character))
{
}
else
{
wordLastChar = i == m_characterCount - 1 && char.IsLetterOrDigit(currentCharacter) ? i : i - 1;
isStartOfWord = false;
int size = m_textInfo.wordInfo.Length;
int index = m_textInfo.wordCount;
if (m_textInfo.wordCount + 1 > size)
TMP_TextInfo.Resize(ref m_textInfo.wordInfo, size + 1);
m_textInfo.wordInfo[index].firstCharacterIndex = wordFirstChar;
m_textInfo.wordInfo[index].lastCharacterIndex = wordLastChar;
m_textInfo.wordInfo[index].characterCount = wordLastChar - wordFirstChar + 1;
m_textInfo.wordInfo[index].textComponent = this;
wordCount += 1;
m_textInfo.wordCount += 1;
m_textInfo.lineInfo[currentLine].wordCount += 1;
}
}
#endregion
// Setup & Handle Underline
#region Underline
// NOTE: Need to figure out how underline will be handled with multiple fonts and which font will be used for the underline.
bool isUnderline = (m_textInfo.characterInfo[i].style & FontStyles.Underline) == FontStyles.Underline;
if (isUnderline)
{
bool isUnderlineVisible = true;
int currentPage = m_textInfo.characterInfo[i].pageNumber;
if (i > m_maxVisibleCharacters || currentLine > m_maxVisibleLines || (m_overflowMode == TextOverflowModes.Page && currentPage + 1 != m_pageToDisplay))
isUnderlineVisible = false;
// We only use the scale of visible characters.
if (!char.IsWhiteSpace(currentCharacter) && currentCharacter != 0x200B)
{
underlineMaxScale = Mathf.Max(underlineMaxScale, m_textInfo.characterInfo[i].scale);
xScaleMax = Mathf.Max(xScaleMax, Mathf.Abs(xScale));
underlineBaseLine = Mathf.Min(currentPage == lastPage ? underlineBaseLine : k_LargePositiveFloat, m_textInfo.characterInfo[i].baseLine + font.faceInfo.underlineOffset * underlineMaxScale);
lastPage = currentPage; // Need to track pages to ensure we reset baseline for the new pages.
}
if (beginUnderline == false && isUnderlineVisible == true && i <= lineInfo.lastVisibleCharacterIndex && currentCharacter != 10 && currentCharacter != 13)
{
if (i == lineInfo.lastVisibleCharacterIndex && char.IsSeparator(currentCharacter))
{ }
else
{
beginUnderline = true;
underlineStartScale = m_textInfo.characterInfo[i].scale;
if (underlineMaxScale == 0)
{
underlineMaxScale = underlineStartScale;
xScaleMax = xScale;
}
underline_start = new Vector3(m_textInfo.characterInfo[i].bottomLeft.x, underlineBaseLine, 0);
underlineColor = m_textInfo.characterInfo[i].underlineColor;
}
}
// End Underline if text only contains one character.
if (beginUnderline && m_characterCount == 1)
{
beginUnderline = false;
underline_end = new Vector3(m_textInfo.characterInfo[i].topRight.x, underlineBaseLine, 0);
underlineEndScale = m_textInfo.characterInfo[i].scale;
DrawUnderlineMesh(underline_start, underline_end, ref last_vert_index, underlineStartScale, underlineEndScale, underlineMaxScale, xScaleMax, underlineColor);
underlineMaxScale = 0;
xScaleMax = 0;
underlineBaseLine = k_LargePositiveFloat;
}
else if (beginUnderline && (i == lineInfo.lastCharacterIndex || i >= lineInfo.lastVisibleCharacterIndex))
{
// Terminate underline at previous visible character if space or carriage return.
if (char.IsWhiteSpace(currentCharacter) || currentCharacter == 0x200B)
{
int lastVisibleCharacterIndex = lineInfo.lastVisibleCharacterIndex;
underline_end = new Vector3(m_textInfo.characterInfo[lastVisibleCharacterIndex].topRight.x, underlineBaseLine, 0);
underlineEndScale = m_textInfo.characterInfo[lastVisibleCharacterIndex].scale;
}
else
{ // End underline if last character of the line.
underline_end = new Vector3(m_textInfo.characterInfo[i].topRight.x, underlineBaseLine, 0);
underlineEndScale = m_textInfo.characterInfo[i].scale;
}
beginUnderline = false;
DrawUnderlineMesh(underline_start, underline_end, ref last_vert_index, underlineStartScale, underlineEndScale, underlineMaxScale, xScaleMax, underlineColor);
underlineMaxScale = 0;
xScaleMax = 0;
underlineBaseLine = k_LargePositiveFloat;
}
else if (beginUnderline && !isUnderlineVisible)
{
beginUnderline = false;
underline_end = new Vector3(m_textInfo.characterInfo[i - 1].topRight.x, underlineBaseLine, 0);
underlineEndScale = m_textInfo.characterInfo[i - 1].scale;
DrawUnderlineMesh(underline_start, underline_end, ref last_vert_index, underlineStartScale, underlineEndScale, underlineMaxScale, xScaleMax, underlineColor);
underlineMaxScale = 0;
xScaleMax = 0;
underlineBaseLine = k_LargePositiveFloat;
}
else if (beginUnderline && i < m_characterCount - 1 && !underlineColor.Compare(m_textInfo.characterInfo[i + 1].underlineColor))
{
// End underline if underline color has changed.
beginUnderline = false;
underline_end = new Vector3(m_textInfo.characterInfo[i].topRight.x, underlineBaseLine, 0);
underlineEndScale = m_textInfo.characterInfo[i].scale;
DrawUnderlineMesh(underline_start, underline_end, ref last_vert_index, underlineStartScale, underlineEndScale, underlineMaxScale, xScaleMax, underlineColor);
underlineMaxScale = 0;
xScaleMax = 0;
underlineBaseLine = k_LargePositiveFloat;
}
}
else
{
// End Underline
if (beginUnderline == true)
{
beginUnderline = false;
underline_end = new Vector3(m_textInfo.characterInfo[i - 1].topRight.x, underlineBaseLine, 0);
underlineEndScale = m_textInfo.characterInfo[i - 1].scale;
DrawUnderlineMesh(underline_start, underline_end, ref last_vert_index, underlineStartScale, underlineEndScale, underlineMaxScale, xScaleMax, underlineColor);
underlineMaxScale = 0;
xScaleMax = 0;
underlineBaseLine = k_LargePositiveFloat;
}
}
#endregion
// Setup & Handle Strikethrough
#region Strikethrough
// NOTE: Need to figure out how underline will be handled with multiple fonts and which font will be used for the underline.
bool isStrikethrough = (m_textInfo.characterInfo[i].style & FontStyles.Strikethrough) == FontStyles.Strikethrough;
float strikethroughOffset = currentFontAsset.faceInfo.strikethroughOffset;
if (isStrikethrough)
{
bool isStrikeThroughVisible = true;
if (i > m_maxVisibleCharacters || currentLine > m_maxVisibleLines || (m_overflowMode == TextOverflowModes.Page && m_textInfo.characterInfo[i].pageNumber + 1 != m_pageToDisplay))
isStrikeThroughVisible = false;
if (beginStrikethrough == false && isStrikeThroughVisible && i <= lineInfo.lastVisibleCharacterIndex && currentCharacter != 10 && currentCharacter != 13)
{
if (i == lineInfo.lastVisibleCharacterIndex && char.IsSeparator(currentCharacter))
{ }
else
{
beginStrikethrough = true;
strikethroughPointSize = m_textInfo.characterInfo[i].pointSize;
strikethroughScale = m_textInfo.characterInfo[i].scale;
strikethrough_start = new Vector3(m_textInfo.characterInfo[i].bottomLeft.x, m_textInfo.characterInfo[i].baseLine + strikethroughOffset * strikethroughScale, 0);
strikethroughColor = m_textInfo.characterInfo[i].strikethroughColor;
strikethroughBaseline = m_textInfo.characterInfo[i].baseLine;
//Debug.Log("Char [" + currentCharacter + "] Start Strikethrough POS: " + strikethrough_start);
}
}
// End Strikethrough if text only contains one character.
if (beginStrikethrough && m_characterCount == 1)
{
beginStrikethrough = false;
strikethrough_end = new Vector3(m_textInfo.characterInfo[i].topRight.x, m_textInfo.characterInfo[i].baseLine + strikethroughOffset * strikethroughScale, 0);
DrawUnderlineMesh(strikethrough_start, strikethrough_end, ref last_vert_index, strikethroughScale, strikethroughScale, strikethroughScale, xScale, strikethroughColor);
}
else if (beginStrikethrough && i == lineInfo.lastCharacterIndex)
{
// Terminate Strikethrough at previous visible character if space or carriage return.
if (char.IsWhiteSpace(currentCharacter) || currentCharacter == 0x200B)
{
int lastVisibleCharacterIndex = lineInfo.lastVisibleCharacterIndex;
strikethrough_end = new Vector3(m_textInfo.characterInfo[lastVisibleCharacterIndex].topRight.x, m_textInfo.characterInfo[lastVisibleCharacterIndex].baseLine + strikethroughOffset * strikethroughScale, 0);
}
else
{
// Terminate Strikethrough at last character of line.
strikethrough_end = new Vector3(m_textInfo.characterInfo[i].topRight.x, m_textInfo.characterInfo[i].baseLine + strikethroughOffset * strikethroughScale, 0);
}
beginStrikethrough = false;
DrawUnderlineMesh(strikethrough_start, strikethrough_end, ref last_vert_index, strikethroughScale, strikethroughScale, strikethroughScale, xScale, strikethroughColor);
}
else if (beginStrikethrough && i < m_characterCount && (m_textInfo.characterInfo[i + 1].pointSize != strikethroughPointSize || !TMP_Math.Approximately(m_textInfo.characterInfo[i + 1].baseLine + offset.y, strikethroughBaseline)))
{
// Terminate Strikethrough if scale changes.
beginStrikethrough = false;
int lastVisibleCharacterIndex = lineInfo.lastVisibleCharacterIndex;
if (i > lastVisibleCharacterIndex)
strikethrough_end = new Vector3(m_textInfo.characterInfo[lastVisibleCharacterIndex].topRight.x, m_textInfo.characterInfo[lastVisibleCharacterIndex].baseLine + strikethroughOffset * strikethroughScale, 0);
else
strikethrough_end = new Vector3(m_textInfo.characterInfo[i].topRight.x, m_textInfo.characterInfo[i].baseLine + strikethroughOffset * strikethroughScale, 0);
DrawUnderlineMesh(strikethrough_start, strikethrough_end, ref last_vert_index, strikethroughScale, strikethroughScale, strikethroughScale, xScale, strikethroughColor);
//Debug.Log("Char [" + currentCharacter + "] at Index: " + i + " End Strikethrough POS: " + strikethrough_end + " Baseline: " + m_textInfo.characterInfo[i].baseLine.ToString("f3"));
}
else if (beginStrikethrough && i < m_characterCount && currentFontAsset.GetInstanceID() != characterInfos[i + 1].fontAsset.GetInstanceID())
{
// Terminate Strikethrough if font asset changes.
beginStrikethrough = false;
strikethrough_end = new Vector3(m_textInfo.characterInfo[i].topRight.x, m_textInfo.characterInfo[i].baseLine + strikethroughOffset * strikethroughScale, 0);
DrawUnderlineMesh(strikethrough_start, strikethrough_end, ref last_vert_index, strikethroughScale, strikethroughScale, strikethroughScale, xScale, strikethroughColor);
}
else if (beginStrikethrough && !isStrikeThroughVisible)
{
// Terminate Strikethrough if character is not visible.
beginStrikethrough = false;
strikethrough_end = new Vector3(m_textInfo.characterInfo[i - 1].topRight.x, m_textInfo.characterInfo[i - 1].baseLine + strikethroughOffset * strikethroughScale, 0);
DrawUnderlineMesh(strikethrough_start, strikethrough_end, ref last_vert_index, strikethroughScale, strikethroughScale, strikethroughScale, xScale, strikethroughColor);
}
}
else
{
// End Strikethrough
if (beginStrikethrough == true)
{
beginStrikethrough = false;
strikethrough_end = new Vector3(m_textInfo.characterInfo[i - 1].topRight.x, m_textInfo.characterInfo[i - 1].baseLine + strikethroughOffset * strikethroughScale, 0);
DrawUnderlineMesh(strikethrough_start, strikethrough_end, ref last_vert_index, strikethroughScale, strikethroughScale, strikethroughScale, xScale, strikethroughColor);
}
}
#endregion
// HANDLE TEXT HIGHLIGHTING
#region Text Highlighting
bool isHighlight = (m_textInfo.characterInfo[i].style & FontStyles.Highlight) == FontStyles.Highlight;
if (isHighlight)
{
bool isHighlightVisible = true;
int currentPage = m_textInfo.characterInfo[i].pageNumber;
if (i > m_maxVisibleCharacters || currentLine > m_maxVisibleLines || (m_overflowMode == TextOverflowModes.Page && currentPage + 1 != m_pageToDisplay))
isHighlightVisible = false;
if (beginHighlight == false && isHighlightVisible == true && i <= lineInfo.lastVisibleCharacterIndex && currentCharacter != 10 && currentCharacter != 13)
{
if (i == lineInfo.lastVisibleCharacterIndex && char.IsSeparator(currentCharacter))
{ }
else
{
beginHighlight = true;
highlight_start = k_LargePositiveVector2;
highlight_end = k_LargeNegativeVector2;
highlightColor = m_textInfo.characterInfo[i].highlightColor;
}
}
if (beginHighlight)
{
Color32 currentHighlightColor = m_textInfo.characterInfo[i].highlightColor;
bool isColorTransition = false;
// Handle Highlight color changes
if (!highlightColor.Compare(currentHighlightColor))
{
// End drawing at the start of new highlight color to prevent a gap between highlight sections.
highlight_end.x = (highlight_end.x + m_textInfo.characterInfo[i].bottomLeft.x) / 2;
highlight_start.y = Mathf.Min(highlight_start.y, m_textInfo.characterInfo[i].descender);
highlight_end.y = Mathf.Max(highlight_end.y, m_textInfo.characterInfo[i].ascender);
DrawTextHighlight(highlight_start, highlight_end, ref last_vert_index, highlightColor);
beginHighlight = true;
highlight_start = highlight_end;
highlight_end = new Vector3(m_textInfo.characterInfo[i].topRight.x, m_textInfo.characterInfo[i].descender, 0);
highlightColor = m_textInfo.characterInfo[i].highlightColor;
isColorTransition = true;
}
if (!isColorTransition)
{
// Use the Min / Max Extents of the Highlight area to handle different character sizes and fonts.
highlight_start.x = Mathf.Min(highlight_start.x, m_textInfo.characterInfo[i].bottomLeft.x);
highlight_start.y = Mathf.Min(highlight_start.y, m_textInfo.characterInfo[i].descender);
highlight_end.x = Mathf.Max(highlight_end.x, m_textInfo.characterInfo[i].topRight.x);
highlight_end.y = Mathf.Max(highlight_end.y, m_textInfo.characterInfo[i].ascender);
}
}
// End Highlight if text only contains one character.
if (beginHighlight && m_characterCount == 1)
{
beginHighlight = false;
DrawTextHighlight(highlight_start, highlight_end, ref last_vert_index, highlightColor);
}
else if (beginHighlight && (i == lineInfo.lastCharacterIndex || i >= lineInfo.lastVisibleCharacterIndex))
{
beginHighlight = false;
DrawTextHighlight(highlight_start, highlight_end, ref last_vert_index, highlightColor);
}
else if (beginHighlight && !isHighlightVisible)
{
beginHighlight = false;
DrawTextHighlight(highlight_start, highlight_end, ref last_vert_index, highlightColor);
}
}
else
{
// End Highlight
if (beginHighlight == true)
{
beginHighlight = false;
DrawTextHighlight(highlight_start, highlight_end, ref last_vert_index, highlightColor);
}
}
#endregion
lastLine = currentLine;
}
#endregion
// METRICS ABOUT THE TEXT OBJECT
m_textInfo.characterCount = m_characterCount;
m_textInfo.spriteCount = m_spriteCount;
m_textInfo.lineCount = lineCount;
m_textInfo.wordCount = wordCount != 0 && m_characterCount > 0 ? wordCount : 1;
m_textInfo.pageCount = m_pageNumber + 1;
////Profiler.BeginSample("TMP Generate Text - Phase III");
// Update Mesh Vertex Data
if (m_renderMode == TextRenderFlags.Render && IsActive())
{
// Clear unused vertices
//m_textInfo.meshInfo[0].ClearUnusedVertices();
// Sort the geometry of the text object if needed.
if (m_geometrySortingOrder != VertexSortingOrder.Normal)
m_textInfo.meshInfo[0].SortGeometry(VertexSortingOrder.Reverse);
// Upload Mesh Data
m_mesh.MarkDynamic();
m_mesh.vertices = m_textInfo.meshInfo[0].vertices;
m_mesh.uv = m_textInfo.meshInfo[0].uvs0;
m_mesh.uv2 = m_textInfo.meshInfo[0].uvs2;
//m_mesh.uv4 = m_textInfo.meshInfo[0].uvs4;
m_mesh.colors32 = m_textInfo.meshInfo[0].colors32;
// Compute Bounds for the mesh. Manual computation is more efficient then using Mesh.recalcualteBounds.
m_mesh.RecalculateBounds();
//m_mesh.bounds = new Bounds(new Vector3((m_meshExtents.max.x + m_meshExtents.min.x) / 2, (m_meshExtents.max.y + m_meshExtents.min.y) / 2, 0) + offset, new Vector3(m_meshExtents.max.x - m_meshExtents.min.x, m_meshExtents.max.y - m_meshExtents.min.y, 0));
for (int i = 1; i < m_textInfo.materialCount; i++)
{
// Clear unused vertices
m_textInfo.meshInfo[i].ClearUnusedVertices();
if (m_subTextObjects[i] == null) continue;
// Sort the geometry of the sub-text objects if needed.
if (m_geometrySortingOrder != VertexSortingOrder.Normal)
m_textInfo.meshInfo[i].SortGeometry(VertexSortingOrder.Reverse);
m_subTextObjects[i].mesh.vertices = m_textInfo.meshInfo[i].vertices;
m_subTextObjects[i].mesh.uv = m_textInfo.meshInfo[i].uvs0;
m_subTextObjects[i].mesh.uv2 = m_textInfo.meshInfo[i].uvs2;
//m_subTextObjects[i].mesh.uv4 = m_textInfo.meshInfo[i].uvs4;
m_subTextObjects[i].mesh.colors32 = m_textInfo.meshInfo[i].colors32;
m_subTextObjects[i].mesh.RecalculateBounds();
// Update the collider on the sub text object
//m_subTextObjects[i].UpdateColliders(m_textInfo.meshInfo[i].vertexCount);
}
}
// Event indicating the text has been regenerated.
TMPro_EventManager.ON_TEXT_CHANGED(this);
////Profiler.EndSample();
//Debug.Log("Done Rendering Text.");
}
/// <summary>
/// Method to return the local corners of the Text Container or RectTransform.
/// </summary>
/// <returns></returns>
protected override Vector3[] GetTextContainerLocalCorners()
{
if (m_rectTransform == null) m_rectTransform = this.rectTransform;
m_rectTransform.GetLocalCorners(m_RectTransformCorners);
return m_RectTransformCorners;
}
/// <summary>
/// Method to disable the renderers.
/// </summary>
void SetMeshFilters(bool state)
{
// Parent text object
if (m_meshFilter != null)
{
if (state)
m_meshFilter.sharedMesh = m_mesh;
else
m_meshFilter.sharedMesh = null;
}
for (int i = 1; i < m_subTextObjects.Length && m_subTextObjects[i] != null; i++)
{
if (m_subTextObjects[i].meshFilter != null)
{
if (state)
m_subTextObjects[i].meshFilter.sharedMesh = m_subTextObjects[i].mesh;
else
m_subTextObjects[i].meshFilter.sharedMesh = null;
}
}
}
/// <summary>
/// Method to Enable or Disable child SubMesh objects.
/// </summary>
/// <param name="state"></param>
protected override void SetActiveSubMeshes(bool state)
{
for (int i = 1; i < m_subTextObjects.Length && m_subTextObjects[i] != null; i++)
{
if (m_subTextObjects[i].enabled != state)
m_subTextObjects[i].enabled = state;
}
}
/// <summary>
/// Destroy Sub Mesh Objects
/// </summary>
protected override void ClearSubMeshObjects()
{
for (int i = 1; i < m_subTextObjects.Length && m_subTextObjects[i] != null; i++)
{
Debug.Log("Destroying Sub Text object[" + i + "].");
DestroyImmediate(m_subTextObjects[i]);
}
}
/// <summary>
/// Method returning the compound bounds of the text object and child sub objects.
/// </summary>
/// <returns></returns>
protected override Bounds GetCompoundBounds()
{
Bounds mainBounds = m_mesh.bounds;
Vector3 min = mainBounds.min;
Vector3 max = mainBounds.max;
for (int i = 1; i < m_subTextObjects.Length && m_subTextObjects[i] != null; i++)
{
Bounds subBounds = m_subTextObjects[i].mesh.bounds;
min.x = min.x < subBounds.min.x ? min.x : subBounds.min.x;
min.y = min.y < subBounds.min.y ? min.y : subBounds.min.y;
max.x = max.x > subBounds.max.x ? max.x : subBounds.max.x;
max.y = max.y > subBounds.max.y ? max.y : subBounds.max.y;
}
Vector3 center = (min + max) / 2;
Vector2 size = max - min;
return new Bounds(center, size);
}
/// <summary>
/// Method to Update Scale in UV2
/// </summary>
//void UpdateSDFScale(float lossyScale)
//{
// // TODO: Resolve - Underline / Strikethrough segments not getting their SDF Scale adjusted.
// //Debug.Log("*** UpdateSDFScale() ***");
// // Iterate through each of the characters.
// for (int i = 0; i < m_textInfo.characterCount; i++)
// {
// // Only update scale for visible characters.
// if (m_textInfo.characterInfo[i].isVisible && m_textInfo.characterInfo[i].elementType == TMP_TextElementType.Character)
// {
// float scale = lossyScale * m_textInfo.characterInfo[i].scale * (1 - m_charWidthAdjDelta);
// if (!m_textInfo.characterInfo[i].isUsingAlternateTypeface && (m_textInfo.characterInfo[i].style & FontStyles.Bold) == FontStyles.Bold) scale *= -1;
// int index = m_textInfo.characterInfo[i].materialReferenceIndex;
// int vertexIndex = m_textInfo.characterInfo[i].vertexIndex;
// m_textInfo.meshInfo[index].uvs2[vertexIndex + 0].y = scale;
// m_textInfo.meshInfo[index].uvs2[vertexIndex + 1].y = scale;
// m_textInfo.meshInfo[index].uvs2[vertexIndex + 2].y = scale;
// m_textInfo.meshInfo[index].uvs2[vertexIndex + 3].y = scale;
// }
// }
// // Push the updated uv2 scale information to the meshes.
// for (int i = 0; i < m_textInfo.meshInfo.Length; i++)
// {
// if (i == 0)
// m_mesh.uv2 = m_textInfo.meshInfo[0].uvs2;
// else
// m_subTextObjects[i].mesh.uv2 = m_textInfo.meshInfo[i].uvs2;
// }
//}
/// <summary>
/// Method to update the SDF Scale in UV2.
/// </summary>
/// <param name="scaleDelta"></param>
void UpdateSDFScale(float scaleDelta)
{
if (scaleDelta == 0 || scaleDelta == float.PositiveInfinity)
{
m_havePropertiesChanged = true;
OnPreRenderObject();
return;
}
for (int materialIndex = 0; materialIndex < m_textInfo.materialCount; materialIndex++)
{
TMP_MeshInfo meshInfo = m_textInfo.meshInfo[materialIndex];
for (int i = 0; i < meshInfo.uvs2.Length; i++)
{
meshInfo.uvs2[i].y *= Mathf.Abs(scaleDelta);
}
}
// Push the updated uv2 scale information to the meshes.
for (int i = 0; i < m_textInfo.meshInfo.Length; i++)
{
if (i == 0)
m_mesh.uv2 = m_textInfo.meshInfo[0].uvs2;
else
m_subTextObjects[i].mesh.uv2 = m_textInfo.meshInfo[i].uvs2;
}
}
// Function to offset vertices position to account for line spacing changes.
protected override void AdjustLineOffset(int startIndex, int endIndex, float offset)
{
Vector3 vertexOffset = new Vector3(0, offset, 0);
for (int i = startIndex; i <= endIndex; i++)
{
m_textInfo.characterInfo[i].bottomLeft -= vertexOffset;
m_textInfo.characterInfo[i].topLeft -= vertexOffset;
m_textInfo.characterInfo[i].topRight -= vertexOffset;
m_textInfo.characterInfo[i].bottomRight -= vertexOffset;
m_textInfo.characterInfo[i].ascender -= vertexOffset.y;
m_textInfo.characterInfo[i].baseLine -= vertexOffset.y;
m_textInfo.characterInfo[i].descender -= vertexOffset.y;
if (m_textInfo.characterInfo[i].isVisible)
{
m_textInfo.characterInfo[i].vertex_BL.position -= vertexOffset;
m_textInfo.characterInfo[i].vertex_TL.position -= vertexOffset;
m_textInfo.characterInfo[i].vertex_TR.position -= vertexOffset;
m_textInfo.characterInfo[i].vertex_BR.position -= vertexOffset;
}
}
}
}
}