TMP_Text.cs 331 KB

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