No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TMP_Text.cs 374KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515
  1. #define TMP_PRESENT
  2. using System;
  3. using System.Collections;
  4. using System.Text;
  5. using System.Collections.Generic;
  6. using Unity.Profiling;
  7. using UnityEngine;
  8. using UnityEngine.TextCore;
  9. using UnityEngine.UI;
  10. namespace TMPro
  11. {
  12. public interface ITextElement
  13. {
  14. Material sharedMaterial { get; }
  15. void Rebuild(CanvasUpdate update);
  16. int GetInstanceID();
  17. }
  18. public enum TextAlignmentOptions
  19. {
  20. TopLeft = HorizontalAlignmentOptions.Left | VerticalAlignmentOptions.Top,
  21. Top = HorizontalAlignmentOptions.Center | VerticalAlignmentOptions.Top,
  22. TopRight = HorizontalAlignmentOptions.Right | VerticalAlignmentOptions.Top,
  23. TopJustified = HorizontalAlignmentOptions.Justified | VerticalAlignmentOptions.Top,
  24. TopFlush = HorizontalAlignmentOptions.Flush | VerticalAlignmentOptions.Top,
  25. TopGeoAligned = HorizontalAlignmentOptions.Geometry | VerticalAlignmentOptions.Top,
  26. Left = HorizontalAlignmentOptions.Left | VerticalAlignmentOptions.Middle,
  27. Center = HorizontalAlignmentOptions.Center | VerticalAlignmentOptions.Middle,
  28. Right = HorizontalAlignmentOptions.Right | VerticalAlignmentOptions.Middle,
  29. Justified = HorizontalAlignmentOptions.Justified | VerticalAlignmentOptions.Middle,
  30. Flush = HorizontalAlignmentOptions.Flush | VerticalAlignmentOptions.Middle,
  31. CenterGeoAligned = HorizontalAlignmentOptions.Geometry | VerticalAlignmentOptions.Middle,
  32. BottomLeft = HorizontalAlignmentOptions.Left | VerticalAlignmentOptions.Bottom,
  33. Bottom = HorizontalAlignmentOptions.Center | VerticalAlignmentOptions.Bottom,
  34. BottomRight = HorizontalAlignmentOptions.Right | VerticalAlignmentOptions.Bottom,
  35. BottomJustified = HorizontalAlignmentOptions.Justified | VerticalAlignmentOptions.Bottom,
  36. BottomFlush = HorizontalAlignmentOptions.Flush | VerticalAlignmentOptions.Bottom,
  37. BottomGeoAligned = HorizontalAlignmentOptions.Geometry | VerticalAlignmentOptions.Bottom,
  38. BaselineLeft = HorizontalAlignmentOptions.Left | VerticalAlignmentOptions.Baseline,
  39. Baseline = HorizontalAlignmentOptions.Center | VerticalAlignmentOptions.Baseline,
  40. BaselineRight = HorizontalAlignmentOptions.Right | VerticalAlignmentOptions.Baseline,
  41. BaselineJustified = HorizontalAlignmentOptions.Justified | VerticalAlignmentOptions.Baseline,
  42. BaselineFlush = HorizontalAlignmentOptions.Flush | VerticalAlignmentOptions.Baseline,
  43. BaselineGeoAligned = HorizontalAlignmentOptions.Geometry | VerticalAlignmentOptions.Baseline,
  44. MidlineLeft = HorizontalAlignmentOptions.Left | VerticalAlignmentOptions.Geometry,
  45. Midline = HorizontalAlignmentOptions.Center | VerticalAlignmentOptions.Geometry,
  46. MidlineRight = HorizontalAlignmentOptions.Right | VerticalAlignmentOptions.Geometry,
  47. MidlineJustified = HorizontalAlignmentOptions.Justified | VerticalAlignmentOptions.Geometry,
  48. MidlineFlush = HorizontalAlignmentOptions.Flush | VerticalAlignmentOptions.Geometry,
  49. MidlineGeoAligned = HorizontalAlignmentOptions.Geometry | VerticalAlignmentOptions.Geometry,
  50. CaplineLeft = HorizontalAlignmentOptions.Left | VerticalAlignmentOptions.Capline,
  51. Capline = HorizontalAlignmentOptions.Center | VerticalAlignmentOptions.Capline,
  52. CaplineRight = HorizontalAlignmentOptions.Right | VerticalAlignmentOptions.Capline,
  53. CaplineJustified = HorizontalAlignmentOptions.Justified | VerticalAlignmentOptions.Capline,
  54. CaplineFlush = HorizontalAlignmentOptions.Flush | VerticalAlignmentOptions.Capline,
  55. CaplineGeoAligned = HorizontalAlignmentOptions.Geometry | VerticalAlignmentOptions.Capline,
  56. Converted = 0xFFFF
  57. };
  58. /// <summary>
  59. /// Horizontal text alignment options.
  60. /// </summary>
  61. public enum HorizontalAlignmentOptions
  62. {
  63. Left = 0x1, Center = 0x2, Right = 0x4, Justified = 0x8, Flush = 0x10, Geometry = 0x20
  64. }
  65. /// <summary>
  66. /// Vertical text alignment options.
  67. /// </summary>
  68. public enum VerticalAlignmentOptions
  69. {
  70. Top = 0x100, Middle = 0x200, Bottom = 0x400, Baseline = 0x800, Geometry = 0x1000, Capline = 0x2000,
  71. }
  72. /// <summary>
  73. /// Flags controlling what vertex data gets pushed to the mesh.
  74. /// </summary>
  75. public enum TextRenderFlags
  76. {
  77. DontRender = 0x0,
  78. Render = 0xFF
  79. };
  80. public enum TMP_TextElementType { Character, Sprite };
  81. public enum MaskingTypes { MaskOff = 0, MaskHard = 1, MaskSoft = 2 }; //, MaskTex = 4 };
  82. public enum TextOverflowModes { Overflow = 0, Ellipsis = 1, Masking = 2, Truncate = 3, ScrollRect = 4, Page = 5, Linked = 6 };
  83. public enum MaskingOffsetMode { Percentage = 0, Pixel = 1 };
  84. public enum TextureMappingOptions { Character = 0, Line = 1, Paragraph = 2, MatchAspect = 3 };
  85. [Flags]
  86. public enum FontStyles { Normal = 0x0, Bold = 0x1, Italic = 0x2, Underline = 0x4, LowerCase = 0x8, UpperCase = 0x10, SmallCaps = 0x20, Strikethrough = 0x40, Superscript = 0x80, Subscript = 0x100, Highlight = 0x200 };
  87. public enum FontWeight { Thin = 100, ExtraLight = 200, Light = 300, Regular = 400, Medium = 500, SemiBold = 600, Bold = 700, Heavy = 800, Black = 900 };
  88. /// <summary>
  89. /// Base class which contains common properties and functions shared between the TextMeshPro and TextMeshProUGUI component.
  90. /// </summary>
  91. public abstract class TMP_Text : MaskableGraphic
  92. {
  93. /// <summary>
  94. /// A string containing the text to be displayed.
  95. /// </summary>
  96. public virtual string text
  97. {
  98. get
  99. {
  100. if (m_IsTextBackingStringDirty)
  101. return InternalTextBackingArrayToString();
  102. return m_text;
  103. }
  104. set
  105. {
  106. if (m_IsTextBackingStringDirty == false && m_text != null && value != null && m_text.Length == value.Length && m_text == value)
  107. return;
  108. m_IsTextBackingStringDirty = false;
  109. m_text = value;
  110. m_inputSource = TextInputSources.TextString;
  111. m_havePropertiesChanged = true;
  112. SetVerticesDirty();
  113. SetLayoutDirty();
  114. }
  115. }
  116. [SerializeField]
  117. [TextArea(5, 10)]
  118. protected string m_text;
  119. /// <summary>
  120. ///
  121. /// </summary>
  122. private bool m_IsTextBackingStringDirty;
  123. /// <summary>
  124. /// The ITextPreprocessor component referenced by the text object (if any)
  125. /// </summary>
  126. public ITextPreprocessor textPreprocessor
  127. {
  128. get { return m_TextPreprocessor; }
  129. set { m_TextPreprocessor = value; }
  130. }
  131. [SerializeField]
  132. protected ITextPreprocessor m_TextPreprocessor;
  133. /// <summary>
  134. ///
  135. /// </summary>
  136. public bool isRightToLeftText
  137. {
  138. get { return m_isRightToLeft; }
  139. set { if (m_isRightToLeft == value) return; m_isRightToLeft = value; m_havePropertiesChanged = true; SetVerticesDirty(); SetLayoutDirty(); }
  140. }
  141. [SerializeField]
  142. protected bool m_isRightToLeft = false;
  143. /// <summary>
  144. /// The Font Asset to be assigned to this text object.
  145. /// </summary>
  146. public TMP_FontAsset font
  147. {
  148. get { return m_fontAsset; }
  149. set { if (m_fontAsset == value) return; m_fontAsset = value; LoadFontAsset(); m_havePropertiesChanged = true; SetVerticesDirty(); SetLayoutDirty(); }
  150. }
  151. [SerializeField]
  152. protected TMP_FontAsset m_fontAsset;
  153. protected TMP_FontAsset m_currentFontAsset;
  154. protected bool m_isSDFShader;
  155. /// <summary>
  156. /// The material to be assigned to this text object.
  157. /// </summary>
  158. public virtual Material fontSharedMaterial
  159. {
  160. get { return m_sharedMaterial; }
  161. set { if (m_sharedMaterial == value) return; SetSharedMaterial(value); m_havePropertiesChanged = true; SetVerticesDirty(); SetMaterialDirty(); }
  162. }
  163. [SerializeField]
  164. protected Material m_sharedMaterial;
  165. protected Material m_currentMaterial;
  166. protected static MaterialReference[] m_materialReferences = new MaterialReference[4];
  167. protected static Dictionary<int, int> m_materialReferenceIndexLookup = new Dictionary<int, int>();
  168. protected static TMP_TextProcessingStack<MaterialReference> m_materialReferenceStack = new TMP_TextProcessingStack<MaterialReference>(new MaterialReference[16]);
  169. protected int m_currentMaterialIndex;
  170. /// <summary>
  171. /// An array containing the materials used by the text object.
  172. /// </summary>
  173. public virtual Material[] fontSharedMaterials
  174. {
  175. get { return GetSharedMaterials(); }
  176. set { SetSharedMaterials(value); m_havePropertiesChanged = true; SetVerticesDirty(); SetMaterialDirty(); }
  177. }
  178. [SerializeField]
  179. protected Material[] m_fontSharedMaterials;
  180. /// <summary>
  181. /// The material to be assigned to this text object. An instance of the material will be assigned to the object's renderer.
  182. /// </summary>
  183. public Material fontMaterial
  184. {
  185. // Return an Instance of the current material.
  186. get { return GetMaterial(m_sharedMaterial); }
  187. // Assign new font material
  188. set
  189. {
  190. if (m_sharedMaterial != null && m_sharedMaterial.GetInstanceID() == value.GetInstanceID()) return;
  191. m_sharedMaterial = value;
  192. m_padding = GetPaddingForMaterial();
  193. m_havePropertiesChanged = true;
  194. SetVerticesDirty();
  195. SetMaterialDirty();
  196. }
  197. }
  198. [SerializeField]
  199. protected Material m_fontMaterial;
  200. /// <summary>
  201. /// The materials to be assigned to this text object. An instance of the materials will be assigned.
  202. /// </summary>
  203. public virtual Material[] fontMaterials
  204. {
  205. get { return GetMaterials(m_fontSharedMaterials); }
  206. set { SetSharedMaterials(value); m_havePropertiesChanged = true; SetVerticesDirty(); SetMaterialDirty(); }
  207. }
  208. [SerializeField]
  209. protected Material[] m_fontMaterials;
  210. protected bool m_isMaterialDirty;
  211. /// <summary>
  212. /// This is the default vertex color assigned to each vertices. Color tags will override vertex colors unless the overrideColorTags is set.
  213. /// </summary>
  214. public override Color color
  215. {
  216. get { return m_fontColor; }
  217. set { if (m_fontColor == value) return; m_havePropertiesChanged = true; m_fontColor = value; SetVerticesDirty(); }
  218. }
  219. //[UnityEngine.Serialization.FormerlySerializedAs("m_fontColor")] // Required for backwards compatibility with pre-Unity 4.6 releases.
  220. [SerializeField]
  221. protected Color32 m_fontColor32 = Color.white;
  222. [SerializeField]
  223. protected Color m_fontColor = Color.white;
  224. protected static Color32 s_colorWhite = new Color32(255, 255, 255, 255);
  225. protected Color32 m_underlineColor = s_colorWhite;
  226. protected Color32 m_strikethroughColor = s_colorWhite;
  227. /// <summary>
  228. /// Sets the vertex color alpha value.
  229. /// </summary>
  230. public float alpha
  231. {
  232. get { return m_fontColor.a; }
  233. set { if (m_fontColor.a == value) return; m_fontColor.a = value; m_havePropertiesChanged = true; SetVerticesDirty(); }
  234. }
  235. /// <summary>
  236. /// Determines if Vertex Color Gradient should be used
  237. /// </summary>
  238. /// <value><c>true</c> if enable vertex gradient; otherwise, <c>false</c>.</value>
  239. public bool enableVertexGradient
  240. {
  241. get { return m_enableVertexGradient; }
  242. set { if (m_enableVertexGradient == value) return; m_havePropertiesChanged = true; m_enableVertexGradient = value; SetVerticesDirty(); }
  243. }
  244. [SerializeField]
  245. protected bool m_enableVertexGradient;
  246. [SerializeField]
  247. protected ColorMode m_colorMode = ColorMode.FourCornersGradient;
  248. /// <summary>
  249. /// Sets the vertex colors for each of the 4 vertices of the character quads.
  250. /// </summary>
  251. /// <value>The color gradient.</value>
  252. public VertexGradient colorGradient
  253. {
  254. get { return m_fontColorGradient; }
  255. set { m_havePropertiesChanged = true; m_fontColorGradient = value; SetVerticesDirty(); }
  256. }
  257. [SerializeField]
  258. protected VertexGradient m_fontColorGradient = new VertexGradient(Color.white);
  259. /// <summary>
  260. /// Set the vertex colors of the 4 vertices of each character quads.
  261. /// </summary>
  262. public TMP_ColorGradient colorGradientPreset
  263. {
  264. get { return m_fontColorGradientPreset; }
  265. set { m_havePropertiesChanged = true; m_fontColorGradientPreset = value; SetVerticesDirty(); }
  266. }
  267. [SerializeField]
  268. protected TMP_ColorGradient m_fontColorGradientPreset;
  269. /// <summary>
  270. /// Sprite Asset used by the text object.
  271. /// </summary>
  272. public TMP_SpriteAsset spriteAsset
  273. {
  274. get { return m_spriteAsset; }
  275. set { m_spriteAsset = value; m_havePropertiesChanged = true; SetVerticesDirty(); SetLayoutDirty(); }
  276. }
  277. [SerializeField]
  278. protected TMP_SpriteAsset m_spriteAsset;
  279. /// <summary>
  280. /// Determines whether or not the sprite color is multiplies by the vertex color of the text.
  281. /// </summary>
  282. public bool tintAllSprites
  283. {
  284. get { return m_tintAllSprites; }
  285. set { if (m_tintAllSprites == value) return; m_tintAllSprites = value; m_havePropertiesChanged = true; SetVerticesDirty(); }
  286. }
  287. [SerializeField]
  288. protected bool m_tintAllSprites;
  289. protected bool m_tintSprite;
  290. protected Color32 m_spriteColor;
  291. /// <summary>
  292. /// Style sheet used by the text object.
  293. /// </summary>
  294. public TMP_StyleSheet styleSheet
  295. {
  296. get { return m_StyleSheet; }
  297. set { m_StyleSheet = value; m_havePropertiesChanged = true; SetVerticesDirty(); SetLayoutDirty(); }
  298. }
  299. [SerializeField]
  300. protected TMP_StyleSheet m_StyleSheet;
  301. /// <summary>
  302. ///
  303. /// </summary>
  304. public TMP_Style textStyle
  305. {
  306. get
  307. {
  308. m_TextStyle = GetStyle(m_TextStyleHashCode);
  309. if (m_TextStyle == null)
  310. {
  311. m_TextStyle = TMP_Style.NormalStyle;
  312. m_TextStyleHashCode = m_TextStyle.hashCode;
  313. }
  314. return m_TextStyle;
  315. }
  316. set { m_TextStyle = value; m_TextStyleHashCode = m_TextStyle.hashCode; m_havePropertiesChanged = true; SetVerticesDirty(); SetLayoutDirty(); }
  317. }
  318. internal TMP_Style m_TextStyle;
  319. [SerializeField]
  320. protected int m_TextStyleHashCode;
  321. /// <summary>
  322. /// This overrides the color tags forcing the vertex colors to be the default font color.
  323. /// </summary>
  324. public bool overrideColorTags
  325. {
  326. get { return m_overrideHtmlColors; }
  327. set { if (m_overrideHtmlColors == value) return; m_havePropertiesChanged = true; m_overrideHtmlColors = value; SetVerticesDirty(); }
  328. }
  329. [SerializeField]
  330. protected bool m_overrideHtmlColors = false;
  331. /// <summary>
  332. /// Sets the color of the _FaceColor property of the assigned material. Changing face color will result in an instance of the material.
  333. /// </summary>
  334. public Color32 faceColor
  335. {
  336. get
  337. {
  338. if (m_sharedMaterial == null) return m_faceColor;
  339. m_faceColor = m_sharedMaterial.GetColor(ShaderUtilities.ID_FaceColor);
  340. return m_faceColor;
  341. }
  342. set { if (m_faceColor.Compare(value)) return; SetFaceColor(value); m_havePropertiesChanged = true; m_faceColor = value; SetVerticesDirty(); SetMaterialDirty(); }
  343. }
  344. [SerializeField]
  345. protected Color32 m_faceColor = Color.white;
  346. /// <summary>
  347. /// Sets the color of the _OutlineColor property of the assigned material. Changing outline color will result in an instance of the material.
  348. /// </summary>
  349. public Color32 outlineColor
  350. {
  351. get
  352. {
  353. if (m_sharedMaterial == null) return m_outlineColor;
  354. m_outlineColor = m_sharedMaterial.GetColor(ShaderUtilities.ID_OutlineColor);
  355. return m_outlineColor;
  356. }
  357. set { if (m_outlineColor.Compare(value)) return; SetOutlineColor(value); m_havePropertiesChanged = true; m_outlineColor = value; SetVerticesDirty(); }
  358. }
  359. //[SerializeField]
  360. protected Color32 m_outlineColor = Color.black;
  361. /// <summary>
  362. /// Sets the thickness of the outline of the font. Setting this value will result in an instance of the material.
  363. /// </summary>
  364. public float outlineWidth
  365. {
  366. get
  367. {
  368. if (m_sharedMaterial == null) return m_outlineWidth;
  369. m_outlineWidth = m_sharedMaterial.GetFloat(ShaderUtilities.ID_OutlineWidth);
  370. return m_outlineWidth;
  371. }
  372. set { if (m_outlineWidth == value) return; SetOutlineThickness(value); m_havePropertiesChanged = true; m_outlineWidth = value; SetVerticesDirty(); }
  373. }
  374. protected float m_outlineWidth = 0.0f;
  375. /// <summary>
  376. /// The point size of the font.
  377. /// </summary>
  378. public float fontSize
  379. {
  380. get { return m_fontSize; }
  381. set { if (m_fontSize == value) return; m_havePropertiesChanged = true; m_fontSize = value; if (!m_enableAutoSizing) m_fontSizeBase = m_fontSize; SetVerticesDirty(); SetLayoutDirty(); }
  382. }
  383. [SerializeField]
  384. protected float m_fontSize = -99; // Font Size
  385. protected float m_currentFontSize; // Temporary Font Size affected by tags
  386. [SerializeField] // TODO: Review if this should be serialized
  387. protected float m_fontSizeBase = 36;
  388. protected TMP_TextProcessingStack<float> m_sizeStack = new TMP_TextProcessingStack<float>(16);
  389. /// <summary>
  390. /// Control the weight of the font if an alternative font asset is assigned for the given weight in the font asset editor.
  391. /// </summary>
  392. public FontWeight fontWeight
  393. {
  394. get { return m_fontWeight; }
  395. set { if (m_fontWeight == value) return; m_fontWeight = value; m_havePropertiesChanged = true; SetVerticesDirty(); SetLayoutDirty(); }
  396. }
  397. [SerializeField]
  398. protected FontWeight m_fontWeight = FontWeight.Regular;
  399. protected FontWeight m_FontWeightInternal = FontWeight.Regular;
  400. protected TMP_TextProcessingStack<FontWeight> m_FontWeightStack = new TMP_TextProcessingStack<FontWeight>(8);
  401. /// <summary>
  402. ///
  403. /// </summary>
  404. public float pixelsPerUnit
  405. {
  406. get
  407. {
  408. var localCanvas = canvas;
  409. if (!localCanvas)
  410. return 1;
  411. // For dynamic fonts, ensure we use one pixel per pixel on the screen.
  412. if (!font)
  413. return localCanvas.scaleFactor;
  414. // For non-dynamic fonts, calculate pixels per unit based on specified font size relative to font object's own font size.
  415. if (m_currentFontAsset == null || m_currentFontAsset.faceInfo.pointSize <= 0 || m_fontSize <= 0)
  416. return 1;
  417. return m_fontSize / m_currentFontAsset.faceInfo.pointSize;
  418. }
  419. }
  420. /// <summary>
  421. /// Enable text auto-sizing
  422. /// </summary>
  423. public bool enableAutoSizing
  424. {
  425. get { return m_enableAutoSizing; }
  426. set { if (m_enableAutoSizing == value) return; m_enableAutoSizing = value; SetVerticesDirty(); SetLayoutDirty(); }
  427. }
  428. [SerializeField]
  429. protected bool m_enableAutoSizing;
  430. protected float m_maxFontSize; // Used in conjunction with auto-sizing
  431. protected float m_minFontSize; // Used in conjunction with auto-sizing
  432. protected int m_AutoSizeIterationCount;
  433. protected int m_AutoSizeMaxIterationCount = 100;
  434. protected bool m_IsAutoSizePointSizeSet;
  435. /// <summary>
  436. /// Minimum point size of the font when text auto-sizing is enabled.
  437. /// </summary>
  438. public float fontSizeMin
  439. {
  440. get { return m_fontSizeMin; }
  441. set { if (m_fontSizeMin == value) return; m_fontSizeMin = value; SetVerticesDirty(); SetLayoutDirty(); }
  442. }
  443. [SerializeField]
  444. protected float m_fontSizeMin = 0; // Text Auto Sizing Min Font Size.
  445. /// <summary>
  446. /// Maximum point size of the font when text auto-sizing is enabled.
  447. /// </summary>
  448. public float fontSizeMax
  449. {
  450. get { return m_fontSizeMax; }
  451. set { if (m_fontSizeMax == value) return; m_fontSizeMax = value; SetVerticesDirty(); SetLayoutDirty(); }
  452. }
  453. [SerializeField]
  454. protected float m_fontSizeMax = 0; // Text Auto Sizing Max Font Size.
  455. /// <summary>
  456. /// The style of the text
  457. /// </summary>
  458. public FontStyles fontStyle
  459. {
  460. get { return m_fontStyle; }
  461. set { if (m_fontStyle == value) return; m_fontStyle = value; m_havePropertiesChanged = true; SetVerticesDirty(); SetLayoutDirty(); }
  462. }
  463. [SerializeField]
  464. protected FontStyles m_fontStyle = FontStyles.Normal;
  465. protected FontStyles m_FontStyleInternal = FontStyles.Normal;
  466. protected TMP_FontStyleStack m_fontStyleStack;
  467. /// <summary>
  468. /// Property used in conjunction with padding calculation for the geometry.
  469. /// </summary>
  470. public bool isUsingBold { get { return m_isUsingBold; } }
  471. protected bool m_isUsingBold = false; // Used to ensure GetPadding & Ratios take into consideration bold characters.
  472. /// <summary>
  473. /// Horizontal alignment options
  474. /// </summary>
  475. public HorizontalAlignmentOptions horizontalAlignment
  476. {
  477. get { return m_HorizontalAlignment; }
  478. set
  479. {
  480. if (m_HorizontalAlignment == value)
  481. return;
  482. m_HorizontalAlignment = value;
  483. m_havePropertiesChanged = true;
  484. SetVerticesDirty();
  485. }
  486. }
  487. [SerializeField]
  488. protected HorizontalAlignmentOptions m_HorizontalAlignment = HorizontalAlignmentOptions.Left;
  489. /// <summary>
  490. /// Vertical alignment options
  491. /// </summary>
  492. public VerticalAlignmentOptions verticalAlignment
  493. {
  494. get { return m_VerticalAlignment; }
  495. set
  496. {
  497. if (m_VerticalAlignment == value)
  498. return;
  499. m_VerticalAlignment = value;
  500. m_havePropertiesChanged = true;
  501. SetVerticesDirty();
  502. }
  503. }
  504. [SerializeField]
  505. protected VerticalAlignmentOptions m_VerticalAlignment = VerticalAlignmentOptions.Top;
  506. /// <summary>
  507. /// Text alignment options
  508. /// </summary>
  509. public TextAlignmentOptions alignment
  510. {
  511. get { return (TextAlignmentOptions)((int)m_HorizontalAlignment | (int)m_VerticalAlignment); }
  512. set
  513. {
  514. HorizontalAlignmentOptions horizontalAlignment = (HorizontalAlignmentOptions)((int)value & 0xFF);
  515. VerticalAlignmentOptions verticalAlignment = (VerticalAlignmentOptions)((int)value & 0xFF00);
  516. if (m_HorizontalAlignment == horizontalAlignment && m_VerticalAlignment == verticalAlignment)
  517. return;
  518. m_HorizontalAlignment = horizontalAlignment;
  519. m_VerticalAlignment = verticalAlignment;
  520. m_havePropertiesChanged = true;
  521. SetVerticesDirty();
  522. }
  523. }
  524. [SerializeField]
  525. [UnityEngine.Serialization.FormerlySerializedAs("m_lineJustification")]
  526. protected TextAlignmentOptions m_textAlignment = TextAlignmentOptions.Converted;
  527. protected HorizontalAlignmentOptions m_lineJustification;
  528. protected TMP_TextProcessingStack<HorizontalAlignmentOptions> m_lineJustificationStack = new TMP_TextProcessingStack<HorizontalAlignmentOptions>(new HorizontalAlignmentOptions[16]);
  529. protected Vector3[] m_textContainerLocalCorners = new Vector3[4];
  530. /// <summary>
  531. /// Use the extents of the text geometry for alignment instead of font metrics.
  532. /// </summary>
  533. //public bool alignByGeometry
  534. //{
  535. // get { return m_alignByGeometry; }
  536. // set { if (m_alignByGeometry == value) return; m_havePropertiesChanged = true; m_alignByGeometry = value; SetVerticesDirty(); }
  537. //}
  538. //[SerializeField]
  539. //protected bool m_alignByGeometry;
  540. /// <summary>
  541. /// The amount of additional spacing between characters.
  542. /// </summary>
  543. public float characterSpacing
  544. {
  545. get { return m_characterSpacing; }
  546. set { if (m_characterSpacing == value) return; m_havePropertiesChanged = true; m_characterSpacing = value; SetVerticesDirty(); SetLayoutDirty(); }
  547. }
  548. [SerializeField]
  549. protected float m_characterSpacing = 0;
  550. protected float m_cSpacing = 0;
  551. protected float m_monoSpacing = 0;
  552. /// <summary>
  553. /// The amount of additional spacing between words.
  554. /// </summary>
  555. public float wordSpacing
  556. {
  557. get { return m_wordSpacing; }
  558. set { if (m_wordSpacing == value) return; m_havePropertiesChanged = true; m_wordSpacing = value; SetVerticesDirty(); SetLayoutDirty(); }
  559. }
  560. [SerializeField]
  561. protected float m_wordSpacing = 0;
  562. /// <summary>
  563. /// The amount of additional spacing to add between each lines of text.
  564. /// </summary>
  565. public float lineSpacing
  566. {
  567. get { return m_lineSpacing; }
  568. set { if (m_lineSpacing == value) return; m_havePropertiesChanged = true; m_lineSpacing = value; SetVerticesDirty(); SetLayoutDirty(); }
  569. }
  570. [SerializeField]
  571. protected float m_lineSpacing = 0;
  572. protected float m_lineSpacingDelta = 0; // Used with Text Auto Sizing feature
  573. protected float m_lineHeight = TMP_Math.FLOAT_UNSET; // Used with the <line-height=xx.x> tag.
  574. protected bool m_IsDrivenLineSpacing;
  575. /// <summary>
  576. /// The amount of potential line spacing adjustment before text auto sizing kicks in.
  577. /// </summary>
  578. public float lineSpacingAdjustment
  579. {
  580. get { return m_lineSpacingMax; }
  581. set { if (m_lineSpacingMax == value) return; m_havePropertiesChanged = true; m_lineSpacingMax = value; SetVerticesDirty(); SetLayoutDirty(); }
  582. }
  583. [SerializeField]
  584. protected float m_lineSpacingMax = 0; // Text Auto Sizing Max Line spacing reduction.
  585. //protected bool m_forceLineBreak;
  586. /// <summary>
  587. /// The amount of additional spacing to add between each lines of text.
  588. /// </summary>
  589. public float paragraphSpacing
  590. {
  591. get { return m_paragraphSpacing; }
  592. set { if (m_paragraphSpacing == value) return; m_havePropertiesChanged = true; m_paragraphSpacing = value; SetVerticesDirty(); SetLayoutDirty(); }
  593. }
  594. [SerializeField]
  595. protected float m_paragraphSpacing = 0;
  596. /// <summary>
  597. /// Percentage the width of characters can be adjusted before text auto-sizing begins to reduce the point size.
  598. /// </summary>
  599. public float characterWidthAdjustment
  600. {
  601. get { return m_charWidthMaxAdj; }
  602. set { if (m_charWidthMaxAdj == value) return; m_havePropertiesChanged = true; m_charWidthMaxAdj = value; SetVerticesDirty(); SetLayoutDirty(); }
  603. }
  604. [SerializeField]
  605. protected float m_charWidthMaxAdj = 0f; // Text Auto Sizing Max Character Width reduction.
  606. protected float m_charWidthAdjDelta = 0;
  607. /// <summary>
  608. /// Controls whether or not word wrapping is applied. When disabled, the text will be displayed on a single line.
  609. /// </summary>
  610. public bool enableWordWrapping
  611. {
  612. get { return m_enableWordWrapping; }
  613. set { if (m_enableWordWrapping == value) return; m_havePropertiesChanged = true; m_enableWordWrapping = value; SetVerticesDirty(); SetLayoutDirty(); }
  614. }
  615. [SerializeField]
  616. protected bool m_enableWordWrapping = false;
  617. protected bool m_isCharacterWrappingEnabled = false;
  618. protected bool m_isNonBreakingSpace = false;
  619. protected bool m_isIgnoringAlignment;
  620. /// <summary>
  621. /// Controls the blending between using character and word spacing to fill-in the space for justified text.
  622. /// </summary>
  623. public float wordWrappingRatios
  624. {
  625. get { return m_wordWrappingRatios; }
  626. set { if (m_wordWrappingRatios == value) return; m_wordWrappingRatios = value; m_havePropertiesChanged = true; SetVerticesDirty(); SetLayoutDirty(); }
  627. }
  628. [SerializeField]
  629. protected float m_wordWrappingRatios = 0.4f; // Controls word wrapping ratios between word or characters.
  630. /// <summary>
  631. ///
  632. /// </summary>
  633. //public bool enableAdaptiveJustification
  634. //{
  635. // get { return m_enableAdaptiveJustification; }
  636. // set { if (m_enableAdaptiveJustification == value) return; m_enableAdaptiveJustification = value; m_havePropertiesChanged = true; m_isCalculateSizeRequired = true; SetVerticesDirty(); SetLayoutDirty(); }
  637. //}
  638. //[SerializeField]
  639. //protected bool m_enableAdaptiveJustification;
  640. //protected float m_adaptiveJustificationThreshold = 10.0f;
  641. /// <summary>
  642. /// Controls the Text Overflow Mode
  643. /// </summary>
  644. public TextOverflowModes overflowMode
  645. {
  646. get { return m_overflowMode; }
  647. set { if (m_overflowMode == value) return; m_overflowMode = value; m_havePropertiesChanged = true; SetVerticesDirty(); SetLayoutDirty(); }
  648. }
  649. [SerializeField]
  650. protected TextOverflowModes m_overflowMode = TextOverflowModes.Overflow;
  651. /// <summary>
  652. /// Indicates if the text exceeds the vertical bounds of its text container.
  653. /// </summary>
  654. public bool isTextOverflowing
  655. {
  656. get { if (m_firstOverflowCharacterIndex != -1) return true; return false; }
  657. }
  658. /// <summary>
  659. /// The first character which exceeds the vertical bounds of its text container.
  660. /// </summary>
  661. public int firstOverflowCharacterIndex
  662. {
  663. get { return m_firstOverflowCharacterIndex; }
  664. }
  665. //[SerializeField]
  666. protected int m_firstOverflowCharacterIndex = -1;
  667. /// <summary>
  668. /// The linked text component used for flowing the text from one text component to another.
  669. /// </summary>
  670. public TMP_Text linkedTextComponent
  671. {
  672. get { return m_linkedTextComponent; }
  673. set
  674. {
  675. if (value == null)
  676. {
  677. // Release linked text components
  678. ReleaseLinkedTextComponent(m_linkedTextComponent);
  679. m_linkedTextComponent = value;
  680. }
  681. else if (IsSelfOrLinkedAncestor(value))
  682. {
  683. // We do nothing since new assigned is invalid
  684. return;
  685. }
  686. else
  687. {
  688. // Release linked text components
  689. ReleaseLinkedTextComponent(m_linkedTextComponent);
  690. m_linkedTextComponent = value;
  691. m_linkedTextComponent.parentLinkedComponent = this;
  692. }
  693. m_havePropertiesChanged = true;
  694. SetVerticesDirty();
  695. SetLayoutDirty();
  696. }
  697. }
  698. [SerializeField]
  699. protected TMP_Text m_linkedTextComponent;
  700. [SerializeField]
  701. internal TMP_Text parentLinkedComponent;
  702. /// <summary>
  703. /// Property indicating whether the text is Truncated or using Ellipsis.
  704. /// </summary>
  705. public bool isTextTruncated { get { return m_isTextTruncated; } }
  706. //[SerializeField]
  707. protected bool m_isTextTruncated;
  708. /// <summary>
  709. /// Determines if kerning is enabled or disabled.
  710. /// </summary>
  711. public bool enableKerning
  712. {
  713. get { return m_enableKerning; }
  714. set { if (m_enableKerning == value) return; m_havePropertiesChanged = true; m_enableKerning = value; SetVerticesDirty(); SetLayoutDirty(); }
  715. }
  716. [SerializeField]
  717. protected bool m_enableKerning;
  718. protected float m_GlyphHorizontalAdvanceAdjustment;
  719. /// <summary>
  720. /// Adds extra padding around each character. This may be necessary when the displayed text is very small to prevent clipping.
  721. /// </summary>
  722. public bool extraPadding
  723. {
  724. get { return m_enableExtraPadding; }
  725. set { if (m_enableExtraPadding == value) return; m_havePropertiesChanged = true; m_enableExtraPadding = value; UpdateMeshPadding(); SetVerticesDirty(); /* SetLayoutDirty();*/ }
  726. }
  727. [SerializeField]
  728. protected bool m_enableExtraPadding = false;
  729. [SerializeField]
  730. protected bool checkPaddingRequired;
  731. /// <summary>
  732. /// Enables or Disables Rich Text Tags
  733. /// </summary>
  734. public bool richText
  735. {
  736. get { return m_isRichText; }
  737. set { if (m_isRichText == value) return; m_isRichText = value; m_havePropertiesChanged = true; SetVerticesDirty(); SetLayoutDirty(); }
  738. }
  739. [SerializeField]
  740. protected bool m_isRichText = true; // Used to enable or disable Rich Text.
  741. /// <summary>
  742. /// Enables or Disables parsing of CTRL characters in input text.
  743. /// </summary>
  744. public bool parseCtrlCharacters
  745. {
  746. get { return m_parseCtrlCharacters; }
  747. set { if (m_parseCtrlCharacters == value) return; m_parseCtrlCharacters = value; m_havePropertiesChanged = true; SetVerticesDirty(); SetLayoutDirty(); }
  748. }
  749. [SerializeField]
  750. protected bool m_parseCtrlCharacters = true;
  751. /// <summary>
  752. /// Sets the RenderQueue along with Ztest to force the text to be drawn last and on top of scene elements.
  753. /// </summary>
  754. public bool isOverlay
  755. {
  756. get { return m_isOverlay; }
  757. set { if (m_isOverlay == value) return; m_isOverlay = value; SetShaderDepth(); m_havePropertiesChanged = true; SetVerticesDirty(); }
  758. }
  759. protected bool m_isOverlay = false;
  760. /// <summary>
  761. /// Sets Perspective Correction to Zero for Orthographic Camera mode & 0.875f for Perspective Camera mode.
  762. /// </summary>
  763. public bool isOrthographic
  764. {
  765. get { return m_isOrthographic; }
  766. set { if (m_isOrthographic == value) return; m_havePropertiesChanged = true; m_isOrthographic = value; SetVerticesDirty(); }
  767. }
  768. [SerializeField]
  769. protected bool m_isOrthographic = false;
  770. /// <summary>
  771. /// Sets the culling on the shaders. Note changing this value will result in an instance of the material.
  772. /// </summary>
  773. public bool enableCulling
  774. {
  775. get { return m_isCullingEnabled; }
  776. set { if (m_isCullingEnabled == value) return; m_isCullingEnabled = value; SetCulling(); m_havePropertiesChanged = true; }
  777. }
  778. [SerializeField]
  779. protected bool m_isCullingEnabled = false;
  780. //
  781. protected bool m_isMaskingEnabled;
  782. protected bool isMaskUpdateRequired;
  783. /// <summary>
  784. /// Forces objects that are not visible to get refreshed.
  785. /// </summary>
  786. public bool ignoreVisibility
  787. {
  788. get { return m_ignoreCulling; }
  789. set { if (m_ignoreCulling == value) return; m_havePropertiesChanged = true; m_ignoreCulling = value; }
  790. }
  791. //[SerializeField]
  792. protected bool m_ignoreCulling = true; // Not implemented yet.
  793. /// <summary>
  794. /// Controls how the face and outline textures will be applied to the text object.
  795. /// </summary>
  796. public TextureMappingOptions horizontalMapping
  797. {
  798. get { return m_horizontalMapping; }
  799. set { if (m_horizontalMapping == value) return; m_havePropertiesChanged = true; m_horizontalMapping = value; SetVerticesDirty(); }
  800. }
  801. [SerializeField]
  802. protected TextureMappingOptions m_horizontalMapping = TextureMappingOptions.Character;
  803. /// <summary>
  804. /// Controls how the face and outline textures will be applied to the text object.
  805. /// </summary>
  806. public TextureMappingOptions verticalMapping
  807. {
  808. get { return m_verticalMapping; }
  809. set { if (m_verticalMapping == value) return; m_havePropertiesChanged = true; m_verticalMapping = value; SetVerticesDirty(); }
  810. }
  811. [SerializeField]
  812. protected TextureMappingOptions m_verticalMapping = TextureMappingOptions.Character;
  813. /// <summary>
  814. /// Controls the UV Offset for the various texture mapping mode on the text object.
  815. /// </summary>
  816. //public Vector2 mappingUvOffset
  817. //{
  818. // get { return m_uvOffset; }
  819. // set { if (m_uvOffset == value) return; m_havePropertiesChanged = true; m_uvOffset = value; SetVerticesDirty(); }
  820. //}
  821. //[SerializeField]
  822. //protected Vector2 m_uvOffset = Vector2.zero; // Used to offset UV on Texturing
  823. /// <summary>
  824. /// Controls the horizontal offset of the UV of the texture mapping mode for each line of the text object.
  825. /// </summary>
  826. public float mappingUvLineOffset
  827. {
  828. get { return m_uvLineOffset; }
  829. set { if (m_uvLineOffset == value) return; m_havePropertiesChanged = true; m_uvLineOffset = value; SetVerticesDirty(); }
  830. }
  831. [SerializeField]
  832. protected float m_uvLineOffset = 0.0f; // Used for UV line offset per line
  833. /// <summary>
  834. /// Determines if the Mesh will be rendered.
  835. /// </summary>
  836. public TextRenderFlags renderMode
  837. {
  838. get { return m_renderMode; }
  839. set { if (m_renderMode == value) return; m_renderMode = value; m_havePropertiesChanged = true; }
  840. }
  841. protected TextRenderFlags m_renderMode = TextRenderFlags.Render;
  842. /// <summary>
  843. /// Determines the sorting order of the geometry of the text object.
  844. /// </summary>
  845. public VertexSortingOrder geometrySortingOrder
  846. {
  847. get { return m_geometrySortingOrder; }
  848. set { m_geometrySortingOrder = value; m_havePropertiesChanged = true; SetVerticesDirty(); }
  849. }
  850. [SerializeField]
  851. protected VertexSortingOrder m_geometrySortingOrder;
  852. /// <summary>
  853. /// Determines if a text object will be excluded from the InternalUpdate callback used to handle updates of SDF Scale when the scale of the text object or parent(s) changes.
  854. /// </summary>
  855. public bool isTextObjectScaleStatic
  856. {
  857. get { return m_IsTextObjectScaleStatic; }
  858. set
  859. {
  860. m_IsTextObjectScaleStatic = value;
  861. if (m_IsTextObjectScaleStatic)
  862. TMP_UpdateManager.UnRegisterTextObjectForUpdate(this);
  863. else
  864. TMP_UpdateManager.RegisterTextObjectForUpdate(this);
  865. }
  866. }
  867. [SerializeField]
  868. protected bool m_IsTextObjectScaleStatic;
  869. /// <summary>
  870. /// Determines if the data structures allocated to contain the geometry of the text object will be reduced in size if the number of characters required to display the text is reduced by more than 256 characters.
  871. /// This reduction has the benefit of reducing the amount of vertex data being submitted to the graphic device but results in GC when it occurs.
  872. /// </summary>
  873. public bool vertexBufferAutoSizeReduction
  874. {
  875. get { return m_VertexBufferAutoSizeReduction; }
  876. set { m_VertexBufferAutoSizeReduction = value; m_havePropertiesChanged = true; SetVerticesDirty(); }
  877. }
  878. [SerializeField]
  879. protected bool m_VertexBufferAutoSizeReduction = false;
  880. /// <summary>
  881. /// The first character which should be made visible in conjunction with the Text Overflow Linked mode.
  882. /// </summary>
  883. public int firstVisibleCharacter
  884. {
  885. get { return m_firstVisibleCharacter; }
  886. set { if (m_firstVisibleCharacter == value) return; m_havePropertiesChanged = true; m_firstVisibleCharacter = value; SetVerticesDirty(); }
  887. }
  888. //[SerializeField]
  889. protected int m_firstVisibleCharacter;
  890. /// <summary>
  891. /// Allows to control how many characters are visible from the input.
  892. /// </summary>
  893. public int maxVisibleCharacters
  894. {
  895. get { return m_maxVisibleCharacters; }
  896. set { if (m_maxVisibleCharacters == value) return; m_havePropertiesChanged = true; m_maxVisibleCharacters = value; SetVerticesDirty(); }
  897. }
  898. protected int m_maxVisibleCharacters = 99999;
  899. /// <summary>
  900. /// Allows to control how many words are visible from the input.
  901. /// </summary>
  902. public int maxVisibleWords
  903. {
  904. get { return m_maxVisibleWords; }
  905. set { if (m_maxVisibleWords == value) return; m_havePropertiesChanged = true; m_maxVisibleWords = value; SetVerticesDirty(); }
  906. }
  907. protected int m_maxVisibleWords = 99999;
  908. /// <summary>
  909. /// Allows control over how many lines of text are displayed.
  910. /// </summary>
  911. public int maxVisibleLines
  912. {
  913. get { return m_maxVisibleLines; }
  914. set { if (m_maxVisibleLines == value) return; m_havePropertiesChanged = true; m_maxVisibleLines = value; SetVerticesDirty(); }
  915. }
  916. protected int m_maxVisibleLines = 99999;
  917. /// <summary>
  918. /// Determines if the text's vertical alignment will be adjusted based on visible descender of the text.
  919. /// </summary>
  920. public bool useMaxVisibleDescender
  921. {
  922. get { return m_useMaxVisibleDescender; }
  923. set { if (m_useMaxVisibleDescender == value) return; m_havePropertiesChanged = true; m_useMaxVisibleDescender = value; SetVerticesDirty(); }
  924. }
  925. [SerializeField]
  926. protected bool m_useMaxVisibleDescender = true;
  927. /// <summary>
  928. /// Controls which page of text is shown
  929. /// </summary>
  930. public int pageToDisplay
  931. {
  932. get { return m_pageToDisplay; }
  933. set { if (m_pageToDisplay == value) return; m_havePropertiesChanged = true; m_pageToDisplay = value; SetVerticesDirty(); }
  934. }
  935. [SerializeField]
  936. protected int m_pageToDisplay = 1;
  937. protected bool m_isNewPage = false;
  938. /// <summary>
  939. /// The margins of the text object.
  940. /// </summary>
  941. public virtual Vector4 margin
  942. {
  943. get { return m_margin; }
  944. set { if (m_margin == value) return; m_margin = value; ComputeMarginSize(); m_havePropertiesChanged = true; SetVerticesDirty(); }
  945. }
  946. [SerializeField]
  947. protected Vector4 m_margin = new Vector4(0, 0, 0, 0);
  948. protected float m_marginLeft;
  949. protected float m_marginRight;
  950. protected float m_marginWidth; // Width of the RectTransform minus left and right margins.
  951. protected float m_marginHeight; // Height of the RectTransform minus top and bottom margins.
  952. protected float m_width = -1;
  953. /// <summary>
  954. /// Returns data about the text object which includes information about each character, word, line, link, etc.
  955. /// </summary>
  956. public TMP_TextInfo textInfo
  957. {
  958. get { return m_textInfo; }
  959. }
  960. //[SerializeField]
  961. protected TMP_TextInfo m_textInfo; // Class which holds information about the Text object such as characters, lines, mesh data as well as metrics.
  962. /// <summary>
  963. /// Property tracking if any of the text properties have changed. Flag is set before the text is regenerated.
  964. /// </summary>
  965. public bool havePropertiesChanged
  966. {
  967. get { return m_havePropertiesChanged; }
  968. set { if (m_havePropertiesChanged == value) return; m_havePropertiesChanged = value; SetAllDirty(); }
  969. }
  970. //[SerializeField]
  971. protected bool m_havePropertiesChanged; // Used to track when properties of the text object have changed.
  972. /// <summary>
  973. /// Property to handle legacy animation component.
  974. /// </summary>
  975. public bool isUsingLegacyAnimationComponent
  976. {
  977. get { return m_isUsingLegacyAnimationComponent; }
  978. set { m_isUsingLegacyAnimationComponent = value; }
  979. }
  980. [SerializeField]
  981. protected bool m_isUsingLegacyAnimationComponent;
  982. /// <summary>
  983. /// Returns are reference to the Transform
  984. /// </summary>
  985. public new Transform transform
  986. {
  987. get
  988. {
  989. if (m_transform == null)
  990. m_transform = GetComponent<Transform>();
  991. return m_transform;
  992. }
  993. }
  994. protected Transform m_transform;
  995. /// <summary>
  996. /// Returns are reference to the RectTransform
  997. /// </summary>
  998. public new RectTransform rectTransform
  999. {
  1000. get
  1001. {
  1002. if (m_rectTransform == null)
  1003. m_rectTransform = GetComponent<RectTransform>();
  1004. return m_rectTransform;
  1005. }
  1006. }
  1007. protected RectTransform m_rectTransform;
  1008. /// <summary>
  1009. /// Used to track potential changes in RectTransform size to allow us to ignore OnRectTransformDimensionsChange getting called due to rounding errors when using Stretch Anchors.
  1010. /// </summary>
  1011. protected Vector2 m_PreviousRectTransformSize;
  1012. /// <summary>
  1013. /// Used to track potential changes in pivot position to allow us to ignore OnRectTransformDimensionsChange getting called due to rounding errors when using Stretch Anchors.
  1014. /// </summary>
  1015. protected Vector2 m_PreviousPivotPosition;
  1016. /// <summary>
  1017. /// Enables control over setting the size of the text container to match the text object.
  1018. /// </summary>
  1019. public virtual bool autoSizeTextContainer
  1020. {
  1021. get;
  1022. set;
  1023. }
  1024. protected bool m_autoSizeTextContainer;
  1025. /// <summary>
  1026. /// The mesh used by the font asset and material assigned to the text object.
  1027. /// </summary>
  1028. public virtual Mesh mesh
  1029. {
  1030. get { return m_mesh; }
  1031. }
  1032. protected Mesh m_mesh;
  1033. /// <summary>
  1034. /// Determines if the geometry of the characters will be quads or volumetric (cubes).
  1035. /// </summary>
  1036. public bool isVolumetricText
  1037. {
  1038. get { return m_isVolumetricText; }
  1039. set { if (m_isVolumetricText == value) return; m_havePropertiesChanged = value; m_textInfo.ResetVertexLayout(value); SetVerticesDirty(); SetLayoutDirty(); }
  1040. }
  1041. [SerializeField]
  1042. protected bool m_isVolumetricText;
  1043. /// <summary>
  1044. /// Returns the bounds of the mesh of the text object in world space.
  1045. /// </summary>
  1046. public Bounds bounds
  1047. {
  1048. get
  1049. {
  1050. if (m_mesh == null) return new Bounds();
  1051. return GetCompoundBounds();
  1052. }
  1053. }
  1054. /// <summary>
  1055. /// Returns the bounds of the text of the text object.
  1056. /// </summary>
  1057. public Bounds textBounds
  1058. {
  1059. get
  1060. {
  1061. if (m_textInfo == null) return new Bounds();
  1062. return GetTextBounds();
  1063. }
  1064. }
  1065. // *** Unity Event Handling ***
  1066. /// <summary>
  1067. /// Event delegate to allow custom loading of TMP_FontAsset when using the <font="Font Asset Name"> tag.
  1068. /// </summary>
  1069. public static event Func<int, string, TMP_FontAsset> OnFontAssetRequest;
  1070. /// <summary>
  1071. /// Event delegate to allow custom loading of TMP_SpriteAsset when using the <sprite="Sprite Asset Name"> tag.
  1072. /// </summary>
  1073. public static event Func<int, string, TMP_SpriteAsset> OnSpriteAssetRequest;
  1074. /// <summary>
  1075. /// Event delegate to allow modifying the text geometry before it is uploaded to the mesh and rendered.
  1076. /// </summary>
  1077. public virtual event Action<TMP_TextInfo> OnPreRenderText = delegate { };
  1078. // *** SPECIAL COMPONENTS ***
  1079. /// <summary>
  1080. /// Component used to control wrapping of text following some arbitrary shape.
  1081. /// </summary>
  1082. //public MarginShaper marginShaper
  1083. //{
  1084. // get
  1085. // {
  1086. // if (m_marginShaper == null) m_marginShaper = GetComponent<MarginShaper>();
  1087. // return m_marginShaper;
  1088. // }
  1089. //}
  1090. //[SerializeField]
  1091. //protected MarginShaper m_marginShaper;
  1092. /// <summary>
  1093. /// Component used to control and animate sprites in the text object.
  1094. /// </summary>
  1095. protected TMP_SpriteAnimator spriteAnimator
  1096. {
  1097. get
  1098. {
  1099. if (m_spriteAnimator == null)
  1100. {
  1101. m_spriteAnimator = GetComponent<TMP_SpriteAnimator>();
  1102. if (m_spriteAnimator == null) m_spriteAnimator = gameObject.AddComponent<TMP_SpriteAnimator>();
  1103. }
  1104. return m_spriteAnimator;
  1105. }
  1106. }
  1107. protected TMP_SpriteAnimator m_spriteAnimator;
  1108. /// <summary>
  1109. ///
  1110. /// </summary>
  1111. //public TMP_TextShaper textShaper
  1112. //{
  1113. // get
  1114. // {
  1115. // if (m_textShaper == null)
  1116. // m_textShaper = GetComponent<TMP_TextShaper>();
  1117. // return m_textShaper;
  1118. // }
  1119. //}
  1120. //[SerializeField]
  1121. //protected TMP_TextShaper m_textShaper;
  1122. // *** PROPERTIES RELATED TO UNITY LAYOUT SYSTEM ***
  1123. /// <summary>
  1124. ///
  1125. /// </summary>
  1126. public float flexibleHeight { get { return m_flexibleHeight; } }
  1127. protected float m_flexibleHeight = -1f;
  1128. /// <summary>
  1129. ///
  1130. /// </summary>
  1131. public float flexibleWidth { get { return m_flexibleWidth; } }
  1132. protected float m_flexibleWidth = -1f;
  1133. /// <summary>
  1134. ///
  1135. /// </summary>
  1136. public float minWidth { get { return m_minWidth; } }
  1137. protected float m_minWidth;
  1138. /// <summary>
  1139. ///
  1140. /// </summary>
  1141. public float minHeight { get { return m_minHeight; } }
  1142. protected float m_minHeight;
  1143. /// <summary>
  1144. ///
  1145. /// </summary>
  1146. public float maxWidth { get { return m_maxWidth; } }
  1147. protected float m_maxWidth;
  1148. /// <summary>
  1149. ///
  1150. /// </summary>
  1151. public float maxHeight { get { return m_maxHeight; } }
  1152. protected float m_maxHeight;
  1153. /// <summary>
  1154. ///
  1155. /// </summary>
  1156. protected LayoutElement layoutElement
  1157. {
  1158. get
  1159. {
  1160. if (m_LayoutElement == null)
  1161. {
  1162. m_LayoutElement = GetComponent<LayoutElement>();
  1163. }
  1164. return m_LayoutElement;
  1165. }
  1166. }
  1167. protected LayoutElement m_LayoutElement;
  1168. /// <summary>
  1169. /// Computed preferred width of the text object.
  1170. /// </summary>
  1171. public virtual float preferredWidth { get { m_preferredWidth = GetPreferredWidth(); return m_preferredWidth; } }
  1172. protected float m_preferredWidth;
  1173. protected float m_renderedWidth;
  1174. protected bool m_isPreferredWidthDirty;
  1175. /// <summary>
  1176. /// Computed preferred height of the text object.
  1177. /// </summary>
  1178. public virtual float preferredHeight { get { m_preferredHeight = GetPreferredHeight(); return m_preferredHeight; } }
  1179. protected float m_preferredHeight;
  1180. protected float m_renderedHeight;
  1181. protected bool m_isPreferredHeightDirty;
  1182. protected bool m_isCalculatingPreferredValues;
  1183. /// <summary>
  1184. /// Compute the rendered width of the text object.
  1185. /// </summary>
  1186. public virtual float renderedWidth { get { return GetRenderedWidth(); } }
  1187. /// <summary>
  1188. /// Compute the rendered height of the text object.
  1189. /// </summary>
  1190. public virtual float renderedHeight { get { return GetRenderedHeight(); } }
  1191. /// <summary>
  1192. ///
  1193. /// </summary>
  1194. public int layoutPriority { get { return m_layoutPriority; } }
  1195. protected int m_layoutPriority = 0;
  1196. protected bool m_isLayoutDirty;
  1197. protected bool m_isAwake;
  1198. internal bool m_isWaitingOnResourceLoad;
  1199. protected struct CharacterSubstitution
  1200. {
  1201. public int index;
  1202. public uint unicode;
  1203. public CharacterSubstitution (int index, uint unicode)
  1204. {
  1205. this.index = index;
  1206. this.unicode = unicode;
  1207. }
  1208. }
  1209. // Protected Fields
  1210. internal enum TextInputSources { TextInputBox = 0, SetText = 1, SetTextArray = 2, TextString = 3 };
  1211. //[SerializeField]
  1212. internal TextInputSources m_inputSource;
  1213. protected float m_fontScaleMultiplier; // Used for handling of superscript and subscript.
  1214. private static char[] m_htmlTag = new char[128]; // Maximum length of rich text tag. This is pre-allocated to avoid GC.
  1215. private static RichTextTagAttribute[] m_xmlAttribute = new RichTextTagAttribute[8];
  1216. private static float[] m_attributeParameterValues = new float[16];
  1217. protected float tag_LineIndent = 0;
  1218. protected float tag_Indent = 0;
  1219. protected TMP_TextProcessingStack<float> m_indentStack = new TMP_TextProcessingStack<float>(new float[16]);
  1220. protected bool tag_NoParsing;
  1221. //protected TMP_LinkInfo tag_LinkInfo = new TMP_LinkInfo();
  1222. protected bool m_isParsingText;
  1223. protected Matrix4x4 m_FXMatrix;
  1224. protected bool m_isFXMatrixSet;
  1225. /// <summary>
  1226. /// Array containing the Unicode characters to be parsed.
  1227. /// </summary>
  1228. internal UnicodeChar[] m_TextProcessingArray = new UnicodeChar[8];
  1229. /// <summary>
  1230. /// The number of Unicode characters that have been parsed and contained in the m_InternalParsingBuffer
  1231. /// </summary>
  1232. internal int m_InternalTextProcessingArraySize;
  1233. [System.Diagnostics.DebuggerDisplay("Unicode ({unicode}) '{(char)unicode}'")]
  1234. internal struct UnicodeChar
  1235. {
  1236. public int unicode;
  1237. public int stringIndex;
  1238. public int length;
  1239. }
  1240. protected struct SpecialCharacter
  1241. {
  1242. public TMP_Character character;
  1243. public TMP_FontAsset fontAsset;
  1244. public Material material;
  1245. public int materialIndex;
  1246. public SpecialCharacter(TMP_Character character, int materialIndex)
  1247. {
  1248. this.character = character;
  1249. this.fontAsset = character.textAsset as TMP_FontAsset;
  1250. this.material = this.fontAsset != null ? this.fontAsset.material : null;
  1251. this.materialIndex = materialIndex;
  1252. }
  1253. }
  1254. private TMP_CharacterInfo[] m_internalCharacterInfo; // Used by functions to calculate preferred values.
  1255. protected int m_totalCharacterCount;
  1256. // Structures used to save the state of the text layout in conjunction with line breaking / word wrapping.
  1257. protected static WordWrapState m_SavedWordWrapState = new WordWrapState();
  1258. protected static WordWrapState m_SavedLineState = new WordWrapState();
  1259. protected static WordWrapState m_SavedEllipsisState = new WordWrapState();
  1260. protected static WordWrapState m_SavedLastValidState = new WordWrapState();
  1261. protected static WordWrapState m_SavedSoftLineBreakState = new WordWrapState();
  1262. //internal Stack<WordWrapState> m_LineBreakCandiateStack = new Stack<WordWrapState>();
  1263. internal static TMP_TextProcessingStack<WordWrapState> m_EllipsisInsertionCandidateStack = new TMP_TextProcessingStack<WordWrapState>(8, 8);
  1264. // Fields whose state is saved in conjunction with text parsing and word wrapping.
  1265. protected int m_characterCount;
  1266. //protected int m_visibleCharacterCount;
  1267. //protected int m_visibleSpriteCount;
  1268. protected int m_firstCharacterOfLine;
  1269. protected int m_firstVisibleCharacterOfLine;
  1270. protected int m_lastCharacterOfLine;
  1271. protected int m_lastVisibleCharacterOfLine;
  1272. protected int m_lineNumber;
  1273. protected int m_lineVisibleCharacterCount;
  1274. protected int m_pageNumber;
  1275. protected float m_PageAscender;
  1276. protected float m_maxTextAscender;
  1277. protected float m_maxCapHeight;
  1278. protected float m_ElementAscender;
  1279. protected float m_ElementDescender;
  1280. protected float m_maxLineAscender;
  1281. protected float m_maxLineDescender;
  1282. protected float m_startOfLineAscender;
  1283. protected float m_startOfLineDescender;
  1284. //protected float m_maxFontScale;
  1285. protected float m_lineOffset;
  1286. protected Extents m_meshExtents;
  1287. // Fields used for vertex colors
  1288. protected Color32 m_htmlColor = new Color(255, 255, 255, 128);
  1289. protected TMP_TextProcessingStack<Color32> m_colorStack = new TMP_TextProcessingStack<Color32>(new Color32[16]);
  1290. protected TMP_TextProcessingStack<Color32> m_underlineColorStack = new TMP_TextProcessingStack<Color32>(new Color32[16]);
  1291. protected TMP_TextProcessingStack<Color32> m_strikethroughColorStack = new TMP_TextProcessingStack<Color32>(new Color32[16]);
  1292. protected TMP_TextProcessingStack<HighlightState> m_HighlightStateStack = new TMP_TextProcessingStack<HighlightState>(new HighlightState[16]);
  1293. protected TMP_ColorGradient m_colorGradientPreset;
  1294. protected TMP_TextProcessingStack<TMP_ColorGradient> m_colorGradientStack = new TMP_TextProcessingStack<TMP_ColorGradient>(new TMP_ColorGradient[16]);
  1295. protected bool m_colorGradientPresetIsTinted;
  1296. protected float m_tabSpacing = 0;
  1297. protected float m_spacing = 0;
  1298. // STYLE TAGS
  1299. protected TMP_TextProcessingStack<int>[] m_TextStyleStacks = new TMP_TextProcessingStack<int>[8];
  1300. protected int m_TextStyleStackDepth = 0;
  1301. protected TMP_TextProcessingStack<int> m_ItalicAngleStack = new TMP_TextProcessingStack<int>(new int[16]);
  1302. protected int m_ItalicAngle;
  1303. protected TMP_TextProcessingStack<int> m_actionStack = new TMP_TextProcessingStack<int>(new int[16]);
  1304. protected float m_padding = 0;
  1305. protected float m_baselineOffset; // Used for superscript and subscript.
  1306. protected TMP_TextProcessingStack<float> m_baselineOffsetStack = new TMP_TextProcessingStack<float>(new float[16]);
  1307. protected float m_xAdvance; // Tracks x advancement from character to character.
  1308. protected TMP_TextElementType m_textElementType;
  1309. protected TMP_TextElement m_cached_TextElement; // Glyph / Character information is cached into this variable which is faster than having to fetch from the Dictionary multiple times.
  1310. protected SpecialCharacter m_Ellipsis;
  1311. protected SpecialCharacter m_Underline;
  1312. protected TMP_SpriteAsset m_defaultSpriteAsset;
  1313. protected TMP_SpriteAsset m_currentSpriteAsset;
  1314. protected int m_spriteCount = 0;
  1315. protected int m_spriteIndex;
  1316. protected int m_spriteAnimationID;
  1317. // Profiler Marker declarations
  1318. private static ProfilerMarker k_ParseTextMarker = new ProfilerMarker("TMP Parse Text");
  1319. private static ProfilerMarker k_InsertNewLineMarker = new ProfilerMarker("TMP.InsertNewLine");
  1320. /// <summary>
  1321. /// Method which derived classes need to override to load Font Assets.
  1322. /// </summary>
  1323. protected virtual void LoadFontAsset() { }
  1324. /// <summary>
  1325. /// Function called internally when a new shared material is assigned via the fontSharedMaterial property.
  1326. /// </summary>
  1327. /// <param name="mat"></param>
  1328. protected virtual void SetSharedMaterial(Material mat) { }
  1329. /// <summary>
  1330. /// Function called internally when a new material is assigned via the fontMaterial property.
  1331. /// </summary>
  1332. protected virtual Material GetMaterial(Material mat) { return null; }
  1333. /// <summary>
  1334. /// Function called internally when assigning a new base material.
  1335. /// </summary>
  1336. /// <param name="mat"></param>
  1337. protected virtual void SetFontBaseMaterial(Material mat) { }
  1338. /// <summary>
  1339. /// Method which returns an array containing the materials used by the text object.
  1340. /// </summary>
  1341. /// <returns></returns>
  1342. protected virtual Material[] GetSharedMaterials() { return null; }
  1343. /// <summary>
  1344. ///
  1345. /// </summary>
  1346. protected virtual void SetSharedMaterials(Material[] materials) { }
  1347. /// <summary>
  1348. /// Method returning instances of the materials used by the text object.
  1349. /// </summary>
  1350. /// <returns></returns>
  1351. protected virtual Material[] GetMaterials(Material[] mats) { return null; }
  1352. /// <summary>
  1353. /// Method to set the materials of the text and sub text objects.
  1354. /// </summary>
  1355. /// <param name="mats"></param>
  1356. //protected virtual void SetMaterials (Material[] mats) { }
  1357. /// <summary>
  1358. /// Function used to create an instance of the material
  1359. /// </summary>
  1360. /// <param name="source"></param>
  1361. /// <returns></returns>
  1362. protected virtual Material CreateMaterialInstance(Material source)
  1363. {
  1364. Material mat = new Material(source);
  1365. mat.shaderKeywords = source.shaderKeywords;
  1366. mat.name += " (Instance)";
  1367. return mat;
  1368. }
  1369. protected void SetVertexColorGradient(TMP_ColorGradient gradient)
  1370. {
  1371. if (gradient == null) return;
  1372. m_fontColorGradient.bottomLeft = gradient.bottomLeft;
  1373. m_fontColorGradient.bottomRight = gradient.bottomRight;
  1374. m_fontColorGradient.topLeft = gradient.topLeft;
  1375. m_fontColorGradient.topRight = gradient.topRight;
  1376. SetVerticesDirty();
  1377. }
  1378. /// <summary>
  1379. /// Function to control the sorting of the geometry of the text object.
  1380. /// </summary>
  1381. protected void SetTextSortingOrder(VertexSortingOrder order)
  1382. {
  1383. }
  1384. /// <summary>
  1385. /// Function to sort the geometry of the text object in accordance to the provided order.
  1386. /// </summary>
  1387. /// <param name="order"></param>
  1388. protected void SetTextSortingOrder(int[] order)
  1389. {
  1390. }
  1391. /// <summary>
  1392. /// Function called internally to set the face color of the material. This will results in an instance of the material.
  1393. /// </summary>
  1394. /// <param name="color"></param>
  1395. protected virtual void SetFaceColor(Color32 color) { }
  1396. /// <summary>
  1397. /// Function called internally to set the outline color of the material. This will results in an instance of the material.
  1398. /// </summary>
  1399. /// <param name="color"></param>
  1400. protected virtual void SetOutlineColor(Color32 color) { }
  1401. /// <summary>
  1402. /// Function called internally to set the outline thickness property of the material. This will results in an instance of the material.
  1403. /// </summary>
  1404. /// <param name="thickness"></param>
  1405. protected virtual void SetOutlineThickness(float thickness) { }
  1406. /// <summary>
  1407. /// Set the Render Queue and ZTest mode on the current material
  1408. /// </summary>
  1409. protected virtual void SetShaderDepth() { }
  1410. /// <summary>
  1411. /// Set the culling mode on the material.
  1412. /// </summary>
  1413. protected virtual void SetCulling() { }
  1414. /// <summary>
  1415. ///
  1416. /// </summary>
  1417. internal virtual void UpdateCulling() {}
  1418. /// <summary>
  1419. /// Get the padding value for the currently assigned material
  1420. /// </summary>
  1421. /// <returns></returns>
  1422. protected virtual float GetPaddingForMaterial()
  1423. {
  1424. ShaderUtilities.GetShaderPropertyIDs();
  1425. if (m_sharedMaterial == null) return 0;
  1426. m_padding = ShaderUtilities.GetPadding(m_sharedMaterial, m_enableExtraPadding, m_isUsingBold);
  1427. m_isMaskingEnabled = ShaderUtilities.IsMaskingEnabled(m_sharedMaterial);
  1428. m_isSDFShader = m_sharedMaterial.HasProperty(ShaderUtilities.ID_WeightNormal);
  1429. return m_padding;
  1430. }
  1431. /// <summary>
  1432. /// Get the padding value for the given material
  1433. /// </summary>
  1434. /// <returns></returns>
  1435. protected virtual float GetPaddingForMaterial(Material mat)
  1436. {
  1437. if (mat == null)
  1438. return 0;
  1439. m_padding = ShaderUtilities.GetPadding(mat, m_enableExtraPadding, m_isUsingBold);
  1440. m_isMaskingEnabled = ShaderUtilities.IsMaskingEnabled(m_sharedMaterial);
  1441. m_isSDFShader = mat.HasProperty(ShaderUtilities.ID_WeightNormal);
  1442. return m_padding;
  1443. }
  1444. /// <summary>
  1445. /// Method to return the local corners of the Text Container or RectTransform.
  1446. /// </summary>
  1447. /// <returns></returns>
  1448. protected virtual Vector3[] GetTextContainerLocalCorners() { return null; }
  1449. // PUBLIC FUNCTIONS
  1450. protected bool m_ignoreActiveState;
  1451. /// <summary>
  1452. /// Function to force regeneration of the text object before its normal process time. This is useful when changes to the text object properties need to be applied immediately.
  1453. /// </summary>
  1454. /// <param name="ignoreActiveState">Ignore Active State of text objects. Inactive objects are ignored by default.</param>
  1455. /// <param name="forceTextReparsing">Force re-parsing of the text.</param>
  1456. public virtual void ForceMeshUpdate(bool ignoreActiveState = false, bool forceTextReparsing = false) { }
  1457. /// <summary>
  1458. /// Function to update the geometry of the main and sub text objects.
  1459. /// </summary>
  1460. /// <param name="mesh"></param>
  1461. /// <param name="index"></param>
  1462. public virtual void UpdateGeometry(Mesh mesh, int index) { }
  1463. /// <summary>
  1464. /// Function to push the updated vertex data into the mesh and renderer.
  1465. /// </summary>
  1466. public virtual void UpdateVertexData(TMP_VertexDataUpdateFlags flags) { }
  1467. /// <summary>
  1468. /// Function to push the updated vertex data into the mesh and renderer.
  1469. /// </summary>
  1470. public virtual void UpdateVertexData() { }
  1471. /// <summary>
  1472. /// Function to push a new set of vertices to the mesh.
  1473. /// </summary>
  1474. /// <param name="vertices"></param>
  1475. public virtual void SetVertices(Vector3[] vertices) { }
  1476. /// <summary>
  1477. /// Function to be used to force recomputing of character padding when Shader / Material properties have been changed via script.
  1478. /// </summary>
  1479. public virtual void UpdateMeshPadding() { }
  1480. /// <summary>
  1481. ///
  1482. /// </summary>
  1483. //public virtual new void UpdateGeometry() { }
  1484. /// <summary>
  1485. /// Tweens the CanvasRenderer color associated with this Graphic.
  1486. /// </summary>
  1487. /// <param name="targetColor">Target color.</param>
  1488. /// <param name="duration">Tween duration.</param>
  1489. /// <param name="ignoreTimeScale">Should ignore Time.scale?</param>
  1490. /// <param name="useAlpha">Should also Tween the alpha channel?</param>
  1491. public override void CrossFadeColor(Color targetColor, float duration, bool ignoreTimeScale, bool useAlpha)
  1492. {
  1493. base.CrossFadeColor(targetColor, duration, ignoreTimeScale, useAlpha);
  1494. InternalCrossFadeColor(targetColor, duration, ignoreTimeScale, useAlpha);
  1495. }
  1496. /// <summary>
  1497. /// Tweens the alpha of the CanvasRenderer color associated with this Graphic.
  1498. /// </summary>
  1499. /// <param name="alpha">Target alpha.</param>
  1500. /// <param name="duration">Duration of the tween in seconds.</param>
  1501. /// <param name="ignoreTimeScale">Should ignore Time.scale?</param>
  1502. public override void CrossFadeAlpha(float alpha, float duration, bool ignoreTimeScale)
  1503. {
  1504. base.CrossFadeAlpha(alpha, duration, ignoreTimeScale);
  1505. InternalCrossFadeAlpha(alpha, duration, ignoreTimeScale);
  1506. }
  1507. /// <summary>
  1508. ///
  1509. /// </summary>
  1510. /// <param name="targetColor"></param>
  1511. /// <param name="duration"></param>
  1512. /// <param name="ignoreTimeScale"></param>
  1513. /// <param name="useAlpha"></param>
  1514. /// <param name="useRGB"></param>
  1515. protected virtual void InternalCrossFadeColor(Color targetColor, float duration, bool ignoreTimeScale, bool useAlpha) { }
  1516. /// <summary>
  1517. ///
  1518. /// </summary>
  1519. /// <param name="alpha"></param>
  1520. /// <param name="duration"></param>
  1521. /// <param name="ignoreTimeScale"></param>
  1522. protected virtual void InternalCrossFadeAlpha(float alpha, float duration, bool ignoreTimeScale) { }
  1523. /// <summary>
  1524. ///
  1525. /// </summary>
  1526. struct TextBackingContainer
  1527. {
  1528. public int Capacity
  1529. {
  1530. get { return m_Array.Length; }
  1531. }
  1532. public int Count
  1533. {
  1534. get { return m_Count; }
  1535. set { m_Count = value; }
  1536. }
  1537. private uint[] m_Array;
  1538. private int m_Count;
  1539. public uint this[int index]
  1540. {
  1541. get { return m_Array[index]; }
  1542. set
  1543. {
  1544. if (index >= m_Array.Length)
  1545. Resize(index);
  1546. m_Array[index] = value;
  1547. }
  1548. }
  1549. public TextBackingContainer(int size)
  1550. {
  1551. m_Array = new uint[size];
  1552. m_Count = 0;
  1553. }
  1554. public void Resize(int size)
  1555. {
  1556. size = Mathf.NextPowerOfTwo(size + 1);
  1557. Array.Resize(ref m_Array, size);
  1558. }
  1559. }
  1560. /// <summary>
  1561. /// Internal array containing the converted source text used in the text parsing process.
  1562. /// </summary>
  1563. private TextBackingContainer m_TextBackingArray = new TextBackingContainer(4);
  1564. /// <summary>
  1565. /// Method to parse the input text based on its source
  1566. /// </summary>
  1567. protected void ParseInputText()
  1568. {
  1569. k_ParseTextMarker.Begin();
  1570. switch (m_inputSource)
  1571. {
  1572. case TextInputSources.TextString:
  1573. case TextInputSources.TextInputBox:
  1574. PopulateTextBackingArray(m_TextPreprocessor == null ? m_text : m_TextPreprocessor.PreprocessText(m_text));
  1575. PopulateTextProcessingArray();
  1576. break;
  1577. case TextInputSources.SetText:
  1578. break;
  1579. case TextInputSources.SetTextArray:
  1580. break;
  1581. }
  1582. SetArraySizes(m_TextProcessingArray);
  1583. k_ParseTextMarker.End();
  1584. }
  1585. /// <summary>
  1586. /// Convert source text to Unicode (uint) and populate internal text backing array.
  1587. /// </summary>
  1588. /// <param name="sourceText">Source text to be converted</param>
  1589. void PopulateTextBackingArray(string sourceText)
  1590. {
  1591. int srcLength = sourceText == null ? 0 : sourceText.Length;
  1592. PopulateTextBackingArray(sourceText, 0, srcLength);
  1593. }
  1594. /// <summary>
  1595. /// Convert source text to uint and populate internal text backing array.
  1596. /// </summary>
  1597. /// <param name="sourceText">string containing the source text to be converted</param>
  1598. /// <param name="start">Index of the first element of the source array to be converted and copied to the internal text backing array.</param>
  1599. /// <param name="length">Number of elements in the array to be converted and copied to the internal text backing array.</param>
  1600. void PopulateTextBackingArray(string sourceText, int start, int length)
  1601. {
  1602. int readIndex;
  1603. int writeIndex = 0;
  1604. // Range check
  1605. if (sourceText == null)
  1606. {
  1607. readIndex = 0;
  1608. length = 0;
  1609. }
  1610. else
  1611. {
  1612. readIndex = Mathf.Clamp(start, 0, sourceText.Length);
  1613. length = Mathf.Clamp(length, 0, start + length < sourceText.Length ? length : sourceText.Length - start);
  1614. }
  1615. // Make sure array size is appropriate
  1616. if (length >= m_TextBackingArray.Capacity)
  1617. m_TextBackingArray.Resize((length));
  1618. int end = readIndex + length;
  1619. for (; readIndex < end; readIndex++)
  1620. {
  1621. m_TextBackingArray[writeIndex] = sourceText[readIndex];
  1622. writeIndex += 1;
  1623. }
  1624. // Terminate array with zero as we are not clearing the array on new invocation of this function.
  1625. m_TextBackingArray[writeIndex] = 0;
  1626. m_TextBackingArray.Count = writeIndex;
  1627. }
  1628. /// <summary>
  1629. /// Convert source text to uint and populate internal text backing array.
  1630. /// </summary>
  1631. /// <param name="sourceText">char array containing the source text to be converted</param>
  1632. /// <param name="start">Index of the first element of the source array to be converted and copied to the internal text backing array.</param>
  1633. /// <param name="length">Number of elements in the array to be converted and copied to the internal text backing array.</param>
  1634. void PopulateTextBackingArray(StringBuilder sourceText, int start, int length)
  1635. {
  1636. int readIndex;
  1637. int writeIndex = 0;
  1638. // Range check
  1639. if (sourceText == null)
  1640. {
  1641. readIndex = 0;
  1642. length = 0;
  1643. }
  1644. else
  1645. {
  1646. readIndex = Mathf.Clamp(start, 0, sourceText.Length);
  1647. length = Mathf.Clamp(length, 0, start + length < sourceText.Length ? length : sourceText.Length - start);
  1648. }
  1649. // Make sure array size is appropriate
  1650. if (length >= m_TextBackingArray.Capacity)
  1651. m_TextBackingArray.Resize((length));
  1652. int end = readIndex + length;
  1653. for (; readIndex < end; readIndex++)
  1654. {
  1655. m_TextBackingArray[writeIndex] = sourceText[readIndex];
  1656. writeIndex += 1;
  1657. }
  1658. // Terminate array with zero as we are not clearing the array on new invocation of this function.
  1659. m_TextBackingArray[writeIndex] = 0;
  1660. m_TextBackingArray.Count = writeIndex;
  1661. }
  1662. /// <summary>
  1663. /// Convert source text to Unicode (uint) and populate internal text backing array.
  1664. /// </summary>
  1665. /// <param name="sourceText">char array containing the source text to be converted</param>
  1666. /// <param name="start">Index of the first element of the source array to be converted and copied to the internal text backing array.</param>
  1667. /// <param name="length">Number of elements in the array to be converted and copied to the internal text backing array.</param>
  1668. void PopulateTextBackingArray(char[] sourceText, int start, int length)
  1669. {
  1670. int readIndex;
  1671. int writeIndex = 0;
  1672. // Range check
  1673. if (sourceText == null)
  1674. {
  1675. readIndex = 0;
  1676. length = 0;
  1677. }
  1678. else
  1679. {
  1680. readIndex = Mathf.Clamp(start, 0, sourceText.Length);
  1681. length = Mathf.Clamp(length, 0, start + length < sourceText.Length ? length : sourceText.Length - start);
  1682. }
  1683. // Make sure array size is appropriate
  1684. if (length >= m_TextBackingArray.Capacity)
  1685. m_TextBackingArray.Resize((length));
  1686. int end = readIndex + length;
  1687. for (; readIndex < end; readIndex++)
  1688. {
  1689. m_TextBackingArray[writeIndex] = sourceText[readIndex];
  1690. writeIndex += 1;
  1691. }
  1692. // Terminate array with zero as we are not clearing the array on new invocation of this function.
  1693. m_TextBackingArray[writeIndex] = 0;
  1694. m_TextBackingArray.Count = writeIndex;
  1695. }
  1696. /// <summary>
  1697. ///
  1698. /// </summary>
  1699. void PopulateTextProcessingArray()
  1700. {
  1701. int srcLength = m_TextBackingArray.Count;
  1702. // Make sure parsing buffer is large enough to handle the required text.
  1703. if (m_TextProcessingArray.Length < srcLength)
  1704. ResizeInternalArray(ref m_TextProcessingArray, srcLength);
  1705. // Reset Style stack back to default
  1706. TMP_TextProcessingStack<int>.SetDefault(m_TextStyleStacks, 0);
  1707. m_TextStyleStackDepth = 0;
  1708. int writeIndex = 0;
  1709. // Insert Opening Style
  1710. if (textStyle.hashCode != (int)MarkupTag.NORMAL)
  1711. InsertOpeningStyleTag(m_TextStyle, 0, ref m_TextProcessingArray, ref writeIndex);
  1712. int readIndex = 0;
  1713. for (; readIndex < srcLength; readIndex++)
  1714. {
  1715. uint c = m_TextBackingArray[readIndex];
  1716. if (c == 0)
  1717. break;
  1718. if (m_inputSource == TextInputSources.TextInputBox && c == '\\' && readIndex < srcLength - 1)
  1719. {
  1720. switch (m_TextBackingArray[readIndex + 1])
  1721. {
  1722. case 92: // \ escape
  1723. if (!m_parseCtrlCharacters) break;
  1724. if (srcLength <= readIndex + 2) break;
  1725. if (writeIndex + 2 > m_TextProcessingArray.Length) ResizeInternalArray(ref m_TextProcessingArray);
  1726. m_TextProcessingArray[writeIndex].unicode = (int)m_TextBackingArray[readIndex + 1];
  1727. m_TextProcessingArray[writeIndex].stringIndex = readIndex;
  1728. m_TextProcessingArray[writeIndex].length = 1;
  1729. m_TextProcessingArray[writeIndex + 1].unicode = (int)m_TextBackingArray[readIndex + 2];
  1730. m_TextProcessingArray[writeIndex + 1].stringIndex = readIndex;
  1731. m_TextProcessingArray[writeIndex + 1].length = 1;
  1732. readIndex += 2;
  1733. writeIndex += 2;
  1734. continue;
  1735. case 110: // \n LineFeed
  1736. if (!m_parseCtrlCharacters) break;
  1737. if (writeIndex == m_TextProcessingArray.Length) ResizeInternalArray(ref m_TextProcessingArray);
  1738. m_TextProcessingArray[writeIndex].unicode = 10;
  1739. m_TextProcessingArray[writeIndex].stringIndex = readIndex;
  1740. m_TextProcessingArray[writeIndex].length = 1;
  1741. readIndex += 1;
  1742. writeIndex += 1;
  1743. continue;
  1744. case 114: // \r Carriage Return
  1745. if (!m_parseCtrlCharacters) break;
  1746. if (writeIndex == m_TextProcessingArray.Length) ResizeInternalArray(ref m_TextProcessingArray);
  1747. m_TextProcessingArray[writeIndex].unicode = 13;
  1748. m_TextProcessingArray[writeIndex].stringIndex = readIndex;
  1749. m_TextProcessingArray[writeIndex].length = 1;
  1750. readIndex += 1;
  1751. writeIndex += 1;
  1752. continue;
  1753. case 116: // \t Tab
  1754. if (!m_parseCtrlCharacters) break;
  1755. if (writeIndex == m_TextProcessingArray.Length) ResizeInternalArray(ref m_TextProcessingArray);
  1756. m_TextProcessingArray[writeIndex].unicode = 9;
  1757. m_TextProcessingArray[writeIndex].stringIndex = readIndex;
  1758. m_TextProcessingArray[writeIndex].length = 1;
  1759. readIndex += 1;
  1760. writeIndex += 1;
  1761. continue;
  1762. case 118: // \v Vertical tab used as soft line break
  1763. if (!m_parseCtrlCharacters) break;
  1764. if (writeIndex == m_TextProcessingArray.Length) ResizeInternalArray(ref m_TextProcessingArray);
  1765. m_TextProcessingArray[writeIndex].unicode = 11;
  1766. m_TextProcessingArray[writeIndex].stringIndex = readIndex;
  1767. m_TextProcessingArray[writeIndex].length = 1;
  1768. readIndex += 1;
  1769. writeIndex += 1;
  1770. continue;
  1771. case 117: // \u0000 for UTF-16 Unicode
  1772. if (srcLength > readIndex + 5)
  1773. {
  1774. if (writeIndex == m_TextProcessingArray.Length) ResizeInternalArray(ref m_TextProcessingArray);
  1775. m_TextProcessingArray[writeIndex].unicode = GetUTF16(m_TextBackingArray, readIndex + 2);
  1776. m_TextProcessingArray[writeIndex].stringIndex = readIndex;
  1777. m_TextProcessingArray[writeIndex].length = 6;
  1778. readIndex += 5;
  1779. writeIndex += 1;
  1780. continue;
  1781. }
  1782. break;
  1783. case 85: // \U00000000 for UTF-32 Unicode
  1784. if (srcLength > readIndex + 9)
  1785. {
  1786. if (writeIndex == m_TextProcessingArray.Length) ResizeInternalArray(ref m_TextProcessingArray);
  1787. m_TextProcessingArray[writeIndex].unicode = GetUTF32(m_TextBackingArray, readIndex + 2);
  1788. m_TextProcessingArray[writeIndex].stringIndex = readIndex;
  1789. m_TextProcessingArray[writeIndex].length = 10;
  1790. readIndex += 9;
  1791. writeIndex += 1;
  1792. continue;
  1793. }
  1794. break;
  1795. }
  1796. }
  1797. // Handle surrogate pair conversion in string, StringBuilder and char[] source.
  1798. if (c >= CodePoint.HIGH_SURROGATE_START && c <= CodePoint.HIGH_SURROGATE_END && srcLength > readIndex + 1 && m_TextBackingArray[readIndex + 1] >= CodePoint.LOW_SURROGATE_START && m_TextBackingArray[readIndex + 1] <= CodePoint.LOW_SURROGATE_END)
  1799. {
  1800. if (writeIndex == m_TextProcessingArray.Length) ResizeInternalArray(ref m_TextProcessingArray);
  1801. m_TextProcessingArray[writeIndex].unicode = (int)TMP_TextParsingUtilities.ConvertToUTF32(c, m_TextBackingArray[readIndex + 1]);
  1802. m_TextProcessingArray[writeIndex].stringIndex = readIndex;
  1803. m_TextProcessingArray[writeIndex].length = 2;
  1804. readIndex += 1;
  1805. writeIndex += 1;
  1806. continue;
  1807. }
  1808. // Handle inline replacement of <style> and <br> tags.
  1809. if (c == '<' && m_isRichText)
  1810. {
  1811. // Read tag hash code
  1812. int hashCode = GetMarkupTagHashCode(m_TextBackingArray, readIndex + 1);
  1813. switch ((MarkupTag)hashCode)
  1814. {
  1815. case MarkupTag.BR:
  1816. if (writeIndex == m_TextProcessingArray.Length) ResizeInternalArray(ref m_TextProcessingArray);
  1817. m_TextProcessingArray[writeIndex].unicode = 10;
  1818. m_TextProcessingArray[writeIndex].stringIndex = readIndex;
  1819. m_TextProcessingArray[writeIndex].length = 4;
  1820. writeIndex += 1;
  1821. readIndex += 3;
  1822. continue;
  1823. case MarkupTag.NBSP:
  1824. if (writeIndex == m_TextProcessingArray.Length) ResizeInternalArray(ref m_TextProcessingArray);
  1825. m_TextProcessingArray[writeIndex].unicode = 160;
  1826. m_TextProcessingArray[writeIndex].stringIndex = readIndex;
  1827. m_TextProcessingArray[writeIndex].length = 6;
  1828. writeIndex += 1;
  1829. readIndex += 5;
  1830. continue;
  1831. case MarkupTag.ZWSP:
  1832. if (writeIndex == m_TextProcessingArray.Length) ResizeInternalArray(ref m_TextProcessingArray);
  1833. m_TextProcessingArray[writeIndex].unicode = 0x200B;
  1834. m_TextProcessingArray[writeIndex].stringIndex = readIndex;
  1835. m_TextProcessingArray[writeIndex].length = 6;
  1836. writeIndex += 1;
  1837. readIndex += 5;
  1838. continue;
  1839. case MarkupTag.STYLE:
  1840. int openWriteIndex = writeIndex;
  1841. if (ReplaceOpeningStyleTag(ref m_TextBackingArray, readIndex, out int srcOffset, ref m_TextProcessingArray, ref writeIndex))
  1842. {
  1843. // Update potential text elements added by the opening style.
  1844. for (; openWriteIndex < writeIndex; openWriteIndex++)
  1845. {
  1846. m_TextProcessingArray[openWriteIndex].stringIndex = readIndex;
  1847. m_TextProcessingArray[openWriteIndex].length = (srcOffset - readIndex) + 1;
  1848. }
  1849. readIndex = srcOffset;
  1850. continue;
  1851. }
  1852. break;
  1853. case MarkupTag.SLASH_STYLE:
  1854. int closeWriteIndex = writeIndex;
  1855. ReplaceClosingStyleTag(ref m_TextBackingArray, readIndex, ref m_TextProcessingArray, ref writeIndex);
  1856. // Update potential text elements added by the closing style.
  1857. for (; closeWriteIndex < writeIndex; closeWriteIndex++)
  1858. {
  1859. m_TextProcessingArray[closeWriteIndex].stringIndex = readIndex;
  1860. m_TextProcessingArray[closeWriteIndex].length = 8;
  1861. }
  1862. readIndex += 7;
  1863. continue;
  1864. }
  1865. }
  1866. if (writeIndex == m_TextProcessingArray.Length) ResizeInternalArray(ref m_TextProcessingArray);
  1867. m_TextProcessingArray[writeIndex].unicode = (int)c;
  1868. m_TextProcessingArray[writeIndex].stringIndex = readIndex;
  1869. m_TextProcessingArray[writeIndex].length = 1;
  1870. writeIndex += 1;
  1871. }
  1872. m_TextStyleStackDepth = 0;
  1873. // Insert Closing Style
  1874. if (textStyle.hashCode != (int)MarkupTag.NORMAL)
  1875. InsertClosingStyleTag(ref m_TextProcessingArray, ref writeIndex);
  1876. if (writeIndex == m_TextProcessingArray.Length) ResizeInternalArray(ref m_TextProcessingArray);
  1877. m_TextProcessingArray[writeIndex].unicode = 0;
  1878. m_InternalTextProcessingArraySize = writeIndex;
  1879. }
  1880. /// <summary>
  1881. /// Function used in conjunction with GetPreferredValues
  1882. /// </summary>
  1883. /// <param name="sourceText"></param>
  1884. void SetTextInternal(string sourceText)
  1885. {
  1886. int srcLength = sourceText == null ? 0 : sourceText.Length;
  1887. PopulateTextBackingArray(sourceText, 0, srcLength);
  1888. // Set input source
  1889. TextInputSources currentInputSource = m_inputSource;
  1890. m_inputSource = TextInputSources.TextString;
  1891. PopulateTextProcessingArray();
  1892. m_inputSource = currentInputSource;
  1893. }
  1894. /// <summary>
  1895. /// This function is the same as using the text property to set the text.
  1896. /// </summary>
  1897. /// <param name="sourceText">String containing the text.</param>
  1898. /// <param name="syncTextInputBox">This optional parameter no longer provides any functionality as this function now simple sets the .text property which is reflected in the Text Input Box.</param>
  1899. public void SetText(string sourceText, bool syncTextInputBox = true)
  1900. {
  1901. int srcLength = sourceText == null ? 0 : sourceText.Length;
  1902. PopulateTextBackingArray(sourceText, 0, srcLength);
  1903. m_text = sourceText;
  1904. // Set input source
  1905. m_inputSource = TextInputSources.TextString;
  1906. PopulateTextProcessingArray();
  1907. m_havePropertiesChanged = true;
  1908. SetVerticesDirty();
  1909. SetLayoutDirty();
  1910. }
  1911. /// <summary>
  1912. /// <para>Formatted string containing a pattern and a value representing the text to be rendered.</para>
  1913. /// <para>Ex. TMP_Text.SetText("A = {0}, B = {1:00}, C = {2:000.0}", 10.75f, 10.75f, 10.75f);</para>
  1914. /// <para>Results "A = 10.75, B = 11, C = 010.8."</para>
  1915. /// </summary>
  1916. /// <param name="sourceText">String containing the pattern.</param>
  1917. /// <param name="arg0">First float value.</param>
  1918. public void SetText(string sourceText, float arg0)
  1919. {
  1920. SetText(sourceText, arg0, 0, 0, 0, 0, 0, 0, 0);
  1921. }
  1922. /// <summary>
  1923. /// <para>Formatted string containing a pattern and a value representing the text to be rendered.</para>
  1924. /// <para>Ex. TMP_Text.SetText("A = {0}, B = {1:00}, C = {2:000.0}", 10.75f, 10.75f, 10.75f);</para>
  1925. /// <para>Results "A = 10.75, B = 11, C = 010.8."</para>
  1926. /// </summary>
  1927. /// <param name="sourceText">String containing the pattern.</param>
  1928. /// <param name="arg0">First float value.</param>
  1929. /// <param name="arg1">Second float value.</param>
  1930. public void SetText(string sourceText, float arg0, float arg1)
  1931. {
  1932. SetText(sourceText, arg0, arg1, 0, 0, 0, 0, 0, 0);
  1933. }
  1934. /// <summary>
  1935. /// <para>Formatted string containing a pattern and a value representing the text to be rendered.</para>
  1936. /// <para>Ex. TMP_Text.SetText("A = {0}, B = {1:00}, C = {2:000.0}", 10.75f, 10.75f, 10.75f);</para>
  1937. /// <para>Results "A = 10.75, B = 11, C = 010.8."</para>
  1938. /// </summary>
  1939. /// <param name="sourceText">String containing the pattern.</param>
  1940. /// <param name="arg0">First float value.</param>
  1941. /// <param name="arg1">Second float value.</param>
  1942. /// <param name="arg2">Third float value.</param>
  1943. public void SetText(string sourceText, float arg0, float arg1, float arg2)
  1944. {
  1945. SetText(sourceText, arg0, arg1, arg2, 0, 0, 0, 0, 0);
  1946. }
  1947. /// <summary>
  1948. /// <para>Formatted string containing a pattern and a value representing the text to be rendered.</para>
  1949. /// <para>Ex. TMP_Text.SetText("A = {0}, B = {1:00}, C = {2:000.0}", 10.75f, 10.75f, 10.75f);</para>
  1950. /// <para>Results "A = 10.75, B = 11, C = 010.8."</para>
  1951. /// </summary>
  1952. /// <param name="sourceText">String containing the pattern.</param>
  1953. /// <param name="arg0">First float value.</param>
  1954. /// <param name="arg1">Second float value.</param>
  1955. /// <param name="arg2">Third float value.</param>
  1956. /// <param name="arg3">Forth float value.</param>
  1957. public void SetText(string sourceText, float arg0, float arg1, float arg2, float arg3)
  1958. {
  1959. SetText(sourceText, arg0, arg1, arg2, arg3, 0, 0, 0, 0);
  1960. }
  1961. /// <summary>
  1962. /// <para>Formatted string containing a pattern and a value representing the text to be rendered.</para>
  1963. /// <para>Ex. TMP_Text.SetText("A = {0}, B = {1:00}, C = {2:000.0}", 10.75f, 10.75f, 10.75f);</para>
  1964. /// <para>Results "A = 10.75, B = 11, C = 010.8."</para>
  1965. /// </summary>
  1966. /// <param name="sourceText">String containing the pattern.</param>
  1967. /// <param name="arg0">First float value.</param>
  1968. /// <param name="arg1">Second float value.</param>
  1969. /// <param name="arg2">Third float value.</param>
  1970. /// <param name="arg3">Forth float value.</param>
  1971. /// <param name="arg4">Fifth float value.</param>
  1972. public void SetText(string sourceText, float arg0, float arg1, float arg2, float arg3, float arg4)
  1973. {
  1974. SetText(sourceText, arg0, arg1, arg2, arg3, arg4, 0, 0, 0);
  1975. }
  1976. /// <summary>
  1977. /// <para>Formatted string containing a pattern and a value representing the text to be rendered.</para>
  1978. /// <para>Ex. TMP_Text.SetText("A = {0}, B = {1:00}, C = {2:000.0}", 10.75f, 10.75f, 10.75f);</para>
  1979. /// <para>Results "A = 10.75, B = 11, C = 010.8."</para>
  1980. /// </summary>
  1981. /// <param name="sourceText">String containing the pattern.</param>
  1982. /// <param name="arg0">First float value.</param>
  1983. /// <param name="arg1">Second float value.</param>
  1984. /// <param name="arg2">Third float value.</param>
  1985. /// <param name="arg3">Forth float value.</param>
  1986. /// <param name="arg4">Fifth float value.</param>
  1987. /// <param name="arg5">Sixth float value.</param>
  1988. public void SetText(string sourceText, float arg0, float arg1, float arg2, float arg3, float arg4, float arg5)
  1989. {
  1990. SetText(sourceText, arg0, arg1, arg2, arg3, arg4, arg5, 0, 0);
  1991. }
  1992. /// <summary>
  1993. /// <para>Formatted string containing a pattern and a value representing the text to be rendered.</para>
  1994. /// <para>Ex. TMP_Text.SetText("A = {0}, B = {1:00}, C = {2:000.0}", 10.75f, 10.75f, 10.75f);</para>
  1995. /// <para>Results "A = 10.75, B = 11, C = 010.8."</para>
  1996. /// </summary>
  1997. /// <param name="sourceText">String containing the pattern.</param>
  1998. /// <param name="arg0">First float value.</param>
  1999. /// <param name="arg1">Second float value.</param>
  2000. /// <param name="arg2">Third float value.</param>
  2001. /// <param name="arg3">Forth float value.</param>
  2002. /// <param name="arg4">Fifth float value.</param>
  2003. /// <param name="arg5">Sixth float value.</param>
  2004. /// <param name="arg6">Seventh float value.</param>
  2005. public void SetText(string sourceText, float arg0, float arg1, float arg2, float arg3, float arg4, float arg5, float arg6)
  2006. {
  2007. SetText(sourceText, arg0, arg1, arg2, arg3, arg4, arg5, arg6, 0);
  2008. }
  2009. /// <summary>
  2010. /// <para>Formatted string containing a pattern and a value representing the text to be rendered.</para>
  2011. /// <para>Ex. TMP_Text.SetText("A = {0}, B = {1:00}, C = {2:000.0}", 10.75f, 10.75f, 10.75f);</para>
  2012. /// <para>Results "A = 10.75, B = 11, C = 010.8."</para>
  2013. /// </summary>
  2014. /// <param name="sourceText">String containing the pattern.</param>
  2015. /// <param name="arg0">First float value.</param>
  2016. /// <param name="arg1">Second float value.</param>
  2017. /// <param name="arg2">Third float value.</param>
  2018. /// <param name="arg3">Forth float value.</param>
  2019. /// <param name="arg4">Fifth float value.</param>
  2020. /// <param name="arg5">Sixth float value.</param>
  2021. /// <param name="arg6">Seventh float value.</param>
  2022. /// <param name="arg7">Eighth float value.</param>
  2023. public void SetText(string sourceText, float arg0, float arg1, float arg2, float arg3, float arg4, float arg5, float arg6, float arg7)
  2024. {
  2025. int argIndex = 0;
  2026. int padding = 0;
  2027. int decimalPrecision = 0;
  2028. int readFlag = 0;
  2029. int readIndex = 0;
  2030. int writeIndex = 0;
  2031. for (; readIndex < sourceText.Length; readIndex++)
  2032. {
  2033. char c = sourceText[readIndex];
  2034. if (c == '{')
  2035. {
  2036. readFlag = 1;
  2037. continue;
  2038. }
  2039. if (c == '}')
  2040. {
  2041. // Add arg(index) to array
  2042. switch (argIndex)
  2043. {
  2044. case 0:
  2045. AddFloatToInternalTextBackingArray(arg0, padding, decimalPrecision, ref writeIndex);
  2046. break;
  2047. case 1:
  2048. AddFloatToInternalTextBackingArray(arg1, padding, decimalPrecision, ref writeIndex);
  2049. break;
  2050. case 2:
  2051. AddFloatToInternalTextBackingArray(arg2, padding, decimalPrecision, ref writeIndex);
  2052. break;
  2053. case 3:
  2054. AddFloatToInternalTextBackingArray(arg3, padding, decimalPrecision, ref writeIndex);
  2055. break;
  2056. case 4:
  2057. AddFloatToInternalTextBackingArray(arg4, padding, decimalPrecision, ref writeIndex);
  2058. break;
  2059. case 5:
  2060. AddFloatToInternalTextBackingArray(arg5, padding, decimalPrecision, ref writeIndex);
  2061. break;
  2062. case 6:
  2063. AddFloatToInternalTextBackingArray(arg6, padding, decimalPrecision, ref writeIndex);
  2064. break;
  2065. case 7:
  2066. AddFloatToInternalTextBackingArray(arg7, padding, decimalPrecision, ref writeIndex);
  2067. break;
  2068. }
  2069. argIndex = 0;
  2070. readFlag = 0;
  2071. padding = 0;
  2072. decimalPrecision = 0;
  2073. continue;
  2074. }
  2075. // Read Argument index
  2076. if (readFlag == 1)
  2077. {
  2078. if (c >= '0' && c <= '8')
  2079. {
  2080. argIndex = c - 48;
  2081. readFlag = 2;
  2082. continue;
  2083. }
  2084. }
  2085. // Read formatting for integral part of the value
  2086. if (readFlag == 2)
  2087. {
  2088. // Skip ':' separator
  2089. if (c == ':')
  2090. continue;
  2091. // Done reading integral formatting and value
  2092. if (c == '.')
  2093. {
  2094. readFlag = 3;
  2095. continue;
  2096. }
  2097. if (c == '#')
  2098. {
  2099. // do something
  2100. continue;
  2101. }
  2102. if (c == '0')
  2103. {
  2104. padding += 1;
  2105. continue;
  2106. }
  2107. if (c == ',')
  2108. {
  2109. // Use commas in the integral value
  2110. continue;
  2111. }
  2112. // Legacy mode
  2113. if (c >= '1' && c <= '9')
  2114. {
  2115. decimalPrecision = c - 48;
  2116. continue;
  2117. }
  2118. }
  2119. // Read Decimal Precision value
  2120. if (readFlag == 3)
  2121. {
  2122. if (c == '0')
  2123. {
  2124. decimalPrecision += 1;
  2125. continue;
  2126. }
  2127. }
  2128. // Write value
  2129. m_TextBackingArray[writeIndex] = c;
  2130. writeIndex += 1;
  2131. }
  2132. m_TextBackingArray[writeIndex] = 0;
  2133. m_TextBackingArray.Count = writeIndex;
  2134. m_IsTextBackingStringDirty = true;
  2135. #if UNITY_EDITOR
  2136. m_text = InternalTextBackingArrayToString();
  2137. #endif
  2138. m_inputSource = TextInputSources.SetText;
  2139. PopulateTextProcessingArray();
  2140. m_havePropertiesChanged = true;
  2141. SetVerticesDirty();
  2142. SetLayoutDirty();
  2143. }
  2144. /// <summary>
  2145. /// Set the text using a StringBuilder object as the source.
  2146. /// </summary>
  2147. /// <description>
  2148. /// Using a StringBuilder instead of concatenating strings prevents memory allocations with temporary objects.
  2149. /// </description>
  2150. /// <param name="sourceText">The StringBuilder object containing the source text.</param>
  2151. public void SetText(StringBuilder sourceText)
  2152. {
  2153. int srcLength = sourceText == null ? 0 : sourceText.Length;
  2154. SetText(sourceText, 0, srcLength);
  2155. }
  2156. /// <summary>
  2157. /// Set the text using a StringBuilder object and specifying the starting character index and length.
  2158. /// </summary>
  2159. /// <param name="sourceText">The StringBuilder object containing the source text.</param>
  2160. /// <param name="start">The index of the first character to read from in the array.</param>
  2161. /// <param name="length">The number of characters in the array to be read.</param>
  2162. void SetText(StringBuilder sourceText, int start, int length)
  2163. {
  2164. PopulateTextBackingArray(sourceText, start, length);
  2165. m_IsTextBackingStringDirty = true;
  2166. #if UNITY_EDITOR
  2167. m_text = InternalTextBackingArrayToString();
  2168. #endif
  2169. // Set input source
  2170. m_inputSource = TextInputSources.SetTextArray;
  2171. PopulateTextProcessingArray();
  2172. m_havePropertiesChanged = true;
  2173. SetVerticesDirty();
  2174. SetLayoutDirty();
  2175. }
  2176. /// <summary>
  2177. /// Set the text using a char array.
  2178. /// </summary>
  2179. /// <param name="sourceText">Source char array containing the Unicode characters of the text.</param>
  2180. public void SetText(char[] sourceText)
  2181. {
  2182. int srcLength = sourceText == null ? 0 : sourceText.Length;
  2183. SetCharArray(sourceText, 0, srcLength);
  2184. }
  2185. /// <summary>
  2186. /// Set the text using a char array and specifying the starting character index and length.
  2187. /// </summary>
  2188. /// <param name="sourceText">Source char array containing the Unicode characters of the text.</param>
  2189. /// <param name="start">Index of the first character to read from in the array.</param>
  2190. /// <param name="length">The number of characters in the array to be read.</param>
  2191. public void SetText(char[] sourceText, int start, int length)
  2192. {
  2193. SetCharArray(sourceText, start, length);
  2194. }
  2195. /// <summary>
  2196. /// Set the text using a char array.
  2197. /// </summary>
  2198. /// <param name="sourceText">Source char array containing the Unicode characters of the text.</param>
  2199. public void SetCharArray(char[] sourceText)
  2200. {
  2201. int srcLength = sourceText == null ? 0 : sourceText.Length;
  2202. SetCharArray(sourceText, 0, srcLength);
  2203. }
  2204. /// <summary>
  2205. /// Set the text using a char array and specifying the starting character index and length.
  2206. /// </summary>
  2207. /// <param name="sourceText">Source char array containing the Unicode characters of the text.</param>
  2208. /// <param name="start">The index of the first character to read from in the array.</param>
  2209. /// <param name="length">The number of characters in the array to be read.</param>
  2210. public void SetCharArray(char[] sourceText, int start, int length)
  2211. {
  2212. PopulateTextBackingArray(sourceText, start, length);
  2213. m_IsTextBackingStringDirty = true;
  2214. #if UNITY_EDITOR
  2215. m_text = InternalTextBackingArrayToString();
  2216. #endif
  2217. // Set input source
  2218. m_inputSource = TextInputSources.SetTextArray;
  2219. PopulateTextProcessingArray();
  2220. m_havePropertiesChanged = true;
  2221. SetVerticesDirty();
  2222. SetLayoutDirty();
  2223. }
  2224. /// <summary>
  2225. ///
  2226. /// </summary>
  2227. /// <param name="hashCode"></param>
  2228. /// <returns></returns>
  2229. TMP_Style GetStyle(int hashCode)
  2230. {
  2231. TMP_Style style = null;
  2232. // Get Style from Style Sheet potentially assigned to text object.
  2233. if (m_StyleSheet != null)
  2234. {
  2235. style = m_StyleSheet.GetStyle(hashCode);
  2236. if (style != null)
  2237. return style;
  2238. }
  2239. if (TMP_Settings.defaultStyleSheet != null)
  2240. style = TMP_Settings.defaultStyleSheet.GetStyle(hashCode);
  2241. return style;
  2242. }
  2243. /// <summary>
  2244. /// Method to handle inline replacement of style tag by opening style definition.
  2245. /// </summary>
  2246. /// <param name="sourceText"></param>
  2247. /// <param name="srcIndex"></param>
  2248. /// <param name="srcOffset"></param>
  2249. /// <param name="charBuffer"></param>
  2250. /// <param name="writeIndex"></param>
  2251. /// <returns></returns>
  2252. bool ReplaceOpeningStyleTag(ref TextBackingContainer sourceText, int srcIndex, out int srcOffset, ref UnicodeChar[] charBuffer, ref int writeIndex)
  2253. {
  2254. // Validate <style> tag.
  2255. int styleHashCode = GetStyleHashCode(ref sourceText, srcIndex + 7, out srcOffset);
  2256. TMP_Style style = GetStyle(styleHashCode);
  2257. // Return if we don't have a valid style.
  2258. if (style == null || srcOffset == 0) return false;
  2259. // Increase style depth
  2260. m_TextStyleStackDepth += 1;
  2261. // Push style hashcode onto stack
  2262. m_TextStyleStacks[m_TextStyleStackDepth].Push(style.hashCode);
  2263. int styleLength = style.styleOpeningTagArray.Length;
  2264. // Replace <style> tag with opening definition
  2265. int[] tagDefinition = style.styleOpeningTagArray;
  2266. for (int i = 0; i < styleLength; i++)
  2267. {
  2268. int c = tagDefinition[i];
  2269. if (c == '\\' && i + 1 < styleLength)
  2270. {
  2271. switch (tagDefinition[i + 1])
  2272. {
  2273. case '\\':
  2274. i += 1;
  2275. break;
  2276. case 'n':
  2277. c = 10;
  2278. i += 1;
  2279. break;
  2280. case 'r':
  2281. break;
  2282. case 't':
  2283. break;
  2284. case 'u':
  2285. // UTF16 format is "\uFF00" or u + 2 hex pairs.
  2286. if (i + 5 < styleLength)
  2287. {
  2288. c = GetUTF16(tagDefinition, i + 2);
  2289. i += 5;
  2290. }
  2291. break;
  2292. case 'U':
  2293. // UTF32 format is "\UFF00FF00" or U + 4 hex pairs.
  2294. if (i + 9 < styleLength)
  2295. {
  2296. c = GetUTF32(tagDefinition, i + 2);
  2297. i += 9;
  2298. }
  2299. break;
  2300. }
  2301. }
  2302. if (c == '<')
  2303. {
  2304. int hashCode = GetMarkupTagHashCode(tagDefinition, i + 1);
  2305. switch ((MarkupTag)hashCode)
  2306. {
  2307. case MarkupTag.BR:
  2308. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2309. charBuffer[writeIndex].unicode = 10;
  2310. writeIndex += 1;
  2311. i += 3;
  2312. continue;
  2313. case MarkupTag.NBSP:
  2314. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2315. charBuffer[writeIndex].unicode = 160;
  2316. writeIndex += 1;
  2317. i += 5;
  2318. continue;
  2319. case MarkupTag.ZWSP:
  2320. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2321. charBuffer[writeIndex].unicode = 0x200B;
  2322. writeIndex += 1;
  2323. i += 5;
  2324. continue;
  2325. case MarkupTag.STYLE:
  2326. if (ReplaceOpeningStyleTag(ref tagDefinition, i, out int offset, ref charBuffer, ref writeIndex))
  2327. {
  2328. i = offset;
  2329. continue;
  2330. }
  2331. break;
  2332. case MarkupTag.SLASH_STYLE:
  2333. ReplaceClosingStyleTag(ref tagDefinition, i, ref charBuffer, ref writeIndex);
  2334. i += 7;
  2335. continue;
  2336. }
  2337. }
  2338. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2339. charBuffer[writeIndex].unicode = c;
  2340. writeIndex += 1;
  2341. }
  2342. m_TextStyleStackDepth -= 1;
  2343. return true;
  2344. }
  2345. /// <summary>
  2346. /// Method to handle inline replacement of style tag by opening style definition.
  2347. /// </summary>
  2348. /// <param name="sourceText"></param>
  2349. /// <param name="srcIndex"></param>
  2350. /// <param name="srcOffset"></param>
  2351. /// <param name="charBuffer"></param>
  2352. /// <param name="writeIndex"></param>
  2353. /// <returns></returns>
  2354. bool ReplaceOpeningStyleTag(ref int[] sourceText, int srcIndex, out int srcOffset, ref UnicodeChar[] charBuffer, ref int writeIndex)
  2355. {
  2356. // Validate <style> tag.
  2357. int styleHashCode = GetStyleHashCode(ref sourceText, srcIndex + 7, out srcOffset);
  2358. TMP_Style style = GetStyle(styleHashCode);
  2359. // Return if we don't have a valid style.
  2360. if (style == null || srcOffset == 0) return false;
  2361. // Increase style depth
  2362. m_TextStyleStackDepth += 1;
  2363. // Push style hashcode onto stack
  2364. m_TextStyleStacks[m_TextStyleStackDepth].Push(style.hashCode);
  2365. int styleLength = style.styleOpeningTagArray.Length;
  2366. // Replace <style> tag with opening definition
  2367. int[] tagDefinition = style.styleOpeningTagArray;
  2368. for (int i = 0; i < styleLength; i++)
  2369. {
  2370. int c = tagDefinition[i];
  2371. if (c == '\\' && i + 1 < styleLength)
  2372. {
  2373. switch (tagDefinition[i + 1])
  2374. {
  2375. case '\\':
  2376. i += 1;
  2377. break;
  2378. case 'n':
  2379. c = 10;
  2380. i += 1;
  2381. break;
  2382. case 'r':
  2383. break;
  2384. case 't':
  2385. break;
  2386. case 'u':
  2387. // UTF16 format is "\uFF00" or u + 2 hex pairs.
  2388. if (i + 5 < styleLength)
  2389. {
  2390. c = GetUTF16(tagDefinition, i + 2);
  2391. i += 5;
  2392. }
  2393. break;
  2394. case 'U':
  2395. // UTF32 format is "\UFF00FF00" or U + 4 hex pairs.
  2396. if (i + 9 < styleLength)
  2397. {
  2398. c = GetUTF32(tagDefinition, i + 2);
  2399. i += 9;
  2400. }
  2401. break;
  2402. }
  2403. }
  2404. if (c == '<')
  2405. {
  2406. int hashCode = GetMarkupTagHashCode(tagDefinition, i + 1);
  2407. switch ((MarkupTag)hashCode)
  2408. {
  2409. case MarkupTag.BR:
  2410. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2411. charBuffer[writeIndex].unicode = 10;
  2412. writeIndex += 1;
  2413. i += 3;
  2414. continue;
  2415. case MarkupTag.NBSP:
  2416. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2417. charBuffer[writeIndex].unicode = 160;
  2418. writeIndex += 1;
  2419. i += 5;
  2420. continue;
  2421. case MarkupTag.ZWSP:
  2422. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2423. charBuffer[writeIndex].unicode = 0x200B;
  2424. writeIndex += 1;
  2425. i += 5;
  2426. continue;
  2427. case MarkupTag.STYLE:
  2428. if (ReplaceOpeningStyleTag(ref tagDefinition, i, out int offset, ref charBuffer, ref writeIndex))
  2429. {
  2430. i = offset;
  2431. continue;
  2432. }
  2433. break;
  2434. case MarkupTag.SLASH_STYLE:
  2435. ReplaceClosingStyleTag(ref tagDefinition, i, ref charBuffer, ref writeIndex);
  2436. i += 7;
  2437. continue;
  2438. }
  2439. }
  2440. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2441. charBuffer[writeIndex].unicode = c;
  2442. writeIndex += 1;
  2443. }
  2444. m_TextStyleStackDepth -= 1;
  2445. return true;
  2446. }
  2447. /// <summary>
  2448. /// Method to handle inline replacement of style tag by closing style definition.
  2449. /// </summary>
  2450. /// <param name="sourceText"></param>
  2451. /// <param name="srcIndex"></param>
  2452. /// <param name="charBuffer"></param>
  2453. /// <param name="writeIndex"></param>
  2454. /// <returns></returns>
  2455. void ReplaceClosingStyleTag(ref TextBackingContainer sourceText, int srcIndex, ref UnicodeChar[] charBuffer, ref int writeIndex)
  2456. {
  2457. // Get style from the Style Stack
  2458. int styleHashCode = m_TextStyleStacks[m_TextStyleStackDepth + 1].Pop();
  2459. TMP_Style style = GetStyle(styleHashCode);
  2460. // Return if we don't have a valid style.
  2461. if (style == null) return;
  2462. // Increase style depth
  2463. m_TextStyleStackDepth += 1;
  2464. int styleLength = style.styleClosingTagArray.Length;
  2465. // Replace <style> tag with opening definition
  2466. int[] tagDefinition = style.styleClosingTagArray;
  2467. for (int i = 0; i < styleLength; i++)
  2468. {
  2469. int c = tagDefinition[i];
  2470. if (c == '\\' && i + 1 < styleLength)
  2471. {
  2472. switch (tagDefinition[i + 1])
  2473. {
  2474. case '\\':
  2475. i += 1;
  2476. break;
  2477. case 'n':
  2478. c = 10;
  2479. i += 1;
  2480. break;
  2481. case 'r':
  2482. break;
  2483. case 't':
  2484. break;
  2485. case 'u':
  2486. // UTF16 format is "\uFF00" or u + 2 hex pairs.
  2487. if (i + 5 < styleLength)
  2488. {
  2489. c = GetUTF16(tagDefinition, i + 2);
  2490. i += 5;
  2491. }
  2492. break;
  2493. case 'U':
  2494. // UTF32 format is "\UFF00FF00" or U + 4 hex pairs.
  2495. if (i + 9 < styleLength)
  2496. {
  2497. c = GetUTF32(tagDefinition, i + 2);
  2498. i += 9;
  2499. }
  2500. break;
  2501. }
  2502. }
  2503. if (c == '<')
  2504. {
  2505. int hashCode = GetMarkupTagHashCode(tagDefinition, i + 1);
  2506. switch ((MarkupTag)hashCode)
  2507. {
  2508. case MarkupTag.BR:
  2509. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2510. charBuffer[writeIndex].unicode = 10;
  2511. writeIndex += 1;
  2512. i += 3;
  2513. continue;
  2514. case MarkupTag.NBSP:
  2515. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2516. charBuffer[writeIndex].unicode = 160;
  2517. writeIndex += 1;
  2518. i += 5;
  2519. continue;
  2520. case MarkupTag.ZWSP:
  2521. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2522. charBuffer[writeIndex].unicode = 0x200B;
  2523. writeIndex += 1;
  2524. i += 5;
  2525. continue;
  2526. case MarkupTag.STYLE:
  2527. if (ReplaceOpeningStyleTag(ref tagDefinition, i, out int offset, ref charBuffer, ref writeIndex))
  2528. {
  2529. i = offset;
  2530. continue;
  2531. }
  2532. break;
  2533. case MarkupTag.SLASH_STYLE:
  2534. ReplaceClosingStyleTag(ref tagDefinition, i, ref charBuffer, ref writeIndex);
  2535. i += 7;
  2536. continue;
  2537. }
  2538. }
  2539. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2540. charBuffer[writeIndex].unicode = c;
  2541. writeIndex += 1;
  2542. }
  2543. m_TextStyleStackDepth -= 1;
  2544. }
  2545. /// <summary>
  2546. /// Method to handle inline replacement of style tag by closing style definition.
  2547. /// </summary>
  2548. /// <param name="sourceText"></param>
  2549. /// <param name="srcIndex"></param>
  2550. /// <param name="charBuffer"></param>
  2551. /// <param name="writeIndex"></param>
  2552. /// <returns></returns>
  2553. void ReplaceClosingStyleTag(ref int[] sourceText, int srcIndex, ref UnicodeChar[] charBuffer, ref int writeIndex)
  2554. {
  2555. // Get style from the Style Stack
  2556. int styleHashCode = m_TextStyleStacks[m_TextStyleStackDepth + 1].Pop();
  2557. TMP_Style style = GetStyle(styleHashCode);
  2558. // Return if we don't have a valid style.
  2559. if (style == null) return;
  2560. // Increase style depth
  2561. m_TextStyleStackDepth += 1;
  2562. int styleLength = style.styleClosingTagArray.Length;
  2563. // Replace <style> tag with opening definition
  2564. int[] tagDefinition = style.styleClosingTagArray;
  2565. for (int i = 0; i < styleLength; i++)
  2566. {
  2567. int c = tagDefinition[i];
  2568. if (c == '\\' && i + 1 < styleLength)
  2569. {
  2570. switch (tagDefinition[i + 1])
  2571. {
  2572. case '\\':
  2573. i += 1;
  2574. break;
  2575. case 'n':
  2576. c = 10;
  2577. i += 1;
  2578. break;
  2579. case 'r':
  2580. break;
  2581. case 't':
  2582. break;
  2583. case 'u':
  2584. // UTF16 format is "\uFF00" or u + 2 hex pairs.
  2585. if (i + 5 < styleLength)
  2586. {
  2587. c = GetUTF16(tagDefinition, i + 2);
  2588. i += 5;
  2589. }
  2590. break;
  2591. case 'U':
  2592. // UTF32 format is "\UFF00FF00" or U + 4 hex pairs.
  2593. if (i + 9 < styleLength)
  2594. {
  2595. c = GetUTF32(tagDefinition, i + 2);
  2596. i += 9;
  2597. }
  2598. break;
  2599. }
  2600. }
  2601. if (c == '<')
  2602. {
  2603. int hashCode = GetMarkupTagHashCode(tagDefinition, i + 1);
  2604. switch ((MarkupTag)hashCode)
  2605. {
  2606. case MarkupTag.BR:
  2607. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2608. charBuffer[writeIndex].unicode = 10;
  2609. writeIndex += 1;
  2610. i += 3;
  2611. continue;
  2612. case MarkupTag.NBSP:
  2613. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2614. charBuffer[writeIndex].unicode = 160;
  2615. writeIndex += 1;
  2616. i += 5;
  2617. continue;
  2618. case MarkupTag.ZWSP:
  2619. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2620. charBuffer[writeIndex].unicode = 0x200B;
  2621. writeIndex += 1;
  2622. i += 5;
  2623. continue;
  2624. case MarkupTag.STYLE:
  2625. if (ReplaceOpeningStyleTag(ref tagDefinition, i, out int offset, ref charBuffer, ref writeIndex))
  2626. {
  2627. i = offset;
  2628. continue;
  2629. }
  2630. break;
  2631. case MarkupTag.SLASH_STYLE:
  2632. ReplaceClosingStyleTag(ref tagDefinition, i, ref charBuffer, ref writeIndex);
  2633. i += 7;
  2634. continue;
  2635. }
  2636. }
  2637. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2638. charBuffer[writeIndex].unicode = c;
  2639. writeIndex += 1;
  2640. }
  2641. m_TextStyleStackDepth -= 1;
  2642. }
  2643. /// <summary>
  2644. ///
  2645. /// </summary>
  2646. /// <param name="style"></param>
  2647. /// <param name="srcIndex"></param>
  2648. /// <param name="charBuffer"></param>
  2649. /// <param name="writeIndex"></param>
  2650. /// <returns></returns>
  2651. bool InsertOpeningStyleTag(TMP_Style style, int srcIndex, ref UnicodeChar[] charBuffer, ref int writeIndex)
  2652. {
  2653. // Return if we don't have a valid style.
  2654. if (style == null) return false;
  2655. m_TextStyleStacks[0].Push(style.hashCode);
  2656. int styleLength = style.styleOpeningTagArray.Length;
  2657. // Replace <style> tag with opening definition
  2658. int[] tagDefinition = style.styleOpeningTagArray;
  2659. for (int i = 0; i < styleLength; i++)
  2660. {
  2661. int c = tagDefinition[i];
  2662. if (c == '\\' && i + 1 < styleLength)
  2663. {
  2664. switch (tagDefinition[i + 1])
  2665. {
  2666. case '\\':
  2667. i += 1;
  2668. break;
  2669. case 'n':
  2670. c = 10;
  2671. i += 1;
  2672. break;
  2673. case 'r':
  2674. break;
  2675. case 't':
  2676. break;
  2677. case 'u':
  2678. // UTF16 format is "\uFF00" or u + 2 hex pairs.
  2679. if (i + 5 < styleLength)
  2680. {
  2681. c = GetUTF16(tagDefinition, i + 2);
  2682. i += 5;
  2683. }
  2684. break;
  2685. case 'U':
  2686. // UTF32 format is "\UFF00FF00" or U + 4 hex pairs.
  2687. if (i + 9 < styleLength)
  2688. {
  2689. c = GetUTF32(tagDefinition, i + 2);
  2690. i += 9;
  2691. }
  2692. break;
  2693. }
  2694. }
  2695. if (c == '<')
  2696. {
  2697. int hashCode = GetMarkupTagHashCode(tagDefinition, i + 1);
  2698. switch ((MarkupTag)hashCode)
  2699. {
  2700. case MarkupTag.BR:
  2701. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2702. charBuffer[writeIndex].unicode = 10;
  2703. writeIndex += 1;
  2704. i += 3;
  2705. continue;
  2706. case MarkupTag.NBSP:
  2707. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2708. charBuffer[writeIndex].unicode = 160;
  2709. writeIndex += 1;
  2710. i += 5;
  2711. continue;
  2712. case MarkupTag.ZWSP:
  2713. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2714. charBuffer[writeIndex].unicode = 0x200B;
  2715. writeIndex += 1;
  2716. i += 5;
  2717. continue;
  2718. case MarkupTag.STYLE:
  2719. if (ReplaceOpeningStyleTag(ref tagDefinition, i, out int offset, ref charBuffer, ref writeIndex))
  2720. {
  2721. i = offset;
  2722. continue;
  2723. }
  2724. break;
  2725. case MarkupTag.SLASH_STYLE:
  2726. ReplaceClosingStyleTag(ref tagDefinition, i, ref charBuffer, ref writeIndex);
  2727. i += 7;
  2728. continue;
  2729. }
  2730. }
  2731. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2732. charBuffer[writeIndex].unicode = c;
  2733. writeIndex += 1;
  2734. }
  2735. m_TextStyleStackDepth = 0;
  2736. return true;
  2737. }
  2738. /// <summary>
  2739. ///
  2740. /// </summary>
  2741. /// <param name="charBuffer"></param>
  2742. /// <param name="writeIndex"></param>
  2743. void InsertClosingStyleTag(ref UnicodeChar[] charBuffer, ref int writeIndex)
  2744. {
  2745. // Get style from the Style Stack
  2746. int styleHashCode = m_TextStyleStacks[0].Pop();
  2747. TMP_Style style = GetStyle(styleHashCode);
  2748. int styleLength = style.styleClosingTagArray.Length;
  2749. // Replace <style> tag with opening definition
  2750. int[] tagDefinition = style.styleClosingTagArray;
  2751. for (int i = 0; i < styleLength; i++)
  2752. {
  2753. int c = tagDefinition[i];
  2754. if (c == '\\' && i + 1 < styleLength)
  2755. {
  2756. switch (tagDefinition[i + 1])
  2757. {
  2758. case '\\':
  2759. i += 1;
  2760. break;
  2761. case 'n':
  2762. c = 10;
  2763. i += 1;
  2764. break;
  2765. case 'r':
  2766. break;
  2767. case 't':
  2768. break;
  2769. case 'u':
  2770. // UTF16 format is "\uFF00" or u + 2 hex pairs.
  2771. if (i + 5 < styleLength)
  2772. {
  2773. c = GetUTF16(tagDefinition, i + 2);
  2774. i += 5;
  2775. }
  2776. break;
  2777. case 'U':
  2778. // UTF32 format is "\UFF00FF00" or U + 4 hex pairs.
  2779. if (i + 9 < styleLength)
  2780. {
  2781. c = GetUTF32(tagDefinition, i + 2);
  2782. i += 9;
  2783. }
  2784. break;
  2785. }
  2786. }
  2787. if (c == '<')
  2788. {
  2789. int hashCode = GetMarkupTagHashCode(tagDefinition, i + 1);
  2790. switch ((MarkupTag)hashCode)
  2791. {
  2792. case MarkupTag.BR:
  2793. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2794. charBuffer[writeIndex].unicode = 10;
  2795. writeIndex += 1;
  2796. i += 3;
  2797. continue;
  2798. case MarkupTag.NBSP:
  2799. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2800. charBuffer[writeIndex].unicode = 160;
  2801. writeIndex += 1;
  2802. i += 5;
  2803. continue;
  2804. case MarkupTag.ZWSP:
  2805. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2806. charBuffer[writeIndex].unicode = 0x200B;
  2807. writeIndex += 1;
  2808. i += 5;
  2809. continue;
  2810. case MarkupTag.STYLE:
  2811. if (ReplaceOpeningStyleTag(ref tagDefinition, i, out int offset, ref charBuffer, ref writeIndex))
  2812. {
  2813. i = offset;
  2814. continue;
  2815. }
  2816. break;
  2817. case MarkupTag.SLASH_STYLE:
  2818. ReplaceClosingStyleTag(ref tagDefinition, i, ref charBuffer, ref writeIndex);
  2819. i += 7;
  2820. continue;
  2821. }
  2822. }
  2823. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2824. charBuffer[writeIndex].unicode = c;
  2825. writeIndex += 1;
  2826. }
  2827. m_TextStyleStackDepth = 0;
  2828. }
  2829. /// <summary>
  2830. ///
  2831. /// </summary>
  2832. /// <param name="tagDefinition"></param>
  2833. /// <param name="readIndex"></param>
  2834. /// <returns></returns>
  2835. int GetMarkupTagHashCode(int[] tagDefinition, int readIndex)
  2836. {
  2837. int hashCode = 0;
  2838. int maxReadIndex = readIndex + 16;
  2839. int tagDefinitionLength = tagDefinition.Length;
  2840. for (; readIndex < maxReadIndex && readIndex < tagDefinitionLength; readIndex++)
  2841. {
  2842. int c = tagDefinition[readIndex];
  2843. if (c == '>' || c == '=' || c == ' ')
  2844. return hashCode;
  2845. hashCode = ((hashCode << 5) + hashCode) ^ (int)TMP_TextUtilities.ToUpperASCIIFast((uint)c);
  2846. }
  2847. return hashCode;
  2848. }
  2849. /// <summary>
  2850. ///
  2851. /// </summary>
  2852. /// <param name="tagDefinition"></param>
  2853. /// <param name="readIndex"></param>
  2854. /// <returns></returns>
  2855. int GetMarkupTagHashCode(TextBackingContainer tagDefinition, int readIndex)
  2856. {
  2857. int hashCode = 0;
  2858. int maxReadIndex = readIndex + 16;
  2859. int tagDefinitionLength = tagDefinition.Capacity;
  2860. for (; readIndex < maxReadIndex && readIndex < tagDefinitionLength; readIndex++)
  2861. {
  2862. uint c = tagDefinition[readIndex];
  2863. if (c == '>' || c == '=' || c == ' ')
  2864. return hashCode;
  2865. hashCode = ((hashCode << 5) + hashCode) ^ (int)TMP_TextUtilities.ToUpperASCIIFast((uint)c);
  2866. }
  2867. return hashCode;
  2868. }
  2869. /// <summary>
  2870. /// Get Hashcode for a given tag.
  2871. /// </summary>
  2872. /// <param name="text"></param>
  2873. /// <param name="index"></param>
  2874. /// <param name="closeIndex"></param>
  2875. /// <returns></returns>
  2876. int GetStyleHashCode(ref int[] text, int index, out int closeIndex)
  2877. {
  2878. int hashCode = 0;
  2879. closeIndex = 0;
  2880. for (int i = index; i < text.Length; i++)
  2881. {
  2882. // Skip quote '"' character
  2883. if (text[i] == 34) continue;
  2884. // Break at '>'
  2885. if (text[i] == 62) { closeIndex = i; break; }
  2886. hashCode = (hashCode << 5) + hashCode ^ TMP_TextParsingUtilities.ToUpperASCIIFast((char)text[i]);
  2887. }
  2888. return hashCode;
  2889. }
  2890. /// <summary>
  2891. /// Get Hashcode for a given tag.
  2892. /// </summary>
  2893. /// <param name="text"></param>
  2894. /// <param name="index"></param>
  2895. /// <param name="closeIndex"></param>
  2896. /// <returns></returns>
  2897. int GetStyleHashCode(ref TextBackingContainer text, int index, out int closeIndex)
  2898. {
  2899. int hashCode = 0;
  2900. closeIndex = 0;
  2901. for (int i = index; i < text.Capacity; i++)
  2902. {
  2903. // Skip quote '"' character
  2904. if (text[i] == 34) continue;
  2905. // Break at '>'
  2906. if (text[i] == 62) { closeIndex = i; break; }
  2907. hashCode = (hashCode << 5) + hashCode ^ TMP_TextParsingUtilities.ToUpperASCIIFast((char)text[i]);
  2908. }
  2909. return hashCode;
  2910. }
  2911. /// <summary>
  2912. ///
  2913. /// </summary>
  2914. void ResizeInternalArray <T>(ref T[] array)
  2915. {
  2916. int size = Mathf.NextPowerOfTwo(array.Length + 1);
  2917. System.Array.Resize(ref array, size);
  2918. }
  2919. void ResizeInternalArray<T>(ref T[] array, int size)
  2920. {
  2921. size = Mathf.NextPowerOfTwo(size + 1);
  2922. System.Array.Resize(ref array, size);
  2923. }
  2924. private readonly decimal[] k_Power = { 5e-1m, 5e-2m, 5e-3m, 5e-4m, 5e-5m, 5e-6m, 5e-7m, 5e-8m, 5e-9m, 5e-10m }; // Used by FormatText to enable rounding and avoid using Mathf.Pow.
  2925. void AddFloatToInternalTextBackingArray(float value, int padding, int precision, ref int writeIndex)
  2926. {
  2927. if (value < 0)
  2928. {
  2929. m_TextBackingArray[writeIndex] = '-';
  2930. writeIndex += 1;
  2931. value = -value;
  2932. }
  2933. // Using decimal type due to floating point precision impacting formatting
  2934. decimal valueD = (decimal)value;
  2935. // Round up value to the specified prevision otherwise set precision to max.
  2936. if (padding == 0 && precision == 0)
  2937. precision = 9;
  2938. else
  2939. valueD += k_Power[Mathf.Min(9, precision)];
  2940. long integer = (long)valueD;
  2941. AddIntegerToInternalTextBackingArray(integer, padding, ref writeIndex);
  2942. if (precision > 0)
  2943. {
  2944. valueD -= integer;
  2945. // Add decimal point and values only if remainder is not zero.
  2946. if (valueD != 0)
  2947. {
  2948. // Add decimal point
  2949. m_TextBackingArray[writeIndex++] = '.';
  2950. for (int p = 0; p < precision; p++)
  2951. {
  2952. valueD *= 10;
  2953. long d = (long)valueD;
  2954. m_TextBackingArray[writeIndex++] = (char)(d + 48);
  2955. valueD -= d;
  2956. if (valueD == 0)
  2957. p = precision;
  2958. }
  2959. }
  2960. }
  2961. }
  2962. /// <summary>
  2963. ///
  2964. /// </summary>
  2965. /// <param name="number"></param>
  2966. /// <param name="padding"></param>
  2967. /// <param name="writeIndex"></param>
  2968. void AddIntegerToInternalTextBackingArray(double number, int padding, ref int writeIndex)
  2969. {
  2970. int integralCount = 0;
  2971. int i = writeIndex;
  2972. do
  2973. {
  2974. m_TextBackingArray[i++] = (char)(number % 10 + 48);
  2975. number /= 10;
  2976. integralCount += 1;
  2977. } while (number > 0.999999999999999d || integralCount < padding);
  2978. int lastIndex = i;
  2979. //// Reverse string
  2980. while (writeIndex + 1 < i)
  2981. {
  2982. i -= 1;
  2983. uint t = m_TextBackingArray[writeIndex];
  2984. m_TextBackingArray[writeIndex] = m_TextBackingArray[i];
  2985. m_TextBackingArray[i] = t;
  2986. writeIndex += 1;
  2987. }
  2988. writeIndex = lastIndex;
  2989. }
  2990. string InternalTextBackingArrayToString()
  2991. {
  2992. char[] array = new char[m_TextBackingArray.Count];
  2993. for (int i = 0; i < m_TextBackingArray.Capacity; i++)
  2994. {
  2995. char c = (char)m_TextBackingArray[i];
  2996. if (c == 0)
  2997. break;
  2998. array[i] = c;
  2999. }
  3000. m_IsTextBackingStringDirty = false;
  3001. return new string(array);
  3002. }
  3003. /// <summary>
  3004. /// Method used to determine the number of visible characters and required buffer allocations.
  3005. /// </summary>
  3006. /// <param name="unicodeChars"></param>
  3007. /// <returns></returns>
  3008. internal virtual int SetArraySizes(UnicodeChar[] unicodeChars) { return 0; }
  3009. /// <summary>
  3010. /// Function to Calculate the Preferred Width and Height of the text object.
  3011. /// </summary>
  3012. /// <returns></returns>
  3013. public Vector2 GetPreferredValues()
  3014. {
  3015. // CALCULATE PREFERRED WIDTH
  3016. m_isPreferredWidthDirty = true;
  3017. float preferredWidth = GetPreferredWidth();
  3018. // CALCULATE PREFERRED HEIGHT
  3019. m_isPreferredHeightDirty = true;
  3020. float preferredHeight = GetPreferredHeight();
  3021. // Reset dirty states as we always want to recalculate preferred values when this function is called.
  3022. m_isPreferredWidthDirty = true;
  3023. m_isPreferredHeightDirty = true;
  3024. return new Vector2(preferredWidth, preferredHeight);
  3025. }
  3026. /// <summary>
  3027. /// Function to Calculate the Preferred Width and Height of the text object given the provided width and height.
  3028. /// </summary>
  3029. /// <returns></returns>
  3030. public Vector2 GetPreferredValues(float width, float height)
  3031. {
  3032. // Reparse input text
  3033. m_isCalculatingPreferredValues = true;
  3034. ParseInputText();
  3035. Vector2 margin = new Vector2(width, height);
  3036. // CALCULATE PREFERRED WIDTH
  3037. float preferredWidth = GetPreferredWidth(margin);
  3038. // CALCULATE PREFERRED HEIGHT
  3039. float preferredHeight = GetPreferredHeight(margin);
  3040. return new Vector2(preferredWidth, preferredHeight);
  3041. }
  3042. /// <summary>
  3043. /// Function to Calculate the Preferred Width and Height of the text object given a certain string.
  3044. /// </summary>
  3045. /// <param name="text"></param>
  3046. /// <returns></returns>
  3047. public Vector2 GetPreferredValues(string text)
  3048. {
  3049. m_isCalculatingPreferredValues = true;
  3050. SetTextInternal(text);
  3051. SetArraySizes(m_TextProcessingArray);
  3052. Vector2 margin = k_LargePositiveVector2;
  3053. // CALCULATE PREFERRED WIDTH
  3054. float preferredWidth = GetPreferredWidth(margin);
  3055. // CALCULATE PREFERRED HEIGHT
  3056. float preferredHeight = GetPreferredHeight(margin);
  3057. return new Vector2(preferredWidth, preferredHeight);
  3058. }
  3059. /// <summary>
  3060. /// Function to Calculate the Preferred Width and Height of the text object given a certain string and size of text container.
  3061. /// </summary>
  3062. /// <param name="text"></param>
  3063. /// <returns></returns>
  3064. public Vector2 GetPreferredValues(string text, float width, float height)
  3065. {
  3066. m_isCalculatingPreferredValues = true;
  3067. SetTextInternal(text);
  3068. SetArraySizes(m_TextProcessingArray);
  3069. Vector2 margin = new Vector2(width, height);
  3070. // CALCULATE PREFERRED WIDTH
  3071. float preferredWidth = GetPreferredWidth(margin);
  3072. // CALCULATE PREFERRED HEIGHT
  3073. float preferredHeight = GetPreferredHeight(margin);
  3074. return new Vector2(preferredWidth, preferredHeight);
  3075. }
  3076. /// <summary>
  3077. /// Method to calculate the preferred width of a text object.
  3078. /// </summary>
  3079. /// <returns></returns>
  3080. protected float GetPreferredWidth()
  3081. {
  3082. if (TMP_Settings.instance == null) return 0;
  3083. // Return cached preferred height if already computed
  3084. if (!m_isPreferredWidthDirty)
  3085. return m_preferredWidth;
  3086. float fontSize = m_enableAutoSizing ? m_fontSizeMax : m_fontSize;
  3087. // Reset auto sizing point size bounds
  3088. m_minFontSize = m_fontSizeMin;
  3089. m_maxFontSize = m_fontSizeMax;
  3090. m_charWidthAdjDelta = 0;
  3091. // Set Margins to Infinity
  3092. Vector2 margin = k_LargePositiveVector2;
  3093. m_isCalculatingPreferredValues = true;
  3094. ParseInputText();
  3095. m_AutoSizeIterationCount = 0;
  3096. float preferredWidth = CalculatePreferredValues(ref fontSize, margin, false, false).x;
  3097. m_isPreferredWidthDirty = false;
  3098. //Debug.Log("GetPreferredWidth() called on Object ID: " + GetInstanceID() + " on frame: " + Time.frameCount + ". Returning width of " + preferredWidth);
  3099. return preferredWidth;
  3100. }
  3101. /// <summary>
  3102. /// Method to calculate the preferred width of a text object.
  3103. /// </summary>
  3104. /// <param name="margin"></param>
  3105. /// <returns></returns>
  3106. float GetPreferredWidth(Vector2 margin)
  3107. {
  3108. float fontSize = m_enableAutoSizing ? m_fontSizeMax : m_fontSize;
  3109. // Reset auto sizing point size bounds
  3110. m_minFontSize = m_fontSizeMin;
  3111. m_maxFontSize = m_fontSizeMax;
  3112. m_charWidthAdjDelta = 0;
  3113. m_AutoSizeIterationCount = 0;
  3114. float preferredWidth = CalculatePreferredValues(ref fontSize, margin, false, false).x;
  3115. //Debug.Log("GetPreferredWidth() Called. Returning width of " + preferredWidth);
  3116. return preferredWidth;
  3117. }
  3118. /// <summary>
  3119. /// Method to calculate the preferred height of a text object.
  3120. /// </summary>
  3121. /// <returns></returns>
  3122. protected float GetPreferredHeight()
  3123. {
  3124. if (TMP_Settings.instance == null) return 0;
  3125. // Return cached preferred height if already computed
  3126. if (!m_isPreferredHeightDirty)
  3127. return m_preferredHeight;
  3128. float fontSize = m_enableAutoSizing ? m_fontSizeMax : m_fontSize;
  3129. // Reset auto sizing point size bounds
  3130. m_minFontSize = m_fontSizeMin;
  3131. m_maxFontSize = m_fontSizeMax;
  3132. m_charWidthAdjDelta = 0;
  3133. Vector2 margin = new Vector2(m_marginWidth != 0 ? m_marginWidth : k_LargePositiveFloat, k_LargePositiveFloat);
  3134. m_isCalculatingPreferredValues = true;
  3135. ParseInputText();
  3136. // Reset Text Auto Size iteration tracking.
  3137. m_IsAutoSizePointSizeSet = false;
  3138. m_AutoSizeIterationCount = 0;
  3139. // The CalculatePreferredValues function is potentially called repeatedly when text auto size is enabled.
  3140. // This is a revised implementation to remove the use of recursion which could potentially result in stack overflow issues.
  3141. float preferredHeight = 0;
  3142. while (m_IsAutoSizePointSizeSet == false)
  3143. {
  3144. preferredHeight = CalculatePreferredValues(ref fontSize, margin, m_enableAutoSizing, m_enableWordWrapping).y;
  3145. m_AutoSizeIterationCount += 1;
  3146. }
  3147. m_isPreferredHeightDirty = false;
  3148. //Debug.Log("GetPreferredHeight() called on Object ID: " + GetInstanceID() + " on frame: " + Time.frameCount +". Returning height of " + preferredHeight);
  3149. return preferredHeight;
  3150. }
  3151. /// <summary>
  3152. /// Method to calculate the preferred height of a text object.
  3153. /// </summary>
  3154. /// <param name="margin"></param>
  3155. /// <returns></returns>
  3156. float GetPreferredHeight(Vector2 margin)
  3157. {
  3158. float fontSize = m_enableAutoSizing ? m_fontSizeMax : m_fontSize;
  3159. // Reset auto sizing point size bounds
  3160. m_minFontSize = m_fontSizeMin;
  3161. m_maxFontSize = m_fontSizeMax;
  3162. m_charWidthAdjDelta = 0;
  3163. // Reset Text Auto Size iteration tracking.
  3164. m_IsAutoSizePointSizeSet = false;
  3165. m_AutoSizeIterationCount = 0;
  3166. // The CalculatePreferredValues function is potentially called repeatedly when text auto size is enabled.
  3167. // This is a revised implementation to remove the use of recursion which could potentially result in stack overflow issues.
  3168. float preferredHeight = 0;
  3169. while (m_IsAutoSizePointSizeSet == false)
  3170. {
  3171. preferredHeight = CalculatePreferredValues(ref fontSize, margin, m_enableAutoSizing, m_enableWordWrapping).y;
  3172. m_AutoSizeIterationCount += 1;
  3173. }
  3174. //Debug.Log("GetPreferredHeight() Called. Returning height of " + preferredHeight);
  3175. return preferredHeight;
  3176. }
  3177. /// <summary>
  3178. /// Method returning the rendered width and height of the text object.
  3179. /// </summary>
  3180. /// <returns></returns>
  3181. public Vector2 GetRenderedValues()
  3182. {
  3183. return GetTextBounds().size;
  3184. }
  3185. /// <summary>
  3186. ///
  3187. /// </summary>
  3188. /// <param name="onlyVisibleCharacters">Should returned value only factor in visible characters and exclude those greater than maxVisibleCharacters for instance.</param>
  3189. /// <returns></returns>
  3190. public Vector2 GetRenderedValues(bool onlyVisibleCharacters)
  3191. {
  3192. return GetTextBounds(onlyVisibleCharacters).size;
  3193. }
  3194. /// <summary>
  3195. /// Method returning the rendered width of the text object.
  3196. /// </summary>
  3197. /// <returns></returns>
  3198. float GetRenderedWidth()
  3199. {
  3200. return GetRenderedValues().x;
  3201. }
  3202. /// <summary>
  3203. /// Method returning the rendered width of the text object.
  3204. /// </summary>
  3205. /// <returns></returns>
  3206. protected float GetRenderedWidth(bool onlyVisibleCharacters)
  3207. {
  3208. return GetRenderedValues(onlyVisibleCharacters).x;
  3209. }
  3210. /// <summary>
  3211. /// Method returning the rendered height of the text object.
  3212. /// </summary>
  3213. /// <returns></returns>
  3214. float GetRenderedHeight()
  3215. {
  3216. return GetRenderedValues().y;
  3217. }
  3218. /// <summary>
  3219. /// Method returning the rendered height of the text object.
  3220. /// </summary>
  3221. /// <returns></returns>
  3222. protected float GetRenderedHeight(bool onlyVisibleCharacters)
  3223. {
  3224. return GetRenderedValues(onlyVisibleCharacters).y;
  3225. }
  3226. /// <summary>
  3227. /// Method to calculate the preferred width and height of the text object.
  3228. /// </summary>
  3229. /// <returns></returns>
  3230. protected virtual Vector2 CalculatePreferredValues(ref float fontSize, Vector2 marginSize, bool isTextAutoSizingEnabled, bool isWordWrappingEnabled)
  3231. {
  3232. //Debug.Log("*** CalculatePreferredValues() ***"); // ***** Frame: " + Time.frameCount);
  3233. // Early exit if no font asset was assigned. This should not be needed since LiberationSans SDF will be assigned by default.
  3234. if (m_fontAsset == null || m_fontAsset.characterLookupTable == null)
  3235. {
  3236. Debug.LogWarning("Can't Generate Mesh! No Font Asset has been assigned to Object ID: " + this.GetInstanceID());
  3237. m_IsAutoSizePointSizeSet = true;
  3238. return Vector2.zero;
  3239. }
  3240. // Early exit if we don't have any Text to generate.
  3241. if (m_TextProcessingArray == null || m_TextProcessingArray.Length == 0 || m_TextProcessingArray[0].unicode == (char)0)
  3242. {
  3243. m_IsAutoSizePointSizeSet = true;
  3244. return Vector2.zero;
  3245. }
  3246. m_currentFontAsset = m_fontAsset;
  3247. m_currentMaterial = m_sharedMaterial;
  3248. m_currentMaterialIndex = 0;
  3249. m_materialReferenceStack.SetDefault(new MaterialReference(0, m_currentFontAsset, null, m_currentMaterial, m_padding));
  3250. // Total character count is computed when the text is parsed.
  3251. int totalCharacterCount = m_totalCharacterCount; // m_VisibleCharacters.Count;
  3252. if (m_internalCharacterInfo == null || totalCharacterCount > m_internalCharacterInfo.Length)
  3253. m_internalCharacterInfo = new TMP_CharacterInfo[totalCharacterCount > 1024 ? totalCharacterCount + 256 : Mathf.NextPowerOfTwo(totalCharacterCount)];
  3254. // Calculate the scale of the font based on selected font size and sampling point size.
  3255. // baseScale is calculated using the font asset assigned to the text object.
  3256. float baseScale = (fontSize / m_fontAsset.faceInfo.pointSize * m_fontAsset.faceInfo.scale * (m_isOrthographic ? 1 : 0.1f));
  3257. float currentElementScale = baseScale;
  3258. float currentEmScale = fontSize * 0.01f * (m_isOrthographic ? 1 : 0.1f);
  3259. m_fontScaleMultiplier = 1;
  3260. m_currentFontSize = fontSize;
  3261. m_sizeStack.SetDefault(m_currentFontSize);
  3262. float fontSizeDelta = 0;
  3263. m_FontStyleInternal = m_fontStyle; // Set the default style.
  3264. m_lineJustification = m_HorizontalAlignment; // m_textAlignment; // Sets the line justification mode to match editor alignment.
  3265. m_lineJustificationStack.SetDefault(m_lineJustification);
  3266. m_baselineOffset = 0; // Used by subscript characters.
  3267. m_baselineOffsetStack.Clear();
  3268. m_lineOffset = 0; // Amount of space between lines (font line spacing + m_linespacing).
  3269. m_lineHeight = TMP_Math.FLOAT_UNSET;
  3270. float lineGap = m_currentFontAsset.faceInfo.lineHeight - (m_currentFontAsset.faceInfo.ascentLine - m_currentFontAsset.faceInfo.descentLine);
  3271. m_cSpacing = 0; // Amount of space added between characters as a result of the use of the <cspace> tag.
  3272. m_monoSpacing = 0;
  3273. //float lineOffsetDelta = 0;
  3274. m_xAdvance = 0; // Used to track the position of each character.
  3275. float maxXAdvance = 0; // Used to determine Preferred Width.
  3276. tag_LineIndent = 0; // Used for indentation of text.
  3277. tag_Indent = 0;
  3278. m_indentStack.SetDefault(0);
  3279. tag_NoParsing = false;
  3280. //m_isIgnoringAlignment = false;
  3281. m_characterCount = 0; // Total characters in the char[]
  3282. // Tracking of line information
  3283. m_firstCharacterOfLine = 0;
  3284. m_maxLineAscender = k_LargeNegativeFloat;
  3285. m_maxLineDescender = k_LargePositiveFloat;
  3286. m_lineNumber = 0;
  3287. m_startOfLineAscender = 0;
  3288. m_IsDrivenLineSpacing = false;
  3289. float marginWidth = marginSize.x;
  3290. float marginHeight = marginSize.y;
  3291. m_marginLeft = 0;
  3292. m_marginRight = 0;
  3293. float lineMarginLeft = 0;
  3294. float lineMarginRight = 0;
  3295. m_width = -1;
  3296. float widthOfTextArea = marginWidth + 0.0001f - m_marginLeft - m_marginRight;
  3297. // Used by Unity's Auto Layout system.
  3298. float renderedWidth = 0;
  3299. float renderedHeight = 0;
  3300. float textWidth = 0;
  3301. m_isCalculatingPreferredValues = true;
  3302. // Tracking of the highest Ascender
  3303. m_maxCapHeight = 0;
  3304. m_maxTextAscender = 0;
  3305. m_ElementDescender = 0;
  3306. float maxVisibleDescender = 0;
  3307. bool isMaxVisibleDescenderSet = false;
  3308. // Initialize struct to track states of word wrapping
  3309. bool isFirstWordOfLine = true;
  3310. m_isNonBreakingSpace = false;
  3311. //bool isLastBreakingChar = false;
  3312. bool isLastCharacterCJK = false;
  3313. //int lastSoftLineBreak = 0;
  3314. CharacterSubstitution characterToSubstitute = new CharacterSubstitution(-1, 0);
  3315. bool isSoftHyphenIgnored = false;
  3316. WordWrapState internalWordWrapState = new WordWrapState();
  3317. WordWrapState internalLineState = new WordWrapState();
  3318. WordWrapState internalSoftLineBreak = new WordWrapState();
  3319. // Counter to prevent recursive lockup when computing preferred values.
  3320. m_AutoSizeIterationCount += 1;
  3321. // Parse through Character buffer to read HTML tags and begin creating mesh.
  3322. for (int i = 0; i < m_TextProcessingArray.Length && m_TextProcessingArray[i].unicode != 0; i++)
  3323. {
  3324. int charCode = m_TextProcessingArray[i].unicode;
  3325. // Parse Rich Text Tag
  3326. #region Parse Rich Text Tag
  3327. if (m_isRichText && charCode == 60) // '<'
  3328. {
  3329. m_isParsingText = true;
  3330. m_textElementType = TMP_TextElementType.Character;
  3331. int endTagIndex;
  3332. // Check if Tag is valid. If valid, skip to the end of the validated tag.
  3333. if (ValidateHtmlTag(m_TextProcessingArray, i + 1, out endTagIndex))
  3334. {
  3335. i = endTagIndex;
  3336. // Continue to next character or handle the sprite element
  3337. if (m_textElementType == TMP_TextElementType.Character)
  3338. continue;
  3339. }
  3340. }
  3341. else
  3342. {
  3343. m_textElementType = m_textInfo.characterInfo[m_characterCount].elementType;
  3344. m_currentMaterialIndex = m_textInfo.characterInfo[m_characterCount].materialReferenceIndex;
  3345. m_currentFontAsset = m_textInfo.characterInfo[m_characterCount].fontAsset;
  3346. }
  3347. #endregion End Parse Rich Text Tag
  3348. int prev_MaterialIndex = m_currentMaterialIndex;
  3349. bool isUsingAltTypeface = m_textInfo.characterInfo[m_characterCount].isUsingAlternateTypeface;
  3350. m_isParsingText = false;
  3351. // Handle potential character substitutions
  3352. #region Character Substitutions
  3353. bool isInjectingCharacter = false;
  3354. if (characterToSubstitute.index == m_characterCount)
  3355. {
  3356. charCode = (int)characterToSubstitute.unicode;
  3357. m_textElementType = TMP_TextElementType.Character;
  3358. isInjectingCharacter = true;
  3359. switch (charCode)
  3360. {
  3361. case 0x03:
  3362. m_internalCharacterInfo[m_characterCount].textElement = m_currentFontAsset.characterLookupTable[0x03];
  3363. m_isTextTruncated = true;
  3364. break;
  3365. case 0x2D:
  3366. //
  3367. break;
  3368. case 0x2026:
  3369. m_internalCharacterInfo[m_characterCount].textElement = m_Ellipsis.character; ;
  3370. m_internalCharacterInfo[m_characterCount].elementType = TMP_TextElementType.Character;
  3371. m_internalCharacterInfo[m_characterCount].fontAsset = m_Ellipsis.fontAsset;
  3372. m_internalCharacterInfo[m_characterCount].material = m_Ellipsis.material;
  3373. m_internalCharacterInfo[m_characterCount].materialReferenceIndex = m_Ellipsis.materialIndex;
  3374. // Indicates the source parsing data has been modified.
  3375. m_isTextTruncated = true;
  3376. // End Of Text
  3377. characterToSubstitute.index = m_characterCount + 1;
  3378. characterToSubstitute.unicode = 0x03;
  3379. break;
  3380. }
  3381. }
  3382. #endregion
  3383. // When using Linked text, mark character as ignored and skip to next character.
  3384. #region Linked Text
  3385. if (m_characterCount < m_firstVisibleCharacter && charCode != 0x03)
  3386. {
  3387. m_internalCharacterInfo[m_characterCount].isVisible = false;
  3388. m_internalCharacterInfo[m_characterCount].character = (char)0x200B;
  3389. m_internalCharacterInfo[m_characterCount].lineNumber = 0;
  3390. m_characterCount += 1;
  3391. continue;
  3392. }
  3393. #endregion
  3394. // Handle Font Styles like LowerCase, UpperCase and SmallCaps.
  3395. #region Handling of LowerCase, UpperCase and SmallCaps Font Styles
  3396. float smallCapsMultiplier = 1.0f;
  3397. if (m_textElementType == TMP_TextElementType.Character)
  3398. {
  3399. if (/*(m_fontStyle & FontStyles.UpperCase) == FontStyles.UpperCase ||*/ (m_FontStyleInternal & FontStyles.UpperCase) == FontStyles.UpperCase)
  3400. {
  3401. // If this character is lowercase, switch to uppercase.
  3402. if (char.IsLower((char)charCode))
  3403. charCode = char.ToUpper((char)charCode);
  3404. }
  3405. else if (/*(m_fontStyle & FontStyles.LowerCase) == FontStyles.LowerCase ||*/ (m_FontStyleInternal & FontStyles.LowerCase) == FontStyles.LowerCase)
  3406. {
  3407. // If this character is uppercase, switch to lowercase.
  3408. if (char.IsUpper((char)charCode))
  3409. charCode = char.ToLower((char)charCode);
  3410. }
  3411. else if (/*(m_fontStyle & FontStyles.SmallCaps) == FontStyles.SmallCaps ||*/ (m_FontStyleInternal & FontStyles.SmallCaps) == FontStyles.SmallCaps)
  3412. {
  3413. if (char.IsLower((char)charCode))
  3414. {
  3415. smallCapsMultiplier = 0.8f;
  3416. charCode = char.ToUpper((char)charCode);
  3417. }
  3418. }
  3419. }
  3420. #endregion
  3421. // Look up Character Data from Dictionary and cache it.
  3422. #region Look up Character Data
  3423. //float baselineOffset = 0;
  3424. float elementAscentLine = 0;
  3425. float elementDescentLine = 0;
  3426. if (m_textElementType == TMP_TextElementType.Sprite)
  3427. {
  3428. // If a sprite is used as a fallback then get a reference to it and set the color to white.
  3429. m_currentSpriteAsset = m_textInfo.characterInfo[m_characterCount].spriteAsset;
  3430. m_spriteIndex = m_textInfo.characterInfo[m_characterCount].spriteIndex;
  3431. TMP_SpriteCharacter sprite = m_currentSpriteAsset.spriteCharacterTable[m_spriteIndex];
  3432. if (sprite == null) continue;
  3433. // Sprites are assigned in the E000 Private Area + sprite Index
  3434. if (charCode == 60)
  3435. charCode = 57344 + m_spriteIndex;
  3436. // The sprite scale calculations are based on the font asset assigned to the text object.
  3437. if (m_currentSpriteAsset.faceInfo.pointSize > 0)
  3438. {
  3439. float spriteScale = (m_currentFontSize / m_currentSpriteAsset.faceInfo.pointSize * m_currentSpriteAsset.faceInfo.scale * (m_isOrthographic ? 1 : 0.1f));
  3440. currentElementScale = sprite.scale * sprite.glyph.scale * spriteScale;
  3441. elementAscentLine = m_currentSpriteAsset.faceInfo.ascentLine;
  3442. //baselineOffset = m_currentSpriteAsset.faceInfo.baseline * m_fontScale * m_fontScaleMultiplier * m_currentSpriteAsset.faceInfo.scale;
  3443. elementDescentLine = m_currentSpriteAsset.faceInfo.descentLine;
  3444. }
  3445. else
  3446. {
  3447. float spriteScale = (m_currentFontSize / m_currentFontAsset.faceInfo.pointSize * m_currentFontAsset.faceInfo.scale * (m_isOrthographic ? 1 : 0.1f));
  3448. currentElementScale = m_currentFontAsset.faceInfo.ascentLine / sprite.glyph.metrics.height * sprite.scale * sprite.glyph.scale * spriteScale;
  3449. float scaleDelta = spriteScale / currentElementScale;
  3450. elementAscentLine = m_currentFontAsset.faceInfo.ascentLine * scaleDelta;
  3451. //baselineOffset = m_currentFontAsset.faceInfo.baseline * m_fontScale * m_fontScaleMultiplier * m_currentFontAsset.faceInfo.scale;
  3452. elementDescentLine = m_currentFontAsset.faceInfo.descentLine * scaleDelta;
  3453. }
  3454. m_cached_TextElement = sprite;
  3455. m_internalCharacterInfo[m_characterCount].elementType = TMP_TextElementType.Sprite;
  3456. m_internalCharacterInfo[m_characterCount].scale = currentElementScale;
  3457. m_currentMaterialIndex = prev_MaterialIndex;
  3458. }
  3459. else if (m_textElementType == TMP_TextElementType.Character)
  3460. {
  3461. m_cached_TextElement = m_textInfo.characterInfo[m_characterCount].textElement;
  3462. if (m_cached_TextElement == null) continue;
  3463. m_currentMaterialIndex = m_textInfo.characterInfo[m_characterCount].materialReferenceIndex;
  3464. float adjustedScale;
  3465. if (isInjectingCharacter && m_TextProcessingArray[i].unicode == 0x0A && m_characterCount != m_firstCharacterOfLine)
  3466. adjustedScale = m_textInfo.characterInfo[m_characterCount - 1].pointSize * smallCapsMultiplier / m_currentFontAsset.m_FaceInfo.pointSize * m_currentFontAsset.m_FaceInfo.scale * (m_isOrthographic ? 1 : 0.1f);
  3467. else
  3468. adjustedScale = m_currentFontSize * smallCapsMultiplier / m_currentFontAsset.m_FaceInfo.pointSize * m_currentFontAsset.m_FaceInfo.scale * (m_isOrthographic ? 1 : 0.1f);
  3469. // Special handling for injected Ellipsis
  3470. if (isInjectingCharacter && charCode == 0x2026)
  3471. {
  3472. elementAscentLine = 0;
  3473. elementDescentLine = 0;
  3474. }
  3475. else
  3476. {
  3477. elementAscentLine = m_currentFontAsset.m_FaceInfo.ascentLine;
  3478. elementDescentLine = m_currentFontAsset.m_FaceInfo.descentLine;
  3479. }
  3480. currentElementScale = adjustedScale * m_fontScaleMultiplier * m_cached_TextElement.scale;
  3481. //baselineOffset = m_currentFontAsset.faceInfo.baseline * m_fontScale * m_fontScaleMultiplier * m_currentFontAsset.faceInfo.scale;
  3482. m_internalCharacterInfo[m_characterCount].elementType = TMP_TextElementType.Character;
  3483. }
  3484. #endregion
  3485. // Handle Soft Hyphen
  3486. #region Handle Soft Hyphen
  3487. float currentElementUnmodifiedScale = currentElementScale;
  3488. if (charCode == 0xAD || charCode == 0x03)
  3489. currentElementScale = 0;
  3490. #endregion
  3491. // Store some of the text object's information
  3492. m_internalCharacterInfo[m_characterCount].character = (char)charCode;
  3493. // Cache glyph metrics
  3494. GlyphMetrics currentGlyphMetrics = m_cached_TextElement.m_Glyph.metrics;
  3495. // Optimization to avoid calling this more than once per character.
  3496. bool isWhiteSpace = charCode <= 0xFFFF && char.IsWhiteSpace((char)charCode);
  3497. // Handle Kerning if Enabled.
  3498. #region Handle Kerning
  3499. TMP_GlyphValueRecord glyphAdjustments = new TMP_GlyphValueRecord();
  3500. float characterSpacingAdjustment = m_characterSpacing;
  3501. m_GlyphHorizontalAdvanceAdjustment = 0;
  3502. if (m_enableKerning)
  3503. {
  3504. TMP_GlyphPairAdjustmentRecord adjustmentPair;
  3505. uint baseGlyphIndex = m_cached_TextElement.m_GlyphIndex;
  3506. if (m_characterCount < totalCharacterCount - 1)
  3507. {
  3508. uint nextGlyphIndex = m_textInfo.characterInfo[m_characterCount + 1].textElement.m_GlyphIndex;
  3509. uint key = nextGlyphIndex << 16 | baseGlyphIndex;
  3510. if (m_currentFontAsset.m_FontFeatureTable.m_GlyphPairAdjustmentRecordLookupDictionary.TryGetValue(key, out adjustmentPair))
  3511. {
  3512. glyphAdjustments = adjustmentPair.m_FirstAdjustmentRecord.m_GlyphValueRecord;
  3513. characterSpacingAdjustment = (adjustmentPair.m_FeatureLookupFlags & FontFeatureLookupFlags.IgnoreSpacingAdjustments) == FontFeatureLookupFlags.IgnoreSpacingAdjustments ? 0 : characterSpacingAdjustment;
  3514. }
  3515. }
  3516. if (m_characterCount >= 1)
  3517. {
  3518. uint previousGlyphIndex = m_textInfo.characterInfo[m_characterCount - 1].textElement.m_GlyphIndex;
  3519. uint key = baseGlyphIndex << 16 | previousGlyphIndex;
  3520. if (m_currentFontAsset.m_FontFeatureTable.m_GlyphPairAdjustmentRecordLookupDictionary.TryGetValue(key, out adjustmentPair))
  3521. {
  3522. glyphAdjustments += adjustmentPair.m_SecondAdjustmentRecord.m_GlyphValueRecord;
  3523. characterSpacingAdjustment = (adjustmentPair.m_FeatureLookupFlags & FontFeatureLookupFlags.IgnoreSpacingAdjustments) == FontFeatureLookupFlags.IgnoreSpacingAdjustments ? 0 : characterSpacingAdjustment;
  3524. }
  3525. }
  3526. m_GlyphHorizontalAdvanceAdjustment = glyphAdjustments.m_XAdvance;
  3527. }
  3528. #endregion
  3529. // Initial Implementation for RTL support.
  3530. #region Handle Right-to-Left
  3531. //if (m_isRightToLeft)
  3532. //{
  3533. // m_xAdvance -= ((m_cached_TextElement.xAdvance * bold_xAdvance_multiplier + m_characterSpacing + m_wordSpacing + m_currentFontAsset.normalSpacingOffset) * currentElementScale + m_cSpacing) * (1 - m_charWidthAdjDelta);
  3534. // if (char.IsWhiteSpace((char)charCode) || charCode == 0x200B)
  3535. // m_xAdvance -= m_wordSpacing * currentElementScale;
  3536. //}
  3537. #endregion
  3538. // Handle Mono Spacing
  3539. #region Handle Mono Spacing
  3540. float monoAdvance = 0;
  3541. if (m_monoSpacing != 0)
  3542. {
  3543. monoAdvance = (m_monoSpacing / 2 - (m_cached_TextElement.glyph.metrics.width / 2 + m_cached_TextElement.glyph.metrics.horizontalBearingX) * currentElementScale) * (1 - m_charWidthAdjDelta);
  3544. m_xAdvance += monoAdvance;
  3545. }
  3546. #endregion
  3547. // Set Padding based on selected font style
  3548. #region Handle Style Padding
  3549. float boldSpacingAdjustment = 0;
  3550. if (m_textElementType == TMP_TextElementType.Character && !isUsingAltTypeface && ((m_FontStyleInternal & FontStyles.Bold) == FontStyles.Bold)) // Checks for any combination of Bold Style.
  3551. boldSpacingAdjustment = m_currentFontAsset.boldSpacing;
  3552. #endregion Handle Style Padding
  3553. m_internalCharacterInfo[m_characterCount].baseLine = 0 - m_lineOffset + m_baselineOffset;
  3554. // Compute text metrics
  3555. #region Compute Ascender & Descender values
  3556. // Element Ascender in line space
  3557. float elementAscender = m_textElementType == TMP_TextElementType.Character
  3558. ? elementAscentLine * currentElementScale / smallCapsMultiplier + m_baselineOffset
  3559. : elementAscentLine * currentElementScale + m_baselineOffset;
  3560. // Element Descender in line space
  3561. float elementDescender = m_textElementType == TMP_TextElementType.Character
  3562. ? elementDescentLine * currentElementScale / smallCapsMultiplier + m_baselineOffset
  3563. : elementDescentLine * currentElementScale + m_baselineOffset;
  3564. float adjustedAscender = elementAscender;
  3565. float adjustedDescender = elementDescender;
  3566. bool isFirstCharacterOfLine = m_characterCount == m_firstCharacterOfLine;
  3567. // Max line ascender and descender in line space
  3568. if (isFirstCharacterOfLine || isWhiteSpace == false)
  3569. {
  3570. // Special handling for Superscript and Subscript where we use the unadjusted line ascender and descender
  3571. if (m_baselineOffset != 0)
  3572. {
  3573. adjustedAscender = Mathf.Max((elementAscender - m_baselineOffset) / m_fontScaleMultiplier, adjustedAscender);
  3574. adjustedDescender = Mathf.Min((elementDescender - m_baselineOffset) / m_fontScaleMultiplier, adjustedDescender);
  3575. }
  3576. m_maxLineAscender = Mathf.Max(adjustedAscender, m_maxLineAscender);
  3577. m_maxLineDescender = Mathf.Min(adjustedDescender, m_maxLineDescender);
  3578. }
  3579. // Element Ascender and Descender in object space
  3580. if (isFirstCharacterOfLine || isWhiteSpace == false)
  3581. {
  3582. m_internalCharacterInfo[m_characterCount].adjustedAscender = adjustedAscender;
  3583. m_internalCharacterInfo[m_characterCount].adjustedDescender = adjustedDescender;
  3584. m_ElementAscender = m_internalCharacterInfo[m_characterCount].ascender = elementAscender - m_lineOffset;
  3585. m_ElementDescender = m_internalCharacterInfo[m_characterCount].descender = elementDescender - m_lineOffset;
  3586. }
  3587. else
  3588. {
  3589. m_internalCharacterInfo[m_characterCount].adjustedAscender = m_maxLineAscender;
  3590. m_internalCharacterInfo[m_characterCount].adjustedDescender = m_maxLineDescender;
  3591. m_ElementAscender = m_internalCharacterInfo[m_characterCount].ascender = m_maxLineAscender - m_lineOffset;
  3592. m_ElementDescender = m_internalCharacterInfo[m_characterCount].descender = m_maxLineDescender - m_lineOffset;
  3593. }
  3594. // Max text object ascender and cap height
  3595. if (m_lineNumber == 0 || m_isNewPage)
  3596. {
  3597. if (isFirstCharacterOfLine || isWhiteSpace == false)
  3598. {
  3599. m_maxTextAscender = m_maxLineAscender;
  3600. m_maxCapHeight = Mathf.Max(m_maxCapHeight, m_currentFontAsset.m_FaceInfo.capLine * currentElementScale / smallCapsMultiplier);
  3601. }
  3602. }
  3603. // Page ascender
  3604. if (m_lineOffset == 0)
  3605. {
  3606. if (!isWhiteSpace || m_characterCount == m_firstCharacterOfLine)
  3607. m_PageAscender = m_PageAscender > elementAscender ? m_PageAscender : elementAscender;
  3608. }
  3609. #endregion
  3610. bool isJustifiedOrFlush = (m_lineJustification & HorizontalAlignmentOptions.Flush) == HorizontalAlignmentOptions.Flush || (m_lineJustification & HorizontalAlignmentOptions.Justified) == HorizontalAlignmentOptions.Justified;
  3611. // Setup Mesh for visible text elements. ie. not a SPACE / LINEFEED / CARRIAGE RETURN.
  3612. #region Handle Visible Characters
  3613. if (charCode == 9 || (isWhiteSpace == false && charCode != 0x200B && charCode != 0xAD && charCode != 0x03) || (charCode == 0xAD && isSoftHyphenIgnored == false) || m_textElementType == TMP_TextElementType.Sprite)
  3614. {
  3615. //float marginLeft = m_marginLeft;
  3616. //float marginRight = m_marginRight;
  3617. // Injected characters do not override margins
  3618. //if (isInjectingCharacter)
  3619. //{
  3620. // marginLeft = m_textInfo.lineInfo[m_lineNumber].marginLeft;
  3621. // marginRight = m_textInfo.lineInfo[m_lineNumber].marginRight;
  3622. //}
  3623. widthOfTextArea = m_width != -1 ? Mathf.Min(marginWidth + 0.0001f - m_marginLeft - m_marginRight, m_width) : marginWidth + 0.0001f - m_marginLeft - m_marginRight;
  3624. // Calculate the line breaking width of the text.
  3625. textWidth = Mathf.Abs(m_xAdvance) + currentGlyphMetrics.horizontalAdvance * (1 - m_charWidthAdjDelta) * (charCode == 0xAD ? currentElementUnmodifiedScale : currentElementScale);
  3626. int testedCharacterCount = m_characterCount;
  3627. // Handling of Horizontal Bounds
  3628. #region Current Line Horizontal Bounds Check
  3629. if (textWidth > widthOfTextArea * (isJustifiedOrFlush ? 1.05f : 1.0f))
  3630. {
  3631. // Handle Line Breaking (if still possible)
  3632. if (isWordWrappingEnabled && m_characterCount != m_firstCharacterOfLine) // && isFirstWord == false)
  3633. {
  3634. // Restore state to previous safe line breaking
  3635. i = RestoreWordWrappingState(ref internalWordWrapState);
  3636. // Replace Soft Hyphen by Hyphen Minus 0x2D
  3637. #region Handle Soft Hyphenation
  3638. if (m_internalCharacterInfo[m_characterCount - 1].character == 0xAD && isSoftHyphenIgnored == false && m_overflowMode == TextOverflowModes.Overflow)
  3639. {
  3640. characterToSubstitute.index = m_characterCount - 1;
  3641. characterToSubstitute.unicode = 0x2D;
  3642. i -= 1;
  3643. m_characterCount -= 1;
  3644. continue;
  3645. }
  3646. isSoftHyphenIgnored = false;
  3647. // Ignore Soft Hyphen to prevent it from wrapping
  3648. if (m_internalCharacterInfo[m_characterCount].character == 0xAD)
  3649. {
  3650. isSoftHyphenIgnored = true;
  3651. continue;
  3652. }
  3653. #endregion
  3654. // Adjust character spacing before breaking up word if auto size is enabled
  3655. #region Handle Text Auto Size (if word wrapping is no longer possible)
  3656. if (isTextAutoSizingEnabled && isFirstWordOfLine)
  3657. {
  3658. // Handle Character Width Adjustments
  3659. #region Character Width Adjustments
  3660. if (m_charWidthAdjDelta < m_charWidthMaxAdj / 100 && m_AutoSizeIterationCount < m_AutoSizeMaxIterationCount)
  3661. {
  3662. float adjustedTextWidth = textWidth;
  3663. // Determine full width of the text
  3664. if (m_charWidthAdjDelta > 0)
  3665. adjustedTextWidth /= 1f - m_charWidthAdjDelta;
  3666. float adjustmentDelta = textWidth - (widthOfTextArea - 0.0001f) * (isJustifiedOrFlush ? 1.05f : 1.0f);
  3667. m_charWidthAdjDelta += adjustmentDelta / adjustedTextWidth;
  3668. m_charWidthAdjDelta = Mathf.Min(m_charWidthAdjDelta, m_charWidthMaxAdj / 100);
  3669. //Debug.Log("[" + m_AutoSizeIterationCount + "] Reducing Character Width by " + (m_charWidthAdjDelta * 100) + "%");
  3670. return Vector2.zero;
  3671. }
  3672. #endregion
  3673. // Handle Text Auto-sizing resulting from text exceeding vertical bounds.
  3674. #region Text Auto-Sizing (Text greater than vertical bounds)
  3675. if (fontSize > m_fontSizeMin && m_AutoSizeIterationCount < m_AutoSizeMaxIterationCount)
  3676. {
  3677. m_maxFontSize = fontSize;
  3678. float sizeDelta = Mathf.Max((fontSize - m_minFontSize) / 2, 0.05f);
  3679. fontSize -= sizeDelta;
  3680. fontSize = Mathf.Max((int)(fontSize * 20 + 0.5f) / 20f, m_fontSizeMin);
  3681. //Debug.Log("[" + m_AutoSizeIterationCount + "] Reducing Point Size from [" + m_maxFontSize.ToString("f3") + "] to [" + m_fontSize.ToString("f3") + "] with delta of [" + sizeDelta.ToString("f3") + "].");
  3682. return Vector2.zero;
  3683. }
  3684. #endregion Text Auto-Sizing
  3685. }
  3686. #endregion
  3687. // Adjust line spacing if necessary
  3688. float baselineAdjustmentDelta = m_maxLineAscender - m_startOfLineAscender;
  3689. if (m_lineOffset > 0 && Math.Abs(baselineAdjustmentDelta) > 0.01f && m_IsDrivenLineSpacing == false && !m_isNewPage)
  3690. {
  3691. //AdjustLineOffset(m_firstCharacterOfLine, m_characterCount, baselineAdjustmentDelta);
  3692. m_ElementDescender -= baselineAdjustmentDelta;
  3693. m_lineOffset += baselineAdjustmentDelta;
  3694. }
  3695. // Calculate line ascender and make sure if last character is superscript or subscript that we check that as well.
  3696. float lineAscender = m_maxLineAscender - m_lineOffset;
  3697. float lineDescender = m_maxLineDescender - m_lineOffset;
  3698. // Update maxDescender and maxVisibleDescender
  3699. m_ElementDescender = m_ElementDescender < lineDescender ? m_ElementDescender : lineDescender;
  3700. if (!isMaxVisibleDescenderSet)
  3701. maxVisibleDescender = m_ElementDescender;
  3702. if (m_useMaxVisibleDescender && (m_characterCount >= m_maxVisibleCharacters || m_lineNumber >= m_maxVisibleLines))
  3703. isMaxVisibleDescenderSet = true;
  3704. // Store first character of the next line.
  3705. m_firstCharacterOfLine = m_characterCount;
  3706. m_lineVisibleCharacterCount = 0;
  3707. // Compute Preferred Width & Height
  3708. renderedWidth += m_xAdvance;
  3709. if (isWordWrappingEnabled)
  3710. renderedHeight = m_maxTextAscender - m_ElementDescender;
  3711. else
  3712. renderedHeight = Mathf.Max(renderedHeight, lineAscender - lineDescender);
  3713. // Store the state of the line before starting on the new line.
  3714. SaveWordWrappingState(ref internalLineState, i, m_characterCount - 1);
  3715. m_lineNumber += 1;
  3716. float ascender = m_internalCharacterInfo[m_characterCount].adjustedAscender;
  3717. // Compute potential new line offset in the event a line break is needed.
  3718. if (m_lineHeight == TMP_Math.FLOAT_UNSET)
  3719. {
  3720. m_lineOffset += 0 - m_maxLineDescender + ascender + (lineGap + m_lineSpacingDelta) * baseScale + m_lineSpacing * currentEmScale;
  3721. m_IsDrivenLineSpacing = false;
  3722. }
  3723. else
  3724. {
  3725. m_lineOffset += m_lineHeight + m_lineSpacing * currentEmScale;
  3726. m_IsDrivenLineSpacing = true;
  3727. }
  3728. m_maxLineAscender = k_LargeNegativeFloat;
  3729. m_maxLineDescender = k_LargePositiveFloat;
  3730. m_startOfLineAscender = ascender;
  3731. m_xAdvance = 0 + tag_Indent;
  3732. //isStartOfNewLine = true;
  3733. isFirstWordOfLine = true;
  3734. continue;
  3735. }
  3736. }
  3737. #endregion
  3738. lineMarginLeft = m_marginLeft;
  3739. lineMarginRight = m_marginRight;
  3740. }
  3741. #endregion Handle Visible Characters
  3742. // Check if Line Spacing of previous line needs to be adjusted.
  3743. #region Adjust Line Spacing
  3744. /*if (m_lineOffset > 0 && !TMP_Math.Approximately(m_maxLineAscender, m_startOfLineAscender) && m_IsDrivenLineSpacing == false && !m_isNewPage)
  3745. {
  3746. float offsetDelta = m_maxLineAscender - m_startOfLineAscender;
  3747. //AdjustLineOffset(m_firstCharacterOfLine, m_characterCount, offsetDelta);
  3748. m_ElementDescender -= offsetDelta;
  3749. m_lineOffset += offsetDelta;
  3750. m_startOfLineAscender += offsetDelta;
  3751. internalWordWrapState.lineOffset = m_lineOffset;
  3752. internalWordWrapState.startOfLineAscender = m_startOfLineAscender;
  3753. }*/
  3754. #endregion
  3755. // Handle xAdvance & Tabulation Stops. Tab stops at every 25% of Font Size.
  3756. #region XAdvance, Tabulation & Stops
  3757. if (charCode == 9)
  3758. {
  3759. float tabSize = m_currentFontAsset.faceInfo.tabWidth * m_currentFontAsset.tabSize * currentElementScale;
  3760. float tabs = Mathf.Ceil(m_xAdvance / tabSize) * tabSize;
  3761. m_xAdvance = tabs > m_xAdvance ? tabs : m_xAdvance + tabSize;
  3762. }
  3763. else if (m_monoSpacing != 0)
  3764. {
  3765. m_xAdvance += (m_monoSpacing - monoAdvance + ((m_currentFontAsset.normalSpacingOffset + characterSpacingAdjustment) * currentEmScale) + m_cSpacing) * (1 - m_charWidthAdjDelta);
  3766. if (isWhiteSpace || charCode == 0x200B)
  3767. m_xAdvance += m_wordSpacing * currentEmScale;
  3768. }
  3769. else
  3770. {
  3771. m_xAdvance += ((currentGlyphMetrics.horizontalAdvance + glyphAdjustments.xAdvance) * currentElementScale + (m_currentFontAsset.normalSpacingOffset + characterSpacingAdjustment + boldSpacingAdjustment) * currentEmScale + m_cSpacing) * (1 - m_charWidthAdjDelta);
  3772. if (isWhiteSpace || charCode == 0x200B)
  3773. m_xAdvance += m_wordSpacing * currentEmScale;
  3774. }
  3775. #endregion Tabulation & Stops
  3776. // Handle Carriage Return
  3777. #region Carriage Return
  3778. if (charCode == 13)
  3779. {
  3780. maxXAdvance = Mathf.Max(maxXAdvance, renderedWidth + m_xAdvance);
  3781. renderedWidth = 0;
  3782. m_xAdvance = 0 + tag_Indent;
  3783. }
  3784. #endregion Carriage Return
  3785. // Handle Line Spacing Adjustments + Word Wrapping & special case for last line.
  3786. #region Check for Line Feed and Last Character
  3787. if (charCode == 10 || charCode == 11 || charCode == 0x03 || charCode == 0x2028 || charCode == 0x2029 || m_characterCount == totalCharacterCount - 1)
  3788. {
  3789. // Check if Line Spacing of previous line needs to be adjusted.
  3790. float baselineAdjustmentDelta = m_maxLineAscender - m_startOfLineAscender;
  3791. if (m_lineOffset > 0 && Math.Abs(baselineAdjustmentDelta) > 0.01f && m_IsDrivenLineSpacing == false && !m_isNewPage)
  3792. {
  3793. m_ElementDescender -= baselineAdjustmentDelta;
  3794. m_lineOffset += baselineAdjustmentDelta;
  3795. }
  3796. m_isNewPage = false;
  3797. // Calculate lineAscender & make sure if last character is superscript or subscript that we check that as well.
  3798. //float lineAscender = m_maxLineAscender - m_lineOffset;
  3799. float lineDescender = m_maxLineDescender - m_lineOffset;
  3800. // Update maxDescender and maxVisibleDescender
  3801. m_ElementDescender = m_ElementDescender < lineDescender ? m_ElementDescender : lineDescender;
  3802. // Store PreferredWidth paying attention to linefeed and last character of text.
  3803. if (m_characterCount == totalCharacterCount - 1)
  3804. renderedWidth = Mathf.Max(maxXAdvance, renderedWidth + textWidth + lineMarginLeft + lineMarginRight);
  3805. else
  3806. {
  3807. maxXAdvance = Mathf.Max(maxXAdvance, renderedWidth + textWidth + lineMarginLeft + lineMarginRight);
  3808. renderedWidth = 0;
  3809. }
  3810. renderedHeight = m_maxTextAscender - m_ElementDescender;
  3811. // Add new line if not last lines or character.
  3812. if (charCode == 10 || charCode == 11 || charCode == 0x2D || charCode == 0x2028 || charCode == 0x2029)
  3813. {
  3814. // Store the state of the line before starting on the new line.
  3815. SaveWordWrappingState(ref internalLineState, i, m_characterCount);
  3816. // Store the state of the last Character before the new line.
  3817. SaveWordWrappingState(ref internalWordWrapState, i, m_characterCount);
  3818. m_lineNumber += 1;
  3819. m_firstCharacterOfLine = m_characterCount + 1;
  3820. float ascender = m_internalCharacterInfo[m_characterCount].adjustedAscender;
  3821. // Apply Line Spacing with special handling for VT char(11)
  3822. if (m_lineHeight == TMP_Math.FLOAT_UNSET)
  3823. {
  3824. float lineOffsetDelta = 0 - m_maxLineDescender + ascender + (lineGap + m_lineSpacingDelta) * baseScale + (m_lineSpacing + (charCode == 10 || charCode == 0x2029 ? m_paragraphSpacing : 0)) * currentEmScale;
  3825. m_lineOffset += lineOffsetDelta;
  3826. m_IsDrivenLineSpacing = false;
  3827. }
  3828. else
  3829. {
  3830. m_lineOffset += m_lineHeight + (m_lineSpacing + (charCode == 10 || charCode == 0x2029 ? m_paragraphSpacing : 0)) * currentEmScale;
  3831. m_IsDrivenLineSpacing = true;
  3832. }
  3833. m_maxLineAscender = k_LargeNegativeFloat;
  3834. m_maxLineDescender = k_LargePositiveFloat;
  3835. m_startOfLineAscender = ascender;
  3836. m_xAdvance = 0 + tag_LineIndent + tag_Indent;
  3837. m_characterCount += 1;
  3838. continue;
  3839. }
  3840. // If End of Text
  3841. if (charCode == 0x03)
  3842. i = m_TextProcessingArray.Length;
  3843. }
  3844. #endregion Check for Linefeed or Last Character
  3845. // Save State of Mesh Creation for handling of Word Wrapping
  3846. #region Save Word Wrapping State
  3847. if (isWordWrappingEnabled || m_overflowMode == TextOverflowModes.Truncate || m_overflowMode == TextOverflowModes.Ellipsis)
  3848. {
  3849. if ((isWhiteSpace || charCode == 0x200B || charCode == 0x2D || charCode == 0xAD) && !m_isNonBreakingSpace && charCode != 0xA0 && charCode != 0x2007 && charCode != 0x2011 && charCode != 0x202F && charCode != 0x2060)
  3850. {
  3851. // We store the state of numerous variables for the most recent Space, LineFeed or Carriage Return to enable them to be restored
  3852. // for Word Wrapping.
  3853. SaveWordWrappingState(ref internalWordWrapState, i, m_characterCount);
  3854. isFirstWordOfLine = false;
  3855. isLastCharacterCJK = false;
  3856. // Reset soft line breaking point since we now have a valid hard break point.
  3857. internalSoftLineBreak.previous_WordBreak = -1;
  3858. }
  3859. // Handling for East Asian languages
  3860. else if (m_isNonBreakingSpace == false &&
  3861. ((charCode > 0x1100 && charCode < 0x11ff || /* Hangul Jamo */
  3862. charCode > 0xA960 && charCode < 0xA97F || /* Hangul Jamo Extended-A */
  3863. charCode > 0xAC00 && charCode < 0xD7FF)&& /* Hangul Syllables */
  3864. TMP_Settings.useModernHangulLineBreakingRules == false ||
  3865. (charCode > 0x2E80 && charCode < 0x9FFF || /* CJK */
  3866. charCode > 0xF900 && charCode < 0xFAFF || /* CJK Compatibility Ideographs */
  3867. charCode > 0xFE30 && charCode < 0xFE4F || /* CJK Compatibility Forms */
  3868. charCode > 0xFF00 && charCode < 0xFFEF))) /* CJK Halfwidth */
  3869. {
  3870. bool isLeadingCharacter = TMP_Settings.linebreakingRules.leadingCharacters.ContainsKey(charCode);
  3871. bool isFollowingCharacter = m_characterCount < totalCharacterCount - 1 && TMP_Settings.linebreakingRules.followingCharacters.ContainsKey(m_internalCharacterInfo[m_characterCount + 1].character);
  3872. if (isFirstWordOfLine || isLeadingCharacter == false)
  3873. {
  3874. if (isFollowingCharacter == false)
  3875. {
  3876. SaveWordWrappingState(ref internalWordWrapState, i, m_characterCount);
  3877. isFirstWordOfLine = false;
  3878. }
  3879. if (isFirstWordOfLine)
  3880. {
  3881. // Special handling for non-breaking space and soft line breaks
  3882. if (isWhiteSpace)
  3883. SaveWordWrappingState(ref internalSoftLineBreak, i, m_characterCount);
  3884. SaveWordWrappingState(ref internalWordWrapState, i, m_characterCount);
  3885. }
  3886. }
  3887. isLastCharacterCJK = true;
  3888. }
  3889. else if (isLastCharacterCJK)
  3890. {
  3891. bool isLeadingCharacter = TMP_Settings.linebreakingRules.leadingCharacters.ContainsKey(charCode);
  3892. if (isLeadingCharacter == false)
  3893. SaveWordWrappingState(ref internalWordWrapState, i, m_characterCount);
  3894. isLastCharacterCJK = false;
  3895. }
  3896. else if (isFirstWordOfLine)
  3897. {
  3898. // Special handling for non-breaking space and soft line breaks
  3899. if (isWhiteSpace || (charCode == 0xAD && isSoftHyphenIgnored == false))
  3900. SaveWordWrappingState(ref internalSoftLineBreak, i, m_characterCount);
  3901. SaveWordWrappingState(ref internalWordWrapState, i, m_characterCount);
  3902. isLastCharacterCJK = false;
  3903. }
  3904. }
  3905. #endregion Save Word Wrapping State
  3906. m_characterCount += 1;
  3907. }
  3908. // Check Auto Sizing and increase font size to fill text container.
  3909. #region Check Auto-Sizing (Upper Font Size Bounds)
  3910. fontSizeDelta = m_maxFontSize - m_minFontSize;
  3911. if (isTextAutoSizingEnabled && fontSizeDelta > 0.051f && fontSize < m_fontSizeMax && m_AutoSizeIterationCount < m_AutoSizeMaxIterationCount)
  3912. {
  3913. // Reset character width adjustment delta
  3914. if (m_charWidthAdjDelta < m_charWidthMaxAdj / 100)
  3915. m_charWidthAdjDelta = 0;
  3916. m_minFontSize = fontSize;
  3917. float sizeDelta = Mathf.Max((m_maxFontSize - fontSize) / 2, 0.05f);
  3918. fontSize += sizeDelta;
  3919. fontSize = Mathf.Min((int)(fontSize * 20 + 0.5f) / 20f, m_fontSizeMax);
  3920. //Debug.Log("[" + m_AutoSizeIterationCount + "] Increasing Point Size from [" + m_minFontSize.ToString("f3") + "] to [" + m_fontSize.ToString("f3") + "] with delta of [" + sizeDelta.ToString("f3") + "].");
  3921. return Vector2.zero;
  3922. }
  3923. #endregion End Auto-sizing Check
  3924. m_IsAutoSizePointSizeSet = true;
  3925. m_isCalculatingPreferredValues = false;
  3926. // Adjust Preferred Width and Height to account for Margins.
  3927. renderedWidth += m_margin.x > 0 ? m_margin.x : 0;
  3928. renderedWidth += m_margin.z > 0 ? m_margin.z : 0;
  3929. renderedHeight += m_margin.y > 0 ? m_margin.y : 0;
  3930. renderedHeight += m_margin.w > 0 ? m_margin.w : 0;
  3931. // Round Preferred Values to nearest 5/100.
  3932. renderedWidth = (int)(renderedWidth * 100 + 1f) / 100f;
  3933. renderedHeight = (int)(renderedHeight * 100 + 1f) / 100f;
  3934. //Debug.Log("Preferred Values: (" + renderedWidth + ", " + renderedHeight + ") with Recursive count of " + m_recursiveCount);
  3935. return new Vector2(renderedWidth, renderedHeight);
  3936. }
  3937. /// <summary>
  3938. /// Method returning the compound bounds of the text object and child sub objects.
  3939. /// </summary>
  3940. /// <returns></returns>
  3941. protected virtual Bounds GetCompoundBounds() { return new Bounds(); }
  3942. internal virtual Rect GetCanvasSpaceClippingRect() { return Rect.zero; }
  3943. /// <summary>
  3944. /// Method which returns the bounds of the text object;
  3945. /// </summary>
  3946. /// <returns></returns>
  3947. protected Bounds GetTextBounds()
  3948. {
  3949. if (m_textInfo == null || m_textInfo.characterCount > m_textInfo.characterInfo.Length) return new Bounds();
  3950. Extents extent = new Extents(k_LargePositiveVector2, k_LargeNegativeVector2);
  3951. for (int i = 0; i < m_textInfo.characterCount && i < m_textInfo.characterInfo.Length; i++)
  3952. {
  3953. if (!m_textInfo.characterInfo[i].isVisible)
  3954. continue;
  3955. extent.min.x = Mathf.Min(extent.min.x, m_textInfo.characterInfo[i].origin);
  3956. extent.min.y = Mathf.Min(extent.min.y, m_textInfo.characterInfo[i].descender);
  3957. extent.max.x = Mathf.Max(extent.max.x, m_textInfo.characterInfo[i].xAdvance);
  3958. extent.max.y = Mathf.Max(extent.max.y, m_textInfo.characterInfo[i].ascender);
  3959. }
  3960. Vector2 size;
  3961. size.x = extent.max.x - extent.min.x;
  3962. size.y = extent.max.y - extent.min.y;
  3963. Vector3 center = (extent.min + extent.max) / 2;
  3964. return new Bounds(center, size);
  3965. }
  3966. /// <summary>
  3967. /// Method which returns the bounds of the text object;
  3968. /// </summary>
  3969. /// <param name="onlyVisibleCharacters"></param>
  3970. /// <returns></returns>
  3971. protected Bounds GetTextBounds(bool onlyVisibleCharacters)
  3972. {
  3973. if (m_textInfo == null) return new Bounds();
  3974. Extents extent = new Extents(k_LargePositiveVector2, k_LargeNegativeVector2);
  3975. for (int i = 0; i < m_textInfo.characterCount; i++)
  3976. {
  3977. if ((i > maxVisibleCharacters || m_textInfo.characterInfo[i].lineNumber > m_maxVisibleLines) && onlyVisibleCharacters)
  3978. break;
  3979. if (onlyVisibleCharacters && !m_textInfo.characterInfo[i].isVisible)
  3980. continue;
  3981. extent.min.x = Mathf.Min(extent.min.x, m_textInfo.characterInfo[i].origin);
  3982. extent.min.y = Mathf.Min(extent.min.y, m_textInfo.characterInfo[i].descender);
  3983. extent.max.x = Mathf.Max(extent.max.x, m_textInfo.characterInfo[i].xAdvance);
  3984. extent.max.y = Mathf.Max(extent.max.y, m_textInfo.characterInfo[i].ascender);
  3985. }
  3986. Vector2 size;
  3987. size.x = extent.max.x - extent.min.x;
  3988. size.y = extent.max.y - extent.min.y;
  3989. Vector2 center = (extent.min + extent.max) / 2;
  3990. return new Bounds(center, size);
  3991. }
  3992. /// <summary>
  3993. /// Method to adjust line spacing as a result of using different fonts or font point size.
  3994. /// </summary>
  3995. /// <param name="startIndex"></param>
  3996. /// <param name="endIndex"></param>
  3997. /// <param name="offset"></param>
  3998. // Function to offset vertices position to account for line spacing changes.
  3999. protected void AdjustLineOffset(int startIndex, int endIndex, float offset)
  4000. {
  4001. Vector3 vertexOffset = new Vector3(0, offset, 0);
  4002. for (int i = startIndex; i <= endIndex; i++)
  4003. {
  4004. m_textInfo.characterInfo[i].bottomLeft -= vertexOffset;
  4005. m_textInfo.characterInfo[i].topLeft -= vertexOffset;
  4006. m_textInfo.characterInfo[i].topRight -= vertexOffset;
  4007. m_textInfo.characterInfo[i].bottomRight -= vertexOffset;
  4008. m_textInfo.characterInfo[i].ascender -= vertexOffset.y;
  4009. m_textInfo.characterInfo[i].baseLine -= vertexOffset.y;
  4010. m_textInfo.characterInfo[i].descender -= vertexOffset.y;
  4011. if (m_textInfo.characterInfo[i].isVisible)
  4012. {
  4013. m_textInfo.characterInfo[i].vertex_BL.position -= vertexOffset;
  4014. m_textInfo.characterInfo[i].vertex_TL.position -= vertexOffset;
  4015. m_textInfo.characterInfo[i].vertex_TR.position -= vertexOffset;
  4016. m_textInfo.characterInfo[i].vertex_BR.position -= vertexOffset;
  4017. }
  4018. }
  4019. }
  4020. /// <summary>
  4021. /// Function to increase the size of the Line Extents Array.
  4022. /// </summary>
  4023. /// <param name="size"></param>
  4024. protected void ResizeLineExtents(int size)
  4025. {
  4026. size = size > 1024 ? size + 256 : Mathf.NextPowerOfTwo(size + 1);
  4027. TMP_LineInfo[] temp_lineInfo = new TMP_LineInfo[size];
  4028. for (int i = 0; i < size; i++)
  4029. {
  4030. if (i < m_textInfo.lineInfo.Length)
  4031. temp_lineInfo[i] = m_textInfo.lineInfo[i];
  4032. else
  4033. {
  4034. temp_lineInfo[i].lineExtents.min = k_LargePositiveVector2;
  4035. temp_lineInfo[i].lineExtents.max = k_LargeNegativeVector2;
  4036. temp_lineInfo[i].ascender = k_LargeNegativeFloat;
  4037. temp_lineInfo[i].descender = k_LargePositiveFloat;
  4038. }
  4039. }
  4040. m_textInfo.lineInfo = temp_lineInfo;
  4041. }
  4042. protected static Vector2 k_LargePositiveVector2 = new Vector2(TMP_Math.INT_MAX, TMP_Math.INT_MAX);
  4043. protected static Vector2 k_LargeNegativeVector2 = new Vector2(TMP_Math.INT_MIN, TMP_Math.INT_MIN);
  4044. protected static float k_LargePositiveFloat = TMP_Math.FLOAT_MAX;
  4045. protected static float k_LargeNegativeFloat = TMP_Math.FLOAT_MIN;
  4046. protected static int k_LargePositiveInt = TMP_Math.INT_MAX;
  4047. protected static int k_LargeNegativeInt = TMP_Math.INT_MIN;
  4048. /// <summary>
  4049. /// Function used to evaluate the length of a text string.
  4050. /// </summary>
  4051. /// <param name="text"></param>
  4052. /// <returns></returns>
  4053. public virtual TMP_TextInfo GetTextInfo(string text) { return null; }
  4054. /// <summary>
  4055. /// Function to force an update of the margin size.
  4056. /// </summary>
  4057. public virtual void ComputeMarginSize() { }
  4058. /// <summary>
  4059. /// Function used in conjunction with GetTextInfo to figure out Array allocations.
  4060. /// </summary>
  4061. /// <param name="chars"></param>
  4062. /// <returns></returns>
  4063. //protected int GetArraySizes(int[] chars)
  4064. //{
  4065. // //Debug.Log("Set Array Size called.");
  4066. // //int visibleCount = 0;
  4067. // //int totalCount = 0;
  4068. // int tagEnd = 0;
  4069. // m_totalCharacterCount = 0;
  4070. // m_isUsingBold = false;
  4071. // m_isParsingText = false;
  4072. // //m_VisibleCharacters.Clear();
  4073. // for (int i = 0; chars[i] != 0; i++)
  4074. // {
  4075. // int c = chars[i];
  4076. // if (m_isRichText && c == 60) // if Char '<'
  4077. // {
  4078. // // Check if Tag is Valid
  4079. // if (ValidateHtmlTag(chars, i + 1, out tagEnd))
  4080. // {
  4081. // i = tagEnd;
  4082. // //if ((m_style & FontStyles.Underline) == FontStyles.Underline) visibleCount += 3;
  4083. // if ((m_style & FontStyles.Bold) == FontStyles.Bold) m_isUsingBold = true;
  4084. // continue;
  4085. // }
  4086. // }
  4087. // //if (!char.IsWhiteSpace((char)c) && c != 0x200B)
  4088. // //{
  4089. // //visibleCount += 1;
  4090. // //}
  4091. // //m_VisibleCharacters.Add((char)c);
  4092. // m_totalCharacterCount += 1;
  4093. // }
  4094. // return m_totalCharacterCount;
  4095. //}
  4096. protected void InsertNewLine(int i, float baseScale, float currentElementScale, float currentEmScale, float glyphAdjustment, float boldSpacingAdjustment, float characterSpacingAdjustment, float width, float lineGap, ref bool isMaxVisibleDescenderSet, ref float maxVisibleDescender)
  4097. {
  4098. k_InsertNewLineMarker.Begin();
  4099. // Adjust line spacing if necessary
  4100. float baselineAdjustmentDelta = m_maxLineAscender - m_startOfLineAscender;
  4101. if (m_lineOffset > 0 && Math.Abs(baselineAdjustmentDelta) > 0.01f && m_IsDrivenLineSpacing == false && !m_isNewPage)
  4102. {
  4103. AdjustLineOffset(m_firstCharacterOfLine, m_characterCount, baselineAdjustmentDelta);
  4104. m_ElementDescender -= baselineAdjustmentDelta;
  4105. m_lineOffset += baselineAdjustmentDelta;
  4106. }
  4107. // Calculate lineAscender & make sure if last character is superscript or subscript that we check that as well.
  4108. float lineAscender = m_maxLineAscender - m_lineOffset;
  4109. float lineDescender = m_maxLineDescender - m_lineOffset;
  4110. // Update maxDescender and maxVisibleDescender
  4111. m_ElementDescender = m_ElementDescender < lineDescender ? m_ElementDescender : lineDescender;
  4112. if (!isMaxVisibleDescenderSet)
  4113. maxVisibleDescender = m_ElementDescender;
  4114. if (m_useMaxVisibleDescender && (m_characterCount >= m_maxVisibleCharacters || m_lineNumber >= m_maxVisibleLines))
  4115. isMaxVisibleDescenderSet = true;
  4116. // Track & Store lineInfo for the new line
  4117. m_textInfo.lineInfo[m_lineNumber].firstCharacterIndex = m_firstCharacterOfLine;
  4118. m_textInfo.lineInfo[m_lineNumber].firstVisibleCharacterIndex = m_firstVisibleCharacterOfLine = m_firstCharacterOfLine > m_firstVisibleCharacterOfLine ? m_firstCharacterOfLine : m_firstVisibleCharacterOfLine;
  4119. int lastCharacterIndex = m_textInfo.lineInfo[m_lineNumber].lastCharacterIndex = m_lastCharacterOfLine = m_characterCount - 1 > 0 ? m_characterCount - 1 : 0;
  4120. m_textInfo.lineInfo[m_lineNumber].lastVisibleCharacterIndex = m_lastVisibleCharacterOfLine = m_lastVisibleCharacterOfLine < m_firstVisibleCharacterOfLine ? m_firstVisibleCharacterOfLine : m_lastVisibleCharacterOfLine;
  4121. m_textInfo.lineInfo[m_lineNumber].characterCount = m_textInfo.lineInfo[m_lineNumber].lastCharacterIndex - m_textInfo.lineInfo[m_lineNumber].firstCharacterIndex + 1;
  4122. m_textInfo.lineInfo[m_lineNumber].visibleCharacterCount = m_lineVisibleCharacterCount;
  4123. m_textInfo.lineInfo[m_lineNumber].lineExtents.min = new Vector2(m_textInfo.characterInfo[m_firstVisibleCharacterOfLine].bottomLeft.x, lineDescender);
  4124. m_textInfo.lineInfo[m_lineNumber].lineExtents.max = new Vector2(m_textInfo.characterInfo[m_lastVisibleCharacterOfLine].topRight.x, lineAscender);
  4125. m_textInfo.lineInfo[m_lineNumber].length = m_textInfo.lineInfo[m_lineNumber].lineExtents.max.x;
  4126. m_textInfo.lineInfo[m_lineNumber].width = width;
  4127. float maxAdvanceOffset = (glyphAdjustment * currentElementScale + (m_currentFontAsset.normalSpacingOffset + characterSpacingAdjustment + boldSpacingAdjustment) * currentEmScale - m_cSpacing) * (1 - m_charWidthAdjDelta);
  4128. float adjustedHorizontalAdvance = m_textInfo.lineInfo[m_lineNumber].maxAdvance = m_textInfo.characterInfo[m_lastVisibleCharacterOfLine].xAdvance + (m_isRightToLeft ? maxAdvanceOffset : - maxAdvanceOffset);
  4129. m_textInfo.characterInfo[lastCharacterIndex].xAdvance = adjustedHorizontalAdvance;
  4130. m_textInfo.lineInfo[m_lineNumber].baseline = 0 - m_lineOffset;
  4131. m_textInfo.lineInfo[m_lineNumber].ascender = lineAscender;
  4132. m_textInfo.lineInfo[m_lineNumber].descender = lineDescender;
  4133. m_textInfo.lineInfo[m_lineNumber].lineHeight = lineAscender - lineDescender + lineGap * baseScale;
  4134. m_firstCharacterOfLine = m_characterCount; // Store first character of the next line.
  4135. m_lineVisibleCharacterCount = 0;
  4136. // Store the state of the line before starting on the new line.
  4137. SaveWordWrappingState(ref m_SavedLineState, i, m_characterCount - 1);
  4138. m_lineNumber += 1;
  4139. // Check to make sure Array is large enough to hold a new line.
  4140. if (m_lineNumber >= m_textInfo.lineInfo.Length)
  4141. ResizeLineExtents(m_lineNumber);
  4142. // Apply Line Spacing based on scale of the last character of the line.
  4143. if (m_lineHeight == TMP_Math.FLOAT_UNSET)
  4144. {
  4145. float ascender = m_textInfo.characterInfo[m_characterCount].adjustedAscender;
  4146. float lineOffsetDelta = 0 - m_maxLineDescender + ascender + (lineGap + m_lineSpacingDelta) * baseScale + m_lineSpacing * currentEmScale;
  4147. m_lineOffset += lineOffsetDelta;
  4148. m_startOfLineAscender = ascender;
  4149. }
  4150. else
  4151. {
  4152. m_lineOffset += m_lineHeight + m_lineSpacing * currentEmScale;
  4153. }
  4154. m_maxLineAscender = k_LargeNegativeFloat;
  4155. m_maxLineDescender = k_LargePositiveFloat;
  4156. m_xAdvance = 0 + tag_Indent;
  4157. k_InsertNewLineMarker.End();
  4158. }
  4159. /// <summary>
  4160. /// Save the State of various variables used in the mesh creation loop in conjunction with Word Wrapping
  4161. /// </summary>
  4162. /// <param name="state"></param>
  4163. /// <param name="index"></param>
  4164. /// <param name="count"></param>
  4165. protected void SaveWordWrappingState(ref WordWrapState state, int index, int count)
  4166. {
  4167. // Multi Font & Material support related
  4168. state.currentFontAsset = m_currentFontAsset;
  4169. state.currentSpriteAsset = m_currentSpriteAsset;
  4170. state.currentMaterial = m_currentMaterial;
  4171. state.currentMaterialIndex = m_currentMaterialIndex;
  4172. state.previous_WordBreak = index;
  4173. state.total_CharacterCount = count;
  4174. state.visible_CharacterCount = m_lineVisibleCharacterCount;
  4175. //state.visible_CharacterCount = m_visibleCharacterCount;
  4176. //state.visible_SpriteCount = m_visibleSpriteCount;
  4177. state.visible_LinkCount = m_textInfo.linkCount;
  4178. state.firstCharacterIndex = m_firstCharacterOfLine;
  4179. state.firstVisibleCharacterIndex = m_firstVisibleCharacterOfLine;
  4180. state.lastVisibleCharIndex = m_lastVisibleCharacterOfLine;
  4181. state.fontStyle = m_FontStyleInternal;
  4182. state.italicAngle = m_ItalicAngle;
  4183. //state.maxFontScale = m_maxFontScale;
  4184. state.fontScaleMultiplier = m_fontScaleMultiplier;
  4185. state.currentFontSize = m_currentFontSize;
  4186. state.xAdvance = m_xAdvance;
  4187. state.maxCapHeight = m_maxCapHeight;
  4188. state.maxAscender = m_maxTextAscender;
  4189. state.maxDescender = m_ElementDescender;
  4190. state.startOfLineAscender = m_startOfLineAscender;
  4191. state.maxLineAscender = m_maxLineAscender;
  4192. state.maxLineDescender = m_maxLineDescender;
  4193. state.pageAscender = m_PageAscender;
  4194. state.preferredWidth = m_preferredWidth;
  4195. state.preferredHeight = m_preferredHeight;
  4196. state.meshExtents = m_meshExtents;
  4197. state.lineNumber = m_lineNumber;
  4198. state.lineOffset = m_lineOffset;
  4199. state.baselineOffset = m_baselineOffset;
  4200. state.isDrivenLineSpacing = m_IsDrivenLineSpacing;
  4201. state.glyphHorizontalAdvanceAdjustment = m_GlyphHorizontalAdvanceAdjustment;
  4202. state.cSpace = m_cSpacing;
  4203. state.mSpace = m_monoSpacing;
  4204. state.horizontalAlignment = m_lineJustification;
  4205. state.marginLeft = m_marginLeft;
  4206. state.marginRight = m_marginRight;
  4207. state.vertexColor = m_htmlColor;
  4208. state.underlineColor = m_underlineColor;
  4209. state.strikethroughColor = m_strikethroughColor;
  4210. state.isNonBreakingSpace = m_isNonBreakingSpace;
  4211. state.tagNoParsing = tag_NoParsing;
  4212. // XML Tag Stack
  4213. state.basicStyleStack = m_fontStyleStack;
  4214. state.italicAngleStack = m_ItalicAngleStack;
  4215. state.colorStack = m_colorStack;
  4216. state.underlineColorStack = m_underlineColorStack;
  4217. state.strikethroughColorStack = m_strikethroughColorStack;
  4218. state.highlightStateStack = m_HighlightStateStack;
  4219. state.colorGradientStack = m_colorGradientStack;
  4220. state.sizeStack = m_sizeStack;
  4221. state.indentStack = m_indentStack;
  4222. state.fontWeightStack = m_FontWeightStack;
  4223. //state.styleStack = m_styleStack;
  4224. state.baselineStack = m_baselineOffsetStack;
  4225. state.actionStack = m_actionStack;
  4226. state.materialReferenceStack = m_materialReferenceStack;
  4227. state.lineJustificationStack = m_lineJustificationStack;
  4228. //state.spriteAnimationStack = m_spriteAnimationStack;
  4229. state.spriteAnimationID = m_spriteAnimationID;
  4230. if (m_lineNumber < m_textInfo.lineInfo.Length)
  4231. state.lineInfo = m_textInfo.lineInfo[m_lineNumber];
  4232. }
  4233. /// <summary>
  4234. /// Restore the State of various variables used in the mesh creation loop.
  4235. /// </summary>
  4236. /// <param name="state"></param>
  4237. /// <returns></returns>
  4238. protected int RestoreWordWrappingState(ref WordWrapState state)
  4239. {
  4240. int index = state.previous_WordBreak;
  4241. // Multi Font & Material support related
  4242. m_currentFontAsset = state.currentFontAsset;
  4243. m_currentSpriteAsset = state.currentSpriteAsset;
  4244. m_currentMaterial = state.currentMaterial;
  4245. m_currentMaterialIndex = state.currentMaterialIndex;
  4246. m_characterCount = state.total_CharacterCount + 1;
  4247. m_lineVisibleCharacterCount = state.visible_CharacterCount;
  4248. //m_visibleCharacterCount = state.visible_CharacterCount;
  4249. //m_visibleSpriteCount = state.visible_SpriteCount;
  4250. m_textInfo.linkCount = state.visible_LinkCount;
  4251. m_firstCharacterOfLine = state.firstCharacterIndex;
  4252. m_firstVisibleCharacterOfLine = state.firstVisibleCharacterIndex;
  4253. m_lastVisibleCharacterOfLine = state.lastVisibleCharIndex;
  4254. m_FontStyleInternal = state.fontStyle;
  4255. m_ItalicAngle = state.italicAngle;
  4256. m_fontScaleMultiplier = state.fontScaleMultiplier;
  4257. //m_maxFontScale = state.maxFontScale;
  4258. m_currentFontSize = state.currentFontSize;
  4259. m_xAdvance = state.xAdvance;
  4260. m_maxCapHeight = state.maxCapHeight;
  4261. m_maxTextAscender = state.maxAscender;
  4262. m_ElementDescender = state.maxDescender;
  4263. m_startOfLineAscender = state.startOfLineAscender;
  4264. m_maxLineAscender = state.maxLineAscender;
  4265. m_maxLineDescender = state.maxLineDescender;
  4266. m_PageAscender = state.pageAscender;
  4267. m_preferredWidth = state.preferredWidth;
  4268. m_preferredHeight = state.preferredHeight;
  4269. m_meshExtents = state.meshExtents;
  4270. m_lineNumber = state.lineNumber;
  4271. m_lineOffset = state.lineOffset;
  4272. m_baselineOffset = state.baselineOffset;
  4273. m_IsDrivenLineSpacing = state.isDrivenLineSpacing;
  4274. m_GlyphHorizontalAdvanceAdjustment = state.glyphHorizontalAdvanceAdjustment;
  4275. m_cSpacing = state.cSpace;
  4276. m_monoSpacing = state.mSpace;
  4277. m_lineJustification = state.horizontalAlignment;
  4278. m_marginLeft = state.marginLeft;
  4279. m_marginRight = state.marginRight;
  4280. m_htmlColor = state.vertexColor;
  4281. m_underlineColor = state.underlineColor;
  4282. m_strikethroughColor = state.strikethroughColor;
  4283. m_isNonBreakingSpace = state.isNonBreakingSpace;
  4284. tag_NoParsing = state.tagNoParsing;
  4285. // XML Tag Stack
  4286. m_fontStyleStack = state.basicStyleStack;
  4287. m_ItalicAngleStack = state.italicAngleStack;
  4288. m_colorStack = state.colorStack;
  4289. m_underlineColorStack = state.underlineColorStack;
  4290. m_strikethroughColorStack = state.strikethroughColorStack;
  4291. m_HighlightStateStack = state.highlightStateStack;
  4292. m_colorGradientStack = state.colorGradientStack;
  4293. m_sizeStack = state.sizeStack;
  4294. m_indentStack = state.indentStack;
  4295. m_FontWeightStack = state.fontWeightStack;
  4296. //m_styleStack = state.styleStack;
  4297. m_baselineOffsetStack = state.baselineStack;
  4298. m_actionStack = state.actionStack;
  4299. m_materialReferenceStack = state.materialReferenceStack;
  4300. m_lineJustificationStack = state.lineJustificationStack;
  4301. //m_spriteAnimationStack = state.spriteAnimationStack;
  4302. m_spriteAnimationID = state.spriteAnimationID;
  4303. if (m_lineNumber < m_textInfo.lineInfo.Length)
  4304. m_textInfo.lineInfo[m_lineNumber] = state.lineInfo;
  4305. return index;
  4306. }
  4307. /// <summary>
  4308. /// Store vertex information for each character.
  4309. /// </summary>
  4310. /// <param name="style_padding">Style_padding.</param>
  4311. /// <param name="vertexColor">Vertex color.</param>
  4312. protected virtual void SaveGlyphVertexInfo(float padding, float style_padding, Color32 vertexColor)
  4313. {
  4314. // Save the Vertex Position for the Character
  4315. #region Setup Mesh Vertices
  4316. m_textInfo.characterInfo[m_characterCount].vertex_BL.position = m_textInfo.characterInfo[m_characterCount].bottomLeft;
  4317. m_textInfo.characterInfo[m_characterCount].vertex_TL.position = m_textInfo.characterInfo[m_characterCount].topLeft;
  4318. m_textInfo.characterInfo[m_characterCount].vertex_TR.position = m_textInfo.characterInfo[m_characterCount].topRight;
  4319. m_textInfo.characterInfo[m_characterCount].vertex_BR.position = m_textInfo.characterInfo[m_characterCount].bottomRight;
  4320. #endregion
  4321. #region Setup Vertex Colors
  4322. // Alpha is the lower of the vertex color or tag color alpha used.
  4323. vertexColor.a = m_fontColor32.a < vertexColor.a ? m_fontColor32.a : vertexColor.a;
  4324. // Handle Vertex Colors & Vertex Color Gradient
  4325. if (!m_enableVertexGradient)
  4326. {
  4327. m_textInfo.characterInfo[m_characterCount].vertex_BL.color = vertexColor;
  4328. m_textInfo.characterInfo[m_characterCount].vertex_TL.color = vertexColor;
  4329. m_textInfo.characterInfo[m_characterCount].vertex_TR.color = vertexColor;
  4330. m_textInfo.characterInfo[m_characterCount].vertex_BR.color = vertexColor;
  4331. }
  4332. else
  4333. {
  4334. if (!m_overrideHtmlColors && m_colorStack.index > 1)
  4335. {
  4336. m_textInfo.characterInfo[m_characterCount].vertex_BL.color = vertexColor;
  4337. m_textInfo.characterInfo[m_characterCount].vertex_TL.color = vertexColor;
  4338. m_textInfo.characterInfo[m_characterCount].vertex_TR.color = vertexColor;
  4339. m_textInfo.characterInfo[m_characterCount].vertex_BR.color = vertexColor;
  4340. }
  4341. else // Handle Vertex Color Gradient
  4342. {
  4343. // Use Vertex Color Gradient Preset (if one is assigned)
  4344. if (m_fontColorGradientPreset != null)
  4345. {
  4346. m_textInfo.characterInfo[m_characterCount].vertex_BL.color = m_fontColorGradientPreset.bottomLeft * vertexColor;
  4347. m_textInfo.characterInfo[m_characterCount].vertex_TL.color = m_fontColorGradientPreset.topLeft * vertexColor;
  4348. m_textInfo.characterInfo[m_characterCount].vertex_TR.color = m_fontColorGradientPreset.topRight * vertexColor;
  4349. m_textInfo.characterInfo[m_characterCount].vertex_BR.color = m_fontColorGradientPreset.bottomRight * vertexColor;
  4350. }
  4351. else
  4352. {
  4353. m_textInfo.characterInfo[m_characterCount].vertex_BL.color = m_fontColorGradient.bottomLeft * vertexColor;
  4354. m_textInfo.characterInfo[m_characterCount].vertex_TL.color = m_fontColorGradient.topLeft * vertexColor;
  4355. m_textInfo.characterInfo[m_characterCount].vertex_TR.color = m_fontColorGradient.topRight * vertexColor;
  4356. m_textInfo.characterInfo[m_characterCount].vertex_BR.color = m_fontColorGradient.bottomRight * vertexColor;
  4357. }
  4358. }
  4359. }
  4360. if (m_colorGradientPreset != null)
  4361. {
  4362. if (m_colorGradientPresetIsTinted)
  4363. {
  4364. m_textInfo.characterInfo[m_characterCount].vertex_BL.color *= m_colorGradientPreset.bottomLeft;
  4365. m_textInfo.characterInfo[m_characterCount].vertex_TL.color *= m_colorGradientPreset.topLeft;
  4366. m_textInfo.characterInfo[m_characterCount].vertex_TR.color *= m_colorGradientPreset.topRight;
  4367. m_textInfo.characterInfo[m_characterCount].vertex_BR.color *= m_colorGradientPreset.bottomRight;
  4368. }
  4369. else
  4370. {
  4371. m_textInfo.characterInfo[m_characterCount].vertex_BL.color = m_colorGradientPreset.bottomLeft.MinAlpha(vertexColor);
  4372. m_textInfo.characterInfo[m_characterCount].vertex_TL.color = m_colorGradientPreset.topLeft.MinAlpha(vertexColor);
  4373. m_textInfo.characterInfo[m_characterCount].vertex_TR.color = m_colorGradientPreset.topRight.MinAlpha(vertexColor);
  4374. m_textInfo.characterInfo[m_characterCount].vertex_BR.color = m_colorGradientPreset.bottomRight.MinAlpha(vertexColor);
  4375. }
  4376. }
  4377. #endregion
  4378. // Apply style_padding only if this is a SDF Shader.
  4379. if (!m_isSDFShader)
  4380. style_padding = 0f;
  4381. // Setup UVs for the Character
  4382. #region Setup UVs
  4383. GlyphRect glyphRect = m_cached_TextElement.m_Glyph.glyphRect;
  4384. Vector2 uv0;
  4385. uv0.x = (glyphRect.x - padding - style_padding) / m_currentFontAsset.m_AtlasWidth;
  4386. uv0.y = (glyphRect.y - padding - style_padding) / m_currentFontAsset.m_AtlasHeight;
  4387. Vector2 uv1;
  4388. uv1.x = uv0.x;
  4389. uv1.y = (glyphRect.y + padding + style_padding + glyphRect.height) / m_currentFontAsset.m_AtlasHeight;
  4390. Vector2 uv2;
  4391. uv2.x = (glyphRect.x + padding + style_padding + glyphRect.width) / m_currentFontAsset.m_AtlasWidth;
  4392. uv2.y = uv1.y;
  4393. Vector2 uv3;
  4394. uv3.x = uv2.x;
  4395. uv3.y = uv0.y;
  4396. // Store UV Information
  4397. m_textInfo.characterInfo[m_characterCount].vertex_BL.uv = uv0;
  4398. m_textInfo.characterInfo[m_characterCount].vertex_TL.uv = uv1;
  4399. m_textInfo.characterInfo[m_characterCount].vertex_TR.uv = uv2;
  4400. m_textInfo.characterInfo[m_characterCount].vertex_BR.uv = uv3;
  4401. #endregion Setup UVs
  4402. // Normal
  4403. #region Setup Normals & Tangents
  4404. //Vector3 normal = new Vector3(0, 0, -1);
  4405. //m_textInfo.characterInfo[m_characterCount].vertex_BL.normal = normal;
  4406. //m_textInfo.characterInfo[m_characterCount].vertex_TL.normal = normal;
  4407. //m_textInfo.characterInfo[m_characterCount].vertex_TR.normal = normal;
  4408. //m_textInfo.characterInfo[m_characterCount].vertex_BR.normal = normal;
  4409. // Tangents
  4410. //Vector4 tangent = new Vector4(-1, 0, 0, 1);
  4411. //m_textInfo.characterInfo[m_characterCount].vertex_BL.tangent = tangent;
  4412. //m_textInfo.characterInfo[m_characterCount].vertex_TL.tangent = tangent;
  4413. //m_textInfo.characterInfo[m_characterCount].vertex_TR.tangent = tangent;
  4414. //m_textInfo.characterInfo[m_characterCount].vertex_BR.tangent = tangent;
  4415. #endregion end Normals & Tangents
  4416. }
  4417. /// <summary>
  4418. /// Store vertex information for each sprite.
  4419. /// </summary>
  4420. /// <param name="padding"></param>
  4421. /// <param name="style_padding"></param>
  4422. /// <param name="vertexColor"></param>
  4423. protected virtual void SaveSpriteVertexInfo(Color32 vertexColor)
  4424. {
  4425. // Save the Vertex Position for the Character
  4426. #region Setup Mesh Vertices
  4427. m_textInfo.characterInfo[m_characterCount].vertex_BL.position = m_textInfo.characterInfo[m_characterCount].bottomLeft;
  4428. m_textInfo.characterInfo[m_characterCount].vertex_TL.position = m_textInfo.characterInfo[m_characterCount].topLeft;
  4429. m_textInfo.characterInfo[m_characterCount].vertex_TR.position = m_textInfo.characterInfo[m_characterCount].topRight;
  4430. m_textInfo.characterInfo[m_characterCount].vertex_BR.position = m_textInfo.characterInfo[m_characterCount].bottomRight;
  4431. #endregion
  4432. // Vertex Color Alpha
  4433. if (m_tintAllSprites) m_tintSprite = true;
  4434. Color32 spriteColor = m_tintSprite ? m_spriteColor.Multiply(vertexColor) : m_spriteColor;
  4435. spriteColor.a = spriteColor.a < m_fontColor32.a ? spriteColor.a = spriteColor.a < vertexColor.a ? spriteColor.a : vertexColor.a : m_fontColor32.a;
  4436. Color32 c0 = spriteColor;
  4437. Color32 c1 = spriteColor;
  4438. Color32 c2 = spriteColor;
  4439. Color32 c3 = spriteColor;
  4440. if (m_enableVertexGradient)
  4441. {
  4442. if (m_fontColorGradientPreset != null)
  4443. {
  4444. c0 = m_tintSprite ? c0.Multiply(m_fontColorGradientPreset.bottomLeft) : c0;
  4445. c1 = m_tintSprite ? c1.Multiply(m_fontColorGradientPreset.topLeft) : c1;
  4446. c2 = m_tintSprite ? c2.Multiply(m_fontColorGradientPreset.topRight) : c2;
  4447. c3 = m_tintSprite ? c3.Multiply(m_fontColorGradientPreset.bottomRight) : c3;
  4448. }
  4449. else
  4450. {
  4451. c0 = m_tintSprite ? c0.Multiply(m_fontColorGradient.bottomLeft) : c0;
  4452. c1 = m_tintSprite ? c1.Multiply(m_fontColorGradient.topLeft) : c1;
  4453. c2 = m_tintSprite ? c2.Multiply(m_fontColorGradient.topRight) : c2;
  4454. c3 = m_tintSprite ? c3.Multiply(m_fontColorGradient.bottomRight) : c3;
  4455. }
  4456. }
  4457. if (m_colorGradientPreset != null)
  4458. {
  4459. c0 = m_tintSprite ? c0.Multiply(m_colorGradientPreset.bottomLeft) : c0;
  4460. c1 = m_tintSprite ? c1.Multiply(m_colorGradientPreset.topLeft) : c1;
  4461. c2 = m_tintSprite ? c2.Multiply(m_colorGradientPreset.topRight) : c2;
  4462. c3 = m_tintSprite ? c3.Multiply(m_colorGradientPreset.bottomRight) : c3;
  4463. }
  4464. m_textInfo.characterInfo[m_characterCount].vertex_BL.color = c0;
  4465. m_textInfo.characterInfo[m_characterCount].vertex_TL.color = c1;
  4466. m_textInfo.characterInfo[m_characterCount].vertex_TR.color = c2;
  4467. m_textInfo.characterInfo[m_characterCount].vertex_BR.color = c3;
  4468. // Setup UVs for the Character
  4469. #region Setup UVs
  4470. GlyphRect glyphRect = m_cached_TextElement.m_Glyph.glyphRect;
  4471. Vector2 uv0 = new Vector2((float)glyphRect.x / m_currentSpriteAsset.spriteSheet.width, (float)glyphRect.y / m_currentSpriteAsset.spriteSheet.height); // bottom left
  4472. Vector2 uv1 = new Vector2(uv0.x, (float)(glyphRect.y + glyphRect.height) / m_currentSpriteAsset.spriteSheet.height); // top left
  4473. Vector2 uv2 = new Vector2((float)(glyphRect.x + glyphRect.width) / m_currentSpriteAsset.spriteSheet.width, uv1.y); // top right
  4474. Vector2 uv3 = new Vector2(uv2.x, uv0.y); // bottom right
  4475. // Store UV Information
  4476. m_textInfo.characterInfo[m_characterCount].vertex_BL.uv = uv0;
  4477. m_textInfo.characterInfo[m_characterCount].vertex_TL.uv = uv1;
  4478. m_textInfo.characterInfo[m_characterCount].vertex_TR.uv = uv2;
  4479. m_textInfo.characterInfo[m_characterCount].vertex_BR.uv = uv3;
  4480. #endregion Setup UVs
  4481. // Normal
  4482. #region Setup Normals & Tangents
  4483. //Vector3 normal = new Vector3(0, 0, -1);
  4484. //m_textInfo.characterInfo[m_characterCount].vertex_BL.normal = normal;
  4485. //m_textInfo.characterInfo[m_characterCount].vertex_TL.normal = normal;
  4486. //m_textInfo.characterInfo[m_characterCount].vertex_TR.normal = normal;
  4487. //m_textInfo.characterInfo[m_characterCount].vertex_BR.normal = normal;
  4488. // Tangents
  4489. //Vector4 tangent = new Vector4(-1, 0, 0, 1);
  4490. //m_textInfo.characterInfo[m_characterCount].vertex_BL.tangent = tangent;
  4491. //m_textInfo.characterInfo[m_characterCount].vertex_TL.tangent = tangent;
  4492. //m_textInfo.characterInfo[m_characterCount].vertex_TR.tangent = tangent;
  4493. //m_textInfo.characterInfo[m_characterCount].vertex_BR.tangent = tangent;
  4494. #endregion end Normals & Tangents
  4495. }
  4496. /// <summary>
  4497. /// Store vertex attributes into the appropriate TMP_MeshInfo.
  4498. /// </summary>
  4499. /// <param name="i"></param>
  4500. /// <param name="index_X4"></param>
  4501. protected virtual void FillCharacterVertexBuffers(int i, int index_X4)
  4502. {
  4503. int materialIndex = m_textInfo.characterInfo[i].materialReferenceIndex;
  4504. index_X4 = m_textInfo.meshInfo[materialIndex].vertexCount;
  4505. // Check to make sure our current mesh buffer allocations can hold these new Quads.
  4506. if (index_X4 >= m_textInfo.meshInfo[materialIndex].vertices.Length)
  4507. m_textInfo.meshInfo[materialIndex].ResizeMeshInfo(Mathf.NextPowerOfTwo((index_X4 + 4) / 4));
  4508. TMP_CharacterInfo[] characterInfoArray = m_textInfo.characterInfo;
  4509. m_textInfo.characterInfo[i].vertexIndex = index_X4;
  4510. // Setup Vertices for Characters
  4511. m_textInfo.meshInfo[materialIndex].vertices[0 + index_X4] = characterInfoArray[i].vertex_BL.position;
  4512. m_textInfo.meshInfo[materialIndex].vertices[1 + index_X4] = characterInfoArray[i].vertex_TL.position;
  4513. m_textInfo.meshInfo[materialIndex].vertices[2 + index_X4] = characterInfoArray[i].vertex_TR.position;
  4514. m_textInfo.meshInfo[materialIndex].vertices[3 + index_X4] = characterInfoArray[i].vertex_BR.position;
  4515. // Setup UVS0
  4516. m_textInfo.meshInfo[materialIndex].uvs0[0 + index_X4] = characterInfoArray[i].vertex_BL.uv;
  4517. m_textInfo.meshInfo[materialIndex].uvs0[1 + index_X4] = characterInfoArray[i].vertex_TL.uv;
  4518. m_textInfo.meshInfo[materialIndex].uvs0[2 + index_X4] = characterInfoArray[i].vertex_TR.uv;
  4519. m_textInfo.meshInfo[materialIndex].uvs0[3 + index_X4] = characterInfoArray[i].vertex_BR.uv;
  4520. // Setup UVS2
  4521. m_textInfo.meshInfo[materialIndex].uvs2[0 + index_X4] = characterInfoArray[i].vertex_BL.uv2;
  4522. m_textInfo.meshInfo[materialIndex].uvs2[1 + index_X4] = characterInfoArray[i].vertex_TL.uv2;
  4523. m_textInfo.meshInfo[materialIndex].uvs2[2 + index_X4] = characterInfoArray[i].vertex_TR.uv2;
  4524. m_textInfo.meshInfo[materialIndex].uvs2[3 + index_X4] = characterInfoArray[i].vertex_BR.uv2;
  4525. // Setup UVS4
  4526. //m_textInfo.meshInfo[0].uvs4[0 + index_X4] = characterInfoArray[i].vertex_BL.uv4;
  4527. //m_textInfo.meshInfo[0].uvs4[1 + index_X4] = characterInfoArray[i].vertex_TL.uv4;
  4528. //m_textInfo.meshInfo[0].uvs4[2 + index_X4] = characterInfoArray[i].vertex_TR.uv4;
  4529. //m_textInfo.meshInfo[0].uvs4[3 + index_X4] = characterInfoArray[i].vertex_BR.uv4;
  4530. // setup Vertex Colors
  4531. m_textInfo.meshInfo[materialIndex].colors32[0 + index_X4] = characterInfoArray[i].vertex_BL.color;
  4532. m_textInfo.meshInfo[materialIndex].colors32[1 + index_X4] = characterInfoArray[i].vertex_TL.color;
  4533. m_textInfo.meshInfo[materialIndex].colors32[2 + index_X4] = characterInfoArray[i].vertex_TR.color;
  4534. m_textInfo.meshInfo[materialIndex].colors32[3 + index_X4] = characterInfoArray[i].vertex_BR.color;
  4535. m_textInfo.meshInfo[materialIndex].vertexCount = index_X4 + 4;
  4536. }
  4537. protected virtual void FillCharacterVertexBuffers(int i, int index_X4, bool isVolumetric)
  4538. {
  4539. int materialIndex = m_textInfo.characterInfo[i].materialReferenceIndex;
  4540. index_X4 = m_textInfo.meshInfo[materialIndex].vertexCount;
  4541. // Check to make sure our current mesh buffer allocations can hold these new Quads.
  4542. if (index_X4 >= m_textInfo.meshInfo[materialIndex].vertices.Length)
  4543. m_textInfo.meshInfo[materialIndex].ResizeMeshInfo(Mathf.NextPowerOfTwo((index_X4 + (isVolumetric ? 8 : 4)) / 4));
  4544. TMP_CharacterInfo[] characterInfoArray = m_textInfo.characterInfo;
  4545. m_textInfo.characterInfo[i].vertexIndex = index_X4;
  4546. // Setup Vertices for Characters
  4547. m_textInfo.meshInfo[materialIndex].vertices[0 + index_X4] = characterInfoArray[i].vertex_BL.position;
  4548. m_textInfo.meshInfo[materialIndex].vertices[1 + index_X4] = characterInfoArray[i].vertex_TL.position;
  4549. m_textInfo.meshInfo[materialIndex].vertices[2 + index_X4] = characterInfoArray[i].vertex_TR.position;
  4550. m_textInfo.meshInfo[materialIndex].vertices[3 + index_X4] = characterInfoArray[i].vertex_BR.position;
  4551. // if (isVolumetric)
  4552. // {
  4553. // Vector3 depth = new Vector3(0, 0, m_fontSize * m_fontScale);
  4554. // m_textInfo.meshInfo[materialIndex].vertices[4 + index_X4] = characterInfoArray[i].vertex_BL.position + depth;
  4555. // m_textInfo.meshInfo[materialIndex].vertices[5 + index_X4] = characterInfoArray[i].vertex_TL.position + depth;
  4556. // m_textInfo.meshInfo[materialIndex].vertices[6 + index_X4] = characterInfoArray[i].vertex_TR.position + depth;
  4557. // m_textInfo.meshInfo[materialIndex].vertices[7 + index_X4] = characterInfoArray[i].vertex_BR.position + depth;
  4558. // }
  4559. // Setup UVS0
  4560. m_textInfo.meshInfo[materialIndex].uvs0[0 + index_X4] = characterInfoArray[i].vertex_BL.uv;
  4561. m_textInfo.meshInfo[materialIndex].uvs0[1 + index_X4] = characterInfoArray[i].vertex_TL.uv;
  4562. m_textInfo.meshInfo[materialIndex].uvs0[2 + index_X4] = characterInfoArray[i].vertex_TR.uv;
  4563. m_textInfo.meshInfo[materialIndex].uvs0[3 + index_X4] = characterInfoArray[i].vertex_BR.uv;
  4564. if (isVolumetric)
  4565. {
  4566. m_textInfo.meshInfo[materialIndex].uvs0[4 + index_X4] = characterInfoArray[i].vertex_BL.uv;
  4567. m_textInfo.meshInfo[materialIndex].uvs0[5 + index_X4] = characterInfoArray[i].vertex_TL.uv;
  4568. m_textInfo.meshInfo[materialIndex].uvs0[6 + index_X4] = characterInfoArray[i].vertex_TR.uv;
  4569. m_textInfo.meshInfo[materialIndex].uvs0[7 + index_X4] = characterInfoArray[i].vertex_BR.uv;
  4570. }
  4571. // Setup UVS2
  4572. m_textInfo.meshInfo[materialIndex].uvs2[0 + index_X4] = characterInfoArray[i].vertex_BL.uv2;
  4573. m_textInfo.meshInfo[materialIndex].uvs2[1 + index_X4] = characterInfoArray[i].vertex_TL.uv2;
  4574. m_textInfo.meshInfo[materialIndex].uvs2[2 + index_X4] = characterInfoArray[i].vertex_TR.uv2;
  4575. m_textInfo.meshInfo[materialIndex].uvs2[3 + index_X4] = characterInfoArray[i].vertex_BR.uv2;
  4576. if (isVolumetric)
  4577. {
  4578. m_textInfo.meshInfo[materialIndex].uvs2[4 + index_X4] = characterInfoArray[i].vertex_BL.uv2;
  4579. m_textInfo.meshInfo[materialIndex].uvs2[5 + index_X4] = characterInfoArray[i].vertex_TL.uv2;
  4580. m_textInfo.meshInfo[materialIndex].uvs2[6 + index_X4] = characterInfoArray[i].vertex_TR.uv2;
  4581. m_textInfo.meshInfo[materialIndex].uvs2[7 + index_X4] = characterInfoArray[i].vertex_BR.uv2;
  4582. }
  4583. // Setup UVS4
  4584. //m_textInfo.meshInfo[0].uvs4[0 + index_X4] = characterInfoArray[i].vertex_BL.uv4;
  4585. //m_textInfo.meshInfo[0].uvs4[1 + index_X4] = characterInfoArray[i].vertex_TL.uv4;
  4586. //m_textInfo.meshInfo[0].uvs4[2 + index_X4] = characterInfoArray[i].vertex_TR.uv4;
  4587. //m_textInfo.meshInfo[0].uvs4[3 + index_X4] = characterInfoArray[i].vertex_BR.uv4;
  4588. // setup Vertex Colors
  4589. m_textInfo.meshInfo[materialIndex].colors32[0 + index_X4] = characterInfoArray[i].vertex_BL.color;
  4590. m_textInfo.meshInfo[materialIndex].colors32[1 + index_X4] = characterInfoArray[i].vertex_TL.color;
  4591. m_textInfo.meshInfo[materialIndex].colors32[2 + index_X4] = characterInfoArray[i].vertex_TR.color;
  4592. m_textInfo.meshInfo[materialIndex].colors32[3 + index_X4] = characterInfoArray[i].vertex_BR.color;
  4593. if (isVolumetric)
  4594. {
  4595. Color32 backColor = new Color32(255, 255, 128, 255);
  4596. m_textInfo.meshInfo[materialIndex].colors32[4 + index_X4] = backColor; //characterInfoArray[i].vertex_BL.color;
  4597. m_textInfo.meshInfo[materialIndex].colors32[5 + index_X4] = backColor; //characterInfoArray[i].vertex_TL.color;
  4598. m_textInfo.meshInfo[materialIndex].colors32[6 + index_X4] = backColor; //characterInfoArray[i].vertex_TR.color;
  4599. m_textInfo.meshInfo[materialIndex].colors32[7 + index_X4] = backColor; //characterInfoArray[i].vertex_BR.color;
  4600. }
  4601. m_textInfo.meshInfo[materialIndex].vertexCount = index_X4 + (!isVolumetric ? 4 : 8);
  4602. }
  4603. /// <summary>
  4604. /// Fill Vertex Buffers for Sprites
  4605. /// </summary>
  4606. /// <param name="i"></param>
  4607. /// <param name="spriteIndex_X4"></param>
  4608. protected virtual void FillSpriteVertexBuffers(int i, int index_X4)
  4609. {
  4610. int materialIndex = m_textInfo.characterInfo[i].materialReferenceIndex;
  4611. index_X4 = m_textInfo.meshInfo[materialIndex].vertexCount;
  4612. // Check to make sure our current mesh buffer allocations can hold these new Quads.
  4613. if (index_X4 >= m_textInfo.meshInfo[materialIndex].vertices.Length)
  4614. m_textInfo.meshInfo[materialIndex].ResizeMeshInfo(Mathf.NextPowerOfTwo((index_X4 + 4) / 4));
  4615. TMP_CharacterInfo[] characterInfoArray = m_textInfo.characterInfo;
  4616. m_textInfo.characterInfo[i].vertexIndex = index_X4;
  4617. // Setup Vertices for Characters
  4618. m_textInfo.meshInfo[materialIndex].vertices[0 + index_X4] = characterInfoArray[i].vertex_BL.position;
  4619. m_textInfo.meshInfo[materialIndex].vertices[1 + index_X4] = characterInfoArray[i].vertex_TL.position;
  4620. m_textInfo.meshInfo[materialIndex].vertices[2 + index_X4] = characterInfoArray[i].vertex_TR.position;
  4621. m_textInfo.meshInfo[materialIndex].vertices[3 + index_X4] = characterInfoArray[i].vertex_BR.position;
  4622. // Setup UVS0
  4623. m_textInfo.meshInfo[materialIndex].uvs0[0 + index_X4] = characterInfoArray[i].vertex_BL.uv;
  4624. m_textInfo.meshInfo[materialIndex].uvs0[1 + index_X4] = characterInfoArray[i].vertex_TL.uv;
  4625. m_textInfo.meshInfo[materialIndex].uvs0[2 + index_X4] = characterInfoArray[i].vertex_TR.uv;
  4626. m_textInfo.meshInfo[materialIndex].uvs0[3 + index_X4] = characterInfoArray[i].vertex_BR.uv;
  4627. // Setup UVS2
  4628. m_textInfo.meshInfo[materialIndex].uvs2[0 + index_X4] = characterInfoArray[i].vertex_BL.uv2;
  4629. m_textInfo.meshInfo[materialIndex].uvs2[1 + index_X4] = characterInfoArray[i].vertex_TL.uv2;
  4630. m_textInfo.meshInfo[materialIndex].uvs2[2 + index_X4] = characterInfoArray[i].vertex_TR.uv2;
  4631. m_textInfo.meshInfo[materialIndex].uvs2[3 + index_X4] = characterInfoArray[i].vertex_BR.uv2;
  4632. // Setup UVS4
  4633. //m_textInfo.meshInfo[0].uvs4[0 + index_X4] = characterInfoArray[i].vertex_BL.uv4;
  4634. //m_textInfo.meshInfo[0].uvs4[1 + index_X4] = characterInfoArray[i].vertex_TL.uv4;
  4635. //m_textInfo.meshInfo[0].uvs4[2 + index_X4] = characterInfoArray[i].vertex_TR.uv4;
  4636. //m_textInfo.meshInfo[0].uvs4[3 + index_X4] = characterInfoArray[i].vertex_BR.uv4;
  4637. // setup Vertex Colors
  4638. m_textInfo.meshInfo[materialIndex].colors32[0 + index_X4] = characterInfoArray[i].vertex_BL.color;
  4639. m_textInfo.meshInfo[materialIndex].colors32[1 + index_X4] = characterInfoArray[i].vertex_TL.color;
  4640. m_textInfo.meshInfo[materialIndex].colors32[2 + index_X4] = characterInfoArray[i].vertex_TR.color;
  4641. m_textInfo.meshInfo[materialIndex].colors32[3 + index_X4] = characterInfoArray[i].vertex_BR.color;
  4642. m_textInfo.meshInfo[materialIndex].vertexCount = index_X4 + 4;
  4643. }
  4644. /// <summary>
  4645. /// Method to add the underline geometry.
  4646. /// </summary>
  4647. /// <param name="start"></param>
  4648. /// <param name="end"></param>
  4649. /// <param name="startScale"></param>
  4650. /// <param name="endScale"></param>
  4651. /// <param name="maxScale"></param>
  4652. /// <param name="underlineColor"></param>
  4653. protected virtual void DrawUnderlineMesh(Vector3 start, Vector3 end, ref int index, float startScale, float endScale, float maxScale, float sdfScale, Color32 underlineColor)
  4654. {
  4655. // Get Underline special character from the primary font asset.
  4656. GetUnderlineSpecialCharacter(m_fontAsset);
  4657. if (m_Underline.character == null)
  4658. {
  4659. if (!TMP_Settings.warningsDisabled)
  4660. Debug.LogWarning("Unable to add underline since the primary Font Asset doesn't contain the underline character.", this);
  4661. return;
  4662. }
  4663. int underlineMaterialIndex = m_Underline.materialIndex;
  4664. int verticesCount = index + 12;
  4665. // Check to make sure our current mesh buffer allocations can hold these new Quads.
  4666. if (verticesCount > m_textInfo.meshInfo[underlineMaterialIndex].vertices.Length)
  4667. {
  4668. // Resize Mesh Buffers
  4669. m_textInfo.meshInfo[underlineMaterialIndex].ResizeMeshInfo(verticesCount / 4);
  4670. }
  4671. // Adjust the position of the underline based on the lowest character. This matters for subscript character.
  4672. start.y = Mathf.Min(start.y, end.y);
  4673. end.y = Mathf.Min(start.y, end.y);
  4674. GlyphMetrics underlineGlyphMetrics = m_Underline.character.glyph.metrics;
  4675. GlyphRect underlineGlyphRect = m_Underline.character.glyph.glyphRect;
  4676. float segmentWidth = underlineGlyphMetrics.width / 2 * maxScale;
  4677. if (end.x - start.x < underlineGlyphMetrics.width * maxScale)
  4678. {
  4679. segmentWidth = (end.x - start.x) / 2f;
  4680. }
  4681. float startPadding = m_padding * startScale / maxScale;
  4682. float endPadding = m_padding * endScale / maxScale;
  4683. float underlineThickness = m_Underline.fontAsset.faceInfo.underlineThickness;
  4684. // UNDERLINE VERTICES FOR (3) LINE SEGMENTS
  4685. #region UNDERLINE VERTICES
  4686. Vector3[] vertices = m_textInfo.meshInfo[underlineMaterialIndex].vertices;
  4687. // Front Part of the Underline
  4688. vertices[index + 0] = start + new Vector3(0, 0 - (underlineThickness + m_padding) * maxScale, 0); // BL
  4689. vertices[index + 1] = start + new Vector3(0, m_padding * maxScale, 0); // TL
  4690. vertices[index + 2] = vertices[index + 1] + new Vector3(segmentWidth, 0, 0); // TR
  4691. vertices[index + 3] = vertices[index + 0] + new Vector3(segmentWidth, 0, 0); // BR
  4692. // Middle Part of the Underline
  4693. vertices[index + 4] = vertices[index + 3]; // BL
  4694. vertices[index + 5] = vertices[index + 2]; // TL
  4695. vertices[index + 6] = end + new Vector3(-segmentWidth, m_padding * maxScale, 0); // TR
  4696. vertices[index + 7] = end + new Vector3(-segmentWidth, -(underlineThickness + m_padding) * maxScale, 0); // BR
  4697. // End Part of the Underline
  4698. vertices[index + 8] = vertices[index + 7]; // BL
  4699. vertices[index + 9] = vertices[index + 6]; // TL
  4700. vertices[index + 10] = end + new Vector3(0, m_padding * maxScale, 0); // TR
  4701. vertices[index + 11] = end + new Vector3(0, -(underlineThickness + m_padding) * maxScale, 0); // BR
  4702. #endregion
  4703. // UNDERLINE UV0
  4704. #region HANDLE UV0
  4705. Vector2[] uvs0 = m_textInfo.meshInfo[underlineMaterialIndex].uvs0;
  4706. int atlasWidth = m_Underline.fontAsset.atlasWidth;
  4707. int atlasHeight = m_Underline.fontAsset.atlasHeight;
  4708. // Calculate UV required to setup the 3 Quads for the Underline.
  4709. Vector2 uv0 = new Vector2((underlineGlyphRect.x - startPadding) / atlasWidth, (underlineGlyphRect.y - m_padding) / atlasHeight); // bottom left
  4710. Vector2 uv1 = new Vector2(uv0.x, (underlineGlyphRect.y + underlineGlyphRect.height + m_padding) / atlasHeight); // top left
  4711. Vector2 uv2 = new Vector2((underlineGlyphRect.x - startPadding + (float)underlineGlyphRect.width / 2) / atlasWidth, uv1.y); // Mid Top Left
  4712. Vector2 uv3 = new Vector2(uv2.x, uv0.y); // Mid Bottom Left
  4713. Vector2 uv4 = new Vector2((underlineGlyphRect.x + endPadding + (float)underlineGlyphRect.width / 2) / atlasWidth, uv1.y); // Mid Top Right
  4714. Vector2 uv5 = new Vector2(uv4.x, uv0.y); // Mid Bottom right
  4715. Vector2 uv6 = new Vector2((underlineGlyphRect.x + endPadding + underlineGlyphRect.width) / atlasWidth, uv1.y); // End Part - Bottom Right
  4716. Vector2 uv7 = new Vector2(uv6.x, uv0.y); // End Part - Top Right
  4717. // Left Part of the Underline
  4718. uvs0[0 + index] = uv0; // BL
  4719. uvs0[1 + index] = uv1; // TL
  4720. uvs0[2 + index] = uv2; // TR
  4721. uvs0[3 + index] = uv3; // BR
  4722. // Middle Part of the Underline
  4723. uvs0[4 + index] = new Vector2(uv2.x - uv2.x * 0.001f, uv0.y);
  4724. uvs0[5 + index] = new Vector2(uv2.x - uv2.x * 0.001f, uv1.y);
  4725. uvs0[6 + index] = new Vector2(uv2.x + uv2.x * 0.001f, uv1.y);
  4726. uvs0[7 + index] = new Vector2(uv2.x + uv2.x * 0.001f, uv0.y);
  4727. // Right Part of the Underline
  4728. uvs0[8 + index] = uv5;
  4729. uvs0[9 + index] = uv4;
  4730. uvs0[10 + index] = uv6;
  4731. uvs0[11 + index] = uv7;
  4732. #endregion
  4733. // UNDERLINE UV2
  4734. #region HANDLE UV2 - SDF SCALE
  4735. // UV1 contains Face / Border UV layout.
  4736. float min_UvX = 0;
  4737. float max_UvX = (vertices[index + 2].x - start.x) / (end.x - start.x);
  4738. //Calculate the xScale or how much the UV's are getting stretched on the X axis for the middle section of the underline.
  4739. float xScale = Mathf.Abs(sdfScale);
  4740. Vector2[] uvs2 = m_textInfo.meshInfo[underlineMaterialIndex].uvs2;
  4741. uvs2[0 + index] = PackUV(0, 0, xScale);
  4742. uvs2[1 + index] = PackUV(0, 1, xScale);
  4743. uvs2[2 + index] = PackUV(max_UvX, 1, xScale);
  4744. uvs2[3 + index] = PackUV(max_UvX, 0, xScale);
  4745. min_UvX = (vertices[index + 4].x - start.x) / (end.x - start.x);
  4746. max_UvX = (vertices[index + 6].x - start.x) / (end.x - start.x);
  4747. uvs2[4 + index] = PackUV(min_UvX, 0, xScale);
  4748. uvs2[5 + index] = PackUV(min_UvX, 1, xScale);
  4749. uvs2[6 + index] = PackUV(max_UvX, 1, xScale);
  4750. uvs2[7 + index] = PackUV(max_UvX, 0, xScale);
  4751. min_UvX = (vertices[index + 8].x - start.x) / (end.x - start.x);
  4752. uvs2[8 + index] = PackUV(min_UvX, 0, xScale);
  4753. uvs2[9 + index] = PackUV(min_UvX, 1, xScale);
  4754. uvs2[10 + index] = PackUV(1, 1, xScale);
  4755. uvs2[11 + index] = PackUV(1, 0, xScale);
  4756. #endregion
  4757. // UNDERLINE VERTEX COLORS
  4758. #region UNDERLINE VERTEX COLORS
  4759. // Alpha is the lower of the vertex color or tag color alpha used.
  4760. underlineColor.a = m_fontColor32.a < underlineColor.a ? m_fontColor32.a : underlineColor.a;
  4761. Color32[] colors32 = m_textInfo.meshInfo[underlineMaterialIndex].colors32;
  4762. colors32[0 + index] = underlineColor;
  4763. colors32[1 + index] = underlineColor;
  4764. colors32[2 + index] = underlineColor;
  4765. colors32[3 + index] = underlineColor;
  4766. colors32[4 + index] = underlineColor;
  4767. colors32[5 + index] = underlineColor;
  4768. colors32[6 + index] = underlineColor;
  4769. colors32[7 + index] = underlineColor;
  4770. colors32[8 + index] = underlineColor;
  4771. colors32[9 + index] = underlineColor;
  4772. colors32[10 + index] = underlineColor;
  4773. colors32[11 + index] = underlineColor;
  4774. #endregion
  4775. index += 12;
  4776. }
  4777. protected virtual void DrawTextHighlight(Vector3 start, Vector3 end, ref int index, Color32 highlightColor)
  4778. {
  4779. if (m_Underline.character == null)
  4780. {
  4781. GetUnderlineSpecialCharacter(m_fontAsset);
  4782. if (m_Underline.character == null)
  4783. {
  4784. if (!TMP_Settings.warningsDisabled)
  4785. Debug.LogWarning("Unable to add highlight since the primary Font Asset doesn't contain the underline character.", this);
  4786. return;
  4787. }
  4788. }
  4789. int underlineMaterialIndex = m_Underline.materialIndex;
  4790. int verticesCount = index + 4;
  4791. // Check to make sure our current mesh buffer allocations can hold these new Quads.
  4792. if (verticesCount > m_textInfo.meshInfo[underlineMaterialIndex].vertices.Length)
  4793. {
  4794. // Resize Mesh Buffers
  4795. m_textInfo.meshInfo[underlineMaterialIndex].ResizeMeshInfo(verticesCount / 4);
  4796. }
  4797. // UNDERLINE VERTICES FOR (3) LINE SEGMENTS
  4798. #region HIGHLIGHT VERTICES
  4799. Vector3[] vertices = m_textInfo.meshInfo[underlineMaterialIndex].vertices;
  4800. // Front Part of the Underline
  4801. vertices[index + 0] = start; // BL
  4802. vertices[index + 1] = new Vector3(start.x, end.y, 0); // TL
  4803. vertices[index + 2] = end; // TR
  4804. vertices[index + 3] = new Vector3(end.x, start.y, 0); // BR
  4805. #endregion
  4806. // UNDERLINE UV0
  4807. #region HANDLE UV0
  4808. Vector2[] uvs0 = m_textInfo.meshInfo[underlineMaterialIndex].uvs0;
  4809. int atlasWidth = m_Underline.fontAsset.atlasWidth;
  4810. int atlasHeight = m_Underline.fontAsset.atlasHeight;
  4811. GlyphRect glyphRect = m_Underline.character.glyph.glyphRect;
  4812. // Calculate UV
  4813. Vector2 uv0 = new Vector2(((float)glyphRect.x + glyphRect.width / 2) / atlasWidth, (glyphRect.y + (float)glyphRect.height / 2) / atlasHeight); // bottom left
  4814. // UVs for the Quad
  4815. uvs0[0 + index] = uv0; // BL
  4816. uvs0[1 + index] = uv0; // TL
  4817. uvs0[2 + index] = uv0; // TR
  4818. uvs0[3 + index] = uv0; // BR
  4819. #endregion
  4820. // HIGHLIGHT UV2
  4821. #region HANDLE UV2 - SDF SCALE
  4822. Vector2[] uvs2 = m_textInfo.meshInfo[underlineMaterialIndex].uvs2;
  4823. Vector2 customUV = new Vector2(0, 1);
  4824. uvs2[0 + index] = customUV;
  4825. uvs2[1 + index] = customUV;
  4826. uvs2[2 + index] = customUV;
  4827. uvs2[3 + index] = customUV;
  4828. #endregion
  4829. // HIGHLIGHT VERTEX COLORS
  4830. #region
  4831. // Alpha is the lower of the vertex color or tag color alpha used.
  4832. highlightColor.a = m_fontColor32.a < highlightColor.a ? m_fontColor32.a : highlightColor.a;
  4833. Color32[] colors32 = m_textInfo.meshInfo[underlineMaterialIndex].colors32;
  4834. colors32[0 + index] = highlightColor;
  4835. colors32[1 + index] = highlightColor;
  4836. colors32[2 + index] = highlightColor;
  4837. colors32[3 + index] = highlightColor;
  4838. #endregion
  4839. index += 4;
  4840. }
  4841. /// <summary>
  4842. /// Internal function used to load the default settings of text objects.
  4843. /// </summary>
  4844. protected void LoadDefaultSettings()
  4845. {
  4846. if (m_fontSize == -99 || m_isWaitingOnResourceLoad)
  4847. {
  4848. m_rectTransform = this.rectTransform;
  4849. if (TMP_Settings.autoSizeTextContainer)
  4850. {
  4851. autoSizeTextContainer = true;
  4852. }
  4853. else
  4854. {
  4855. if (GetType() == typeof(TextMeshPro))
  4856. {
  4857. if (m_rectTransform.sizeDelta == new Vector2(100, 100))
  4858. m_rectTransform.sizeDelta = TMP_Settings.defaultTextMeshProTextContainerSize;
  4859. }
  4860. else
  4861. {
  4862. if (m_rectTransform.sizeDelta == new Vector2(100, 100))
  4863. m_rectTransform.sizeDelta = TMP_Settings.defaultTextMeshProUITextContainerSize;
  4864. }
  4865. }
  4866. m_enableWordWrapping = TMP_Settings.enableWordWrapping;
  4867. m_enableKerning = TMP_Settings.enableKerning;
  4868. m_enableExtraPadding = TMP_Settings.enableExtraPadding;
  4869. m_tintAllSprites = TMP_Settings.enableTintAllSprites;
  4870. m_parseCtrlCharacters = TMP_Settings.enableParseEscapeCharacters;
  4871. m_fontSize = m_fontSizeBase = TMP_Settings.defaultFontSize;
  4872. m_fontSizeMin = m_fontSize * TMP_Settings.defaultTextAutoSizingMinRatio;
  4873. m_fontSizeMax = m_fontSize * TMP_Settings.defaultTextAutoSizingMaxRatio;
  4874. m_isWaitingOnResourceLoad = false;
  4875. raycastTarget = TMP_Settings.enableRaycastTarget;
  4876. m_IsTextObjectScaleStatic = TMP_Settings.isTextObjectScaleStatic;
  4877. }
  4878. else if ((int)m_textAlignment < 0xFF)
  4879. {
  4880. // Convert Legacy TextAlignmentOptions enumerations from Unity 5.2 / 5.3.
  4881. m_textAlignment = TMP_Compatibility.ConvertTextAlignmentEnumValues(m_textAlignment);
  4882. }
  4883. // Convert text alignment to independent horizontal and vertical alignment properties
  4884. if (m_textAlignment != TextAlignmentOptions.Converted)
  4885. {
  4886. m_HorizontalAlignment = (HorizontalAlignmentOptions)((int)m_textAlignment & 0xFF);
  4887. m_VerticalAlignment = (VerticalAlignmentOptions)((int)m_textAlignment & 0xFF00);
  4888. m_textAlignment = TextAlignmentOptions.Converted;
  4889. }
  4890. }
  4891. /// <summary>
  4892. /// Method used to find and cache references to the Underline and Ellipsis characters.
  4893. /// </summary>
  4894. /// <param name=""></param>
  4895. protected void GetSpecialCharacters(TMP_FontAsset fontAsset)
  4896. {
  4897. GetEllipsisSpecialCharacter(fontAsset);
  4898. GetUnderlineSpecialCharacter(fontAsset);
  4899. }
  4900. protected void GetEllipsisSpecialCharacter(TMP_FontAsset fontAsset)
  4901. {
  4902. bool isUsingAlternativeTypeface;
  4903. // Search base font asset
  4904. TMP_Character character = TMP_FontAssetUtilities.GetCharacterFromFontAsset(0x2026, fontAsset, false, m_FontStyleInternal, m_FontWeightInternal, out isUsingAlternativeTypeface);
  4905. if (character == null)
  4906. {
  4907. // Search primary fallback list
  4908. if (fontAsset.m_FallbackFontAssetTable != null && fontAsset.m_FallbackFontAssetTable.Count > 0)
  4909. character = TMP_FontAssetUtilities.GetCharacterFromFontAssets(0x2026, fontAsset, fontAsset.m_FallbackFontAssetTable, true, m_FontStyleInternal, m_FontWeightInternal, out isUsingAlternativeTypeface);
  4910. }
  4911. // Search TMP Settings general fallback list
  4912. if (character == null)
  4913. {
  4914. if (TMP_Settings.fallbackFontAssets != null && TMP_Settings.fallbackFontAssets.Count > 0)
  4915. character = TMP_FontAssetUtilities.GetCharacterFromFontAssets(0x2026, fontAsset, TMP_Settings.fallbackFontAssets, true, m_FontStyleInternal, m_FontWeightInternal, out isUsingAlternativeTypeface);
  4916. }
  4917. // Search TMP Settings' default font asset
  4918. if (character == null)
  4919. {
  4920. if (TMP_Settings.defaultFontAsset != null)
  4921. character = TMP_FontAssetUtilities.GetCharacterFromFontAsset(0x2026, TMP_Settings.defaultFontAsset, true, m_FontStyleInternal, m_FontWeightInternal, out isUsingAlternativeTypeface);
  4922. }
  4923. if (character != null)
  4924. m_Ellipsis = new SpecialCharacter(character, 0);
  4925. }
  4926. protected void GetUnderlineSpecialCharacter(TMP_FontAsset fontAsset)
  4927. {
  4928. bool isUsingAlternativeTypeface;
  4929. // Search primary font asset for underline character while ignoring font style and weight as these do not affect the underline character.
  4930. TMP_Character character = TMP_FontAssetUtilities.GetCharacterFromFontAsset(0x5F, fontAsset, false, FontStyles.Normal, FontWeight.Regular, out isUsingAlternativeTypeface);
  4931. /*
  4932. if (m_Underline.character == null)
  4933. {
  4934. // Search primary fallback list
  4935. if (fontAsset.m_FallbackFontAssetTable != null && fontAsset.m_FallbackFontAssetTable.Count > 0)
  4936. m_Underline.character = TMP_FontAssetUtilities.GetCharacterFromFontAssets(0x5F, fontAsset.m_FallbackFontAssetTable, true, m_FontStyleInternal, m_FontWeightInternal, out isUsingAlternativeTypeface, out tempFontAsset);
  4937. }
  4938. // Search TMP Settings general fallback list
  4939. if (m_Underline.character == null)
  4940. {
  4941. if (TMP_Settings.fallbackFontAssets != null && TMP_Settings.fallbackFontAssets.Count > 0)
  4942. m_Underline.character = TMP_FontAssetUtilities.GetCharacterFromFontAssets(0x5F, TMP_Settings.fallbackFontAssets, true, m_FontStyleInternal, m_FontWeightInternal, out isUsingAlternativeTypeface, out tempFontAsset);
  4943. }
  4944. // Search TMP Settings' default font asset
  4945. if (m_Underline.character == null)
  4946. {
  4947. if (TMP_Settings.defaultFontAsset != null)
  4948. m_Underline.character = TMP_FontAssetUtilities.GetCharacterFromFontAsset(0x5F, TMP_Settings.defaultFontAsset, true, m_FontStyleInternal, m_FontWeightInternal, out isUsingAlternativeTypeface, out tempFontAsset);
  4949. }
  4950. */
  4951. if (character != null)
  4952. {
  4953. m_Underline = new SpecialCharacter(character, 0);
  4954. }
  4955. else
  4956. {
  4957. if (!TMP_Settings.warningsDisabled)
  4958. Debug.LogWarning("The character used for Underline is not available in font asset [" + fontAsset.name + "].", this);
  4959. }
  4960. }
  4961. /// <summary>
  4962. /// Replace a given number of characters (tag) in the array with a new character and shift subsequent characters in the array.
  4963. /// </summary>
  4964. /// <param name="chars">Array which contains the text.</param>
  4965. /// <param name="insertionIndex">The index of where the new character will be inserted</param>
  4966. /// <param name="tagLength">Length of the tag being replaced.</param>
  4967. /// <param name="c">The replacement character.</param>
  4968. protected void ReplaceTagWithCharacter(int[] chars, int insertionIndex, int tagLength, char c)
  4969. {
  4970. chars[insertionIndex] = c;
  4971. for (int i = insertionIndex + tagLength; i < chars.Length; i++)
  4972. {
  4973. chars[i - 3] = chars[i];
  4974. }
  4975. }
  4976. /// <summary>
  4977. ///
  4978. /// </summary>
  4979. /// <returns></returns>
  4980. //protected int GetMaterialReferenceForFontWeight()
  4981. //{
  4982. // //bool isItalic = (m_style & FontStyles.Italic) == FontStyles.Italic || (m_fontStyle & FontStyles.Italic) == FontStyles.Italic;
  4983. // m_currentMaterialIndex = MaterialReference.AddMaterialReference(m_currentFontAsset.fontWeights[0].italicTypeface.material, m_currentFontAsset.fontWeights[0].italicTypeface, m_materialReferences, m_materialReferenceIndexLookup);
  4984. // return 0;
  4985. //}
  4986. /// <summary>
  4987. ///
  4988. /// </summary>
  4989. /// <returns></returns>
  4990. protected TMP_FontAsset GetFontAssetForWeight(int fontWeight)
  4991. {
  4992. bool isItalic = (m_FontStyleInternal & FontStyles.Italic) == FontStyles.Italic || (m_fontStyle & FontStyles.Italic) == FontStyles.Italic;
  4993. TMP_FontAsset fontAsset = null;
  4994. int weightIndex = fontWeight / 100;
  4995. if (isItalic)
  4996. fontAsset = m_currentFontAsset.fontWeightTable[weightIndex].italicTypeface;
  4997. else
  4998. fontAsset = m_currentFontAsset.fontWeightTable[weightIndex].regularTypeface;
  4999. return fontAsset;
  5000. }
  5001. internal TMP_TextElement GetTextElement(uint unicode, TMP_FontAsset fontAsset, FontStyles fontStyle, FontWeight fontWeight, out bool isUsingAlternativeTypeface)
  5002. {
  5003. TMP_Character character = TMP_FontAssetUtilities.GetCharacterFromFontAsset(unicode, fontAsset, false, fontStyle, fontWeight, out isUsingAlternativeTypeface);
  5004. if (character != null)
  5005. return character;
  5006. // Search potential list of fallback font assets assigned to the font asset.
  5007. if (fontAsset.m_FallbackFontAssetTable != null && fontAsset.m_FallbackFontAssetTable.Count > 0)
  5008. character = TMP_FontAssetUtilities.GetCharacterFromFontAssets(unicode, fontAsset, fontAsset.m_FallbackFontAssetTable, true, fontStyle, fontWeight, out isUsingAlternativeTypeface);
  5009. if (character != null)
  5010. {
  5011. // Add character to font asset lookup cache
  5012. //fontAsset.AddCharacterToLookupCache(unicode, character);
  5013. return character;
  5014. }
  5015. // Search for the character in the primary font asset if not the current font asset
  5016. if (fontAsset.instanceID != m_fontAsset.instanceID)
  5017. {
  5018. // Search primary font asset
  5019. character = TMP_FontAssetUtilities.GetCharacterFromFontAsset(unicode, m_fontAsset, false, fontStyle, fontWeight, out isUsingAlternativeTypeface);
  5020. // Use material and index of primary font asset.
  5021. if (character != null)
  5022. {
  5023. m_currentMaterialIndex = 0;
  5024. m_currentMaterial = m_materialReferences[0].material;
  5025. // Add character to font asset lookup cache
  5026. //fontAsset.AddCharacterToLookupCache(unicode, character);
  5027. return character;
  5028. }
  5029. // Search list of potential fallback font assets assigned to the primary font asset.
  5030. if (m_fontAsset.m_FallbackFontAssetTable != null && m_fontAsset.m_FallbackFontAssetTable.Count > 0)
  5031. character = TMP_FontAssetUtilities.GetCharacterFromFontAssets(unicode, fontAsset, m_fontAsset.m_FallbackFontAssetTable, true, fontStyle, fontWeight, out isUsingAlternativeTypeface);
  5032. if (character != null)
  5033. {
  5034. // Add character to font asset lookup cache
  5035. //fontAsset.AddCharacterToLookupCache(unicode, character);
  5036. return character;
  5037. }
  5038. }
  5039. // Search for the character in potential local Sprite Asset assigned to the text object.
  5040. if (m_spriteAsset != null)
  5041. {
  5042. TMP_SpriteCharacter spriteCharacter = TMP_FontAssetUtilities.GetSpriteCharacterFromSpriteAsset(unicode, m_spriteAsset, true);
  5043. if (spriteCharacter != null)
  5044. return spriteCharacter;
  5045. }
  5046. // Search for the character in the list of fallback assigned in the TMP Settings (General Fallbacks).
  5047. if (TMP_Settings.fallbackFontAssets != null && TMP_Settings.fallbackFontAssets.Count > 0)
  5048. character = TMP_FontAssetUtilities.GetCharacterFromFontAssets(unicode, fontAsset, TMP_Settings.fallbackFontAssets, true, fontStyle, fontWeight, out isUsingAlternativeTypeface);
  5049. if (character != null)
  5050. {
  5051. // Add character to font asset lookup cache
  5052. //fontAsset.AddCharacterToLookupCache(unicode, character);
  5053. return character;
  5054. }
  5055. // Search for the character in the Default Font Asset assigned in the TMP Settings file.
  5056. if (TMP_Settings.defaultFontAsset != null)
  5057. character = TMP_FontAssetUtilities.GetCharacterFromFontAsset(unicode, TMP_Settings.defaultFontAsset, true, fontStyle, fontWeight, out isUsingAlternativeTypeface);
  5058. if (character != null)
  5059. {
  5060. // Add character to font asset lookup cache
  5061. //fontAsset.AddCharacterToLookupCache(unicode, character);
  5062. return character;
  5063. }
  5064. // Search for the character in the Default Sprite Asset assigned in the TMP Settings file.
  5065. if (TMP_Settings.defaultSpriteAsset != null)
  5066. {
  5067. TMP_SpriteCharacter spriteCharacter = TMP_FontAssetUtilities.GetSpriteCharacterFromSpriteAsset(unicode, TMP_Settings.defaultSpriteAsset, true);
  5068. if (spriteCharacter != null)
  5069. return spriteCharacter;
  5070. }
  5071. return null;
  5072. }
  5073. /// <summary>
  5074. /// Method to Enable or Disable child SubMesh objects.
  5075. /// </summary>
  5076. /// <param name="state"></param>
  5077. protected virtual void SetActiveSubMeshes(bool state) { }
  5078. /// <summary>
  5079. /// Destroy Sub Mesh Objects.
  5080. /// </summary>
  5081. protected virtual void DestroySubMeshObjects() { }
  5082. /// <summary>
  5083. /// Function to clear the geometry of the Primary and Sub Text objects.
  5084. /// </summary>
  5085. public virtual void ClearMesh() { }
  5086. /// <summary>
  5087. /// Function to clear the geometry of the Primary and Sub Text objects.
  5088. /// </summary>
  5089. public virtual void ClearMesh(bool uploadGeometry) { }
  5090. /// <summary>
  5091. /// Function which returns the text after it has been parsed and rich text tags removed.
  5092. /// </summary>
  5093. /// <returns></returns>
  5094. public virtual string GetParsedText()
  5095. {
  5096. if (m_textInfo == null)
  5097. return string.Empty;
  5098. int characterCount = m_textInfo.characterCount;
  5099. // TODO - Could implement some static buffer pool shared by all instances of TMP objects.
  5100. char[] buffer = new char[characterCount];
  5101. for (int i = 0; i < characterCount && i < m_textInfo.characterInfo.Length; i++)
  5102. {
  5103. buffer[i] = m_textInfo.characterInfo[i].character;
  5104. }
  5105. return new string(buffer);
  5106. }
  5107. internal bool IsSelfOrLinkedAncestor(TMP_Text targetTextComponent)
  5108. {
  5109. if (targetTextComponent == null)
  5110. return true;
  5111. if (parentLinkedComponent != null)
  5112. {
  5113. if (parentLinkedComponent.IsSelfOrLinkedAncestor(targetTextComponent))
  5114. return true;
  5115. }
  5116. if (this.GetInstanceID() == targetTextComponent.GetInstanceID())
  5117. return true;
  5118. return false;
  5119. }
  5120. internal void ReleaseLinkedTextComponent(TMP_Text targetTextComponent)
  5121. {
  5122. if (targetTextComponent == null)
  5123. return;
  5124. TMP_Text childLinkedComponent = targetTextComponent.linkedTextComponent;
  5125. if (childLinkedComponent != null)
  5126. ReleaseLinkedTextComponent(childLinkedComponent);
  5127. targetTextComponent.text = string.Empty;
  5128. targetTextComponent.firstVisibleCharacter = 0;
  5129. targetTextComponent.linkedTextComponent = null;
  5130. targetTextComponent.parentLinkedComponent = null;
  5131. }
  5132. /// <summary>
  5133. /// Function to pack scale information in the UV2 Channel.
  5134. /// </summary>
  5135. /// <param name="x"></param>
  5136. /// <param name="y"></param>
  5137. /// <param name="scale"></param>
  5138. /// <returns></returns>
  5139. //protected Vector2 PackUV(float x, float y, float scale)
  5140. //{
  5141. // Vector2 output;
  5142. // output.x = Mathf.Floor(x * 4095);
  5143. // output.y = Mathf.Floor(y * 4095);
  5144. // output.x = (output.x * 4096) + output.y;
  5145. // output.y = scale;
  5146. // return output;
  5147. //}
  5148. /// <summary>
  5149. /// Function to pack scale information in the UV2 Channel.
  5150. /// </summary>
  5151. /// <param name="x"></param>
  5152. /// <param name="y"></param>
  5153. /// <param name="scale"></param>
  5154. /// <returns></returns>
  5155. protected Vector2 PackUV(float x, float y, float scale)
  5156. {
  5157. Vector2 output;
  5158. output.x = (int)(x * 511);
  5159. output.y = (int)(y * 511);
  5160. output.x = (output.x * 4096) + output.y;
  5161. output.y = scale;
  5162. return output;
  5163. }
  5164. /// <summary>
  5165. ///
  5166. /// </summary>
  5167. /// <param name="x"></param>
  5168. /// <param name="y"></param>
  5169. /// <returns></returns>
  5170. protected float PackUV(float x, float y)
  5171. {
  5172. double x0 = (int)(x * 511);
  5173. double y0 = (int)(y * 511);
  5174. return (float)((x0 * 4096) + y0);
  5175. }
  5176. /// <summary>
  5177. /// Function used as a replacement for LateUpdate()
  5178. /// </summary>
  5179. internal virtual void InternalUpdate() { }
  5180. /// <summary>
  5181. /// Function to pack scale information in the UV2 Channel.
  5182. /// </summary>
  5183. /// <param name="x"></param>
  5184. /// <param name="y"></param>
  5185. /// <param name="scale"></param>
  5186. /// <returns></returns>
  5187. //protected Vector2 PackUV(float x, float y, float scale)
  5188. //{
  5189. // Vector2 output;
  5190. // output.x = Mathf.Floor(x * 4095);
  5191. // output.y = Mathf.Floor(y * 4095);
  5192. // return new Vector2((output.x * 4096) + output.y, scale);
  5193. //}
  5194. /// <summary>
  5195. ///
  5196. /// </summary>
  5197. /// <param name="x"></param>
  5198. /// <param name="y"></param>
  5199. /// <returns></returns>
  5200. //protected float PackUV(float x, float y)
  5201. //{
  5202. // x = (x % 5) / 5;
  5203. // y = (y % 5) / 5;
  5204. // return Mathf.Round(x * 4096) + y;
  5205. //}
  5206. /// <summary>
  5207. /// Method to convert Hex to Int
  5208. /// </summary>
  5209. /// <param name="hex"></param>
  5210. /// <returns></returns>
  5211. protected int HexToInt(char hex)
  5212. {
  5213. switch (hex)
  5214. {
  5215. case '0': return 0;
  5216. case '1': return 1;
  5217. case '2': return 2;
  5218. case '3': return 3;
  5219. case '4': return 4;
  5220. case '5': return 5;
  5221. case '6': return 6;
  5222. case '7': return 7;
  5223. case '8': return 8;
  5224. case '9': return 9;
  5225. case 'A': return 10;
  5226. case 'B': return 11;
  5227. case 'C': return 12;
  5228. case 'D': return 13;
  5229. case 'E': return 14;
  5230. case 'F': return 15;
  5231. case 'a': return 10;
  5232. case 'b': return 11;
  5233. case 'c': return 12;
  5234. case 'd': return 13;
  5235. case 'e': return 14;
  5236. case 'f': return 15;
  5237. }
  5238. return 15;
  5239. }
  5240. /// <summary>
  5241. /// Convert UTF-16 Hex to Char
  5242. /// </summary>
  5243. /// <returns>The Unicode hex.</returns>
  5244. /// <param name="i">The index.</param>
  5245. protected int GetUTF16(string text, int i)
  5246. {
  5247. int unicode = 0;
  5248. unicode += HexToInt(text[i]) << 12;
  5249. unicode += HexToInt(text[i + 1]) << 8;
  5250. unicode += HexToInt(text[i + 2]) << 4;
  5251. unicode += HexToInt(text[i + 3]);
  5252. return unicode;
  5253. }
  5254. protected int GetUTF16(int[] text, int i)
  5255. {
  5256. int unicode = 0;
  5257. unicode += HexToInt((char)text[i]) << 12;
  5258. unicode += HexToInt((char)text[i + 1]) << 8;
  5259. unicode += HexToInt((char)text[i + 2]) << 4;
  5260. unicode += HexToInt((char)text[i + 3]);
  5261. return unicode;
  5262. }
  5263. internal int GetUTF16(uint[] text, int i)
  5264. {
  5265. int unicode = 0;
  5266. unicode += HexToInt((char)text[i]) << 12;
  5267. unicode += HexToInt((char)text[i + 1]) << 8;
  5268. unicode += HexToInt((char)text[i + 2]) << 4;
  5269. unicode += HexToInt((char)text[i + 3]);
  5270. return unicode;
  5271. }
  5272. /// <summary>
  5273. /// Convert UTF-16 Hex to Char
  5274. /// </summary>
  5275. /// <returns>The Unicode hex.</returns>
  5276. /// <param name="i">The index.</param>
  5277. protected int GetUTF16(StringBuilder text, int i)
  5278. {
  5279. int unicode = 0;
  5280. unicode += HexToInt(text[i]) << 12;
  5281. unicode += HexToInt(text[i + 1]) << 8;
  5282. unicode += HexToInt(text[i + 2]) << 4;
  5283. unicode += HexToInt(text[i + 3]);
  5284. return unicode;
  5285. }
  5286. private int GetUTF16(TextBackingContainer text, int i)
  5287. {
  5288. int unicode = 0;
  5289. unicode += HexToInt((char)text[i]) << 12;
  5290. unicode += HexToInt((char)text[i + 1]) << 8;
  5291. unicode += HexToInt((char)text[i + 2]) << 4;
  5292. unicode += HexToInt((char)text[i + 3]);
  5293. return unicode;
  5294. }
  5295. /// <summary>
  5296. /// Convert UTF-32 Hex to Char
  5297. /// </summary>
  5298. /// <returns>The Unicode hex.</returns>
  5299. /// <param name="i">The index.</param>
  5300. protected int GetUTF32(string text, int i)
  5301. {
  5302. int unicode = 0;
  5303. unicode += HexToInt(text[i]) << 28;
  5304. unicode += HexToInt(text[i + 1]) << 24;
  5305. unicode += HexToInt(text[i + 2]) << 20;
  5306. unicode += HexToInt(text[i + 3]) << 16;
  5307. unicode += HexToInt(text[i + 4]) << 12;
  5308. unicode += HexToInt(text[i + 5]) << 8;
  5309. unicode += HexToInt(text[i + 6]) << 4;
  5310. unicode += HexToInt(text[i + 7]);
  5311. return unicode;
  5312. }
  5313. protected int GetUTF32(int[] text, int i)
  5314. {
  5315. int unicode = 0;
  5316. unicode += HexToInt((char)text[i]) << 28;
  5317. unicode += HexToInt((char)text[i + 1]) << 24;
  5318. unicode += HexToInt((char)text[i + 2]) << 20;
  5319. unicode += HexToInt((char)text[i + 3]) << 16;
  5320. unicode += HexToInt((char)text[i + 4]) << 12;
  5321. unicode += HexToInt((char)text[i + 5]) << 8;
  5322. unicode += HexToInt((char)text[i + 6]) << 4;
  5323. unicode += HexToInt((char)text[i + 7]);
  5324. return unicode;
  5325. }
  5326. internal int GetUTF32(uint[] text, int i)
  5327. {
  5328. int unicode = 0;
  5329. unicode += HexToInt((char)text[i]) << 28;
  5330. unicode += HexToInt((char)text[i + 1]) << 24;
  5331. unicode += HexToInt((char)text[i + 2]) << 20;
  5332. unicode += HexToInt((char)text[i + 3]) << 16;
  5333. unicode += HexToInt((char)text[i + 4]) << 12;
  5334. unicode += HexToInt((char)text[i + 5]) << 8;
  5335. unicode += HexToInt((char)text[i + 6]) << 4;
  5336. unicode += HexToInt((char)text[i + 7]);
  5337. return unicode;
  5338. }
  5339. /// <summary>
  5340. /// Convert UTF-32 Hex to Char
  5341. /// </summary>
  5342. /// <returns>The Unicode hex.</returns>
  5343. /// <param name="i">The index.</param>
  5344. protected int GetUTF32(StringBuilder text, int i)
  5345. {
  5346. int unicode = 0;
  5347. unicode += HexToInt(text[i]) << 28;
  5348. unicode += HexToInt(text[i + 1]) << 24;
  5349. unicode += HexToInt(text[i + 2]) << 20;
  5350. unicode += HexToInt(text[i + 3]) << 16;
  5351. unicode += HexToInt(text[i + 4]) << 12;
  5352. unicode += HexToInt(text[i + 5]) << 8;
  5353. unicode += HexToInt(text[i + 6]) << 4;
  5354. unicode += HexToInt(text[i + 7]);
  5355. return unicode;
  5356. }
  5357. int GetUTF32(TextBackingContainer text, int i)
  5358. {
  5359. int unicode = 0;
  5360. unicode += HexToInt((char)text[i]) << 28;
  5361. unicode += HexToInt((char)text[i + 1]) << 24;
  5362. unicode += HexToInt((char)text[i + 2]) << 20;
  5363. unicode += HexToInt((char)text[i + 3]) << 16;
  5364. unicode += HexToInt((char)text[i + 4]) << 12;
  5365. unicode += HexToInt((char)text[i + 5]) << 8;
  5366. unicode += HexToInt((char)text[i + 6]) << 4;
  5367. unicode += HexToInt((char)text[i + 7]);
  5368. return unicode;
  5369. }
  5370. /// <summary>
  5371. /// Method to convert Hex color values to Color32
  5372. /// </summary>
  5373. /// <param name="hexChars"></param>
  5374. /// <param name="tagCount"></param>
  5375. /// <returns></returns>
  5376. protected Color32 HexCharsToColor(char[] hexChars, int tagCount)
  5377. {
  5378. if (tagCount == 4)
  5379. {
  5380. byte r = (byte)(HexToInt(hexChars[1]) * 16 + HexToInt(hexChars[1]));
  5381. byte g = (byte)(HexToInt(hexChars[2]) * 16 + HexToInt(hexChars[2]));
  5382. byte b = (byte)(HexToInt(hexChars[3]) * 16 + HexToInt(hexChars[3]));
  5383. return new Color32(r, g, b, 255);
  5384. }
  5385. else if (tagCount == 5)
  5386. {
  5387. byte r = (byte)(HexToInt(hexChars[1]) * 16 + HexToInt(hexChars[1]));
  5388. byte g = (byte)(HexToInt(hexChars[2]) * 16 + HexToInt(hexChars[2]));
  5389. byte b = (byte)(HexToInt(hexChars[3]) * 16 + HexToInt(hexChars[3]));
  5390. byte a = (byte)(HexToInt(hexChars[4]) * 16 + HexToInt(hexChars[4]));
  5391. return new Color32(r, g, b, a);
  5392. }
  5393. else if (tagCount == 7)
  5394. {
  5395. byte r = (byte)(HexToInt(hexChars[1]) * 16 + HexToInt(hexChars[2]));
  5396. byte g = (byte)(HexToInt(hexChars[3]) * 16 + HexToInt(hexChars[4]));
  5397. byte b = (byte)(HexToInt(hexChars[5]) * 16 + HexToInt(hexChars[6]));
  5398. return new Color32(r, g, b, 255);
  5399. }
  5400. else if (tagCount == 9)
  5401. {
  5402. byte r = (byte)(HexToInt(hexChars[1]) * 16 + HexToInt(hexChars[2]));
  5403. byte g = (byte)(HexToInt(hexChars[3]) * 16 + HexToInt(hexChars[4]));
  5404. byte b = (byte)(HexToInt(hexChars[5]) * 16 + HexToInt(hexChars[6]));
  5405. byte a = (byte)(HexToInt(hexChars[7]) * 16 + HexToInt(hexChars[8]));
  5406. return new Color32(r, g, b, a);
  5407. }
  5408. else if (tagCount == 10)
  5409. {
  5410. byte r = (byte)(HexToInt(hexChars[7]) * 16 + HexToInt(hexChars[7]));
  5411. byte g = (byte)(HexToInt(hexChars[8]) * 16 + HexToInt(hexChars[8]));
  5412. byte b = (byte)(HexToInt(hexChars[9]) * 16 + HexToInt(hexChars[9]));
  5413. return new Color32(r, g, b, 255);
  5414. }
  5415. else if (tagCount == 11)
  5416. {
  5417. byte r = (byte)(HexToInt(hexChars[7]) * 16 + HexToInt(hexChars[7]));
  5418. byte g = (byte)(HexToInt(hexChars[8]) * 16 + HexToInt(hexChars[8]));
  5419. byte b = (byte)(HexToInt(hexChars[9]) * 16 + HexToInt(hexChars[9]));
  5420. byte a = (byte)(HexToInt(hexChars[10]) * 16 + HexToInt(hexChars[10]));
  5421. return new Color32(r, g, b, a);
  5422. }
  5423. else if (tagCount == 13)
  5424. {
  5425. byte r = (byte)(HexToInt(hexChars[7]) * 16 + HexToInt(hexChars[8]));
  5426. byte g = (byte)(HexToInt(hexChars[9]) * 16 + HexToInt(hexChars[10]));
  5427. byte b = (byte)(HexToInt(hexChars[11]) * 16 + HexToInt(hexChars[12]));
  5428. return new Color32(r, g, b, 255);
  5429. }
  5430. else if (tagCount == 15)
  5431. {
  5432. byte r = (byte)(HexToInt(hexChars[7]) * 16 + HexToInt(hexChars[8]));
  5433. byte g = (byte)(HexToInt(hexChars[9]) * 16 + HexToInt(hexChars[10]));
  5434. byte b = (byte)(HexToInt(hexChars[11]) * 16 + HexToInt(hexChars[12]));
  5435. byte a = (byte)(HexToInt(hexChars[13]) * 16 + HexToInt(hexChars[14]));
  5436. return new Color32(r, g, b, a);
  5437. }
  5438. return new Color32(255, 255, 255, 255);
  5439. }
  5440. /// <summary>
  5441. /// Method to convert Hex Color values to Color32
  5442. /// </summary>
  5443. /// <param name="hexChars"></param>
  5444. /// <param name="startIndex"></param>
  5445. /// <param name="length"></param>
  5446. /// <returns></returns>
  5447. protected Color32 HexCharsToColor(char[] hexChars, int startIndex, int length)
  5448. {
  5449. if (length == 7)
  5450. {
  5451. byte r = (byte)(HexToInt(hexChars[startIndex + 1]) * 16 + HexToInt(hexChars[startIndex + 2]));
  5452. byte g = (byte)(HexToInt(hexChars[startIndex + 3]) * 16 + HexToInt(hexChars[startIndex + 4]));
  5453. byte b = (byte)(HexToInt(hexChars[startIndex + 5]) * 16 + HexToInt(hexChars[startIndex + 6]));
  5454. return new Color32(r, g, b, 255);
  5455. }
  5456. else if (length == 9)
  5457. {
  5458. byte r = (byte)(HexToInt(hexChars[startIndex + 1]) * 16 + HexToInt(hexChars[startIndex + 2]));
  5459. byte g = (byte)(HexToInt(hexChars[startIndex + 3]) * 16 + HexToInt(hexChars[startIndex + 4]));
  5460. byte b = (byte)(HexToInt(hexChars[startIndex + 5]) * 16 + HexToInt(hexChars[startIndex + 6]));
  5461. byte a = (byte)(HexToInt(hexChars[startIndex + 7]) * 16 + HexToInt(hexChars[startIndex + 8]));
  5462. return new Color32(r, g, b, a);
  5463. }
  5464. return s_colorWhite;
  5465. }
  5466. /// <summary>
  5467. /// Method which returns the number of parameters used in a tag attribute and populates an array with such values.
  5468. /// </summary>
  5469. /// <param name="chars">Char[] containing the tag attribute and data</param>
  5470. /// <param name="startIndex">The index of the first char of the data</param>
  5471. /// <param name="length">The length of the data</param>
  5472. /// <param name="parameters">The number of parameters contained in the Char[]</param>
  5473. /// <returns></returns>
  5474. int GetAttributeParameters(char[] chars, int startIndex, int length, ref float[] parameters)
  5475. {
  5476. int endIndex = startIndex;
  5477. int attributeCount = 0;
  5478. while (endIndex < startIndex + length)
  5479. {
  5480. parameters[attributeCount] = ConvertToFloat(chars, startIndex, length, out endIndex);
  5481. length -= (endIndex - startIndex) + 1;
  5482. startIndex = endIndex + 1;
  5483. attributeCount += 1;
  5484. }
  5485. return attributeCount;
  5486. }
  5487. /// <summary>
  5488. /// Extracts a float value from char[] assuming we know the position of the start, end and decimal point.
  5489. /// </summary>
  5490. /// <param name="chars"></param>
  5491. /// <param name="startIndex"></param>
  5492. /// <param name="length"></param>
  5493. /// <returns></returns>
  5494. protected float ConvertToFloat(char[] chars, int startIndex, int length)
  5495. {
  5496. int lastIndex;
  5497. return ConvertToFloat(chars, startIndex, length, out lastIndex);
  5498. }
  5499. /// <summary>
  5500. /// Extracts a float value from char[] given a start index and length.
  5501. /// </summary>
  5502. /// <param name="chars"></param> The Char[] containing the numerical sequence.
  5503. /// <param name="startIndex"></param> The index of the start of the numerical sequence.
  5504. /// <param name="length"></param> The length of the numerical sequence.
  5505. /// <param name="lastIndex"></param> Index of the last character in the validated sequence.
  5506. /// <returns></returns>
  5507. protected float ConvertToFloat(char[] chars, int startIndex, int length, out int lastIndex)
  5508. {
  5509. if (startIndex == 0)
  5510. {
  5511. lastIndex = 0;
  5512. return Int16.MinValue;
  5513. }
  5514. int endIndex = startIndex + length;
  5515. bool isIntegerValue = true;
  5516. float decimalPointMultiplier = 0;
  5517. // Set value multiplier checking the first character to determine if we are using '+' or '-'
  5518. int valueSignMultiplier = 1;
  5519. if (chars[startIndex] == '+')
  5520. {
  5521. valueSignMultiplier = 1;
  5522. startIndex += 1;
  5523. }
  5524. else if (chars[startIndex] == '-')
  5525. {
  5526. valueSignMultiplier = -1;
  5527. startIndex += 1;
  5528. }
  5529. float value = 0;
  5530. for (int i = startIndex; i < endIndex; i++)
  5531. {
  5532. uint c = chars[i];
  5533. if (c >= '0' && c <= '9' || c == '.')
  5534. {
  5535. if (c == '.')
  5536. {
  5537. isIntegerValue = false;
  5538. decimalPointMultiplier = 0.1f;
  5539. continue;
  5540. }
  5541. //Calculate integer and floating point value
  5542. if (isIntegerValue)
  5543. value = value * 10 + (c - 48) * valueSignMultiplier;
  5544. else
  5545. {
  5546. value = value + (c - 48) * decimalPointMultiplier * valueSignMultiplier;
  5547. decimalPointMultiplier *= 0.1f;
  5548. }
  5549. continue;
  5550. }
  5551. else if (c == ',')
  5552. {
  5553. if (i + 1 < endIndex && chars[i + 1] == ' ')
  5554. lastIndex = i + 1;
  5555. else
  5556. lastIndex = i;
  5557. // Make sure value is within reasonable range.
  5558. if (value > 32767)
  5559. return Int16.MinValue;
  5560. return value;
  5561. }
  5562. }
  5563. lastIndex = endIndex;
  5564. // Make sure value is within reasonable range.
  5565. if (value > 32767)
  5566. return Int16.MinValue;
  5567. return value;
  5568. }
  5569. /// <summary>
  5570. /// Function to identify and validate the rich tag. Returns the position of the > if the tag was valid.
  5571. /// </summary>
  5572. /// <param name="chars"></param>
  5573. /// <param name="startIndex"></param>
  5574. /// <param name="endIndex"></param>
  5575. /// <returns></returns>
  5576. internal bool ValidateHtmlTag(UnicodeChar[] chars, int startIndex, out int endIndex)
  5577. {
  5578. int tagCharCount = 0;
  5579. byte attributeFlag = 0;
  5580. int attributeIndex = 0;
  5581. m_xmlAttribute[attributeIndex].nameHashCode = 0;
  5582. m_xmlAttribute[attributeIndex].valueHashCode = 0;
  5583. m_xmlAttribute[attributeIndex].valueStartIndex = 0;
  5584. m_xmlAttribute[attributeIndex].valueLength = 0;
  5585. TagValueType tagValueType = m_xmlAttribute[attributeIndex].valueType = TagValueType.None;
  5586. TagUnitType tagUnitType = m_xmlAttribute[attributeIndex].unitType = TagUnitType.Pixels;
  5587. // Clear attribute name hash codes
  5588. m_xmlAttribute[1].nameHashCode = 0;
  5589. m_xmlAttribute[2].nameHashCode = 0;
  5590. m_xmlAttribute[3].nameHashCode = 0;
  5591. m_xmlAttribute[4].nameHashCode = 0;
  5592. endIndex = startIndex;
  5593. bool isTagSet = false;
  5594. bool isValidHtmlTag = false;
  5595. for (int i = startIndex; i < chars.Length && chars[i].unicode != 0 && tagCharCount < m_htmlTag.Length && chars[i].unicode != '<'; i++)
  5596. {
  5597. int unicode = chars[i].unicode;
  5598. if (unicode == '>') // ASCII Code of End HTML tag '>'
  5599. {
  5600. isValidHtmlTag = true;
  5601. endIndex = i;
  5602. m_htmlTag[tagCharCount] = (char)0;
  5603. break;
  5604. }
  5605. m_htmlTag[tagCharCount] = (char)unicode;
  5606. tagCharCount += 1;
  5607. if (attributeFlag == 1)
  5608. {
  5609. if (tagValueType == TagValueType.None)
  5610. {
  5611. // Check for attribute type
  5612. if (unicode == '+' || unicode == '-' || unicode == '.' || (unicode >= '0' && unicode <= '9'))
  5613. {
  5614. tagUnitType = TagUnitType.Pixels;
  5615. tagValueType = m_xmlAttribute[attributeIndex].valueType = TagValueType.NumericalValue;
  5616. m_xmlAttribute[attributeIndex].valueStartIndex = tagCharCount - 1;
  5617. m_xmlAttribute[attributeIndex].valueLength += 1;
  5618. }
  5619. else if (unicode == '#')
  5620. {
  5621. tagUnitType = TagUnitType.Pixels;
  5622. tagValueType = m_xmlAttribute[attributeIndex].valueType = TagValueType.ColorValue;
  5623. m_xmlAttribute[attributeIndex].valueStartIndex = tagCharCount - 1;
  5624. m_xmlAttribute[attributeIndex].valueLength += 1;
  5625. }
  5626. else if (unicode == '"')
  5627. {
  5628. tagUnitType = TagUnitType.Pixels;
  5629. tagValueType = m_xmlAttribute[attributeIndex].valueType = TagValueType.StringValue;
  5630. m_xmlAttribute[attributeIndex].valueStartIndex = tagCharCount;
  5631. }
  5632. else
  5633. {
  5634. tagUnitType = TagUnitType.Pixels;
  5635. tagValueType = m_xmlAttribute[attributeIndex].valueType = TagValueType.StringValue;
  5636. m_xmlAttribute[attributeIndex].valueStartIndex = tagCharCount - 1;
  5637. m_xmlAttribute[attributeIndex].valueHashCode = (m_xmlAttribute[attributeIndex].valueHashCode << 5) + m_xmlAttribute[attributeIndex].valueHashCode ^ unicode;
  5638. m_xmlAttribute[attributeIndex].valueLength += 1;
  5639. }
  5640. }
  5641. else
  5642. {
  5643. if (tagValueType == TagValueType.NumericalValue)
  5644. {
  5645. // Check for termination of numerical value.
  5646. if (unicode == 'p' || unicode == 'e' || unicode == '%' || unicode == ' ')
  5647. {
  5648. attributeFlag = 2;
  5649. tagValueType = TagValueType.None;
  5650. switch (unicode)
  5651. {
  5652. case 'e':
  5653. m_xmlAttribute[attributeIndex].unitType = tagUnitType = TagUnitType.FontUnits;
  5654. break;
  5655. case '%':
  5656. m_xmlAttribute[attributeIndex].unitType = tagUnitType = TagUnitType.Percentage;
  5657. break;
  5658. default:
  5659. m_xmlAttribute[attributeIndex].unitType = tagUnitType = TagUnitType.Pixels;
  5660. break;
  5661. }
  5662. attributeIndex += 1;
  5663. m_xmlAttribute[attributeIndex].nameHashCode = 0;
  5664. m_xmlAttribute[attributeIndex].valueHashCode = 0;
  5665. m_xmlAttribute[attributeIndex].valueType = TagValueType.None;
  5666. m_xmlAttribute[attributeIndex].unitType = TagUnitType.Pixels;
  5667. m_xmlAttribute[attributeIndex].valueStartIndex = 0;
  5668. m_xmlAttribute[attributeIndex].valueLength = 0;
  5669. }
  5670. else if (attributeFlag != 2)
  5671. {
  5672. m_xmlAttribute[attributeIndex].valueLength += 1;
  5673. }
  5674. }
  5675. else if (tagValueType == TagValueType.ColorValue)
  5676. {
  5677. if (unicode != ' ')
  5678. {
  5679. m_xmlAttribute[attributeIndex].valueLength += 1;
  5680. }
  5681. else
  5682. {
  5683. attributeFlag = 2;
  5684. tagValueType = TagValueType.None;
  5685. tagUnitType = TagUnitType.Pixels;
  5686. attributeIndex += 1;
  5687. m_xmlAttribute[attributeIndex].nameHashCode = 0;
  5688. m_xmlAttribute[attributeIndex].valueType = TagValueType.None;
  5689. m_xmlAttribute[attributeIndex].unitType = TagUnitType.Pixels;
  5690. m_xmlAttribute[attributeIndex].valueHashCode = 0;
  5691. m_xmlAttribute[attributeIndex].valueStartIndex = 0;
  5692. m_xmlAttribute[attributeIndex].valueLength = 0;
  5693. }
  5694. }
  5695. else if (tagValueType == TagValueType.StringValue)
  5696. {
  5697. // Compute HashCode value for the named tag.
  5698. if (unicode != '"')
  5699. {
  5700. m_xmlAttribute[attributeIndex].valueHashCode = (m_xmlAttribute[attributeIndex].valueHashCode << 5) + m_xmlAttribute[attributeIndex].valueHashCode ^ unicode;
  5701. m_xmlAttribute[attributeIndex].valueLength += 1;
  5702. }
  5703. else
  5704. {
  5705. attributeFlag = 2;
  5706. tagValueType = TagValueType.None;
  5707. tagUnitType = TagUnitType.Pixels;
  5708. attributeIndex += 1;
  5709. m_xmlAttribute[attributeIndex].nameHashCode = 0;
  5710. m_xmlAttribute[attributeIndex].valueType = TagValueType.None;
  5711. m_xmlAttribute[attributeIndex].unitType = TagUnitType.Pixels;
  5712. m_xmlAttribute[attributeIndex].valueHashCode = 0;
  5713. m_xmlAttribute[attributeIndex].valueStartIndex = 0;
  5714. m_xmlAttribute[attributeIndex].valueLength = 0;
  5715. }
  5716. }
  5717. }
  5718. }
  5719. if (unicode == '=') // '='
  5720. attributeFlag = 1;
  5721. // Compute HashCode for the name of the attribute
  5722. if (attributeFlag == 0 && unicode == ' ')
  5723. {
  5724. if (isTagSet) return false;
  5725. isTagSet = true;
  5726. attributeFlag = 2;
  5727. tagValueType = TagValueType.None;
  5728. tagUnitType = TagUnitType.Pixels;
  5729. attributeIndex += 1;
  5730. m_xmlAttribute[attributeIndex].nameHashCode = 0;
  5731. m_xmlAttribute[attributeIndex].valueType = TagValueType.None;
  5732. m_xmlAttribute[attributeIndex].unitType = TagUnitType.Pixels;
  5733. m_xmlAttribute[attributeIndex].valueHashCode = 0;
  5734. m_xmlAttribute[attributeIndex].valueStartIndex = 0;
  5735. m_xmlAttribute[attributeIndex].valueLength = 0;
  5736. }
  5737. if (attributeFlag == 0)
  5738. m_xmlAttribute[attributeIndex].nameHashCode = (m_xmlAttribute[attributeIndex].nameHashCode << 3) - m_xmlAttribute[attributeIndex].nameHashCode + unicode;
  5739. if (attributeFlag == 2 && unicode == ' ')
  5740. attributeFlag = 0;
  5741. }
  5742. if (!isValidHtmlTag)
  5743. {
  5744. return false;
  5745. }
  5746. //Debug.Log("Tag is [" + m_htmlTag.ArrayToString() + "]. Tag HashCode: " + m_xmlAttribute[0].nameHashCode + " Tag Value HashCode: " + m_xmlAttribute[0].valueHashCode + " Attribute 1 HashCode: " + m_xmlAttribute[1].nameHashCode + " Value HashCode: " + m_xmlAttribute[1].valueHashCode);
  5747. //for (int i = 0; i < attributeIndex; i++)
  5748. // Debug.Log("Tag [" + i + "] with HashCode: " + m_xmlAttribute[i].nameHashCode + " has value of [" + new string(m_htmlTag, m_xmlAttribute[i].valueStartIndex, m_xmlAttribute[i].valueLength) + "] Numerical Value: " + ConvertToFloat(m_htmlTag, m_xmlAttribute[i].valueStartIndex, m_xmlAttribute[i].valueLength));
  5749. #region Rich Text Tag Processing
  5750. #if !RICH_TEXT_ENABLED
  5751. // Special handling of the no parsing tag </noparse> </NOPARSE> tag
  5752. if (tag_NoParsing && (m_xmlAttribute[0].nameHashCode != 53822163 && m_xmlAttribute[0].nameHashCode != 49429939))
  5753. return false;
  5754. else if (m_xmlAttribute[0].nameHashCode == 53822163 || m_xmlAttribute[0].nameHashCode == 49429939)
  5755. {
  5756. tag_NoParsing = false;
  5757. return true;
  5758. }
  5759. // Color <#FFF> 3 Hex values (short form)
  5760. if (m_htmlTag[0] == 35 && tagCharCount == 4)
  5761. {
  5762. m_htmlColor = HexCharsToColor(m_htmlTag, tagCharCount);
  5763. m_colorStack.Add(m_htmlColor);
  5764. return true;
  5765. }
  5766. // Color <#FFF7> 4 Hex values with alpha (short form)
  5767. else if (m_htmlTag[0] == 35 && tagCharCount == 5)
  5768. {
  5769. m_htmlColor = HexCharsToColor(m_htmlTag, tagCharCount);
  5770. m_colorStack.Add(m_htmlColor);
  5771. return true;
  5772. }
  5773. // Color <#FF00FF>
  5774. else if (m_htmlTag[0] == 35 && tagCharCount == 7) // if Tag begins with # and contains 7 characters.
  5775. {
  5776. m_htmlColor = HexCharsToColor(m_htmlTag, tagCharCount);
  5777. m_colorStack.Add(m_htmlColor);
  5778. return true;
  5779. }
  5780. // Color <#FF00FF00> with alpha
  5781. else if (m_htmlTag[0] == 35 && tagCharCount == 9) // if Tag begins with # and contains 9 characters.
  5782. {
  5783. m_htmlColor = HexCharsToColor(m_htmlTag, tagCharCount);
  5784. m_colorStack.Add(m_htmlColor);
  5785. return true;
  5786. }
  5787. else
  5788. {
  5789. float value = 0;
  5790. float fontScale;
  5791. switch (m_xmlAttribute[0].nameHashCode)
  5792. {
  5793. case 98: // <b>
  5794. case 66: // <B>
  5795. m_FontStyleInternal |= FontStyles.Bold;
  5796. m_fontStyleStack.Add(FontStyles.Bold);
  5797. m_FontWeightInternal = FontWeight.Bold;
  5798. return true;
  5799. case 427: // </b>
  5800. case 395: // </B>
  5801. if ((m_fontStyle & FontStyles.Bold) != FontStyles.Bold)
  5802. {
  5803. if (m_fontStyleStack.Remove(FontStyles.Bold) == 0)
  5804. {
  5805. m_FontStyleInternal &= ~FontStyles.Bold;
  5806. m_FontWeightInternal = m_FontWeightStack.Peek();
  5807. }
  5808. }
  5809. return true;
  5810. case 105: // <i>
  5811. case 73: // <I>
  5812. m_FontStyleInternal |= FontStyles.Italic;
  5813. m_fontStyleStack.Add(FontStyles.Italic);
  5814. if (m_xmlAttribute[1].nameHashCode == 276531 || m_xmlAttribute[1].nameHashCode == 186899)
  5815. {
  5816. m_ItalicAngle = (int)ConvertToFloat(m_htmlTag, m_xmlAttribute[1].valueStartIndex, m_xmlAttribute[1].valueLength);
  5817. // Make sure angle is within valid range.
  5818. if (m_ItalicAngle < -180 || m_ItalicAngle > 180) return false;
  5819. }
  5820. else
  5821. m_ItalicAngle = m_currentFontAsset.italicStyle;
  5822. m_ItalicAngleStack.Add(m_ItalicAngle);
  5823. return true;
  5824. case 434: // </i>
  5825. case 402: // </I>
  5826. if ((m_fontStyle & FontStyles.Italic) != FontStyles.Italic)
  5827. {
  5828. m_ItalicAngle = m_ItalicAngleStack.Remove();
  5829. if (m_fontStyleStack.Remove(FontStyles.Italic) == 0)
  5830. m_FontStyleInternal &= ~FontStyles.Italic;
  5831. }
  5832. return true;
  5833. case 115: // <s>
  5834. case 83: // <S>
  5835. m_FontStyleInternal |= FontStyles.Strikethrough;
  5836. m_fontStyleStack.Add(FontStyles.Strikethrough);
  5837. if (m_xmlAttribute[1].nameHashCode == 281955 || m_xmlAttribute[1].nameHashCode == 192323)
  5838. {
  5839. m_strikethroughColor = HexCharsToColor(m_htmlTag, m_xmlAttribute[1].valueStartIndex, m_xmlAttribute[1].valueLength);
  5840. m_strikethroughColor.a = m_htmlColor.a < m_strikethroughColor.a ? (byte)(m_htmlColor.a) : (byte)(m_strikethroughColor .a);
  5841. }
  5842. else
  5843. m_strikethroughColor = m_htmlColor;
  5844. m_strikethroughColorStack.Add(m_strikethroughColor);
  5845. return true;
  5846. case 444: // </s>
  5847. case 412: // </S>
  5848. if ((m_fontStyle & FontStyles.Strikethrough) != FontStyles.Strikethrough)
  5849. {
  5850. if (m_fontStyleStack.Remove(FontStyles.Strikethrough) == 0)
  5851. m_FontStyleInternal &= ~FontStyles.Strikethrough;
  5852. }
  5853. m_strikethroughColor = m_strikethroughColorStack.Remove();
  5854. return true;
  5855. case 117: // <u>
  5856. case 85: // <U>
  5857. m_FontStyleInternal |= FontStyles.Underline;
  5858. m_fontStyleStack.Add(FontStyles.Underline);
  5859. if (m_xmlAttribute[1].nameHashCode == 281955 || m_xmlAttribute[1].nameHashCode == 192323)
  5860. {
  5861. m_underlineColor = HexCharsToColor(m_htmlTag, m_xmlAttribute[1].valueStartIndex, m_xmlAttribute[1].valueLength);
  5862. m_underlineColor.a = m_htmlColor.a < m_underlineColor.a ? (byte)(m_htmlColor.a) : (byte)(m_underlineColor.a);
  5863. }
  5864. else
  5865. m_underlineColor = m_htmlColor;
  5866. m_underlineColorStack.Add(m_underlineColor);
  5867. return true;
  5868. case 446: // </u>
  5869. case 414: // </U>
  5870. if ((m_fontStyle & FontStyles.Underline) != FontStyles.Underline)
  5871. {
  5872. m_underlineColor = m_underlineColorStack.Remove();
  5873. if (m_fontStyleStack.Remove(FontStyles.Underline) == 0)
  5874. m_FontStyleInternal &= ~FontStyles.Underline;
  5875. }
  5876. m_underlineColor = m_underlineColorStack.Remove();
  5877. return true;
  5878. case 43045: // <mark=#FF00FF80>
  5879. case 30245: // <MARK>
  5880. m_FontStyleInternal |= FontStyles.Highlight;
  5881. m_fontStyleStack.Add(FontStyles.Highlight);
  5882. Color32 highlightColor = new Color32(255, 255, 0, 64);
  5883. TMP_Offset highlightPadding = TMP_Offset.zero;
  5884. // Handle Mark Tag and potential attributes
  5885. for (int i = 0; i < m_xmlAttribute.Length && m_xmlAttribute[i].nameHashCode != 0; i++)
  5886. {
  5887. int nameHashCode = m_xmlAttribute[i].nameHashCode;
  5888. switch (nameHashCode)
  5889. {
  5890. // Mark tag
  5891. case 43045:
  5892. case 30245:
  5893. if (m_xmlAttribute[i].valueType == TagValueType.ColorValue)
  5894. highlightColor = HexCharsToColor(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength);
  5895. break;
  5896. // Color attribute
  5897. case 281955:
  5898. highlightColor = HexCharsToColor(m_htmlTag, m_xmlAttribute[i].valueStartIndex, m_xmlAttribute[i].valueLength);
  5899. break;
  5900. // Padding attribute
  5901. case 15087385:
  5902. int paramCount = GetAttributeParameters(m_htmlTag, m_xmlAttribute[i].valueStartIndex, m_xmlAttribute[i].valueLength, ref m_attributeParameterValues);
  5903. if (paramCount != 4) return false;
  5904. highlightPadding = new TMP_Offset(m_attributeParameterValues[0], m_attributeParameterValues[1], m_attributeParameterValues[2], m_attributeParameterValues[3]);
  5905. highlightPadding *= m_fontSize * 0.01f * (m_isOrthographic ? 1 : 0.1f);
  5906. break;
  5907. }
  5908. }
  5909. highlightColor.a = m_htmlColor.a < highlightColor.a ? (byte)(m_htmlColor.a) : (byte)(highlightColor.a);
  5910. HighlightState state = new HighlightState(highlightColor, highlightPadding);
  5911. m_HighlightStateStack.Push(state);
  5912. return true;
  5913. case 155892: // </mark>
  5914. case 143092: // </MARK>
  5915. if ((m_fontStyle & FontStyles.Highlight) != FontStyles.Highlight)
  5916. {
  5917. m_HighlightStateStack.Remove();
  5918. if (m_fontStyleStack.Remove(FontStyles.Highlight) == 0)
  5919. m_FontStyleInternal &= ~FontStyles.Highlight;
  5920. }
  5921. return true;
  5922. case 6552: // <sub>
  5923. case 4728: // <SUB>
  5924. m_fontScaleMultiplier *= m_currentFontAsset.faceInfo.subscriptSize > 0 ? m_currentFontAsset.faceInfo.subscriptSize : 1;
  5925. m_baselineOffsetStack.Push(m_baselineOffset);
  5926. fontScale = (m_currentFontSize / m_currentFontAsset.faceInfo.pointSize * m_currentFontAsset.faceInfo.scale * (m_isOrthographic ? 1 : 0.1f));
  5927. m_baselineOffset += m_currentFontAsset.faceInfo.subscriptOffset * fontScale * m_fontScaleMultiplier;
  5928. m_fontStyleStack.Add(FontStyles.Subscript);
  5929. m_FontStyleInternal |= FontStyles.Subscript;
  5930. return true;
  5931. case 22673: // </sub>
  5932. case 20849: // </SUB>
  5933. if ((m_FontStyleInternal & FontStyles.Subscript) == FontStyles.Subscript)
  5934. {
  5935. if (m_fontScaleMultiplier < 1)
  5936. {
  5937. m_baselineOffset = m_baselineOffsetStack.Pop();
  5938. m_fontScaleMultiplier /= m_currentFontAsset.faceInfo.subscriptSize > 0 ? m_currentFontAsset.faceInfo.subscriptSize : 1;
  5939. }
  5940. if (m_fontStyleStack.Remove(FontStyles.Subscript) == 0)
  5941. m_FontStyleInternal &= ~FontStyles.Subscript;
  5942. }
  5943. return true;
  5944. case 6566: // <sup>
  5945. case 4742: // <SUP>
  5946. m_fontScaleMultiplier *= m_currentFontAsset.faceInfo.superscriptSize > 0 ? m_currentFontAsset.faceInfo.superscriptSize : 1;
  5947. m_baselineOffsetStack.Push(m_baselineOffset);
  5948. fontScale = (m_currentFontSize / m_currentFontAsset.faceInfo.pointSize * m_currentFontAsset.faceInfo.scale * (m_isOrthographic ? 1 : 0.1f));
  5949. m_baselineOffset += m_currentFontAsset.faceInfo.superscriptOffset * fontScale * m_fontScaleMultiplier;
  5950. m_fontStyleStack.Add(FontStyles.Superscript);
  5951. m_FontStyleInternal |= FontStyles.Superscript;
  5952. return true;
  5953. case 22687: // </sup>
  5954. case 20863: // </SUP>
  5955. if ((m_FontStyleInternal & FontStyles.Superscript) == FontStyles.Superscript)
  5956. {
  5957. if (m_fontScaleMultiplier < 1)
  5958. {
  5959. m_baselineOffset = m_baselineOffsetStack.Pop();
  5960. m_fontScaleMultiplier /= m_currentFontAsset.faceInfo.superscriptSize > 0 ? m_currentFontAsset.faceInfo.superscriptSize : 1;
  5961. }
  5962. if (m_fontStyleStack.Remove(FontStyles.Superscript) == 0)
  5963. m_FontStyleInternal &= ~FontStyles.Superscript;
  5964. }
  5965. return true;
  5966. case -330774850: // <font-weight>
  5967. case 2012149182: // <FONT-WEIGHT>
  5968. value = ConvertToFloat(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength);
  5969. // Reject tag if value is invalid.
  5970. if (value == Int16.MinValue) return false;
  5971. switch ((int)value)
  5972. {
  5973. case 100:
  5974. m_FontWeightInternal = FontWeight.Thin;
  5975. break;
  5976. case 200:
  5977. m_FontWeightInternal = FontWeight.ExtraLight;
  5978. break;
  5979. case 300:
  5980. m_FontWeightInternal = FontWeight.Light;
  5981. break;
  5982. case 400:
  5983. m_FontWeightInternal = FontWeight.Regular;
  5984. break;
  5985. case 500:
  5986. m_FontWeightInternal = FontWeight.Medium;
  5987. break;
  5988. case 600:
  5989. m_FontWeightInternal = FontWeight.SemiBold;
  5990. break;
  5991. case 700:
  5992. m_FontWeightInternal = FontWeight.Bold;
  5993. break;
  5994. case 800:
  5995. m_FontWeightInternal = FontWeight.Heavy;
  5996. break;
  5997. case 900:
  5998. m_FontWeightInternal = FontWeight.Black;
  5999. break;
  6000. }
  6001. m_FontWeightStack.Add(m_FontWeightInternal);
  6002. return true;
  6003. case -1885698441: // </font-weight>
  6004. case 457225591: // </FONT-WEIGHT>
  6005. m_FontWeightStack.Remove();
  6006. if (m_FontStyleInternal == FontStyles.Bold)
  6007. m_FontWeightInternal = FontWeight.Bold;
  6008. else
  6009. m_FontWeightInternal = m_FontWeightStack.Peek();
  6010. return true;
  6011. case 6380: // <pos=000.00px> <pos=0em> <pos=50%>
  6012. case 4556: // <POS>
  6013. value = ConvertToFloat(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength);
  6014. // Reject tag if value is invalid.
  6015. if (value == Int16.MinValue) return false;
  6016. switch (tagUnitType)
  6017. {
  6018. case TagUnitType.Pixels:
  6019. m_xAdvance = value * (m_isOrthographic ? 1.0f : 0.1f);
  6020. //m_isIgnoringAlignment = true;
  6021. return true;
  6022. case TagUnitType.FontUnits:
  6023. m_xAdvance = value * m_currentFontSize * (m_isOrthographic ? 1.0f : 0.1f);
  6024. //m_isIgnoringAlignment = true;
  6025. return true;
  6026. case TagUnitType.Percentage:
  6027. m_xAdvance = m_marginWidth * value / 100;
  6028. //m_isIgnoringAlignment = true;
  6029. return true;
  6030. }
  6031. return false;
  6032. case 22501: // </pos>
  6033. case 20677: // </POS>
  6034. m_isIgnoringAlignment = false;
  6035. return true;
  6036. case 16034505: // <voffset>
  6037. case 11642281: // <VOFFSET>
  6038. value = ConvertToFloat(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength);
  6039. // Reject tag if value is invalid.
  6040. if (value == Int16.MinValue) return false;
  6041. switch (tagUnitType)
  6042. {
  6043. case TagUnitType.Pixels:
  6044. m_baselineOffset = value * (m_isOrthographic ? 1 : 0.1f);
  6045. return true;
  6046. case TagUnitType.FontUnits:
  6047. m_baselineOffset = value * (m_isOrthographic ? 1 : 0.1f) * m_currentFontSize;
  6048. return true;
  6049. case TagUnitType.Percentage:
  6050. //m_baselineOffset = m_marginHeight * val / 100;
  6051. return false;
  6052. }
  6053. return false;
  6054. case 54741026: // </voffset>
  6055. case 50348802: // </VOFFSET>
  6056. m_baselineOffset = 0;
  6057. return true;
  6058. case 43991: // <page>
  6059. case 31191: // <PAGE>
  6060. // This tag only works when Overflow - Page mode is used.
  6061. if (m_overflowMode == TextOverflowModes.Page)
  6062. {
  6063. m_xAdvance = 0 + tag_LineIndent + tag_Indent;
  6064. m_lineOffset = 0;
  6065. m_pageNumber += 1;
  6066. m_isNewPage = true;
  6067. }
  6068. return true;
  6069. // <BR> tag is now handled inline where it is replaced by a linefeed or \n.
  6070. //case 544: // <BR>
  6071. //case 800: // <br>
  6072. // m_forceLineBreak = true;
  6073. // return true;
  6074. case 43969: // <nobr>
  6075. case 31169: // <NOBR>
  6076. m_isNonBreakingSpace = true;
  6077. return true;
  6078. case 156816: // </nobr>
  6079. case 144016: // </NOBR>
  6080. m_isNonBreakingSpace = false;
  6081. return true;
  6082. case 45545: // <size=>
  6083. case 32745: // <SIZE>
  6084. value = ConvertToFloat(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength);
  6085. // Reject tag if value is invalid.
  6086. if (value == Int16.MinValue) return false;
  6087. switch (tagUnitType)
  6088. {
  6089. case TagUnitType.Pixels:
  6090. if (m_htmlTag[5] == 43) // <size=+00>
  6091. {
  6092. m_currentFontSize = m_fontSize + value;
  6093. m_sizeStack.Add(m_currentFontSize);
  6094. return true;
  6095. }
  6096. else if (m_htmlTag[5] == 45) // <size=-00>
  6097. {
  6098. m_currentFontSize = m_fontSize + value;
  6099. m_sizeStack.Add(m_currentFontSize);
  6100. return true;
  6101. }
  6102. else // <size=00.0>
  6103. {
  6104. m_currentFontSize = value;
  6105. m_sizeStack.Add(m_currentFontSize);
  6106. return true;
  6107. }
  6108. case TagUnitType.FontUnits:
  6109. m_currentFontSize = m_fontSize * value;
  6110. m_sizeStack.Add(m_currentFontSize);
  6111. return true;
  6112. case TagUnitType.Percentage:
  6113. m_currentFontSize = m_fontSize * value / 100;
  6114. m_sizeStack.Add(m_currentFontSize);
  6115. return true;
  6116. }
  6117. return false;
  6118. case 158392: // </size>
  6119. case 145592: // </SIZE>
  6120. m_currentFontSize = m_sizeStack.Remove();
  6121. return true;
  6122. case 41311: // <font=xx>
  6123. case 28511: // <FONT>
  6124. int fontHashCode = m_xmlAttribute[0].valueHashCode;
  6125. int materialAttributeHashCode = m_xmlAttribute[1].nameHashCode;
  6126. int materialHashCode = m_xmlAttribute[1].valueHashCode;
  6127. // Special handling for <font=default> or <font=Default>
  6128. if (fontHashCode == 764638571 || fontHashCode == 523367755)
  6129. {
  6130. m_currentFontAsset = m_materialReferences[0].fontAsset;
  6131. m_currentMaterial = m_materialReferences[0].material;
  6132. m_currentMaterialIndex = 0;
  6133. //Debug.Log("<font=Default> assigning Font Asset [" + m_currentFontAsset.name + "] with Material [" + m_currentMaterial.name + "].");
  6134. m_materialReferenceStack.Add(m_materialReferences[0]);
  6135. return true;
  6136. }
  6137. TMP_FontAsset tempFont;
  6138. Material tempMaterial;
  6139. // HANDLE NEW FONT ASSET
  6140. //TMP_ResourceManager.TryGetFontAsset(fontHashCode, out tempFont);
  6141. // Check if we already have a reference to this font asset.
  6142. MaterialReferenceManager.TryGetFontAsset(fontHashCode, out tempFont);
  6143. // Try loading font asset from potential delegate or resources.
  6144. if (tempFont == null)
  6145. {
  6146. // Check for anyone registered to this callback
  6147. tempFont = OnFontAssetRequest?.Invoke(fontHashCode, new string(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength));
  6148. if (tempFont == null)
  6149. {
  6150. // Load Font Asset
  6151. tempFont = Resources.Load<TMP_FontAsset>(TMP_Settings.defaultFontAssetPath + new string(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength));
  6152. }
  6153. if (tempFont == null)
  6154. return false;
  6155. // Add new reference to the font asset as well as default material to the MaterialReferenceManager
  6156. MaterialReferenceManager.AddFontAsset(tempFont);
  6157. }
  6158. // HANDLE NEW MATERIAL
  6159. if (materialAttributeHashCode == 0 && materialHashCode == 0)
  6160. {
  6161. // No material specified then use default font asset material.
  6162. m_currentMaterial = tempFont.material;
  6163. m_currentMaterialIndex = MaterialReference.AddMaterialReference(m_currentMaterial, tempFont, ref m_materialReferences, m_materialReferenceIndexLookup);
  6164. m_materialReferenceStack.Add(m_materialReferences[m_currentMaterialIndex]);
  6165. }
  6166. else if (materialAttributeHashCode == 103415287 || materialAttributeHashCode == 72669687) // using material attribute
  6167. {
  6168. if (MaterialReferenceManager.TryGetMaterial(materialHashCode, out tempMaterial))
  6169. {
  6170. m_currentMaterial = tempMaterial;
  6171. m_currentMaterialIndex = MaterialReference.AddMaterialReference(m_currentMaterial, tempFont, ref m_materialReferences, m_materialReferenceIndexLookup);
  6172. m_materialReferenceStack.Add(m_materialReferences[m_currentMaterialIndex]);
  6173. }
  6174. else
  6175. {
  6176. // Load new material
  6177. tempMaterial = Resources.Load<Material>(TMP_Settings.defaultFontAssetPath + new string(m_htmlTag, m_xmlAttribute[1].valueStartIndex, m_xmlAttribute[1].valueLength));
  6178. if (tempMaterial == null)
  6179. return false;
  6180. // Add new reference to this material in the MaterialReferenceManager
  6181. MaterialReferenceManager.AddFontMaterial(materialHashCode, tempMaterial);
  6182. m_currentMaterial = tempMaterial;
  6183. m_currentMaterialIndex = MaterialReference.AddMaterialReference(m_currentMaterial, tempFont, ref m_materialReferences, m_materialReferenceIndexLookup);
  6184. m_materialReferenceStack.Add(m_materialReferences[m_currentMaterialIndex]);
  6185. }
  6186. }
  6187. else
  6188. return false;
  6189. m_currentFontAsset = tempFont;
  6190. return true;
  6191. case 154158: // </font>
  6192. case 141358: // </FONT>
  6193. {
  6194. MaterialReference materialReference = m_materialReferenceStack.Remove();
  6195. m_currentFontAsset = materialReference.fontAsset;
  6196. m_currentMaterial = materialReference.material;
  6197. m_currentMaterialIndex = materialReference.index;
  6198. return true;
  6199. }
  6200. case 103415287: // <material="material name">
  6201. case 72669687: // <MATERIAL>
  6202. materialHashCode = m_xmlAttribute[0].valueHashCode;
  6203. // Special handling for <material=default> or <material=Default>
  6204. if (materialHashCode == 764638571 || materialHashCode == 523367755)
  6205. {
  6206. // Check if material font atlas texture matches that of the current font asset.
  6207. //if (m_currentFontAsset.atlas.GetInstanceID() != m_currentMaterial.GetTexture(ShaderUtilities.ID_MainTex).GetInstanceID()) return false;
  6208. m_currentMaterial = m_materialReferences[0].material;
  6209. m_currentMaterialIndex = 0;
  6210. m_materialReferenceStack.Add(m_materialReferences[0]);
  6211. return true;
  6212. }
  6213. // Check if material
  6214. if (MaterialReferenceManager.TryGetMaterial(materialHashCode, out tempMaterial))
  6215. {
  6216. // Check if material font atlas texture matches that of the current font asset.
  6217. //if (m_currentFontAsset.atlas.GetInstanceID() != tempMaterial.GetTexture(ShaderUtilities.ID_MainTex).GetInstanceID()) return false;
  6218. m_currentMaterial = tempMaterial;
  6219. m_currentMaterialIndex = MaterialReference.AddMaterialReference(m_currentMaterial, m_currentFontAsset, ref m_materialReferences, m_materialReferenceIndexLookup);
  6220. m_materialReferenceStack.Add(m_materialReferences[m_currentMaterialIndex]);
  6221. }
  6222. else
  6223. {
  6224. // Load new material
  6225. tempMaterial = Resources.Load<Material>(TMP_Settings.defaultFontAssetPath + new string(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength));
  6226. if (tempMaterial == null)
  6227. return false;
  6228. // Check if material font atlas texture matches that of the current font asset.
  6229. //if (m_currentFontAsset.atlas.GetInstanceID() != tempMaterial.GetTexture(ShaderUtilities.ID_MainTex).GetInstanceID()) return false;
  6230. // Add new reference to this material in the MaterialReferenceManager
  6231. MaterialReferenceManager.AddFontMaterial(materialHashCode, tempMaterial);
  6232. m_currentMaterial = tempMaterial;
  6233. m_currentMaterialIndex = MaterialReference.AddMaterialReference(m_currentMaterial, m_currentFontAsset, ref m_materialReferences, m_materialReferenceIndexLookup);
  6234. m_materialReferenceStack.Add(m_materialReferences[m_currentMaterialIndex]);
  6235. }
  6236. return true;
  6237. case 374360934: // </material>
  6238. case 343615334: // </MATERIAL>
  6239. {
  6240. //if (m_currentMaterial.GetTexture(ShaderUtilities.ID_MainTex).GetInstanceID() != m_materialReferenceStack.PreviousItem().material.GetTexture(ShaderUtilities.ID_MainTex).GetInstanceID())
  6241. // return false;
  6242. MaterialReference materialReference = m_materialReferenceStack.Remove();
  6243. m_currentMaterial = materialReference.material;
  6244. m_currentMaterialIndex = materialReference.index;
  6245. return true;
  6246. }
  6247. case 320078: // <space=000.00>
  6248. case 230446: // <SPACE>
  6249. value = ConvertToFloat(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength);
  6250. // Reject tag if value is invalid.
  6251. if (value == Int16.MinValue) return false;
  6252. switch (tagUnitType)
  6253. {
  6254. case TagUnitType.Pixels:
  6255. m_xAdvance += value * (m_isOrthographic ? 1 : 0.1f);
  6256. return true;
  6257. case TagUnitType.FontUnits:
  6258. m_xAdvance += value * (m_isOrthographic ? 1 : 0.1f) * m_currentFontSize;
  6259. return true;
  6260. case TagUnitType.Percentage:
  6261. // Not applicable
  6262. return false;
  6263. }
  6264. return false;
  6265. case 276254: // <alpha=#FF>
  6266. case 186622: // <ALPHA>
  6267. if (m_xmlAttribute[0].valueLength != 3) return false;
  6268. m_htmlColor.a = (byte)(HexToInt(m_htmlTag[7]) * 16 + HexToInt(m_htmlTag[8]));
  6269. return true;
  6270. case 1750458: // <a name=" ">
  6271. return false;
  6272. case 426: // </a>
  6273. return true;
  6274. case 43066: // <link="name">
  6275. case 30266: // <LINK>
  6276. if (m_isParsingText && !m_isCalculatingPreferredValues)
  6277. {
  6278. int index = m_textInfo.linkCount;
  6279. if (index + 1 > m_textInfo.linkInfo.Length)
  6280. TMP_TextInfo.Resize(ref m_textInfo.linkInfo, index + 1);
  6281. m_textInfo.linkInfo[index].textComponent = this;
  6282. m_textInfo.linkInfo[index].hashCode = m_xmlAttribute[0].valueHashCode;
  6283. m_textInfo.linkInfo[index].linkTextfirstCharacterIndex = m_characterCount;
  6284. m_textInfo.linkInfo[index].linkIdFirstCharacterIndex = startIndex + m_xmlAttribute[0].valueStartIndex;
  6285. m_textInfo.linkInfo[index].linkIdLength = m_xmlAttribute[0].valueLength;
  6286. m_textInfo.linkInfo[index].SetLinkID(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength);
  6287. }
  6288. return true;
  6289. case 155913: // </link>
  6290. case 143113: // </LINK>
  6291. if (m_isParsingText && !m_isCalculatingPreferredValues)
  6292. {
  6293. if (m_textInfo.linkCount < m_textInfo.linkInfo.Length)
  6294. {
  6295. m_textInfo.linkInfo[m_textInfo.linkCount].linkTextLength = m_characterCount - m_textInfo.linkInfo[m_textInfo.linkCount].linkTextfirstCharacterIndex;
  6296. m_textInfo.linkCount += 1;
  6297. }
  6298. }
  6299. return true;
  6300. case 275917: // <align=>
  6301. case 186285: // <ALIGN>
  6302. switch (m_xmlAttribute[0].valueHashCode)
  6303. {
  6304. case 3774683: // <align=left>
  6305. m_lineJustification = HorizontalAlignmentOptions.Left;
  6306. m_lineJustificationStack.Add(m_lineJustification);
  6307. return true;
  6308. case 136703040: // <align=right>
  6309. m_lineJustification = HorizontalAlignmentOptions.Right;
  6310. m_lineJustificationStack.Add(m_lineJustification);
  6311. return true;
  6312. case -458210101: // <align=center>
  6313. m_lineJustification = HorizontalAlignmentOptions.Center;
  6314. m_lineJustificationStack.Add(m_lineJustification);
  6315. return true;
  6316. case -523808257: // <align=justified>
  6317. m_lineJustification = HorizontalAlignmentOptions.Justified;
  6318. m_lineJustificationStack.Add(m_lineJustification);
  6319. return true;
  6320. case 122383428: // <align=flush>
  6321. m_lineJustification = HorizontalAlignmentOptions.Flush;
  6322. m_lineJustificationStack.Add(m_lineJustification);
  6323. return true;
  6324. }
  6325. return false;
  6326. case 1065846: // </align>
  6327. case 976214: // </ALIGN>
  6328. m_lineJustification = m_lineJustificationStack.Remove();
  6329. return true;
  6330. case 327550: // <width=xx>
  6331. case 237918: // <WIDTH>
  6332. value = ConvertToFloat(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength);
  6333. // Reject tag if value is invalid.
  6334. if (value == Int16.MinValue) return false;
  6335. switch (tagUnitType)
  6336. {
  6337. case TagUnitType.Pixels:
  6338. m_width = value * (m_isOrthographic ? 1 : 0.1f);
  6339. break;
  6340. case TagUnitType.FontUnits:
  6341. return false;
  6342. //break;
  6343. case TagUnitType.Percentage:
  6344. m_width = m_marginWidth * value / 100;
  6345. break;
  6346. }
  6347. return true;
  6348. case 1117479: // </width>
  6349. case 1027847: // </WIDTH>
  6350. m_width = -1;
  6351. return true;
  6352. // STYLE tag is now handled inline and replaced by its definition.
  6353. //case 322689: // <style="name">
  6354. //case 233057: // <STYLE>
  6355. // TMP_Style style = TMP_StyleSheet.GetStyle(m_xmlAttribute[0].valueHashCode);
  6356. // if (style == null) return false;
  6357. // m_styleStack.Add(style.hashCode);
  6358. // // Parse Style Macro
  6359. // for (int i = 0; i < style.styleOpeningTagArray.Length; i++)
  6360. // {
  6361. // if (style.styleOpeningTagArray[i] == 60)
  6362. // {
  6363. // if (ValidateHtmlTag(style.styleOpeningTagArray, i + 1, out i) == false) return false;
  6364. // }
  6365. // }
  6366. // return true;
  6367. //case 1112618: // </style>
  6368. //case 1022986: // </STYLE>
  6369. // style = TMP_StyleSheet.GetStyle(m_xmlAttribute[0].valueHashCode);
  6370. // if (style == null)
  6371. // {
  6372. // // Get style from the Style Stack
  6373. // int styleHashCode = m_styleStack.CurrentItem();
  6374. // style = TMP_StyleSheet.GetStyle(styleHashCode);
  6375. // m_styleStack.Remove();
  6376. // }
  6377. // if (style == null) return false;
  6378. // //// Parse Style Macro
  6379. // for (int i = 0; i < style.styleClosingTagArray.Length; i++)
  6380. // {
  6381. // if (style.styleClosingTagArray[i] == 60)
  6382. // ValidateHtmlTag(style.styleClosingTagArray, i + 1, out i);
  6383. // }
  6384. // return true;
  6385. case 281955: // <color> <color=#FF00FF> or <color=#FF00FF00>
  6386. case 192323: // <COLOR=#FF00FF>
  6387. // <color=#FFF> 3 Hex (short hand)
  6388. if (m_htmlTag[6] == 35 && tagCharCount == 10)
  6389. {
  6390. m_htmlColor = HexCharsToColor(m_htmlTag, tagCharCount);
  6391. m_colorStack.Add(m_htmlColor);
  6392. return true;
  6393. }
  6394. // <color=#FFF7> 4 Hex (short hand)
  6395. else if (m_htmlTag[6] == 35 && tagCharCount == 11)
  6396. {
  6397. m_htmlColor = HexCharsToColor(m_htmlTag, tagCharCount);
  6398. m_colorStack.Add(m_htmlColor);
  6399. return true;
  6400. }
  6401. // <color=#FF00FF> 3 Hex pairs
  6402. if (m_htmlTag[6] == 35 && tagCharCount == 13)
  6403. {
  6404. m_htmlColor = HexCharsToColor(m_htmlTag, tagCharCount);
  6405. m_colorStack.Add(m_htmlColor);
  6406. return true;
  6407. }
  6408. // <color=#FF00FF00> 4 Hex pairs
  6409. else if (m_htmlTag[6] == 35 && tagCharCount == 15)
  6410. {
  6411. m_htmlColor = HexCharsToColor(m_htmlTag, tagCharCount);
  6412. m_colorStack.Add(m_htmlColor);
  6413. return true;
  6414. }
  6415. // <color=name>
  6416. switch (m_xmlAttribute[0].valueHashCode)
  6417. {
  6418. case 125395: // <color=red>
  6419. m_htmlColor = Color.red;
  6420. m_colorStack.Add(m_htmlColor);
  6421. return true;
  6422. case -992792864: // <color=lightblue>
  6423. m_htmlColor = new Color32(173, 216, 230, 255);
  6424. m_colorStack.Add(m_htmlColor);
  6425. return true;
  6426. case 3573310: // <color=blue>
  6427. m_htmlColor = Color.blue;
  6428. m_colorStack.Add(m_htmlColor);
  6429. return true;
  6430. case 3680713: // <color=grey>
  6431. m_htmlColor = new Color32(128, 128, 128, 255);
  6432. m_colorStack.Add(m_htmlColor);
  6433. return true;
  6434. case 117905991: // <color=black>
  6435. m_htmlColor = Color.black;
  6436. m_colorStack.Add(m_htmlColor);
  6437. return true;
  6438. case 121463835: // <color=green>
  6439. m_htmlColor = Color.green;
  6440. m_colorStack.Add(m_htmlColor);
  6441. return true;
  6442. case 140357351: // <color=white>
  6443. m_htmlColor = Color.white;
  6444. m_colorStack.Add(m_htmlColor);
  6445. return true;
  6446. case 26556144: // <color=orange>
  6447. m_htmlColor = new Color32(255, 128, 0, 255);
  6448. m_colorStack.Add(m_htmlColor);
  6449. return true;
  6450. case -36881330: // <color=purple>
  6451. m_htmlColor = new Color32(160, 32, 240, 255);
  6452. m_colorStack.Add(m_htmlColor);
  6453. return true;
  6454. case 554054276: // <color=yellow>
  6455. m_htmlColor = Color.yellow;
  6456. m_colorStack.Add(m_htmlColor);
  6457. return true;
  6458. }
  6459. return false;
  6460. case 100149144: //<gradient>
  6461. case 69403544: // <GRADIENT>
  6462. int gradientPresetHashCode = m_xmlAttribute[0].valueHashCode;
  6463. TMP_ColorGradient tempColorGradientPreset;
  6464. // Check if Color Gradient Preset has already been loaded.
  6465. if (MaterialReferenceManager.TryGetColorGradientPreset(gradientPresetHashCode, out tempColorGradientPreset))
  6466. {
  6467. m_colorGradientPreset = tempColorGradientPreset;
  6468. }
  6469. else
  6470. {
  6471. // Load Color Gradient Preset
  6472. if (tempColorGradientPreset == null)
  6473. {
  6474. tempColorGradientPreset = Resources.Load<TMP_ColorGradient>(TMP_Settings.defaultColorGradientPresetsPath + new string(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength));
  6475. }
  6476. if (tempColorGradientPreset == null)
  6477. return false;
  6478. MaterialReferenceManager.AddColorGradientPreset(gradientPresetHashCode, tempColorGradientPreset);
  6479. m_colorGradientPreset = tempColorGradientPreset;
  6480. }
  6481. m_colorGradientPresetIsTinted = false;
  6482. // Check Attributes
  6483. for (int i = 1; i < m_xmlAttribute.Length && m_xmlAttribute[i].nameHashCode != 0; i++)
  6484. {
  6485. // Get attribute name
  6486. int nameHashCode = m_xmlAttribute[i].nameHashCode;
  6487. switch (nameHashCode)
  6488. {
  6489. case 45819: // tint
  6490. case 33019: // TINT
  6491. m_colorGradientPresetIsTinted = ConvertToFloat(m_htmlTag, m_xmlAttribute[i].valueStartIndex, m_xmlAttribute[i].valueLength) != 0;
  6492. break;
  6493. }
  6494. }
  6495. m_colorGradientStack.Add(m_colorGradientPreset);
  6496. // TODO : Add support for defining preset in the tag itself
  6497. return true;
  6498. case 371094791: // </gradient>
  6499. case 340349191: // </GRADIENT>
  6500. m_colorGradientPreset = m_colorGradientStack.Remove();
  6501. return true;
  6502. case 1983971: // <cspace=xx.x>
  6503. case 1356515: // <CSPACE>
  6504. value = ConvertToFloat(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength);
  6505. // Reject tag if value is invalid.
  6506. if (value == Int16.MinValue) return false;
  6507. switch (tagUnitType)
  6508. {
  6509. case TagUnitType.Pixels:
  6510. m_cSpacing = value * (m_isOrthographic ? 1 : 0.1f);
  6511. break;
  6512. case TagUnitType.FontUnits:
  6513. m_cSpacing = value * (m_isOrthographic ? 1 : 0.1f) * m_currentFontSize;
  6514. break;
  6515. case TagUnitType.Percentage:
  6516. return false;
  6517. }
  6518. return true;
  6519. case 7513474: // </cspace>
  6520. case 6886018: // </CSPACE>
  6521. if (!m_isParsingText) return true;
  6522. // Adjust xAdvance to remove extra space from last character.
  6523. if (m_characterCount > 0)
  6524. {
  6525. m_xAdvance -= m_cSpacing;
  6526. m_textInfo.characterInfo[m_characterCount - 1].xAdvance = m_xAdvance;
  6527. }
  6528. m_cSpacing = 0;
  6529. return true;
  6530. case 2152041: // <mspace=xx.x>
  6531. case 1524585: // <MSPACE>
  6532. value = ConvertToFloat(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength);
  6533. // Reject tag if value is invalid.
  6534. if (value == Int16.MinValue) return false;
  6535. switch (tagUnitType)
  6536. {
  6537. case TagUnitType.Pixels:
  6538. m_monoSpacing = value * (m_isOrthographic ? 1 : 0.1f);
  6539. break;
  6540. case TagUnitType.FontUnits:
  6541. m_monoSpacing = value * (m_isOrthographic ? 1 : 0.1f) * m_currentFontSize;
  6542. break;
  6543. case TagUnitType.Percentage:
  6544. return false;
  6545. }
  6546. return true;
  6547. case 7681544: // </mspace>
  6548. case 7054088: // </MSPACE>
  6549. m_monoSpacing = 0;
  6550. return true;
  6551. case 280416: // <class="name">
  6552. return false;
  6553. case 1071884: // </color>
  6554. case 982252: // </COLOR>
  6555. m_htmlColor = m_colorStack.Remove();
  6556. return true;
  6557. case 2068980: // <indent=10px> <indent=10em> <indent=50%>
  6558. case 1441524: // <INDENT>
  6559. value = ConvertToFloat(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength);
  6560. // Reject tag if value is invalid.
  6561. if (value == Int16.MinValue) return false;
  6562. switch (tagUnitType)
  6563. {
  6564. case TagUnitType.Pixels:
  6565. tag_Indent = value * (m_isOrthographic ? 1 : 0.1f);
  6566. break;
  6567. case TagUnitType.FontUnits:
  6568. tag_Indent = value * (m_isOrthographic ? 1 : 0.1f) * m_currentFontSize;
  6569. break;
  6570. case TagUnitType.Percentage:
  6571. tag_Indent = m_marginWidth * value / 100;
  6572. break;
  6573. }
  6574. m_indentStack.Add(tag_Indent);
  6575. m_xAdvance = tag_Indent;
  6576. return true;
  6577. case 7598483: // </indent>
  6578. case 6971027: // </INDENT>
  6579. tag_Indent = m_indentStack.Remove();
  6580. //m_xAdvance = tag_Indent;
  6581. return true;
  6582. case 1109386397: // <line-indent>
  6583. case -842656867: // <LINE-INDENT>
  6584. value = ConvertToFloat(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength);
  6585. // Reject tag if value is invalid.
  6586. if (value == Int16.MinValue) return false;
  6587. switch (tagUnitType)
  6588. {
  6589. case TagUnitType.Pixels:
  6590. tag_LineIndent = value * (m_isOrthographic ? 1 : 0.1f);
  6591. break;
  6592. case TagUnitType.FontUnits:
  6593. tag_LineIndent = value * (m_isOrthographic ? 1 : 0.1f) * m_currentFontSize;
  6594. break;
  6595. case TagUnitType.Percentage:
  6596. tag_LineIndent = m_marginWidth * value / 100;
  6597. break;
  6598. }
  6599. m_xAdvance += tag_LineIndent;
  6600. return true;
  6601. case -445537194: // </line-indent>
  6602. case 1897386838: // </LINE-INDENT>
  6603. tag_LineIndent = 0;
  6604. return true;
  6605. case 2246877: // <sprite=x>
  6606. case 1619421: // <SPRITE>
  6607. int spriteAssetHashCode = m_xmlAttribute[0].valueHashCode;
  6608. TMP_SpriteAsset tempSpriteAsset;
  6609. m_spriteIndex = -1;
  6610. // CHECK TAG FORMAT
  6611. if (m_xmlAttribute[0].valueType == TagValueType.None || m_xmlAttribute[0].valueType == TagValueType.NumericalValue)
  6612. {
  6613. // No Sprite Asset is assigned to the text object
  6614. if (m_spriteAsset != null)
  6615. {
  6616. m_currentSpriteAsset = m_spriteAsset;
  6617. }
  6618. else if (m_defaultSpriteAsset != null)
  6619. {
  6620. m_currentSpriteAsset = m_defaultSpriteAsset;
  6621. }
  6622. else if (m_defaultSpriteAsset == null)
  6623. {
  6624. if (TMP_Settings.defaultSpriteAsset != null)
  6625. m_defaultSpriteAsset = TMP_Settings.defaultSpriteAsset;
  6626. else
  6627. m_defaultSpriteAsset = Resources.Load<TMP_SpriteAsset>("Sprite Assets/Default Sprite Asset");
  6628. m_currentSpriteAsset = m_defaultSpriteAsset;
  6629. }
  6630. // No valid sprite asset available
  6631. if (m_currentSpriteAsset == null)
  6632. return false;
  6633. }
  6634. else
  6635. {
  6636. // A Sprite Asset has been specified
  6637. if (MaterialReferenceManager.TryGetSpriteAsset(spriteAssetHashCode, out tempSpriteAsset))
  6638. {
  6639. m_currentSpriteAsset = tempSpriteAsset;
  6640. }
  6641. else
  6642. {
  6643. // Load Sprite Asset
  6644. if (tempSpriteAsset == null)
  6645. {
  6646. //
  6647. tempSpriteAsset = OnSpriteAssetRequest?.Invoke(spriteAssetHashCode, new string(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength));
  6648. if (tempSpriteAsset == null)
  6649. tempSpriteAsset = Resources.Load<TMP_SpriteAsset>(TMP_Settings.defaultSpriteAssetPath + new string(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength));
  6650. }
  6651. if (tempSpriteAsset == null)
  6652. return false;
  6653. //Debug.Log("Loading & assigning new Sprite Asset: " + tempSpriteAsset.name);
  6654. MaterialReferenceManager.AddSpriteAsset(spriteAssetHashCode, tempSpriteAsset);
  6655. m_currentSpriteAsset = tempSpriteAsset;
  6656. }
  6657. }
  6658. // Handling of <sprite=index> legacy tag format.
  6659. if (m_xmlAttribute[0].valueType == TagValueType.NumericalValue) // <sprite=index>
  6660. {
  6661. int index = (int)ConvertToFloat(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength);
  6662. // Reject tag if value is invalid.
  6663. if (index == Int16.MinValue) return false;
  6664. // Check to make sure sprite index is valid
  6665. if (index > m_currentSpriteAsset.spriteCharacterTable.Count - 1) return false;
  6666. m_spriteIndex = index;
  6667. }
  6668. m_spriteColor = s_colorWhite;
  6669. m_tintSprite = false;
  6670. // Handle Sprite Tag Attributes
  6671. for (int i = 0; i < m_xmlAttribute.Length && m_xmlAttribute[i].nameHashCode != 0; i++)
  6672. {
  6673. //Debug.Log("Attribute[" + i + "].nameHashCode=" + m_xmlAttribute[i].nameHashCode + " Value:" + ConvertToFloat(m_htmlTag, m_xmlAttribute[i].valueStartIndex, m_xmlAttribute[i].valueLength));
  6674. int nameHashCode = m_xmlAttribute[i].nameHashCode;
  6675. int index = 0;
  6676. switch (nameHashCode)
  6677. {
  6678. case 43347: // <sprite name="">
  6679. case 30547: // <SPRITE NAME="">
  6680. m_currentSpriteAsset = TMP_SpriteAsset.SearchForSpriteByHashCode(m_currentSpriteAsset, m_xmlAttribute[i].valueHashCode, true, out index);
  6681. if (index == -1) return false;
  6682. m_spriteIndex = index;
  6683. break;
  6684. case 295562: // <sprite index=>
  6685. case 205930: // <SPRITE INDEX=>
  6686. index = (int)ConvertToFloat(m_htmlTag, m_xmlAttribute[1].valueStartIndex, m_xmlAttribute[1].valueLength);
  6687. // Reject tag if value is invalid.
  6688. if (index == Int16.MinValue) return false;
  6689. // Check to make sure sprite index is valid
  6690. if (index > m_currentSpriteAsset.spriteCharacterTable.Count - 1) return false;
  6691. m_spriteIndex = index;
  6692. break;
  6693. case 45819: // tint
  6694. case 33019: // TINT
  6695. m_tintSprite = ConvertToFloat(m_htmlTag, m_xmlAttribute[i].valueStartIndex, m_xmlAttribute[i].valueLength) != 0;
  6696. break;
  6697. case 281955: // color=#FF00FF80
  6698. case 192323: // COLOR
  6699. m_spriteColor = HexCharsToColor(m_htmlTag, m_xmlAttribute[i].valueStartIndex, m_xmlAttribute[i].valueLength);
  6700. break;
  6701. case 39505: // anim="0,16,12" start, end, fps
  6702. case 26705: // ANIM
  6703. //Debug.Log("Start: " + m_xmlAttribute[i].valueStartIndex + " Length: " + m_xmlAttribute[i].valueLength);
  6704. int paramCount = GetAttributeParameters(m_htmlTag, m_xmlAttribute[i].valueStartIndex, m_xmlAttribute[i].valueLength, ref m_attributeParameterValues);
  6705. if (paramCount != 3) return false;
  6706. m_spriteIndex = (int)m_attributeParameterValues[0];
  6707. if (m_isParsingText)
  6708. {
  6709. // TODO : fix this!
  6710. // It is possible for a sprite to get animated when it ends up being truncated.
  6711. // Should consider moving the animation of the sprite after text geometry upload.
  6712. spriteAnimator.DoSpriteAnimation(m_characterCount, m_currentSpriteAsset, m_spriteIndex, (int)m_attributeParameterValues[1], (int)m_attributeParameterValues[2]);
  6713. }
  6714. break;
  6715. //case 45545: // size
  6716. //case 32745: // SIZE
  6717. // break;
  6718. default:
  6719. if (nameHashCode != 2246877 && nameHashCode != 1619421)
  6720. return false;
  6721. break;
  6722. }
  6723. }
  6724. if (m_spriteIndex == -1) return false;
  6725. // Material HashCode for the Sprite Asset is the Sprite Asset Hash Code
  6726. m_currentMaterialIndex = MaterialReference.AddMaterialReference(m_currentSpriteAsset.material, m_currentSpriteAsset, ref m_materialReferences, m_materialReferenceIndexLookup);
  6727. m_textElementType = TMP_TextElementType.Sprite;
  6728. return true;
  6729. case 730022849: // <lowercase>
  6730. case 514803617: // <LOWERCASE>
  6731. m_FontStyleInternal |= FontStyles.LowerCase;
  6732. m_fontStyleStack.Add(FontStyles.LowerCase);
  6733. return true;
  6734. case -1668324918: // </lowercase>
  6735. case -1883544150: // </LOWERCASE>
  6736. if ((m_fontStyle & FontStyles.LowerCase) != FontStyles.LowerCase)
  6737. {
  6738. if (m_fontStyleStack.Remove(FontStyles.LowerCase) == 0)
  6739. m_FontStyleInternal &= ~FontStyles.LowerCase;
  6740. }
  6741. return true;
  6742. case 13526026: // <allcaps>
  6743. case 9133802: // <ALLCAPS>
  6744. case 781906058: // <uppercase>
  6745. case 566686826: // <UPPERCASE>
  6746. m_FontStyleInternal |= FontStyles.UpperCase;
  6747. m_fontStyleStack.Add(FontStyles.UpperCase);
  6748. return true;
  6749. case 52232547: // </allcaps>
  6750. case 47840323: // </ALLCAPS>
  6751. case -1616441709: // </uppercase>
  6752. case -1831660941: // </UPPERCASE>
  6753. if ((m_fontStyle & FontStyles.UpperCase) != FontStyles.UpperCase)
  6754. {
  6755. if (m_fontStyleStack.Remove(FontStyles.UpperCase) == 0)
  6756. m_FontStyleInternal &= ~FontStyles.UpperCase;
  6757. }
  6758. return true;
  6759. case 766244328: // <smallcaps>
  6760. case 551025096: // <SMALLCAPS>
  6761. m_FontStyleInternal |= FontStyles.SmallCaps;
  6762. m_fontStyleStack.Add(FontStyles.SmallCaps);
  6763. return true;
  6764. case -1632103439: // </smallcaps>
  6765. case -1847322671: // </SMALLCAPS>
  6766. if ((m_fontStyle & FontStyles.SmallCaps) != FontStyles.SmallCaps)
  6767. {
  6768. if (m_fontStyleStack.Remove(FontStyles.SmallCaps) == 0)
  6769. m_FontStyleInternal &= ~FontStyles.SmallCaps;
  6770. }
  6771. return true;
  6772. case 2109854: // <margin=00.0> <margin=00em> <margin=50%>
  6773. case 1482398: // <MARGIN>
  6774. // Check value type
  6775. switch (m_xmlAttribute[0].valueType)
  6776. {
  6777. case TagValueType.NumericalValue:
  6778. value = ConvertToFloat(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength); // px
  6779. // Reject tag if value is invalid.
  6780. if (value == Int16.MinValue) return false;
  6781. // Determine tag unit type
  6782. switch (tagUnitType)
  6783. {
  6784. case TagUnitType.Pixels:
  6785. m_marginLeft = value * (m_isOrthographic ? 1 : 0.1f);
  6786. break;
  6787. case TagUnitType.FontUnits:
  6788. m_marginLeft = value * (m_isOrthographic ? 1 : 0.1f) * m_currentFontSize;
  6789. break;
  6790. case TagUnitType.Percentage:
  6791. m_marginLeft = (m_marginWidth - (m_width != -1 ? m_width : 0)) * value / 100;
  6792. break;
  6793. }
  6794. m_marginLeft = m_marginLeft >= 0 ? m_marginLeft : 0;
  6795. m_marginRight = m_marginLeft;
  6796. return true;
  6797. case TagValueType.None:
  6798. for (int i = 1; i < m_xmlAttribute.Length && m_xmlAttribute[i].nameHashCode != 0; i++)
  6799. {
  6800. // Get attribute name
  6801. int nameHashCode = m_xmlAttribute[i].nameHashCode;
  6802. switch (nameHashCode)
  6803. {
  6804. case 42823: // <margin left=value>
  6805. value = ConvertToFloat(m_htmlTag, m_xmlAttribute[i].valueStartIndex, m_xmlAttribute[i].valueLength); // px
  6806. // Reject tag if value is invalid.
  6807. if (value == Int16.MinValue) return false;
  6808. switch (m_xmlAttribute[i].unitType)
  6809. {
  6810. case TagUnitType.Pixels:
  6811. m_marginLeft = value * (m_isOrthographic ? 1 : 0.1f);
  6812. break;
  6813. case TagUnitType.FontUnits:
  6814. m_marginLeft = value * (m_isOrthographic ? 1 : 0.1f) * m_currentFontSize;
  6815. break;
  6816. case TagUnitType.Percentage:
  6817. m_marginLeft = (m_marginWidth - (m_width != -1 ? m_width : 0)) * value / 100;
  6818. break;
  6819. }
  6820. m_marginLeft = m_marginLeft >= 0 ? m_marginLeft : 0;
  6821. break;
  6822. case 315620: // <margin right=value>
  6823. value = ConvertToFloat(m_htmlTag, m_xmlAttribute[i].valueStartIndex, m_xmlAttribute[i].valueLength); // px
  6824. // Reject tag if value is invalid.
  6825. if (value == Int16.MinValue) return false;
  6826. switch (m_xmlAttribute[i].unitType)
  6827. {
  6828. case TagUnitType.Pixels:
  6829. m_marginRight = value * (m_isOrthographic ? 1 : 0.1f);
  6830. break;
  6831. case TagUnitType.FontUnits:
  6832. m_marginRight = value * (m_isOrthographic ? 1 : 0.1f) * m_currentFontSize;
  6833. break;
  6834. case TagUnitType.Percentage:
  6835. m_marginRight = (m_marginWidth - (m_width != -1 ? m_width : 0)) * value / 100;
  6836. break;
  6837. }
  6838. m_marginRight = m_marginRight >= 0 ? m_marginRight : 0;
  6839. break;
  6840. }
  6841. }
  6842. return true;
  6843. }
  6844. return false;
  6845. case 7639357: // </margin>
  6846. case 7011901: // </MARGIN>
  6847. m_marginLeft = 0;
  6848. m_marginRight = 0;
  6849. return true;
  6850. case 1100728678: // <margin-left=xx.x>
  6851. case -855002522: // <MARGIN-LEFT>
  6852. value = ConvertToFloat(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength); // px
  6853. // Reject tag if value is invalid.
  6854. if (value == Int16.MinValue) return false;
  6855. switch (tagUnitType)
  6856. {
  6857. case TagUnitType.Pixels:
  6858. m_marginLeft = value * (m_isOrthographic ? 1 : 0.1f);
  6859. break;
  6860. case TagUnitType.FontUnits:
  6861. m_marginLeft = value * (m_isOrthographic ? 1 : 0.1f) * m_currentFontSize;
  6862. break;
  6863. case TagUnitType.Percentage:
  6864. m_marginLeft = (m_marginWidth - (m_width != -1 ? m_width : 0)) * value / 100;
  6865. break;
  6866. }
  6867. m_marginLeft = m_marginLeft >= 0 ? m_marginLeft : 0;
  6868. return true;
  6869. case -884817987: // <margin-right=xx.x>
  6870. case -1690034531: // <MARGIN-RIGHT>
  6871. value = ConvertToFloat(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength); // px
  6872. // Reject tag if value is invalid.
  6873. if (value == Int16.MinValue) return false;
  6874. switch (tagUnitType)
  6875. {
  6876. case TagUnitType.Pixels:
  6877. m_marginRight = value * (m_isOrthographic ? 1 : 0.1f);
  6878. break;
  6879. case TagUnitType.FontUnits:
  6880. m_marginRight = value * (m_isOrthographic ? 1 : 0.1f) * m_currentFontSize;
  6881. break;
  6882. case TagUnitType.Percentage:
  6883. m_marginRight = (m_marginWidth - (m_width != -1 ? m_width : 0)) * value / 100;
  6884. break;
  6885. }
  6886. m_marginRight = m_marginRight >= 0 ? m_marginRight : 0;
  6887. return true;
  6888. case 1109349752: // <line-height=xx.x>
  6889. case -842693512: // <LINE-HEIGHT>
  6890. value = ConvertToFloat(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength);
  6891. // Reject tag if value is invalid.
  6892. if (value == Int16.MinValue) return false;
  6893. switch (tagUnitType)
  6894. {
  6895. case TagUnitType.Pixels:
  6896. m_lineHeight = value * (m_isOrthographic ? 1 : 0.1f);
  6897. break;
  6898. case TagUnitType.FontUnits:
  6899. m_lineHeight = value * (m_isOrthographic ? 1 : 0.1f) * m_currentFontSize;
  6900. break;
  6901. case TagUnitType.Percentage:
  6902. fontScale = (m_currentFontSize / m_currentFontAsset.faceInfo.pointSize * m_currentFontAsset.faceInfo.scale * (m_isOrthographic ? 1 : 0.1f));
  6903. m_lineHeight = m_fontAsset.faceInfo.lineHeight * value / 100 * fontScale;
  6904. break;
  6905. }
  6906. return true;
  6907. case -445573839: // </line-height>
  6908. case 1897350193: // </LINE-HEIGHT>
  6909. m_lineHeight = TMP_Math.FLOAT_UNSET;
  6910. return true;
  6911. case 15115642: // <noparse>
  6912. case 10723418: // <NOPARSE>
  6913. tag_NoParsing = true;
  6914. return true;
  6915. case 1913798: // <action>
  6916. case 1286342: // <ACTION>
  6917. int actionID = m_xmlAttribute[0].valueHashCode;
  6918. if (m_isParsingText)
  6919. {
  6920. m_actionStack.Add(actionID);
  6921. Debug.Log("Action ID: [" + actionID + "] First character index: " + m_characterCount);
  6922. }
  6923. //if (m_isParsingText)
  6924. //{
  6925. // TMP_Action action = TMP_Action.GetAction(m_xmlAttribute[0].valueHashCode);
  6926. //}
  6927. return true;
  6928. case 7443301: // </action>
  6929. case 6815845: // </ACTION>
  6930. if (m_isParsingText)
  6931. {
  6932. Debug.Log("Action ID: [" + m_actionStack.CurrentItem() + "] Last character index: " + (m_characterCount - 1));
  6933. }
  6934. m_actionStack.Remove();
  6935. return true;
  6936. case 315682: // <scale=xx.x>
  6937. case 226050: // <SCALE=xx.x>
  6938. value = ConvertToFloat(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength);
  6939. // Reject tag if value is invalid.
  6940. if (value == Int16.MinValue) return false;
  6941. m_FXMatrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(value, 1, 1));
  6942. m_isFXMatrixSet = true;
  6943. return true;
  6944. case 1105611: // </scale>
  6945. case 1015979: // </SCALE>
  6946. m_isFXMatrixSet = false;
  6947. return true;
  6948. case 2227963: // <rotate=xx.x>
  6949. case 1600507: // <ROTATE=xx.x>
  6950. // TODO: Add ability to use Random Rotation
  6951. value = ConvertToFloat(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength);
  6952. // Reject tag if value is invalid.
  6953. if (value == Int16.MinValue) return false;
  6954. m_FXMatrix = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0, 0, value), Vector3.one);
  6955. m_isFXMatrixSet = true;
  6956. return true;
  6957. case 7757466: // </rotate>
  6958. case 7130010: // </ROTATE>
  6959. m_isFXMatrixSet = false;
  6960. return true;
  6961. case 317446: // <table>
  6962. case 227814: // <TABLE>
  6963. //switch (m_xmlAttribute[1].nameHashCode)
  6964. //{
  6965. // case 327550: // width
  6966. // float tableWidth = ConvertToFloat(m_htmlTag, m_xmlAttribute[1].valueStartIndex, m_xmlAttribute[1].valueLength);
  6967. // // Reject tag if value is invalid.
  6968. // if (tableWidth == Int16.MinValue) return false;
  6969. // switch (tagUnitType)
  6970. // {
  6971. // case TagUnitType.Pixels:
  6972. // Debug.Log("Table width = " + tableWidth + "px.");
  6973. // break;
  6974. // case TagUnitType.FontUnits:
  6975. // Debug.Log("Table width = " + tableWidth + "em.");
  6976. // break;
  6977. // case TagUnitType.Percentage:
  6978. // Debug.Log("Table width = " + tableWidth + "%.");
  6979. // break;
  6980. // }
  6981. // break;
  6982. //}
  6983. return false;
  6984. case 1107375: // </table>
  6985. case 1017743: // </TABLE>
  6986. return true;
  6987. case 926: // <tr>
  6988. case 670: // <TR>
  6989. return true;
  6990. case 3229: // </tr>
  6991. case 2973: // </TR>
  6992. return true;
  6993. case 916: // <th>
  6994. case 660: // <TH>
  6995. // Set style to bold and center alignment
  6996. return true;
  6997. case 3219: // </th>
  6998. case 2963: // </TH>
  6999. return true;
  7000. case 912: // <td>
  7001. case 656: // <TD>
  7002. // Style options
  7003. //for (int i = 1; i < m_xmlAttribute.Length && m_xmlAttribute[i].nameHashCode != 0; i++)
  7004. //{
  7005. // switch (m_xmlAttribute[i].nameHashCode)
  7006. // {
  7007. // case 327550: // width
  7008. // float tableWidth = ConvertToFloat(m_htmlTag, m_xmlAttribute[i].valueStartIndex, m_xmlAttribute[i].valueLength);
  7009. // switch (tagUnitType)
  7010. // {
  7011. // case TagUnitType.Pixels:
  7012. // Debug.Log("Table width = " + tableWidth + "px.");
  7013. // break;
  7014. // case TagUnitType.FontUnits:
  7015. // Debug.Log("Table width = " + tableWidth + "em.");
  7016. // break;
  7017. // case TagUnitType.Percentage:
  7018. // Debug.Log("Table width = " + tableWidth + "%.");
  7019. // break;
  7020. // }
  7021. // break;
  7022. // case 275917: // align
  7023. // switch (m_xmlAttribute[i].valueHashCode)
  7024. // {
  7025. // case 3774683: // left
  7026. // Debug.Log("TD align=\"left\".");
  7027. // break;
  7028. // case 136703040: // right
  7029. // Debug.Log("TD align=\"right\".");
  7030. // break;
  7031. // case -458210101: // center
  7032. // Debug.Log("TD align=\"center\".");
  7033. // break;
  7034. // case -523808257: // justified
  7035. // Debug.Log("TD align=\"justified\".");
  7036. // break;
  7037. // }
  7038. // break;
  7039. // }
  7040. //}
  7041. return false;
  7042. case 3215: // </td>
  7043. case 2959: // </TD>
  7044. return false;
  7045. }
  7046. }
  7047. #endif
  7048. #endregion
  7049. return false;
  7050. }
  7051. }
  7052. }