TMP_Text.cs 331 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630
  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. int srcOffset;
  1609. if (ReplaceOpeningStyleTag(ref sourceText, i, out srcOffset, ref m_TextParsingBuffer, ref writeIndex))
  1610. {
  1611. i = srcOffset;
  1612. continue;
  1613. }
  1614. }
  1615. else if (IsTagName(ref sourceText, "</STYLE>", i))
  1616. {
  1617. ReplaceClosingStyleTag(ref sourceText, i, ref m_TextParsingBuffer, ref writeIndex);
  1618. // Strip </style> even if style is invalid.
  1619. i += 7;
  1620. continue;
  1621. }
  1622. }
  1623. if (writeIndex == m_TextParsingBuffer.Length) ResizeInternalArray(ref m_TextParsingBuffer);
  1624. m_TextParsingBuffer[writeIndex].unicode = sourceText[i];
  1625. writeIndex += 1;
  1626. }
  1627. if (writeIndex == m_TextParsingBuffer.Length) ResizeInternalArray(ref m_TextParsingBuffer);
  1628. m_TextParsingBuffer[writeIndex].unicode = 0;
  1629. m_inputSource = TextInputSources.SetCharArray;
  1630. m_isInputParsingRequired = true;
  1631. m_havePropertiesChanged = true;
  1632. m_isCalculateSizeRequired = true;
  1633. SetVerticesDirty();
  1634. SetLayoutDirty();
  1635. }
  1636. /// <summary>
  1637. /// Character array containing the text to be displayed.
  1638. /// </summary>
  1639. /// <param name="sourceText"></param>
  1640. public void SetCharArray(char[] sourceText, int start, int length)
  1641. {
  1642. // Initialize internal character buffer if necessary
  1643. if (m_TextParsingBuffer == null) m_TextParsingBuffer = new UnicodeChar[8];
  1644. #if UNITY_EDITOR
  1645. // Create new string to be displayed in the Input Text Box of the Editor Panel.
  1646. if (sourceText == null || sourceText.Length == 0 || length == 0)
  1647. {
  1648. m_text = string.Empty;
  1649. start = 0;
  1650. length = 0;
  1651. }
  1652. else
  1653. {
  1654. // TODO: Add potential range check on start + length relative to array size.
  1655. m_text = new string(sourceText, start, length);
  1656. }
  1657. #endif
  1658. // Clear the Style stack.
  1659. m_styleStack.Clear();
  1660. int writeIndex = 0;
  1661. int i = start;
  1662. int end = start + length;
  1663. for (; i < end; i++)
  1664. {
  1665. if (sourceText[i] == 92 && i < length - 1)
  1666. {
  1667. switch ((int)sourceText[i + 1])
  1668. {
  1669. case 110: // \n LineFeed
  1670. if (writeIndex == m_TextParsingBuffer.Length) ResizeInternalArray(ref m_TextParsingBuffer);
  1671. m_TextParsingBuffer[writeIndex].unicode = 10;
  1672. i += 1;
  1673. writeIndex += 1;
  1674. continue;
  1675. case 114: // \r LineFeed
  1676. if (writeIndex == m_TextParsingBuffer.Length) ResizeInternalArray(ref m_TextParsingBuffer);
  1677. m_TextParsingBuffer[writeIndex].unicode = 13;
  1678. i += 1;
  1679. writeIndex += 1;
  1680. continue;
  1681. case 116: // \t Tab
  1682. if (writeIndex == m_TextParsingBuffer.Length) ResizeInternalArray(ref m_TextParsingBuffer);
  1683. m_TextParsingBuffer[writeIndex].unicode = 9;
  1684. i += 1;
  1685. writeIndex += 1;
  1686. continue;
  1687. }
  1688. }
  1689. // Handle inline replacement of <stlye> and <br> tags.
  1690. if (sourceText[i] == 60)
  1691. {
  1692. if (IsTagName(ref sourceText, "<BR>", i))
  1693. {
  1694. if (writeIndex == m_TextParsingBuffer.Length) ResizeInternalArray(ref m_TextParsingBuffer);
  1695. m_TextParsingBuffer[writeIndex].unicode = 10;
  1696. writeIndex += 1;
  1697. i += 3;
  1698. continue;
  1699. }
  1700. else if (IsTagName(ref sourceText, "<STYLE=", i))
  1701. {
  1702. int srcOffset;
  1703. if (ReplaceOpeningStyleTag(ref sourceText, i, out srcOffset, ref m_TextParsingBuffer, ref writeIndex))
  1704. {
  1705. i = srcOffset;
  1706. continue;
  1707. }
  1708. }
  1709. else if (IsTagName(ref sourceText, "</STYLE>", i))
  1710. {
  1711. ReplaceClosingStyleTag(ref sourceText, i, ref m_TextParsingBuffer, ref writeIndex);
  1712. // Strip </style> even if style is invalid.
  1713. i += 7;
  1714. continue;
  1715. }
  1716. }
  1717. if (writeIndex == m_TextParsingBuffer.Length) ResizeInternalArray(ref m_TextParsingBuffer);
  1718. m_TextParsingBuffer[writeIndex].unicode = sourceText[i];
  1719. writeIndex += 1;
  1720. }
  1721. if (writeIndex == m_TextParsingBuffer.Length) ResizeInternalArray(ref m_TextParsingBuffer);
  1722. m_TextParsingBuffer[writeIndex].unicode = 0;
  1723. m_inputSource = TextInputSources.SetCharArray;
  1724. m_havePropertiesChanged = true;
  1725. m_isInputParsingRequired = true;
  1726. m_isCalculateSizeRequired = true;
  1727. SetVerticesDirty();
  1728. SetLayoutDirty();
  1729. }
  1730. /// <summary>
  1731. /// Character array containing the text to be displayed.
  1732. /// </summary>
  1733. /// <param name="sourceText"></param>
  1734. public void SetCharArray(int[] sourceText, int start, int length)
  1735. {
  1736. // Initialize internal character buffer if necessary
  1737. if (m_TextParsingBuffer == null) m_TextParsingBuffer = new UnicodeChar[8];
  1738. #if UNITY_EDITOR
  1739. // Create new string to be displayed in the Input Text Box of the Editor Panel.
  1740. if (sourceText == null || sourceText.Length == 0 || length == 0)
  1741. {
  1742. m_text = string.Empty;
  1743. start = 0;
  1744. length = 0;
  1745. }
  1746. else
  1747. {
  1748. m_text = sourceText.IntToString(start, length);
  1749. }
  1750. #endif
  1751. // Clear the Style stack.
  1752. m_styleStack.Clear();
  1753. int writeIndex = 0;
  1754. int end = start + length;
  1755. for (int i = start; i < end && i < sourceText.Length; i++)
  1756. {
  1757. if (sourceText[i] == 92 && i < length - 1)
  1758. {
  1759. switch ((int)sourceText[i + 1])
  1760. {
  1761. case 110: // \n LineFeed
  1762. if (writeIndex == m_TextParsingBuffer.Length) ResizeInternalArray(ref m_TextParsingBuffer);
  1763. m_TextParsingBuffer[writeIndex].unicode = 10;
  1764. i += 1;
  1765. writeIndex += 1;
  1766. continue;
  1767. case 114: // \r LineFeed
  1768. if (writeIndex == m_TextParsingBuffer.Length) ResizeInternalArray(ref m_TextParsingBuffer);
  1769. m_TextParsingBuffer[writeIndex].unicode = 13;
  1770. i += 1;
  1771. writeIndex += 1;
  1772. continue;
  1773. case 116: // \t Tab
  1774. if (writeIndex == m_TextParsingBuffer.Length) ResizeInternalArray(ref m_TextParsingBuffer);
  1775. m_TextParsingBuffer[writeIndex].unicode = 9;
  1776. i += 1;
  1777. writeIndex += 1;
  1778. continue;
  1779. }
  1780. }
  1781. // Handle inline replacement of <stlye> and <br> tags.
  1782. if (sourceText[i] == 60)
  1783. {
  1784. if (IsTagName(ref sourceText, "<BR>", i))
  1785. {
  1786. if (writeIndex == m_TextParsingBuffer.Length) ResizeInternalArray(ref m_TextParsingBuffer);
  1787. m_TextParsingBuffer[writeIndex].unicode = 10;
  1788. writeIndex += 1;
  1789. i += 3;
  1790. continue;
  1791. }
  1792. else if (IsTagName(ref sourceText, "<STYLE=", i))
  1793. {
  1794. int srcOffset;
  1795. if (ReplaceOpeningStyleTag(ref sourceText, i, out srcOffset, ref m_TextParsingBuffer, ref writeIndex))
  1796. {
  1797. i = srcOffset;
  1798. continue;
  1799. }
  1800. }
  1801. else if (IsTagName(ref sourceText, "</STYLE>", i))
  1802. {
  1803. ReplaceClosingStyleTag(ref sourceText, i, ref m_TextParsingBuffer, ref writeIndex);
  1804. // Strip </style> even if style is invalid.
  1805. i += 7;
  1806. continue;
  1807. }
  1808. }
  1809. if (writeIndex == m_TextParsingBuffer.Length) ResizeInternalArray(ref m_TextParsingBuffer);
  1810. m_TextParsingBuffer[writeIndex].unicode = sourceText[i];
  1811. writeIndex += 1;
  1812. }
  1813. if (writeIndex == m_TextParsingBuffer.Length) ResizeInternalArray(ref m_TextParsingBuffer);
  1814. m_TextParsingBuffer[writeIndex].unicode = 0;
  1815. m_inputSource = TextInputSources.SetCharArray;
  1816. m_havePropertiesChanged = true;
  1817. m_isInputParsingRequired = true;
  1818. m_isCalculateSizeRequired = true;
  1819. SetVerticesDirty();
  1820. SetLayoutDirty();
  1821. }
  1822. /// <summary>
  1823. /// Copies Content of formatted SetText() to charBuffer.
  1824. /// </summary>
  1825. /// <param name="sourceText"></param>
  1826. /// <param name="charBuffer"></param>
  1827. protected void SetTextArrayToCharArray(char[] sourceText, ref UnicodeChar[] charBuffer)
  1828. {
  1829. //Debug.Log("SetText Array to Char called.");
  1830. if (sourceText == null || m_charArray_Length == 0)
  1831. return;
  1832. if (charBuffer == null) charBuffer = new UnicodeChar[8];
  1833. // Clear the Style stack.
  1834. m_styleStack.Clear();
  1835. int writeIndex = 0;
  1836. for (int i = 0; i < m_charArray_Length; i++)
  1837. {
  1838. // Handle UTF-32 in the input text (string).
  1839. if (char.IsHighSurrogate(sourceText[i]) && char.IsLowSurrogate(sourceText[i + 1]))
  1840. {
  1841. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  1842. charBuffer[writeIndex].unicode = char.ConvertToUtf32(sourceText[i], sourceText[i + 1]);
  1843. i += 1;
  1844. writeIndex += 1;
  1845. continue;
  1846. }
  1847. // Handle inline replacement of <stlye> and <br> tags.
  1848. if (sourceText[i] == 60)
  1849. {
  1850. if (IsTagName(ref sourceText, "<BR>", i))
  1851. {
  1852. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  1853. charBuffer[writeIndex].unicode = 10;
  1854. writeIndex += 1;
  1855. i += 3;
  1856. continue;
  1857. }
  1858. else if (IsTagName(ref sourceText, "<STYLE=", i))
  1859. {
  1860. int srcOffset;
  1861. if (ReplaceOpeningStyleTag(ref sourceText, i, out srcOffset, ref charBuffer, ref writeIndex))
  1862. {
  1863. i = srcOffset;
  1864. continue;
  1865. }
  1866. }
  1867. else if (IsTagName(ref sourceText, "</STYLE>", i))
  1868. {
  1869. ReplaceClosingStyleTag(ref sourceText, i, ref charBuffer, ref writeIndex);
  1870. // Strip </style> even if style is invalid.
  1871. i += 7;
  1872. continue;
  1873. }
  1874. }
  1875. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  1876. charBuffer[writeIndex].unicode = sourceText[i];
  1877. writeIndex += 1;
  1878. }
  1879. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  1880. charBuffer[writeIndex].unicode = 0;
  1881. }
  1882. /// <summary>
  1883. /// Method to store the content of a string into an integer array.
  1884. /// </summary>
  1885. /// <param name="sourceText"></param>
  1886. /// <param name="charBuffer"></param>
  1887. protected void StringToCharArray(string sourceText, ref UnicodeChar[] charBuffer)
  1888. {
  1889. if (sourceText == null)
  1890. {
  1891. charBuffer[0].unicode = 0;
  1892. return;
  1893. }
  1894. if (charBuffer == null) charBuffer = new UnicodeChar[8];
  1895. // Clear the Style stack.
  1896. m_styleStack.SetDefault(0);
  1897. int writeIndex = 0;
  1898. for (int i = 0; i < sourceText.Length; i++)
  1899. {
  1900. if (m_inputSource == TextInputSources.Text && sourceText[i] == 92 && sourceText.Length > i + 1)
  1901. {
  1902. switch ((int)sourceText[i + 1])
  1903. {
  1904. case 85: // \U00000000 for UTF-32 Unicode
  1905. if (sourceText.Length > i + 9)
  1906. {
  1907. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  1908. charBuffer[writeIndex].unicode = GetUTF32(sourceText, i + 2);
  1909. charBuffer[writeIndex].stringIndex = i;
  1910. charBuffer[writeIndex].length = 10;
  1911. i += 9;
  1912. writeIndex += 1;
  1913. continue;
  1914. }
  1915. break;
  1916. case 92: // \ escape
  1917. if (!m_parseCtrlCharacters) break;
  1918. if (sourceText.Length <= i + 2) break;
  1919. if (writeIndex + 2 > charBuffer.Length) ResizeInternalArray(ref charBuffer);
  1920. charBuffer[writeIndex].unicode = sourceText[i + 1];
  1921. charBuffer[writeIndex + 1].unicode = sourceText[i + 2];
  1922. i += 2;
  1923. writeIndex += 2;
  1924. continue;
  1925. case 110: // \n LineFeed
  1926. if (!m_parseCtrlCharacters) break;
  1927. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  1928. charBuffer[writeIndex].unicode = 10;
  1929. charBuffer[writeIndex].stringIndex = i;
  1930. charBuffer[writeIndex].length = 1;
  1931. i += 1;
  1932. writeIndex += 1;
  1933. continue;
  1934. case 114: // \r
  1935. if (!m_parseCtrlCharacters) break;
  1936. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  1937. charBuffer[writeIndex].unicode = 13;
  1938. charBuffer[writeIndex].stringIndex = i;
  1939. charBuffer[writeIndex].length = 1;
  1940. i += 1;
  1941. writeIndex += 1;
  1942. continue;
  1943. case 116: // \t Tab
  1944. if (!m_parseCtrlCharacters) break;
  1945. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  1946. charBuffer[writeIndex].unicode = 9;
  1947. charBuffer[writeIndex].stringIndex = i;
  1948. charBuffer[writeIndex].length = 1;
  1949. i += 1;
  1950. writeIndex += 1;
  1951. continue;
  1952. case 117: // \u0000 for UTF-16 Unicode
  1953. if (sourceText.Length > i + 5)
  1954. {
  1955. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  1956. charBuffer[writeIndex].unicode = GetUTF16(sourceText, i + 2);
  1957. charBuffer[writeIndex].stringIndex = i;
  1958. charBuffer[writeIndex].length = 6;
  1959. i += 5;
  1960. writeIndex += 1;
  1961. continue;
  1962. }
  1963. break;
  1964. }
  1965. }
  1966. // Handle UTF-32 in the input text (string). // Not sure this is needed //
  1967. if (char.IsHighSurrogate(sourceText[i]) && char.IsLowSurrogate(sourceText[i + 1]))
  1968. {
  1969. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  1970. charBuffer[writeIndex].unicode = char.ConvertToUtf32(sourceText[i], sourceText[i + 1]);
  1971. charBuffer[writeIndex].stringIndex = i;
  1972. charBuffer[writeIndex].length = 2;
  1973. i += 1;
  1974. writeIndex += 1;
  1975. continue;
  1976. }
  1977. //// Handle inline replacement of <stlye> and <br> tags.
  1978. if (sourceText[i] == 60 && m_isRichText)
  1979. {
  1980. if (IsTagName(ref sourceText, "<BR>", i))
  1981. {
  1982. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  1983. charBuffer[writeIndex].unicode = 10;
  1984. charBuffer[writeIndex].stringIndex = i;
  1985. charBuffer[writeIndex].length = 1;
  1986. writeIndex += 1;
  1987. i += 3;
  1988. continue;
  1989. }
  1990. else if (IsTagName(ref sourceText, "<STYLE=", i))
  1991. {
  1992. int srcOffset;
  1993. if (ReplaceOpeningStyleTag(ref sourceText, i, out srcOffset, ref charBuffer, ref writeIndex))
  1994. {
  1995. i = srcOffset;
  1996. continue;
  1997. }
  1998. }
  1999. else if (IsTagName(ref sourceText, "</STYLE>", i))
  2000. {
  2001. ReplaceClosingStyleTag(ref sourceText, i, ref charBuffer, ref writeIndex);
  2002. // Strip </style> even if style is invalid.
  2003. i += 7;
  2004. continue;
  2005. }
  2006. }
  2007. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2008. charBuffer[writeIndex].unicode = sourceText[i];
  2009. charBuffer[writeIndex].stringIndex = i;
  2010. charBuffer[writeIndex].length = 1;
  2011. writeIndex += 1;
  2012. }
  2013. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2014. charBuffer[writeIndex].unicode = 0;
  2015. }
  2016. /// <summary>
  2017. /// Copy contents of StringBuilder into int array.
  2018. /// </summary>
  2019. /// <param name="sourceText">Text to copy.</param>
  2020. /// <param name="charBuffer">Array to store contents.</param>
  2021. protected void StringBuilderToIntArray(StringBuilder sourceText, ref UnicodeChar[] charBuffer)
  2022. {
  2023. if (sourceText == null)
  2024. {
  2025. charBuffer[0].unicode = 0;
  2026. return;
  2027. }
  2028. if (charBuffer == null) charBuffer = new UnicodeChar[8];
  2029. // Clear the Style stack.
  2030. m_styleStack.Clear();
  2031. #if UNITY_EDITOR
  2032. // Create new string to be displayed in the Input Text Box of the Editor Panel.
  2033. m_text = sourceText.ToString();
  2034. #endif
  2035. int writeIndex = 0;
  2036. for (int i = 0; i < sourceText.Length; i++)
  2037. {
  2038. if (m_parseCtrlCharacters && sourceText[i] == 92 && sourceText.Length > i + 1)
  2039. {
  2040. switch ((int)sourceText[i + 1])
  2041. {
  2042. case 85: // \U00000000 for UTF-32 Unicode
  2043. if (sourceText.Length > i + 9)
  2044. {
  2045. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2046. charBuffer[writeIndex].unicode = GetUTF32(sourceText, i + 2);
  2047. i += 9;
  2048. writeIndex += 1;
  2049. continue;
  2050. }
  2051. break;
  2052. case 92: // \ escape
  2053. if (sourceText.Length <= i + 2) break;
  2054. if (writeIndex + 2 > charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2055. charBuffer[writeIndex].unicode = sourceText[i + 1];
  2056. charBuffer[writeIndex + 1].unicode = sourceText[i + 2];
  2057. i += 2;
  2058. writeIndex += 2;
  2059. continue;
  2060. case 110: // \n LineFeed
  2061. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2062. charBuffer[writeIndex].unicode = 10;
  2063. i += 1;
  2064. writeIndex += 1;
  2065. continue;
  2066. case 114: // \r
  2067. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2068. charBuffer[writeIndex].unicode = 13;
  2069. i += 1;
  2070. writeIndex += 1;
  2071. continue;
  2072. case 116: // \t Tab
  2073. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2074. charBuffer[writeIndex].unicode = 9;
  2075. i += 1;
  2076. writeIndex += 1;
  2077. continue;
  2078. case 117: // \u0000 for UTF-16 Unicode
  2079. if (sourceText.Length > i + 5)
  2080. {
  2081. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2082. charBuffer[writeIndex].unicode = GetUTF16(sourceText, i + 2);
  2083. i += 5;
  2084. writeIndex += 1;
  2085. continue;
  2086. }
  2087. break;
  2088. }
  2089. }
  2090. // Handle UTF-32 in the input text (string).
  2091. if (char.IsHighSurrogate(sourceText[i]) && char.IsLowSurrogate(sourceText[i + 1]))
  2092. {
  2093. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2094. charBuffer[writeIndex].unicode = char.ConvertToUtf32(sourceText[i], sourceText[i + 1]);
  2095. i += 1;
  2096. writeIndex += 1;
  2097. continue;
  2098. }
  2099. // Handle inline replacement of <stlye> and <br> tags.
  2100. if (sourceText[i] == 60)
  2101. {
  2102. if (IsTagName(ref sourceText, "<BR>", i))
  2103. {
  2104. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2105. charBuffer[writeIndex].unicode = 10;
  2106. writeIndex += 1;
  2107. i += 3;
  2108. continue;
  2109. }
  2110. else if (IsTagName(ref sourceText, "<STYLE=", i))
  2111. {
  2112. int srcOffset;
  2113. if (ReplaceOpeningStyleTag(ref sourceText, i, out srcOffset, ref charBuffer, ref writeIndex))
  2114. {
  2115. i = srcOffset;
  2116. continue;
  2117. }
  2118. }
  2119. else if (IsTagName(ref sourceText, "</STYLE>", i))
  2120. {
  2121. ReplaceClosingStyleTag(ref sourceText, i, ref charBuffer, ref writeIndex);
  2122. // Strip </style> even if style is invalid.
  2123. i += 7;
  2124. continue;
  2125. }
  2126. }
  2127. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2128. charBuffer[writeIndex].unicode = sourceText[i];
  2129. writeIndex += 1;
  2130. }
  2131. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2132. charBuffer[writeIndex].unicode = 0;
  2133. }
  2134. /// <summary>
  2135. /// Method to handle inline replacement of style tag by opening style definition.
  2136. /// </summary>
  2137. /// <param name="sourceText"></param>
  2138. /// <param name="srcIndex"></param>
  2139. /// <param name="srcOffset"></param>
  2140. /// <param name="charBuffer"></param>
  2141. /// <param name="writeIndex"></param>
  2142. /// <returns></returns>
  2143. bool ReplaceOpeningStyleTag(ref string sourceText, int srcIndex, out int srcOffset, ref UnicodeChar[] charBuffer, ref int writeIndex)
  2144. {
  2145. // Validate <style> tag.
  2146. int hashCode = GetTagHashCode(ref sourceText, srcIndex + 7, out srcOffset);
  2147. TMP_Style style = TMP_StyleSheet.GetStyle(hashCode);
  2148. // Return if we don't have a valid style.
  2149. if (style == null || srcOffset == 0) return false;
  2150. m_styleStack.Add(style.hashCode);
  2151. int styleLength = style.styleOpeningTagArray.Length;
  2152. // Replace <style> tag with opening definition
  2153. int[] openingTagArray = style.styleOpeningTagArray;
  2154. for (int i = 0; i < styleLength; i++)
  2155. {
  2156. int c = openingTagArray[i];
  2157. if (c == 60)
  2158. {
  2159. if (IsTagName(ref openingTagArray, "<BR>", i))
  2160. {
  2161. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2162. charBuffer[writeIndex].unicode = 10;
  2163. writeIndex += 1;
  2164. i += 3;
  2165. continue;
  2166. }
  2167. else if (IsTagName(ref openingTagArray, "<STYLE=", i))
  2168. {
  2169. int offset;
  2170. if (ReplaceOpeningStyleTag(ref openingTagArray, i, out offset, ref charBuffer, ref writeIndex))
  2171. {
  2172. i = offset;
  2173. continue;
  2174. }
  2175. }
  2176. else if (IsTagName(ref openingTagArray, "</STYLE>", i))
  2177. {
  2178. ReplaceClosingStyleTag(ref openingTagArray, i, ref charBuffer, ref writeIndex);
  2179. // Strip </style> even if style is invalid.
  2180. i += 7;
  2181. continue;
  2182. }
  2183. }
  2184. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2185. charBuffer[writeIndex].unicode = c;
  2186. writeIndex += 1;
  2187. }
  2188. return true;
  2189. }
  2190. /// <summary>
  2191. /// Method to handle inline replacement of style tag by opening style definition.
  2192. /// </summary>
  2193. /// <param name="sourceText"></param>
  2194. /// <param name="srcIndex"></param>
  2195. /// <param name="srcOffset"></param>
  2196. /// <param name="charBuffer"></param>
  2197. /// <param name="writeIndex"></param>
  2198. /// <returns></returns>
  2199. bool ReplaceOpeningStyleTag(ref int[] sourceText, int srcIndex, out int srcOffset, ref UnicodeChar[] charBuffer, ref int writeIndex)
  2200. {
  2201. // Validate <style> tag.
  2202. int hashCode = GetTagHashCode(ref sourceText, srcIndex + 7, out srcOffset);
  2203. TMP_Style style = TMP_StyleSheet.GetStyle(hashCode);
  2204. // Return if we don't have a valid style.
  2205. if (style == null || srcOffset == 0) return false;
  2206. m_styleStack.Add(style.hashCode);
  2207. int styleLength = style.styleOpeningTagArray.Length;
  2208. // Replace <style> tag with opening definition
  2209. int[] openingTagArray = style.styleOpeningTagArray;
  2210. for (int i = 0; i < styleLength; i++)
  2211. {
  2212. int c = openingTagArray[i];
  2213. if (c == 60)
  2214. {
  2215. if (IsTagName(ref openingTagArray, "<BR>", i))
  2216. {
  2217. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2218. charBuffer[writeIndex].unicode = 10;
  2219. writeIndex += 1;
  2220. i += 3;
  2221. continue;
  2222. }
  2223. else if (IsTagName(ref openingTagArray, "<STYLE=", i))
  2224. {
  2225. int offset;
  2226. if (ReplaceOpeningStyleTag(ref openingTagArray, i, out offset, ref charBuffer, ref writeIndex))
  2227. {
  2228. i = offset;
  2229. continue;
  2230. }
  2231. }
  2232. else if (IsTagName(ref openingTagArray, "</STYLE>", i))
  2233. {
  2234. ReplaceClosingStyleTag(ref openingTagArray, i, ref charBuffer, ref writeIndex);
  2235. // Strip </style> even if style is invalid.
  2236. i += 7;
  2237. continue;
  2238. }
  2239. }
  2240. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2241. charBuffer[writeIndex].unicode = c;
  2242. writeIndex += 1;
  2243. }
  2244. return true;
  2245. }
  2246. /// <summary>
  2247. /// Method to handle inline replacement of style tag by opening style definition.
  2248. /// </summary>
  2249. /// <param name="sourceText"></param>
  2250. /// <param name="srcIndex"></param>
  2251. /// <param name="srcOffset"></param>
  2252. /// <param name="charBuffer"></param>
  2253. /// <param name="writeIndex"></param>
  2254. /// <returns></returns>
  2255. bool ReplaceOpeningStyleTag(ref char[] sourceText, int srcIndex, out int srcOffset, ref UnicodeChar[] charBuffer, ref int writeIndex)
  2256. {
  2257. // Validate <style> tag.
  2258. int hashCode = GetTagHashCode(ref sourceText, srcIndex + 7, out srcOffset);
  2259. TMP_Style style = TMP_StyleSheet.GetStyle(hashCode);
  2260. // Return if we don't have a valid style.
  2261. if (style == null || srcOffset == 0) return false;
  2262. m_styleStack.Add(style.hashCode);
  2263. int styleLength = style.styleOpeningTagArray.Length;
  2264. // Replace <style> tag with opening definition
  2265. int[] openingTagArray = style.styleOpeningTagArray;
  2266. for (int i = 0; i < styleLength; i++)
  2267. {
  2268. int c = openingTagArray[i];
  2269. if (c == 60)
  2270. {
  2271. if (IsTagName(ref openingTagArray, "<BR>", i))
  2272. {
  2273. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2274. charBuffer[writeIndex].unicode = 10;
  2275. writeIndex += 1;
  2276. i += 3;
  2277. continue;
  2278. }
  2279. else if (IsTagName(ref openingTagArray, "<STYLE=", i))
  2280. {
  2281. int offset;
  2282. if (ReplaceOpeningStyleTag(ref openingTagArray, i, out offset, ref charBuffer, ref writeIndex))
  2283. {
  2284. i = offset;
  2285. continue;
  2286. }
  2287. }
  2288. else if (IsTagName(ref openingTagArray, "</STYLE>", i))
  2289. {
  2290. ReplaceClosingStyleTag(ref openingTagArray, i, ref charBuffer, ref writeIndex);
  2291. // Strip </style> even if style is invalid.
  2292. i += 7;
  2293. continue;
  2294. }
  2295. }
  2296. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2297. charBuffer[writeIndex].unicode = c;
  2298. writeIndex += 1;
  2299. }
  2300. return true;
  2301. }
  2302. /// <summary>
  2303. /// Method to handle inline replacement of style tag by opening style definition.
  2304. /// </summary>
  2305. /// <param name="sourceText"></param>
  2306. /// <param name="srcIndex"></param>
  2307. /// <param name="srcOffset"></param>
  2308. /// <param name="charBuffer"></param>
  2309. /// <param name="writeIndex"></param>
  2310. /// <returns></returns>
  2311. bool ReplaceOpeningStyleTag(ref StringBuilder sourceText, int srcIndex, out int srcOffset, ref UnicodeChar[] charBuffer, ref int writeIndex)
  2312. {
  2313. // Validate <style> tag.
  2314. int hashCode = GetTagHashCode(ref sourceText, srcIndex + 7, out srcOffset);
  2315. TMP_Style style = TMP_StyleSheet.GetStyle(hashCode);
  2316. // Return if we don't have a valid style.
  2317. if (style == null || srcOffset == 0) return false;
  2318. m_styleStack.Add(style.hashCode);
  2319. int styleLength = style.styleOpeningTagArray.Length;
  2320. // Replace <style> tag with opening definition
  2321. int[] openingTagArray = style.styleOpeningTagArray;
  2322. for (int i = 0; i < styleLength; i++)
  2323. {
  2324. int c = openingTagArray[i];
  2325. if (c == 60)
  2326. {
  2327. if (IsTagName(ref openingTagArray, "<BR>", i))
  2328. {
  2329. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2330. charBuffer[writeIndex].unicode = 10;
  2331. writeIndex += 1;
  2332. i += 3;
  2333. continue;
  2334. }
  2335. else if (IsTagName(ref openingTagArray, "<STYLE=", i))
  2336. {
  2337. int offset;
  2338. if (ReplaceOpeningStyleTag(ref openingTagArray, i, out offset, ref charBuffer, ref writeIndex))
  2339. {
  2340. i = offset;
  2341. continue;
  2342. }
  2343. }
  2344. else if (IsTagName(ref openingTagArray, "</STYLE>", i))
  2345. {
  2346. ReplaceClosingStyleTag(ref openingTagArray, i, ref charBuffer, ref writeIndex);
  2347. // Strip </style> even if style is invalid.
  2348. i += 7;
  2349. continue;
  2350. }
  2351. }
  2352. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2353. charBuffer[writeIndex].unicode = c;
  2354. writeIndex += 1;
  2355. }
  2356. return true;
  2357. }
  2358. /// <summary>
  2359. /// Method to handle inline replacement of style tag by closing style definition.
  2360. /// </summary>
  2361. /// <param name="sourceText"></param>
  2362. /// <param name="srcIndex"></param>
  2363. /// <param name="charBuffer"></param>
  2364. /// <param name="writeIndex"></param>
  2365. /// <returns></returns>
  2366. bool ReplaceClosingStyleTag(ref string sourceText, int srcIndex, ref UnicodeChar[] charBuffer, ref int writeIndex)
  2367. {
  2368. // Get style from the Style Stack
  2369. int hashCode = m_styleStack.CurrentItem();
  2370. TMP_Style style = TMP_StyleSheet.GetStyle(hashCode);
  2371. m_styleStack.Remove();
  2372. // Return if we don't have a valid style.
  2373. if (style == null) return false;
  2374. int styleLength = style.styleClosingTagArray.Length;
  2375. // Replace <style> tag with opening definition
  2376. int[] closingTagArray = style.styleClosingTagArray;
  2377. for (int i = 0; i < styleLength; i++)
  2378. {
  2379. int c = closingTagArray[i];
  2380. if (c == 60)
  2381. {
  2382. if (IsTagName(ref closingTagArray, "<BR>", i))
  2383. {
  2384. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2385. charBuffer[writeIndex].unicode = 10;
  2386. writeIndex += 1;
  2387. i += 3;
  2388. continue;
  2389. }
  2390. else if (IsTagName(ref closingTagArray, "<STYLE=", i))
  2391. {
  2392. int offset;
  2393. if (ReplaceOpeningStyleTag(ref closingTagArray, i, out offset, ref charBuffer, ref writeIndex))
  2394. {
  2395. i = offset;
  2396. continue;
  2397. }
  2398. }
  2399. else if (IsTagName(ref closingTagArray, "</STYLE>", i))
  2400. {
  2401. ReplaceClosingStyleTag(ref closingTagArray, i, ref charBuffer, ref writeIndex);
  2402. // Strip </style> even if style is invalid.
  2403. i += 7;
  2404. continue;
  2405. }
  2406. }
  2407. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2408. charBuffer[writeIndex].unicode = c;
  2409. writeIndex += 1;
  2410. }
  2411. return true;
  2412. }
  2413. /// <summary>
  2414. /// Method to handle inline replacement of style tag by closing style definition.
  2415. /// </summary>
  2416. /// <param name="sourceText"></param>
  2417. /// <param name="srcIndex"></param>
  2418. /// <param name="charBuffer"></param>
  2419. /// <param name="writeIndex"></param>
  2420. /// <returns></returns>
  2421. bool ReplaceClosingStyleTag(ref int[] sourceText, int srcIndex, ref UnicodeChar[] charBuffer, ref int writeIndex)
  2422. {
  2423. // Get style from the Style Stack
  2424. int hashCode = m_styleStack.CurrentItem();
  2425. TMP_Style style = TMP_StyleSheet.GetStyle(hashCode);
  2426. m_styleStack.Remove();
  2427. // Return if we don't have a valid style.
  2428. if (style == null) return false;
  2429. int styleLength = style.styleClosingTagArray.Length;
  2430. // Replace <style> tag with opening definition
  2431. int[] closingTagArray = style.styleClosingTagArray;
  2432. for (int i = 0; i < styleLength; i++)
  2433. {
  2434. int c = closingTagArray[i];
  2435. if (c == 60)
  2436. {
  2437. if (IsTagName(ref closingTagArray, "<BR>", i))
  2438. {
  2439. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2440. charBuffer[writeIndex].unicode = 10;
  2441. writeIndex += 1;
  2442. i += 3;
  2443. continue;
  2444. }
  2445. else if (IsTagName(ref closingTagArray, "<STYLE=", i))
  2446. {
  2447. int offset;
  2448. if (ReplaceOpeningStyleTag(ref closingTagArray, i, out offset, ref charBuffer, ref writeIndex))
  2449. {
  2450. i = offset;
  2451. continue;
  2452. }
  2453. }
  2454. else if (IsTagName(ref closingTagArray, "</STYLE>", i))
  2455. {
  2456. ReplaceClosingStyleTag(ref closingTagArray, i, ref charBuffer, ref writeIndex);
  2457. // Strip </style> even if style is invalid.
  2458. i += 7;
  2459. continue;
  2460. }
  2461. }
  2462. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2463. charBuffer[writeIndex].unicode = c;
  2464. writeIndex += 1;
  2465. }
  2466. return true;
  2467. }
  2468. /// <summary>
  2469. /// Method to handle inline replacement of style tag by closing style definition.
  2470. /// </summary>
  2471. /// <param name="sourceText"></param>
  2472. /// <param name="srcIndex"></param>
  2473. /// <param name="charBuffer"></param>
  2474. /// <param name="writeIndex"></param>
  2475. /// <returns></returns>
  2476. bool ReplaceClosingStyleTag(ref char[] sourceText, int srcIndex, ref UnicodeChar[] charBuffer, ref int writeIndex)
  2477. {
  2478. // Get style from the Style Stack
  2479. int hashCode = m_styleStack.CurrentItem();
  2480. TMP_Style style = TMP_StyleSheet.GetStyle(hashCode);
  2481. m_styleStack.Remove();
  2482. // Return if we don't have a valid style.
  2483. if (style == null) return false;
  2484. int styleLength = style.styleClosingTagArray.Length;
  2485. // Replace <style> tag with opening definition
  2486. int[] closingTagArray = style.styleClosingTagArray;
  2487. for (int i = 0; i < styleLength; i++)
  2488. {
  2489. int c = closingTagArray[i];
  2490. if (c == 60)
  2491. {
  2492. if (IsTagName(ref closingTagArray, "<BR>", i))
  2493. {
  2494. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2495. charBuffer[writeIndex].unicode = 10;
  2496. writeIndex += 1;
  2497. i += 3;
  2498. continue;
  2499. }
  2500. else if (IsTagName(ref closingTagArray, "<STYLE=", i))
  2501. {
  2502. int offset;
  2503. if (ReplaceOpeningStyleTag(ref closingTagArray, i, out offset, ref charBuffer, ref writeIndex))
  2504. {
  2505. i = offset;
  2506. continue;
  2507. }
  2508. }
  2509. else if (IsTagName(ref closingTagArray, "</STYLE>", i))
  2510. {
  2511. ReplaceClosingStyleTag(ref closingTagArray, i, ref charBuffer, ref writeIndex);
  2512. // Strip </style> even if style is invalid.
  2513. i += 7;
  2514. continue;
  2515. }
  2516. }
  2517. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2518. charBuffer[writeIndex].unicode = c;
  2519. writeIndex += 1;
  2520. }
  2521. return true;
  2522. }
  2523. /// <summary>
  2524. /// Method to handle inline replacement of style tag by closing style definition.
  2525. /// </summary>
  2526. /// <param name="sourceText"></param>
  2527. /// <param name="srcIndex"></param>
  2528. /// <param name="charBuffer"></param>
  2529. /// <param name="writeIndex"></param>
  2530. /// <returns></returns>
  2531. bool ReplaceClosingStyleTag(ref StringBuilder sourceText, int srcIndex, ref UnicodeChar[] charBuffer, ref int writeIndex)
  2532. {
  2533. // Get style from the Style Stack
  2534. int hashCode = m_styleStack.CurrentItem();
  2535. TMP_Style style = TMP_StyleSheet.GetStyle(hashCode);
  2536. m_styleStack.Remove();
  2537. // Return if we don't have a valid style.
  2538. if (style == null) return false;
  2539. int styleLength = style.styleClosingTagArray.Length;
  2540. // Replace <style> tag with opening definition
  2541. int[] closingTagArray = style.styleClosingTagArray;
  2542. for (int i = 0; i < styleLength; i++)
  2543. {
  2544. int c = closingTagArray[i];
  2545. if (c == 60)
  2546. {
  2547. if (IsTagName(ref closingTagArray, "<BR>", i))
  2548. {
  2549. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2550. charBuffer[writeIndex].unicode = 10;
  2551. writeIndex += 1;
  2552. i += 3;
  2553. continue;
  2554. }
  2555. else if (IsTagName(ref closingTagArray, "<STYLE=", i))
  2556. {
  2557. int offset;
  2558. if (ReplaceOpeningStyleTag(ref closingTagArray, i, out offset, ref charBuffer, ref writeIndex))
  2559. {
  2560. i = offset;
  2561. continue;
  2562. }
  2563. }
  2564. else if (IsTagName(ref closingTagArray, "</STYLE>", i))
  2565. {
  2566. ReplaceClosingStyleTag(ref closingTagArray, i, ref charBuffer, ref writeIndex);
  2567. // Strip </style> even if style is invalid.
  2568. i += 7;
  2569. continue;
  2570. }
  2571. }
  2572. if (writeIndex == charBuffer.Length) ResizeInternalArray(ref charBuffer);
  2573. charBuffer[writeIndex].unicode = c;
  2574. writeIndex += 1;
  2575. }
  2576. return true;
  2577. }
  2578. /// <summary>
  2579. /// Method to check for a matching rich text tag.
  2580. /// </summary>
  2581. /// <param name="text"></param>
  2582. /// <param name="tag"></param>
  2583. /// <param name="index"></param>
  2584. /// <returns></returns>
  2585. bool IsTagName (ref string text, string tag, int index)
  2586. {
  2587. if (text.Length < index + tag.Length) return false;
  2588. for (int i = 0; i < tag.Length; i++)
  2589. {
  2590. if (TMP_TextUtilities.ToUpperFast(text[index + i]) != tag[i]) return false;
  2591. }
  2592. return true;
  2593. }
  2594. /// <summary>
  2595. /// Method to check for a matching rich text tag.
  2596. /// </summary>
  2597. /// <param name="text"></param>
  2598. /// <param name="tag"></param>
  2599. /// <param name="index"></param>
  2600. /// <returns></returns>
  2601. bool IsTagName(ref char[] text, string tag, int index)
  2602. {
  2603. if (text.Length < index + tag.Length) return false;
  2604. for (int i = 0; i < tag.Length; i++)
  2605. {
  2606. if (TMP_TextUtilities.ToUpperFast(text[index + i]) != tag[i]) return false;
  2607. }
  2608. return true;
  2609. }
  2610. /// <summary>
  2611. /// Method to check for a matching rich text tag.
  2612. /// </summary>
  2613. /// <param name="text"></param>
  2614. /// <param name="tag"></param>
  2615. /// <param name="index"></param>
  2616. /// <returns></returns>
  2617. bool IsTagName(ref int[] text, string tag, int index)
  2618. {
  2619. if (text.Length < index + tag.Length) return false;
  2620. for (int i = 0; i < tag.Length; i++)
  2621. {
  2622. if (TMP_TextUtilities.ToUpperFast((char)text[index + i]) != tag[i]) return false;
  2623. }
  2624. return true;
  2625. }
  2626. /// <summary>
  2627. /// Method to check for a matching rich text tag.
  2628. /// </summary>
  2629. /// <param name="text"></param>
  2630. /// <param name="tag"></param>
  2631. /// <param name="index"></param>
  2632. /// <returns></returns>
  2633. bool IsTagName(ref StringBuilder text, string tag, int index)
  2634. {
  2635. if (text.Length < index + tag.Length) return false;
  2636. for (int i = 0; i < tag.Length; i++)
  2637. {
  2638. if (TMP_TextUtilities.ToUpperFast(text[index + i]) != tag[i]) return false;
  2639. }
  2640. return true;
  2641. }
  2642. /// <summary>
  2643. /// Get Hashcode for a given tag.
  2644. /// </summary>
  2645. /// <param name="text"></param>
  2646. /// <param name="index"></param>
  2647. /// <param name="closeIndex"></param>
  2648. /// <returns></returns>
  2649. int GetTagHashCode(ref string text, int index, out int closeIndex)
  2650. {
  2651. int hashCode = 0;
  2652. closeIndex = 0;
  2653. for (int i = index; i < text.Length; i++)
  2654. {
  2655. // Skip quote '"' character
  2656. if (text[i] == 34) continue;
  2657. // Break at '>'
  2658. if (text[i] == 62) { closeIndex = i; break; }
  2659. hashCode = (hashCode << 5) + hashCode ^ text[i];
  2660. }
  2661. return hashCode;
  2662. }
  2663. /// <summary>
  2664. /// Get Hashcode for a given tag.
  2665. /// </summary>
  2666. /// <param name="text"></param>
  2667. /// <param name="index"></param>
  2668. /// <param name="closeIndex"></param>
  2669. /// <returns></returns>
  2670. int GetTagHashCode(ref char[] text, int index, out int closeIndex)
  2671. {
  2672. int hashCode = 0;
  2673. closeIndex = 0;
  2674. for (int i = index; i < text.Length; i++)
  2675. {
  2676. // Skip quote '"' character
  2677. if (text[i] == 34) continue;
  2678. // Break at '>'
  2679. if (text[i] == 62) { closeIndex = i; break; }
  2680. hashCode = (hashCode << 5) + hashCode ^ text[i];
  2681. }
  2682. return hashCode;
  2683. }
  2684. /// <summary>
  2685. /// Get Hashcode for a given tag.
  2686. /// </summary>
  2687. /// <param name="text"></param>
  2688. /// <param name="index"></param>
  2689. /// <param name="closeIndex"></param>
  2690. /// <returns></returns>
  2691. int GetTagHashCode(ref int[] text, int index, out int closeIndex)
  2692. {
  2693. int hashCode = 0;
  2694. closeIndex = 0;
  2695. for (int i = index; i < text.Length; i++)
  2696. {
  2697. // Skip quote '"' character
  2698. if (text[i] == 34) continue;
  2699. // Break at '>'
  2700. if (text[i] == 62) { closeIndex = i; break; }
  2701. hashCode = (hashCode << 5) + hashCode ^ text[i];
  2702. }
  2703. return hashCode;
  2704. }
  2705. /// <summary>
  2706. /// Get Hashcode for a given tag.
  2707. /// </summary>
  2708. /// <param name="text"></param>
  2709. /// <param name="index"></param>
  2710. /// <param name="closeIndex"></param>
  2711. /// <returns></returns>
  2712. int GetTagHashCode(ref StringBuilder text, int index, out int closeIndex)
  2713. {
  2714. int hashCode = 0;
  2715. closeIndex = 0;
  2716. for (int i = index; i < text.Length; i++)
  2717. {
  2718. // Skip quote '"' character
  2719. if (text[i] == 34) continue;
  2720. // Break at '>'
  2721. if (text[i] == 62) { closeIndex = i; break; }
  2722. hashCode = (hashCode << 5) + hashCode ^ text[i];
  2723. }
  2724. return hashCode;
  2725. }
  2726. /// <summary>
  2727. ///
  2728. /// </summary>
  2729. void ResizeInternalArray <T>(ref T[] array)
  2730. {
  2731. int size = Mathf.NextPowerOfTwo(array.Length + 1);
  2732. System.Array.Resize(ref array, size);
  2733. }
  2734. 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.
  2735. /// <summary>
  2736. /// Function used in conjunction with SetText()
  2737. /// </summary>
  2738. /// <param name="number"></param>
  2739. /// <param name="index"></param>
  2740. /// <param name="precision"></param>
  2741. protected void AddFloatToCharArray(double number, ref int index, int precision)
  2742. {
  2743. if (number < 0)
  2744. {
  2745. m_input_CharArray[index++] = '-';
  2746. number = -number;
  2747. }
  2748. number += k_Power[Mathf.Min(9, precision)];
  2749. double integer = Math.Truncate(number);
  2750. AddIntToCharArray(integer, ref index, precision);
  2751. if (precision > 0)
  2752. {
  2753. // Add the decimal point
  2754. m_input_CharArray[index++] = '.';
  2755. number -= integer;
  2756. for (int p = 0; p < precision; p++)
  2757. {
  2758. number *= 10;
  2759. long d = (long)(number);
  2760. m_input_CharArray[index++] = (char)(d + 48);
  2761. number -= d;
  2762. }
  2763. }
  2764. }
  2765. /// <summary>
  2766. /// // Function used in conjunction with SetText()
  2767. /// </summary>
  2768. /// <param name="number"></param>
  2769. /// <param name="index"></param>
  2770. /// <param name="precision"></param>
  2771. protected void AddIntToCharArray(double number, ref int index, int precision)
  2772. {
  2773. if (number < 0)
  2774. {
  2775. m_input_CharArray[index++] = '-';
  2776. number = -number;
  2777. }
  2778. int i = index;
  2779. do
  2780. {
  2781. m_input_CharArray[i++] = (char)(number % 10 + 48);
  2782. number /= 10;
  2783. } while (number > 0.999d);
  2784. int lastIndex = i;
  2785. // Reverse string
  2786. while (index + 1 < i)
  2787. {
  2788. i -= 1;
  2789. char t = m_input_CharArray[index];
  2790. m_input_CharArray[index] = m_input_CharArray[i];
  2791. m_input_CharArray[i] = t;
  2792. index += 1;
  2793. }
  2794. index = lastIndex;
  2795. }
  2796. /// <summary>
  2797. /// Method used to determine the number of visible characters and required buffer allocations.
  2798. /// </summary>
  2799. /// <param name="chars"></param>
  2800. /// <returns></returns>
  2801. protected virtual int SetArraySizes(UnicodeChar[] chars) { return 0; }
  2802. /// <summary>
  2803. /// Method which parses the text input, does the layout of the text as well as generating the geometry.
  2804. /// </summary>
  2805. protected virtual void GenerateTextMesh() { }
  2806. /// <summary>
  2807. /// Function to Calculate the Preferred Width and Height of the text object.
  2808. /// </summary>
  2809. /// <returns></returns>
  2810. public Vector2 GetPreferredValues()
  2811. {
  2812. if (m_isInputParsingRequired || m_isTextTruncated)
  2813. {
  2814. m_isCalculatingPreferredValues = true;
  2815. ParseInputText();
  2816. }
  2817. // CALCULATE PREFERRED WIDTH
  2818. float preferredWidth = GetPreferredWidth();
  2819. // CALCULATE PREFERRED HEIGHT
  2820. float preferredHeight = GetPreferredHeight();
  2821. return new Vector2(preferredWidth, preferredHeight);
  2822. }
  2823. /// <summary>
  2824. /// Function to Calculate the Preferred Width and Height of the text object given the provided width and height.
  2825. /// </summary>
  2826. /// <returns></returns>
  2827. public Vector2 GetPreferredValues(float width, float height)
  2828. {
  2829. if (m_isInputParsingRequired || m_isTextTruncated)
  2830. {
  2831. m_isCalculatingPreferredValues = true;
  2832. ParseInputText();
  2833. }
  2834. Vector2 margin = new Vector2(width, height);
  2835. // CALCULATE PREFERRED WIDTH
  2836. float preferredWidth = GetPreferredWidth(margin);
  2837. // CALCULATE PREFERRED HEIGHT
  2838. float preferredHeight = GetPreferredHeight(margin);
  2839. return new Vector2(preferredWidth, preferredHeight);
  2840. }
  2841. /// <summary>
  2842. /// Function to Calculate the Preferred Width and Height of the text object given a certain string.
  2843. /// </summary>
  2844. /// <param name="text"></param>
  2845. /// <returns></returns>
  2846. public Vector2 GetPreferredValues(string text)
  2847. {
  2848. m_isCalculatingPreferredValues = true;
  2849. StringToCharArray(text, ref m_TextParsingBuffer);
  2850. SetArraySizes(m_TextParsingBuffer);
  2851. Vector2 margin = k_LargePositiveVector2;
  2852. // CALCULATE PREFERRED WIDTH
  2853. float preferredWidth = GetPreferredWidth(margin);
  2854. // CALCULATE PREFERRED HEIGHT
  2855. float preferredHeight = GetPreferredHeight(margin);
  2856. return new Vector2(preferredWidth, preferredHeight);
  2857. }
  2858. /// <summary>
  2859. /// Function to Calculate the Preferred Width and Height of the text object given a certain string and size of text container.
  2860. /// </summary>
  2861. /// <param name="text"></param>
  2862. /// <returns></returns>
  2863. public Vector2 GetPreferredValues(string text, float width, float height)
  2864. {
  2865. m_isCalculatingPreferredValues = true;
  2866. StringToCharArray(text, ref m_TextParsingBuffer);
  2867. SetArraySizes(m_TextParsingBuffer);
  2868. Vector2 margin = new Vector2(width, height);
  2869. // CALCULATE PREFERRED WIDTH
  2870. float preferredWidth = GetPreferredWidth(margin);
  2871. // CALCULATE PREFERRED HEIGHT
  2872. float preferredHeight = GetPreferredHeight(margin);
  2873. return new Vector2(preferredWidth, preferredHeight);
  2874. }
  2875. /// <summary>
  2876. /// Method to calculate the preferred width of a text object.
  2877. /// </summary>
  2878. /// <returns></returns>
  2879. protected float GetPreferredWidth()
  2880. {
  2881. if (TMP_Settings.instance == null) return 0;
  2882. float fontSize = m_enableAutoSizing ? m_fontSizeMax : m_fontSize;
  2883. // Reset auto sizing point size bounds
  2884. m_minFontSize = m_fontSizeMin;
  2885. m_maxFontSize = m_fontSizeMax;
  2886. m_charWidthAdjDelta = 0;
  2887. // Set Margins to Infinity
  2888. Vector2 margin = k_LargePositiveVector2;
  2889. if (m_isInputParsingRequired || m_isTextTruncated)
  2890. {
  2891. m_isCalculatingPreferredValues = true;
  2892. ParseInputText();
  2893. }
  2894. m_recursiveCount = 0;
  2895. float preferredWidth = CalculatePreferredValues(fontSize, margin, true).x;
  2896. m_isPreferredWidthDirty = false;
  2897. //Debug.Log("GetPreferredWidth() Called at frame " + Time.frameCount + ". Returning width of " + preferredWidth);
  2898. return preferredWidth;
  2899. }
  2900. /// <summary>
  2901. /// Method to calculate the preferred width of a text object.
  2902. /// </summary>
  2903. /// <param name="margin"></param>
  2904. /// <returns></returns>
  2905. protected float GetPreferredWidth(Vector2 margin)
  2906. {
  2907. float fontSize = m_enableAutoSizing ? m_fontSizeMax : m_fontSize;
  2908. // Reset auto sizing point size bounds
  2909. m_minFontSize = m_fontSizeMin;
  2910. m_maxFontSize = m_fontSizeMax;
  2911. m_charWidthAdjDelta = 0;
  2912. m_recursiveCount = 0;
  2913. float preferredWidth = CalculatePreferredValues(fontSize, margin, true).x;
  2914. //Debug.Log("GetPreferredWidth() Called. Returning width of " + preferredWidth);
  2915. return preferredWidth;
  2916. }
  2917. /// <summary>
  2918. /// Method to calculate the preferred height of a text object.
  2919. /// </summary>
  2920. /// <returns></returns>
  2921. protected float GetPreferredHeight()
  2922. {
  2923. if (TMP_Settings.instance == null) return 0;
  2924. float fontSize = m_enableAutoSizing ? m_fontSizeMax : m_fontSize;
  2925. // Reset auto sizing point size bounds
  2926. m_minFontSize = m_fontSizeMin;
  2927. m_maxFontSize = m_fontSizeMax;
  2928. m_charWidthAdjDelta = 0;
  2929. Vector2 margin = new Vector2(m_marginWidth != 0 ? m_marginWidth : k_LargePositiveFloat, k_LargePositiveFloat);
  2930. if (m_isInputParsingRequired || m_isTextTruncated)
  2931. {
  2932. m_isCalculatingPreferredValues = true;
  2933. ParseInputText();
  2934. }
  2935. m_recursiveCount = 0;
  2936. float preferredHeight = CalculatePreferredValues(fontSize, margin, !m_enableAutoSizing).y;
  2937. m_isPreferredHeightDirty = false;
  2938. //Debug.Log("GetPreferredHeight() Called. Returning height of " + preferredHeight);
  2939. return preferredHeight;
  2940. }
  2941. /// <summary>
  2942. /// Method to calculate the preferred height of a text object.
  2943. /// </summary>
  2944. /// <param name="margin"></param>
  2945. /// <returns></returns>
  2946. protected float GetPreferredHeight(Vector2 margin)
  2947. {
  2948. float fontSize = m_enableAutoSizing ? m_fontSizeMax : m_fontSize;
  2949. // Reset auto sizing point size bounds
  2950. m_minFontSize = m_fontSizeMin;
  2951. m_maxFontSize = m_fontSizeMax;
  2952. m_charWidthAdjDelta = 0;
  2953. m_recursiveCount = 0;
  2954. float preferredHeight = CalculatePreferredValues(fontSize, margin, true).y;
  2955. //Debug.Log("GetPreferredHeight() Called. Returning height of " + preferredHeight);
  2956. return preferredHeight;
  2957. }
  2958. /// <summary>
  2959. /// Method returning the rendered width and height of the text object.
  2960. /// </summary>
  2961. /// <returns></returns>
  2962. public Vector2 GetRenderedValues()
  2963. {
  2964. return GetTextBounds().size;
  2965. }
  2966. /// <summary>
  2967. ///
  2968. /// </summary>
  2969. /// <param name="onlyVisibleCharacters">Should returned value only factor in visible characters and exclude those greater than maxVisibleCharacters for instance.</param>
  2970. /// <returns></returns>
  2971. public Vector2 GetRenderedValues(bool onlyVisibleCharacters)
  2972. {
  2973. return GetTextBounds(onlyVisibleCharacters).size;
  2974. }
  2975. /// <summary>
  2976. /// Method returning the rendered width of the text object.
  2977. /// </summary>
  2978. /// <returns></returns>
  2979. protected float GetRenderedWidth()
  2980. {
  2981. return GetRenderedValues().x;
  2982. }
  2983. /// <summary>
  2984. /// Method returning the rendered width of the text object.
  2985. /// </summary>
  2986. /// <returns></returns>
  2987. protected float GetRenderedWidth(bool onlyVisibleCharacters)
  2988. {
  2989. return GetRenderedValues(onlyVisibleCharacters).x;
  2990. }
  2991. /// <summary>
  2992. /// Method returning the rendered height of the text object.
  2993. /// </summary>
  2994. /// <returns></returns>
  2995. protected float GetRenderedHeight()
  2996. {
  2997. return GetRenderedValues().y;
  2998. }
  2999. /// <summary>
  3000. /// Method returning the rendered height of the text object.
  3001. /// </summary>
  3002. /// <returns></returns>
  3003. protected float GetRenderedHeight(bool onlyVisibleCharacters)
  3004. {
  3005. return GetRenderedValues(onlyVisibleCharacters).y;
  3006. }
  3007. /// <summary>
  3008. /// Method to calculate the preferred width and height of the text object.
  3009. /// </summary>
  3010. /// <returns></returns>
  3011. protected virtual Vector2 CalculatePreferredValues(float defaultFontSize, Vector2 marginSize, bool ignoreTextAutoSizing)
  3012. {
  3013. //Debug.Log("*** CalculatePreferredValues() ***"); // ***** Frame: " + Time.frameCount);
  3014. ////Profiler.BeginSample("TMP Generate Text - Phase I");
  3015. // Early exit if no font asset was assigned. This should not be needed since LiberationSans SDF will be assigned by default.
  3016. if (m_fontAsset == null || m_fontAsset.characterLookupTable == null)
  3017. {
  3018. Debug.LogWarning("Can't Generate Mesh! No Font Asset has been assigned to Object ID: " + this.GetInstanceID());
  3019. return Vector2.zero;
  3020. }
  3021. // Early exit if we don't have any Text to generate.
  3022. if (m_TextParsingBuffer == null || m_TextParsingBuffer.Length == 0 || m_TextParsingBuffer[0].unicode == (char)0)
  3023. {
  3024. return Vector2.zero;
  3025. }
  3026. m_currentFontAsset = m_fontAsset;
  3027. m_currentMaterial = m_sharedMaterial;
  3028. m_currentMaterialIndex = 0;
  3029. m_materialReferenceStack.SetDefault(new MaterialReference(0, m_currentFontAsset, null, m_currentMaterial, m_padding));
  3030. // Total character count is computed when the text is parsed.
  3031. int totalCharacterCount = m_totalCharacterCount; // m_VisibleCharacters.Count;
  3032. if (m_internalCharacterInfo == null || totalCharacterCount > m_internalCharacterInfo.Length)
  3033. {
  3034. m_internalCharacterInfo = new TMP_CharacterInfo[totalCharacterCount > 1024 ? totalCharacterCount + 256 : Mathf.NextPowerOfTwo(totalCharacterCount)];
  3035. }
  3036. // Calculate the scale of the font based on selected font size and sampling point size.
  3037. // baseScale is calculated using the font asset assigned to the text object.
  3038. float baseScale = m_fontScale = (defaultFontSize / m_fontAsset.faceInfo.pointSize * m_fontAsset.faceInfo.scale * (m_isOrthographic ? 1 : 0.1f));
  3039. float currentElementScale = baseScale;
  3040. m_fontScaleMultiplier = 1;
  3041. m_currentFontSize = defaultFontSize;
  3042. m_sizeStack.SetDefault(m_currentFontSize);
  3043. float fontSizeDelta = 0;
  3044. int charCode = 0; // Holds the character code of the currently being processed character.
  3045. m_FontStyleInternal = m_fontStyle; // Set the default style.
  3046. m_lineJustification = m_textAlignment; // Sets the line justification mode to match editor alignment.
  3047. m_lineJustificationStack.SetDefault(m_lineJustification);
  3048. float bold_xAdvance_multiplier = 1; // Used to increase spacing between character when style is bold.
  3049. m_baselineOffset = 0; // Used by subscript characters.
  3050. m_baselineOffsetStack.Clear();
  3051. m_lineOffset = 0; // Amount of space between lines (font line spacing + m_linespacing).
  3052. m_lineHeight = TMP_Math.FLOAT_UNSET;
  3053. float lineGap = m_currentFontAsset.faceInfo.lineHeight - (m_currentFontAsset.faceInfo.ascentLine - m_currentFontAsset.faceInfo.descentLine);
  3054. m_cSpacing = 0; // Amount of space added between characters as a result of the use of the <cspace> tag.
  3055. m_monoSpacing = 0;
  3056. float lineOffsetDelta = 0;
  3057. m_xAdvance = 0; // Used to track the position of each character.
  3058. float maxXAdvance = 0; // Used to determine Preferred Width.
  3059. tag_LineIndent = 0; // Used for indentation of text.
  3060. tag_Indent = 0;
  3061. m_indentStack.SetDefault(0);
  3062. tag_NoParsing = false;
  3063. //m_isIgnoringAlignment = false;
  3064. m_characterCount = 0; // Total characters in the char[]
  3065. // Tracking of line information
  3066. m_firstCharacterOfLine = 0;
  3067. m_maxLineAscender = k_LargeNegativeFloat;
  3068. m_maxLineDescender = k_LargePositiveFloat;
  3069. m_lineNumber = 0;
  3070. float marginWidth = marginSize.x;
  3071. //float marginHeight = marginSize.y;
  3072. m_marginLeft = 0;
  3073. m_marginRight = 0;
  3074. m_width = -1;
  3075. // Used by Unity's Auto Layout system.
  3076. float renderedWidth = 0;
  3077. float renderedHeight = 0;
  3078. float linebreakingWidth = 0;
  3079. m_isCalculatingPreferredValues = true;
  3080. // Tracking of the highest Ascender
  3081. m_maxAscender = 0;
  3082. m_maxDescender = 0;
  3083. // Initialize struct to track states of word wrapping
  3084. bool isFirstWord = true;
  3085. bool isLastBreakingChar = false;
  3086. WordWrapState savedLineState = new WordWrapState();
  3087. SaveWordWrappingState(ref savedLineState, 0, 0);
  3088. WordWrapState savedWordWrapState = new WordWrapState();
  3089. int wrappingIndex = 0;
  3090. // Counter to prevent recursive lockup when computing preferred values.
  3091. m_recursiveCount += 1;
  3092. // Parse through Character buffer to read HTML tags and begin creating mesh.
  3093. for (int i = 0; m_TextParsingBuffer[i].unicode != 0; i++)
  3094. {
  3095. charCode = (int)m_TextParsingBuffer[i].unicode;
  3096. // Parse Rich Text Tag
  3097. #region Parse Rich Text Tag
  3098. if (m_isRichText && charCode == 60) // '<'
  3099. {
  3100. m_isParsingText = true;
  3101. m_textElementType = TMP_TextElementType.Character;
  3102. int endTagIndex;
  3103. // Check if Tag is valid. If valid, skip to the end of the validated tag.
  3104. if (ValidateHtmlTag(m_TextParsingBuffer, i + 1, out endTagIndex))
  3105. {
  3106. i = endTagIndex;
  3107. // Continue to next character or handle the sprite element
  3108. if (m_textElementType == TMP_TextElementType.Character)
  3109. continue;
  3110. }
  3111. }
  3112. else
  3113. {
  3114. m_textElementType = m_textInfo.characterInfo[m_characterCount].elementType;
  3115. m_currentMaterialIndex = m_textInfo.characterInfo[m_characterCount].materialReferenceIndex;
  3116. m_currentFontAsset = m_textInfo.characterInfo[m_characterCount].fontAsset;
  3117. }
  3118. #endregion End Parse Rich Text Tag
  3119. int prev_MaterialIndex = m_currentMaterialIndex;
  3120. bool isUsingAltTypeface = m_textInfo.characterInfo[m_characterCount].isUsingAlternateTypeface;
  3121. m_isParsingText = false;
  3122. // Handle Font Styles like LowerCase, UpperCase and SmallCaps.
  3123. #region Handling of LowerCase, UpperCase and SmallCaps Font Styles
  3124. float smallCapsMultiplier = 1.0f;
  3125. if (m_textElementType == TMP_TextElementType.Character)
  3126. {
  3127. if (/*(m_fontStyle & FontStyles.UpperCase) == FontStyles.UpperCase ||*/ (m_FontStyleInternal & FontStyles.UpperCase) == FontStyles.UpperCase)
  3128. {
  3129. // If this character is lowercase, switch to uppercase.
  3130. if (char.IsLower((char)charCode))
  3131. charCode = char.ToUpper((char)charCode);
  3132. }
  3133. else if (/*(m_fontStyle & FontStyles.LowerCase) == FontStyles.LowerCase ||*/ (m_FontStyleInternal & FontStyles.LowerCase) == FontStyles.LowerCase)
  3134. {
  3135. // If this character is uppercase, switch to lowercase.
  3136. if (char.IsUpper((char)charCode))
  3137. charCode = char.ToLower((char)charCode);
  3138. }
  3139. else if (/*(m_fontStyle & FontStyles.SmallCaps) == FontStyles.SmallCaps ||*/ (m_FontStyleInternal & FontStyles.SmallCaps) == FontStyles.SmallCaps)
  3140. {
  3141. if (char.IsLower((char)charCode))
  3142. {
  3143. smallCapsMultiplier = 0.8f;
  3144. charCode = char.ToUpper((char)charCode);
  3145. }
  3146. }
  3147. }
  3148. #endregion
  3149. // Look up Character Data from Dictionary and cache it.
  3150. #region Look up Character Data
  3151. if (m_textElementType == TMP_TextElementType.Sprite)
  3152. {
  3153. // If a sprite is used as a fallback then get a reference to it and set the color to white.
  3154. m_currentSpriteAsset = m_textInfo.characterInfo[m_characterCount].spriteAsset;
  3155. m_spriteIndex = m_textInfo.characterInfo[m_characterCount].spriteIndex;
  3156. TMP_SpriteCharacter sprite = m_currentSpriteAsset.spriteCharacterTable[m_spriteIndex];
  3157. if (sprite == null) continue;
  3158. // Sprites are assigned in the E000 Private Area + sprite Index
  3159. if (charCode == 60)
  3160. charCode = 57344 + m_spriteIndex;
  3161. m_currentFontAsset = m_fontAsset;
  3162. // The sprite scale calculations are based on the font asset assigned to the text object.
  3163. // Sprite scale is used to determine line height
  3164. // Current element scale represents a modified scale to normalize the sprite based on the font baseline to ascender.
  3165. float spriteScale = (m_currentFontSize / m_fontAsset.faceInfo.pointSize * m_fontAsset.faceInfo.scale * (m_isOrthographic ? 1 : 0.1f));
  3166. currentElementScale = m_fontAsset.faceInfo.ascentLine / sprite.glyph.metrics.height * sprite.scale * spriteScale;
  3167. m_cached_TextElement = sprite;
  3168. m_internalCharacterInfo[m_characterCount].elementType = TMP_TextElementType.Sprite;
  3169. m_internalCharacterInfo[m_characterCount].scale = spriteScale;
  3170. //m_internalCharacterInfo[m_characterCount].spriteAsset = m_currentSpriteAsset;
  3171. //m_internalCharacterInfo[m_characterCount].fontAsset = m_currentFontAsset;
  3172. //m_internalCharacterInfo[m_characterCount].materialReferenceIndex = m_currentMaterialIndex;
  3173. m_currentMaterialIndex = prev_MaterialIndex;
  3174. }
  3175. else if (m_textElementType == TMP_TextElementType.Character)
  3176. {
  3177. m_cached_TextElement = m_textInfo.characterInfo[m_characterCount].textElement;
  3178. if (m_cached_TextElement == null) continue;
  3179. //m_currentFontAsset = m_textInfo.characterInfo[m_characterCount].fontAsset;
  3180. //m_currentMaterial = m_textInfo.characterInfo[m_characterCount].material;
  3181. m_currentMaterialIndex = m_textInfo.characterInfo[m_characterCount].materialReferenceIndex;
  3182. // Re-calculate font scale as the font asset may have changed.
  3183. m_fontScale = m_currentFontSize * smallCapsMultiplier / m_currentFontAsset.faceInfo.pointSize * m_currentFontAsset.faceInfo.scale * (m_isOrthographic ? 1 : 0.1f);
  3184. currentElementScale = m_fontScale * m_fontScaleMultiplier * m_cached_TextElement.scale;
  3185. m_internalCharacterInfo[m_characterCount].elementType = TMP_TextElementType.Character;
  3186. }
  3187. #endregion
  3188. // Handle Soft Hyphen
  3189. #region Handle Soft Hyphen
  3190. float old_scale = currentElementScale;
  3191. if (charCode == 0xAD)
  3192. {
  3193. currentElementScale = 0;
  3194. }
  3195. #endregion
  3196. // Store some of the text object's information
  3197. m_internalCharacterInfo[m_characterCount].character = (char)charCode;
  3198. // Handle Kerning if Enabled.
  3199. #region Handle Kerning
  3200. TMP_GlyphValueRecord glyphAdjustments = new TMP_GlyphValueRecord();
  3201. float characterSpacingAdjustment = m_characterSpacing;
  3202. if (m_enableKerning)
  3203. {
  3204. TMP_GlyphPairAdjustmentRecord adjustmentPair;
  3205. if (m_characterCount < totalCharacterCount - 1)
  3206. {
  3207. uint firstGlyphIndex = m_cached_TextElement.glyphIndex;
  3208. uint secondGlyphIndex = m_textInfo.characterInfo[m_characterCount + 1].textElement.glyphIndex;
  3209. long key = new GlyphPairKey(firstGlyphIndex, secondGlyphIndex).key;
  3210. if (m_currentFontAsset.fontFeatureTable.m_GlyphPairAdjustmentRecordLookupDictionary.TryGetValue(key, out adjustmentPair))
  3211. {
  3212. glyphAdjustments = adjustmentPair.firstAdjustmentRecord.glyphValueRecord;
  3213. characterSpacingAdjustment = (adjustmentPair.featureLookupFlags & FontFeatureLookupFlags.IgnoreSpacingAdjustments) == FontFeatureLookupFlags.IgnoreSpacingAdjustments ? 0 : characterSpacingAdjustment;
  3214. }
  3215. }
  3216. if (m_characterCount >= 1)
  3217. {
  3218. uint firstGlyphIndex = m_textInfo.characterInfo[m_characterCount - 1].textElement.glyphIndex;
  3219. uint secondGlyphIndex = m_cached_TextElement.glyphIndex;
  3220. long key = new GlyphPairKey(firstGlyphIndex, secondGlyphIndex).key;
  3221. if (m_currentFontAsset.fontFeatureTable.m_GlyphPairAdjustmentRecordLookupDictionary.TryGetValue(key, out adjustmentPair))
  3222. {
  3223. glyphAdjustments += adjustmentPair.secondAdjustmentRecord.glyphValueRecord;
  3224. characterSpacingAdjustment = (adjustmentPair.featureLookupFlags & FontFeatureLookupFlags.IgnoreSpacingAdjustments) == FontFeatureLookupFlags.IgnoreSpacingAdjustments ? 0 : characterSpacingAdjustment;
  3225. }
  3226. }
  3227. }
  3228. #endregion
  3229. // Initial Implementation for RTL support.
  3230. #region Handle Right-to-Left
  3231. //if (m_isRightToLeft)
  3232. //{
  3233. // m_xAdvance -= ((m_cached_TextElement.xAdvance * bold_xAdvance_multiplier + m_characterSpacing + m_wordSpacing + m_currentFontAsset.normalSpacingOffset) * currentElementScale + m_cSpacing) * (1 - m_charWidthAdjDelta);
  3234. // if (char.IsWhiteSpace((char)charCode) || charCode == 0x200B)
  3235. // m_xAdvance -= m_wordSpacing * currentElementScale;
  3236. //}
  3237. #endregion
  3238. // Handle Mono Spacing
  3239. #region Handle Mono Spacing
  3240. float monoAdvance = 0;
  3241. if (m_monoSpacing != 0)
  3242. {
  3243. monoAdvance = (m_monoSpacing / 2 - (m_cached_TextElement.glyph.metrics.width / 2 + m_cached_TextElement.glyph.metrics.horizontalBearingX) * currentElementScale);
  3244. m_xAdvance += monoAdvance;
  3245. }
  3246. #endregion
  3247. // Set Padding based on selected font style
  3248. #region Handle Style Padding
  3249. if (m_textElementType == TMP_TextElementType.Character && !isUsingAltTypeface && ((m_FontStyleInternal & FontStyles.Bold) == FontStyles.Bold)) // Checks for any combination of Bold Style.
  3250. {
  3251. bold_xAdvance_multiplier = 1 + m_currentFontAsset.boldSpacing * 0.01f;
  3252. }
  3253. else
  3254. {
  3255. //style_padding = m_currentFontAsset.normalStyle * 2;
  3256. bold_xAdvance_multiplier = 1.0f;
  3257. }
  3258. #endregion Handle Style Padding
  3259. m_internalCharacterInfo[m_characterCount].baseLine = 0 - m_lineOffset + m_baselineOffset;
  3260. // Compute and save text element Ascender and maximum line Ascender.
  3261. float elementAscender = m_currentFontAsset.faceInfo.ascentLine * (m_textElementType == TMP_TextElementType.Character ? currentElementScale / smallCapsMultiplier : m_internalCharacterInfo[m_characterCount].scale) + m_baselineOffset;
  3262. m_internalCharacterInfo[m_characterCount].ascender = elementAscender - m_lineOffset;
  3263. m_maxLineAscender = elementAscender > m_maxLineAscender ? elementAscender : m_maxLineAscender;
  3264. // Compute and save text element Descender and maximum line Descender.
  3265. float elementDescender = m_currentFontAsset.faceInfo.descentLine * (m_textElementType == TMP_TextElementType.Character ? currentElementScale / smallCapsMultiplier: m_internalCharacterInfo[m_characterCount].scale) + m_baselineOffset;
  3266. float elementDescenderII = m_internalCharacterInfo[m_characterCount].descender = elementDescender - m_lineOffset;
  3267. m_maxLineDescender = elementDescender < m_maxLineDescender ? elementDescender : m_maxLineDescender;
  3268. // Adjust maxLineAscender and maxLineDescender if style is superscript or subscript
  3269. if ((m_FontStyleInternal & FontStyles.Subscript) == FontStyles.Subscript || (m_FontStyleInternal & FontStyles.Superscript) == FontStyles.Superscript)
  3270. {
  3271. float baseAscender = (elementAscender - m_baselineOffset) / m_currentFontAsset.faceInfo.subscriptSize;
  3272. elementAscender = m_maxLineAscender;
  3273. m_maxLineAscender = baseAscender > m_maxLineAscender ? baseAscender : m_maxLineAscender;
  3274. float baseDescender = (elementDescender - m_baselineOffset) / m_currentFontAsset.faceInfo.subscriptSize;
  3275. elementDescender = m_maxLineDescender;
  3276. m_maxLineDescender = baseDescender < m_maxLineDescender ? baseDescender : m_maxLineDescender;
  3277. }
  3278. if (m_lineNumber == 0) m_maxAscender = m_maxAscender > elementAscender ? m_maxAscender : elementAscender;
  3279. //if (m_lineOffset == 0) pageAscender = pageAscender > elementAscender ? pageAscender : elementAscender;
  3280. // Setup Mesh for visible text elements. ie. not a SPACE / LINEFEED / CARRIAGE RETURN.
  3281. #region Handle Visible Characters
  3282. if (charCode == 9 || charCode == 0xA0 || charCode == 0x2007 || (!char.IsWhiteSpace((char)charCode) && charCode != 0x200B) || m_textElementType == TMP_TextElementType.Sprite)
  3283. {
  3284. // Check if Character exceeds the width of the Text Container
  3285. #region Handle Line Breaking, Text Auto-Sizing and Horizontal Overflow
  3286. float width = m_width != -1 ? Mathf.Min(marginWidth + 0.0001f - m_marginLeft - m_marginRight, m_width) : marginWidth + 0.0001f - m_marginLeft - m_marginRight;
  3287. bool isJustifiedOrFlush = ((_HorizontalAlignmentOptions)m_lineJustification & _HorizontalAlignmentOptions.Flush) == _HorizontalAlignmentOptions.Flush || ((_HorizontalAlignmentOptions)m_lineJustification & _HorizontalAlignmentOptions.Justified) == _HorizontalAlignmentOptions.Justified;
  3288. // Calculate the line breaking width of the text.
  3289. linebreakingWidth = m_xAdvance + m_cached_TextElement.glyph.metrics.horizontalAdvance * (1 - m_charWidthAdjDelta) * (charCode != 0xAD ? currentElementScale : old_scale);
  3290. // Check if Character exceeds the width of the Text Container
  3291. if (linebreakingWidth > width * (isJustifiedOrFlush ? 1.05f : 1.0f))
  3292. {
  3293. // Word Wrapping
  3294. #region Handle Word Wrapping
  3295. if (enableWordWrapping && m_characterCount != m_firstCharacterOfLine)
  3296. {
  3297. // Check if word wrapping is still possible
  3298. #region Line Breaking Check
  3299. if (wrappingIndex == savedWordWrapState.previous_WordBreak || isFirstWord)
  3300. {
  3301. // Word wrapping is no longer possible. Shrink size of text if auto-sizing is enabled.
  3302. #region Text Auto-Sizing
  3303. if (ignoreTextAutoSizing == false && m_currentFontSize > m_fontSizeMin)
  3304. {
  3305. // Handle Character Width Adjustments
  3306. #region Character Width Adjustments
  3307. if (m_charWidthAdjDelta < m_charWidthMaxAdj / 100)
  3308. {
  3309. m_recursiveCount = 0;
  3310. m_charWidthAdjDelta += 0.01f;
  3311. return CalculatePreferredValues(defaultFontSize, marginSize, false);
  3312. }
  3313. #endregion
  3314. // Adjust Point Size
  3315. m_maxFontSize = defaultFontSize;
  3316. defaultFontSize -= Mathf.Max((defaultFontSize - m_minFontSize) / 2, 0.05f);
  3317. defaultFontSize = (int)(Mathf.Max(defaultFontSize, m_fontSizeMin) * 20 + 0.5f) / 20f;
  3318. if (m_recursiveCount > 20) return new Vector2(renderedWidth, renderedHeight);
  3319. return CalculatePreferredValues(defaultFontSize, marginSize, false);
  3320. }
  3321. #endregion
  3322. // Word wrapping is no longer possible, now breaking up individual words.
  3323. if (m_isCharacterWrappingEnabled == false)
  3324. {
  3325. m_isCharacterWrappingEnabled = true;
  3326. }
  3327. else
  3328. isLastBreakingChar = true;
  3329. }
  3330. #endregion
  3331. // Restore to previously stored state of last valid (space character or linefeed)
  3332. i = RestoreWordWrappingState(ref savedWordWrapState);
  3333. wrappingIndex = i; // Used to detect when line length can no longer be reduced.
  3334. // Handling for Soft Hyphen
  3335. if (m_TextParsingBuffer[i].unicode == 0xAD) // && !m_isCharacterWrappingEnabled) // && ellipsisIndex != i && !m_isCharacterWrappingEnabled)
  3336. {
  3337. m_isTextTruncated = true;
  3338. m_TextParsingBuffer[i].unicode = 0x2D;
  3339. return CalculatePreferredValues(defaultFontSize, marginSize, true);
  3340. }
  3341. // Check if Line Spacing of previous line needs to be adjusted.
  3342. if (m_lineNumber > 0 && !TMP_Math.Approximately(m_maxLineAscender, m_startOfLineAscender) && m_lineHeight == TMP_Math.FLOAT_UNSET)
  3343. {
  3344. //Debug.Log("(1) Adjusting Line Spacing on line #" + m_lineNumber);
  3345. float offsetDelta = m_maxLineAscender - m_startOfLineAscender;
  3346. //AdjustLineOffset(m_firstCharacterOfLine, m_characterCount, offsetDelta);
  3347. m_lineOffset += offsetDelta;
  3348. savedWordWrapState.lineOffset = m_lineOffset;
  3349. savedWordWrapState.previousLineAscender = m_maxLineAscender;
  3350. // TODO - Add check for character exceeding vertical bounds
  3351. }
  3352. //m_isNewPage = false;
  3353. // Calculate lineAscender & make sure if last character is superscript or subscript that we check that as well.
  3354. float lineAscender = m_maxLineAscender - m_lineOffset;
  3355. float lineDescender = m_maxLineDescender - m_lineOffset;
  3356. // Update maxDescender and maxVisibleDescender
  3357. m_maxDescender = m_maxDescender < lineDescender ? m_maxDescender : lineDescender;
  3358. m_firstCharacterOfLine = m_characterCount; // Store first character of the next line.
  3359. // Compute Preferred Width & Height
  3360. renderedWidth += m_xAdvance;
  3361. if (m_enableWordWrapping)
  3362. renderedHeight = m_maxAscender - m_maxDescender;
  3363. else
  3364. renderedHeight = Mathf.Max(renderedHeight, lineAscender - lineDescender);
  3365. // Store the state of the line before starting on the new line.
  3366. SaveWordWrappingState(ref savedLineState, i, m_characterCount - 1);
  3367. m_lineNumber += 1;
  3368. //isStartOfNewLine = true;
  3369. // Check to make sure Array is large enough to hold a new line.
  3370. //if (m_lineNumber >= m_internalTextInfo.lineInfo.Length)
  3371. // ResizeLineExtents(m_lineNumber);
  3372. // Apply Line Spacing based on scale of the last character of the line.
  3373. if (m_lineHeight == TMP_Math.FLOAT_UNSET)
  3374. {
  3375. float ascender = m_internalCharacterInfo[m_characterCount].ascender - m_internalCharacterInfo[m_characterCount].baseLine;
  3376. lineOffsetDelta = 0 - m_maxLineDescender + ascender + (lineGap + m_lineSpacing + m_lineSpacingDelta) * baseScale;
  3377. m_lineOffset += lineOffsetDelta;
  3378. m_startOfLineAscender = ascender;
  3379. }
  3380. else
  3381. m_lineOffset += m_lineHeight + m_lineSpacing * baseScale;
  3382. m_maxLineAscender = k_LargeNegativeFloat;
  3383. m_maxLineDescender = k_LargePositiveFloat;
  3384. m_xAdvance = 0 + tag_Indent;
  3385. continue;
  3386. }
  3387. #endregion End Word Wrapping
  3388. // Text Auto-Sizing (text exceeding Width of container.
  3389. #region Handle Text Auto-Sizing
  3390. if (ignoreTextAutoSizing == false && defaultFontSize > m_fontSizeMin)
  3391. {
  3392. // Handle Character Width Adjustments
  3393. #region Character Width Adjustments
  3394. if (m_charWidthAdjDelta < m_charWidthMaxAdj / 100)
  3395. {
  3396. m_recursiveCount = 0;
  3397. m_charWidthAdjDelta += 0.01f;
  3398. return CalculatePreferredValues(defaultFontSize, marginSize, false);
  3399. }
  3400. #endregion
  3401. // Adjust Point Size
  3402. m_maxFontSize = defaultFontSize;
  3403. defaultFontSize -= Mathf.Max((defaultFontSize - m_minFontSize) / 2, 0.05f);
  3404. defaultFontSize = (int)(Mathf.Max(defaultFontSize, m_fontSizeMin) * 20 + 0.5f) / 20f;
  3405. if (m_recursiveCount > 20) return new Vector2(renderedWidth, renderedHeight);
  3406. return CalculatePreferredValues(defaultFontSize, marginSize, false);
  3407. }
  3408. #endregion End Text Auto-Sizing
  3409. }
  3410. #endregion End Check for Characters Exceeding Width of Text Container
  3411. }
  3412. #endregion Handle Visible Characters
  3413. // Check if Line Spacing of previous line needs to be adjusted.
  3414. #region Adjust Line Spacing
  3415. if (m_lineNumber > 0 && !TMP_Math.Approximately(m_maxLineAscender, m_startOfLineAscender) && m_lineHeight == TMP_Math.FLOAT_UNSET && !m_isNewPage)
  3416. {
  3417. //Debug.Log("Inline - Adjusting Line Spacing on line #" + m_lineNumber);
  3418. //float gap = 0; // Compute gap.
  3419. float offsetDelta = m_maxLineAscender - m_startOfLineAscender;
  3420. //AdjustLineOffset(m_firstCharacterOfLine, m_characterCount, offsetDelta);
  3421. elementDescenderII -= offsetDelta;
  3422. m_lineOffset += offsetDelta;
  3423. m_startOfLineAscender += offsetDelta;
  3424. savedWordWrapState.lineOffset = m_lineOffset;
  3425. savedWordWrapState.previousLineAscender = m_startOfLineAscender;
  3426. }
  3427. #endregion
  3428. // Check if text Exceeds the vertical bounds of the margin area.
  3429. #region Check Vertical Bounds & Auto-Sizing
  3430. /*
  3431. if (m_maxAscender - elementDescenderII > marginHeight + 0.0001f)
  3432. {
  3433. // Handle Line spacing adjustments
  3434. #region Line Spacing Adjustments
  3435. if (m_enableAutoSizing && m_lineSpacingDelta > m_lineSpacingMax && m_lineNumber > 0)
  3436. {
  3437. //loopCountA = 0;
  3438. //m_lineSpacingDelta -= 1;
  3439. //GenerateTextMesh();
  3440. //return;
  3441. }
  3442. #endregion
  3443. // Handle Text Auto-sizing resulting from text exceeding vertical bounds.
  3444. #region Text Auto-Sizing (Text greater than vertical bounds)
  3445. if (m_enableAutoSizing && m_fontSize > m_fontSizeMin)
  3446. {
  3447. m_maxFontSize = m_fontSize;
  3448. m_fontSize -= Mathf.Max((m_fontSize - m_minFontSize) / 2, 0.05f);
  3449. m_fontSize = (int)(Mathf.Max(m_fontSize, m_fontSizeMin) * 20 + 0.5f) / 20f;
  3450. //m_recursiveCount = 0;
  3451. //if (loopCountA > 20) return; // Added to debug
  3452. CalculatePreferredValues(m_fontSize, marginSize, false);
  3453. return Vector2.zero;
  3454. }
  3455. #endregion Text Auto-Sizing
  3456. }
  3457. */
  3458. #endregion Check Vertical Bounds
  3459. // Handle xAdvance & Tabulation Stops. Tab stops at every 25% of Font Size.
  3460. #region XAdvance, Tabulation & Stops
  3461. if (charCode == 9)
  3462. {
  3463. float tabSize = m_currentFontAsset.faceInfo.tabWidth * currentElementScale;
  3464. float tabs = Mathf.Ceil(m_xAdvance / tabSize) * tabSize;
  3465. m_xAdvance = tabs > m_xAdvance ? tabs : m_xAdvance + tabSize;
  3466. }
  3467. else if (m_monoSpacing != 0)
  3468. {
  3469. m_xAdvance += (m_monoSpacing - monoAdvance + ((characterSpacingAdjustment + m_currentFontAsset.normalSpacingOffset) * currentElementScale) + m_cSpacing) * (1 - m_charWidthAdjDelta);
  3470. if (char.IsWhiteSpace((char)charCode) || charCode == 0x200B)
  3471. m_xAdvance += m_wordSpacing * currentElementScale;
  3472. }
  3473. else
  3474. {
  3475. m_xAdvance += ((m_cached_TextElement.glyph.metrics.horizontalAdvance * bold_xAdvance_multiplier + characterSpacingAdjustment + m_currentFontAsset.normalSpacingOffset + glyphAdjustments.xAdvance) * currentElementScale + m_cSpacing) * (1 - m_charWidthAdjDelta);
  3476. if (char.IsWhiteSpace((char)charCode) || charCode == 0x200B)
  3477. m_xAdvance += m_wordSpacing * currentElementScale;
  3478. }
  3479. #endregion Tabulation & Stops
  3480. // Handle Carriage Return
  3481. #region Carriage Return
  3482. if (charCode == 13)
  3483. {
  3484. maxXAdvance = Mathf.Max(maxXAdvance, renderedWidth + m_xAdvance);
  3485. renderedWidth = 0;
  3486. m_xAdvance = 0 + tag_Indent;
  3487. }
  3488. #endregion Carriage Return
  3489. // Handle Line Spacing Adjustments + Word Wrapping & special case for last line.
  3490. #region Check for Line Feed and Last Character
  3491. if (charCode == 10 || m_characterCount == totalCharacterCount - 1)
  3492. {
  3493. // Check if Line Spacing of previous line needs to be adjusted.
  3494. if (m_lineNumber > 0 && !TMP_Math.Approximately(m_maxLineAscender, m_startOfLineAscender) && m_lineHeight == TMP_Math.FLOAT_UNSET)
  3495. {
  3496. //Debug.Log("(2) Adjusting Line Spacing on line #" + m_lineNumber);
  3497. float offsetDelta = m_maxLineAscender - m_startOfLineAscender;
  3498. //AdjustLineOffset(m_firstCharacterOfLine, m_characterCount, offsetDelta);
  3499. elementDescenderII -= offsetDelta;
  3500. m_lineOffset += offsetDelta;
  3501. }
  3502. // Calculate lineAscender & make sure if last character is superscript or subscript that we check that as well.
  3503. //float lineAscender = m_maxLineAscender - m_lineOffset;
  3504. float lineDescender = m_maxLineDescender - m_lineOffset;
  3505. // Update maxDescender and maxVisibleDescender
  3506. m_maxDescender = m_maxDescender < lineDescender ? m_maxDescender : lineDescender;
  3507. m_firstCharacterOfLine = m_characterCount + 1;
  3508. // Store PreferredWidth paying attention to linefeed and last character of text.
  3509. if (charCode == 10 && m_characterCount != totalCharacterCount - 1)
  3510. {
  3511. maxXAdvance = Mathf.Max(maxXAdvance, renderedWidth + linebreakingWidth);
  3512. renderedWidth = 0;
  3513. }
  3514. else
  3515. renderedWidth = Mathf.Max(maxXAdvance, renderedWidth + linebreakingWidth);
  3516. renderedHeight = m_maxAscender - m_maxDescender;
  3517. // Add new line if not last lines or character.
  3518. if (charCode == 10)
  3519. {
  3520. // Store the state of the line before starting on the new line.
  3521. SaveWordWrappingState(ref savedLineState, i, m_characterCount);
  3522. // Store the state of the last Character before the new line.
  3523. SaveWordWrappingState(ref savedWordWrapState, i, m_characterCount);
  3524. m_lineNumber += 1;
  3525. // Apply Line Spacing
  3526. if (m_lineHeight == TMP_Math.FLOAT_UNSET)
  3527. {
  3528. lineOffsetDelta = 0 - m_maxLineDescender + elementAscender + (lineGap + m_lineSpacing + m_paragraphSpacing + m_lineSpacingDelta) * baseScale;
  3529. m_lineOffset += lineOffsetDelta;
  3530. }
  3531. else
  3532. m_lineOffset += m_lineHeight + (m_lineSpacing + m_paragraphSpacing) * baseScale;
  3533. m_maxLineAscender = k_LargeNegativeFloat;
  3534. m_maxLineDescender = k_LargePositiveFloat;
  3535. m_startOfLineAscender = elementAscender;
  3536. m_xAdvance = 0 + tag_LineIndent + tag_Indent;
  3537. m_characterCount += 1;
  3538. continue;
  3539. }
  3540. }
  3541. #endregion Check for Linefeed or Last Character
  3542. // Save State of Mesh Creation for handling of Word Wrapping
  3543. #region Save Word Wrapping State
  3544. if (m_enableWordWrapping || m_overflowMode == TextOverflowModes.Truncate || m_overflowMode == TextOverflowModes.Ellipsis)
  3545. {
  3546. if ((char.IsWhiteSpace((char)charCode) || charCode == 0x200B || charCode == 0x2D || charCode == 0xAD) && !m_isNonBreakingSpace && charCode != 0xA0 && charCode != 0x2011 && charCode != 0x202F && charCode != 0x2060)
  3547. {
  3548. // We store the state of numerous variables for the most recent Space, LineFeed or Carriage Return to enable them to be restored
  3549. // for Word Wrapping.
  3550. SaveWordWrappingState(ref savedWordWrapState, i, m_characterCount);
  3551. m_isCharacterWrappingEnabled = false;
  3552. isFirstWord = false;
  3553. }
  3554. // Handling for East Asian languages
  3555. else if ((charCode > 0x1100 && charCode < 0x11ff || /* Hangul Jamo */
  3556. charCode > 0x2E80 && charCode < 0x9FFF || /* CJK */
  3557. charCode > 0xA960 && charCode < 0xA97F || /* Hangul Jame Extended-A */
  3558. charCode > 0xAC00 && charCode < 0xD7FF || /* Hangul Syllables */
  3559. charCode > 0xF900 && charCode < 0xFAFF || /* CJK Compatibility Ideographs */
  3560. charCode > 0xFE30 && charCode < 0xFE4F || /* CJK Compatibility Forms */
  3561. charCode > 0xFF00 && charCode < 0xFFEF) /* CJK Halfwidth */
  3562. && !m_isNonBreakingSpace)
  3563. {
  3564. if (isFirstWord || isLastBreakingChar || TMP_Settings.linebreakingRules.leadingCharacters.ContainsKey(charCode) == false &&
  3565. (m_characterCount < totalCharacterCount - 1 &&
  3566. TMP_Settings.linebreakingRules.followingCharacters.ContainsKey(m_internalCharacterInfo[m_characterCount + 1].character) == false))
  3567. {
  3568. SaveWordWrappingState(ref savedWordWrapState, i, m_characterCount);
  3569. m_isCharacterWrappingEnabled = false;
  3570. isFirstWord = false;
  3571. }
  3572. }
  3573. else if ((isFirstWord || m_isCharacterWrappingEnabled == true || isLastBreakingChar))
  3574. SaveWordWrappingState(ref savedWordWrapState, i, m_characterCount);
  3575. }
  3576. #endregion Save Word Wrapping State
  3577. m_characterCount += 1;
  3578. }
  3579. // Check Auto Sizing and increase font size to fill text container.
  3580. #region Check Auto-Sizing (Upper Font Size Bounds)
  3581. fontSizeDelta = m_maxFontSize - m_minFontSize;
  3582. if (!m_isCharacterWrappingEnabled && ignoreTextAutoSizing == false && fontSizeDelta > 0.051f && defaultFontSize < m_fontSizeMax)
  3583. {
  3584. m_minFontSize = defaultFontSize;
  3585. defaultFontSize += Mathf.Max((m_maxFontSize - defaultFontSize) / 2, 0.05f);
  3586. defaultFontSize = (int)(Mathf.Min(defaultFontSize, m_fontSizeMax) * 20 + 0.5f) / 20f;
  3587. if (m_recursiveCount > 20) return new Vector2(renderedWidth, renderedHeight);
  3588. return CalculatePreferredValues(defaultFontSize, marginSize, false);
  3589. }
  3590. #endregion End Auto-sizing Check
  3591. m_isCharacterWrappingEnabled = false;
  3592. m_isCalculatingPreferredValues = false;
  3593. // Adjust Preferred Width and Height to account for Margins.
  3594. renderedWidth += m_margin.x > 0 ? m_margin.x : 0;
  3595. renderedWidth += m_margin.z > 0 ? m_margin.z : 0;
  3596. renderedHeight += m_margin.y > 0 ? m_margin.y : 0;
  3597. renderedHeight += m_margin.w > 0 ? m_margin.w : 0;
  3598. // Round Preferred Values to nearest 5/100.
  3599. renderedWidth = (int)(renderedWidth * 100 + 1f) / 100f;
  3600. renderedHeight = (int)(renderedHeight * 100 + 1f) / 100f;
  3601. //Debug.Log("Preferred Values: (" + renderedWidth + ", " + renderedHeight + ") with Recursive count of " + m_recursiveCount);
  3602. ////Profiler.EndSample();
  3603. return new Vector2(renderedWidth, renderedHeight);
  3604. }
  3605. /// <summary>
  3606. /// Method returning the compound bounds of the text object and child sub objects.
  3607. /// </summary>
  3608. /// <returns></returns>
  3609. protected virtual Bounds GetCompoundBounds() { return new Bounds(); }
  3610. /// <summary>
  3611. /// Method which returns the bounds of the text object;
  3612. /// </summary>
  3613. /// <returns></returns>
  3614. protected Bounds GetTextBounds()
  3615. {
  3616. if (m_textInfo == null || m_textInfo.characterCount > m_textInfo.characterInfo.Length) return new Bounds();
  3617. Extents extent = new Extents(k_LargePositiveVector2, k_LargeNegativeVector2);
  3618. for (int i = 0; i < m_textInfo.characterCount && i < m_textInfo.characterInfo.Length; i++)
  3619. {
  3620. if (!m_textInfo.characterInfo[i].isVisible) continue;
  3621. extent.min.x = Mathf.Min(extent.min.x, m_textInfo.characterInfo[i].bottomLeft.x);
  3622. extent.min.y = Mathf.Min(extent.min.y, m_textInfo.characterInfo[i].descender);
  3623. extent.max.x = Mathf.Max(extent.max.x, m_textInfo.characterInfo[i].xAdvance);
  3624. extent.max.y = Mathf.Max(extent.max.y, m_textInfo.characterInfo[i].ascender);
  3625. }
  3626. Vector2 size;
  3627. size.x = extent.max.x - extent.min.x;
  3628. size.y = extent.max.y - extent.min.y;
  3629. Vector3 center = (extent.min + extent.max) / 2;
  3630. return new Bounds(center, size);
  3631. }
  3632. /// <summary>
  3633. /// Method which returns the bounds of the text object;
  3634. /// </summary>
  3635. /// <param name="onlyVisibleCharacters"></param>
  3636. /// <returns></returns>
  3637. protected Bounds GetTextBounds(bool onlyVisibleCharacters)
  3638. {
  3639. if (m_textInfo == null) return new Bounds();
  3640. Extents extent = new Extents(k_LargePositiveVector2, k_LargeNegativeVector2);
  3641. for (int i = 0; i < m_textInfo.characterCount; i++)
  3642. {
  3643. if ((i > maxVisibleCharacters || m_textInfo.characterInfo[i].lineNumber > m_maxVisibleLines) && onlyVisibleCharacters) break;
  3644. if (onlyVisibleCharacters && !m_textInfo.characterInfo[i].isVisible) continue;
  3645. extent.min.x = Mathf.Min(extent.min.x, m_textInfo.characterInfo[i].origin);
  3646. extent.min.y = Mathf.Min(extent.min.y, m_textInfo.characterInfo[i].descender);
  3647. extent.max.x = Mathf.Max(extent.max.x, m_textInfo.characterInfo[i].xAdvance);
  3648. extent.max.y = Mathf.Max(extent.max.y, m_textInfo.characterInfo[i].ascender);
  3649. }
  3650. Vector2 size;
  3651. size.x = extent.max.x - extent.min.x;
  3652. size.y = extent.max.y - extent.min.y;
  3653. Vector2 center = (extent.min + extent.max) / 2;
  3654. return new Bounds(center, size);
  3655. }
  3656. /// <summary>
  3657. /// Method to adjust line spacing as a result of using different fonts or font point size.
  3658. /// </summary>
  3659. /// <param name="startIndex"></param>
  3660. /// <param name="endIndex"></param>
  3661. /// <param name="offset"></param>
  3662. protected virtual void AdjustLineOffset(int startIndex, int endIndex, float offset) { }
  3663. /// <summary>
  3664. /// Function to increase the size of the Line Extents Array.
  3665. /// </summary>
  3666. /// <param name="size"></param>
  3667. protected void ResizeLineExtents(int size)
  3668. {
  3669. size = size > 1024 ? size + 256 : Mathf.NextPowerOfTwo(size + 1);
  3670. TMP_LineInfo[] temp_lineInfo = new TMP_LineInfo[size];
  3671. for (int i = 0; i < size; i++)
  3672. {
  3673. if (i < m_textInfo.lineInfo.Length)
  3674. temp_lineInfo[i] = m_textInfo.lineInfo[i];
  3675. else
  3676. {
  3677. temp_lineInfo[i].lineExtents.min = k_LargePositiveVector2;
  3678. temp_lineInfo[i].lineExtents.max = k_LargeNegativeVector2;
  3679. temp_lineInfo[i].ascender = k_LargeNegativeFloat;
  3680. temp_lineInfo[i].descender = k_LargePositiveFloat;
  3681. }
  3682. }
  3683. m_textInfo.lineInfo = temp_lineInfo;
  3684. }
  3685. protected static Vector2 k_LargePositiveVector2 = new Vector2(TMP_Math.INT_MAX, TMP_Math.INT_MAX);
  3686. protected static Vector2 k_LargeNegativeVector2 = new Vector2(TMP_Math.INT_MIN, TMP_Math.INT_MIN);
  3687. protected static float k_LargePositiveFloat = TMP_Math.FLOAT_MAX;
  3688. protected static float k_LargeNegativeFloat = TMP_Math.FLOAT_MIN;
  3689. protected static int k_LargePositiveInt = TMP_Math.INT_MAX;
  3690. protected static int k_LargeNegativeInt = TMP_Math.INT_MIN;
  3691. /// <summary>
  3692. /// Function used to evaluate the length of a text string.
  3693. /// </summary>
  3694. /// <param name="text"></param>
  3695. /// <returns></returns>
  3696. public virtual TMP_TextInfo GetTextInfo(string text) { return null; }
  3697. /// <summary>
  3698. /// Function to force an update of the margin size.
  3699. /// </summary>
  3700. public virtual void ComputeMarginSize() { }
  3701. /// <summary>
  3702. /// Function used in conjunction with GetTextInfo to figure out Array allocations.
  3703. /// </summary>
  3704. /// <param name="chars"></param>
  3705. /// <returns></returns>
  3706. //protected int GetArraySizes(int[] chars)
  3707. //{
  3708. // //Debug.Log("Set Array Size called.");
  3709. // //int visibleCount = 0;
  3710. // //int totalCount = 0;
  3711. // int tagEnd = 0;
  3712. // m_totalCharacterCount = 0;
  3713. // m_isUsingBold = false;
  3714. // m_isParsingText = false;
  3715. // //m_VisibleCharacters.Clear();
  3716. // for (int i = 0; chars[i] != 0; i++)
  3717. // {
  3718. // int c = chars[i];
  3719. // if (m_isRichText && c == 60) // if Char '<'
  3720. // {
  3721. // // Check if Tag is Valid
  3722. // if (ValidateHtmlTag(chars, i + 1, out tagEnd))
  3723. // {
  3724. // i = tagEnd;
  3725. // //if ((m_style & FontStyles.Underline) == FontStyles.Underline) visibleCount += 3;
  3726. // if ((m_style & FontStyles.Bold) == FontStyles.Bold) m_isUsingBold = true;
  3727. // continue;
  3728. // }
  3729. // }
  3730. // //if (!char.IsWhiteSpace((char)c) && c != 0x200B)
  3731. // //{
  3732. // //visibleCount += 1;
  3733. // //}
  3734. // //m_VisibleCharacters.Add((char)c);
  3735. // m_totalCharacterCount += 1;
  3736. // }
  3737. // return m_totalCharacterCount;
  3738. //}
  3739. /// <summary>
  3740. /// Save the State of various variables used in the mesh creation loop in conjunction with Word Wrapping
  3741. /// </summary>
  3742. /// <param name="state"></param>
  3743. /// <param name="index"></param>
  3744. /// <param name="count"></param>
  3745. protected void SaveWordWrappingState(ref WordWrapState state, int index, int count)
  3746. {
  3747. // Multi Font & Material support related
  3748. state.currentFontAsset = m_currentFontAsset;
  3749. state.currentSpriteAsset = m_currentSpriteAsset;
  3750. state.currentMaterial = m_currentMaterial;
  3751. state.currentMaterialIndex = m_currentMaterialIndex;
  3752. state.previous_WordBreak = index;
  3753. state.total_CharacterCount = count;
  3754. state.visible_CharacterCount = m_lineVisibleCharacterCount;
  3755. //state.visible_CharacterCount = m_visibleCharacterCount;
  3756. //state.visible_SpriteCount = m_visibleSpriteCount;
  3757. state.visible_LinkCount = m_textInfo.linkCount;
  3758. state.firstCharacterIndex = m_firstCharacterOfLine;
  3759. state.firstVisibleCharacterIndex = m_firstVisibleCharacterOfLine;
  3760. state.lastVisibleCharIndex = m_lastVisibleCharacterOfLine;
  3761. state.fontStyle = m_FontStyleInternal;
  3762. state.fontScale = m_fontScale;
  3763. //state.maxFontScale = m_maxFontScale;
  3764. state.fontScaleMultiplier = m_fontScaleMultiplier;
  3765. state.currentFontSize = m_currentFontSize;
  3766. state.xAdvance = m_xAdvance;
  3767. state.maxCapHeight = m_maxCapHeight;
  3768. state.maxAscender = m_maxAscender;
  3769. state.maxDescender = m_maxDescender;
  3770. state.maxLineAscender = m_maxLineAscender;
  3771. state.maxLineDescender = m_maxLineDescender;
  3772. state.previousLineAscender = m_startOfLineAscender;
  3773. state.preferredWidth = m_preferredWidth;
  3774. state.preferredHeight = m_preferredHeight;
  3775. state.meshExtents = m_meshExtents;
  3776. state.lineNumber = m_lineNumber;
  3777. state.lineOffset = m_lineOffset;
  3778. state.baselineOffset = m_baselineOffset;
  3779. //state.alignment = m_lineJustification;
  3780. state.vertexColor = m_htmlColor;
  3781. state.underlineColor = m_underlineColor;
  3782. state.strikethroughColor = m_strikethroughColor;
  3783. state.highlightColor = m_highlightColor;
  3784. state.isNonBreakingSpace = m_isNonBreakingSpace;
  3785. state.tagNoParsing = tag_NoParsing;
  3786. // XML Tag Stack
  3787. state.basicStyleStack = m_fontStyleStack;
  3788. state.colorStack = m_colorStack;
  3789. state.underlineColorStack = m_underlineColorStack;
  3790. state.strikethroughColorStack = m_strikethroughColorStack;
  3791. state.highlightColorStack = m_highlightColorStack;
  3792. state.colorGradientStack = m_colorGradientStack;
  3793. state.sizeStack = m_sizeStack;
  3794. state.indentStack = m_indentStack;
  3795. state.fontWeightStack = m_FontWeightStack;
  3796. state.styleStack = m_styleStack;
  3797. state.baselineStack = m_baselineOffsetStack;
  3798. state.actionStack = m_actionStack;
  3799. state.materialReferenceStack = m_materialReferenceStack;
  3800. state.lineJustificationStack = m_lineJustificationStack;
  3801. //state.spriteAnimationStack = m_spriteAnimationStack;
  3802. state.spriteAnimationID = m_spriteAnimationID;
  3803. if (m_lineNumber < m_textInfo.lineInfo.Length)
  3804. state.lineInfo = m_textInfo.lineInfo[m_lineNumber];
  3805. }
  3806. /// <summary>
  3807. /// Restore the State of various variables used in the mesh creation loop.
  3808. /// </summary>
  3809. /// <param name="state"></param>
  3810. /// <returns></returns>
  3811. protected int RestoreWordWrappingState(ref WordWrapState state)
  3812. {
  3813. int index = state.previous_WordBreak;
  3814. // Multi Font & Material support related
  3815. m_currentFontAsset = state.currentFontAsset;
  3816. m_currentSpriteAsset = state.currentSpriteAsset;
  3817. m_currentMaterial = state.currentMaterial;
  3818. m_currentMaterialIndex = state.currentMaterialIndex;
  3819. m_characterCount = state.total_CharacterCount + 1;
  3820. m_lineVisibleCharacterCount = state.visible_CharacterCount;
  3821. //m_visibleCharacterCount = state.visible_CharacterCount;
  3822. //m_visibleSpriteCount = state.visible_SpriteCount;
  3823. m_textInfo.linkCount = state.visible_LinkCount;
  3824. m_firstCharacterOfLine = state.firstCharacterIndex;
  3825. m_firstVisibleCharacterOfLine = state.firstVisibleCharacterIndex;
  3826. m_lastVisibleCharacterOfLine = state.lastVisibleCharIndex;
  3827. m_FontStyleInternal = state.fontStyle;
  3828. m_fontScale = state.fontScale;
  3829. m_fontScaleMultiplier = state.fontScaleMultiplier;
  3830. //m_maxFontScale = state.maxFontScale;
  3831. m_currentFontSize = state.currentFontSize;
  3832. m_xAdvance = state.xAdvance;
  3833. m_maxCapHeight = state.maxCapHeight;
  3834. m_maxAscender = state.maxAscender;
  3835. m_maxDescender = state.maxDescender;
  3836. m_maxLineAscender = state.maxLineAscender;
  3837. m_maxLineDescender = state.maxLineDescender;
  3838. m_startOfLineAscender = state.previousLineAscender;
  3839. m_preferredWidth = state.preferredWidth;
  3840. m_preferredHeight = state.preferredHeight;
  3841. m_meshExtents = state.meshExtents;
  3842. m_lineNumber = state.lineNumber;
  3843. m_lineOffset = state.lineOffset;
  3844. m_baselineOffset = state.baselineOffset;
  3845. //m_lineJustification = state.alignment;
  3846. m_htmlColor = state.vertexColor;
  3847. m_underlineColor = state.underlineColor;
  3848. m_strikethroughColor = state.strikethroughColor;
  3849. m_highlightColor = state.highlightColor;
  3850. m_isNonBreakingSpace = state.isNonBreakingSpace;
  3851. tag_NoParsing = state.tagNoParsing;
  3852. // XML Tag Stack
  3853. m_fontStyleStack = state.basicStyleStack;
  3854. m_colorStack = state.colorStack;
  3855. m_underlineColorStack = state.underlineColorStack;
  3856. m_strikethroughColorStack = state.strikethroughColorStack;
  3857. m_highlightColorStack = state.highlightColorStack;
  3858. m_colorGradientStack = state.colorGradientStack;
  3859. m_sizeStack = state.sizeStack;
  3860. m_indentStack = state.indentStack;
  3861. m_FontWeightStack = state.fontWeightStack;
  3862. m_styleStack = state.styleStack;
  3863. m_baselineOffsetStack = state.baselineStack;
  3864. m_actionStack = state.actionStack;
  3865. m_materialReferenceStack = state.materialReferenceStack;
  3866. m_lineJustificationStack = state.lineJustificationStack;
  3867. //m_spriteAnimationStack = state.spriteAnimationStack;
  3868. m_spriteAnimationID = state.spriteAnimationID;
  3869. if (m_lineNumber < m_textInfo.lineInfo.Length)
  3870. m_textInfo.lineInfo[m_lineNumber] = state.lineInfo;
  3871. return index;
  3872. }
  3873. /// <summary>
  3874. /// Store vertex information for each character.
  3875. /// </summary>
  3876. /// <param name="style_padding">Style_padding.</param>
  3877. /// <param name="vertexColor">Vertex color.</param>
  3878. protected virtual void SaveGlyphVertexInfo(float padding, float style_padding, Color32 vertexColor)
  3879. {
  3880. // Save the Vertex Position for the Character
  3881. #region Setup Mesh Vertices
  3882. m_textInfo.characterInfo[m_characterCount].vertex_BL.position = m_textInfo.characterInfo[m_characterCount].bottomLeft;
  3883. m_textInfo.characterInfo[m_characterCount].vertex_TL.position = m_textInfo.characterInfo[m_characterCount].topLeft;
  3884. m_textInfo.characterInfo[m_characterCount].vertex_TR.position = m_textInfo.characterInfo[m_characterCount].topRight;
  3885. m_textInfo.characterInfo[m_characterCount].vertex_BR.position = m_textInfo.characterInfo[m_characterCount].bottomRight;
  3886. #endregion
  3887. #region Setup Vertex Colors
  3888. // Alpha is the lower of the vertex color or tag color alpha used.
  3889. vertexColor.a = m_fontColor32.a < vertexColor.a ? (byte)(m_fontColor32.a) : (byte)(vertexColor.a);
  3890. // Handle Vertex Colors & Vertex Color Gradient
  3891. if (!m_enableVertexGradient)
  3892. {
  3893. m_textInfo.characterInfo[m_characterCount].vertex_BL.color = vertexColor;
  3894. m_textInfo.characterInfo[m_characterCount].vertex_TL.color = vertexColor;
  3895. m_textInfo.characterInfo[m_characterCount].vertex_TR.color = vertexColor;
  3896. m_textInfo.characterInfo[m_characterCount].vertex_BR.color = vertexColor;
  3897. }
  3898. else
  3899. {
  3900. if (!m_overrideHtmlColors && m_colorStack.m_Index > 1)
  3901. {
  3902. m_textInfo.characterInfo[m_characterCount].vertex_BL.color = vertexColor;
  3903. m_textInfo.characterInfo[m_characterCount].vertex_TL.color = vertexColor;
  3904. m_textInfo.characterInfo[m_characterCount].vertex_TR.color = vertexColor;
  3905. m_textInfo.characterInfo[m_characterCount].vertex_BR.color = vertexColor;
  3906. }
  3907. else // Handle Vertex Color Gradient
  3908. {
  3909. // Use Vertex Color Gradient Preset (if one is assigned)
  3910. if (m_fontColorGradientPreset != null)
  3911. {
  3912. m_textInfo.characterInfo[m_characterCount].vertex_BL.color = m_fontColorGradientPreset.bottomLeft * vertexColor;
  3913. m_textInfo.characterInfo[m_characterCount].vertex_TL.color = m_fontColorGradientPreset.topLeft * vertexColor;
  3914. m_textInfo.characterInfo[m_characterCount].vertex_TR.color = m_fontColorGradientPreset.topRight * vertexColor;
  3915. m_textInfo.characterInfo[m_characterCount].vertex_BR.color = m_fontColorGradientPreset.bottomRight * vertexColor;
  3916. }
  3917. else
  3918. {
  3919. m_textInfo.characterInfo[m_characterCount].vertex_BL.color = m_fontColorGradient.bottomLeft * vertexColor;
  3920. m_textInfo.characterInfo[m_characterCount].vertex_TL.color = m_fontColorGradient.topLeft * vertexColor;
  3921. m_textInfo.characterInfo[m_characterCount].vertex_TR.color = m_fontColorGradient.topRight * vertexColor;
  3922. m_textInfo.characterInfo[m_characterCount].vertex_BR.color = m_fontColorGradient.bottomRight * vertexColor;
  3923. }
  3924. }
  3925. }
  3926. if (m_colorGradientPreset != null)
  3927. {
  3928. m_textInfo.characterInfo[m_characterCount].vertex_BL.color *= m_colorGradientPreset.bottomLeft;
  3929. m_textInfo.characterInfo[m_characterCount].vertex_TL.color *= m_colorGradientPreset.topLeft;
  3930. m_textInfo.characterInfo[m_characterCount].vertex_TR.color *= m_colorGradientPreset.topRight;
  3931. m_textInfo.characterInfo[m_characterCount].vertex_BR.color *= m_colorGradientPreset.bottomRight;
  3932. }
  3933. #endregion
  3934. // Apply style_padding only if this is a SDF Shader.
  3935. if (!m_isSDFShader)
  3936. style_padding = 0f;
  3937. // Setup UVs for the Character
  3938. #region Setup UVs
  3939. Vector2 uv0;
  3940. uv0.x = (m_cached_TextElement.glyph.glyphRect.x - padding - style_padding) / m_currentFontAsset.atlasWidth;
  3941. uv0.y = (m_cached_TextElement.glyph.glyphRect.y - padding - style_padding) / m_currentFontAsset.atlasHeight;
  3942. Vector2 uv1;
  3943. uv1.x = uv0.x;
  3944. uv1.y = (m_cached_TextElement.glyph.glyphRect.y + padding + style_padding + m_cached_TextElement.glyph.glyphRect.height) / m_currentFontAsset.atlasHeight;
  3945. Vector2 uv2;
  3946. uv2.x = (m_cached_TextElement.glyph.glyphRect.x + padding + style_padding + m_cached_TextElement.glyph.glyphRect.width) / m_currentFontAsset.atlasWidth;
  3947. uv2.y = uv1.y;
  3948. Vector2 uv3;
  3949. uv3.x = uv2.x;
  3950. uv3.y = uv0.y;
  3951. // Store UV Information
  3952. m_textInfo.characterInfo[m_characterCount].vertex_BL.uv = uv0;
  3953. m_textInfo.characterInfo[m_characterCount].vertex_TL.uv = uv1;
  3954. m_textInfo.characterInfo[m_characterCount].vertex_TR.uv = uv2;
  3955. m_textInfo.characterInfo[m_characterCount].vertex_BR.uv = uv3;
  3956. #endregion Setup UVs
  3957. // Normal
  3958. #region Setup Normals & Tangents
  3959. //Vector3 normal = new Vector3(0, 0, -1);
  3960. //m_textInfo.characterInfo[m_characterCount].vertex_BL.normal = normal;
  3961. //m_textInfo.characterInfo[m_characterCount].vertex_TL.normal = normal;
  3962. //m_textInfo.characterInfo[m_characterCount].vertex_TR.normal = normal;
  3963. //m_textInfo.characterInfo[m_characterCount].vertex_BR.normal = normal;
  3964. // Tangents
  3965. //Vector4 tangent = new Vector4(-1, 0, 0, 1);
  3966. //m_textInfo.characterInfo[m_characterCount].vertex_BL.tangent = tangent;
  3967. //m_textInfo.characterInfo[m_characterCount].vertex_TL.tangent = tangent;
  3968. //m_textInfo.characterInfo[m_characterCount].vertex_TR.tangent = tangent;
  3969. //m_textInfo.characterInfo[m_characterCount].vertex_BR.tangent = tangent;
  3970. #endregion end Normals & Tangents
  3971. }
  3972. /// <summary>
  3973. /// Store vertex information for each sprite.
  3974. /// </summary>
  3975. /// <param name="padding"></param>
  3976. /// <param name="style_padding"></param>
  3977. /// <param name="vertexColor"></param>
  3978. protected virtual void SaveSpriteVertexInfo(Color32 vertexColor)
  3979. {
  3980. // Save the Vertex Position for the Character
  3981. #region Setup Mesh Vertices
  3982. m_textInfo.characterInfo[m_characterCount].vertex_BL.position = m_textInfo.characterInfo[m_characterCount].bottomLeft;
  3983. m_textInfo.characterInfo[m_characterCount].vertex_TL.position = m_textInfo.characterInfo[m_characterCount].topLeft;
  3984. m_textInfo.characterInfo[m_characterCount].vertex_TR.position = m_textInfo.characterInfo[m_characterCount].topRight;
  3985. m_textInfo.characterInfo[m_characterCount].vertex_BR.position = m_textInfo.characterInfo[m_characterCount].bottomRight;
  3986. #endregion
  3987. // Vertex Color Alpha
  3988. if (m_tintAllSprites) m_tintSprite = true;
  3989. Color32 spriteColor = m_tintSprite ? m_spriteColor.Multiply(vertexColor) : m_spriteColor;
  3990. spriteColor.a = spriteColor.a < m_fontColor32.a ? spriteColor.a = spriteColor.a < vertexColor.a ? spriteColor.a : vertexColor.a : m_fontColor32.a;
  3991. Color32 c0 = spriteColor;
  3992. Color32 c1 = spriteColor;
  3993. Color32 c2 = spriteColor;
  3994. Color32 c3 = spriteColor;
  3995. if (m_enableVertexGradient)
  3996. {
  3997. if (m_fontColorGradientPreset != null)
  3998. {
  3999. c0 = m_tintSprite ? c0.Multiply(m_fontColorGradientPreset.bottomLeft) : c0;
  4000. c1 = m_tintSprite ? c1.Multiply(m_fontColorGradientPreset.topLeft) : c1;
  4001. c2 = m_tintSprite ? c2.Multiply(m_fontColorGradientPreset.topRight) : c2;
  4002. c3 = m_tintSprite ? c3.Multiply(m_fontColorGradientPreset.bottomRight) : c3;
  4003. }
  4004. else
  4005. {
  4006. c0 = m_tintSprite ? c0.Multiply(m_fontColorGradient.bottomLeft) : c0;
  4007. c1 = m_tintSprite ? c1.Multiply(m_fontColorGradient.topLeft) : c1;
  4008. c2 = m_tintSprite ? c2.Multiply(m_fontColorGradient.topRight) : c2;
  4009. c3 = m_tintSprite ? c3.Multiply(m_fontColorGradient.bottomRight) : c3;
  4010. }
  4011. }
  4012. if (m_colorGradientPreset != null)
  4013. {
  4014. c0 = m_tintSprite ? c0.Multiply(m_colorGradientPreset.bottomLeft) : c0;
  4015. c1 = m_tintSprite ? c1.Multiply(m_colorGradientPreset.topLeft) : c1;
  4016. c2 = m_tintSprite ? c2.Multiply(m_colorGradientPreset.topRight) : c2;
  4017. c3 = m_tintSprite ? c3.Multiply(m_colorGradientPreset.bottomRight) : c3;
  4018. }
  4019. m_textInfo.characterInfo[m_characterCount].vertex_BL.color = c0;
  4020. m_textInfo.characterInfo[m_characterCount].vertex_TL.color = c1;
  4021. m_textInfo.characterInfo[m_characterCount].vertex_TR.color = c2;
  4022. m_textInfo.characterInfo[m_characterCount].vertex_BR.color = c3;
  4023. // Setup UVs for the Character
  4024. #region Setup UVs
  4025. 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
  4026. 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
  4027. 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
  4028. Vector2 uv3 = new Vector2(uv2.x, uv0.y); // bottom right
  4029. // Store UV Information
  4030. m_textInfo.characterInfo[m_characterCount].vertex_BL.uv = uv0;
  4031. m_textInfo.characterInfo[m_characterCount].vertex_TL.uv = uv1;
  4032. m_textInfo.characterInfo[m_characterCount].vertex_TR.uv = uv2;
  4033. m_textInfo.characterInfo[m_characterCount].vertex_BR.uv = uv3;
  4034. #endregion Setup UVs
  4035. // Normal
  4036. #region Setup Normals & Tangents
  4037. //Vector3 normal = new Vector3(0, 0, -1);
  4038. //m_textInfo.characterInfo[m_characterCount].vertex_BL.normal = normal;
  4039. //m_textInfo.characterInfo[m_characterCount].vertex_TL.normal = normal;
  4040. //m_textInfo.characterInfo[m_characterCount].vertex_TR.normal = normal;
  4041. //m_textInfo.characterInfo[m_characterCount].vertex_BR.normal = normal;
  4042. // Tangents
  4043. //Vector4 tangent = new Vector4(-1, 0, 0, 1);
  4044. //m_textInfo.characterInfo[m_characterCount].vertex_BL.tangent = tangent;
  4045. //m_textInfo.characterInfo[m_characterCount].vertex_TL.tangent = tangent;
  4046. //m_textInfo.characterInfo[m_characterCount].vertex_TR.tangent = tangent;
  4047. //m_textInfo.characterInfo[m_characterCount].vertex_BR.tangent = tangent;
  4048. #endregion end Normals & Tangents
  4049. }
  4050. /// <summary>
  4051. /// Store vertex attributes into the appropriate TMP_MeshInfo.
  4052. /// </summary>
  4053. /// <param name="i"></param>
  4054. /// <param name="index_X4"></param>
  4055. protected virtual void FillCharacterVertexBuffers(int i, int index_X4)
  4056. {
  4057. int materialIndex = m_textInfo.characterInfo[i].materialReferenceIndex;
  4058. index_X4 = m_textInfo.meshInfo[materialIndex].vertexCount;
  4059. // Make sure buffers allocation are sufficient to hold the vertex data
  4060. //if (m_textInfo.meshInfo[materialIndex].vertices.Length < index_X4 + 4)
  4061. // m_textInfo.meshInfo[materialIndex].ResizeMeshInfo(Mathf.NextPowerOfTwo(index_X4 + 4));
  4062. TMP_CharacterInfo[] characterInfoArray = m_textInfo.characterInfo;
  4063. m_textInfo.characterInfo[i].vertexIndex = index_X4;
  4064. // Setup Vertices for Characters
  4065. m_textInfo.meshInfo[materialIndex].vertices[0 + index_X4] = characterInfoArray[i].vertex_BL.position;
  4066. m_textInfo.meshInfo[materialIndex].vertices[1 + index_X4] = characterInfoArray[i].vertex_TL.position;
  4067. m_textInfo.meshInfo[materialIndex].vertices[2 + index_X4] = characterInfoArray[i].vertex_TR.position;
  4068. m_textInfo.meshInfo[materialIndex].vertices[3 + index_X4] = characterInfoArray[i].vertex_BR.position;
  4069. // Setup UVS0
  4070. m_textInfo.meshInfo[materialIndex].uvs0[0 + index_X4] = characterInfoArray[i].vertex_BL.uv;
  4071. m_textInfo.meshInfo[materialIndex].uvs0[1 + index_X4] = characterInfoArray[i].vertex_TL.uv;
  4072. m_textInfo.meshInfo[materialIndex].uvs0[2 + index_X4] = characterInfoArray[i].vertex_TR.uv;
  4073. m_textInfo.meshInfo[materialIndex].uvs0[3 + index_X4] = characterInfoArray[i].vertex_BR.uv;
  4074. // Setup UVS2
  4075. m_textInfo.meshInfo[materialIndex].uvs2[0 + index_X4] = characterInfoArray[i].vertex_BL.uv2;
  4076. m_textInfo.meshInfo[materialIndex].uvs2[1 + index_X4] = characterInfoArray[i].vertex_TL.uv2;
  4077. m_textInfo.meshInfo[materialIndex].uvs2[2 + index_X4] = characterInfoArray[i].vertex_TR.uv2;
  4078. m_textInfo.meshInfo[materialIndex].uvs2[3 + index_X4] = characterInfoArray[i].vertex_BR.uv2;
  4079. // Setup UVS4
  4080. //m_textInfo.meshInfo[0].uvs4[0 + index_X4] = characterInfoArray[i].vertex_BL.uv4;
  4081. //m_textInfo.meshInfo[0].uvs4[1 + index_X4] = characterInfoArray[i].vertex_TL.uv4;
  4082. //m_textInfo.meshInfo[0].uvs4[2 + index_X4] = characterInfoArray[i].vertex_TR.uv4;
  4083. //m_textInfo.meshInfo[0].uvs4[3 + index_X4] = characterInfoArray[i].vertex_BR.uv4;
  4084. // setup Vertex Colors
  4085. m_textInfo.meshInfo[materialIndex].colors32[0 + index_X4] = characterInfoArray[i].vertex_BL.color;
  4086. m_textInfo.meshInfo[materialIndex].colors32[1 + index_X4] = characterInfoArray[i].vertex_TL.color;
  4087. m_textInfo.meshInfo[materialIndex].colors32[2 + index_X4] = characterInfoArray[i].vertex_TR.color;
  4088. m_textInfo.meshInfo[materialIndex].colors32[3 + index_X4] = characterInfoArray[i].vertex_BR.color;
  4089. m_textInfo.meshInfo[materialIndex].vertexCount = index_X4 + 4;
  4090. }
  4091. protected virtual void FillCharacterVertexBuffers(int i, int index_X4, bool isVolumetric)
  4092. {
  4093. int materialIndex = m_textInfo.characterInfo[i].materialReferenceIndex;
  4094. index_X4 = m_textInfo.meshInfo[materialIndex].vertexCount;
  4095. TMP_CharacterInfo[] characterInfoArray = m_textInfo.characterInfo;
  4096. m_textInfo.characterInfo[i].vertexIndex = index_X4;
  4097. // Setup Vertices for Characters
  4098. m_textInfo.meshInfo[materialIndex].vertices[0 + index_X4] = characterInfoArray[i].vertex_BL.position;
  4099. m_textInfo.meshInfo[materialIndex].vertices[1 + index_X4] = characterInfoArray[i].vertex_TL.position;
  4100. m_textInfo.meshInfo[materialIndex].vertices[2 + index_X4] = characterInfoArray[i].vertex_TR.position;
  4101. m_textInfo.meshInfo[materialIndex].vertices[3 + index_X4] = characterInfoArray[i].vertex_BR.position;
  4102. if (isVolumetric)
  4103. {
  4104. Vector3 depth = new Vector3(0, 0, m_fontSize * m_fontScale);
  4105. m_textInfo.meshInfo[materialIndex].vertices[4 + index_X4] = characterInfoArray[i].vertex_BL.position + depth;
  4106. m_textInfo.meshInfo[materialIndex].vertices[5 + index_X4] = characterInfoArray[i].vertex_TL.position + depth;
  4107. m_textInfo.meshInfo[materialIndex].vertices[6 + index_X4] = characterInfoArray[i].vertex_TR.position + depth;
  4108. m_textInfo.meshInfo[materialIndex].vertices[7 + index_X4] = characterInfoArray[i].vertex_BR.position + depth;
  4109. }
  4110. // Setup UVS0
  4111. m_textInfo.meshInfo[materialIndex].uvs0[0 + index_X4] = characterInfoArray[i].vertex_BL.uv;
  4112. m_textInfo.meshInfo[materialIndex].uvs0[1 + index_X4] = characterInfoArray[i].vertex_TL.uv;
  4113. m_textInfo.meshInfo[materialIndex].uvs0[2 + index_X4] = characterInfoArray[i].vertex_TR.uv;
  4114. m_textInfo.meshInfo[materialIndex].uvs0[3 + index_X4] = characterInfoArray[i].vertex_BR.uv;
  4115. if (isVolumetric)
  4116. {
  4117. m_textInfo.meshInfo[materialIndex].uvs0[4 + index_X4] = characterInfoArray[i].vertex_BL.uv;
  4118. m_textInfo.meshInfo[materialIndex].uvs0[5 + index_X4] = characterInfoArray[i].vertex_TL.uv;
  4119. m_textInfo.meshInfo[materialIndex].uvs0[6 + index_X4] = characterInfoArray[i].vertex_TR.uv;
  4120. m_textInfo.meshInfo[materialIndex].uvs0[7 + index_X4] = characterInfoArray[i].vertex_BR.uv;
  4121. }
  4122. // Setup UVS2
  4123. m_textInfo.meshInfo[materialIndex].uvs2[0 + index_X4] = characterInfoArray[i].vertex_BL.uv2;
  4124. m_textInfo.meshInfo[materialIndex].uvs2[1 + index_X4] = characterInfoArray[i].vertex_TL.uv2;
  4125. m_textInfo.meshInfo[materialIndex].uvs2[2 + index_X4] = characterInfoArray[i].vertex_TR.uv2;
  4126. m_textInfo.meshInfo[materialIndex].uvs2[3 + index_X4] = characterInfoArray[i].vertex_BR.uv2;
  4127. if (isVolumetric)
  4128. {
  4129. m_textInfo.meshInfo[materialIndex].uvs2[4 + index_X4] = characterInfoArray[i].vertex_BL.uv2;
  4130. m_textInfo.meshInfo[materialIndex].uvs2[5 + index_X4] = characterInfoArray[i].vertex_TL.uv2;
  4131. m_textInfo.meshInfo[materialIndex].uvs2[6 + index_X4] = characterInfoArray[i].vertex_TR.uv2;
  4132. m_textInfo.meshInfo[materialIndex].uvs2[7 + index_X4] = characterInfoArray[i].vertex_BR.uv2;
  4133. }
  4134. // Setup UVS4
  4135. //m_textInfo.meshInfo[0].uvs4[0 + index_X4] = characterInfoArray[i].vertex_BL.uv4;
  4136. //m_textInfo.meshInfo[0].uvs4[1 + index_X4] = characterInfoArray[i].vertex_TL.uv4;
  4137. //m_textInfo.meshInfo[0].uvs4[2 + index_X4] = characterInfoArray[i].vertex_TR.uv4;
  4138. //m_textInfo.meshInfo[0].uvs4[3 + index_X4] = characterInfoArray[i].vertex_BR.uv4;
  4139. // setup Vertex Colors
  4140. m_textInfo.meshInfo[materialIndex].colors32[0 + index_X4] = characterInfoArray[i].vertex_BL.color;
  4141. m_textInfo.meshInfo[materialIndex].colors32[1 + index_X4] = characterInfoArray[i].vertex_TL.color;
  4142. m_textInfo.meshInfo[materialIndex].colors32[2 + index_X4] = characterInfoArray[i].vertex_TR.color;
  4143. m_textInfo.meshInfo[materialIndex].colors32[3 + index_X4] = characterInfoArray[i].vertex_BR.color;
  4144. if (isVolumetric)
  4145. {
  4146. Color32 backColor = new Color32(255, 255, 128, 255);
  4147. m_textInfo.meshInfo[materialIndex].colors32[4 + index_X4] = backColor; //characterInfoArray[i].vertex_BL.color;
  4148. m_textInfo.meshInfo[materialIndex].colors32[5 + index_X4] = backColor; //characterInfoArray[i].vertex_TL.color;
  4149. m_textInfo.meshInfo[materialIndex].colors32[6 + index_X4] = backColor; //characterInfoArray[i].vertex_TR.color;
  4150. m_textInfo.meshInfo[materialIndex].colors32[7 + index_X4] = backColor; //characterInfoArray[i].vertex_BR.color;
  4151. }
  4152. m_textInfo.meshInfo[materialIndex].vertexCount = index_X4 + (!isVolumetric ? 4 : 8);
  4153. }
  4154. /// <summary>
  4155. /// Fill Vertex Buffers for Sprites
  4156. /// </summary>
  4157. /// <param name="i"></param>
  4158. /// <param name="spriteIndex_X4"></param>
  4159. protected virtual void FillSpriteVertexBuffers(int i, int index_X4)
  4160. {
  4161. int materialIndex = m_textInfo.characterInfo[i].materialReferenceIndex;
  4162. index_X4 = m_textInfo.meshInfo[materialIndex].vertexCount;
  4163. TMP_CharacterInfo[] characterInfoArray = m_textInfo.characterInfo;
  4164. m_textInfo.characterInfo[i].vertexIndex = index_X4;
  4165. // Setup Vertices for Characters
  4166. m_textInfo.meshInfo[materialIndex].vertices[0 + index_X4] = characterInfoArray[i].vertex_BL.position;
  4167. m_textInfo.meshInfo[materialIndex].vertices[1 + index_X4] = characterInfoArray[i].vertex_TL.position;
  4168. m_textInfo.meshInfo[materialIndex].vertices[2 + index_X4] = characterInfoArray[i].vertex_TR.position;
  4169. m_textInfo.meshInfo[materialIndex].vertices[3 + index_X4] = characterInfoArray[i].vertex_BR.position;
  4170. // Setup UVS0
  4171. m_textInfo.meshInfo[materialIndex].uvs0[0 + index_X4] = characterInfoArray[i].vertex_BL.uv;
  4172. m_textInfo.meshInfo[materialIndex].uvs0[1 + index_X4] = characterInfoArray[i].vertex_TL.uv;
  4173. m_textInfo.meshInfo[materialIndex].uvs0[2 + index_X4] = characterInfoArray[i].vertex_TR.uv;
  4174. m_textInfo.meshInfo[materialIndex].uvs0[3 + index_X4] = characterInfoArray[i].vertex_BR.uv;
  4175. // Setup UVS2
  4176. m_textInfo.meshInfo[materialIndex].uvs2[0 + index_X4] = characterInfoArray[i].vertex_BL.uv2;
  4177. m_textInfo.meshInfo[materialIndex].uvs2[1 + index_X4] = characterInfoArray[i].vertex_TL.uv2;
  4178. m_textInfo.meshInfo[materialIndex].uvs2[2 + index_X4] = characterInfoArray[i].vertex_TR.uv2;
  4179. m_textInfo.meshInfo[materialIndex].uvs2[3 + index_X4] = characterInfoArray[i].vertex_BR.uv2;
  4180. // Setup UVS4
  4181. //m_textInfo.meshInfo[0].uvs4[0 + index_X4] = characterInfoArray[i].vertex_BL.uv4;
  4182. //m_textInfo.meshInfo[0].uvs4[1 + index_X4] = characterInfoArray[i].vertex_TL.uv4;
  4183. //m_textInfo.meshInfo[0].uvs4[2 + index_X4] = characterInfoArray[i].vertex_TR.uv4;
  4184. //m_textInfo.meshInfo[0].uvs4[3 + index_X4] = characterInfoArray[i].vertex_BR.uv4;
  4185. // setup Vertex Colors
  4186. m_textInfo.meshInfo[materialIndex].colors32[0 + index_X4] = characterInfoArray[i].vertex_BL.color;
  4187. m_textInfo.meshInfo[materialIndex].colors32[1 + index_X4] = characterInfoArray[i].vertex_TL.color;
  4188. m_textInfo.meshInfo[materialIndex].colors32[2 + index_X4] = characterInfoArray[i].vertex_TR.color;
  4189. m_textInfo.meshInfo[materialIndex].colors32[3 + index_X4] = characterInfoArray[i].vertex_BR.color;
  4190. m_textInfo.meshInfo[materialIndex].vertexCount = index_X4 + 4;
  4191. }
  4192. /// <summary>
  4193. /// Method to add the underline geometry.
  4194. /// </summary>
  4195. /// <param name="start"></param>
  4196. /// <param name="end"></param>
  4197. /// <param name="startScale"></param>
  4198. /// <param name="endScale"></param>
  4199. /// <param name="maxScale"></param>
  4200. /// <param name="underlineColor"></param>
  4201. protected virtual void DrawUnderlineMesh(Vector3 start, Vector3 end, ref int index, float startScale, float endScale, float maxScale, float sdfScale, Color32 underlineColor)
  4202. {
  4203. if (m_cached_Underline_Character == null)
  4204. {
  4205. if (!TMP_Settings.warningsDisabled)
  4206. Debug.LogWarning("Unable to add underline since the Font Asset doesn't contain the underline character.", this);
  4207. return;
  4208. }
  4209. int verticesCount = index + 12;
  4210. // Check to make sure our current mesh buffer allocations can hold these new Quads.
  4211. if (verticesCount > m_textInfo.meshInfo[0].vertices.Length)
  4212. {
  4213. // Resize Mesh Buffers
  4214. m_textInfo.meshInfo[0].ResizeMeshInfo(verticesCount / 4);
  4215. }
  4216. // Adjust the position of the underline based on the lowest character. This matters for subscript character.
  4217. start.y = Mathf.Min(start.y, end.y);
  4218. end.y = Mathf.Min(start.y, end.y);
  4219. float segmentWidth = m_cached_Underline_Character.glyph.metrics.width / 2 * maxScale;
  4220. if (end.x - start.x < m_cached_Underline_Character.glyph.metrics.width * maxScale)
  4221. {
  4222. segmentWidth = (end.x - start.x) / 2f;
  4223. }
  4224. float startPadding = m_padding * startScale / maxScale;
  4225. float endPadding = m_padding * endScale / maxScale;
  4226. float underlineThickness = m_fontAsset.faceInfo.underlineThickness;
  4227. // UNDERLINE VERTICES FOR (3) LINE SEGMENTS
  4228. #region UNDERLINE VERTICES
  4229. Vector3[] vertices = m_textInfo.meshInfo[0].vertices;
  4230. // Front Part of the Underline
  4231. vertices[index + 0] = start + new Vector3(0, 0 - (underlineThickness + m_padding) * maxScale, 0); // BL
  4232. vertices[index + 1] = start + new Vector3(0, m_padding * maxScale, 0); // TL
  4233. vertices[index + 2] = vertices[index + 1] + new Vector3(segmentWidth, 0, 0); // TR
  4234. vertices[index + 3] = vertices[index + 0] + new Vector3(segmentWidth, 0, 0); // BR
  4235. // Middle Part of the Underline
  4236. vertices[index + 4] = vertices[index + 3]; // BL
  4237. vertices[index + 5] = vertices[index + 2]; // TL
  4238. vertices[index + 6] = end + new Vector3(-segmentWidth, m_padding * maxScale, 0); // TR
  4239. vertices[index + 7] = end + new Vector3(-segmentWidth, -(underlineThickness + m_padding) * maxScale, 0); // BR
  4240. // End Part of the Underline
  4241. vertices[index + 8] = vertices[index + 7]; // BL
  4242. vertices[index + 9] = vertices[index + 6]; // TL
  4243. vertices[index + 10] = end + new Vector3(0, m_padding * maxScale, 0); // TR
  4244. vertices[index + 11] = end + new Vector3(0, -(underlineThickness + m_padding) * maxScale, 0); // BR
  4245. #endregion
  4246. // UNDERLINE UV0
  4247. #region HANDLE UV0
  4248. Vector2[] uvs0 = m_textInfo.meshInfo[0].uvs0;
  4249. // Calculate UV required to setup the 3 Quads for the Underline.
  4250. 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
  4251. 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
  4252. 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
  4253. Vector2 uv3 = new Vector2(uv2.x, uv0.y); // Mid Bottom Left
  4254. 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
  4255. Vector2 uv5 = new Vector2(uv4.x, uv0.y); // Mid Bottom right
  4256. 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
  4257. Vector2 uv7 = new Vector2(uv6.x, uv0.y); // End Part - Top Right
  4258. // Left Part of the Underline
  4259. uvs0[0 + index] = uv0; // BL
  4260. uvs0[1 + index] = uv1; // TL
  4261. uvs0[2 + index] = uv2; // TR
  4262. uvs0[3 + index] = uv3; // BR
  4263. // Middle Part of the Underline
  4264. uvs0[4 + index] = new Vector2(uv2.x - uv2.x * 0.001f, uv0.y);
  4265. uvs0[5 + index] = new Vector2(uv2.x - uv2.x * 0.001f, uv1.y);
  4266. uvs0[6 + index] = new Vector2(uv2.x + uv2.x * 0.001f, uv1.y);
  4267. uvs0[7 + index] = new Vector2(uv2.x + uv2.x * 0.001f, uv0.y);
  4268. // Right Part of the Underline
  4269. uvs0[8 + index] = uv5;
  4270. uvs0[9 + index] = uv4;
  4271. uvs0[10 + index] = uv6;
  4272. uvs0[11 + index] = uv7;
  4273. #endregion
  4274. // UNDERLINE UV2
  4275. #region HANDLE UV2 - SDF SCALE
  4276. // UV1 contains Face / Border UV layout.
  4277. float min_UvX = 0;
  4278. float max_UvX = (vertices[index + 2].x - start.x) / (end.x - start.x);
  4279. //Calculate the xScale or how much the UV's are getting stretched on the X axis for the middle section of the underline.
  4280. float xScale = Mathf.Abs(sdfScale);
  4281. Vector2[] uvs2 = m_textInfo.meshInfo[0].uvs2;
  4282. uvs2[0 + index] = PackUV(0, 0, xScale);
  4283. uvs2[1 + index] = PackUV(0, 1, xScale);
  4284. uvs2[2 + index] = PackUV(max_UvX, 1, xScale);
  4285. uvs2[3 + index] = PackUV(max_UvX, 0, xScale);
  4286. min_UvX = (vertices[index + 4].x - start.x) / (end.x - start.x);
  4287. max_UvX = (vertices[index + 6].x - start.x) / (end.x - start.x);
  4288. uvs2[4 + index] = PackUV(min_UvX, 0, xScale);
  4289. uvs2[5 + index] = PackUV(min_UvX, 1, xScale);
  4290. uvs2[6 + index] = PackUV(max_UvX, 1, xScale);
  4291. uvs2[7 + index] = PackUV(max_UvX, 0, xScale);
  4292. min_UvX = (vertices[index + 8].x - start.x) / (end.x - start.x);
  4293. max_UvX = (vertices[index + 6].x - start.x) / (end.x - start.x);
  4294. uvs2[8 + index] = PackUV(min_UvX, 0, xScale);
  4295. uvs2[9 + index] = PackUV(min_UvX, 1, xScale);
  4296. uvs2[10 + index] = PackUV(1, 1, xScale);
  4297. uvs2[11 + index] = PackUV(1, 0, xScale);
  4298. #endregion
  4299. // UNDERLINE VERTEX COLORS
  4300. #region
  4301. // Alpha is the lower of the vertex color or tag color alpha used.
  4302. underlineColor.a = m_fontColor32.a < underlineColor.a ? (byte)(m_fontColor32.a) : (byte)(underlineColor.a);
  4303. Color32[] colors32 = m_textInfo.meshInfo[0].colors32;
  4304. colors32[0 + index] = underlineColor;
  4305. colors32[1 + index] = underlineColor;
  4306. colors32[2 + index] = underlineColor;
  4307. colors32[3 + index] = underlineColor;
  4308. colors32[4 + index] = underlineColor;
  4309. colors32[5 + index] = underlineColor;
  4310. colors32[6 + index] = underlineColor;
  4311. colors32[7 + index] = underlineColor;
  4312. colors32[8 + index] = underlineColor;
  4313. colors32[9 + index] = underlineColor;
  4314. colors32[10 + index] = underlineColor;
  4315. colors32[11 + index] = underlineColor;
  4316. #endregion
  4317. index += 12;
  4318. }
  4319. protected virtual void DrawTextHighlight(Vector3 start, Vector3 end, ref int index, Color32 highlightColor)
  4320. {
  4321. if (m_cached_Underline_Character == null)
  4322. {
  4323. if (!TMP_Settings.warningsDisabled) Debug.LogWarning("Unable to add underline since the Font Asset doesn't contain the underline character.", this);
  4324. return;
  4325. }
  4326. int verticesCount = index + 4;
  4327. // Check to make sure our current mesh buffer allocations can hold these new Quads.
  4328. if (verticesCount > m_textInfo.meshInfo[0].vertices.Length)
  4329. {
  4330. // Resize Mesh Buffers
  4331. m_textInfo.meshInfo[0].ResizeMeshInfo(verticesCount / 4);
  4332. }
  4333. // UNDERLINE VERTICES FOR (3) LINE SEGMENTS
  4334. #region HIGHLIGHT VERTICES
  4335. Vector3[] vertices = m_textInfo.meshInfo[0].vertices;
  4336. // Front Part of the Underline
  4337. vertices[index + 0] = start; // BL
  4338. vertices[index + 1] = new Vector3(start.x, end.y, 0); // TL
  4339. vertices[index + 2] = end; // TR
  4340. vertices[index + 3] = new Vector3(end.x, start.y, 0); // BR
  4341. #endregion
  4342. // UNDERLINE UV0
  4343. #region HANDLE UV0
  4344. Vector2[] uvs0 = m_textInfo.meshInfo[0].uvs0;
  4345. // Calculate UV required to setup the 3 Quads for the Underline.
  4346. 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
  4347. //Vector2 uv1 = new Vector2(uv0.x, uv0.y); // top left
  4348. //Vector2 uv2 = new Vector2(uv0.x, uv0.y); // Top Right
  4349. //Vector2 uv3 = new Vector2(uv2.x, uv0.y); // Bottom Right
  4350. // Left Part of the Underline
  4351. uvs0[0 + index] = uv0; // BL
  4352. uvs0[1 + index] = uv0; // TL
  4353. uvs0[2 + index] = uv0; // TR
  4354. uvs0[3 + index] = uv0; // BR
  4355. #endregion
  4356. // UNDERLINE UV2
  4357. #region HANDLE UV2 - SDF SCALE
  4358. // UV1 contains Face / Border UV layout.
  4359. //float min_UvX = 0;
  4360. //float max_UvX = (vertices[index + 2].x - start.x) / (end.x - start.x);
  4361. ////Calculate the xScale or how much the UV's are getting stretched on the X axis for the middle section of the underline.
  4362. //float xScale = 0; // Mathf.Abs(sdfScale);
  4363. Vector2[] uvs2 = m_textInfo.meshInfo[0].uvs2;
  4364. Vector2 customUV = new Vector2(0, 1);
  4365. uvs2[0 + index] = customUV; // PackUV(-0.2f, -0.2f, xScale);
  4366. uvs2[1 + index] = customUV; // PackUV(-0.2f, -0.1f, xScale);
  4367. uvs2[2 + index] = customUV; // PackUV(-0.1f, -0.1f, xScale);
  4368. uvs2[3 + index] = customUV; // PackUV(-0.1f, -0.2f, xScale);
  4369. #endregion
  4370. // HIGHLIGHT VERTEX COLORS
  4371. #region
  4372. // Alpha is the lower of the vertex color or tag color alpha used.
  4373. highlightColor.a = m_fontColor32.a < highlightColor.a ? m_fontColor32.a : highlightColor.a;
  4374. Color32[] colors32 = m_textInfo.meshInfo[0].colors32;
  4375. colors32[0 + index] = highlightColor;
  4376. colors32[1 + index] = highlightColor;
  4377. colors32[2 + index] = highlightColor;
  4378. colors32[3 + index] = highlightColor;
  4379. #endregion
  4380. index += 4;
  4381. }
  4382. /// <summary>
  4383. /// Internal function used to load the default settings of text objects.
  4384. /// </summary>
  4385. protected void LoadDefaultSettings()
  4386. {
  4387. if (m_text == null || m_isWaitingOnResourceLoad)
  4388. {
  4389. if (TMP_Settings.autoSizeTextContainer)
  4390. autoSizeTextContainer = true;
  4391. else
  4392. {
  4393. m_rectTransform = this.rectTransform;
  4394. if (GetType() == typeof(TextMeshPro))
  4395. m_rectTransform.sizeDelta = TMP_Settings.defaultTextMeshProTextContainerSize;
  4396. else
  4397. m_rectTransform.sizeDelta = TMP_Settings.defaultTextMeshProUITextContainerSize;
  4398. }
  4399. m_enableWordWrapping = TMP_Settings.enableWordWrapping;
  4400. m_enableKerning = TMP_Settings.enableKerning;
  4401. m_enableExtraPadding = TMP_Settings.enableExtraPadding;
  4402. m_tintAllSprites = TMP_Settings.enableTintAllSprites;
  4403. m_parseCtrlCharacters = TMP_Settings.enableParseEscapeCharacters;
  4404. m_fontSize = m_fontSizeBase = TMP_Settings.defaultFontSize;
  4405. m_fontSizeMin = m_fontSize * TMP_Settings.defaultTextAutoSizingMinRatio;
  4406. m_fontSizeMax = m_fontSize * TMP_Settings.defaultTextAutoSizingMaxRatio;
  4407. m_isWaitingOnResourceLoad = false;
  4408. raycastTarget = TMP_Settings.enableRaycastTarget;
  4409. }
  4410. }
  4411. /// <summary>
  4412. /// Method used to find and cache references to the Underline and Ellipsis characters.
  4413. /// </summary>
  4414. /// <param name=""></param>
  4415. protected void GetSpecialCharacters(TMP_FontAsset fontAsset)
  4416. {
  4417. bool isUsingAlternativeTypeface;
  4418. TMP_FontAsset tempFontAsset;
  4419. // Check & Assign Underline Character for use with the Underline tag.
  4420. if (!fontAsset.characterLookupTable.TryGetValue(95, out m_cached_Underline_Character))
  4421. {
  4422. m_cached_Underline_Character = TMP_FontAssetUtilities.GetCharacterFromFontAsset(95,fontAsset, false, m_FontStyleInternal, (FontWeight)m_FontWeightInternal, out isUsingAlternativeTypeface, out tempFontAsset);
  4423. if (m_cached_Underline_Character == null)
  4424. {
  4425. if (!TMP_Settings.warningsDisabled)
  4426. Debug.LogWarning("The character used for Underline and Strikethrough is not available in font asset [" + fontAsset.name + "].", this);
  4427. }
  4428. }
  4429. // Check & Assign Underline Character for use with the Underline tag.
  4430. if (!fontAsset.characterLookupTable.TryGetValue(8230, out m_cached_Ellipsis_Character)) //95
  4431. {
  4432. m_cached_Ellipsis_Character = TMP_FontAssetUtilities.GetCharacterFromFontAsset(8230, fontAsset, false, m_FontStyleInternal, (FontWeight)m_FontWeightInternal, out isUsingAlternativeTypeface, out tempFontAsset);
  4433. if (m_cached_Ellipsis_Character == null)
  4434. {
  4435. if (!TMP_Settings.warningsDisabled)
  4436. Debug.LogWarning("The character used for Ellipsis is not available in font asset [" + fontAsset.name + "].", this);
  4437. }
  4438. }
  4439. }
  4440. /// <summary>
  4441. /// Replace a given number of characters (tag) in the array with a new character and shift subsequent characters in the array.
  4442. /// </summary>
  4443. /// <param name="chars">Array which contains the text.</param>
  4444. /// <param name="insertionIndex">The index of where the new character will be inserted</param>
  4445. /// <param name="tagLength">Length of the tag being replaced.</param>
  4446. /// <param name="c">The replacement character.</param>
  4447. protected void ReplaceTagWithCharacter(int[] chars, int insertionIndex, int tagLength, char c)
  4448. {
  4449. chars[insertionIndex] = c;
  4450. for (int i = insertionIndex + tagLength; i < chars.Length; i++)
  4451. {
  4452. chars[i - 3] = chars[i];
  4453. }
  4454. }
  4455. /// <summary>
  4456. ///
  4457. /// </summary>
  4458. /// <returns></returns>
  4459. //protected int GetMaterialReferenceForFontWeight()
  4460. //{
  4461. // //bool isItalic = (m_style & FontStyles.Italic) == FontStyles.Italic || (m_fontStyle & FontStyles.Italic) == FontStyles.Italic;
  4462. // m_currentMaterialIndex = MaterialReference.AddMaterialReference(m_currentFontAsset.fontWeights[0].italicTypeface.material, m_currentFontAsset.fontWeights[0].italicTypeface, m_materialReferences, m_materialReferenceIndexLookup);
  4463. // return 0;
  4464. //}
  4465. /// <summary>
  4466. ///
  4467. /// </summary>
  4468. /// <returns></returns>
  4469. protected TMP_FontAsset GetFontAssetForWeight(int fontWeight)
  4470. {
  4471. bool isItalic = (m_FontStyleInternal & FontStyles.Italic) == FontStyles.Italic || (m_fontStyle & FontStyles.Italic) == FontStyles.Italic;
  4472. TMP_FontAsset fontAsset = null;
  4473. int weightIndex = fontWeight / 100;
  4474. if (isItalic)
  4475. fontAsset = m_currentFontAsset.fontWeightTable[weightIndex].italicTypeface;
  4476. else
  4477. fontAsset = m_currentFontAsset.fontWeightTable[weightIndex].regularTypeface;
  4478. return fontAsset;
  4479. }
  4480. /// <summary>
  4481. /// Method to Enable or Disable child SubMesh objects.
  4482. /// </summary>
  4483. /// <param name="state"></param>
  4484. protected virtual void SetActiveSubMeshes(bool state) { }
  4485. /// <summary>
  4486. /// Destroy Sub Mesh Objects.
  4487. /// </summary>
  4488. protected virtual void ClearSubMeshObjects() { }
  4489. /// <summary>
  4490. /// Function to clear the geometry of the Primary and Sub Text objects.
  4491. /// </summary>
  4492. public virtual void ClearMesh() { }
  4493. /// <summary>
  4494. /// Function to clear the geometry of the Primary and Sub Text objects.
  4495. /// </summary>
  4496. public virtual void ClearMesh(bool uploadGeometry) { }
  4497. /// <summary>
  4498. /// Function which returns the text after it has been parsed and rich text tags removed.
  4499. /// </summary>
  4500. /// <returns></returns>
  4501. public virtual string GetParsedText()
  4502. {
  4503. if (m_textInfo == null)
  4504. return string.Empty;
  4505. int characterCount = m_textInfo.characterCount;
  4506. // TODO - Could implement some static buffer pool shared by all instances of TMP objects.
  4507. char[] buffer = new char[characterCount];
  4508. for (int i = 0; i < characterCount && i < m_textInfo.characterInfo.Length; i++)
  4509. {
  4510. buffer[i] = m_textInfo.characterInfo[i].character;
  4511. }
  4512. return new string(buffer);
  4513. }
  4514. /// <summary>
  4515. /// Function to pack scale information in the UV2 Channel.
  4516. /// </summary>
  4517. /// <param name="x"></param>
  4518. /// <param name="y"></param>
  4519. /// <param name="scale"></param>
  4520. /// <returns></returns>
  4521. //protected Vector2 PackUV(float x, float y, float scale)
  4522. //{
  4523. // Vector2 output;
  4524. // output.x = Mathf.Floor(x * 4095);
  4525. // output.y = Mathf.Floor(y * 4095);
  4526. // output.x = (output.x * 4096) + output.y;
  4527. // output.y = scale;
  4528. // return output;
  4529. //}
  4530. /// <summary>
  4531. /// Function to pack scale information in the UV2 Channel.
  4532. /// </summary>
  4533. /// <param name="x"></param>
  4534. /// <param name="y"></param>
  4535. /// <param name="scale"></param>
  4536. /// <returns></returns>
  4537. protected Vector2 PackUV(float x, float y, float scale)
  4538. {
  4539. Vector2 output;
  4540. output.x = (int)(x * 511);
  4541. output.y = (int)(y * 511);
  4542. output.x = (output.x * 4096) + output.y;
  4543. output.y = scale;
  4544. return output;
  4545. }
  4546. /// <summary>
  4547. ///
  4548. /// </summary>
  4549. /// <param name="x"></param>
  4550. /// <param name="y"></param>
  4551. /// <returns></returns>
  4552. protected float PackUV(float x, float y)
  4553. {
  4554. double x0 = (int)(x * 511);
  4555. double y0 = (int)(y * 511);
  4556. return (float)((x0 * 4096) + y0);
  4557. }
  4558. /// <summary>
  4559. /// Function used as a replacement for LateUpdate()
  4560. /// </summary>
  4561. internal virtual void InternalUpdate() { }
  4562. /// <summary>
  4563. /// Function to pack scale information in the UV2 Channel.
  4564. /// </summary>
  4565. /// <param name="x"></param>
  4566. /// <param name="y"></param>
  4567. /// <param name="scale"></param>
  4568. /// <returns></returns>
  4569. //protected Vector2 PackUV(float x, float y, float scale)
  4570. //{
  4571. // Vector2 output;
  4572. // output.x = Mathf.Floor(x * 4095);
  4573. // output.y = Mathf.Floor(y * 4095);
  4574. // return new Vector2((output.x * 4096) + output.y, scale);
  4575. //}
  4576. /// <summary>
  4577. ///
  4578. /// </summary>
  4579. /// <param name="x"></param>
  4580. /// <param name="y"></param>
  4581. /// <returns></returns>
  4582. //protected float PackUV(float x, float y)
  4583. //{
  4584. // x = (x % 5) / 5;
  4585. // y = (y % 5) / 5;
  4586. // return Mathf.Round(x * 4096) + y;
  4587. //}
  4588. /// <summary>
  4589. /// Method to convert Hex to Int
  4590. /// </summary>
  4591. /// <param name="hex"></param>
  4592. /// <returns></returns>
  4593. protected int HexToInt(char hex)
  4594. {
  4595. switch (hex)
  4596. {
  4597. case '0': return 0;
  4598. case '1': return 1;
  4599. case '2': return 2;
  4600. case '3': return 3;
  4601. case '4': return 4;
  4602. case '5': return 5;
  4603. case '6': return 6;
  4604. case '7': return 7;
  4605. case '8': return 8;
  4606. case '9': return 9;
  4607. case 'A': return 10;
  4608. case 'B': return 11;
  4609. case 'C': return 12;
  4610. case 'D': return 13;
  4611. case 'E': return 14;
  4612. case 'F': return 15;
  4613. case 'a': return 10;
  4614. case 'b': return 11;
  4615. case 'c': return 12;
  4616. case 'd': return 13;
  4617. case 'e': return 14;
  4618. case 'f': return 15;
  4619. }
  4620. return 15;
  4621. }
  4622. /// <summary>
  4623. /// Convert UTF-16 Hex to Char
  4624. /// </summary>
  4625. /// <returns>The Unicode hex.</returns>
  4626. /// <param name="i">The index.</param>
  4627. protected int GetUTF16(string text, int i)
  4628. {
  4629. int unicode = 0;
  4630. unicode += HexToInt(text[i]) << 12;
  4631. unicode += HexToInt(text[i + 1]) << 8;
  4632. unicode += HexToInt(text[i + 2]) << 4;
  4633. unicode += HexToInt(text[i + 3]);
  4634. return unicode;
  4635. }
  4636. /// <summary>
  4637. /// Convert UTF-16 Hex to Char
  4638. /// </summary>
  4639. /// <returns>The Unicode hex.</returns>
  4640. /// <param name="i">The index.</param>
  4641. protected int GetUTF16(StringBuilder text, int i)
  4642. {
  4643. int unicode = 0;
  4644. unicode += HexToInt(text[i]) << 12;
  4645. unicode += HexToInt(text[i + 1]) << 8;
  4646. unicode += HexToInt(text[i + 2]) << 4;
  4647. unicode += HexToInt(text[i + 3]);
  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(string 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. /// Convert UTF-32 Hex to Char
  4670. /// </summary>
  4671. /// <returns>The Unicode hex.</returns>
  4672. /// <param name="i">The index.</param>
  4673. protected int GetUTF32(StringBuilder text, int i)
  4674. {
  4675. int unicode = 0;
  4676. unicode += HexToInt(text[i]) << 30;
  4677. unicode += HexToInt(text[i + 1]) << 24;
  4678. unicode += HexToInt(text[i + 2]) << 20;
  4679. unicode += HexToInt(text[i + 3]) << 16;
  4680. unicode += HexToInt(text[i + 4]) << 12;
  4681. unicode += HexToInt(text[i + 5]) << 8;
  4682. unicode += HexToInt(text[i + 6]) << 4;
  4683. unicode += HexToInt(text[i + 7]);
  4684. return unicode;
  4685. }
  4686. /// <summary>
  4687. /// Method to convert Hex color values to Color32
  4688. /// </summary>
  4689. /// <param name="hexChars"></param>
  4690. /// <param name="tagCount"></param>
  4691. /// <returns></returns>
  4692. protected Color32 HexCharsToColor(char[] hexChars, int tagCount)
  4693. {
  4694. if (tagCount == 4)
  4695. {
  4696. byte r = (byte)(HexToInt(hexChars[1]) * 16 + HexToInt(hexChars[1]));
  4697. byte g = (byte)(HexToInt(hexChars[2]) * 16 + HexToInt(hexChars[2]));
  4698. byte b = (byte)(HexToInt(hexChars[3]) * 16 + HexToInt(hexChars[3]));
  4699. return new Color32(r, g, b, 255);
  4700. }
  4701. else if (tagCount == 5)
  4702. {
  4703. byte r = (byte)(HexToInt(hexChars[1]) * 16 + HexToInt(hexChars[1]));
  4704. byte g = (byte)(HexToInt(hexChars[2]) * 16 + HexToInt(hexChars[2]));
  4705. byte b = (byte)(HexToInt(hexChars[3]) * 16 + HexToInt(hexChars[3]));
  4706. byte a = (byte)(HexToInt(hexChars[4]) * 16 + HexToInt(hexChars[4]));
  4707. return new Color32(r, g, b, a);
  4708. }
  4709. else if (tagCount == 7)
  4710. {
  4711. byte r = (byte)(HexToInt(hexChars[1]) * 16 + HexToInt(hexChars[2]));
  4712. byte g = (byte)(HexToInt(hexChars[3]) * 16 + HexToInt(hexChars[4]));
  4713. byte b = (byte)(HexToInt(hexChars[5]) * 16 + HexToInt(hexChars[6]));
  4714. return new Color32(r, g, b, 255);
  4715. }
  4716. else if (tagCount == 9)
  4717. {
  4718. byte r = (byte)(HexToInt(hexChars[1]) * 16 + HexToInt(hexChars[2]));
  4719. byte g = (byte)(HexToInt(hexChars[3]) * 16 + HexToInt(hexChars[4]));
  4720. byte b = (byte)(HexToInt(hexChars[5]) * 16 + HexToInt(hexChars[6]));
  4721. byte a = (byte)(HexToInt(hexChars[7]) * 16 + HexToInt(hexChars[8]));
  4722. return new Color32(r, g, b, a);
  4723. }
  4724. else if (tagCount == 10)
  4725. {
  4726. byte r = (byte)(HexToInt(hexChars[7]) * 16 + HexToInt(hexChars[7]));
  4727. byte g = (byte)(HexToInt(hexChars[8]) * 16 + HexToInt(hexChars[8]));
  4728. byte b = (byte)(HexToInt(hexChars[9]) * 16 + HexToInt(hexChars[9]));
  4729. return new Color32(r, g, b, 255);
  4730. }
  4731. else if (tagCount == 11)
  4732. {
  4733. byte r = (byte)(HexToInt(hexChars[7]) * 16 + HexToInt(hexChars[7]));
  4734. byte g = (byte)(HexToInt(hexChars[8]) * 16 + HexToInt(hexChars[8]));
  4735. byte b = (byte)(HexToInt(hexChars[9]) * 16 + HexToInt(hexChars[9]));
  4736. byte a = (byte)(HexToInt(hexChars[10]) * 16 + HexToInt(hexChars[10]));
  4737. return new Color32(r, g, b, a);
  4738. }
  4739. else if (tagCount == 13)
  4740. {
  4741. byte r = (byte)(HexToInt(hexChars[7]) * 16 + HexToInt(hexChars[8]));
  4742. byte g = (byte)(HexToInt(hexChars[9]) * 16 + HexToInt(hexChars[10]));
  4743. byte b = (byte)(HexToInt(hexChars[11]) * 16 + HexToInt(hexChars[12]));
  4744. return new Color32(r, g, b, 255);
  4745. }
  4746. else if (tagCount == 15)
  4747. {
  4748. byte r = (byte)(HexToInt(hexChars[7]) * 16 + HexToInt(hexChars[8]));
  4749. byte g = (byte)(HexToInt(hexChars[9]) * 16 + HexToInt(hexChars[10]));
  4750. byte b = (byte)(HexToInt(hexChars[11]) * 16 + HexToInt(hexChars[12]));
  4751. byte a = (byte)(HexToInt(hexChars[13]) * 16 + HexToInt(hexChars[14]));
  4752. return new Color32(r, g, b, a);
  4753. }
  4754. return new Color32(255, 255, 255, 255);
  4755. }
  4756. /// <summary>
  4757. /// Method to convert Hex Color values to Color32
  4758. /// </summary>
  4759. /// <param name="hexChars"></param>
  4760. /// <param name="startIndex"></param>
  4761. /// <param name="length"></param>
  4762. /// <returns></returns>
  4763. protected Color32 HexCharsToColor(char[] hexChars, int startIndex, int length)
  4764. {
  4765. if (length == 7)
  4766. {
  4767. byte r = (byte)(HexToInt(hexChars[startIndex + 1]) * 16 + HexToInt(hexChars[startIndex + 2]));
  4768. byte g = (byte)(HexToInt(hexChars[startIndex + 3]) * 16 + HexToInt(hexChars[startIndex + 4]));
  4769. byte b = (byte)(HexToInt(hexChars[startIndex + 5]) * 16 + HexToInt(hexChars[startIndex + 6]));
  4770. return new Color32(r, g, b, 255);
  4771. }
  4772. else if (length == 9)
  4773. {
  4774. byte r = (byte)(HexToInt(hexChars[startIndex + 1]) * 16 + HexToInt(hexChars[startIndex + 2]));
  4775. byte g = (byte)(HexToInt(hexChars[startIndex + 3]) * 16 + HexToInt(hexChars[startIndex + 4]));
  4776. byte b = (byte)(HexToInt(hexChars[startIndex + 5]) * 16 + HexToInt(hexChars[startIndex + 6]));
  4777. byte a = (byte)(HexToInt(hexChars[startIndex + 7]) * 16 + HexToInt(hexChars[startIndex + 8]));
  4778. return new Color32(r, g, b, a);
  4779. }
  4780. return s_colorWhite;
  4781. }
  4782. /// <summary>
  4783. /// Method which returns the number of parameters used in a tag attribute and populates an array with such values.
  4784. /// </summary>
  4785. /// <param name="chars">Char[] containing the tag attribute and data</param>
  4786. /// <param name="startIndex">The index of the first char of the data</param>
  4787. /// <param name="length">The length of the data</param>
  4788. /// <param name="parameters">The number of parameters contained in the Char[]</param>
  4789. /// <returns></returns>
  4790. int GetAttributeParameters(char[] chars, int startIndex, int length, ref float[] parameters)
  4791. {
  4792. int endIndex = startIndex;
  4793. int attributeCount = 0;
  4794. while (endIndex < startIndex + length)
  4795. {
  4796. parameters[attributeCount] = ConvertToFloat(chars, startIndex, length, out endIndex);
  4797. length -= (endIndex - startIndex) + 1;
  4798. startIndex = endIndex + 1;
  4799. attributeCount += 1;
  4800. }
  4801. return attributeCount;
  4802. }
  4803. /// <summary>
  4804. /// Extracts a float value from char[] assuming we know the position of the start, end and decimal point.
  4805. /// </summary>
  4806. /// <param name="chars"></param>
  4807. /// <param name="startIndex"></param>
  4808. /// <param name="length"></param>
  4809. /// <returns></returns>
  4810. protected float ConvertToFloat(char[] chars, int startIndex, int length)
  4811. {
  4812. int lastIndex;
  4813. return ConvertToFloat(chars, startIndex, length, out lastIndex);
  4814. }
  4815. /// <summary>
  4816. /// Extracts a float value from char[] given a start index and length.
  4817. /// </summary>
  4818. /// <param name="chars"></param> The Char[] containing the numerical sequence.
  4819. /// <param name="startIndex"></param> The index of the start of the numerical sequence.
  4820. /// <param name="length"></param> The length of the numerical sequence.
  4821. /// <param name="lastIndex"></param> Index of the last character in the validated sequence.
  4822. /// <returns></returns>
  4823. protected float ConvertToFloat(char[] chars, int startIndex, int length, out int lastIndex)
  4824. {
  4825. if (startIndex == 0) { lastIndex = 0; return -9999; }
  4826. int endIndex = startIndex + length;
  4827. bool isIntegerValue = true;
  4828. float decimalPointMultiplier = 0;
  4829. // Set value multiplier checking the first character to determine if we are using '+' or '-'
  4830. int valueSignMultiplier = 1;
  4831. if (chars[startIndex] == '+')
  4832. {
  4833. valueSignMultiplier = 1;
  4834. startIndex += 1;
  4835. }
  4836. else if (chars[startIndex] == '-')
  4837. {
  4838. valueSignMultiplier = -1;
  4839. startIndex += 1;
  4840. }
  4841. float value = 0;
  4842. for (int i = startIndex; i < endIndex; i++)
  4843. {
  4844. uint c = chars[i];
  4845. if (c >= '0' && c <= '9' || c == '.')
  4846. {
  4847. if (c == '.')
  4848. {
  4849. isIntegerValue = false;
  4850. decimalPointMultiplier = 0.1f;
  4851. continue;
  4852. }
  4853. //Calculate integer and floating point value
  4854. if (isIntegerValue)
  4855. value = value * 10 + (c - 48) * valueSignMultiplier;
  4856. else
  4857. {
  4858. value = value + (c - 48) * decimalPointMultiplier * valueSignMultiplier;
  4859. decimalPointMultiplier *= 0.1f;
  4860. }
  4861. continue;
  4862. }
  4863. else if (c == ',')
  4864. {
  4865. if (i + 1 < endIndex && chars[i + 1] == ' ')
  4866. lastIndex = i + 1;
  4867. else
  4868. lastIndex = i;
  4869. return value;
  4870. }
  4871. }
  4872. lastIndex = endIndex;
  4873. return value;
  4874. }
  4875. /// <summary>
  4876. /// Function to identify and validate the rich tag. Returns the position of the > if the tag was valid.
  4877. /// </summary>
  4878. /// <param name="chars"></param>
  4879. /// <param name="startIndex"></param>
  4880. /// <param name="endIndex"></param>
  4881. /// <returns></returns>
  4882. protected bool ValidateHtmlTag(UnicodeChar[] chars, int startIndex, out int endIndex)
  4883. {
  4884. int tagCharCount = 0;
  4885. byte attributeFlag = 0;
  4886. int attributeIndex = 0;
  4887. m_xmlAttribute[attributeIndex].nameHashCode = 0;
  4888. m_xmlAttribute[attributeIndex].valueHashCode = 0;
  4889. m_xmlAttribute[attributeIndex].valueStartIndex = 0;
  4890. m_xmlAttribute[attributeIndex].valueLength = 0;
  4891. TagValueType tagValueType = m_xmlAttribute[attributeIndex].valueType = TagValueType.None;
  4892. TagUnitType tagUnitType = m_xmlAttribute[attributeIndex].unitType = TagUnitType.Pixels;
  4893. // Clear attribute name hash codes
  4894. m_xmlAttribute[1].nameHashCode = 0;
  4895. m_xmlAttribute[2].nameHashCode = 0;
  4896. m_xmlAttribute[3].nameHashCode = 0;
  4897. m_xmlAttribute[4].nameHashCode = 0;
  4898. endIndex = startIndex;
  4899. bool isTagSet = false;
  4900. bool isValidHtmlTag = false;
  4901. for (int i = startIndex; i < chars.Length && chars[i].unicode != 0 && tagCharCount < m_htmlTag.Length && chars[i].unicode != '<'; i++)
  4902. {
  4903. int unicode = chars[i].unicode;
  4904. if (unicode == '>') // ASCII Code of End HTML tag '>'
  4905. {
  4906. isValidHtmlTag = true;
  4907. endIndex = i;
  4908. m_htmlTag[tagCharCount] = (char)0;
  4909. break;
  4910. }
  4911. m_htmlTag[tagCharCount] = (char)unicode;
  4912. tagCharCount += 1;
  4913. if (attributeFlag == 1)
  4914. {
  4915. if (tagValueType == TagValueType.None)
  4916. {
  4917. // Check for attribute type
  4918. if (unicode == '+' || unicode == '-' || unicode == '.' || (unicode >= '0' && unicode <= '9'))
  4919. {
  4920. tagUnitType = TagUnitType.Pixels;
  4921. tagValueType = m_xmlAttribute[attributeIndex].valueType = TagValueType.NumericalValue;
  4922. m_xmlAttribute[attributeIndex].valueStartIndex = tagCharCount - 1;
  4923. m_xmlAttribute[attributeIndex].valueLength += 1;
  4924. }
  4925. else if (unicode == '#')
  4926. {
  4927. tagUnitType = TagUnitType.Pixels;
  4928. tagValueType = m_xmlAttribute[attributeIndex].valueType = TagValueType.ColorValue;
  4929. m_xmlAttribute[attributeIndex].valueStartIndex = tagCharCount - 1;
  4930. m_xmlAttribute[attributeIndex].valueLength += 1;
  4931. }
  4932. else if (unicode == '"')
  4933. {
  4934. tagUnitType = TagUnitType.Pixels;
  4935. tagValueType = m_xmlAttribute[attributeIndex].valueType = TagValueType.StringValue;
  4936. m_xmlAttribute[attributeIndex].valueStartIndex = tagCharCount;
  4937. }
  4938. else
  4939. {
  4940. tagUnitType = TagUnitType.Pixels;
  4941. tagValueType = m_xmlAttribute[attributeIndex].valueType = TagValueType.StringValue;
  4942. m_xmlAttribute[attributeIndex].valueStartIndex = tagCharCount - 1;
  4943. m_xmlAttribute[attributeIndex].valueHashCode = (m_xmlAttribute[attributeIndex].valueHashCode << 5) + m_xmlAttribute[attributeIndex].valueHashCode ^ unicode;
  4944. m_xmlAttribute[attributeIndex].valueLength += 1;
  4945. }
  4946. }
  4947. else
  4948. {
  4949. if (tagValueType == TagValueType.NumericalValue)
  4950. {
  4951. // Check for termination of numerical value.
  4952. if (unicode == 'p' || unicode == 'e' || unicode == '%' || unicode == ' ')
  4953. {
  4954. attributeFlag = 2;
  4955. tagValueType = TagValueType.None;
  4956. switch (unicode)
  4957. {
  4958. case 'e':
  4959. m_xmlAttribute[attributeIndex].unitType = tagUnitType = TagUnitType.FontUnits;
  4960. break;
  4961. case '%':
  4962. m_xmlAttribute[attributeIndex].unitType = tagUnitType = TagUnitType.Percentage;
  4963. break;
  4964. default:
  4965. m_xmlAttribute[attributeIndex].unitType = tagUnitType = TagUnitType.Pixels;
  4966. break;
  4967. }
  4968. attributeIndex += 1;
  4969. m_xmlAttribute[attributeIndex].nameHashCode = 0;
  4970. m_xmlAttribute[attributeIndex].valueHashCode = 0;
  4971. m_xmlAttribute[attributeIndex].valueType = TagValueType.None;
  4972. m_xmlAttribute[attributeIndex].unitType = TagUnitType.Pixels;
  4973. m_xmlAttribute[attributeIndex].valueStartIndex = 0;
  4974. m_xmlAttribute[attributeIndex].valueLength = 0;
  4975. }
  4976. else if (attributeFlag != 2)
  4977. {
  4978. m_xmlAttribute[attributeIndex].valueLength += 1;
  4979. }
  4980. }
  4981. else if (tagValueType == TagValueType.ColorValue)
  4982. {
  4983. if (unicode != ' ')
  4984. {
  4985. m_xmlAttribute[attributeIndex].valueLength += 1;
  4986. }
  4987. else
  4988. {
  4989. attributeFlag = 2;
  4990. tagValueType = TagValueType.None;
  4991. tagUnitType = TagUnitType.Pixels;
  4992. attributeIndex += 1;
  4993. m_xmlAttribute[attributeIndex].nameHashCode = 0;
  4994. m_xmlAttribute[attributeIndex].valueType = TagValueType.None;
  4995. m_xmlAttribute[attributeIndex].unitType = TagUnitType.Pixels;
  4996. m_xmlAttribute[attributeIndex].valueHashCode = 0;
  4997. m_xmlAttribute[attributeIndex].valueStartIndex = 0;
  4998. m_xmlAttribute[attributeIndex].valueLength = 0;
  4999. }
  5000. }
  5001. else if (tagValueType == TagValueType.StringValue)
  5002. {
  5003. // Compute HashCode value for the named tag.
  5004. if (unicode != '"')
  5005. {
  5006. m_xmlAttribute[attributeIndex].valueHashCode = (m_xmlAttribute[attributeIndex].valueHashCode << 5) + m_xmlAttribute[attributeIndex].valueHashCode ^ unicode;
  5007. m_xmlAttribute[attributeIndex].valueLength += 1;
  5008. }
  5009. else
  5010. {
  5011. attributeFlag = 2;
  5012. tagValueType = TagValueType.None;
  5013. tagUnitType = TagUnitType.Pixels;
  5014. attributeIndex += 1;
  5015. m_xmlAttribute[attributeIndex].nameHashCode = 0;
  5016. m_xmlAttribute[attributeIndex].valueType = TagValueType.None;
  5017. m_xmlAttribute[attributeIndex].unitType = TagUnitType.Pixels;
  5018. m_xmlAttribute[attributeIndex].valueHashCode = 0;
  5019. m_xmlAttribute[attributeIndex].valueStartIndex = 0;
  5020. m_xmlAttribute[attributeIndex].valueLength = 0;
  5021. }
  5022. }
  5023. }
  5024. }
  5025. if (unicode == '=') // '='
  5026. attributeFlag = 1;
  5027. // Compute HashCode for the name of the attribute
  5028. if (attributeFlag == 0 && unicode == ' ')
  5029. {
  5030. if (isTagSet) return false;
  5031. isTagSet = true;
  5032. attributeFlag = 2;
  5033. tagValueType = TagValueType.None;
  5034. tagUnitType = TagUnitType.Pixels;
  5035. attributeIndex += 1;
  5036. m_xmlAttribute[attributeIndex].nameHashCode = 0;
  5037. m_xmlAttribute[attributeIndex].valueType = TagValueType.None;
  5038. m_xmlAttribute[attributeIndex].unitType = TagUnitType.Pixels;
  5039. m_xmlAttribute[attributeIndex].valueHashCode = 0;
  5040. m_xmlAttribute[attributeIndex].valueStartIndex = 0;
  5041. m_xmlAttribute[attributeIndex].valueLength = 0;
  5042. }
  5043. if (attributeFlag == 0)
  5044. m_xmlAttribute[attributeIndex].nameHashCode = (m_xmlAttribute[attributeIndex].nameHashCode << 3) - m_xmlAttribute[attributeIndex].nameHashCode + unicode;
  5045. if (attributeFlag == 2 && unicode == ' ')
  5046. attributeFlag = 0;
  5047. }
  5048. if (!isValidHtmlTag)
  5049. {
  5050. return false;
  5051. }
  5052. //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);
  5053. //for (int i = 0; i < attributeIndex; i++)
  5054. // 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));
  5055. #region Rich Text Tag Processing
  5056. #if !RICH_TEXT_ENABLED
  5057. // Special handling of the no parsing tag </noparse> </NOPARSE> tag
  5058. if (tag_NoParsing && (m_xmlAttribute[0].nameHashCode != 53822163 && m_xmlAttribute[0].nameHashCode != 49429939))
  5059. return false;
  5060. else if (m_xmlAttribute[0].nameHashCode == 53822163 || m_xmlAttribute[0].nameHashCode == 49429939)
  5061. {
  5062. tag_NoParsing = false;
  5063. return true;
  5064. }
  5065. // Color <#FFF> 3 Hex values (short form)
  5066. if (m_htmlTag[0] == 35 && tagCharCount == 4)
  5067. {
  5068. m_htmlColor = HexCharsToColor(m_htmlTag, tagCharCount);
  5069. m_colorStack.Add(m_htmlColor);
  5070. return true;
  5071. }
  5072. // Color <#FFF7> 4 Hex values with alpha (short form)
  5073. else if (m_htmlTag[0] == 35 && tagCharCount == 5)
  5074. {
  5075. m_htmlColor = HexCharsToColor(m_htmlTag, tagCharCount);
  5076. m_colorStack.Add(m_htmlColor);
  5077. return true;
  5078. }
  5079. // Color <#FF00FF>
  5080. else if (m_htmlTag[0] == 35 && tagCharCount == 7) // if Tag begins with # and contains 7 characters.
  5081. {
  5082. m_htmlColor = HexCharsToColor(m_htmlTag, tagCharCount);
  5083. m_colorStack.Add(m_htmlColor);
  5084. return true;
  5085. }
  5086. // Color <#FF00FF00> with alpha
  5087. else if (m_htmlTag[0] == 35 && tagCharCount == 9) // if Tag begins with # and contains 9 characters.
  5088. {
  5089. m_htmlColor = HexCharsToColor(m_htmlTag, tagCharCount);
  5090. m_colorStack.Add(m_htmlColor);
  5091. return true;
  5092. }
  5093. else
  5094. {
  5095. float value = 0;
  5096. switch (m_xmlAttribute[0].nameHashCode)
  5097. {
  5098. case 98: // <b>
  5099. case 66: // <B>
  5100. m_FontStyleInternal |= FontStyles.Bold;
  5101. m_fontStyleStack.Add(FontStyles.Bold);
  5102. m_FontWeightInternal = FontWeight.Bold;
  5103. return true;
  5104. case 427: // </b>
  5105. case 395: // </B>
  5106. if ((m_fontStyle & FontStyles.Bold) != FontStyles.Bold)
  5107. {
  5108. if (m_fontStyleStack.Remove(FontStyles.Bold) == 0)
  5109. {
  5110. m_FontStyleInternal &= ~FontStyles.Bold;
  5111. m_FontWeightInternal = m_FontWeightStack.Peek();
  5112. }
  5113. }
  5114. return true;
  5115. case 105: // <i>
  5116. case 73: // <I>
  5117. m_FontStyleInternal |= FontStyles.Italic;
  5118. m_fontStyleStack.Add(FontStyles.Italic);
  5119. return true;
  5120. case 434: // </i>
  5121. case 402: // </I>
  5122. if ((m_fontStyle & FontStyles.Italic) != FontStyles.Italic)
  5123. {
  5124. if (m_fontStyleStack.Remove(FontStyles.Italic) == 0)
  5125. m_FontStyleInternal &= ~FontStyles.Italic;
  5126. }
  5127. return true;
  5128. case 115: // <s>
  5129. case 83: // <S>
  5130. m_FontStyleInternal |= FontStyles.Strikethrough;
  5131. m_fontStyleStack.Add(FontStyles.Strikethrough);
  5132. if (m_xmlAttribute[1].nameHashCode == 281955 || m_xmlAttribute[1].nameHashCode == 192323)
  5133. {
  5134. m_strikethroughColor = HexCharsToColor(m_htmlTag, m_xmlAttribute[1].valueStartIndex, m_xmlAttribute[1].valueLength);
  5135. m_strikethroughColor.a = m_htmlColor.a < m_strikethroughColor.a ? (byte)(m_htmlColor.a) : (byte)(m_strikethroughColor .a);
  5136. }
  5137. else
  5138. m_strikethroughColor = m_htmlColor;
  5139. m_strikethroughColorStack.Add(m_strikethroughColor);
  5140. return true;
  5141. case 444: // </s>
  5142. case 412: // </S>
  5143. if ((m_fontStyle & FontStyles.Strikethrough) != FontStyles.Strikethrough)
  5144. {
  5145. if (m_fontStyleStack.Remove(FontStyles.Strikethrough) == 0)
  5146. m_FontStyleInternal &= ~FontStyles.Strikethrough;
  5147. }
  5148. return true;
  5149. case 117: // <u>
  5150. case 85: // <U>
  5151. m_FontStyleInternal |= FontStyles.Underline;
  5152. m_fontStyleStack.Add(FontStyles.Underline);
  5153. if (m_xmlAttribute[1].nameHashCode == 281955 || m_xmlAttribute[1].nameHashCode == 192323)
  5154. {
  5155. m_underlineColor = HexCharsToColor(m_htmlTag, m_xmlAttribute[1].valueStartIndex, m_xmlAttribute[1].valueLength);
  5156. m_underlineColor.a = m_htmlColor.a < m_underlineColor.a ? (byte)(m_htmlColor.a) : (byte)(m_underlineColor.a);
  5157. }
  5158. else
  5159. m_underlineColor = m_htmlColor;
  5160. m_underlineColorStack.Add(m_underlineColor);
  5161. return true;
  5162. case 446: // </u>
  5163. case 414: // </U>
  5164. if ((m_fontStyle & FontStyles.Underline) != FontStyles.Underline)
  5165. {
  5166. m_underlineColor = m_underlineColorStack.Remove();
  5167. if (m_fontStyleStack.Remove(FontStyles.Underline) == 0)
  5168. m_FontStyleInternal &= ~FontStyles.Underline;
  5169. }
  5170. return true;
  5171. case 43045: // <mark=#FF00FF80>
  5172. case 30245: // <MARK>
  5173. m_FontStyleInternal |= FontStyles.Highlight;
  5174. m_fontStyleStack.Add(FontStyles.Highlight);
  5175. m_highlightColor = HexCharsToColor(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength);
  5176. m_highlightColor.a = m_htmlColor.a < m_highlightColor.a ? (byte)(m_htmlColor.a) : (byte)(m_highlightColor.a);
  5177. m_highlightColorStack.Add(m_highlightColor);
  5178. // Handle Mark Tag Attributes
  5179. for (int i = 0; i < m_xmlAttribute.Length && m_xmlAttribute[i].nameHashCode != 0; i++)
  5180. {
  5181. int nameHashCode = m_xmlAttribute[i].nameHashCode;
  5182. switch (nameHashCode)
  5183. {
  5184. case 281955: // color
  5185. break;
  5186. case 15087385: // padding
  5187. int paramCount = GetAttributeParameters(m_htmlTag, m_xmlAttribute[i].valueStartIndex, m_xmlAttribute[i].valueLength, ref m_attributeParameterValues);
  5188. if (paramCount != 4) return false;
  5189. m_highlightPadding = new Vector4(m_attributeParameterValues[0], m_attributeParameterValues[1], m_attributeParameterValues[2], m_attributeParameterValues[3]);
  5190. break;
  5191. }
  5192. }
  5193. return true;
  5194. case 155892: // </mark>
  5195. case 143092: // </MARK>
  5196. if ((m_fontStyle & FontStyles.Highlight) != FontStyles.Highlight)
  5197. {
  5198. m_highlightColor = m_highlightColorStack.Remove();
  5199. if (m_fontStyleStack.Remove(FontStyles.Highlight) == 0)
  5200. m_FontStyleInternal &= ~FontStyles.Highlight;
  5201. }
  5202. return true;
  5203. case 6552: // <sub>
  5204. case 4728: // <SUB>
  5205. m_fontScaleMultiplier *= m_currentFontAsset.faceInfo.subscriptSize > 0 ? m_currentFontAsset.faceInfo.subscriptSize : 1;
  5206. m_baselineOffsetStack.Push(m_baselineOffset);
  5207. m_baselineOffset += m_currentFontAsset.faceInfo.subscriptOffset * m_fontScale * m_fontScaleMultiplier;
  5208. m_fontStyleStack.Add(FontStyles.Subscript);
  5209. m_FontStyleInternal |= FontStyles.Subscript;
  5210. return true;
  5211. case 22673: // </sub>
  5212. case 20849: // </SUB>
  5213. if ((m_FontStyleInternal & FontStyles.Subscript) == FontStyles.Subscript)
  5214. {
  5215. if (m_fontScaleMultiplier < 1)
  5216. {
  5217. //m_baselineOffset -= m_currentFontAsset.fontInfo.SubscriptOffset * m_fontScale * m_fontScaleMultiplier;
  5218. m_baselineOffset = m_baselineOffsetStack.Pop();
  5219. m_fontScaleMultiplier /= m_currentFontAsset.faceInfo.subscriptSize > 0 ? m_currentFontAsset.faceInfo.subscriptSize : 1;
  5220. }
  5221. if (m_fontStyleStack.Remove(FontStyles.Subscript) == 0)
  5222. m_FontStyleInternal &= ~FontStyles.Subscript;
  5223. }
  5224. return true;
  5225. case 6566: // <sup>
  5226. case 4742: // <SUP>
  5227. m_fontScaleMultiplier *= m_currentFontAsset.faceInfo.superscriptSize > 0 ? m_currentFontAsset.faceInfo.superscriptSize : 1;
  5228. m_baselineOffsetStack.Push(m_baselineOffset);
  5229. m_baselineOffset += m_currentFontAsset.faceInfo.superscriptOffset * m_fontScale * m_fontScaleMultiplier;
  5230. m_fontStyleStack.Add(FontStyles.Superscript);
  5231. m_FontStyleInternal |= FontStyles.Superscript;
  5232. return true;
  5233. case 22687: // </sup>
  5234. case 20863: // </SUP>
  5235. if ((m_FontStyleInternal & FontStyles.Superscript) == FontStyles.Superscript)
  5236. {
  5237. if (m_fontScaleMultiplier < 1)
  5238. {
  5239. //m_baselineOffset -= m_currentFontAsset.fontInfo.SuperscriptOffset * m_fontScale * m_fontScaleMultiplier;
  5240. m_baselineOffset = m_baselineOffsetStack.Pop();
  5241. m_fontScaleMultiplier /= m_currentFontAsset.faceInfo.superscriptSize > 0 ? m_currentFontAsset.faceInfo.superscriptSize : 1;
  5242. }
  5243. if (m_fontStyleStack.Remove(FontStyles.Superscript) == 0)
  5244. m_FontStyleInternal &= ~FontStyles.Superscript;
  5245. }
  5246. return true;
  5247. case -330774850: // <font-weight>
  5248. case 2012149182: // <FONT-WEIGHT>
  5249. value = ConvertToFloat(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength);
  5250. //if (value == -9999) return false;
  5251. //if ((m_fontStyle & FontStyles.Bold) == FontStyles.Bold)
  5252. //{
  5253. // // Nothing happens since Bold is forced on the text.
  5254. // //m_fontWeight = 700;
  5255. // return true;
  5256. //}
  5257. //// Remove bold style
  5258. //m_style &= ~FontStyles.Bold;
  5259. switch ((int)value)
  5260. {
  5261. case 100:
  5262. m_FontWeightInternal = FontWeight.Thin;
  5263. break;
  5264. case 200:
  5265. m_FontWeightInternal = FontWeight.ExtraLight;
  5266. break;
  5267. case 300:
  5268. m_FontWeightInternal = FontWeight.Light;
  5269. break;
  5270. case 400:
  5271. m_FontWeightInternal = FontWeight.Regular;
  5272. break;
  5273. case 500:
  5274. m_FontWeightInternal = FontWeight.Medium;
  5275. break;
  5276. case 600:
  5277. m_FontWeightInternal = FontWeight.SemiBold;
  5278. break;
  5279. case 700:
  5280. m_FontWeightInternal = FontWeight.Bold;
  5281. break;
  5282. case 800:
  5283. m_FontWeightInternal = FontWeight.Heavy;
  5284. break;
  5285. case 900:
  5286. m_FontWeightInternal = FontWeight.Black;
  5287. break;
  5288. }
  5289. m_FontWeightStack.Add(m_FontWeightInternal);
  5290. return true;
  5291. case -1885698441: // </font-weight>
  5292. case 457225591: // </FONT-WEIGHT>
  5293. m_FontWeightStack.Remove();
  5294. if (m_FontStyleInternal == FontStyles.Bold)
  5295. m_FontWeightInternal = FontWeight.Bold;
  5296. else
  5297. m_FontWeightInternal = m_FontWeightStack.Peek();
  5298. return true;
  5299. case 6380: // <pos=000.00px> <pos=0em> <pos=50%>
  5300. case 4556: // <POS>
  5301. value = ConvertToFloat(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength);
  5302. if (value == -9999) return false;
  5303. switch (tagUnitType)
  5304. {
  5305. case TagUnitType.Pixels:
  5306. m_xAdvance = value * (m_isOrthographic ? 1.0f : 0.1f);
  5307. //m_isIgnoringAlignment = true;
  5308. return true;
  5309. case TagUnitType.FontUnits:
  5310. m_xAdvance = value * m_currentFontSize * (m_isOrthographic ? 1.0f : 0.1f);
  5311. //m_isIgnoringAlignment = true;
  5312. return true;
  5313. case TagUnitType.Percentage:
  5314. m_xAdvance = m_marginWidth * value / 100;
  5315. //m_isIgnoringAlignment = true;
  5316. return true;
  5317. }
  5318. return false;
  5319. case 22501: // </pos>
  5320. case 20677: // </POS>
  5321. m_isIgnoringAlignment = false;
  5322. return true;
  5323. case 16034505: // <voffset>
  5324. case 11642281: // <VOFFSET>
  5325. value = ConvertToFloat(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength);
  5326. if (value == -9999) return false;
  5327. switch (tagUnitType)
  5328. {
  5329. case TagUnitType.Pixels:
  5330. m_baselineOffset = value * (m_isOrthographic ? 1 : 0.1f);
  5331. return true;
  5332. case TagUnitType.FontUnits:
  5333. m_baselineOffset = value * (m_isOrthographic ? 1 : 0.1f) * m_currentFontSize;
  5334. return true;
  5335. case TagUnitType.Percentage:
  5336. //m_baselineOffset = m_marginHeight * val / 100;
  5337. return false;
  5338. }
  5339. return false;
  5340. case 54741026: // </voffset>
  5341. case 50348802: // </VOFFSET>
  5342. m_baselineOffset = 0;
  5343. return true;
  5344. case 43991: // <page>
  5345. case 31191: // <PAGE>
  5346. // This tag only works when Overflow - Page mode is used.
  5347. if (m_overflowMode == TextOverflowModes.Page)
  5348. {
  5349. m_xAdvance = 0 + tag_LineIndent + tag_Indent;
  5350. m_lineOffset = 0;
  5351. m_pageNumber += 1;
  5352. m_isNewPage = true;
  5353. }
  5354. return true;
  5355. // <BR> tag is now handled inline where it is replaced by a linefeed or \n.
  5356. //case 544: // <BR>
  5357. //case 800: // <br>
  5358. // m_forceLineBreak = true;
  5359. // return true;
  5360. case 43969: // <nobr>
  5361. case 31169: // <NOBR>
  5362. m_isNonBreakingSpace = true;
  5363. return true;
  5364. case 156816: // </nobr>
  5365. case 144016: // </NOBR>
  5366. m_isNonBreakingSpace = false;
  5367. return true;
  5368. case 45545: // <size=>
  5369. case 32745: // <SIZE>
  5370. value = ConvertToFloat(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength);
  5371. if (value == -9999) return false;
  5372. switch (tagUnitType)
  5373. {
  5374. case TagUnitType.Pixels:
  5375. if (m_htmlTag[5] == 43) // <size=+00>
  5376. {
  5377. m_currentFontSize = m_fontSize + value;
  5378. m_sizeStack.Add(m_currentFontSize);
  5379. m_fontScale = (m_currentFontSize / m_currentFontAsset.faceInfo.pointSize * m_currentFontAsset.faceInfo.scale * (m_isOrthographic ? 1 : 0.1f));
  5380. return true;
  5381. }
  5382. else if (m_htmlTag[5] == 45) // <size=-00>
  5383. {
  5384. m_currentFontSize = m_fontSize + value;
  5385. m_sizeStack.Add(m_currentFontSize);
  5386. m_fontScale = (m_currentFontSize / m_currentFontAsset.faceInfo.pointSize * m_currentFontAsset.faceInfo.scale * (m_isOrthographic ? 1 : 0.1f));
  5387. return true;
  5388. }
  5389. else // <size=00.0>
  5390. {
  5391. m_currentFontSize = value;
  5392. m_sizeStack.Add(m_currentFontSize);
  5393. m_fontScale = (m_currentFontSize / m_currentFontAsset.faceInfo.pointSize * m_currentFontAsset.faceInfo.scale * (m_isOrthographic ? 1 : 0.1f));
  5394. return true;
  5395. }
  5396. case TagUnitType.FontUnits:
  5397. m_currentFontSize = m_fontSize * value;
  5398. m_sizeStack.Add(m_currentFontSize);
  5399. m_fontScale = (m_currentFontSize / m_currentFontAsset.faceInfo.pointSize * m_currentFontAsset.faceInfo.scale * (m_isOrthographic ? 1 : 0.1f));
  5400. return true;
  5401. case TagUnitType.Percentage:
  5402. m_currentFontSize = m_fontSize * value / 100;
  5403. m_sizeStack.Add(m_currentFontSize);
  5404. m_fontScale = (m_currentFontSize / m_currentFontAsset.faceInfo.pointSize * m_currentFontAsset.faceInfo.scale * (m_isOrthographic ? 1 : 0.1f));
  5405. return true;
  5406. }
  5407. return false;
  5408. case 158392: // </size>
  5409. case 145592: // </SIZE>
  5410. m_currentFontSize = m_sizeStack.Remove();
  5411. m_fontScale = (m_currentFontSize / m_currentFontAsset.faceInfo.pointSize * m_currentFontAsset.faceInfo.scale * (m_isOrthographic ? 1 : 0.1f));
  5412. return true;
  5413. case 41311: // <font=xx>
  5414. case 28511: // <FONT>
  5415. int fontHashCode = m_xmlAttribute[0].valueHashCode;
  5416. int materialAttributeHashCode = m_xmlAttribute[1].nameHashCode;
  5417. int materialHashCode = m_xmlAttribute[1].valueHashCode;
  5418. // Special handling for <font=default> or <font=Default>
  5419. if (fontHashCode == 764638571 || fontHashCode == 523367755)
  5420. {
  5421. m_currentFontAsset = m_materialReferences[0].fontAsset;
  5422. m_currentMaterial = m_materialReferences[0].material;
  5423. m_currentMaterialIndex = 0;
  5424. //Debug.Log("<font=Default> assigning Font Asset [" + m_currentFontAsset.name + "] with Material [" + m_currentMaterial.name + "].");
  5425. m_fontScale = (m_currentFontSize / m_currentFontAsset.faceInfo.pointSize * m_currentFontAsset.faceInfo.scale * (m_isOrthographic ? 1 : 0.1f));
  5426. m_materialReferenceStack.Add(m_materialReferences[0]);
  5427. return true;
  5428. }
  5429. TMP_FontAsset tempFont;
  5430. Material tempMaterial;
  5431. // HANDLE NEW FONT ASSET
  5432. if (MaterialReferenceManager.TryGetFontAsset(fontHashCode, out tempFont))
  5433. {
  5434. //if (tempFont != m_currentFontAsset)
  5435. //{
  5436. // //Debug.Log("Assigning Font Asset: " + tempFont.name);
  5437. // m_currentFontAsset = tempFont;
  5438. // m_fontScale = (m_currentFontSize / m_currentFontAsset.fontInfo.PointSize * m_currentFontAsset.fontInfo.Scale * (m_isOrthographic ? 1 : 0.1f));
  5439. //}
  5440. }
  5441. else
  5442. {
  5443. // Load Font Asset
  5444. tempFont = Resources.Load<TMP_FontAsset>(TMP_Settings.defaultFontAssetPath + new string(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength));
  5445. if (tempFont == null)
  5446. return false;
  5447. // Add new reference to the font asset as well as default material to the MaterialReferenceManager
  5448. MaterialReferenceManager.AddFontAsset(tempFont);
  5449. }
  5450. // HANDLE NEW MATERIAL
  5451. if (materialAttributeHashCode == 0 && materialHashCode == 0)
  5452. {
  5453. // No material specified then use default font asset material.
  5454. m_currentMaterial = tempFont.material;
  5455. m_currentMaterialIndex = MaterialReference.AddMaterialReference(m_currentMaterial, tempFont, m_materialReferences, m_materialReferenceIndexLookup);
  5456. m_materialReferenceStack.Add(m_materialReferences[m_currentMaterialIndex]);
  5457. }
  5458. else if (materialAttributeHashCode == 103415287 || materialAttributeHashCode == 72669687) // using material attribute
  5459. {
  5460. if (MaterialReferenceManager.TryGetMaterial(materialHashCode, out tempMaterial))
  5461. {
  5462. m_currentMaterial = tempMaterial;
  5463. m_currentMaterialIndex = MaterialReference.AddMaterialReference(m_currentMaterial, tempFont, m_materialReferences, m_materialReferenceIndexLookup);
  5464. m_materialReferenceStack.Add(m_materialReferences[m_currentMaterialIndex]);
  5465. }
  5466. else
  5467. {
  5468. // Load new material
  5469. tempMaterial = Resources.Load<Material>(TMP_Settings.defaultFontAssetPath + new string(m_htmlTag, m_xmlAttribute[1].valueStartIndex, m_xmlAttribute[1].valueLength));
  5470. if (tempMaterial == null)
  5471. return false;
  5472. // Add new reference to this material in the MaterialReferenceManager
  5473. MaterialReferenceManager.AddFontMaterial(materialHashCode, tempMaterial);
  5474. m_currentMaterial = tempMaterial;
  5475. m_currentMaterialIndex = MaterialReference.AddMaterialReference(m_currentMaterial, tempFont, m_materialReferences, m_materialReferenceIndexLookup);
  5476. m_materialReferenceStack.Add(m_materialReferences[m_currentMaterialIndex]);
  5477. }
  5478. }
  5479. else
  5480. return false;
  5481. m_currentFontAsset = tempFont;
  5482. m_fontScale = (m_currentFontSize / m_currentFontAsset.faceInfo.pointSize * m_currentFontAsset.faceInfo.scale * (m_isOrthographic ? 1 : 0.1f));
  5483. return true;
  5484. case 154158: // </font>
  5485. case 141358: // </FONT>
  5486. {
  5487. MaterialReference materialReference = m_materialReferenceStack.Remove();
  5488. m_currentFontAsset = materialReference.fontAsset;
  5489. m_currentMaterial = materialReference.material;
  5490. m_currentMaterialIndex = materialReference.index;
  5491. m_fontScale = (m_currentFontSize / m_currentFontAsset.faceInfo.pointSize * m_currentFontAsset.faceInfo.scale * (m_isOrthographic ? 1 : 0.1f));
  5492. return true;
  5493. }
  5494. case 103415287: // <material="material name">
  5495. case 72669687: // <MATERIAL>
  5496. materialHashCode = m_xmlAttribute[0].valueHashCode;
  5497. // Special handling for <material=default> or <material=Default>
  5498. if (materialHashCode == 764638571 || materialHashCode == 523367755)
  5499. {
  5500. // Check if material font atlas texture matches that of the current font asset.
  5501. //if (m_currentFontAsset.atlas.GetInstanceID() != m_currentMaterial.GetTexture(ShaderUtilities.ID_MainTex).GetInstanceID()) return false;
  5502. m_currentMaterial = m_materialReferences[0].material;
  5503. m_currentMaterialIndex = 0;
  5504. m_materialReferenceStack.Add(m_materialReferences[0]);
  5505. return true;
  5506. }
  5507. // Check if material
  5508. if (MaterialReferenceManager.TryGetMaterial(materialHashCode, out tempMaterial))
  5509. {
  5510. // Check if material font atlas texture matches that of the current font asset.
  5511. //if (m_currentFontAsset.atlas.GetInstanceID() != tempMaterial.GetTexture(ShaderUtilities.ID_MainTex).GetInstanceID()) return false;
  5512. m_currentMaterial = tempMaterial;
  5513. m_currentMaterialIndex = MaterialReference.AddMaterialReference(m_currentMaterial, m_currentFontAsset, m_materialReferences, m_materialReferenceIndexLookup);
  5514. m_materialReferenceStack.Add(m_materialReferences[m_currentMaterialIndex]);
  5515. }
  5516. else
  5517. {
  5518. // Load new material
  5519. tempMaterial = Resources.Load<Material>(TMP_Settings.defaultFontAssetPath + new string(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength));
  5520. if (tempMaterial == null)
  5521. return false;
  5522. // Check if material font atlas texture matches that of the current font asset.
  5523. //if (m_currentFontAsset.atlas.GetInstanceID() != tempMaterial.GetTexture(ShaderUtilities.ID_MainTex).GetInstanceID()) return false;
  5524. // Add new reference to this material in the MaterialReferenceManager
  5525. MaterialReferenceManager.AddFontMaterial(materialHashCode, tempMaterial);
  5526. m_currentMaterial = tempMaterial;
  5527. m_currentMaterialIndex = MaterialReference.AddMaterialReference(m_currentMaterial, m_currentFontAsset , m_materialReferences, m_materialReferenceIndexLookup);
  5528. m_materialReferenceStack.Add(m_materialReferences[m_currentMaterialIndex]);
  5529. }
  5530. return true;
  5531. case 374360934: // </material>
  5532. case 343615334: // </MATERIAL>
  5533. {
  5534. //if (m_currentMaterial.GetTexture(ShaderUtilities.ID_MainTex).GetInstanceID() != m_materialReferenceStack.PreviousItem().material.GetTexture(ShaderUtilities.ID_MainTex).GetInstanceID())
  5535. // return false;
  5536. MaterialReference materialReference = m_materialReferenceStack.Remove();
  5537. m_currentMaterial = materialReference.material;
  5538. m_currentMaterialIndex = materialReference.index;
  5539. return true;
  5540. }
  5541. case 320078: // <space=000.00>
  5542. case 230446: // <SPACE>
  5543. value = ConvertToFloat(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength);
  5544. if (value == -9999) return false;
  5545. switch (tagUnitType)
  5546. {
  5547. case TagUnitType.Pixels:
  5548. m_xAdvance += value * (m_isOrthographic ? 1 : 0.1f);
  5549. return true;
  5550. case TagUnitType.FontUnits:
  5551. m_xAdvance += value * (m_isOrthographic ? 1 : 0.1f) * m_currentFontSize;
  5552. return true;
  5553. case TagUnitType.Percentage:
  5554. // Not applicable
  5555. return false;
  5556. }
  5557. return false;
  5558. case 276254: // <alpha=#FF>
  5559. case 186622: // <ALPHA>
  5560. if (m_xmlAttribute[0].valueLength != 3) return false;
  5561. m_htmlColor.a = (byte)(HexToInt(m_htmlTag[7]) * 16 + HexToInt(m_htmlTag[8]));
  5562. return true;
  5563. case 1750458: // <a name=" ">
  5564. return false;
  5565. case 426: // </a>
  5566. return true;
  5567. case 43066: // <link="name">
  5568. case 30266: // <LINK>
  5569. if (m_isParsingText && !m_isCalculatingPreferredValues)
  5570. {
  5571. int index = m_textInfo.linkCount;
  5572. if (index + 1 > m_textInfo.linkInfo.Length)
  5573. TMP_TextInfo.Resize(ref m_textInfo.linkInfo, index + 1);
  5574. m_textInfo.linkInfo[index].textComponent = this;
  5575. m_textInfo.linkInfo[index].hashCode = m_xmlAttribute[0].valueHashCode;
  5576. m_textInfo.linkInfo[index].linkTextfirstCharacterIndex = m_characterCount;
  5577. m_textInfo.linkInfo[index].linkIdFirstCharacterIndex = startIndex + m_xmlAttribute[0].valueStartIndex;
  5578. m_textInfo.linkInfo[index].linkIdLength = m_xmlAttribute[0].valueLength;
  5579. m_textInfo.linkInfo[index].SetLinkID(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength);
  5580. }
  5581. return true;
  5582. case 155913: // </link>
  5583. case 143113: // </LINK>
  5584. if (m_isParsingText && !m_isCalculatingPreferredValues)
  5585. {
  5586. if (m_textInfo.linkCount < m_textInfo.linkInfo.Length)
  5587. {
  5588. m_textInfo.linkInfo[m_textInfo.linkCount].linkTextLength = m_characterCount - m_textInfo.linkInfo[m_textInfo.linkCount].linkTextfirstCharacterIndex;
  5589. m_textInfo.linkCount += 1;
  5590. }
  5591. }
  5592. return true;
  5593. case 275917: // <align=>
  5594. case 186285: // <ALIGN>
  5595. switch (m_xmlAttribute[0].valueHashCode)
  5596. {
  5597. case 3774683: // <align=left>
  5598. m_lineJustification = TextAlignmentOptions.Left;
  5599. m_lineJustificationStack.Add(m_lineJustification);
  5600. return true;
  5601. case 136703040: // <align=right>
  5602. m_lineJustification = TextAlignmentOptions.Right;
  5603. m_lineJustificationStack.Add(m_lineJustification);
  5604. return true;
  5605. case -458210101: // <align=center>
  5606. m_lineJustification = TextAlignmentOptions.Center;
  5607. m_lineJustificationStack.Add(m_lineJustification);
  5608. return true;
  5609. case -523808257: // <align=justified>
  5610. m_lineJustification = TextAlignmentOptions.Justified;
  5611. m_lineJustificationStack.Add(m_lineJustification);
  5612. return true;
  5613. case 122383428: // <align=flush>
  5614. m_lineJustification = TextAlignmentOptions.Flush;
  5615. m_lineJustificationStack.Add(m_lineJustification);
  5616. return true;
  5617. }
  5618. return false;
  5619. case 1065846: // </align>
  5620. case 976214: // </ALIGN>
  5621. m_lineJustification = m_lineJustificationStack.Remove();
  5622. return true;
  5623. case 327550: // <width=xx>
  5624. case 237918: // <WIDTH>
  5625. value = ConvertToFloat(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength);
  5626. if (value == -9999) return false;
  5627. switch (tagUnitType)
  5628. {
  5629. case TagUnitType.Pixels:
  5630. m_width = value * (m_isOrthographic ? 1 : 0.1f);
  5631. break;
  5632. case TagUnitType.FontUnits:
  5633. return false;
  5634. //break;
  5635. case TagUnitType.Percentage:
  5636. m_width = m_marginWidth * value / 100;
  5637. break;
  5638. }
  5639. return true;
  5640. case 1117479: // </width>
  5641. case 1027847: // </WIDTH>
  5642. m_width = -1;
  5643. return true;
  5644. // STYLE tag is now handled inline and replaced by its definition.
  5645. //case 322689: // <style="name">
  5646. //case 233057: // <STYLE>
  5647. // TMP_Style style = TMP_StyleSheet.GetStyle(m_xmlAttribute[0].valueHashCode);
  5648. // if (style == null) return false;
  5649. // m_styleStack.Add(style.hashCode);
  5650. // // Parse Style Macro
  5651. // for (int i = 0; i < style.styleOpeningTagArray.Length; i++)
  5652. // {
  5653. // if (style.styleOpeningTagArray[i] == 60)
  5654. // {
  5655. // if (ValidateHtmlTag(style.styleOpeningTagArray, i + 1, out i) == false) return false;
  5656. // }
  5657. // }
  5658. // return true;
  5659. //case 1112618: // </style>
  5660. //case 1022986: // </STYLE>
  5661. // style = TMP_StyleSheet.GetStyle(m_xmlAttribute[0].valueHashCode);
  5662. // if (style == null)
  5663. // {
  5664. // // Get style from the Style Stack
  5665. // int styleHashCode = m_styleStack.CurrentItem();
  5666. // style = TMP_StyleSheet.GetStyle(styleHashCode);
  5667. // m_styleStack.Remove();
  5668. // }
  5669. // if (style == null) return false;
  5670. // //// Parse Style Macro
  5671. // for (int i = 0; i < style.styleClosingTagArray.Length; i++)
  5672. // {
  5673. // if (style.styleClosingTagArray[i] == 60)
  5674. // ValidateHtmlTag(style.styleClosingTagArray, i + 1, out i);
  5675. // }
  5676. // return true;
  5677. case 281955: // <color> <color=#FF00FF> or <color=#FF00FF00>
  5678. case 192323: // <COLOR=#FF00FF>
  5679. // <color=#FFF> 3 Hex (short hand)
  5680. if (m_htmlTag[6] == 35 && tagCharCount == 10)
  5681. {
  5682. m_htmlColor = HexCharsToColor(m_htmlTag, tagCharCount);
  5683. m_colorStack.Add(m_htmlColor);
  5684. return true;
  5685. }
  5686. // <color=#FFF7> 4 Hex (short hand)
  5687. else if (m_htmlTag[6] == 35 && tagCharCount == 11)
  5688. {
  5689. m_htmlColor = HexCharsToColor(m_htmlTag, tagCharCount);
  5690. m_colorStack.Add(m_htmlColor);
  5691. return true;
  5692. }
  5693. // <color=#FF00FF> 3 Hex pairs
  5694. if (m_htmlTag[6] == 35 && tagCharCount == 13)
  5695. {
  5696. m_htmlColor = HexCharsToColor(m_htmlTag, tagCharCount);
  5697. m_colorStack.Add(m_htmlColor);
  5698. return true;
  5699. }
  5700. // <color=#FF00FF00> 4 Hex pairs
  5701. else if (m_htmlTag[6] == 35 && tagCharCount == 15)
  5702. {
  5703. m_htmlColor = HexCharsToColor(m_htmlTag, tagCharCount);
  5704. m_colorStack.Add(m_htmlColor);
  5705. return true;
  5706. }
  5707. // <color=name>
  5708. switch (m_xmlAttribute[0].valueHashCode)
  5709. {
  5710. case 125395: // <color=red>
  5711. m_htmlColor = Color.red;
  5712. m_colorStack.Add(m_htmlColor);
  5713. return true;
  5714. case 3573310: // <color=blue>
  5715. m_htmlColor = Color.blue;
  5716. m_colorStack.Add(m_htmlColor);
  5717. return true;
  5718. case 117905991: // <color=black>
  5719. m_htmlColor = Color.black;
  5720. m_colorStack.Add(m_htmlColor);
  5721. return true;
  5722. case 121463835: // <color=green>
  5723. m_htmlColor = Color.green;
  5724. m_colorStack.Add(m_htmlColor);
  5725. return true;
  5726. case 140357351: // <color=white>
  5727. m_htmlColor = Color.white;
  5728. m_colorStack.Add(m_htmlColor);
  5729. return true;
  5730. case 26556144: // <color=orange>
  5731. m_htmlColor = new Color32(255, 128, 0, 255);
  5732. m_colorStack.Add(m_htmlColor);
  5733. return true;
  5734. case -36881330: // <color=purple>
  5735. m_htmlColor = new Color32(160, 32, 240, 255);
  5736. m_colorStack.Add(m_htmlColor);
  5737. return true;
  5738. case 554054276: // <color=yellow>
  5739. m_htmlColor = Color.yellow;
  5740. m_colorStack.Add(m_htmlColor);
  5741. return true;
  5742. }
  5743. return false;
  5744. case 100149144: //<gradient>
  5745. case 69403544: // <GRADIENT>
  5746. int gradientPresetHashCode = m_xmlAttribute[0].valueHashCode;
  5747. TMP_ColorGradient tempColorGradientPreset;
  5748. // Check if Color Gradient Preset has already been loaded.
  5749. if (MaterialReferenceManager.TryGetColorGradientPreset(gradientPresetHashCode, out tempColorGradientPreset))
  5750. {
  5751. m_colorGradientPreset = tempColorGradientPreset;
  5752. }
  5753. else
  5754. {
  5755. // Load Color Gradient Preset
  5756. if (tempColorGradientPreset == null)
  5757. {
  5758. tempColorGradientPreset = Resources.Load<TMP_ColorGradient>(TMP_Settings.defaultColorGradientPresetsPath + new string(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength));
  5759. }
  5760. if (tempColorGradientPreset == null)
  5761. return false;
  5762. MaterialReferenceManager.AddColorGradientPreset(gradientPresetHashCode, tempColorGradientPreset);
  5763. m_colorGradientPreset = tempColorGradientPreset;
  5764. }
  5765. m_colorGradientStack.Add(m_colorGradientPreset);
  5766. // TODO : Add support for defining preset in the tag itself
  5767. return true;
  5768. case 371094791: // </gradient>
  5769. case 340349191: // </GRADIENT>
  5770. m_colorGradientPreset = m_colorGradientStack.Remove();
  5771. return true;
  5772. case 1983971: // <cspace=xx.x>
  5773. case 1356515: // <CSPACE>
  5774. value = ConvertToFloat(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength);
  5775. if (value == -9999) return false;
  5776. switch (tagUnitType)
  5777. {
  5778. case TagUnitType.Pixels:
  5779. m_cSpacing = value * (m_isOrthographic ? 1 : 0.1f);
  5780. break;
  5781. case TagUnitType.FontUnits:
  5782. m_cSpacing = value * (m_isOrthographic ? 1 : 0.1f) * m_currentFontSize;
  5783. break;
  5784. case TagUnitType.Percentage:
  5785. return false;
  5786. }
  5787. return true;
  5788. case 7513474: // </cspace>
  5789. case 6886018: // </CSPACE>
  5790. if (!m_isParsingText) return true;
  5791. // Adjust xAdvance to remove extra space from last character.
  5792. if (m_characterCount > 0)
  5793. {
  5794. m_xAdvance -= m_cSpacing;
  5795. m_textInfo.characterInfo[m_characterCount - 1].xAdvance = m_xAdvance;
  5796. }
  5797. m_cSpacing = 0;
  5798. return true;
  5799. case 2152041: // <mspace=xx.x>
  5800. case 1524585: // <MSPACE>
  5801. value = ConvertToFloat(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength);
  5802. if (value == -9999) return false;
  5803. switch (tagUnitType)
  5804. {
  5805. case TagUnitType.Pixels:
  5806. m_monoSpacing = value * (m_isOrthographic ? 1 : 0.1f);
  5807. break;
  5808. case TagUnitType.FontUnits:
  5809. m_monoSpacing = value * (m_isOrthographic ? 1 : 0.1f) * m_currentFontSize;
  5810. break;
  5811. case TagUnitType.Percentage:
  5812. return false;
  5813. }
  5814. return true;
  5815. case 7681544: // </mspace>
  5816. case 7054088: // </MSPACE>
  5817. m_monoSpacing = 0;
  5818. return true;
  5819. case 280416: // <class="name">
  5820. return false;
  5821. case 1071884: // </color>
  5822. case 982252: // </COLOR>
  5823. m_htmlColor = m_colorStack.Remove();
  5824. return true;
  5825. case 2068980: // <indent=10px> <indent=10em> <indent=50%>
  5826. case 1441524: // <INDENT>
  5827. value = ConvertToFloat(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength);
  5828. if (value == -9999) return false;
  5829. switch (tagUnitType)
  5830. {
  5831. case TagUnitType.Pixels:
  5832. tag_Indent = value * (m_isOrthographic ? 1 : 0.1f);
  5833. break;
  5834. case TagUnitType.FontUnits:
  5835. tag_Indent = value * (m_isOrthographic ? 1 : 0.1f) * m_currentFontSize;
  5836. break;
  5837. case TagUnitType.Percentage:
  5838. tag_Indent = m_marginWidth * value / 100;
  5839. break;
  5840. }
  5841. m_indentStack.Add(tag_Indent);
  5842. m_xAdvance = tag_Indent;
  5843. return true;
  5844. case 7598483: // </indent>
  5845. case 6971027: // </INDENT>
  5846. tag_Indent = m_indentStack.Remove();
  5847. //m_xAdvance = tag_Indent;
  5848. return true;
  5849. case 1109386397: // <line-indent>
  5850. case -842656867: // <LINE-INDENT>
  5851. value = ConvertToFloat(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength);
  5852. if (value == -9999) return false;
  5853. switch (tagUnitType)
  5854. {
  5855. case TagUnitType.Pixels:
  5856. tag_LineIndent = value * (m_isOrthographic ? 1 : 0.1f);
  5857. break;
  5858. case TagUnitType.FontUnits:
  5859. tag_LineIndent = value * (m_isOrthographic ? 1 : 0.1f) * m_currentFontSize;
  5860. break;
  5861. case TagUnitType.Percentage:
  5862. tag_LineIndent = m_marginWidth * value / 100;
  5863. break;
  5864. }
  5865. m_xAdvance += tag_LineIndent;
  5866. return true;
  5867. case -445537194: // </line-indent>
  5868. case 1897386838: // </LINE-INDENT>
  5869. tag_LineIndent = 0;
  5870. return true;
  5871. case 2246877: // <sprite=x>
  5872. case 1619421: // <SPRITE>
  5873. int spriteAssetHashCode = m_xmlAttribute[0].valueHashCode;
  5874. TMP_SpriteAsset tempSpriteAsset;
  5875. m_spriteIndex = -1;
  5876. // CHECK TAG FORMAT
  5877. if (m_xmlAttribute[0].valueType == TagValueType.None || m_xmlAttribute[0].valueType == TagValueType.NumericalValue)
  5878. {
  5879. // No Sprite Asset is assigned to the text object
  5880. if (m_spriteAsset != null)
  5881. {
  5882. m_currentSpriteAsset = m_spriteAsset;
  5883. }
  5884. else if (m_defaultSpriteAsset != null)
  5885. {
  5886. m_currentSpriteAsset = m_defaultSpriteAsset;
  5887. }
  5888. else if (m_defaultSpriteAsset == null)
  5889. {
  5890. if (TMP_Settings.defaultSpriteAsset != null)
  5891. m_defaultSpriteAsset = TMP_Settings.defaultSpriteAsset;
  5892. else
  5893. m_defaultSpriteAsset = Resources.Load<TMP_SpriteAsset>("Sprite Assets/Default Sprite Asset");
  5894. m_currentSpriteAsset = m_defaultSpriteAsset;
  5895. }
  5896. // No valid sprite asset available
  5897. if (m_currentSpriteAsset == null)
  5898. return false;
  5899. }
  5900. else
  5901. {
  5902. // A Sprite Asset has been specified
  5903. if (MaterialReferenceManager.TryGetSpriteAsset(spriteAssetHashCode, out tempSpriteAsset))
  5904. {
  5905. m_currentSpriteAsset = tempSpriteAsset;
  5906. }
  5907. else
  5908. {
  5909. // Load Sprite Asset
  5910. if (tempSpriteAsset == null)
  5911. {
  5912. tempSpriteAsset = Resources.Load<TMP_SpriteAsset>(TMP_Settings.defaultSpriteAssetPath + new string(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength));
  5913. }
  5914. if (tempSpriteAsset == null)
  5915. return false;
  5916. //Debug.Log("Loading & assigning new Sprite Asset: " + tempSpriteAsset.name);
  5917. MaterialReferenceManager.AddSpriteAsset(spriteAssetHashCode, tempSpriteAsset);
  5918. m_currentSpriteAsset = tempSpriteAsset;
  5919. }
  5920. }
  5921. // Handling of <sprite=index> legacy tag format.
  5922. if (m_xmlAttribute[0].valueType == TagValueType.NumericalValue) // <sprite=index>
  5923. {
  5924. int index = (int)ConvertToFloat(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength);
  5925. if (index == -9999) return false;
  5926. // Check to make sure sprite index is valid
  5927. if (index > m_currentSpriteAsset.spriteCharacterTable.Count - 1) return false;
  5928. m_spriteIndex = index;
  5929. }
  5930. m_spriteColor = s_colorWhite;
  5931. m_tintSprite = false;
  5932. // Handle Sprite Tag Attributes
  5933. for (int i = 0; i < m_xmlAttribute.Length && m_xmlAttribute[i].nameHashCode != 0; i++)
  5934. {
  5935. //Debug.Log("Attribute[" + i + "].nameHashCode=" + m_xmlAttribute[i].nameHashCode + " Value:" + ConvertToFloat(m_htmlTag, m_xmlAttribute[i].valueStartIndex, m_xmlAttribute[i].valueLength));
  5936. int nameHashCode = m_xmlAttribute[i].nameHashCode;
  5937. int index = 0;
  5938. switch (nameHashCode)
  5939. {
  5940. case 43347: // <sprite name="">
  5941. case 30547: // <SPRITE NAME="">
  5942. m_currentSpriteAsset = TMP_SpriteAsset.SearchForSpriteByHashCode(m_currentSpriteAsset, m_xmlAttribute[i].valueHashCode, true, out index);
  5943. if (index == -1) return false;
  5944. m_spriteIndex = index;
  5945. break;
  5946. case 295562: // <sprite index=>
  5947. case 205930: // <SPRITE INDEX=>
  5948. index = (int)ConvertToFloat(m_htmlTag, m_xmlAttribute[1].valueStartIndex, m_xmlAttribute[1].valueLength);
  5949. if (index == -9999) return false;
  5950. // Check to make sure sprite index is valid
  5951. if (index > m_currentSpriteAsset.spriteCharacterTable.Count - 1) return false;
  5952. m_spriteIndex = index;
  5953. break;
  5954. case 45819: // tint
  5955. case 33019: // TINT
  5956. m_tintSprite = ConvertToFloat(m_htmlTag, m_xmlAttribute[i].valueStartIndex, m_xmlAttribute[i].valueLength) != 0;
  5957. break;
  5958. case 281955: // color=#FF00FF80
  5959. case 192323: // COLOR
  5960. m_spriteColor = HexCharsToColor(m_htmlTag, m_xmlAttribute[i].valueStartIndex, m_xmlAttribute[i].valueLength);
  5961. break;
  5962. case 39505: // anim="0,16,12" start, end, fps
  5963. case 26705: // ANIM
  5964. //Debug.Log("Start: " + m_xmlAttribute[i].valueStartIndex + " Length: " + m_xmlAttribute[i].valueLength);
  5965. int paramCount = GetAttributeParameters(m_htmlTag, m_xmlAttribute[i].valueStartIndex, m_xmlAttribute[i].valueLength, ref m_attributeParameterValues);
  5966. if (paramCount != 3) return false;
  5967. m_spriteIndex = (int)m_attributeParameterValues[0];
  5968. if (m_isParsingText)
  5969. {
  5970. // TODO : fix this!
  5971. //if (m_attributeParameterValues[0] > m_currentSpriteAsset.spriteInfoList.Count - 1 || m_attributeParameterValues[1] > m_currentSpriteAsset.spriteInfoList.Count - 1)
  5972. // return false;
  5973. spriteAnimator.DoSpriteAnimation(m_characterCount, m_currentSpriteAsset, m_spriteIndex, (int)m_attributeParameterValues[1], (int)m_attributeParameterValues[2]);
  5974. }
  5975. break;
  5976. //case 45545: // size
  5977. //case 32745: // SIZE
  5978. // break;
  5979. default:
  5980. if (nameHashCode != 2246877 && nameHashCode != 1619421)
  5981. return false;
  5982. break;
  5983. }
  5984. }
  5985. if (m_spriteIndex == -1) return false;
  5986. // Material HashCode for the Sprite Asset is the Sprite Asset Hash Code
  5987. m_currentMaterialIndex = MaterialReference.AddMaterialReference(m_currentSpriteAsset.material, m_currentSpriteAsset, m_materialReferences, m_materialReferenceIndexLookup);
  5988. m_textElementType = TMP_TextElementType.Sprite;
  5989. return true;
  5990. case 730022849: // <lowercase>
  5991. case 514803617: // <LOWERCASE>
  5992. m_FontStyleInternal |= FontStyles.LowerCase;
  5993. m_fontStyleStack.Add(FontStyles.LowerCase);
  5994. return true;
  5995. case -1668324918: // </lowercase>
  5996. case -1883544150: // </LOWERCASE>
  5997. if ((m_fontStyle & FontStyles.LowerCase) != FontStyles.LowerCase)
  5998. {
  5999. if (m_fontStyleStack.Remove(FontStyles.LowerCase) == 0)
  6000. m_FontStyleInternal &= ~FontStyles.LowerCase;
  6001. }
  6002. return true;
  6003. case 13526026: // <allcaps>
  6004. case 9133802: // <ALLCAPS>
  6005. case 781906058: // <uppercase>
  6006. case 566686826: // <UPPERCASE>
  6007. m_FontStyleInternal |= FontStyles.UpperCase;
  6008. m_fontStyleStack.Add(FontStyles.UpperCase);
  6009. return true;
  6010. case 52232547: // </allcaps>
  6011. case 47840323: // </ALLCAPS>
  6012. case -1616441709: // </uppercase>
  6013. case -1831660941: // </UPPERCASE>
  6014. if ((m_fontStyle & FontStyles.UpperCase) != FontStyles.UpperCase)
  6015. {
  6016. if (m_fontStyleStack.Remove(FontStyles.UpperCase) == 0)
  6017. m_FontStyleInternal &= ~FontStyles.UpperCase;
  6018. }
  6019. return true;
  6020. case 766244328: // <smallcaps>
  6021. case 551025096: // <SMALLCAPS>
  6022. m_FontStyleInternal |= FontStyles.SmallCaps;
  6023. m_fontStyleStack.Add(FontStyles.SmallCaps);
  6024. return true;
  6025. case -1632103439: // </smallcaps>
  6026. case -1847322671: // </SMALLCAPS>
  6027. if ((m_fontStyle & FontStyles.SmallCaps) != FontStyles.SmallCaps)
  6028. {
  6029. if (m_fontStyleStack.Remove(FontStyles.SmallCaps) == 0)
  6030. m_FontStyleInternal &= ~FontStyles.SmallCaps;
  6031. }
  6032. return true;
  6033. case 2109854: // <margin=00.0> <margin=00em> <margin=50%>
  6034. case 1482398: // <MARGIN>
  6035. // Check value type
  6036. switch (m_xmlAttribute[0].valueType)
  6037. {
  6038. case TagValueType.NumericalValue:
  6039. value = ConvertToFloat(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength); // px
  6040. if (value == -9999) return false;
  6041. // Determine tag unit type
  6042. switch (tagUnitType)
  6043. {
  6044. case TagUnitType.Pixels:
  6045. m_marginLeft = value * (m_isOrthographic ? 1 : 0.1f);
  6046. break;
  6047. case TagUnitType.FontUnits:
  6048. m_marginLeft = value * (m_isOrthographic ? 1 : 0.1f) * m_currentFontSize;
  6049. break;
  6050. case TagUnitType.Percentage:
  6051. m_marginLeft = (m_marginWidth - (m_width != -1 ? m_width : 0)) * value / 100;
  6052. break;
  6053. }
  6054. m_marginLeft = m_marginLeft >= 0 ? m_marginLeft : 0;
  6055. m_marginRight = m_marginLeft;
  6056. return true;
  6057. case TagValueType.None:
  6058. for (int i = 1; i < m_xmlAttribute.Length && m_xmlAttribute[i].nameHashCode != 0; i++)
  6059. {
  6060. // Get attribute name
  6061. int nameHashCode = m_xmlAttribute[i].nameHashCode;
  6062. switch (nameHashCode)
  6063. {
  6064. case 42823: // <margin left=value>
  6065. value = ConvertToFloat(m_htmlTag, m_xmlAttribute[i].valueStartIndex, m_xmlAttribute[i].valueLength); // px
  6066. if (value == -9999) return false;
  6067. switch (m_xmlAttribute[i].unitType)
  6068. {
  6069. case TagUnitType.Pixels:
  6070. m_marginLeft = value * (m_isOrthographic ? 1 : 0.1f);
  6071. break;
  6072. case TagUnitType.FontUnits:
  6073. m_marginLeft = value * (m_isOrthographic ? 1 : 0.1f) * m_currentFontSize;
  6074. break;
  6075. case TagUnitType.Percentage:
  6076. m_marginLeft = (m_marginWidth - (m_width != -1 ? m_width : 0)) * value / 100;
  6077. break;
  6078. }
  6079. m_marginLeft = m_marginLeft >= 0 ? m_marginLeft : 0;
  6080. break;
  6081. case 315620: // <margin right=value>
  6082. value = ConvertToFloat(m_htmlTag, m_xmlAttribute[i].valueStartIndex, m_xmlAttribute[i].valueLength); // px
  6083. if (value == -9999) return false;
  6084. switch (m_xmlAttribute[i].unitType)
  6085. {
  6086. case TagUnitType.Pixels:
  6087. m_marginRight = value * (m_isOrthographic ? 1 : 0.1f);
  6088. break;
  6089. case TagUnitType.FontUnits:
  6090. m_marginRight = value * (m_isOrthographic ? 1 : 0.1f) * m_currentFontSize;
  6091. break;
  6092. case TagUnitType.Percentage:
  6093. m_marginRight = (m_marginWidth - (m_width != -1 ? m_width : 0)) * value / 100;
  6094. break;
  6095. }
  6096. m_marginRight = m_marginRight >= 0 ? m_marginRight : 0;
  6097. break;
  6098. }
  6099. }
  6100. return true;
  6101. }
  6102. return false;
  6103. case 7639357: // </margin>
  6104. case 7011901: // </MARGIN>
  6105. m_marginLeft = 0;
  6106. m_marginRight = 0;
  6107. return true;
  6108. case 1100728678: // <margin-left=xx.x>
  6109. case -855002522: // <MARGIN-LEFT>
  6110. value = ConvertToFloat(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength); // px
  6111. if (value == -9999) return false;
  6112. switch (tagUnitType)
  6113. {
  6114. case TagUnitType.Pixels:
  6115. m_marginLeft = value * (m_isOrthographic ? 1 : 0.1f);
  6116. break;
  6117. case TagUnitType.FontUnits:
  6118. m_marginLeft = value * (m_isOrthographic ? 1 : 0.1f) * m_currentFontSize;
  6119. break;
  6120. case TagUnitType.Percentage:
  6121. m_marginLeft = (m_marginWidth - (m_width != -1 ? m_width : 0)) * value / 100;
  6122. break;
  6123. }
  6124. m_marginLeft = m_marginLeft >= 0 ? m_marginLeft : 0;
  6125. return true;
  6126. case -884817987: // <margin-right=xx.x>
  6127. case -1690034531: // <MARGIN-RIGHT>
  6128. value = ConvertToFloat(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength); // px
  6129. if (value == -9999) return false;
  6130. switch (tagUnitType)
  6131. {
  6132. case TagUnitType.Pixels:
  6133. m_marginRight = value * (m_isOrthographic ? 1 : 0.1f);
  6134. break;
  6135. case TagUnitType.FontUnits:
  6136. m_marginRight = value * (m_isOrthographic ? 1 : 0.1f) * m_currentFontSize;
  6137. break;
  6138. case TagUnitType.Percentage:
  6139. m_marginRight = (m_marginWidth - (m_width != -1 ? m_width : 0)) * value / 100;
  6140. break;
  6141. }
  6142. m_marginRight = m_marginRight >= 0 ? m_marginRight : 0;
  6143. return true;
  6144. case 1109349752: // <line-height=xx.x>
  6145. case -842693512: // <LINE-HEIGHT>
  6146. value = ConvertToFloat(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength);
  6147. if (value == -9999 || value == 0) return false;
  6148. switch (tagUnitType)
  6149. {
  6150. case TagUnitType.Pixels:
  6151. m_lineHeight = value * (m_isOrthographic ? 1 : 0.1f);
  6152. break;
  6153. case TagUnitType.FontUnits:
  6154. m_lineHeight = value * (m_isOrthographic ? 1 : 0.1f) * m_currentFontSize;
  6155. break;
  6156. case TagUnitType.Percentage:
  6157. m_lineHeight = m_fontAsset.faceInfo.lineHeight * value / 100 * m_fontScale;
  6158. break;
  6159. }
  6160. return true;
  6161. case -445573839: // </line-height>
  6162. case 1897350193: // </LINE-HEIGHT>
  6163. m_lineHeight = TMP_Math.FLOAT_UNSET;
  6164. return true;
  6165. case 15115642: // <noparse>
  6166. case 10723418: // <NOPARSE>
  6167. tag_NoParsing = true;
  6168. return true;
  6169. case 1913798: // <action>
  6170. case 1286342: // <ACTION>
  6171. int actionID = m_xmlAttribute[0].valueHashCode;
  6172. if (m_isParsingText)
  6173. {
  6174. m_actionStack.Add(actionID);
  6175. Debug.Log("Action ID: [" + actionID + "] First character index: " + m_characterCount);
  6176. }
  6177. //if (m_isParsingText)
  6178. //{
  6179. // TMP_Action action = TMP_Action.GetAction(m_xmlAttribute[0].valueHashCode);
  6180. //}
  6181. return true;
  6182. case 7443301: // </action>
  6183. case 6815845: // </ACTION>
  6184. if (m_isParsingText)
  6185. {
  6186. Debug.Log("Action ID: [" + m_actionStack.CurrentItem() + "] Last character index: " + (m_characterCount - 1));
  6187. }
  6188. m_actionStack.Remove();
  6189. return true;
  6190. case 315682: // <scale=xx.x>
  6191. case 226050: // <SCALE=xx.x>
  6192. value = ConvertToFloat(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength);
  6193. if (value == -9999) return false;
  6194. m_FXMatrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(value, 1, 1));
  6195. m_isFXMatrixSet = true;
  6196. return true;
  6197. case 1105611: // </scale>
  6198. case 1015979: // </SCALE>
  6199. m_isFXMatrixSet = false;
  6200. return true;
  6201. case 2227963: // <rotate=xx.x>
  6202. case 1600507: // <ROTATE=xx.x>
  6203. // TODO: Add ability to use Random Rotation
  6204. value = ConvertToFloat(m_htmlTag, m_xmlAttribute[0].valueStartIndex, m_xmlAttribute[0].valueLength);
  6205. if (value == -9999) return false;
  6206. m_FXMatrix = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0, 0, value), Vector3.one);
  6207. m_isFXMatrixSet = true;
  6208. return true;
  6209. case 7757466: // </rotate>
  6210. case 7130010: // </ROTATE>
  6211. m_isFXMatrixSet = false;
  6212. return true;
  6213. case 317446: // <table>
  6214. case 227814: // <TABLE>
  6215. switch (m_xmlAttribute[1].nameHashCode)
  6216. {
  6217. case 327550: // width
  6218. float tableWidth = ConvertToFloat(m_htmlTag, m_xmlAttribute[1].valueStartIndex, m_xmlAttribute[1].valueLength);
  6219. switch (tagUnitType)
  6220. {
  6221. case TagUnitType.Pixels:
  6222. Debug.Log("Table width = " + tableWidth + "px.");
  6223. break;
  6224. case TagUnitType.FontUnits:
  6225. Debug.Log("Table width = " + tableWidth + "em.");
  6226. break;
  6227. case TagUnitType.Percentage:
  6228. Debug.Log("Table width = " + tableWidth + "%.");
  6229. break;
  6230. }
  6231. break;
  6232. }
  6233. return true;
  6234. case 1107375: // </table>
  6235. case 1017743: // </TABLE>
  6236. return true;
  6237. case 926: // <tr>
  6238. case 670: // <TR>
  6239. return true;
  6240. case 3229: // </tr>
  6241. case 2973: // </TR>
  6242. return true;
  6243. case 916: // <th>
  6244. case 660: // <TH>
  6245. // Set style to bold and center alignment
  6246. return true;
  6247. case 3219: // </th>
  6248. case 2963: // </TH>
  6249. return true;
  6250. case 912: // <td>
  6251. case 656: // <TD>
  6252. // Style options
  6253. for (int i = 1; i < m_xmlAttribute.Length && m_xmlAttribute[i].nameHashCode != 0; i++)
  6254. {
  6255. switch (m_xmlAttribute[i].nameHashCode)
  6256. {
  6257. case 327550: // width
  6258. float tableWidth = ConvertToFloat(m_htmlTag, m_xmlAttribute[i].valueStartIndex, m_xmlAttribute[i].valueLength);
  6259. switch (tagUnitType)
  6260. {
  6261. case TagUnitType.Pixels:
  6262. Debug.Log("Table width = " + tableWidth + "px.");
  6263. break;
  6264. case TagUnitType.FontUnits:
  6265. Debug.Log("Table width = " + tableWidth + "em.");
  6266. break;
  6267. case TagUnitType.Percentage:
  6268. Debug.Log("Table width = " + tableWidth + "%.");
  6269. break;
  6270. }
  6271. break;
  6272. case 275917: // align
  6273. switch (m_xmlAttribute[i].valueHashCode)
  6274. {
  6275. case 3774683: // left
  6276. Debug.Log("TD align=\"left\".");
  6277. break;
  6278. case 136703040: // right
  6279. Debug.Log("TD align=\"right\".");
  6280. break;
  6281. case -458210101: // center
  6282. Debug.Log("TD align=\"center\".");
  6283. break;
  6284. case -523808257: // justified
  6285. Debug.Log("TD align=\"justified\".");
  6286. break;
  6287. }
  6288. break;
  6289. }
  6290. }
  6291. return true;
  6292. case 3215: // </td>
  6293. case 2959: // </TD>
  6294. return true;
  6295. }
  6296. }
  6297. #endif
  6298. #endregion
  6299. return false;
  6300. }
  6301. }
  6302. }